|
12 | 12 | color_yellow = '\033[93m'
|
13 | 13 | color_cyan = '\033[96m'
|
14 | 14 |
|
| 15 | +config = {'frame': 'round', |
| 16 | + 'max_width': 60} |
| 17 | + |
| 18 | +box_lines = { |
| 19 | + 'round': {'h': '\u2500', |
| 20 | + 'v': '\u2502', |
| 21 | + 'top_left': '\u256D', |
| 22 | + 'top_right': '\u256E', |
| 23 | + 'bottom_left':'\u2570', |
| 24 | + 'bottom_right': '\u256F'}, |
| 25 | + 'square': {'h': '\u2500', |
| 26 | + 'v': '\u2502', |
| 27 | + 'top_left': '\u250C', |
| 28 | + 'top_right': '\u2510', |
| 29 | + 'bottom_left':'\u2514', |
| 30 | + 'bottom_right': '\u2518'}, |
| 31 | + 'ascii': {'h': '-', |
| 32 | + 'v': '|', |
| 33 | + 'top_left': '-', |
| 34 | + 'top_right': '-', |
| 35 | + 'bottom_left': '-', |
| 36 | + 'bottom_right': '-'} |
| 37 | +} |
| 38 | + |
15 | 39 | def exit_error(error):
|
16 | 40 | print(error)
|
17 | 41 | exit()
|
18 | 42 |
|
| 43 | +def readConfigFile(): |
| 44 | + config_path = os.path.expanduser('~') + '/.config/gccnicerc'; |
| 45 | + |
| 46 | + try: |
| 47 | + config_file = open(config_path, 'r') |
| 48 | + config_json = json.loads(config_file.read()) |
| 49 | + for key in config: |
| 50 | + if key in config_json: |
| 51 | + config[key] = config_json[key] |
| 52 | + except: |
| 53 | + config_file = open(config_path, 'w') |
| 54 | + config_file.write(json.dumps(default_config, indent = 4)) |
| 55 | + config_file.close() |
| 56 | + |
19 | 57 | def getTerminalWidth():
|
20 | 58 | return shutil.get_terminal_size((80, 24)).columns
|
21 | 59 |
|
@@ -71,13 +109,15 @@ def bold(color):
|
71 | 109 | def wrapInOutline(text, text_width, label = None, color = color_normal,
|
72 | 110 | label_left = True, label_color = None):
|
73 | 111 |
|
| 112 | + lines = box_lines[config['frame']] |
| 113 | + |
74 | 114 | text = wrap(text, text_width,
|
75 |
| - horizontal = '\u2500', |
76 |
| - vertical = color + '\u2502' + color_normal, |
77 |
| - top_left = color + '\u256D', |
78 |
| - top_right = '\u256E' + color_normal, |
79 |
| - bottom_left = color + '\u2570', |
80 |
| - bottom_right = '\u256F' + color_normal) |
| 115 | + horizontal = lines['h'], |
| 116 | + vertical = color + lines['v'] + color_normal, |
| 117 | + top_left = color + lines['top_left'], |
| 118 | + top_right = lines['top_right'] + color_normal, |
| 119 | + bottom_left = color + lines['bottom_left'], |
| 120 | + bottom_right = lines['bottom_right'] + color_normal) |
81 | 121 |
|
82 | 122 | final_label = label
|
83 | 123 | if label_color:
|
@@ -210,7 +250,9 @@ def printMessage(message, width):
|
210 | 250 | print(' ' + line)
|
211 | 251 |
|
212 | 252 | if __name__ == '__main__':
|
213 |
| - term_width = min(getTerminalWidth(), 60) |
| 253 | + readConfigFile() |
| 254 | + |
| 255 | + term_width = min(getTerminalWidth(), config['max_width']) |
214 | 256 | gcc_json = readMessageJson()
|
215 | 257 |
|
216 | 258 | print("")
|
|
0 commit comments