Debug/Improve

This commit is contained in:
Loic Guegan 2019-10-07 21:00:48 -04:00
parent 9adb0c6b4b
commit 523d774550
2 changed files with 33 additions and 4 deletions

View file

@ -14,10 +14,24 @@ config_keys=["client.focused",
"inactive_workspace", "inactive_workspace",
"urgent_workspace"] "urgent_workspace"]
##### Parsing Utils #####
def contains(r,line): def contains(r,line):
"""
Return true if line contains regex r.
"""
return(re.match(r,line)!=None) return(re.match(r,line)!=None)
def before_token(token, line):
"""
Return what is before token in line.
"""
found=re.search(".*"+token,line)
if found:
return(found.group(0)[:-len(token)])
return("")
def no_comment(line): def no_comment(line):
"""
Remove comment from a line.
"""
newline="" newline=""
for ch in line: for ch in line:
if ch=='#': if ch=='#':
@ -25,7 +39,9 @@ def no_comment(line):
else: else:
newline+=ch newline+=ch
return(newline) return(newline)
#########################
def extract(config_file): def extract(config_file):
""" """
Return a temporary file path containing the current user configuration Return a temporary file path containing the current user configuration
@ -99,7 +115,7 @@ def write_theme(tmp_config,theme):
client_theme=theme["window_colors"] client_theme=theme["window_colors"]
f=open(tmp_config,mode="a") f=open(tmp_config,mode="a")
for key,value in client_theme.items(): for key,value in client_theme.items():
f.write("client."+key+" "+value["border"]+" "+value["background"]+" "+value["text"]+" "+value["indicator"]+" "+safe_get(value,"child_border")+"\n") f.write("client."+key+" "+value["border"]+" "+value["background"]+" "+value["text"]+" "+value["indicator"]+" "+value["child_border"]+"\n")
f.close() f.close()

View file

@ -4,12 +4,16 @@ def configure(theme):
if "colors" in theme: if "colors" in theme:
colors=theme["colors"] colors=theme["colors"]
window_colors=theme["window_colors"] window_colors=theme["window_colors"]
##### Apply colors to window #####
for key1,value1 in window_colors.items(): for key1,value1 in window_colors.items():
for key2,value2 in value1.items(): for key2,value2 in value1.items():
if re.match("#.*",value2) == None: if re.match("#.*",value2) == None:
window_colors[key1][key2]=colors[value2] window_colors[key1][key2]=colors[value2]
theme["window_colors"]=window_colors theme["window_colors"]=window_colors
##################################
##### Apply color to bar #####
bar_colors=theme["bar_colors"] bar_colors=theme["bar_colors"]
for key1,value1 in bar_colors.items(): for key1,value1 in bar_colors.items():
if isinstance(value1,dict): if isinstance(value1,dict):
@ -20,6 +24,15 @@ def configure(theme):
if re.match("#.*",value1) == None: if re.match("#.*",value1) == None:
bar_colors[key1]=colors[value1] bar_colors[key1]=colors[value1]
theme["bar_colors"]=bar_colors theme["bar_colors"]=bar_colors
##############################
##### I3-style theme do not include child_border by default #####
window_colors=theme["window_colors"]
for key,value in window_colors.items():
if not("child_border" in value):
newvalue=value
theme["window_colors"][key]["child_border"]=newvalue["border"] # Set it to border by default
#################################################################
return(theme) return(theme)
def validate(theme): def validate(theme):