[core/theme] add xresources support

add support for reading foreground and background, and colors, from
xresources.py

many thanks to @Aliuakbar for the addition!

fixes #731
This commit is contained in:
tobi-wan-kenobi 2020-12-07 08:59:56 +01:00
parent 13b06793da
commit fa66873582
2 changed files with 21 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import glob
import core.event import core.event
import util.algorithm import util.algorithm
import util.xresources
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -89,13 +90,21 @@ class Theme(object):
try: try:
if isinstance(name, dict): if isinstance(name, dict):
return name return name
result = {}
if name.lower() == "wal": if name.lower() == "wal":
wal = self.__load_json("~/.cache/wal/colors.json") wal = self.__load_json("~/.cache/wal/colors.json")
result = {}
for field in ["special", "colors"]: for field in ["special", "colors"]:
for key in wal.get(field, {}): for key in wal.get(field, {}):
result[key] = wal[field][key] result[key] = wal[field][key]
return result if name.lower() == "xresources":
for key in ("background", "foreground"):
result[key] = xresources.query(key)
for i in range(16):
key = color + str(i)
result[key] = xresources.query(key)
return result
except Exception as e: except Exception as e:
log.error("failed to load colors: {}", e) log.error("failed to load colors: {}", e)

View file

@ -0,0 +1,10 @@
import subprocess
import shutil
def query(key):
if shutil.which("xgetres"):
return subprocess.run(["xgetres", key],
capture_output=True).stdout.decode("utf-8").strip()
else:
raise Exception("xgetres must be installed for this theme")