From 5dc172040ffb50ee02a4fbf599353420d50714f9 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 8 Oct 2019 15:27:16 -0400 Subject: [PATCH] Handle variables while extracting theme --- src/config.py | 4 +++- src/theme.py | 23 ++++++++++++++++++----- themes/google | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 themes/google diff --git a/src/config.py b/src/config.py index 80e264f..b59f79d 100755 --- a/src/config.py +++ b/src/config.py @@ -83,7 +83,9 @@ def extract_theme(config_file): is_theme_line=True if contains(".*colors",line): in_colors=True - if is_theme_line or in_colors: + if contains("(\s)*set",line): # If var definition + build.parse(line_orig) + elif is_theme_line or in_colors: build.parse(line_orig) # Seems to by strange to have comment here if contains(".*}",line) and in_colors: in_colors=False diff --git a/src/theme.py b/src/theme.py index fd1461a..f18df35 100644 --- a/src/theme.py +++ b/src/theme.py @@ -77,9 +77,18 @@ class ThemeBuilder: self.theme={"meta": {"description": "Generated From i3-colors"}, "window_colors":dict(), "bar_colors":dict()} + self.vars=list() + self.vars_values=dict() + def dump(self): print(yaml.dump(self.theme)) + def get(self,key): + if key in self.vars: + return(self.vars_values[key]) + else: + return(key) + def parse(self,line): if re.match("client.*",line): tokens=line.split() @@ -88,14 +97,14 @@ class ThemeBuilder: subkeys=["border","background","text","indicator","child_border"] self.theme["window_colors"][key]=dict() for token in tokens: - self.theme["window_colors"][key][subkeys[0]]=token + self.theme["window_colors"][key][subkeys[0]]=self.get(token) subkeys.pop(0) elif re.match(".*background.*",line): - self.theme["bar_colors"]["background"]=line.split()[1] + self.theme["bar_colors"]["background"]=self.get(line.split()[1]) elif re.match(".*statusline.*",line): - self.theme["bar_colors"]["statusline"]=line.split()[1] + self.theme["bar_colors"]["statusline"]=self.get(line.split()[1]) elif re.match(".*separator.*",line): - self.theme["bar_colors"]["separator"]=line.split()[1] + self.theme["bar_colors"]["separator"]=self.get(line.split()[1]) elif re.match(".*_workspace.*",line): tokens=line.split() key=tokens[0] @@ -103,7 +112,11 @@ class ThemeBuilder: subkeys=["border","background","text"] self.theme["bar_colors"][key]=dict() for token in tokens: - self.theme["bar_colors"][key][subkeys[0]]=token + self.theme["bar_colors"][key][subkeys[0]]=self.get(token) subkeys.pop(0) + elif re.match("(\s)*set",line): + key,name,value=line.split() + self.vars.append(name) + self.vars_values[name]=value diff --git a/themes/google b/themes/google new file mode 100644 index 0000000..9cd4443 --- /dev/null +++ b/themes/google @@ -0,0 +1,44 @@ +bar_colors: + active_workspace: + background: '#2d2d2d' + border: '#414141' + text: '#ffffff' + background: '#2d2d2d' + focused_workspace: + background: '#2d76f6' + border: '#4183F6' + text: '#ffffff' + inactive_workspace: + background: '#2d2d2d' + border: '#414141' + text: '#bbbbbb' + separator: '#bbbbbb' + statusline: '#ffffff' + urgent_workspace: + background: '#ffc609' + border: '#FFCB21' + text: '#ffffff' +meta: + description: Generated From i3-colors +window_colors: + focused: + background: '#2d76f6' + border: '#4183F6' + indicator: '#d8442e' + text: '#ffffff' + focused_inactive: + background: '#bbbbbb' + border: '#C1C1C1' + indicator: '#009c58' + text: '#ffffff' + unfocused: + background: '#2d2d2d' + border: '#414141' + indicator: '#bbbbbb' + text: '#ffffff' + urgent: + background: '#ffc609' + border: '#FFCB21' + indicator: '#d8442e' + text: '#ffffff' +