def read_config():
counter = 0
new_config = CONFIG # make a copy of the default config
with open(CONFIG_PATH, 'r') as f:
lines = [x.strip('\n') for x in f.readlines()] # strip any unempty lines
for line in lines:
counter += 1
if line.strip() and line.lstrip()[0] != '#': # skip lines with '#' at beginning
split = line.split(':') # break the line into two parts item and attributes
item = split[0].strip()
if item in palette_items: # if this line is a palette line
attribs = split[1].strip().split(",")
try: # try creating an urwid attr spec
a = urwid.AttrSpec(attribs[0].strip(), attribs[1].strip(), colors=256)
if attribs[2] not in text_options:
attribs[2] = ''
new_config[item] = [item]+[a.foreground, a.background, attribs[2]] # add this to the new config
except:
print("error on line" + str(counter))
else: # this line isn't a palette lime
if item in new_config: # if this item exists in config dict
new_config[item] = split[1].strip() # redefine it in the dict
return new_config
评论列表
文章目录