aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2019-10-07 13:38:30 -0400
committerLoic Guegan <manzerbredes@mailbox.org>2019-10-07 13:38:30 -0400
commit82251214b814db66e83c821c625e1b586510c00e (patch)
tree764ff1164dbe8ad6a13fb529559d4d62b2b205cb
parentb8fa5e732a8b065ec67be57bcb94676785c944f9 (diff)
Improve theme validation
-rwxr-xr-xsrc/config.py43
-rwxr-xr-xsrc/i3-colors.py2
-rw-r--r--src/theme.py23
-rw-r--r--themes/alphare3
-rw-r--r--themes/archlinux4
-rw-r--r--themes/base16-tomorrow4
-rw-r--r--themes/debian3
-rw-r--r--themes/deep-purple4
8 files changed, 39 insertions, 47 deletions
diff --git a/src/config.py b/src/config.py
index fdee9fc..3d67ff3 100755
--- a/src/config.py
+++ b/src/config.py
@@ -2,7 +2,7 @@
import re,tempfile,shutil
-theme_keys=["client.focused",
+config_keys=["client.focused",
"client.focused_inactive",
"client.unfocused",
"client.urgent",
@@ -22,7 +22,7 @@ def extract_config(config_file):
tmp=tempfile.NamedTemporaryFile(mode="w",delete=False)
for line in f:
is_theme_line=False
- for key in theme_keys:
+ for key in config_keys:
if contains(".*"+key+"\s",line):
is_theme_line=True
if not(is_theme_line):
@@ -63,45 +63,10 @@ def apply_to_config(tmp_config,theme):
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.close()
-
+
+
def apply_theme(config_file,theme):
tmp=extract_config(config_file)
apply_to_config(tmp,theme)
shutil.move(tmp,config_file)
-theme={
- "bar":{
- "separator": "#666666",
- "background": "#333333",
- "statusline": "#bbbbbb",
- "focused_workspace": { "border":"#888888",
- "background": "#dddddd",
- "text": "#222222"},
- "active_workspace": { "border": "#333333",
- "background": "#555555",
- "text": "#bbbbbb"},
- "inactive_workspace": { "border": "#333333",
- "background": "#555555",
- "text": "#bbbbbb"},
- "urgent_workspace": { "border": "#2f343a",
- "background": "#900000",
- "text": "#ffffff"}},
- "client": {
- "client.focused": { "background": "#888888",
- "text": "#dddddd",
- "indicator": "#222222",
- "child_border": "#2e9ef4"},
- "client.focused_inactive": { "background": "#333333",
- "text": "#555555",
- "indicator": "#bbbbbb",
- "child_border": "#484e50"},
- "client.unfocused": { "background": "#333333",
- "text": "#333333",
- "indicator": "#888888",
- "child_border": "#292d2e"},
- "client.urgent": { "background": "#2f343a",
- "text": "#900000",
- "indicator": "#ffffff",
- "child_border": "#900000"}}
-}
-
diff --git a/src/i3-colors.py b/src/i3-colors.py
index 1e367b5..dd13df5 100755
--- a/src/i3-colors.py
+++ b/src/i3-colors.py
@@ -21,9 +21,9 @@ args = args_parser.parse_args()
##### Apply Theme #####
loaded_theme=theme.load(args.theme_path)
+config.apply_theme(os.environ["HOME"]+"/.config/i3/config",loaded_theme)
for meta_key,meta_value in loaded_theme["meta"].items():
log(meta_value,title=meta_key.title())
-config.apply_theme(os.environ["HOME"]+"/.config/i3/config",loaded_theme)
if args.restart:
subprocess.Popen("i3-msg restart".split())
#######################
diff --git a/src/theme.py b/src/theme.py
index d83b6b5..943832c 100644
--- a/src/theme.py
+++ b/src/theme.py
@@ -1,4 +1,4 @@
-import yaml,re
+import yaml,re, sys
def configure(theme):
if "colors" in theme:
@@ -22,8 +22,27 @@ def configure(theme):
theme["bar_colors"]=bar_colors
return(theme)
+def validate(theme):
+ abort=lambda msg: sys.exit("Error while loading theme: "+msg)
+ inv_key=lambda key: abort("invalid key \""+key+"\"")
+ for key,value in theme.items():
+ if not(key in ["meta","colors","window_colors","bar_colors"]):
+ inv_key(key)
+ if key=="bar_colors":
+ for key,value in value.items():
+ if not(key in ["separator","background","statusline",
+ "focused_workspace","active_workspace","inactive_workspace","urgent_workspace"]):
+ inv_key(key)
+ if key=="window_colors":
+ for key,value in value.items():
+ if not(key in ["focused","focused_inactive","unfocused","urgent","child_border"]):
+ inv_key(key)
+
+
def load(theme_file):
f=open(theme_file,mode="r")
theme=yaml.load(f,Loader=yaml.FullLoader)
f.close()
- return(configure(theme))
+ theme=configure(theme)
+ validate(theme)
+ return(theme)
diff --git a/themes/alphare b/themes/alphare
index 66df78d..8640df3 100644
--- a/themes/alphare
+++ b/themes/alphare
@@ -1,7 +1,8 @@
# vim: filetype=yaml
---
meta:
- description: A beige theme by Alphare
+ author: Alphare
+ description: A beige theme
colors:
black: '#000000'
oldlace: '#FDF6E3'
diff --git a/themes/archlinux b/themes/archlinux
index bfad5aa..b386b25 100644
--- a/themes/archlinux
+++ b/themes/archlinux
@@ -2,7 +2,9 @@
# TODO: use color aliases to make the theme more readable
---
meta:
- description: 'Archlinux theme by okraits <http://okraits.de>'
+ author: okraits
+ url: http://okraits.de
+ description: 'Archlinux theme'
window_colors:
focused:
border: '#0088CC'
diff --git a/themes/base16-tomorrow b/themes/base16-tomorrow
index dfab555..6c2fdce 100644
--- a/themes/base16-tomorrow
+++ b/themes/base16-tomorrow
@@ -19,7 +19,9 @@ colors:
base0F: '#a3685a'
meta:
- description: 'Base16 Tomorrow, by Chris Kempson (http://chriskempson.com)'
+ author: Chris Kempson
+ url: http://chriskempson.com
+ description: 'Base16 Tomorrow'
window_colors:
focused:
border: 'base0D'
diff --git a/themes/debian b/themes/debian
index 16a5380..206cc7e 100644
--- a/themes/debian
+++ b/themes/debian
@@ -2,7 +2,8 @@
# TODO: use color aliases to make the theme more readable
---
meta:
- description: 'Debian theme by lasers'
+ author: lasers
+ description: 'Debian theme'
window_colors:
focused:
border: '#d70a53'
diff --git a/themes/deep-purple b/themes/deep-purple
index 7474fa3..ea63c01 100644
--- a/themes/deep-purple
+++ b/themes/deep-purple
@@ -1,7 +1,9 @@
# vim: filetype=yaml
---
meta:
- description: 'Inspired by the Purple and Default themes. By jcpst <http://jcpst.com>'
+ author: jcpst
+ url: http://jcpst.com
+ description: 'Inspired by the Purple and Default themes.'
bar_colors:
separator: dimgrey
background: black