This commit is contained in:
Loic Guegan 2019-10-07 21:15:06 -04:00
parent 523d774550
commit d0b93f18c9
2 changed files with 25 additions and 24 deletions

View file

@ -1,5 +1,3 @@
#!/usr/bin/python
import re,tempfile,shutil
config_keys=["client.focused",
@ -41,7 +39,6 @@ def no_comment(line):
return(newline)
#########################
def extract(config_file):
"""
Return a temporary file path containing the current user configuration
@ -59,7 +56,7 @@ def extract(config_file):
is_theme_line=True
if contains(".*colors",line):
in_colors=True
beforeColor=re.search(".*colors",line).group(0)[:-6]
beforeColor=before_token("colors",line).strip()
if len(beforeColor)>0:
tmp.write(beforeColor+"\n")
if not(is_theme_line) and not(in_colors):
@ -70,14 +67,6 @@ def extract(config_file):
tmp.close()
return(tmp.name)
def safe_get(theme,key):
"""
TODO: To remove (useless now)
"""
if key in theme:
return(theme[key])
return("")
def write_theme(tmp_config,theme):
"""
Write the theme in a temporary file
@ -94,7 +83,7 @@ def write_theme(tmp_config,theme):
if contains("(\s)*bar",line):
in_bar=True
if contains(".*}",line) and in_bar:
beforeBrace=re.search(".*}",line).group(0)[:-1]
beforeBrace=before_token("}",line).strip()
if len(beforeBrace)>0:
tmp.write(beforeBrace+"\n")
tmp.write(" colors {\n")

View file

@ -1,6 +1,9 @@
import yaml,re, sys
def configure(theme):
"""
Apply user define colors and apply some correction factors.
"""
if "colors" in theme:
colors=theme["colors"]
window_colors=theme["window_colors"]
@ -36,6 +39,9 @@ def configure(theme):
return(theme)
def validate(theme):
"""
Abort if theme is in a wrong format.
"""
abort=lambda msg: sys.exit("Error while loading theme: "+msg)
inv_key=lambda key: abort("invalid key \""+key+"\"")
for key,value in theme.items():
@ -51,8 +57,14 @@ def validate(theme):
if not(key in ["focused","focused_inactive","unfocused","urgent","child_border"]):
inv_key(key)
def load(theme_file):
"""
Load a theme as a dict():
- Open YAML file
- Parse it as a dict
- Configure the parsed dict
- Validate the configured dict
"""
f=open(theme_file,mode="r")
theme=yaml.load(f,Loader=yaml.FullLoader)
f.close()