main
1#!/usr/bin/env python3
2import argparse
3import xml.etree.ElementTree as ET
4from pathlib import Path
5
6ICON_DIR = Path(__file__).resolve().parent / "icons"
7PRESETS = ("color", "mono-dark", "mono-light")
8COLORS = {
9 "workspace": ("#A99AF2", "#302A45"),
10 "session": ("#83B7E8", "#25384B"),
11 "shell": ("#B2BFCD", "#2B3541"),
12 "agent-claude": ("#F0B294", "#49342F"),
13 "agent-copilot": ("#C6BAF5", "#37304B"),
14 "agent-pi": ("#EACB84", "#433A28"),
15 "agent-gemini": ("#9EBFF5", "#2C354D"),
16 "agent-codex": ("#A6D8CA", "#2A403D"),
17 "status-working": ("#A6D8CA", "#2A403D"),
18 "status-waiting": ("#F0B294", "#49342F"),
19 "status-idle": ("#9EBFF5", "#2C354D"),
20 "status-done": ("#EACB84", "#433A28"),
21 "status-unknown": ("#B2BFCD", "#2B3541"),
22}
23DEFAULT_COLORS = ("#B9D4E7", "#2D3B49")
24SVG = "http://www.w3.org/2000/svg"
25ET.register_namespace("", SVG)
26
27
28def render_icon(source, preset):
29 mark = ET.fromstring(source.read_text())
30 if preset == "color":
31 foreground, background = COLORS.get(source.stem, DEFAULT_COLORS)
32 else:
33 foreground = "#EEEAF4" if preset == "mono-dark" else "#343342"
34 background = None
35 for element in mark.iter():
36 for name, value in list(element.attrib.items()):
37 if value == "currentColor":
38 element.set(name, foreground)
39 root = ET.Element(
40 f"{{{SVG}}}svg",
41 {"viewBox": "0 0 32 32", "width": "32", "height": "32"},
42 )
43 if background:
44 ET.SubElement(
45 root,
46 f"{{{SVG}}}rect",
47 {"width": "32", "height": "32", "rx": "8", "fill": background},
48 )
49 mark.set("x", "6")
50 mark.set("y", "6")
51 mark.set("width", "20")
52 mark.set("height", "20")
53 root.append(mark)
54 return ET.tostring(root, encoding="unicode") + "\n"
55
56
57def main():
58 parser = argparse.ArgumentParser()
59 parser.add_argument("--check", action="store_true")
60 args = parser.parse_args()
61 stale = []
62 for source in sorted((ICON_DIR / "source").glob("*.svg")):
63 for preset in PRESETS:
64 target = ICON_DIR / preset / source.name
65 content = render_icon(source, preset)
66 if args.check:
67 if not target.is_file() or target.read_text() != content:
68 stale.append(str(target))
69 else:
70 target.parent.mkdir(parents=True, exist_ok=True)
71 target.write_text(content)
72 if stale:
73 parser.exit(
74 1,
75 "Run uv run --no-project python3 scripts/herdr/generate_icons.py to refresh:\n"
76 + "\n".join(stale)
77 + "\n",
78 )
79
80
81if __name__ == "__main__":
82 main()