1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
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()
|