Skip to content

Commit f444847

Browse files
committed
Can now store user preferences in a config file in "~/.config". Added support for 3 frame styles and minimum frame width.
1 parent 52a1a7c commit f444847

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cve-2014-1266.c
22
out.json
33
test.c
4+
test.cpp

gccnice.py

+49-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,48 @@
1212
color_yellow = '\033[93m'
1313
color_cyan = '\033[96m'
1414

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+
1539
def exit_error(error):
1640
print(error)
1741
exit()
1842

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+
1957
def getTerminalWidth():
2058
return shutil.get_terminal_size((80, 24)).columns
2159

@@ -71,13 +109,15 @@ def bold(color):
71109
def wrapInOutline(text, text_width, label = None, color = color_normal,
72110
label_left = True, label_color = None):
73111

112+
lines = box_lines[config['frame']]
113+
74114
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)
81121

82122
final_label = label
83123
if label_color:
@@ -210,7 +250,9 @@ def printMessage(message, width):
210250
print(' ' + line)
211251

212252
if __name__ == '__main__':
213-
term_width = min(getTerminalWidth(), 60)
253+
readConfigFile()
254+
255+
term_width = min(getTerminalWidth(), config['max_width'])
214256
gcc_json = readMessageJson()
215257

216258
print("")

0 commit comments

Comments
 (0)