summaryrefslogtreecommitdiff
path: root/core/theme_schema.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 21:16:19 -0300
committerGabriel Schneider <[email protected]>2026-11-25 23:32:17 -0300
commite960fb9a7d837c4e952a98890dc5ddf9c130d195 (patch)
tree5c0be1e8a5a9cfd4637daf9d93b55c9f2bc47f61 /core/theme_schema.zig
parent1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e (diff)
downloadpardes-e960fb9a7d837c4e952a98890dc5ddf9c130d195.tar.gz
pardes-e960fb9a7d837c4e952a98890dc5ddf9c130d195.zip
colors, theme_schema: the colour system's core (the themes programme's L1; DESIGN.md B2-B4, B6, G1', H): a theme says ten colours and the terminal's sixteen in names that say the role (`Theme`: page, text, tag, tag_text, accent, selection, keyword, string, number, comment, ansi, then B3's overrides and G1''s `mode`), and everything a surface draws is worked out from it once a theme change by one function, `Chrome.of` (R0-R16 by halves: `hold` moves an ink's lightness alone, `hued` steps a ground off another in a hue's tint), into one set, `Chrome`: the page's, the two tag grounds' (plain and focus, G1': the mode is a mark on the grip, `grip.mode`, never a ground) and the status row's inks, each held on its own ground (text, H's `word`, dim, rule, key, match, the four severities, a selection rebuilt there); the selection's faint and the three sweeps; hits and the solid current hit; added and deleted rows; lanes and churn; the grips (focus, ring, mode and its glyph, dirty, a column's grabbed and at rest); rules, rail, empty column; syntax, line numbers, names and the sixteen; read by `Pardes.chrome()`; H's tag: the plain tag lifted to a band 1.1:1 off the page (across it where the gamut ends) unless rules of 3:1 part panes (acme), the focused band a focus step off it and louder than it off the page, a mid-grey tag no ink reads on the page a step off, the full ink up to 7:1, command words toward the ground to 4.5:1; no surface reads `Chrome` yet: the L2 lines move them, so no frame moves here; THE SEAM: the theme files and every ThemeFile so far speak the old names (`LegacyTheme`, theme_schema.zig, the old struct verbatim): `fold` folds them as they are (`legacy_themes`) and renames them at comptime (`themes`, `Theme.fromLegacy`: one table of old and new names, the fields now always derived left out, a compile error for a field on either side without its line, so G6's rename stays one table to drop); `Pardes.theme()` hands the surfaces still reading a theme's own fields the old names' view (the ring's own, a ThemeFile's file itself, or a new-names file's view filled from its Chrome, `Theme.toLegacy`), and ChromeTheme, Roles and Grounds keep today's derivations on it, unchanged, beside the new set (`ChromeTheme.resolved`), until each surface moves; `custom_theme` keeps its type, so no dump or digest changes; a ThemeFile is read in the old names when it names `tag_bg` (the user's one_dark_zed_mod.zon, an older DumpThemes'), else in the new; DumpThemes writes the new; `initial_chrome` (comptime) goes: the chrome is resolved at the session's start (finishThemeInitialization, as before, into `theme_chrome`, the field `chrome()` reads it from), and each place that resolves one hands it to the body's cache (Core.bodyChrome), which made its own again at the first frame; B9's budget: the derivations convert to and from OKLab with no pow (`labOf`, `rgbOf`: `to_linear`, and the light where a byte's rounding turns; `toOklab`/`fromOklab` stay the old views' so none of their values moves), one ink's line toward its ground is walked once for its words, dim and rule, a status row that is the plain tag's takes its inks, and the name tint's search (today's, the old view's too) skips by luminance the candidates that cannot read before the bytes round them, and a source hue already tried, its answers the same over the whole ring (compared byte for byte); readings where DESIGN.md is silent or in tension, each in the report: `tag_name` for B3's `name` (the theme's own `name` holds its name), `@"error"`, `hold` wherever B4 says held (the prototype pushes tag, selection and ANSI inks toward white or black), the current hit the hue itself held (R8's words; the prototype held its rejected own ground), each tag ground's full ink its own (B1.3; hring holds one ink on both), a port's `column_grip` held on the page (B3; hring takes the number), the focus step tried lighter on a dark tag first, as the prototype does in effect (H's "away from the page" first would sink lagoon's and forge_soft's focused tags to #0b2722 and #020205), R3's status-bar swap left to the importer (L4: no import flag in a theme), B6's selection triple without key and match, no `filter[256]` (ghostty's, L2d) and no InactiveDim table (L2e); RUN (TEST FIRST): colors.zig "every theme in the ring meets every floor pardes owns ..." (every theme x the designer's checks, A8, with B4's per-ground inks, G1''s mark and H's words, band, loudest focus and column grip: the natives and dark held to the professional floors too; the original's text, syntax, comments, line numbers and sixteen asserted never moved): 261 of 285 pass, and the 24 on its list fail as it says: L3 5 (acme's ANSI 10 and 14; solarized_dark and _light, seoul256_light_254 and _255: a `hit`, `added`/`deleted` of their own), L4 6 (everforest_light, github_dark_dimmed, gruvbox_material_light_hard/_medium/_soft, hex_toxic), L5 1 (dark: its derived ANSI 8 at 3:1, under the pro 4.5), L7 8 (retired), and 4 no line fixes (dusk, lagoon, solarium, forge_soft: soft by design, their text under the pro 7:1: C1's ruling); "the whole ring resolves in 150 ms of CPU, no theme in over 0.5 ms (Debug)": 39 to 44 ms of CPU, the slowest theme 291 to 307 us (seoul256_dark_239, modus_vivendi), each the least of five (under a load of 8.7, before the speedups, it measured twice that: 871 us); "a theme file in the old names, a user's own or an older DumpThemes', and DumpThemes' now in the new names, load to the same Chrome" (one_dark_zed_mod.zon's shape copied into the test); the neonotte84 and acme goldens on Chrome, re-pinned where B4 moves them (text, dim, rule and key as D4's; the match the hits' amber on that ground alone, neonotte84 #e29e47, where D4's pushed #f1a271 over seven grounds at once, acme its number #a05200; the reading mark sky on the grip, #2b92bc and #1e8ab3, where D4 tinted the tag, #29271e, and acme's own #f3f0cc; the hit an amber ground 1.5:1 off the page, #4c301a and #ffc790; the current hit the hue itself, #e29e47 and #a05200, where D4 drew a 1.9:1 ground); the error ink red on the page and both tags; against C1's prototype over the ring's 285 (resolve.py, g1ring.py, hring.py; the R3 status-bar swap aside, L4's): the page's tokens (11,115 values) 84 % the same, 96 % within 2, 2 % over 6, each from a reading above (hold for push: ANSI 1 and 9 in 37 themes; the current hit in 46); with the prototype's own choices put back (an experiment), 17,081 of 20,520 the same and 59 over 6, at floors that a bisection and a 0.005 walk cross on different sides; H's tag grounds against hring.py the same or within 2 in 271 (plain) and 268 (focus) of 285, the others R3's status-bar swap (13, L4's) and monokai_pro_light_sun (its tag its page: lifted darker, hring lighter); G1's mark sky in 225, mint 50, violet 9, paper 1 (C1: 225, 50, 10); no frame moves: core-test 1115/1287 (172 skipped: +3, the ring, timing and loader tests; the two goldens rewritten in place), shell-test 1335/1338 (3 skipped: +3), pane-test 183/184 (1 skipped), behaviour-test 280/280 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 147 failed (3 skipped, no golden moved), term-test 17/17, kitty-test 45/45, the gui unit-test 1938/1942 (4 skipped; its one failure the known BaselineHarnessMismatch); perfops against the installed tree (1e8787e0b2eb, its prefix built here) at 10 % a cell: PASS, 121 counts, the largest `open on small` +3.02 % (5,736,138 to 5,909,480 instructions: each cell boots a session, which now resolves its chrome at start where `initial_chrome` was comptime; +11.3 % before the body's cache took the start's chrome and create stopped resolving one of its own), the boots' setup +0.13 %, every operation within 0.01 %; the dump and the digest unchanged (`custom_theme` keeps its type, `theme_chrome` is local), so no fuzz or soak; load 2.0 to 10.2
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/theme_schema.zig')
-rw-r--r--core/theme_schema.zig284
1 files changed, 284 insertions, 0 deletions
diff --git a/core/theme_schema.zig b/core/theme_schema.zig
new file mode 100644
index 00000000..788cf3bf
--- /dev/null
+++ b/core/theme_schema.zig
@@ -0,0 +1,284 @@
+//! What a theme says (DESIGN.md B2, B3: the themes programme's v2 schema),
+//! and the shape every theme had before it (`LegacyTheme`), with the
+//! mechanical map between the two: the theme files in core/themes and the
+//! generated ones are written in the old names until their own lines move
+//! them, and a ThemeFile written in them (a user's own, DumpThemes' output
+//! of an older build) loads forever. colors.zig derives everything a
+//! surface draws from a `Theme` (colors.Chrome.of).
+const std = @import("std");
+
+/// A theme: ten colours, the syntax four among them, and the terminal's
+/// sixteen (B2), each named for its role; then what a faithful port, acme
+/// or lapis says of its own where the derived one would not be its (B3),
+/// each derived when absent (colors.Chrome.of, rule by rule).
+pub const Theme = struct {
+ name: []const u8,
+ /// The body's ground and ink; null leaves them to the host terminal (a
+ /// window: colors.null_page and #cccccc).
+ page: ?[3]u8,
+ text: ?[3]u8,
+ /// A pane's tag at rest, and its ink.
+ tag: [3]u8,
+ tag_text: [3]u8,
+ /// The theme's one accent: the focused grip, keys, the walked word,
+ /// links, the sam fence.
+ accent: [3]u8,
+ /// The selection's ground (its ink is derived, or `selection_text`).
+ selection: [3]u8,
+ keyword: [3]u8,
+ string: [3]u8,
+ number: [3]u8,
+ comment: [3]u8,
+ /// The terminal's sixteen, and the semantic hues: 1 red (error,
+ /// deleted), 2 green (added), 3 yellow (warning, hits), 4 blue (info), 6
+ /// cyan (hint). Null: derived from the theme's own hues (R14).
+ ansi: ?[16][3]u8,
+
+ // The overrides (B3).
+ selection_text: ?[3]u8 = null,
+ /// The focused tag's ground and ink (R4: else the tag a focus step off).
+ tag_focus: ?[3]u8 = null,
+ tag_focus_text: ?[3]u8 = null,
+ /// The mark on a reading pane's grip (R5', DESIGN.md G1': else sky,
+ /// mint, violet, paper or rose, the first told from the grip's other
+ /// hues, 3:1 on the tags).
+ mode: ?[3]u8 = null,
+ /// A name's tint in a tag (R13: else a hue of the theme's own at the
+ /// tag ink's lightness).
+ tag_name: ?[3]u8 = null,
+ /// The workspace row, an editor's status bar where it has one.
+ workspace: ?[3]u8 = null,
+ workspace_text: ?[3]u8 = null,
+ line_number: ?[3]u8 = null,
+ line_number_current: ?[3]u8 = null,
+ /// A search hit's ground (R8: else the page toward amber).
+ hit: ?[3]u8 = null,
+ /// The severities' inks (R9: else the ANSI red, yellow, blue, cyan).
+ @"error": ?[3]u8 = null,
+ warning: ?[3]u8 = null,
+ info: ?[3]u8 = null,
+ hint: ?[3]u8 = null,
+ /// What a diff adds and deletes (R10: else ANSI 2 and 1).
+ added: ?[3]u8 = null,
+ deleted: ?[3]u8 = null,
+ /// The rules between panes and columns, the scroll column and its
+ /// thumb, what an empty column shows, the rule under a tag (R11).
+ rule: ?[3]u8 = null,
+ rail: ?[3]u8 = null,
+ rail_thumb: ?[3]u8 = null,
+ empty_column: ?[3]u8 = null,
+ tag_rule: ?[3]u8 = null,
+ /// A grip's ring at rest, its fill while its file is unsaved, and a
+ /// column's grip (R6).
+ grip_ring: ?[3]u8 = null,
+ dirty: ?[3]u8 = null,
+ column_grip: ?[3]u8 = null,
+ /// A tag's selection where it is not the body's (acme's #9eeeee), and
+ /// each pointer button's sweep, select, exec and look (R7).
+ tag_selection: ?[3]u8 = null,
+ sweeps: ?[3]Sweep = null,
+ /// A pixel shell's rules and scroll column, in pixels (2 and 12 unset).
+ rule_px: ?u8 = null,
+ rail_px: ?u8 = null,
+
+ pub const Sweep = struct { ground: [3]u8, text: [3]u8 };
+
+ /// A theme in the old names, in the new: each field renamed, the ones
+ /// now always derived (`dropped`) left out, the sweeps' two lists one.
+ pub fn fromLegacy(old: LegacyTheme) Theme {
+ var out: Theme = undefined;
+ inline for (renames) |r| @field(out, r[1]) = @field(old, r[0]);
+ out.sweeps = if (old.sweep_bg) |grounds| sweeps: {
+ var s: [3]Sweep = undefined;
+ for (&s, grounds, 0..) |*sweep, ground, i| sweep.* = .{ .ground = ground, .text = if (old.sweep_fg) |inks| inks[i] else old.sel_fg };
+ break :sweeps s;
+ } else null;
+ out.mode = null;
+ out.added = null;
+ out.deleted = null;
+ return out;
+ }
+
+ /// The old names' view of a theme, for what still reads them: the
+ /// fields the new names leave to the derivation (`derived`) filled in
+ /// from it; `added`, `deleted` and `mode`, which the old names have no
+ /// field for, left out.
+ pub fn toLegacy(th: *const Theme, derived: Derived) LegacyTheme {
+ var out: LegacyTheme = undefined;
+ inline for (renames) |r| {
+ const from = @field(th, r[1]);
+ const same = comptime @FieldType(LegacyTheme, r[0]) == @TypeOf(from);
+ @field(out, r[0]) = if (same) from else from orelse @field(derived, r[0]);
+ }
+ inline for (dropped) |name| @field(out, name) = @field(derived, name);
+ if (th.sweeps) |sweeps| {
+ out.sweep_bg = undefined;
+ out.sweep_fg = undefined;
+ for (sweeps, &out.sweep_bg.?, &out.sweep_fg.?) |s, *ground, *ink| {
+ ground.* = s.ground;
+ ink.* = s.text;
+ }
+ } else {
+ out.sweep_bg = null;
+ out.sweep_fg = null;
+ }
+ return out;
+ }
+
+ /// What `toLegacy` takes from the derivation: the old names' required
+ /// fields the new ones make optional, and the ones they leave out.
+ pub const Derived = struct {
+ sel_fg: [3]u8,
+ lineno: [3]u8,
+ scroll_track: [3]u8,
+ scroll_thumb: [3]u8,
+ box_dim: [3]u8,
+ column_box_dim: ?[3]u8 = null,
+ tag_active_name_fg: ?[3]u8 = null,
+ search_fg: ?[3]u8 = null,
+ tag_reading_bg: ?[3]u8 = null,
+ };
+};
+
+/// Old name, new name: the mechanical layer (DESIGN.md G6). Without the
+/// rename this table, `LegacyTheme` and the two maps go.
+const renames = [_][2][]const u8{
+ .{ "name", "name" },
+ .{ "bg", "page" },
+ .{ "fg", "text" },
+ .{ "tag_bg", "tag" },
+ .{ "tag_fg", "tag_text" },
+ .{ "box", "accent" },
+ .{ "sel_bg", "selection" },
+ .{ "kw", "keyword" },
+ .{ "str", "string" },
+ .{ "num", "number" },
+ .{ "comment", "comment" },
+ .{ "palette", "ansi" },
+ .{ "sel_fg", "selection_text" },
+ .{ "tag_active_bg", "tag_focus" },
+ .{ "tag_active_fg", "tag_focus_text" },
+ .{ "tag_name_fg", "tag_name" },
+ .{ "tagline_bg", "workspace" },
+ .{ "tagline_fg", "workspace_text" },
+ .{ "lineno", "line_number" },
+ .{ "lineno_active", "line_number_current" },
+ .{ "search_bg", "hit" },
+ .{ "diagnostic_error", "error" },
+ .{ "diagnostic_warning", "warning" },
+ .{ "diagnostic_info", "info" },
+ .{ "diagnostic_hint", "hint" },
+ .{ "border", "rule" },
+ .{ "scroll_track", "rail" },
+ .{ "scroll_thumb", "rail_thumb" },
+ .{ "empty_col", "empty_column" },
+ .{ "tag_rule", "tag_rule" },
+ .{ "box_border", "grip_ring" },
+ .{ "box_dirty", "dirty" },
+ .{ "column_box", "column_grip" },
+ .{ "tag_sel_bg", "tag_selection" },
+ .{ "rule_px", "rule_px" },
+ .{ "rail_px", "rail_px" },
+};
+
+/// The old fields the new names derive always (B8), and the reading tag's
+/// ground, which is the tag's now (G1').
+const dropped = [_][]const u8{ "box_dim", "column_box_dim", "tag_active_name_fg", "search_fg", "tag_reading_bg" };
+
+// Every old field is renamed, dropped, or a sweep's; every new one renamed
+// to, the sweeps, or new (`mode`, `added`, `deleted`): a field added to either
+// without its line here is a compile error.
+comptime {
+ @setEvalBranchQuota(20_000);
+ for (@typeInfo(LegacyTheme).@"struct".field_names) |f| {
+ const known = for (renames) |r| {
+ if (std.mem.eql(u8, r[0], f)) break true;
+ } else for (dropped) |d| {
+ if (std.mem.eql(u8, d, f)) break true;
+ } else std.mem.eql(u8, f, "sweep_bg") or std.mem.eql(u8, f, "sweep_fg");
+ if (!known) @compileError("LegacyTheme." ++ f ++ " has no new name");
+ }
+ for (@typeInfo(Theme).@"struct".field_names) |f| {
+ const known = for (renames) |r| {
+ if (std.mem.eql(u8, r[1], f)) break true;
+ } else std.mem.eql(u8, f, "sweeps") or std.mem.eql(u8, f, "mode") or std.mem.eql(u8, f, "added") or std.mem.eql(u8, f, "deleted");
+ if (!known) @compileError("Theme." ++ f ++ " has no old name");
+ }
+}
+
+/// A theme as every theme was written up to 2026-11-25: the files in
+/// core/themes and the generated ones (folded through it at comptime:
+/// colors.fold), and every ThemeFile in it (`.tag_bg` names it).
+pub const LegacyTheme = struct {
+ name: []const u8,
+ bg: ?[3]u8,
+ fg: ?[3]u8,
+ sel_bg: [3]u8,
+ sel_fg: [3]u8,
+ tag_bg: [3]u8,
+ tag_fg: [3]u8,
+ box: [3]u8, // move box, focused pane
+ box_dim: [3]u8, // move box, everything else
+ kw: [3]u8,
+ str: [3]u8,
+ num: [3]u8,
+ comment: [3]u8,
+ lineno: [3]u8,
+ scroll_track: [3]u8,
+ scroll_thumb: [3]u8,
+ palette: ?[16][3]u8,
+
+ // Pardes UI roles. Optional so existing ThemeFile documents and imported
+ // editor palettes keep working; ChromeTheme resolves their legacy defaults.
+ tag_active_bg: ?[3]u8 = null,
+ tag_active_fg: ?[3]u8 = null,
+ /// The workspace row (the tagline): an editor's status bar in its own
+ /// colours, where it has them; else the tag's.
+ tagline_bg: ?[3]u8 = null,
+ tagline_fg: ?[3]u8 = null,
+ /// Filename/output-name accent, also used by the Term command.
+ tag_name_fg: ?[3]u8 = null,
+ /// Active tint; absence preserves the shared name tint or active tag ink.
+ tag_active_name_fg: ?[3]u8 = null,
+ /// Column grips stay distinct from pane grips in both focus states.
+ column_box: ?[3]u8 = null,
+ column_box_dim: ?[3]u8 = null,
+ border: ?[3]u8 = null,
+ /// What an empty column shows under its tag; the border fill without it.
+ empty_col: ?[3]u8 = null,
+ search_bg: ?[3]u8 = null,
+ search_fg: ?[3]u8 = null,
+ diagnostic_error: ?[3]u8 = null,
+ diagnostic_warning: ?[3]u8 = null,
+ diagnostic_info: ?[3]u8 = null,
+ diagnostic_hint: ?[3]u8 = null,
+ // The current line number is a quiet foreground cue, not a tag-colored
+ // background block. Older themes fall back to their normal gutter ink.
+ lineno_active: ?[3]u8 = null,
+ /// A tag's selection, where it differs from the body's (acme's #9eeeee).
+ tag_sel_bg: ?[3]u8 = null,
+ /// The tag of a reading pane, one a jump steps (Trail.zig): unset, or
+ /// too near the tag to see, the tag toward paper yellow (readingOf).
+ tag_reading_bg: ?[3]u8 = null,
+ /// Each pointer button's sweep, select, exec and look (Mouse.Button
+ /// order), and the ink over it. Unset, tints of `sel_bg` in `sel_fg`.
+ sweep_bg: ?[3][3]u8 = null,
+ sweep_fg: ?[3][3]u8 = null,
+ /// A pixel shell's rules, in pixels (2 unset); the rule between a tag
+ /// and its body is always one.
+ rule_px: ?u8 = null,
+ /// A grip is acme's button: `box` filled when focused, else a ring of
+ /// `box_border` (unset: `box_dim`) round the tag's ground; `box_dirty`
+ /// (unset: `diagnostic_warning`, then `num`) fills it, in either ring,
+ /// while its file is unsaved.
+ box_border: ?[3]u8 = null,
+ box_dirty: ?[3]u8 = null,
+ /// The rule between a pane's tag and its body, one pixel, quieter than
+ /// the rules between panes (acme's #8888cc under its 2px black ones).
+ /// Unset, halfway between the tag's ground and the page.
+ tag_rule: ?[3]u8 = null,
+ /// A pixel shell's scroll column, the grip's button over the scrollbar,
+ /// in pixels at a 17px tagline, the thumb one narrower (acme's 12px
+ /// Scrollwid, the default).
+ rail_px: ?u8 = null,
+};