aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-09 18:11:25 +0100
committerDanilo M. <danix@danix.xyz>2026-11-09 18:11:25 +0100
commitd1afaffd414fcb9328f17983540076b539456bd3 (patch)
treec85f83cf7e17f8c3013b67a6c70420f2aaa1f4b1
parent0b303ba68c19e38a4487de59df0fdc93c6dd48cf (diff)
downloaddeck-it-d1afaffd414fcb9328f17983540076b539456bd3.tar.gz
deck-it-d1afaffd414fcb9328f17983540076b539456bd3.zip
feat: UDT palette theming
-rw-r--r--deckit/theme.py58
-rw-r--r--tests/fixtures/accent.rasi1
-rw-r--r--tests/fixtures/palette.rasi20
-rw-r--r--tests/test_theme.py34
4 files changed, 113 insertions, 0 deletions
diff --git a/deckit/theme.py b/deckit/theme.py
new file mode 100644
index 0000000..7aa347b
--- /dev/null
+++ b/deckit/theme.py
@@ -0,0 +1,58 @@
+"""Read UDT's palette output and render it as CSS custom properties.
+
+UDT writes the structural palette to ~/.config/rofi/udt/palette.rasi and the
+wallpaper accent to ~/.cache/udt/udt-accent.rasi. deck-it reads both rather
+than restating the colours, so a scheme or wallpaper change reaches the tablet.
+"""
+
+import re
+from pathlib import Path
+
+PALETTE_LINE = re.compile(r"^\s*([a-z0-9]+)\s*:\s*(#[0-9a-fA-F]{6,8});", re.M)
+ACCENT = re.compile(r"accent:\s*(#[0-9a-fA-F]{6,8})")
+
+PALETTE_PATH = Path.home() / ".config" / "rofi" / "udt" / "palette.rasi"
+ACCENT_PATH = Path.home() / ".cache" / "udt" / "udt-accent.rasi"
+
+# Catppuccin Macchiato, used before UDT has ever generated its files.
+FALLBACK = {
+ "base": "#24273a", "mantle": "#1e2030", "crust": "#181926",
+ "surface0": "#363a4f", "surface1": "#494d64", "surface2": "#5b6078",
+ "text": "#cad3f5", "subtext0": "#a5adcb", "subtext1": "#b8c0e0",
+ "overlay0": "#6e738d", "red": "#ed8796", "green": "#a6da95",
+ "yellow": "#eed49f", "teal": "#8bd5ca", "blue": "#8aadf4",
+ "lavender": "#b7bdf8", "peach": "#f5a97f", "mauve": "#c6a0f6",
+ "accent": "#b7bdf8",
+}
+
+
+def parse_palette(text: str) -> dict[str, str]:
+ return dict(PALETTE_LINE.findall(text))
+
+
+def parse_accent(text: str) -> str | None:
+ m = ACCENT.search(text)
+ return m[1] if m else None
+
+
+def css(colors: dict, accent: str | None) -> str:
+ lines = [":root {"]
+ lines += [f" --udt-{name}: {value};" for name, value in colors.items()]
+ lines.append(f" --udt-accent: {accent or FALLBACK['accent']};")
+ lines.append("}")
+ return "\n".join(lines) + "\n"
+
+
+def load() -> str:
+ """Render the live UDT palette as CSS, falling back if it is not installed."""
+ try:
+ colors = parse_palette(PALETTE_PATH.read_text())
+ except OSError:
+ colors = {}
+ if not colors:
+ colors = dict(FALLBACK)
+ try:
+ accent = parse_accent(ACCENT_PATH.read_text())
+ except OSError:
+ accent = None
+ return css(colors, accent)
diff --git a/tests/fixtures/accent.rasi b/tests/fixtures/accent.rasi
new file mode 100644
index 0000000..082cf44
--- /dev/null
+++ b/tests/fixtures/accent.rasi
@@ -0,0 +1 @@
+* { accent: #b7bdf8; }
diff --git a/tests/fixtures/palette.rasi b/tests/fixtures/palette.rasi
new file mode 100644
index 0000000..2ee0c6b
--- /dev/null
+++ b/tests/fixtures/palette.rasi
@@ -0,0 +1,20 @@
+* {
+ base: #24273aff;
+ mantle: #1e2030ff;
+ crust: #181926ff;
+ surface0: #363a4fff;
+ surface1: #494d64ff;
+ surface2: #5b6078ff;
+ text: #cad3f5ff;
+ subtext0: #a5adcbff;
+ subtext1: #b8c0e0ff;
+ overlay0: #6e738dff;
+ red: #ed8796ff;
+ green: #a6da95ff;
+ yellow: #eed49fff;
+ teal: #8bd5caff;
+ blue: #8aadf4ff;
+ lavender: #b7bdf8ff;
+ peach: #f5a97fff;
+ mauve: #c6a0f6ff;
+}
diff --git a/tests/test_theme.py b/tests/test_theme.py
new file mode 100644
index 0000000..5f2f533
--- /dev/null
+++ b/tests/test_theme.py
@@ -0,0 +1,34 @@
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+
+import unittest
+
+import deckit.theme as theme
+
+PALETTE = """* {
+ base: #24273aff;
+ text: #cad3f5ff;
+ surface0: #363a4fff;
+}"""
+ACCENT = "* { accent: #b7bdf8; }"
+
+
+class Theme(unittest.TestCase):
+ def test_parses_palette(self):
+ self.assertEqual(theme.parse_palette(PALETTE),
+ {"base": "#24273aff", "text": "#cad3f5ff", "surface0": "#363a4fff"})
+
+ def test_parses_accent(self):
+ self.assertEqual(theme.parse_accent(ACCENT), "#b7bdf8")
+ self.assertIsNone(theme.parse_accent("nothing"))
+
+ def test_css_exposes_vars_and_falls_back(self):
+ out = theme.css({"base": "#24273a"}, None)
+ self.assertIn("--udt-base: #24273a", out)
+ self.assertIn("--udt-accent:", out) # fallback accent
+
+
+if __name__ == "__main__":
+ unittest.main()