Skip to content

Commit 31e323a

Browse files
committed
Add better config handling
1 parent f444847 commit 31e323a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.gitignore

100644100755
File mode changed.

README.md

100644100755
File mode changed.

gccnice.py

100644100755
+12-7
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ def exit_error(error):
4141
exit()
4242

4343
def readConfigFile():
44-
config_path = os.path.expanduser('~') + '/.config/gccnicerc';
44+
config_path = os.path.expanduser('~') + '/.config/';
45+
config_filename = 'gccnicerc'
4546

4647
try:
47-
config_file = open(config_path, 'r')
48+
config_file = open(config_path + config_filename, 'r')
4849
config_json = json.loads(config_file.read())
50+
4951
for key in config:
5052
if key in config_json:
5153
config[key] = config_json[key]
5254
except:
53-
config_file = open(config_path, 'w')
54-
config_file.write(json.dumps(default_config, indent = 4))
55+
os.makedirs(config_path, exist_ok = True)
56+
57+
config_file = open(config_path + config_filename, 'w')
58+
config_file.write(json.dumps(config, indent = 4))
5559
config_file.close()
5660

5761
def getTerminalWidth():
@@ -64,7 +68,7 @@ def readMessageJson():
6468

6569
try:
6670
return json.loads(gcc_output)
67-
except:
71+
except: # This is not a compiler error and was not JSON-formatted.
6872
print(gcc_output)
6973
exit()
7074

@@ -80,10 +84,11 @@ def wrap(text, text_width, horizontal = ' ', vertical = ' ',
8084
+ top_right
8185
+ '\n')
8286

83-
final += '\n'.join((vertical if wrap_horizontal else '')
87+
vertical_char = vertical if wrap_horizontal else ''
88+
final += '\n'.join(vertical_char
8489
+ line
8590
+ ' ' * (text_width - len(removeColorSequences(line)))
86-
+ (vertical if wrap_horizontal else '')
91+
+ vertical_char
8792
for line in text.split('\n'))
8893

8994
if (wrap_vertical):

0 commit comments

Comments
 (0)