aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2019-10-07 21:15:06 -0400
committerLoic Guegan <manzerbredes@mailbox.org>2019-10-07 21:15:06 -0400
commitd0b93f18c92a3b71b091a498acbba2e8419ef94c (patch)
tree5b91b2806d034819ba8d3ec7b58de6a04e791b2b /src
parent523d774550087bacc6250f83421b05fce2ccc3fb (diff)
Debug
Diffstat (limited to 'src')
-rwxr-xr-xsrc/config.py35
-rw-r--r--src/theme.py14
2 files changed, 25 insertions, 24 deletions
diff --git a/src/config.py b/src/config.py
index a94c288..c8fa8bd 100755
--- a/src/config.py
+++ b/src/config.py
@@ -1,18 +1,16 @@
-#!/usr/bin/python
-
import re,tempfile,shutil
config_keys=["client.focused",
- "client.focused_inactive",
- "client.unfocused",
- "client.urgent",
- "separator",
- "background",
- "statusline",
- "focused_workspace",
- "active_workspace",
- "inactive_workspace",
- "urgent_workspace"]
+ "client.focused_inactive",
+ "client.unfocused",
+ "client.urgent",
+ "separator",
+ "background",
+ "statusline",
+ "focused_workspace",
+ "active_workspace",
+ "inactive_workspace",
+ "urgent_workspace"]
##### Parsing Utils #####
def contains(r,line):
@@ -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")
diff --git a/src/theme.py b/src/theme.py
index ad59ca4..50a7ee0 100644
--- a/src/theme.py
+++ b/src/theme.py
@@ -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()