diff options
| author | skylar <me@casper> | 2026-11-28 05:59:53 -0800 |
|---|---|---|
| committer | skylar <me@casper> | 2026-11-28 05:59:53 -0800 |
| commit | e4306e5435eef76bad7fa9b3b909362304a8a47e (patch) | |
| tree | d7856752d733cf2ef4551b3f6c6125635060ab58 /luxnox | |
palette.toml drives kitty, the dwl desktop (dwl, fuzzel, swaync, wob, wmenu), GTK, Qt, the console and Emacs; luxnox-toggle switches lux and nox.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'luxnox')
| -rwxr-xr-x | luxnox | 697 |
1 files changed, 697 insertions, 0 deletions
@@ -0,0 +1,697 @@ +#!/usr/bin/env python3 +"""luxnox: generate app themes from palette.toml and check their contrast. + + ./luxnox check contrast report for every color (fails under 7:1) + ./luxnox gen write build/... for every app + ./luxnox show sample text using the terminal's own 16 colors + +build/ layout: + kitty/{lux,nox}.conf kitty's light/dark-theme.auto.conf + kitty/luxnox.conf kitty options (contrast floor), included by kitty.conf + dwl/luxnox.h both palettes for dwl (copied into the dwl repo) + console/vtrgb the text consoles' 16 colors (nox), for setvtrgb + gtk/gtk-4.0.css ~/.config/gtk-4.0/gtk.css, both modes (libadwaita) + gtk/luxnox{,-dark} GTK3 themes; luxnox-apply sets the one in use + emacs/{lux,nox}-theme.el Modus-derived Emacs themes + qt/luxnox-{lux,nox}.conf qt6ct palettes; luxnox-apply selects one + {lux,nox}/... per-mode files that luxnox-apply links into place: + fuzzel.ini, wob.ini, swaync.css, swaylock, wmenu; + and kdeglobals, which it copies (Flatpak Qt apps) +""" +import sys, tomllib +from pathlib import Path + +ROOT = Path(__file__).resolve().parent +BUILD = ROOT / "build" +MODES = ["nox", "lux"] +ANSI = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"] +SLOTS = ANSI + ["bright_" + n for n in ANSI] +# Slots that are the background itself and may be unreadable as text. +EXEMPT = {"nox": {"black"}, "lux": {"bright_white"}} +MIN = 7.0 +HEADER = "Generated by luxnox from palette.toml; edit that, not this." + + +def load(): + with open(ROOT / "palette.toml", "rb") as f: + return tomllib.load(f) + + +def luminance(hx): + def lin(c): + c /= 255 + return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 + r, g, b = (lin(int(hx[i:i + 2], 16)) for i in (1, 3, 5)) + return 0.2126 * r + 0.7152 * g + 0.0722 * b + + +def contrast(a, b): + x, y = sorted((luminance(a), luminance(b)), reverse=True) + return (x + 0.05) / (y + 0.05) + + +def rgb(hx): + return tuple(int(hx[i:i + 2], 16) for i in (1, 3, 5)) + + +def swatch(hx, text): + r, g, b = rgb(hx) + return f"\x1b[38;2;{r};{g};{b}m{text}\x1b[0m" + + +def check(pal, quiet=False): + ok = True + for mode in MODES: + p = pal[mode] + bg = p["background"] + lines = [f"{mode} (background {bg})"] + # Text-on-background pairs, plus the ones where bg is drawn on a color. + pairs = [(k, p[k], bg) for k in ["foreground", "dim", "accent"] + SLOTS] + pairs += [("bg on accent", bg, p["accent"]), + ("fg on surface", p["foreground"], p["surface"]), + ("fg on hover", p["foreground"], p["hover"])] + for key, fg, back in pairs: + c = contrast(fg, back) + exempt = key in EXEMPT[mode] + mark = "exempt" if exempt else ("ok" if c >= MIN else "FAIL") + ok &= exempt or c >= MIN + lines.append(f" {key:15} {fg} {c:5.2f}:1 {mark:6} {swatch(fg, 'The quick brown fox')}") + if not quiet or not ok: + print("\n".join(lines) + "\n") + return ok + + +# --- kitty ------------------------------------------------------------------- + +def kitty(mode, p): + name = {"nox": "nox (luxnox dark)", "lux": "lux (luxnox light)"}[mode] + lines = [ + f"## name: {name}", + f"## {HEADER}", + "", + f"background {p['background']}", + f"foreground {p['foreground']}", + "", + "# Inverted selection", + f"selection_background {p['foreground']}", + f"selection_foreground {p['background']}", + "", + f"cursor {p['accent']}", + f"cursor_text_color {p['background']}", + f"url_color {p['accent']}", + "", + f"active_border_color {p['accent']}", + f"inactive_border_color {p['border']}", + f"bell_border_color {p['red']}", + "", + f"tab_bar_background {p['background']}", + f"active_tab_background {p['accent']}", + f"active_tab_foreground {p['background']}", + f"inactive_tab_background {p['surface']}", + f"inactive_tab_foreground {p['foreground']}", + "", + f"mark1_background {p['blue']}", + f"mark1_foreground {p['background']}", + f"mark2_background {p['yellow']}", + f"mark2_foreground {p['background']}", + f"mark3_background {p['magenta']}", + f"mark3_foreground {p['background']}", + "", + ] + lines += [f"color{i} {p[s]}" for i, s in enumerate(SLOTS)] + return "\n".join(lines) + "\n" + + +def kitty_options(): + """Non-color settings: kitty ignores everything but colors in + *-theme.auto.conf, so these go in a file kitty.conf includes.""" + return "\n".join([ + f"# {HEADER}", + "", + "# The 16 colors are tuned as text on the page background, so as", + "# backgrounds they clash with black/white text (htop's black on green:", + "# 2.5:1 in lux). Let kitty shift the text's lightness, keeping its hue,", + "# until it meets luxnox's minimum contrast.", + f"text_fg_override_threshold {MIN:g} ratio", + ]) + "\n" + + +# --- dwl --------------------------------------------------------------------- + +def dwl(pal): + def u32(hx): + return f"0x{hx[1:]}ff" + out = [f"/* luxnox.h: dwl's colors in both modes. {HEADER}", + " * (~/Projects/luxnox: `make install-dwl` copies it here.) */", + "enum { LuxnoxNox, LuxnoxLux };", + "", + "static const uint32_t luxnox_colors[2][3][3] = {", + "\t/* fg bg border */"] + for mode in MODES: + p = pal[mode] + out += [f"\t[Luxnox{mode.title()}] = {{", + f"\t\t[SchemeNorm] = {{ {u32(p['foreground'])}, {u32(p['background'])}, {u32(p['border'])} }},", + f"\t\t[SchemeSel] = {{ {u32(p['background'])}, {u32(p['accent'])}, {u32(p['accent'])} }},", + f"\t\t[SchemeUrg] = {{ 0, 0, {u32(p['yellow'])} }},", + "\t},"] + out += ["};", "", + "/* the desktop behind the windows */", + "static const uint32_t luxnox_root[2] = {"] + out += [f"\t[Luxnox{m.title()}] = {u32(pal[m]['background'])}," for m in MODES] + out += ["};", "", + "/* window borders of disposable VMs (dvm): red, faded when unfocused */", + "static const uint32_t luxnox_dvm[2][3] = {"] + for mode in MODES: + p = pal[mode] + faded = blend(p['red'], p['background'], 0.55) + out += [f"\t[Luxnox{mode.title()}] = {{ [SchemeNorm] = {u32(faded)}, " + f"[SchemeSel] = {u32(p['red'])}, [SchemeUrg] = {u32(p['red'])} }},"] + out += ["};", ""] + return "\n".join(out) + + +# --- per-mode desktop files ---------------------------------------------------- + +def fuzzel(p): + def c(k): + return p[k][1:] + "ff" + return f"""# {HEADER} +# Included from ~/.config/fuzzel/fuzzel.ini. +[colors] +background={c('background')} +text={c('foreground')} +prompt={c('accent')} +placeholder={c('dim')} +input={c('foreground')} +match={c('accent')} +selection={c('accent')} +selection-text={c('background')} +selection-match={c('background')} +counter={c('dim')} +border={c('accent')} +""" + + +def wob(p): + return f"""# {HEADER} +# ~/.config/wob/wob.ini links here (via ~/.local/state/luxnox/current), so +# the layout lives in luxnox too. The volume/brightness bar dwl-osd shows. +timeout = 1000 +max = 100 +width = 320 +height = 36 +border_size = 2 +border_offset = 0 +bar_padding = 6 +anchor = bottom center +margin = 120 +border_color = {p['dim'][1:]} +background_color = {p['background'][1:]} +bar_color = {p['accent'][1:]} +overflow_mode = nowrap + +# volume while muted +[style.muted] +bar_color = {p['dim'][1:]} +""" + + +def swaync(p): + def r(k): + return "rgb({}, {}, {})".format(*rgb(p[k])) + a = "{}, {}, {}".format(*rgb(p["accent"])) + return f"""/* {HEADER} + Imported by ~/.config/swaync/style.css. */ +:root {{ + --cc-bg: {r('background')}; + --noti-border-color: {r('border')}; + --noti-bg: {'{}, {}, {}'.format(*rgb(p['surface']))}; + --noti-bg-alpha: 1; + --noti-bg-darker: {r('background')}; + --noti-bg-hover: {r('hover')}; + --noti-bg-focus: rgba({a}, 0.25); + --noti-close-bg: {r('hover')}; + --noti-close-bg-hover: {r('border')}; + --text-color: {r('foreground')}; + --text-color-disabled: {r('dim')}; + --bg-selected: {r('accent')}; +}} + +.notification-row .notification-background .notification.critical {{ + border-color: {r('red')}; +}} + +/* Action buttons ("Play in mpv"): the accent, background-colored text on it */ +.notification-row .notification-background .notification .notification-action > button:hover {{ + background: {r('accent')}; + color: {r('background')}; +}} + +.control-center {{ + border: 1px solid {r('border')}; +}} +""" + + +def swaylock(p): + def c(k): + return p[k][1:] + lines = [f"# {HEADER}", + "# ~/.config/swaylock/config links here (via ~/.local/state/luxnox/current).", + f"color={c('background')}"] + for state in ["", "-clear", "-caps-lock", "-ver", "-wrong"]: + lines += [f"inside{state}-color={c('background')}", + f"line{state}-color={c('background')}"] + lines += [f"ring-color={c('border')}", + f"ring-clear-color={c('dim')}", + f"ring-caps-lock-color={c('yellow')}", + f"ring-ver-color={c('accent')}", + f"ring-wrong-color={c('red')}", + f"key-hl-color={c('accent')}", + f"bs-hl-color={c('red')}", + f"caps-lock-key-hl-color={c('yellow')}", + f"caps-lock-bs-hl-color={c('red')}", + f"separator-color={c('background')}", + f"text-color={c('foreground')}", + f"text-clear-color={c('foreground')}", + f"text-caps-lock-color={c('yellow')}", + f"text-ver-color={c('foreground')}", + f"text-wrong-color={c('red')}", + f"layout-bg-color={c('background')}", + f"layout-border-color={c('border')}", + f"layout-text-color={c('foreground')}"] + return "\n".join(lines) + "\n" + + +# --- GTK --------------------------------------------------------------------- +# libadwaita's named colors (adw-gtk3 uses the same names for GTK3). Flat: +# every surface is the background; areas are told apart by border lines. + +def blend(fg, bg, a): + f, b = rgb(fg), rgb(bg) + return "#" + "".join(f"{round(x * a + y * (1 - a)):02x}" for x, y in zip(f, b)) + + +def dim_opacity(pal): + """libadwaita fades secondary text by --dim-opacity; the lowest that keeps + it at MIN contrast in both modes (plus a little margin).""" + need = 0 + for p in pal.values(): + a = next(i for i in range(30, 101) + if contrast(blend(p["foreground"], p["background"], i / 100), p["background"]) >= MIN) + need = max(need, a) + return min(100, need + 3) + + +def gtk_colors(p): + bg, fg, line = p["background"], p["foreground"], p["border"] + c = {} + for area in ["window", "view", "headerbar", "sidebar", "secondary_sidebar", + "card", "dialog", "popover", "thumbnail"]: + c[f"{area}_bg_color"] = bg + c[f"{area}_fg_color"] = fg + c.update({ + "headerbar_backdrop_color": bg, + "headerbar_border_color": fg, + "headerbar_shade_color": line, + "headerbar_darker_shade_color": line, + "sidebar_backdrop_color": bg, + "sidebar_shade_color": line, + "sidebar_border_color": line, + "secondary_sidebar_backdrop_color": bg, + "secondary_sidebar_shade_color": line, + "secondary_sidebar_border_color": line, + "card_shade_color": line, + "popover_shade_color": line, + "shade_color": line, + "scrollbar_outline_color": bg, + }) + # Filled (bg) and standalone (text) variants: the 7:1 normals either way; + # text on the filled ones is the background (also 7:1+, see check). + for role, key in [("accent", "accent"), ("destructive", "red"), ("error", "red"), + ("success", "green"), ("warning", "yellow")]: + c[f"{role}_bg_color"] = p[key] + c[f"{role}_fg_color"] = bg + c[f"{role}_color"] = p[key] + return c + + +# Readability fixes on top of libadwaita's own styles. +GTK4_RULES = """/* Unfocused windows keep full-strength text: dwl's border shows focus, + so libadwaita's 50% fade of bars in the backdrop isn't needed. */ +headerbar:backdrop > windowhandle, +tabbar .box:backdrop > scrolledwindow, +tabbar .box:backdrop > .start-action, +tabbar .box:backdrop > .end-action, +searchbar > revealer > box:backdrop > *, +actionbar > revealer > box:backdrop > *, +banner > revealer > widget:backdrop > label, +banner > revealer > widget:backdrop > button, +toolbarview > .top-bar:backdrop > windowhandle, +toolbarview > .bottom-bar:backdrop > windowhandle { + filter: none; +} + +/* List column headers: faded like other secondary text (7:1), not 40%. */ +columnview > header > button > box, +treeview.view > header > button > box { + color: color-mix(in srgb, currentColor var(--dim-opacity), transparent); +} +""" + + +def gtk4(pal): + dim = dim_opacity(pal) + + def block(p, indent): + out = [f"{indent}@define-color {k} {v};" for k, v in gtk_colors(p).items()] + out += [f"{indent}:root {{", + f"{indent} --accent-bg-color: {p['accent']};", + f"{indent} --accent-fg-color: {p['background']};", + f"{indent} --accent-color: {p['accent']};", + f"{indent}}}"] + return out + + out = [f"/* GTK4 / libadwaita colours: luxnox lux (light) and nox (dark).", + f" {HEADER}", + " libadwaita picks the block for the system color-scheme itself. */", + "", + ":root {", + f" --dim-opacity: {dim}%; /* faded text stays at {MIN:g}:1 */", + " --border-opacity: 30%; /* flat surfaces: borders do the separating */", + "}", + ""] + out += block(pal["lux"], "") + out += ["", "@media (prefers-color-scheme: dark) {"] + out += block(pal["nox"], " ") + out += ["}", "", GTK4_RULES] + return "\n".join(out) + + +def gtk3(mode, p): + base = {"nox": "adw-gtk3-dark", "lux": "adw-gtk3"}[mode] + out = [f"/* GTK3, luxnox {mode}: {base} in luxnox colours.", + f" {HEADER} */", + f'@import url("file:///usr/share/themes/{base}/gtk-3.0/gtk.css");', + ""] + out += [f"@define-color {k} {v};" for k, v in gtk_colors(p).items()] + dim = dim_opacity(PALETTE) / 100 + out += ["", f"""/* Flat surfaces need visible lines. libhandy headerbars draw no border + or shadow, so the line is part of the background. */ +.titlebar headerbar, .titlebar headerbar:backdrop, +headerbar.titlebar, headerbar.titlebar:backdrop {{ + border-width: 0; + background: linear-gradient(to top, {p['border']} 1px, {p['background']} 1px); +}} +separator.sidebar {{ + min-width: 1px; + min-height: 1px; +}} + +/* Unfocused windows keep full-strength text (dwl's border shows focus). */ +headerbar:not(.selection-mode):backdrop, +headerbar:not(.selection-mode) entry:backdrop, +.titlebar:not(.selection-mode):backdrop, +.titlebar:not(.selection-mode) entry:backdrop, +headerbar:not(.selection-mode) button:not(.suggested-action):not(.destructive-action):backdrop, +.titlebar:not(.selection-mode) button:not(.suggested-action):not(.destructive-action):backdrop, +.default-decoration .title:backdrop, +tabbar .box:backdrop {{ + color: {p['foreground']}; +}} + +/* Secondary text faded only as far as {MIN:g}:1. */ +.dim-label, .welcome .dim-label, +headerbar .subtitle, .titlebar:not(headerbar) .subtitle, label.separator {{ + opacity: {dim:.2f}; +}}"""] + return "\n".join(out) + "\n" + + +# --- Qt ---------------------------------------------------------------------- +# qt6ct palettes (Fusion style). luxnox-apply points qt6ct.conf at one; qt6ct +# watches its folder and repaints running apps. + +QT_ROLES = ["WindowText", "Button", "Light", "Midlight", "Dark", "Mid", "Text", + "BrightText", "ButtonText", "Base", "Window", "Shadow", "Highlight", + "HighlightedText", "Link", "LinkVisited", "AlternateBase", "NoRole", + "ToolTipBase", "ToolTipText", "PlaceholderText", "Accent"] + + +def qt(mode, p): + bg, fg = p["background"], p["foreground"] + lux = mode == "lux" + roles = { + "WindowText": fg, "Text": fg, "ButtonText": fg, "ToolTipText": fg, + "Window": bg, "Base": bg, "NoRole": bg, + # Fusion draws buttons and frames from these: a faint surface for + # buttons, border-coloured edges, so the flat look still has lines. + "Button": p["surface"], "Light": bg, + "Midlight": p["hover"], "Dark": p["border"], "Mid": p["border"], + "Shadow": p["dim"] if lux else "#000000", + "BrightText": p["bright_white"] if not lux else p["black"], + "Highlight": p["accent"], "HighlightedText": bg, "Accent": p["accent"], + "Link": p["blue"], "LinkVisited": p["magenta"], + "AlternateBase": p["line"], "ToolTipBase": p["surface"], + "PlaceholderText": p["dim"], + } + def row(over=None): + r = dict(roles, **(over or {})) + return ", ".join("#ff" + r[k][1:] for k in QT_ROLES) + faded = blend(fg, bg, 0.45) + disabled = {"WindowText": faded, "Text": faded, "ButtonText": faded, + "Highlight": p["border"], "HighlightedText": faded} + return (f"# luxnox {mode} for qt6ct. {HEADER}\n" + "# Unfocused windows look the same as focused ones (inactive = active).\n\n" + "[ColorScheme]\n" + f"active_colors={row()}\n" + f"disabled_colors={row(disabled)}\n" + f"inactive_colors={row()}\n") + + +# KDE color scheme, as kdeglobals. Flatpak Qt apps can't load the host's +# qt6ct, but the KDE runtime ships KDE's platform theme, which reads +# ~/.config/kdeglobals (bind-mounted into apps with xdg-config/kdeglobals) and +# repaints when it changes. luxnox-apply writes the mode's copy over it. + +# Widget style Fusion, as with qt6ct: Breeze colors the toolbar and menu bar +# (background and text) from its own copy of kdeglobals, read once at start, +# so they'd keep the mode the app started in. Fusion uses only the palette, +# which follows. For the same reason there's no Header set (only Breeze uses it). +KDE_SETS = ["View", "Window", "Button", "Selection", "Tooltip", "Complementary"] + + +def kdeglobals(mode, p): + bg, fg, acc = p["background"], p["foreground"], p["accent"] + def c(hx): + return ",".join(map(str, rgb(hx))) + def colorset(back, alt, text): + sel = text == bg # text on the accent: everything in the text color + f = (lambda k: text) if sel else (lambda k: p[k]) + tint = lambda k: back if sel else blend(p[k], back, 0.15) + return { + "BackgroundNormal": back, "BackgroundAlternate": alt, + "BackgroundActive": back if sel else p["hover"], + "BackgroundLink": tint("blue"), "BackgroundVisited": tint("magenta"), + "BackgroundNegative": tint("red"), "BackgroundNeutral": tint("yellow"), + "BackgroundPositive": tint("green"), + "ForegroundNormal": text, "ForegroundInactive": f("dim"), + "ForegroundActive": f("accent"), "ForegroundLink": f("blue"), + "ForegroundVisited": f("magenta"), "ForegroundNegative": f("red"), + "ForegroundNeutral": f("yellow"), "ForegroundPositive": f("green"), + "DecorationFocus": acc, "DecorationHover": acc, + } + sets = { + "View": colorset(bg, p["line"], fg), # lists: alternate rows barely there + "Window": colorset(bg, p["surface"], fg), + "Button": colorset(p["surface"], p["hover"], fg), + "Selection": colorset(acc, acc, bg), # inverted, as everywhere + "Tooltip": colorset(p["surface"], p["surface"], fg), + "Complementary": colorset(bg, p["surface"], fg), + } + out = [f"# luxnox {mode} for KDE/Qt (Flatpak apps). {HEADER}", + "# luxnox-apply copies this over ~/.config/kdeglobals.", "", + "[General]", f"ColorScheme=luxnox-{mode}", ""] + for name in KDE_SETS: + out.append(f"[Colors:{name}]") + out += [f"{k}={c(v)}" for k, v in sets[name].items()] + out.append("") + # Disabled text fades to the same mix as the qt6ct palettes (45% fg); + # unfocused windows look the same as focused ones. + out += ["[ColorEffects:Disabled]", "Enable=true", "IntensityEffect=0", + "ColorEffect=0", "ContrastEffect=1", "ContrastAmount=0.55", "", + "[ColorEffects:Inactive]", "Enable=false", "", + "[KDE]", "widgetStyle=Fusion", "", + "[Icons]", f"Theme={'breeze-dark' if mode == 'nox' else 'breeze'}", ""] + return "\n".join(out) + + +# --- Emacs ------------------------------------------------------------------- +# Modus derivatives: Modus Operandi/Vivendi's face mappings (built for 7:1, +# hundreds of packages) with luxnox's palette and semantic choices on top. +# Palette entries not named here keep Modus's own values, which are already +# 7:1 against the same white/black backgrounds. + +def emacs(mode, p): + name = mode + core = {"lux": "modus-themes-operandi-palette", "nox": "modus-themes-vivendi-palette"}[mode] + bgmode = {"lux": "light", "nox": "dark"}[mode] + over = { + "bg-main": p["background"], "fg-main": p["foreground"], + "bg-dim": p["surface"], "fg-dim": p["dim"], "border": p["border"], + "bg-hl-line": p["line"], + "cursor": p["accent"], + # inverted selection + "bg-region": p["foreground"], "fg-region": p["background"], + # mode line: plain, a border line, inactive dimmed + "bg-mode-line-active": p["background"], "fg-mode-line-active": p["foreground"], + "border-mode-line-active": p["border"], + "bg-mode-line-inactive": p["background"], "fg-mode-line-inactive": p["dim"], + "border-mode-line-inactive": p["border"], + "bg-tab-bar": p["surface"], "bg-tab-current": p["background"], "bg-tab-other": p["surface"], + # Org/Markdown blocks: flat, only the faint current-line tint behind code + "bg-prose-block-contents": p["line"], "bg-prose-block-delimiter": p["background"], + } + for hue in ["red", "green", "yellow", "blue", "magenta", "cyan"]: + over[hue] = p[hue] + over[f"{hue}-intense"] = p[f"bright_{hue}"] + # Terminals inside Emacs (vterm, eshell, compilation) get kitty's 16. + for n in ANSI: + for layer in ["fg", "bg"]: + over[f"{layer}-term-{n}"] = p[n] + over[f"{layer}-term-{n}-bright"] = p[f"bright_{n}"] + # Symbols name other palette entries. + sem = { + "keyword": "magenta", "builtin": "yellow", "fnname": "blue", "fnname-call": "blue", + "string": "green", "docstring": "green-faint", "type": "cyan", "constant": "red", + "variable": "fg-main", "variable-use": "fg-main", "comment": "fg-dim", + "fg-link": "blue", "underline-link": "blue", "keybind": "blue", "fg-prompt": "blue", + "err": "red", "warning": "yellow", "info": "green", + "accent-0": "blue", "accent-1": "magenta", "accent-2": "cyan", "accent-3": "red", + "fg-heading-1": "blue", "fg-heading-2": "magenta", "fg-heading-3": "cyan", + "fg-heading-4": "green", "fg-heading-5": "yellow", "fg-heading-6": "red", + "fg-heading-7": "blue-faint", "fg-heading-8": "magenta-faint", + } + rows = [f' ({k} "{v}")' for k, v in over.items()] + [f" ({k} {v})" for k, v in sem.items()] + title = {"lux": "light", "nox": "dark"}[mode] + base = {"lux": "Modus Operandi", "nox": "Modus Vivendi"}[mode] + return f""";;; {name}-theme.el --- luxnox {title}: {base} in luxnox colours -*- lexical-binding: t; -*- + +;; {HEADER} +;; Modus options (bold/italic constructs, headings) apply as for Modus itself. + +;;; Code: + +(require-theme 'modus-themes) + +(defvar {name}-palette-user nil + "Extra palette entries for the `{name}' theme.") + +(defconst {name}-palette-overrides + '( +{chr(10).join(rows)} + ) + "luxnox's colours and mappings over `{core}'.") + +(modus-themes-theme + '{name} + 'luxnox + "luxnox {title}: {base}'s faces in luxnox's high-contrast palette." + '{bgmode} + '{core} + '{name}-palette-user + '{name}-palette-overrides) + +;;; {name}-theme.el ends here +""" + + +def wmenu(p): + # wmenu has no config file; luxnox-menu passes these flags. + def c(k): + return p[k][1:] + return (f"-N {c('background')} -n {c('foreground')} -M {c('accent')} -m {c('background')} " + f"-S {c('accent')} -s {c('background')}\n") + + +def vtrgb(p): + # The Linux console's 16 colors, for setvtrgb(8): three lines (red, green, + # blue) of 16 decimal values in ANSI slot order. The console draws its + # background with slot 0 and its default text with slot 7, so those are + # the palette's background and foreground rather than black and white. + # setvtrgb takes no comments, so the "generated" note is on the unit. + cols = [rgb(p[s]) for s in SLOTS] + cols[0], cols[7] = rgb(p["background"]), rgb(p["foreground"]) + return "".join(",".join(str(c[i]) for c in cols) + "\n" for i in range(3)) + + +DESKTOP = {"fuzzel.ini": fuzzel, "wmenu": wmenu, "wob.ini": wob, "swaync.css": swaync, "swaylock": swaylock} + + +def write(path, text): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text) + print(f"wrote {path.relative_to(ROOT)}") + + +def gen(pal): + for mode in MODES: + p = pal[mode] + write(BUILD / "kitty" / f"{mode}.conf", kitty(mode, p)) + write(BUILD / "kitty" / "luxnox.conf", kitty_options()) + for mode in MODES: + p = pal[mode] + for name, fn in DESKTOP.items(): + write(BUILD / mode / name, fn(p)) + write(BUILD / "dwl" / "luxnox.h", dwl(pal)) + # The text consoles (and tuigreet on them) are always nox: there's no + # light/dark mode before login. + write(BUILD / "console" / "vtrgb", vtrgb(pal["nox"])) + write(BUILD / "gtk" / "gtk-4.0.css", gtk4(pal)) + for mode in MODES: + write(BUILD / "emacs" / f"{mode}-theme.el", emacs(mode, pal[mode])) + write(BUILD / "qt" / f"luxnox-{mode}.conf", qt(mode, pal[mode])) + write(BUILD / mode / "kdeglobals", kdeglobals(mode, pal[mode])) + # GTK3, named like adw-gtk3: "luxnox" is light with a dark variant + # (gtk-dark.css), "luxnox-dark" is dark either way. libhandy apps in dark + # mode strip "-dark" from the theme name and ask for the base theme's dark + # variant, so the base theme must exist and have one. + nox, lux = gtk3("nox", pal["nox"]), gtk3("lux", pal["lux"]) + for name, light, dark in [("luxnox", lux, nox), ("luxnox-dark", nox, nox)]: + write(BUILD / "gtk" / name / "gtk-3.0" / "gtk.css", light) + write(BUILD / "gtk" / name / "gtk-3.0" / "gtk-dark.css", dark) + + +def show(): + E = "\x1b[" + for i, n in enumerate(ANSI): + print(f"{n:8} {E}3{i}mnormal text{E}0m {E}9{i}mbright text{E}0m " + f"{E}1;3{i}mbold{E}0m {E}7;3{i}m reverse {E}0m {E}4{i}m{E}30m on {n} {E}0m") + print(f"\n{E}35mdef{E}0m {E}34mgreet{E}0m(name: {E}36mstr{E}0m): {E}90m# a comment{E}0m") + print(f" {E}35mraise{E}0m {E}33mValueError{E}0m({E}32m\"empty\"{E}0m, {E}31m42{E}0m)") + print(f"{E}31m-removed line{E}0m\n{E}32m+added line{E}0m\n{E}36m@@ -1,3 +1,4 @@{E}0m") + print(f"{E}1;93mwarning{E}0m: unused {E}1;91merror{E}0m: mismatched types " + f"{E}97;41m FAIL {E}0m {E}30;42m PASS {E}0m") + + +PALETTE = {} + + +def main(): + cmd = sys.argv[1] if len(sys.argv) > 1 else "check" + pal = load() + PALETTE.update(pal) + if cmd == "check": + sys.exit(0 if check(pal) else 1) + elif cmd == "show": + show() + elif cmd == "gen": + if not check(pal, quiet=True): + sys.exit("contrast check failed; not generating") + gen(pal) + else: + sys.exit(__doc__) + + +if __name__ == "__main__": + main() |