|
1 | 1 | import os |
2 | 2 | from sys import stdout |
| 3 | +from types import SimpleNamespace as sns |
| 4 | +import colorama |
3 | 5 |
|
4 | 6 | try: |
5 | 7 | terminal_width = os.get_terminal_size()[0] |
6 | 8 | except OSError: |
7 | 9 | terminal_width = 80 |
8 | 10 |
|
| 11 | +colorama.init() # enable compatibility w/ Windows |
| 12 | +colors = sns( |
| 13 | + nc='\x1b[0m', # no color |
| 14 | + br='\x1b[1;91m', # bright red |
| 15 | + by='\x1b[1;33m', # bright yellow |
| 16 | + bo='\x1b[38;5;214m', # bright orange |
| 17 | + bg='\x1b[1;92m', # bright green |
| 18 | + bw='\x1b[1;97m', # bright white |
| 19 | + dg='\x1b[32m', # dark green |
| 20 | + dy='\x1b[33m', # dark yellow |
| 21 | + gry='\x1b[90m' # gray |
| 22 | +) |
| 23 | + |
| 24 | +def data(msg) : print(f'\n{colors.bw}{msg}{colors.nc}') |
| 25 | +def dim(msg) : print(f'\n{colors.gry}{msg}{colors.nc}') |
| 26 | +def error(msg) : print(f'\n{colors.br}ERROR: {msg}{colors.nc}') |
| 27 | +def info(msg, end='') : print(f'\n{colors.by}{msg}{colors.nc}', end=end) |
| 28 | +def overwrite_print(msg) : stdout.write('\r' + msg.ljust(terminal_width)[:terminal_width]) |
| 29 | +def tip(msg) : print(f'\n{colors.by}TIP: {msg}{colors.nc}') |
| 30 | +def success(msg) : print(f'\n{colors.bg}{msg}{colors.nc}') |
| 31 | +def warn(msg) : print(f'\n{colors.bo}WARNING: {msg}{colors.nc}') |
| 32 | + |
9 | 33 | def final_summary(summary_dict): |
10 | | - trunc('\nAll JSON files updated successfully!\n') |
| 34 | + success('\nAll JSON files updated successfully!') |
11 | 35 | for name, lang_set in summary_dict.items(): |
12 | 36 | if lang_set: |
13 | 37 | status = name.replace('_', ' ') |
14 | | - print(f'\nLanguages {status}: {len(lang_set)}') |
15 | | - print(f"[ {', '.join(lang_set)} ]") |
16 | | - |
17 | | -def overwrite_print(msg) : stdout.write('\r' + msg.ljust(terminal_width)[:terminal_width]) |
| 38 | + status_color = colors.by if status == 'translated' else colors.bg if status == 'added' else colors.gry |
| 39 | + data(f'Languages {status}: {len(lang_set)}') |
| 40 | + print(f"{status_color}[ {', '.join(lang_set)} ]{colors.nc}") |
18 | 41 |
|
19 | 42 | def trunc(msg, end='\n'): |
20 | 43 | truncated_lines = [ |
21 | | - line if len(line) < terminal_width else line[:terminal_width -4] + '...' for line in msg.splitlines() ] |
| 44 | + line if len(line) < terminal_width else line[:terminal_width -4] + '...' for line in msg.splitlines()] |
22 | 45 | print('\n'.join(truncated_lines), end=end) |
0 commit comments