From 0788ce68c4c43148d3d5fa173b4fe46aa10371c9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 03:40:00 -0300 Subject: themes, colors, gen_themes: every theme file in the v2 names, values unchanged (the themes programme's L3; DESIGN.md B2, B3, B8, E1, G4, G6), the fields the new names derive deleted, the comptime fold of the old names gone, each faithful port's file saying each own colour pardes moves to meet a floor, and E1's five fixes: THE FILES: core/themes/*.zig renamed by a script (bg page, fg text, tag_bg tag, tag_fg tag_text, box accent, sel_bg selection, kw keyword, str string, num number, palette ansi, sel_fg selection_text, tag_active_* tag_focus*, tag_name_fg tag_name, tagline_* workspace*, lineno* line_number*, search_bg hit, diagnostic_* the severities, border rule, scroll_* rail*, empty_col empty_column, box_border grip_ring, box_dirty dirty, column_box column_grip, tag_sel_bg tag_selection; seoul256's level rows and their citations too), box_dim, column_box_dim, tag_active_name_fg, search_fg and acme's tag_reading_bg deleted with the lines citing them (B8: always derived; G1': acme's #f3f0cc reading tint goes with the ground), acme's sweep_bg and sweep_fg one `sweeps`; tools/gen_themes.zig writes the generated ones in the same names (its emitted box_dim, the selection again, gone); `colors.fold` folds the files into `Theme` itself (a field no Theme has is a compile error; `as` turns acme's sweep literals into Theme.Sweep, which a literal's own struct type does not coerce to); `legacy_themes`, the ring folded in the old names at comptime, deleted: THE OLD NAMES' VIEW (what draw.zig and the old ChromeTheme and Roles still read until L2a) is a ring theme's chrome's, `ChromeTheme.view`, filled from its Chrome as L1 filled a new-names ThemeFile's (`viewOf`: the old required fields a theme leaves unset, and the derived ones: box_dim a resting grip's fill, the tag's own ground where a theme rings its grips itself (acme's clean button, so its grid grip keeps its look) else the resting ring; tag_active_name_fg `name[1]`, column_box_dim `grip.column_rest`); `Pardes.theme()` reads it (a ThemeFile's, the file itself, as before); ChromeTheme.box, the focused grip the grid fills, is the chrome's `grip.focus` (the accent held 3:1, R6: ayu_light's accent, 2:1 on its tag, was its resting ring too, and the grid drew its focused and resting grips alike); the library's `Theme` and `themes` are the v2 ones (lib_syntax: page, ink and synInk read page, text, keyword, string, number, comment; Grounds.of takes a Theme), runtime/macos.zig's bare page reads `themes[0].page`; E1's FIXES (the ring test's L3 list): acme's sixteen each 4.5:1 on its page, the native floor (6, 8 and 13 held darker in their hue; 10, 11 and 14, held there, landed on their normal colour and go 0.06 OKLab darker than it, R14's bright on a light page: #038384 #757575 #016e08 #785300 #b942b9 #017070); solarized_dark's, solarized_light's and seoul256's light levels' search hit their own hue as a ground the text reads on (#1d180e, #ffeb99, #a6e6fe; each file says from what and why); R8 takes a theme's own hit at R0's visible alternative, 1.1:1 off the page with 0.08 OKLab, only where its text leaves no room for 1.5:1 (no ground that far off keeps the text its floor: those four and forge_soft and ayu_light, whose own hits are taken now where an amber stood; no other theme's hit moves), else E1's `hit` fixes could not be met; G4: core/themes' ports say, under "Moved by pardes as it loads", each own colour Chrome.of moves (focused tag and grip, the resting and unsaved grip, the selection and its ink, the hit, the four severities on the page; 267 lines over 54 files, written from the test's own output by .scratch/themes/L3457/tools/g4_headers.py); RUN (TEST FIRST): colors.zig "every faithful port's file says each of its own colours pardes moves to meet a floor (DESIGN.md G4)" (each port's own value Chrome.of moves, as `role #own -> #got`, found in its file): fails on the renamed files with 273 unsaid, passes now; "every theme in the ring meets every floor ..." with L3's five taken off its list: acme fails ansi and ansi_pro, solarized_dark, solarized_light, seoul256_light_254 and _255 fail hit, all five pass now: 266 of 285 themes pass (261 at L1), 19 on the list (L4 6, L5 1, L7 8, soft 4); draw.zig's "an unfocused reading pane's box in the grid is its ring round the reading tint where the box's fill is the tag's own ground (acme's)" failed on the first view (acme's resting fill its ring), passes with the tag's ground; "a grip's four states ... are each its own" failed in ayu_light on the raw accent, passes on grip.focus; the old tests that pinned the deleted fields' file values keep what is still a file's (a name's tint at its tag ink's lightness, the accent off the column grip; the helix document test strips the derived fields too; the names test reads Chrome's names, an ink held to white or black its own name, ao's and modus_vivendi's); the consumer's lib.zig pins orchard's page, ink and syntax unchanged (dark's page its `.tag`); the ring's values unchanged by the rename (the ring test's count and every original's colour asserted unmoved); core-test 1133/1306 (173 skipped: L2b's 1132/1305 + the G4 test); OUTSIDE my files: core/Core.zig `theme()` (the view), core/lib_syntax.zig (v2 Theme), runtime/macos.zig `pardes_theme_bg` (one line), test/consumer/lib.zig (`.tag`); the process goldens move with the view (the grid's resting grip, the focused name's tint, the column grip at rest, acme's reading grip) and are re-recorded and read at the programme's end gate; no dump or digest change (the view is the chrome's, a `local` field) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- tools/gen_themes.zig | 146 +++++++++++++++++++++++++-------------------------- 1 file changed, 71 insertions(+), 75 deletions(-) (limited to 'tools') diff --git a/tools/gen_themes.zig b/tools/gen_themes.zig index b9a9adb0..fd152aa6 100644 --- a/tools/gen_themes.zig +++ b/tools/gen_themes.zig @@ -57,26 +57,25 @@ const Rgb = [3]u8; /// code) — core/colors.zig's `fold` is what turns it into a real Theme. const Theme = struct { name: []const u8, - bg: ?Rgb, - fg: ?Rgb, - sel_bg: Rgb, - sel_fg: Rgb, - tag_bg: Rgb, - tag_fg: Rgb, - box: Rgb, - box_dim: Rgb, - kw: Rgb, - str: Rgb, - num: Rgb, + page: ?Rgb, + text: ?Rgb, + selection: Rgb, + selection_text: Rgb, + tag: Rgb, + tag_text: Rgb, + accent: Rgb, + keyword: Rgb, + string: Rgb, + number: Rgb, comment: Rgb, - lineno: Rgb, - scroll_track: Rgb, - scroll_thumb: Rgb, - /// A message's error ink (colors.Roles.err): diagnostic.error's, else - /// error's, else the theme's red (UX E3: neonotte's diagnostic.error is - /// an underline only). - diagnostic_error: ?Rgb = null, - palette: ?[16]Rgb, + line_number: Rgb, + rail: Rgb, + rail_thumb: Rgb, + /// A message's error ink (colors.Chrome's severities): diagnostic.error's, + /// else error's, else the theme's red (UX E3: neonotte's diagnostic.error + /// is an underline only). + @"error": ?Rgb = null, + ansi: ?[16]Rgb, }; pub fn main(init: std.process.Init) !void { @@ -142,22 +141,22 @@ fn emit(w: *std.Io.Writer, t: Theme) !void { const info = @typeInfo(Theme).@"struct"; inline for (info.field_names, info.field_types) |name, T| { if (comptime std.mem.eql(u8, name, "name")) continue; - if (comptime std.mem.eql(u8, name, "palette")) continue; - try w.print(" .{s} = ", .{name}); + if (comptime std.mem.eql(u8, name, "ansi")) continue; + try w.print(" .{f} = ", .{std.zig.fmtId(name)}); if (comptime @typeInfo(T) == .optional) { if (@field(t, name)) |c| try rgb(w, c) else try w.writeAll("null"); } else try rgb(w, @field(t, name)); try w.writeAll(",\n"); } - if (t.palette) |p| { - try w.writeAll(" .palette = .{\n"); + if (t.ansi) |p| { + try w.writeAll(" .ansi = .{\n"); for (p) |c| { try w.writeAll(" "); try rgb(w, c); try w.writeAll(",\n"); } try w.writeAll(" },\n"); - } else try w.writeAll(" .palette = null,\n"); + } else try w.writeAll(" .ansi = null,\n"); try w.writeAll("};\n"); } @@ -270,37 +269,36 @@ fn resolve(arena: std.mem.Allocator, tomls: *const std.StringHashMapUnmanaged(To return .{ .path = t.path, .keys = keys, .palette = palette }; } -/// A resolved helix theme mapped onto pardes's fourteen fields. +/// A resolved helix theme mapped onto pardes's fields (core/theme_schema.zig). /// /// EVERY FALLBACK HERE IS HELIX'S OWN RULE, which is why none of them is fatal: /// an unstyled scope wears `ui.text`, an unpainted cell wears `ui.background`, /// and a theme that styles neither is saying "wear whatever the terminal is /// already wearing" (the base16/term16/transparent themes exist precisely to do -/// that). pardes spells that last step as a null bg/fg, so those two pass -/// straight through — but the other twelve fields are RGB and cannot be null, so +/// that). pardes spells that last step as a null page/text, so those two pass +/// straight through — but the other fields are RGB and cannot be null, so /// they need a concrete stand-in for "the terminal's", and that is the default /// palette's ink and page below. Field by field: /// -/// bg ui.background.bg, else null = the host terminal's own cell -/// fg ui.text.fg, else null = ditto -/// box ui.cursor.primary.bg, else ui.cursor.bg, else keyword.fg, +/// page ui.background.bg, else null = the host terminal's own cell +/// text ui.text.fg, else null = ditto +/// accent ui.cursor.primary.bg, else ui.cursor.bg, else keyword.fg, /// else ink — skipping any of them that IS the page (see /// firstNotPage) -/// box_dim, -/// scroll_thumb, -/// sel_bg ui.selection.bg, else ui.selection.primary.bg, else +/// rail_thumb, +/// selection ui.selection.bg, else ui.selection.primary.bg, else /// ui.selection.fg, same page-skipping, else page. No selection /// colour anywhere means the author drew no selection either, -/// and a dim box the colour of the page is the honest rendering -/// of that — no theme in the vendored set actually gets there -/// sel_fg ui.selection.fg, unless that IS sel_bg, else whichever of -/// ink and page the highlight is farther from -/// tag_bg, -/// scroll_track ui.statusline.bg, else page -/// tag_fg ui.statusline.fg, else ink -/// kw/str/comment their scope's fg, else ink (helix: unstyled = ui.text) -/// num constant.numeric.fg, else constant.fg, else ink -/// lineno ui.linenr.fg, else ink +/// and a selection the colour of the page is the honest +/// rendering of that — no theme in the vendored set gets there +/// selection_text ui.selection.fg, unless that IS the selection, else +/// whichever of ink and page the highlight is farther from +/// tag, +/// rail ui.statusline.bg, else page +/// tag_text ui.statusline.fg, else ink +/// keyword/string/comment their scope's fg, else ink (helix: unstyled = ui.text) +/// number constant.numeric.fg, else constant.fg, else ink +/// line_number ui.linenr.fg, else ink fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme { const fg = h.get("ui.text", .fg); const bg = h.get("ui.background", .bg); @@ -345,28 +343,27 @@ fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme { .name = try slug(arena, stem), // `palette` stays null: helix leaves the colors a PROGRAM emits alone, // and so do we. - .bg = bg, - .fg = fg, - .sel_bg = sel, - .sel_fg = if (named_ink) |c| (if (std.mem.eql(u8, &c, &sel)) sel_far else c) else sel_far, - .tag_bg = h.get("ui.statusline", .bg) orelse page, - .tag_fg = h.get("ui.statusline", .fg) orelse ink, - .box = box, - .box_dim = sel, - .kw = h.get("keyword", .fg) orelse ink, - .str = h.get("string", .fg) orelse ink, + .page = bg, + .text = fg, + .selection = sel, + .selection_text = if (named_ink) |c| (if (std.mem.eql(u8, &c, &sel)) sel_far else c) else sel_far, + .tag = h.get("ui.statusline", .bg) orelse page, + .tag_text = h.get("ui.statusline", .fg) orelse ink, + .accent = box, + .keyword = h.get("keyword", .fg) orelse ink, + .string = h.get("string", .fg) orelse ink, // most themes only colour `constant`; the ones that split out numbers // are being more specific, so they win - .num = h.first(&.{ .{ "constant.numeric", .fg }, .{ "constant", .fg } }) orelse ink, + .number = h.first(&.{ .{ "constant.numeric", .fg }, .{ "constant", .fg } }) orelse ink, .comment = h.get("comment", .fg) orelse ink, - .lineno = h.get("ui.linenr", .fg) orelse ink, + .line_number = h.get("ui.linenr", .fg) orelse ink, // the scrollbar is chrome, so it takes the chrome colors: the tag bar's // own background for the track, the selection (one step brighter than // anything else in the theme's greys) for the thumb riding it - .scroll_track = h.get("ui.statusline", .bg) orelse page, - .scroll_thumb = sel, - .diagnostic_error = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.color("red"), - .palette = null, + .rail = h.get("ui.statusline", .bg) orelse page, + .rail_thumb = sel, + .@"error" = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.color("red"), + .ansi = null, }; } @@ -555,8 +552,8 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t // name rather than a suffix that appears only on the eight that // happen to clash today .name = try std.fmt.allocPrint(arena, "{s}_zed", .{try slug(arena, (v.get("name") orelse std.process.fatal("{s}: a variant has no `name`", .{path})).string)}), - .bg = z.need("editor.background"), - .fg = z.need("editor.foreground"), + .page = z.need("editor.background"), + .text = z.need("editor.foreground"), // zed's TEXT selection is `players[0].selection`, and it is a 24% // alpha over the page — the colour on screen is the composite, not // the value. pardes paints opaque cells and `hex` drops alpha, so @@ -565,24 +562,23 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t // selected" fill, which is the question actually being asked. The // ink then stays the editor's own text colour, because that fill is // always a step off the background and never off the text. - .sel_bg = z.need("element.selected"), - .sel_fg = z.need("editor.foreground"), - .tag_bg = z.need("status_bar.background"), - .tag_fg = z.need("text.muted"), + .selection = z.need("element.selected"), + .selection_text = z.need("editor.foreground"), + .tag = z.need("status_bar.background"), + .tag_text = z.need("text.muted"), // zed names its accent, so the move box does not have to be guessed // out of the cursor the way it is for a helix theme - .box = z.need("text.accent"), - .box_dim = z.need("border"), - .kw = z.syn(syntax, "keyword"), - .str = z.syn(syntax, "string"), - .num = z.syn(syntax, "number"), + .accent = z.need("text.accent"), + .keyword = z.syn(syntax, "keyword"), + .string = z.syn(syntax, "string"), + .number = z.syn(syntax, "number"), .comment = z.syn(syntax, "comment"), - .lineno = z.need("editor.line_number"), - .scroll_track = z.need("scrollbar.thumb.border"), - .scroll_thumb = z.need("scrollbar.thumb.background"), + .line_number = z.need("editor.line_number"), + .rail = z.need("scrollbar.thumb.border"), + .rail_thumb = z.need("scrollbar.thumb.background"), // its status colour, else the palette's red (colors.zig) - .diagnostic_error = if (z.style.get("error") != null) z.need("error") else null, - .palette = pal, + .@"error" = if (z.style.get("error") != null) z.need("error") else null, + .ansi = pal, }); } } -- cgit v1.3 From 47952d7797b25f41a3e29ec0dc349564c0185fd4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 04:30:06 -0300 Subject: gen_themes: the importer reads what the helix and zed sources already say (the themes programme's L4; DESIGN.md B7, R3, E1): HELIX: the text the theme draws code in, `variable` where it is a neutral ink (OKLab chroma under 0.04) that reads 4.5:1 on the page, else `ui.text` (github's muted #8b949e gives way to its #c9d1d9; github_dark_dimmed's 3.9:1 to 7.6:1); the tag the inactive status bar where the theme has one, the active one its focused tag where it is tone on tone, the tag's ink the status bar's (an inactive bar's is often faded, neonotte's #555973); the four severities from `diagnostic.*` (often an underline only, no fg) and the plain `error`/`warning`/`info`/`hint` scopes, error else the theme's own palette red (UX E3), never the terminal's guessed one; `added`/`deleted` from `diff.plus`/`diff.minus` where they are a green and a red (each a hue, within 60 degrees: a grey, a yellow deleted or a tritan blue cannot be told apart as R10's rows: ashen, wolf_alabaster's four, zenburn, github_light_tritanopia and modus_operandi_tritanopia failed the ring's diff check on them, and keep pardes's); the caret's line number from `ui.linenr.selected`; a program's sixteen from the theme's own palette where it names red, green, yellow, blue, magenta (or purple) and cyan (or aqua), their light or bright ones, black, white and a grey (else the page, the ink, the comment), else null for R14; ZED: the active tab the focused tag, error/warning/info/hint, created/deleted (the same green-and-red rule), the search match as drawn (its alpha over the editor's page, not dropped), the active line number; R3, THE IMPORT RULE (L1 left it to the importer: a theme carries no import flag): a status bar on the other side of light from its page is no tag: the tag is the page a 1.15:1 step off in its own hue (its light scaled), in the text; E1's import FIXES, a table in the generator (a name no vendored theme has is a build error): everforest_light's and hex_toxic's search hit, their own yellow as a ground their soft text reads on (#ffe699 1.14:1 off the page, the text 4.53:1; #2f3200 1.11:1, 4.27:1; R8 takes it at R0's 1.1:1 with 0.08 OKLab, L3); the generator does the little colour maths it needs (luminance, contrast, OKLab a/b, the step), the dependency-free host tool it was; across the 203 imports: 202 errors, 202 warnings, 196 infos, 198 hints, 178 added/deleted pairs, 195 caret line numbers, 59 focused tags, 13 hits of their own; RUN (TEST FIRST): tools/gen_themes.zig's own tests, a minimal toml or json each, now in core-test (build/tests.zig, on the host): "B7: the text is helix's `variable` ...", "B7: the tag is the inactive status bar, and the active one its focus where it is tone on tone", "R3, the import rule: ...", "B7: the severities from diagnostic.* and the plain scopes ...", "B7: added and deleted from diff.plus and diff.minus ... (a yellow deleted, a grey added: none)", "B7: a program's sixteen from the palette ...", "B7, zed: ... a search match as drawn over the page": on L3's generator none compiles (no field for any of them); the ring test with L4's six taken off its list: everforest_light and hex_toxic fail hit, github_dark_dimmed text, gruvbox_material_light_hard/_medium/_soft severities4; with the mapping the diff rows of the eight above failed until the green-and-red rule: 272 of 285 themes pass (266 at L3), 13 on the list (L5 1, L7 8, soft 4); colors.zig's neonotte84 golden re-pinned where B7 moves it: its match ink and current hit, the hits' amber, #e29e47 (the warning pardes derived) to #e59d3c (its own palette's yellow now its warning); core-test 1140/1313 (173 skipped: L3's 1133/1306 + the importer's 7; the full run's one failure the neonotte84 golden, re-pinned after it, its test alone passing); OUTSIDE my files: build/tests.zig (the importer's tests in core-test, 5 lines); no dump or digest change Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- build/tests.zig | 5 + core/colors.zig | 13 +- tools/gen_themes.zig | 363 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 361 insertions(+), 20 deletions(-) (limited to 'tools') diff --git a/build/tests.zig b/build/tests.zig index 8cf42acd..c35857f7 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -76,6 +76,11 @@ pub fn add(b: *std.Build, c: struct { core_test_step.dependOn(&run_core_test.step); if (core_match) |check| check.addArtifactArg(core_test); } + // The theme importer's own tests (tools/gen_themes.zig): its mapping, + // rule by rule, on the machine that builds. + const gen_themes_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("tools/gen_themes.zig"), .target = b.graph.host, .optimize = .debug }), .filters = c.test_filters }); + core_test_step.dependOn(&b.addRunArtifact(gen_themes_test).step); + if (core_match) |check| check.addArtifactArg(gen_themes_test); // The terminal module's own tests (core/term/): the emulator without a core. const run_term_test = units.add(b, b.addTest(.{ .root_module = c.parts.term, .filters = c.test_filters }), null); b.step("term-test", "run the terminal module's own tests (core/term/)").dependOn(&run_term_test.step); diff --git a/core/colors.zig b/core/colors.zig index ed82b731..b089a1b9 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -2384,12 +2384,14 @@ test "neonotte84's and acme's inks on the plain tag, their reading mark and thei const wants = [_]Want{ // Text, dim, rule and key as D4 derived them; the match the hits' // amber held on this ground alone (D4's pushed neonotte84's number - // over all seven grounds at once: #f1a271); the reading mark sky + // over all seven grounds at once: #f1a271; L1's #e29e47 the warning + // pardes derived, its own palette's since B7, #e59d3c, the current + // hit's too); the reading mark sky // on the grip, 3:1 on both tags (D4 tinted the whole tag #29271e); // the hit an amber ground 1.5:1 off the page (D4's mixed the // number in: #47322e) and the current one that amber itself, solid // (D4's a 1.9:1 ground, #5f3f33). - .{ .name = "neonotte84", .text = .{ 0xb5, 0xbf, 0xe3 }, .dim = .{ 0x70, 0x76, 0x8f }, .rule = .{ 0x4c, 0x50, 0x63 }, .key = .{ 0xf8, 0xde, 0xd9 }, .match = .{ 0xe2, 0x9e, 0x47 }, .mode = .{ 0x2b, 0x92, 0xbc }, .hit = .{ 0x4c, 0x30, 0x1a }, .hit_current = .{ 0xe2, 0x9e, 0x47 } }, + .{ .name = "neonotte84", .text = .{ 0xb5, 0xbf, 0xe3 }, .dim = .{ 0x70, 0x76, 0x8f }, .rule = .{ 0x4c, 0x50, 0x63 }, .key = .{ 0xf8, 0xde, 0xd9 }, .match = .{ 0xe5, 0x9d, 0x3c }, .mode = .{ 0x2b, 0x92, 0xbc }, .hit = .{ 0x4c, 0x30, 0x1a }, .hit_current = .{ 0xe5, 0x9d, 0x3c } }, // acme's key and match on its plain tag alone, never held to its // #9eeeee selection and its reading ground at once (D4's #555583, // #8f4800): its #8888cc darkened to 4.5:1, its number as it is; the @@ -2604,13 +2606,6 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { /// them lands (DESIGN.md E1, F): the list shrinks as each does, and a theme /// on it that passes fails the test, so it is taken off. const ring_expected = [_]struct { []const u8, []const u8 }{ - // L4 (tools/gen_themes.zig): B7's mapping, or an import's override. - .{ "everforest_light", "L4: `hit` of its own" }, - .{ "github_dark_dimmed", "L4: its text from helix's `variable`" }, - .{ "gruvbox_material_light_hard", "L4: `info`/`hint` from its own scopes" }, - .{ "gruvbox_material_light_medium", "L4: `info`/`hint` from its own scopes" }, - .{ "gruvbox_material_light_soft", "L4: `info`/`hint` from its own scopes" }, - .{ "hex_toxic", "L4: `hit` and `added`/`deleted` of its own" }, // L5: dark's own sixteen (its derived ANSI 8 is 3:1, under the pro 4.5). .{ "dark", "L5: its designed ANSI (DESIGN.md C)" }, // L7: retired. diff --git a/tools/gen_themes.zig b/tools/gen_themes.zig index fd152aa6..c369b744 100644 --- a/tools/gen_themes.zig +++ b/tools/gen_themes.zig @@ -71,10 +71,22 @@ const Theme = struct { line_number: Rgb, rail: Rgb, rail_thumb: Rgb, - /// A message's error ink (colors.Chrome's severities): diagnostic.error's, - /// else error's, else the theme's red (UX E3: neonotte's diagnostic.error - /// is an underline only). + /// B7: what the sources say beyond the ten (core/theme_schema.zig's + /// overrides): the focused tag, the severities, a diff's hues, the hits, + /// the caret's line number. Null: derived (colors.Chrome.of). + tag_focus: ?Rgb = null, + tag_focus_text: ?Rgb = null, + /// A message's error ink: diagnostic.error's, else error's, else the + /// theme's own red (UX E3: neonotte's diagnostic.error is an underline + /// only). @"error": ?Rgb = null, + warning: ?Rgb = null, + info: ?Rgb = null, + hint: ?Rgb = null, + added: ?Rgb = null, + deleted: ?Rgb = null, + hit: ?Rgb = null, + line_number_current: ?Rgb = null, ansi: ?[16]Rgb, }; @@ -104,6 +116,13 @@ pub fn main(init: std.process.Init) !void { } } for (stems.items) |stem| try themes.append(arena, try helixTheme(arena, stem, resolve(arena, &tomls, stem, 8))); + for (themes.items) |*t| toneOnTone(t); + for (fixes) |f| { + const t = for (themes.items) |*t| { + if (std.mem.eql(u8, t.name, f.name)) break t; + } else std.process.fatal("tools/gen_themes.zig fixes {s}, which no vendored theme is", .{f.name}); + t.hit = f.hit; + } // sorted, so the ring's tail is the same on every machine whatever order // the directory happened to be read in std.mem.sort(Theme, themes.items, {}, byName); @@ -304,6 +323,12 @@ fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme { const bg = h.get("ui.background", .bg); const ink = fg orelse ansi_default[7]; const page = bg orelse ansi_default[0]; + // B7: the text is what the theme draws code in. Many set `ui.text` to a + // muted UI grey and code in `variable` (github's #8b949e and #c9d1d9): + // `variable` where it is a neutral ink that reads 4.5:1 on the page; a + // coloured one (base16's red) is an identifier's hue, not the text. + const text = if (h.get("variable", .fg)) |v| (if (chroma(v) < 0.04 and contrast(v, page) >= 4.5) v else fg) else fg; + const body = text orelse ink; // The move box is the accent that says "here". helix's is the primary // cursor's background — but a theme that draws its cursor by REVERSING // video (nord, monokai) never names one, so the fallback is the loudest @@ -333,22 +358,30 @@ fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme { const sel_lum = @as(i32, sel[0]) * 3 + @as(i32, sel[1]) * 6 + sel[2]; const ink_lum = @as(i32, ink[0]) * 3 + @as(i32, ink[1]) * 6 + ink[2]; const page_lum = @as(i32, page[0]) * 3 + @as(i32, page[1]) * 6 + page[2]; - const sel_far = if (@abs(sel_lum - ink_lum) >= @abs(sel_lum - page_lum)) ink else page; + const sel_far = if (@abs(sel_lum - ink_lum) >= @abs(sel_lum - page_lum)) body else page; // A theme that DID name a selection foreground meant it — 16 of the // vendored ones do — except when it is the colour taken for the background // one line up, which is the reverse-video case again: those two would paint // the highlight in one colour on itself. const named_ink = h.get("ui.selection", .fg); + // B7: the tag is the inactive status bar where the theme has one (107 + // do), and the active one its focused tag where it is tone on tone. + const inactive = h.get("ui.statusline.inactive", .bg); + const tag = inactive orelse h.get("ui.statusline", .bg) orelse page; + const active = if (inactive != null) h.get("ui.statusline", .bg) else null; + const focused = if (active) |a| !std.mem.eql(u8, &a, &tag) and dark(a) == dark(tag) else false; return .{ .name = try slug(arena, stem), - // `palette` stays null: helix leaves the colors a PROGRAM emits alone, - // and so do we. .page = bg, - .text = fg, + .text = text, .selection = sel, .selection_text = if (named_ink) |c| (if (std.mem.eql(u8, &c, &sel)) sel_far else c) else sel_far, - .tag = h.get("ui.statusline", .bg) orelse page, + .tag = tag, + // the status bar's ink (an inactive bar's is often a faded one, + // neonotte's #555973, where pardes's tag holds words to run) .tag_text = h.get("ui.statusline", .fg) orelse ink, + .tag_focus = if (focused) active else null, + .tag_focus_text = if (focused) h.get("ui.statusline", .fg) else null, .accent = box, .keyword = h.get("keyword", .fg) orelse ink, .string = h.get("string", .fg) orelse ink, @@ -362,11 +395,47 @@ fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme { // anything else in the theme's greys) for the thumb riding it .rail = h.get("ui.statusline", .bg) orelse page, .rail_thumb = sel, - .@"error" = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.color("red"), - .ansi = null, + // B7: the severities from diagnostic.* (often an underline only, + // which names no fg) and the plain scopes; error, else the theme's + // own red (UX E3) + .@"error" = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.named(&.{"red"}), + .warning = h.first(&.{ .{ "diagnostic.warning", .fg }, .{ "warning", .fg } }), + .info = h.first(&.{ .{ "diagnostic.info", .fg }, .{ "info", .fg } }), + .hint = h.first(&.{ .{ "diagnostic.hint", .fg }, .{ "hint", .fg } }), + .added = diffPair(h.get("diff.plus", .fg), h.get("diff.minus", .fg))[0], + .deleted = diffPair(h.get("diff.plus", .fg), h.get("diff.minus", .fg))[1], + .line_number_current = h.get("ui.linenr.selected", .fg), + // B7: a program's sixteen from the theme's own palette where it names + // the six hues; else pardes derives them from its colours (R14) + .ansi = h.sixteen(page, ink, h.get("comment", .fg) orelse ink), }; } +/// DESIGN.md E1's fixes for an import: a colour of its own its source does +/// not name, where the one pardes derives cannot meet a floor. +const fixes = [_]struct { name: []const u8, hit: Rgb }{ + // Its text reads 5.18:1 on its page: no ground 1.5:1 off leaves it its + // 4.5:1, and the derived amber stops short: its yellow (#dfa000) as a + // ground 1.14:1 off the page, 0.09 OKLab, the text 4.53:1 on it (R0, R8). + .{ .name = "everforest_light", .hit = .{ 0xff, 0xe6, 0x99 } }, + // Its text 4.73:1: its toxic yellow (#c9d400) a ground 1.11:1 off the + // page, 0.09 OKLab, the text 4.27:1 on it, its floor (R0, R8). + .{ .name = "hex_toxic", .hit = .{ 0x2f, 0x32, 0x00 } }, +}; + +/// R3, the import rule: a status bar on the other side of light from the +/// page (merionette's red one on a dark page) is no tag: the tag is the page +/// a 1.15 step off in its own hue, in the text (tone on tone). +fn toneOnTone(t: *Theme) void { + const page = t.page orelse ansi_default[0]; + if (dark(t.tag) == dark(page)) return; + t.tag = stepOff(page, 1.15); + t.tag_text = t.text orelse ansi_default[7]; + t.tag_focus = null; + t.tag_focus_text = null; + t.rail = t.tag; +} + /// helix lets a theme name one of the terminal's sixteen colors instead of an /// RGB (`fg = "light-gray"`), and four of them — base16_terminal, term16_dark, /// term16_light, ttox — are written that way from top to bottom. pardes's Theme @@ -412,6 +481,38 @@ const Helix = struct { return null; } + /// The first of `names` the theme's own [palette] has (never the + /// terminal's sixteen it falls back to: those are a guess). + fn named(h: Helix, names: []const []const u8) ?Rgb { + for (names) |n| if (h.palette.contains(n)) return h.color(n); + return null; + } + + /// B7: a program's sixteen from the palette's own red, green, yellow, + /// blue, magenta (or purple) and cyan (or aqua), their light or bright + /// ones (else the same), black (else the page), white (else the ink) and + /// a grey (else the comment); null unless all six hues are named. + fn sixteen(h: Helix, page: Rgb, ink: Rgb, comment: Rgb) ?[16]Rgb { + const hues = [6][2][]const u8{ .{ "red", "red" }, .{ "green", "green" }, .{ "yellow", "yellow" }, .{ "blue", "blue" }, .{ "magenta", "purple" }, .{ "cyan", "aqua" } }; + var out: [16]Rgb = undefined; + var buf: [4][32]u8 = undefined; + for (hues, 1..) |pair, i| { + const n = if (h.palette.contains(pair[0])) pair[0] else pair[1]; + out[i] = h.named(&.{n}) orelse return null; + out[i + 8] = h.named(&.{ + std.fmt.bufPrint(&buf[0], "light-{s}", .{n}) catch unreachable, + std.fmt.bufPrint(&buf[1], "bright-{s}", .{n}) catch unreachable, + std.fmt.bufPrint(&buf[2], "light_{s}", .{n}) catch unreachable, + std.fmt.bufPrint(&buf[3], "bright_{s}", .{n}) catch unreachable, + }) orelse out[i]; + } + out[0] = h.named(&.{"black"}) orelse page; + out[7] = h.named(&.{ "white", "light-gray", "light_gray" }) orelse ink; + out[8] = h.named(&.{ "gray", "grey", "bright-black", "bright_black" }) orelse comment; + out[15] = h.named(&.{ "bright-white", "bright_white", "light-white" }) orelse out[7]; + return out; + } + /// `first`, skipping any candidate that comes out equal to the page. A /// cursor or a selection painted in the page's own colour is a theme /// drawing that highlight by REVERSING video (it names the cell it is about @@ -564,8 +665,10 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t // always a step off the background and never off the text. .selection = z.need("element.selected"), .selection_text = z.need("editor.foreground"), + // B7: the status bar the tag, the active tab its focus .tag = z.need("status_bar.background"), .tag_text = z.need("text.muted"), + .tag_focus = z.get("tab.active_background"), // zed names its accent, so the move box does not have to be guessed // out of the cursor the way it is for a helix theme .accent = z.need("text.accent"), @@ -577,7 +680,15 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t .rail = z.need("scrollbar.thumb.border"), .rail_thumb = z.need("scrollbar.thumb.background"), // its status colour, else the palette's red (colors.zig) - .@"error" = if (z.style.get("error") != null) z.need("error") else null, + .@"error" = z.get("error"), + .warning = z.get("warning"), + .info = z.get("info"), + .hint = z.get("hint"), + .added = diffPair(z.get("created"), z.get("deleted"))[0], + .deleted = diffPair(z.get("created"), z.get("deleted"))[1], + // a search match is a translucent wash over the page: as drawn + .hit = z.over("search.match_background", z.need("editor.background")), + .line_number_current = z.get("editor.active_line_number"), .ansi = pal, }); } @@ -590,6 +701,24 @@ const Zed = struct { path: []const u8, style: std.json.ObjectMap, + fn get(z: Zed, key: []const u8) ?Rgb { + return if (z.style.get(key) != null) z.need(key) else null; + } + + /// A colour with an alpha (`#rrggbbaa`) as it shows over `ground`. + fn over(z: Zed, key: []const u8, ground: Rgb) ?Rgb { + const s = switch (z.style.get(key) orelse return null) { + .string => |s| s, + else => std.process.fatal("{s}: style.{s} is not a color string", .{ z.path, key }), + }; + const c = hex(z.path, s); + const d = if (s.len > 0 and s[0] == '#') s[1..] else s; + const alpha: f32 = if (d.len == 8) @as(f32, @floatFromInt(std.fmt.parseInt(u8, d[6..8], 16) catch std.process.fatal("{s}: \"{s}\" is not #rrggbbaa", .{ z.path, s }))) / 255 else 1; + var out: Rgb = undefined; + for (&out, c, ground) |*o, x, g| o.* = @intFromFloat(@round(@as(f32, @floatFromInt(x)) * alpha + @as(f32, @floatFromInt(g)) * (1 - alpha))); + return out; + } + fn need(z: Zed, key: []const u8) Rgb { const v = z.style.get(key) orelse std.process.fatal("{s}: missing style.{s}", .{ z.path, key }); return switch (v) { @@ -608,6 +737,79 @@ const Zed = struct { } }; +// ---- colour: the little of colors.zig's maths B7 and R3 need ---- + +fn linear(c: u8) f32 { + const x = @as(f32, @floatFromInt(c)) / 255; + return if (x <= 0.04045) x / 12.92 else std.math.pow(f32, (x + 0.055) / 1.055, 2.4); +} + +fn luminance(c: Rgb) f32 { + return 0.2126 * linear(c[0]) + 0.7152 * linear(c[1]) + 0.0722 * linear(c[2]); +} + +fn contrast(a: Rgb, b: Rgb) f32 { + const x = luminance(a); + const y = luminance(b); + return (@max(x, y) + 0.05) / (@min(x, y) + 0.05); +} + +/// colors.zig's isDark. +fn dark(c: Rgb) bool { + return luminance(c) < 0.18; +} + +/// A colour's OKLab a and b: where its hue points and how far from grey. +fn ab(c: Rgb) [2]f32 { + const l = [3]f32{ linear(c[0]), linear(c[1]), linear(c[2]) }; + const lm = std.math.cbrt(0.4122214708 * l[0] + 0.5363325363 * l[1] + 0.0514459929 * l[2]); + const mm = std.math.cbrt(0.2119034982 * l[0] + 0.6806995451 * l[1] + 0.1073969566 * l[2]); + const sm = std.math.cbrt(0.0883024619 * l[0] + 0.2817188376 * l[1] + 0.6299787005 * l[2]); + return .{ 1.9779984951 * lm - 2.4285922050 * mm + 0.4505937099 * sm, 0.0259040371 * lm + 0.7827717662 * mm - 0.8086757660 * sm }; +} + +/// How far from grey a colour is: its OKLab chroma. +fn chroma(c: Rgb) f32 { + const v = ab(c); + return @sqrt(v[0] * v[0] + v[1] * v[1]); +} + +/// A hue (chroma 0.04) within 60 degrees of `hue` (OKLab). +fn hueNear(c: Rgb, hue: f32) bool { + const v = ab(c); + const h = std.math.radiansToDegrees(std.math.atan2(v[1], v[0])); + const apart = @abs(@mod(h - hue + 540, 360) - 180); + return chroma(c) >= 0.04 and apart <= 60; +} + +/// R10 draws a diff's rows in its added and deleted hues: a theme's own +/// where they are a green and a red, else pardes's, its sixteen's (a grey, a +/// yellow for deleted or a tritan blue cannot be told apart as rows: ashen, +/// wolf_alabaster's, modus_operandi_tritanopia's). +fn diffPair(plus: ?Rgb, minus: ?Rgb) [2]?Rgb { + const p = plus orelse return .{ null, null }; + const m = minus orelse return .{ null, null }; + return if (hueNear(p, 145) and hueNear(m, 25)) .{ p, m } else .{ null, null }; +} + +/// `page` a `step`:1 contrast off itself, lighter on a dark page, darker on +/// a light one, its light scaled so its hue stays (a black page a grey). +fn stepOff(page: Rgb, step: f32) Rgb { + const y = luminance(page); + const want = if (dark(page)) step * (y + 0.05) - 0.05 else (y + 0.05) / step - 0.05; + var out: Rgb = undefined; + for (&out, page) |*o, c| { + const l = if (y > 0) @min(linear(c) * want / y, 1) else want; + const e = if (l <= 0.0031308) l * 12.92 else 1.055 * std.math.pow(f32, l, 1.0 / 2.4) - 0.055; + o.* = @intFromFloat(@round(e * 255)); + } + // the bytes' rounding short of the step: one more + while (contrast(out, page) < step) for (&out) |*o| { + o.* = if (dark(page)) o.* +| 1 else o.* -| 1; + }; + return out; +} + /// `#rrggbb`, helix's `#rgb` shorthand, or zed's `#rrggbbaa`. The alpha is /// DROPPED: pardes paints opaque cells, and the only translucent colors we read /// are the scrollbar's, where a dropped alpha reads as a slightly bolder bar and @@ -625,3 +827,142 @@ fn hex(path: []const u8, s: []const u8) Rgb { } return out; } + +// ---- tests: each of B7's rules on a minimal theme ---- + +fn helixOf(arena: std.mem.Allocator, text: []const u8) !Theme { + var tomls: std.StringHashMapUnmanaged(Toml) = .empty; + try tomls.put(arena, "t", parseToml(arena, "t.toml", text)); + var t = try helixTheme(arena, "t", resolve(arena, &tomls, "t", 8)); + toneOnTone(&t); + return t; +} + +test "B7: the text is helix's `variable` where it is a neutral ink that reads 4.5:1, else ui.text" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + // github's: ui.text a muted grey, code in a neutral variable + const github = try helixOf(a, "\"ui.background\" = { bg = \"#0d1117\" }\n\"ui.text\" = \"#8b949e\"\nvariable = \"#c9d1d9\"\n"); + try std.testing.expectEqual(Rgb{ 0xc9, 0xd1, 0xd9 }, github.text.?); + // a coloured variable (base16's red) is an identifier's hue + const base16 = try helixOf(a, "\"ui.background\" = { bg = \"#181818\" }\n\"ui.text\" = \"#d8d8d8\"\nvariable = \"#ab4642\"\n"); + try std.testing.expectEqual(Rgb{ 0xd8, 0xd8, 0xd8 }, base16.text.?); + // a neutral variable that does not read stays out + const faint = try helixOf(a, "\"ui.background\" = { bg = \"#181818\" }\n\"ui.text\" = \"#d8d8d8\"\nvariable = \"#444444\"\n"); + try std.testing.expectEqual(Rgb{ 0xd8, 0xd8, 0xd8 }, faint.text.?); +} + +test "B7: the tag is the inactive status bar, and the active one its focus where it is tone on tone" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const both = try helixOf(a, "\"ui.background\" = { bg = \"#1e1e2e\" }\n\"ui.text\" = \"#cdd6f4\"\n\"ui.statusline\" = { fg = \"#cdd6f4\", bg = \"#313244\" }\n\"ui.statusline.inactive\" = { fg = \"#a6adc8\", bg = \"#181825\" }\n"); + try std.testing.expectEqual(Rgb{ 0x18, 0x18, 0x25 }, both.tag); + try std.testing.expectEqual(Rgb{ 0xcd, 0xd6, 0xf4 }, both.tag_text); + try std.testing.expectEqual(Rgb{ 0x31, 0x32, 0x44 }, both.tag_focus.?); + try std.testing.expectEqual(Rgb{ 0xcd, 0xd6, 0xf4 }, both.tag_focus_text.?); + // one status bar: the tag, its focus pardes's to derive + const one = try helixOf(a, "\"ui.background\" = { bg = \"#1e1e2e\" }\n\"ui.statusline\" = { fg = \"#cdd6f4\", bg = \"#313244\" }\n"); + try std.testing.expectEqual(Rgb{ 0x31, 0x32, 0x44 }, one.tag); + try std.testing.expectEqual(null, one.tag_focus); + // an active bar on the other side of light is no focus + const loud = try helixOf(a, "\"ui.background\" = { bg = \"#1e1e2e\" }\n\"ui.statusline\" = { fg = \"#000000\", bg = \"#f0f0f0\" }\n\"ui.statusline.inactive\" = { fg = \"#a6adc8\", bg = \"#181825\" }\n"); + try std.testing.expectEqual(null, loud.tag_focus); +} + +test "R3, the import rule: a status bar on the other side of light from the page leaves the page a 1.15 step off as the tag, in the text" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const t = try helixOf(arena.allocator(), "\"ui.background\" = { bg = \"#1a1a1a\" }\n\"ui.text\" = \"#e0e0e0\"\n\"ui.statusline\" = { fg = \"#ffffff\", bg = \"#e05050\" }\n"); + try std.testing.expect(dark(t.tag) and contrast(t.tag, .{ 0x1a, 0x1a, 0x1a }) >= 1.15 and contrast(t.tag, .{ 0x1a, 0x1a, 0x1a }) < 1.2); + try std.testing.expectEqual(Rgb{ 0xe0, 0xe0, 0xe0 }, t.tag_text); + try std.testing.expectEqual(t.tag, t.rail); + // and on paper, darker + const light = try helixOf(arena.allocator(), "\"ui.background\" = { bg = \"#f8f8f0\" }\n\"ui.text\" = \"#202020\"\n\"ui.statusline\" = { fg = \"#ffffff\", bg = \"#203040\" }\n"); + try std.testing.expect(!dark(light.tag) and luminance(light.tag) < luminance(.{ 0xf8, 0xf8, 0xf0 }) and contrast(light.tag, .{ 0xf8, 0xf8, 0xf0 }) >= 1.15); +} + +test "B7: the severities from diagnostic.* and the plain scopes, error else the theme's own red" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + // gruvbox_material's: diagnostic.* an underline only, the plain scopes named + const t = try helixOf(a, "\"diagnostic.error\" = { underline = { color = \"red\", style = \"curl\" } }\n\"diagnostic.warning\" = { fg = \"#d8a657\" }\nerror = \"red\"\nwarning = \"#111111\"\ninfo = \"blue\"\nhint = \"#a9b665\"\n[palette]\nred = \"#ea6962\"\nblue = \"#7daea3\"\n"); + try std.testing.expectEqual(Rgb{ 0xea, 0x69, 0x62 }, t.@"error".?); + try std.testing.expectEqual(Rgb{ 0xd8, 0xa6, 0x57 }, t.warning.?); + try std.testing.expectEqual(Rgb{ 0x7d, 0xae, 0xa3 }, t.info.?); + try std.testing.expectEqual(Rgb{ 0xa9, 0xb6, 0x65 }, t.hint.?); + // none named: the theme's own red, never the terminal's guess; the rest pardes's + const bare = try helixOf(a, "[palette]\nred = \"#ff7ea2\"\n"); + try std.testing.expectEqual(Rgb{ 0xff, 0x7e, 0xa2 }, bare.@"error".?); + try std.testing.expectEqual(null, bare.warning); + try std.testing.expectEqual(null, (try helixOf(a, "\"ui.text\" = \"#cccccc\"\n")).@"error"); +} + +test "B7: added and deleted from diff.plus and diff.minus, the caret's line number from ui.linenr.selected" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const t = try helixOf(arena.allocator(), "\"diff.plus\" = \"#9feb99\"\n\"diff.minus\" = { fg = \"#ff7ea2\" }\n\"ui.linenr.selected\" = { fg = \"#abb7ff\" }\n"); + try std.testing.expectEqual(Rgb{ 0x9f, 0xeb, 0x99 }, t.added.?); + try std.testing.expectEqual(Rgb{ 0xff, 0x7e, 0xa2 }, t.deleted.?); + try std.testing.expectEqual(Rgb{ 0xab, 0xb7, 0xff }, t.line_number_current.?); + // wolf_alabaster's deleted is a yellow, ashen's added a grey: rows of + // them cannot be told apart, so pardes's green and red + const yellow = try helixOf(arena.allocator(), "\"diff.plus\" = \"#95cb82\"\n\"diff.minus\" = \"#dfdf8e\"\n"); + try std.testing.expectEqual(null, yellow.added); + try std.testing.expectEqual(null, yellow.deleted); + try std.testing.expectEqual(null, (try helixOf(arena.allocator(), "\"diff.plus\" = \"#737373\"\n\"diff.minus\" = \"#b14242\"\n")).added); +} + +test "B7: a program's sixteen from the palette where it names the six hues, purple and aqua for magenta and cyan" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const t = try helixOf(a, "\"ui.background\" = { bg = \"#282828\" }\n\"ui.text\" = \"#ebdbb2\"\ncomment = \"#928374\"\n[palette]\nred = \"#cc241d\"\ngreen = \"#98971a\"\nyellow = \"#d79921\"\nblue = \"#458588\"\npurple = \"#b16286\"\naqua = \"#689d6a\"\nlight-red = \"#fb4934\"\n"); + const s = t.ansi.?; + try std.testing.expectEqual(Rgb{ 0xcc, 0x24, 0x1d }, s[1]); + try std.testing.expectEqual(Rgb{ 0xb1, 0x62, 0x86 }, s[5]); + try std.testing.expectEqual(Rgb{ 0x68, 0x9d, 0x6a }, s[6]); + try std.testing.expectEqual(Rgb{ 0xfb, 0x49, 0x34 }, s[9]); + try std.testing.expectEqual(s[2], s[10]); + try std.testing.expectEqual(Rgb{ 0x28, 0x28, 0x28 }, s[0]); + try std.testing.expectEqual(Rgb{ 0xeb, 0xdb, 0xb2 }, s[7]); + try std.testing.expectEqual(Rgb{ 0x92, 0x83, 0x74 }, s[8]); + // five of six: pardes derives them + try std.testing.expectEqual(null, (try helixOf(a, "[palette]\nred = \"#cc241d\"\ngreen = \"#98971a\"\nyellow = \"#d79921\"\nblue = \"#458588\"\npurple = \"#b16286\"\n")).ansi); +} + +test "B7, zed: the status bar the tag, the active tab its focus, the status colours, a search match as drawn over the page" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + var style: std.ArrayList(u8) = .empty; + const keys = [_][2][]const u8{ + .{ "editor.background", "#282c33ff" }, .{ "editor.foreground", "#acb2beff" }, + .{ "element.selected", "#454a56ff" }, .{ "status_bar.background", "#3b414dff" }, + .{ "text.muted", "#a9afbcff" }, .{ "text.accent", "#74ade8ff" }, + .{ "editor.line_number", "#4e5a5f" }, .{ "scrollbar.thumb.border", "#363c46ff" }, + .{ "scrollbar.thumb.background", "#c8ccd44c" }, .{ "tab.active_background", "#282c33ff" }, + .{ "error", "#d07277ff" }, .{ "warning", "#dec184ff" }, + .{ "info", "#74ade8ff" }, .{ "hint", "#788ca6ff" }, + .{ "created", "#a1c181ff" }, .{ "deleted", "#d07277ff" }, + .{ "search.match_background", "#74ade866" }, .{ "editor.active_line_number", "#d0d4da" }, + }; + for (keys) |k| try style.print(a, "\"{s}\": \"{s}\", ", .{ k[0], k[1] }); + inline for (ansi) |n| try style.print(a, "\"terminal.ansi.{s}\": \"#101010\", \"terminal.ansi.bright_{s}\": \"#202020\", ", .{ n, n }); + const json = try std.fmt.allocPrint(a, "{{\"themes\": [{{\"name\": \"One Dark\", \"style\": {{ {s} \"syntax\": {{ \"keyword\": {{\"color\": \"#b477cf\"}}, \"string\": {{\"color\": \"#a1c181\"}}, \"number\": {{\"color\": \"#bf956a\"}}, \"comment\": {{\"color\": \"#5d636f\"}} }} }} }}]}}", .{style.items}); + var out: std.ArrayList(Theme) = .empty; + try readZed(a, std.testing.allocator, "one.json", json, &out); + const t = out.items[0]; + try std.testing.expectEqualStrings("one_dark_zed", t.name); + try std.testing.expectEqual(Rgb{ 0x3b, 0x41, 0x4d }, t.tag); + try std.testing.expectEqual(Rgb{ 0x28, 0x2c, 0x33 }, t.tag_focus.?); + try std.testing.expectEqual(Rgb{ 0xd0, 0x72, 0x77 }, t.@"error".?); + try std.testing.expectEqual(Rgb{ 0x78, 0x8c, 0xa6 }, t.hint.?); + try std.testing.expectEqual(Rgb{ 0xa1, 0xc1, 0x81 }, t.added.?); + try std.testing.expectEqual(Rgb{ 0xd0, 0x72, 0x77 }, t.deleted.?); + try std.testing.expectEqual(Rgb{ 0xd0, 0xd4, 0xda }, t.line_number_current.?); + // #74ade8 at 0x66 (40 %) over #282c33 + try std.testing.expectEqual(Rgb{ 0x46, 0x60, 0x7b }, t.hit.?); +} -- cgit v1.3 From fed268f2282a6d393a116d103e1fd88da87ecbff Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 04:36:36 -0300 Subject: themes, colors, gen_themes: `dark` refreshed and four new pardes themes, light, mono, okabe and sepia, and the ring in DESIGN.md E's groups (the themes programme's L5; DESIGN.md C, D, E, G2, G3): DARK (C): still the one theme with no page and no text of its own, so a terminal keeps the host's cell, ink and sixteen (ansi.inkOf's `host`), and a window draws colors.null_page #121212 and #cccccc (G2 (a)); its comments the brightest ink, #f0f0f0; keywords violet #d76ef0 (6.6:1; was #da5eea, 5.9:1); the lilac tag #2c2a3e with #aba9c3 ink, focused #d6d4e8; the grip #a58bff (3.4:1 on its focused tag; was #663fe0, 1.45:1); a violet selection #46337a in #f4f0ff (G3 (a): the tan #513c17 sat in the hits' amber); its own severities #ff6e7f #ffb454 #7fa8ff #62d2c4, line numbers #5c5c66 / #8e8c9e, and a designed sixteen for the window (its ANSI 8 #7e7b96, 4.6:1, where L1's derived one was 3:1); its focused tag, mode ring, grip ring, dirty, rules, hits and diff rows Chrome.of's; LIGHT, MONO, OKABE, SEPIA (D): each its primitives as the designer's prototype resolved and audited them (.scratch/themes/C1/newthemes.py, swatches.md: page, text, tag and its ink, accent, selection and its ink, the four syntax hues, line numbers, the four severities, the sixteen; okabe's added blue #56b4e9 and deleted vermilion #ff8a4c), everything else Chrome.of's; THE RING (E): curated in the picker's sections: Pardes (dark, light, orchard, orchard_black, ink, mono, okabe, sepia, paper, daybreak, dusk, lapis), Pardes, after a classic (forge, forge_black, forge_soft, lagoon, solarium, spectrum, harvest, clay), acme (acme, atelier), the faithful ports a family at a time as before, Captured (helix; "Legacy themes" gone); the imported a family at a time, each under its heading (`Imported: gruvbox`, a family the name's first word, two themes or more), the lone ones last under one (`Imported, one of a kind`): the generator rings them so (gen_themes `byFamily`) and colors.zig heads them at comptime (`import_heads`, a compile error where a family rings after a lone theme); ORCHARD THE DEFAULT BY NAME (`colors.default_theme`: config.Settings' `theme`, the library's `default_theme`, macos.zig's bare page), never index 0, which is dark now; THE RING TEST: dusk, lagoon, solarium and forge_soft `soft` (`soft_themes`: held at AA, their text and tag text never to the pro 7:1; the coordinator's ruling) where they were on the expected list; the diff rows' "unless the text holds it nearer" exception for the ports and imports only, pardes's own held to 1.15:1 (the coordinator's ruling: every one of them meets it); pardes's own are every theme before the first faithful port, so dark and the new four are held to the pro floors with the natives; the old tests that read the first fifteen by place read the fifteen designed natives by name (`designed`; `native_theme_count` gone, B8); RUN (TEST FIRST): the ring test with dark off its list and the soft four marked failed on L4's dark (ansi_pro: its ANSI 8 3:1) and, with the soft mark on text alone, on lagoon's and solarium's tag_text7: 281 of 289 themes pass (272 of 285 at L4, the four new ones passing every floor, pro included), 8 on the list (L7's retired); colors.zig "the picker's sections run in ring order and cover it": dark first, orchard the default by name, each imported family's heading at its first, none after the lone ones' (fails on L4: "Pardes themes", orchard at 0); test/process/tty_themes.zig's `theme` case boots in dark (`Theme dark`, its own init line) and steps NextColor through the 24 of the new order into the first ports (dark, light, orchard, orchard-black, ink, mono, okabe, sepia, paper, daybreak, dusk, lapis, forge, ..., clay, acme, atelier, dark-plus, solarized-dark), `themesel` walks the Themes list from its first row the same 24 (both goldens re-recorded and read at the programme's end gate: the snaps are named for the new order); core-test 1140/1313 (173 skipped: as L4, the picker test grown); OUTSIDE my files: core/config.zig (the default, 1 line), core/lib_syntax.zig (`default_theme`), runtime/macos.zig (1 line), test/consumer/lib.zig (orchard is `default_theme`), test/process/tty_themes.zig (the two cases); no dump or digest change (a dump names its theme; settings.theme is a place in this build's ring, as before) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/colors.zig | 177 +++++++++++++++++++++++++++++--------------- core/config.zig | 2 +- core/lib_syntax.zig | 5 +- core/themes/dark.zig | 55 +++++++------- core/themes/light.zig | 30 ++++++++ core/themes/mono.zig | 31 ++++++++ core/themes/okabe.zig | 32 ++++++++ core/themes/sepia.zig | 30 ++++++++ runtime/macos.zig | 2 +- test/consumer/lib.zig | 2 +- test/process/tty_themes.zig | 177 +++++++++++++++++++++++++++++--------------- tools/gen_themes.zig | 17 ++++- 12 files changed, 406 insertions(+), 154 deletions(-) create mode 100644 core/themes/light.zig create mode 100644 core/themes/mono.zig create mode 100644 core/themes/okabe.zig create mode 100644 core/themes/sepia.zig (limited to 'tools') diff --git a/core/colors.zig b/core/colors.zig index b089a1b9..9091760f 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -1096,23 +1096,33 @@ pub const Grounds = struct { const seoul256 = @import("themes/seoul256.zig"); const curated = struct { + // DESIGN.md E's groups, the picker's sections (`theme_groups`): pardes's + // own, dark first (the host's page, the favourite), orchard the default + // (`default_theme`, by name). + pub const dark = @import("themes/dark.zig"); + pub const light = @import("themes/light.zig"); pub const orchard = @import("themes/orchard.zig"); - pub const dusk = @import("themes/dusk.zig"); + pub const orchard_black = @import("themes/orchard_black.zig"); pub const ink = @import("themes/ink.zig"); + pub const mono = @import("themes/mono.zig"); + pub const okabe = @import("themes/okabe.zig"); + pub const sepia = @import("themes/sepia.zig"); pub const paper = @import("themes/paper.zig"); pub const daybreak = @import("themes/daybreak.zig"); - pub const atelier = @import("themes/atelier.zig"); + pub const dusk = @import("themes/dusk.zig"); + pub const lapis = @import("themes/lapis.zig"); + // Pardes's, after a classic. pub const forge = @import("themes/forge.zig"); + pub const forge_black = @import("themes/forge_black.zig"); + pub const forge_soft = @import("themes/forge_soft.zig"); pub const lagoon = @import("themes/lagoon.zig"); pub const solarium = @import("themes/solarium.zig"); pub const spectrum = @import("themes/spectrum.zig"); pub const harvest = @import("themes/harvest.zig"); pub const clay = @import("themes/clay.zig"); - pub const forge_black = @import("themes/forge_black.zig"); - pub const forge_soft = @import("themes/forge_soft.zig"); - pub const orchard_black = @import("themes/orchard_black.zig"); + // acme's. pub const acme = @import("themes/acme.zig"); - pub const lapis = @import("themes/lapis.zig"); + pub const atelier = @import("themes/atelier.zig"); // Faithful ports of well-known themes, a family at a time (core/themes/ // .zig says where each value came from): `theme_groups`. pub const dark_plus = @import("themes/dark_plus.zig"); @@ -1178,9 +1188,8 @@ const curated = struct { pub const ayu_light = @import("themes/ayu_light.zig"); pub const doom_one = @import("themes/doom_one.zig"); pub const doom_one_light = @import("themes/doom_one_light.zig"); - // The legacy pair last. + // Captured: an old helix setup, kept (it works). pub const helix = @import("themes/helix.zig"); - pub const dark = @import("themes/dark.zig"); }; /// A struct of theme files as themes: each file's `theme`, a field it @@ -1235,13 +1244,14 @@ pub const native_count = @typeInfo(curated).@"struct".decl_names.len; /// The picker's sections (`Themes`), in ring order, each running from /// the theme it names to the next section's; `NextColor` and `Theme` still -/// see one flat ring. The current pardes themes, then the faithful ports a -/// family at a time, then the legacy pair (`helix`, captured from an old -/// helix setup and the boot default before orchard; `dark`, the host -/// terminal's own ground), then everything imported. +/// see one flat ring (DESIGN.md E): pardes's own, those after a classic, +/// acme's, the faithful ports a family at a time, the captured helix setup; +/// then the imported, a family at a time (`import_heads`). pub const ThemeGroup = struct { title: []const u8, first: []const u8 }; const theme_groups = [_]ThemeGroup{ - .{ .title = "Pardes themes", .first = "orchard" }, + .{ .title = "Pardes", .first = "dark" }, + .{ .title = "Pardes, after a classic", .first = "forge" }, + .{ .title = "acme", .first = "acme" }, .{ .title = "Visual Studio Code", .first = "dark_plus" }, .{ .title = "Solarized", .first = "solarized_dark" }, .{ .title = "Dracula", .first = "dracula" }, @@ -1255,9 +1265,12 @@ const theme_groups = [_]ThemeGroup{ .{ .title = "Nord", .first = "nord" }, .{ .title = "Ayu", .first = "ayu_dark" }, .{ .title = "Doom One", .first = "doom_one" }, - .{ .title = "Legacy themes", .first = "helix" }, + .{ .title = "Captured", .first = "helix" }, }; +/// The theme a session starts in, by name: never a place in the ring. +pub const default_theme = indexOfTheme("orchard"); + fn indexOfTheme(comptime name: []const u8) usize { return comptime blk: { @setEvalBranchQuota(100000); @@ -1269,12 +1282,38 @@ fn indexOfTheme(comptime name: []const u8) usize { /// The heading of the picker section that starts at ring index `index`. pub fn groupAt(index: usize) ?[]const u8 { inline for (theme_groups) |g| if (index == comptime indexOfTheme(g.first)) return g.title; - if (index == native_count) return "Imported themes (helix, zed)"; - return null; -} - -/// Original and classic-inspired Pardes palettes precede retained imports. -pub const native_theme_count = 15; + return if (index >= native_count) import_heads[index - native_count] else null; +} + +/// A theme's family: its name's first word (gruvbox_dark_hard's gruvbox). +fn familyOf(name: []const u8) []const u8 { + return name[0 .. std.mem.indexOfScalar(u8, name, '_') orelse name.len]; +} + +/// The imported themes' headings, a family's at its first (DESIGN.md E: a +/// heading per family, not one flat run), and one over the lone ones the +/// generator rings after every family (tools/gen_themes.zig `byFamily`). +const import_heads: [themes.len - native_count]?[]const u8 = blk: { + @setEvalBranchQuota(2_000_000); + const imported = themes[native_count..]; + var out: [imported.len]?[]const u8 = @splat(null); + var lone_seen = false; + for (imported, 0..) |t, i| { + const family = familyOf(t.name); + var members: usize = 0; + for (imported) |u| { + if (std.mem.eql(u8, familyOf(u.name), family)) members += 1; + } + if (members < 2) { + if (!lone_seen) out[i] = "Imported, one of a kind"; + lone_seen = true; + } else if (i == 0 or !std.mem.eql(u8, familyOf(imported[i - 1].name), family)) { + if (lone_seen) @compileError("imported family " ++ family ++ " rings after a lone theme (tools/gen_themes.zig byFamily)"); + out[i] = "Imported: " ++ family; + } + } + break :blk out; +}; comptime { if (themes.len > std.math.maxInt(u16) + 1) @@ -1904,9 +1943,8 @@ test "every native theme's separators stand off its page, and its focus tint off const chrome = ChromeTheme.fromTheme(theme); const page = theme.bg orelse null_page; try std.testing.expect(contrast(chrome.border, page) >= separator_floor); - // A dark page's focused tag is told by its band too, not the grip - // alone; acme's (light, and acme's own) is told by its button. - if (relativeLuminance(page) < 0.18) try std.testing.expect(theme.tag_active_bg != null); + // A focused tag of its own stands off the plain one (R4 derives the + // rest: the ring test's `focus`). if (theme.tag_active_bg) |own| { try std.testing.expect(contrast(chrome.tag_active_bg, theme.tag_bg) >= focusTintFloor(theme)); // And its text still reads. @@ -1917,7 +1955,7 @@ test "every native theme's separators stand off its page, and its focus tint off } test "every faithful port meets pardes's chrome floors in its own colours, with nothing left to derive" { - const first = comptime indexOfTheme("lapis") + 1; + const first = comptime indexOfTheme("dark_plus"); const last = comptime indexOfTheme("helix"); for (themes[first..last]) |*ring_theme| { const view = ChromeTheme.ofTheme(ring_theme).view; @@ -1973,10 +2011,23 @@ test "the picker's sections run in ring order and cover it" { if (n == 0) try std.testing.expectEqual(@as(usize, 0), at) else try std.testing.expect(at > last); last = at; } - try std.testing.expectEqualStrings("Pardes themes", groupAt(0).?); + try std.testing.expectEqualStrings("Pardes", groupAt(0).?); + try std.testing.expectEqualStrings("dark", themes[0].name); + try std.testing.expectEqualStrings("orchard", themes[default_theme].name); // acme is a current theme, not a legacy one. try std.testing.expect(indexOfTheme("acme") < indexOfTheme("helix")); - try std.testing.expect(groupAt(native_count) != null); + // The imported a family at a time, each under its heading, the lone + // ones last under one. + try std.testing.expect(std.mem.startsWith(u8, groupAt(native_count).?, "Imported: ")); + const gruvbox = for (themes, 0..) |t, i| { + if (std.mem.eql(u8, t.name, "gruvbox")) break i; + } else unreachable; + try std.testing.expectEqualStrings("Imported: gruvbox", groupAt(gruvbox).?); + try std.testing.expectEqual(null, groupAt(gruvbox + 1)); + const lone = for (themes[native_count..], native_count..) |_, i| { + if (groupAt(i)) |title| if (std.mem.eql(u8, title, "Imported, one of a kind")) break i; + } else unreachable; + for (themes[lone + 1 ..], lone + 1..) |_, i| try std.testing.expectEqual(null, groupAt(i)); } test "seoul256's twelve backgrounds ring in their order, after Catppuccin and before Zenbones" { @@ -2054,7 +2105,7 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { return error.MissingThemeFileRequest; try std.testing.expectEqualStrings("/tmp/pardes-config/themes/mine.zon", request.path); - var custom = themes[0]; + var custom = themes[default_theme]; custom.name = "mine"; custom.page = .{ 1, 2, 3 }; custom.tag = .{ 4, 5, 6 }; @@ -2074,8 +2125,8 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { try std.testing.expectEqualStrings("mine", p.theme().name); try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().bg); - setThemeIndex(p, 0); - try std.testing.expectEqualStrings(themes[0].name, p.theme().name); + setThemeIndex(p, default_theme); + try std.testing.expectEqualStrings(themes[default_theme].name, p.theme().name); try std.testing.expect(themeFileRequest(p, request_effect.generation) == null); const stop = while (p.nextEffect()) |effect| switch (effect) { .theme_file => |theme_file| break theme_file, @@ -2085,11 +2136,8 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { } test "native themes keep text and UI roles readable on their own surfaces" { - const names = [_][]const u8{ "orchard", "dusk", "ink", "paper", "daybreak", "atelier", "forge", "lagoon", "solarium", "spectrum", "harvest", "clay", "forge_black", "forge_soft", "orchard_black" }; - try std.testing.expectEqual(names.len, native_theme_count); - for (themes[0..names.len], names) |own, name| { - const th = ChromeTheme.ofTheme(&own).view; - try std.testing.expectEqualStrings(name, th.name); + for (designed) |name| { + const th = ChromeTheme.ofTheme(&themes[themeIndex(name).?]).view; const chrome = ChromeTheme.fromTheme(&th); const minimum: f32 = if (std.mem.eql(u8, name, "ink") or std.mem.eql(u8, name, "daybreak")) 7 else 4.5; const text_colors = [_][3]u8{ @@ -2121,8 +2169,14 @@ test "native themes keep text and UI roles readable on their own surfaces" { } } +/// The natives written before the colour system (DESIGN.md B), each with a +/// name tint and a column grip of its own: what the tests of their own +/// values below hold (the ring test holds every theme to B4's floors). +const designed = [_][]const u8{ "orchard", "dusk", "ink", "paper", "daybreak", "atelier", "forge", "lagoon", "solarium", "spectrum", "harvest", "clay", "forge_black", "forge_soft", "orchard_black" }; + test "native filename tints change hue without changing perceived lightness" { - for (themes[0..native_theme_count]) |*th| { + for (designed) |native| { + const th = &themes[themeIndex(native).?]; // The theme's own tint at its tag ink's lightness (the focused one // Chrome.of's, R13). const pairs = [1][2][3]u8{ @@ -2146,8 +2200,8 @@ test "native filename tints change hue without changing perceived lightness" { } test "native dark palettes choose near-black or deliberately soft contrast" { - for (themes[0..native_theme_count]) |ring_theme| { - const th = ChromeTheme.ofTheme(&ring_theme).view; + for (designed) |name| { + const th = ChromeTheme.ofTheme(&themes[themeIndex(name).?]).view; if (contrast(th.bg.?, .{ 0, 0, 0 }) > 10) continue; // light paper const soft = std.mem.eql(u8, th.name, "dusk") or std.mem.eql(u8, th.name, "lagoon") or std.mem.eql(u8, th.name, "solarium") or std.mem.eql(u8, th.name, "forge_soft"); @@ -2175,7 +2229,7 @@ test "line numbers stay quiet without a current-line tag background" { const pane = try p.setTestFile("first\nsecond\n"); pane.body.cur_pinned = true; pane.body.cur_row = 0; - var custom = ChromeTheme.ofTheme(&themes[0]).view; + var custom = ChromeTheme.ofTheme(&themes[default_theme]).view; custom.name = try gpa.dupe(u8, "quiet-gutter"); custom.lineno = .{ 70, 70, 70 }; custom.lineno_active = .{ 95, 95, 95 }; @@ -2252,7 +2306,8 @@ test "legacy ThemeFile documents inherit Pardes UI roles without new fields" { } test "column grip colors remain distinct from pane grips across native themes" { - for (themes[0..native_theme_count]) |*th| { + for (designed) |name| { + const th = &themes[themeIndex(name).?]; // The theme's own (their rest and grabbed inks Chrome.of's, R6, H). for ([_][2][3]u8{ .{ th.accent, th.column_grip.? }, @@ -2265,7 +2320,7 @@ test "column grip colors remain distinct from pane grips across native themes" { try std.testing.expect(distance >= 30 * 30); } } - var custom = ChromeTheme.ofTheme(&themes[0]).view; + var custom = ChromeTheme.ofTheme(&themes[default_theme]).view; custom.column_box = .{ 90, 130, 170 }; custom.column_box_dim = null; var chrome = ChromeTheme.fromTheme(&custom); @@ -2277,7 +2332,7 @@ test "column grip colors remain distinct from pane grips across native themes" { } test "custom filename tints preserve optional active fallback precedence" { - var theme = ChromeTheme.ofTheme(&themes[0]).view; + var theme = ChromeTheme.ofTheme(&themes[default_theme]).view; theme.tag_name_fg = null; theme.tag_active_name_fg = null; var chrome = ChromeTheme.fromTheme(&theme); @@ -2484,7 +2539,7 @@ const RingCheck = enum { }; /// The checks `th`'s chrome fails. -fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { +fn ringFailures(th: *const Theme, c: *const Chrome, designed_here: bool) std.EnumSet(RingCheck) { var f: std.EnumSet(RingCheck) = .empty; const de = struct { fn of(a: [3]u8, b: [3]u8) f32 { @@ -2571,12 +2626,13 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { f.setPresent(.severities4, apart4 < Chrome.severity_apart); const err = lch(c.page.severity[0]); f.setPresent(.error_red, !(err[1] >= 0.08 and (err[2] <= 50 or err[2] >= 330))); - // R10: each diff row 1.15:1 off the page, unless the text holds it - // nearer (never under its floor there: tokyonight_day's text, 4.9:1, - // leaves 1.11:1), and the two 0.05 apart. + // R10: each diff row 1.15:1 off the page, and the two 0.05 apart; a + // port's or an import's nearer where its own text holds it (never + // under its floor there: tokyonight_day's text, 4.9:1, leaves 1.11:1); + // pardes's own themes always (the coordinator's ruling). const diff_floor = @min(4.5, text * 0.9); for ([2][3]u8{ c.add.row, c.del.row }) |row| { - if (contrast(row, page) < Chrome.row_step - 0.005 and contrast(ink, row) > diff_floor + 0.05) f.insert(.diff); + if (contrast(row, page) < Chrome.row_step - 0.005 and (designed_here or contrast(ink, row) > diff_floor + 0.05)) f.insert(.diff); } if (de(c.add.row, c.del.row) < 0.05) f.insert(.diff); var ansi_least: f32 = 21; @@ -2606,8 +2662,6 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { /// them lands (DESIGN.md E1, F): the list shrinks as each does, and a theme /// on it that passes fails the test, so it is taken off. const ring_expected = [_]struct { []const u8, []const u8 }{ - // L5: dark's own sixteen (its derived ANSI 8 is 3:1, under the pro 4.5). - .{ "dark", "L5: its designed ANSI (DESIGN.md C)" }, // L7: retired. .{ "seoul256_dark_238", "L7: retired" }, .{ "seoul256_dark_239", "L7: retired" }, @@ -2617,17 +2671,17 @@ const ring_expected = [_]struct { []const u8, []const u8 }{ .{ "hex_poison", "L7: retired" }, .{ "hex_steel", "L7: retired" }, .{ "ingrid", "L7: retired" }, - // No line: the soft natives' text is 4.5-7:1 by design (the native - // test below), under the professional 7:1. C1's ruling. - .{ "dusk", "soft by design: text under the pro 7:1" }, - .{ "lagoon", "soft by design: text under the pro 7:1" }, - .{ "solarium", "soft by design: text under the pro 7:1" }, - .{ "forge_soft", "soft by design: text under the pro 7:1" }, }; +/// The soft natives: their text 4.5-7:1 by design, held at AA, never the +/// professional 7:1, and never retuned (the coordinator's ruling; solarium +/// is the user's). +const soft_themes = [_][]const u8{ "dusk", "lagoon", "solarium", "forge_soft" }; + test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), natives and dark the professional ones too; the original's own colours never moved" { - const lapis = comptime indexOfTheme("lapis"); - const dark = comptime indexOfTheme("dark"); + // pardes's own: every theme before the first faithful port (dark and + // the new ones among them), and the captured helix's originals. + const ports = comptime indexOfTheme("dark_plus"); const helix = comptime indexOfTheme("helix"); var passing: usize = 0; var wrong: usize = 0; @@ -2639,12 +2693,17 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati if (th.page) |own| try std.testing.expectEqual(own, c.page.ground); if (th.ansi) |own| try std.testing.expectEqual(own, c.ansi); if (th.line_number) |own| try std.testing.expectEqual(own, c.line_number); - const ours = i <= lapis or i == dark or i == helix; - const failures = ringFailures(th, &c); + const ours = i < ports or i == helix; + const soft = for (soft_themes) |name| { + if (std.mem.eql(u8, name, th.name)) break true; + } else false; + const failures = ringFailures(th, &c, i < ports); var held: std.EnumSet(RingCheck) = .empty; var it = failures.iterator(); while (it.next()) |check| { - if (check.pro() and !(i <= lapis or i == dark)) continue; + if (check.pro() and i >= ports) continue; + // A soft theme's text is held at AA, 4.5:1, never the pro 7:1. + if (soft and (check == .text7 or check == .tag_text7)) continue; if (check.original() and !ours and !(std.mem.startsWith(u8, @tagName(check), "ansi") and th.ansi == null)) continue; held.insert(check); } diff --git a/core/config.zig b/core/config.zig index 03cb6044..dc1d98dc 100644 --- a/core/config.zig +++ b/core/config.zig @@ -614,7 +614,7 @@ pub const kill_to_line_start: []const Chord = &.{.{ .cp = 'u', .ctrl = true }}; pub const kill_to_line_end: []const Chord = &.{.{ .cp = 'k', .ctrl = true }}; pub const Settings = struct { - theme: usize = 0, + theme: usize = pardes.colors.default_theme, wrap: bool = true, debug: bool = false, /// The workspace tag row. Native shells with their own chrome (the macOS diff --git a/core/lib_syntax.zig b/core/lib_syntax.zig index 2c771b72..448ac7f3 100644 --- a/core/lib_syntax.zig +++ b/core/lib_syntax.zig @@ -103,9 +103,10 @@ pub const Span = syntax.Span; pub const walkNodes = syntax.walkNodes; pub const Theme = colors.Theme; -/// Every theme: pardes's own, then those imported from helix and zed. The -/// first is the default. +/// Every theme: pardes's own, then those imported from helix and zed. pub const themes: []const Theme = &colors.themes; +/// The one a session starts in (`orchard`), its place in `themes`. +pub const default_theme = colors.default_theme; /// The theme named `name`, whatever its case. pub fn theme(name: []const u8) ?*const Theme { return &colors.themes[colors.themeIndex(name) orelse return null]; diff --git a/core/themes/dark.zig b/core/themes/dark.zig index 51768f56..24506f6b 100644 --- a/core/themes/dark.zig +++ b/core/themes/dark.zig @@ -1,33 +1,36 @@ -//! pardes's own dark theme, and the boot default until the helix capture -//! displaced it. It stays in the ring because it is the only one that leaves -//! `bg`/`fg` NULL: the page keeps the host terminal's own default cell, so -//! pardes sits inside whatever the surrounding terminal already looks like and -//! only paints its chrome. Every other theme here dresses the whole page. -//! -//! The selection pair is the warm tan pardes used to paint EVERY theme's -//! selection with, back when those six numbers were module constants. This is -//! the theme it belongs to: a null page is the host terminal's, and a tan that -//! reads as keyboard-driven on whatever dark cell that turns out to be is -//! exactly what it was picked for. +//! pardes dark: the host terminal's own page, white comments, violet stuff. +//! The one theme that leaves `page` and `text` NULL: in a terminal the page +//! is the host's own cell, ink and sixteen, so pardes sits inside whatever +//! the terminal already looks like and paints only its chrome; a window +//! draws colors.null_page (#121212) and #cccccc, and its sixteen below. +//! DESIGN.md part C: comments the brightest ink (#f0f0f0, 16.4:1), keywords +//! violet (#d76ef0, 6.6:1), a lilac tag, a violet grip that reads (#a58bff, +//! 3.4:1 on the focused tag) and a violet selection (#46337a) so the hits +//! keep amber; its own severities and sixteen (the window's). pub const theme = .{ .name = "dark", .page = null, .text = null, - .selection = .{ 0x51, 0x3c, 0x17 }, - .selection_text = .{ 0xd8, 0xc8, 0xa8 }, .tag = .{ 0x2c, 0x2a, 0x3e }, - .tag_text = .{ 0x96, 0x96, 0x96 }, - // The focused tag: its band lighter in its own hue (1.54:1 off the - // plain one), its ink lighter to keep reading on it. - .tag_focus = .{ 0x48, 0x45, 0x66 }, - .tag_focus_text = .{ 0xc8, 0xc8, 0xc8 }, - .accent = .{ 0x66, 0x3f, 0xe0 }, - .keyword = .{ 0xda, 0x5e, 0xea }, - .string = .{ 0x85, 0xc3, 0x6f }, - .number = .{ 0xe1, 0xcb, 0x5f }, + .tag_text = .{ 0xab, 0xa9, 0xc3 }, + .tag_focus_text = .{ 0xd6, 0xd4, 0xe8 }, + .accent = .{ 0xa5, 0x8b, 0xff }, + .selection = .{ 0x46, 0x33, 0x7a }, + .selection_text = .{ 0xf4, 0xf0, 0xff }, + .keyword = .{ 0xd7, 0x6e, 0xf0 }, + .string = .{ 0x8f, 0xca, 0x78 }, + .number = .{ 0xe3, 0xcd, 0x64 }, .comment = .{ 0xf0, 0xf0, 0xf0 }, - .line_number = .{ 0x5a, 0x5a, 0x5a }, - .rail = .{ 0x2a, 0x2a, 0x2a }, - .rail_thumb = .{ 0x52, 0x52, 0x52 }, - .ansi = null, + .line_number = .{ 0x5c, 0x5c, 0x66 }, + .line_number_current = .{ 0x8e, 0x8c, 0x9e }, + .@"error" = .{ 0xff, 0x6e, 0x7f }, + .warning = .{ 0xff, 0xb4, 0x54 }, + .info = .{ 0x7f, 0xa8, 0xff }, + .hint = .{ 0x62, 0xd2, 0xc4 }, + .ansi = .{ + .{ 0x2c, 0x2a, 0x3e }, .{ 0xff, 0x6e, 0x7f }, .{ 0x8f, 0xca, 0x78 }, .{ 0xe3, 0xcd, 0x64 }, + .{ 0x7f, 0xa8, 0xff }, .{ 0xd7, 0x6e, 0xf0 }, .{ 0x62, 0xd2, 0xc4 }, .{ 0xc4, 0xc4, 0xcc }, + .{ 0x7e, 0x7b, 0x96 }, .{ 0xff, 0x95, 0xa1 }, .{ 0xae, 0xe3, 0x9a }, .{ 0xf2, 0xe0, 0x8a }, + .{ 0xa6, 0xc3, 0xff }, .{ 0xe6, 0x9c, 0xf7 }, .{ 0x8f, 0xe6, 0xda }, .{ 0xf0, 0xf0, 0xf0 }, + }, }; diff --git a/core/themes/light.zig b/core/themes/light.zig new file mode 100644 index 00000000..681c000a --- /dev/null +++ b/core/themes/light.zig @@ -0,0 +1,30 @@ +//! pardes light: dark's daylight sibling (DESIGN.md part D). White paper, +//! the comments the darkest ink as dark's are the brightest, violet keywords +//! and grip, a lilac-grey tag, a pale violet selection. For dark's users at a +//! sunny desk, or a phone outdoors. +pub const theme = .{ + .name = "light", + .page = .{ 0xfb, 0xfb, 0xfd }, + .text = .{ 0x34, 0x32, 0x3f }, + .tag = .{ 0xe9, 0xe7, 0xf3 }, + .tag_text = .{ 0x4b, 0x48, 0x62 }, + .accent = .{ 0x6a, 0x3f, 0xd8 }, + .selection = .{ 0xdd, 0xd3, 0xfb }, + .selection_text = .{ 0x1c, 0x1a, 0x24 }, + .keyword = .{ 0x8b, 0x2a, 0xb8 }, + .string = .{ 0x2f, 0x6e, 0x1f }, + .number = .{ 0x8a, 0x57, 0x00 }, + .comment = .{ 0x0d, 0x0c, 0x12 }, + .line_number = .{ 0xa3, 0xa1, 0xb0 }, + .line_number_current = .{ 0x6e, 0x6b, 0x80 }, + .@"error" = .{ 0xc0, 0x23, 0x3a }, + .warning = .{ 0x9a, 0x5a, 0x00 }, + .info = .{ 0x24, 0x57, 0xc5 }, + .hint = .{ 0x0f, 0x76, 0x6e }, + .ansi = .{ + .{ 0xe9, 0xe7, 0xf3 }, .{ 0xc0, 0x23, 0x3a }, .{ 0x2f, 0x6e, 0x1f }, .{ 0x8a, 0x57, 0x00 }, + .{ 0x24, 0x57, 0xc5 }, .{ 0x8b, 0x2a, 0xb8 }, .{ 0x0f, 0x76, 0x6e }, .{ 0x55, 0x53, 0x6a }, + .{ 0x73, 0x71, 0x84 }, .{ 0xd2, 0x36, 0x4d }, .{ 0x35, 0x82, 0x21 }, .{ 0xa0, 0x67, 0x00 }, + .{ 0x39, 0x6c, 0xde }, .{ 0xa4, 0x3f, 0xd4 }, .{ 0x04, 0x81, 0x77 }, .{ 0x0d, 0x0c, 0x12 }, + }, +}; diff --git a/core/themes/mono.zig b/core/themes/mono.zig new file mode 100644 index 00000000..f0dd109a --- /dev/null +++ b/core/themes/mono.zig @@ -0,0 +1,31 @@ +//! pardes mono: acme at night (DESIGN.md part D). Syntax by lightness +//! alone: keywords the brightest, strings a warm off-white, numbers the +//! text's, comments a step down (5.6:1). Hue only where pardes says a state: +//! the selection, hits, severities, added and deleted. For acme and Plan 9 +//! users, anyone who finds syntax colour noise, and screen sharing. +pub const theme = .{ + .name = "mono", + .page = .{ 0x11, 0x11, 0x13 }, + .text = .{ 0xbf, 0xc0, 0xc6 }, + .tag = .{ 0x1e, 0x1f, 0x24 }, + .tag_text = .{ 0xa2, 0xa4, 0xad }, + .accent = .{ 0xe6, 0xe7, 0xec }, + .selection = .{ 0x3b, 0x3d, 0x47 }, + .selection_text = .{ 0xf2, 0xf2, 0xf5 }, + .keyword = .{ 0xf2, 0xf2, 0xf5 }, + .string = .{ 0xd4, 0xd0, 0xc4 }, + .number = .{ 0xbf, 0xc0, 0xc6 }, + .comment = .{ 0x8a, 0x8b, 0x94 }, + .line_number = .{ 0x55, 0x56, 0x5e }, + .line_number_current = .{ 0x80, 0x81, 0x8b }, + .@"error" = .{ 0xff, 0x7b, 0x72 }, + .warning = .{ 0xe3, 0xb3, 0x41 }, + .info = .{ 0x79, 0xc0, 0xff }, + .hint = .{ 0xa5, 0xd6, 0xa7 }, + .ansi = .{ + .{ 0x1e, 0x1f, 0x24 }, .{ 0xff, 0x7b, 0x72 }, .{ 0x7e, 0xe7, 0x87 }, .{ 0xe3, 0xb3, 0x41 }, + .{ 0x79, 0xc0, 0xff }, .{ 0xd2, 0xa8, 0xff }, .{ 0x76, 0xe3, 0xea }, .{ 0xbf, 0xc0, 0xc6 }, + .{ 0x7b, 0x7d, 0x86 }, .{ 0xff, 0xa1, 0x98 }, .{ 0xa5, 0xf0, 0xb0 }, .{ 0xf2, 0xcc, 0x60 }, + .{ 0xa5, 0xd6, 0xff }, .{ 0xe2, 0xc5, 0xff }, .{ 0xb3, 0xf0, 0xff }, .{ 0xf2, 0xf2, 0xf5 }, + }, +}; diff --git a/core/themes/okabe.zig b/core/themes/okabe.zig new file mode 100644 index 00000000..ba8b1888 --- /dev/null +++ b/core/themes/okabe.zig @@ -0,0 +1,32 @@ +//! pardes okabe: colour-blind safe (DESIGN.md part D): Okabe and Ito's +//! eight hues, lightened for a dark page. Added is blue, deleted vermilion, +//! errors vermilion and warnings yellow: nothing says red against green. For +//! the 8 % of men with a colour vision deficiency, and anyone reading diffs. +pub const theme = .{ + .name = "okabe", + .page = .{ 0x0e, 0x12, 0x18 }, + .text = .{ 0xd8, 0xde, 0xe8 }, + .tag = .{ 0x1b, 0x22, 0x2c }, + .tag_text = .{ 0xa9, 0xb4, 0xc4 }, + .accent = .{ 0x56, 0xb4, 0xe9 }, + .selection = .{ 0x27, 0x41, 0x5e }, + .selection_text = .{ 0xee, 0xf3, 0xfa }, + .keyword = .{ 0x6c, 0xc0, 0xf0 }, + .string = .{ 0x3c, 0xcf, 0xa4 }, + .number = .{ 0xf0, 0xa8, 0x30 }, + .comment = .{ 0xd7, 0xcf, 0x7a }, + .line_number = .{ 0x4e, 0x58, 0x66 }, + .line_number_current = .{ 0x7d, 0x88, 0x98 }, + .@"error" = .{ 0xff, 0x8a, 0x4c }, + .warning = .{ 0xf0, 0xe4, 0x42 }, + .info = .{ 0x8c, 0xc8, 0xf0 }, + .hint = .{ 0xe5, 0x94, 0xc8 }, + .added = .{ 0x56, 0xb4, 0xe9 }, + .deleted = .{ 0xff, 0x8a, 0x4c }, + .ansi = .{ + .{ 0x1b, 0x22, 0x2c }, .{ 0xff, 0x8a, 0x4c }, .{ 0x3c, 0xcf, 0xa4 }, .{ 0xf0, 0xe4, 0x42 }, + .{ 0x56, 0xb4, 0xe9 }, .{ 0xe5, 0x94, 0xc8 }, .{ 0x8f, 0xd8, 0xf0 }, .{ 0xc4, 0xcc, 0xd8 }, + .{ 0x73, 0x7e, 0x8e }, .{ 0xff, 0xab, 0x7c }, .{ 0x6f, 0xe0, 0xbd }, .{ 0xf6, 0xee, 0x80 }, + .{ 0x86, 0xcc, 0xf2 }, .{ 0xf0, 0xb4, 0xda }, .{ 0xb4, 0xe6, 0xf6 }, .{ 0xee, 0xf3, 0xfa }, + }, +}; diff --git a/core/themes/sepia.zig b/core/themes/sepia.zig new file mode 100644 index 00000000..06cf96c1 --- /dev/null +++ b/core/themes/sepia.zig @@ -0,0 +1,30 @@ +//! pardes sepia: long reading by daylight (DESIGN.md part D). Warm paper, +//! brown-black ink, earth hues, a calm comment that still reads 5.9:1, and a +//! cool grey-blue selection so the hits keep their amber. For prose, docs and +//! PDFs side by side, and long sessions where white paper glares. +pub const theme = .{ + .name = "sepia", + .page = .{ 0xf4, 0xec, 0xdb }, + .text = .{ 0x3a, 0x2e, 0x22 }, + .tag = .{ 0xe6, 0xd8, 0xba }, + .tag_text = .{ 0x4b, 0x3d, 0x2b }, + .accent = .{ 0xa0, 0x56, 0x2a }, + .selection = .{ 0xc9, 0xd4, 0xdc }, + .selection_text = .{ 0x23, 0x1a, 0x10 }, + .keyword = .{ 0x94, 0x35, 0x1c }, + .string = .{ 0x4c, 0x6a, 0x1f }, + .number = .{ 0x7b, 0x4b, 0x9a }, + .comment = .{ 0x6a, 0x57, 0x3e }, + .line_number = .{ 0xa8, 0x98, 0x7c }, + .line_number_current = .{ 0x76, 0x65, 0x4b }, + .@"error" = .{ 0xb3, 0x26, 0x1e }, + .warning = .{ 0x8a, 0x5a, 0x00 }, + .info = .{ 0x2f, 0x5f, 0x8f }, + .hint = .{ 0x3f, 0x6f, 0x5f }, + .ansi = .{ + .{ 0xe6, 0xd8, 0xba }, .{ 0xb3, 0x26, 0x1e }, .{ 0x4c, 0x6a, 0x1f }, .{ 0x8a, 0x5a, 0x00 }, + .{ 0x2f, 0x5f, 0x8f }, .{ 0x7b, 0x4b, 0x9a }, .{ 0x2f, 0x6f, 0x6a }, .{ 0x5a, 0x4a, 0x36 }, + .{ 0x7a, 0x68, 0x4b }, .{ 0xc1, 0x39, 0x28 }, .{ 0x52, 0x75, 0x17 }, .{ 0x8f, 0x60, 0x00 }, + .{ 0x36, 0x6d, 0xa2 }, .{ 0x88, 0x54, 0xa7 }, .{ 0x29, 0x76, 0x71 }, .{ 0x23, 0x1a, 0x10 }, + }, +}; diff --git a/runtime/macos.zig b/runtime/macos.zig index 2778507f..0e47fb02 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -479,7 +479,7 @@ export fn pardes_animating() bool { export fn pardes_theme_bg() u32 { pardes.turn.wake(); defer pardes.turn.rest(); - const page = if (state) |*st| st.core.theme().bg else pardes.themes[0].page; + const page = if (state) |*st| st.core.theme().bg else pardes.themes[pardes.colors.default_theme].page; const bg = page orelse return color_default; return @as(u32, bg[0]) << 16 | @as(u32, bg[1]) << 8 | bg[2]; } diff --git a/test/consumer/lib.zig b/test/consumer/lib.zig index 68134cc3..2832bdf1 100644 --- a/test/consumer/lib.zig +++ b/test/consumer/lib.zig @@ -88,7 +88,7 @@ test "a C and a Zig source are coloured, outlined and walked as pardes has them, try std.testing.expectEqual(null, pardes.parse("main.rs", "fn main() {}")); const orchard = pardes.theme("Orchard").?; - try std.testing.expectEqual(orchard, &pardes.themes[0]); + try std.testing.expectEqual(orchard, &pardes.themes[pardes.default_theme]); try std.testing.expectEqual([3]u8{ 0x0d, 0x14, 0x10 }, pardes.page(orchard)); try std.testing.expectEqual([3]u8{ 0xe5, 0xee, 0xe5 }, pardes.ink(orchard)); try std.testing.expectEqual([3]u8{ 0xc9, 0xa7, 0xed }, pardes.synInk(orchard, .keyword).?); diff --git a/test/process/tty_themes.zig b/test/process/tty_themes.zig index 1975c02b..8c49b77f 100644 --- a/test/process/tty_themes.zig +++ b/test/process/tty_themes.zig @@ -17,6 +17,10 @@ pub const cases = .{ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "theme"); defer t.deinit(); + // From the ring's first, dark (the host's page: the tty's own cells), + // through pardes's own, those after a classic and acme's, into the first + // faithful ports (DESIGN.md E's groups). + try t.config("Theme dark"); try t.file("t.txt", "x"); try t.start(31, 100, &.{ "-n", "3" }); try t.wait(8000, "t.txt"); @@ -30,13 +34,23 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("esc"); try t.settle(100); try t.stable(700, 10000); + try t.snap("dark"); + try t.style("dark"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); + try t.snap("light"); + try t.style("light"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); try t.snap("orchard"); try t.style("orchard"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); - try t.snap("dusk"); - try t.style("dusk"); + try t.snap("orchard-black"); + try t.style("orchard-black"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); @@ -45,6 +59,21 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); + try t.snap("mono"); + try t.style("mono"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); + try t.snap("okabe"); + try t.style("okabe"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); + try t.snap("sepia"); + try t.style("sepia"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); try t.snap("paper"); try t.style("paper"); try t.press("middle", "@NextColor", 1); @@ -55,8 +84,13 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); - try t.snap("atelier"); - try t.style("atelier"); + try t.snap("dusk"); + try t.style("dusk"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); + try t.snap("lapis"); + try t.style("lapis"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); @@ -65,6 +99,16 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); + try t.snap("forge-black"); + try t.style("forge-black"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); + try t.snap("forge-soft"); + try t.style("forge-soft"); + try t.press("middle", "@NextColor", 1); + try t.release("middle", "@NextColor", 1); + try t.stable(700, 10000); try t.snap("lagoon"); try t.style("lagoon"); try t.press("middle", "@NextColor", 1); @@ -90,28 +134,13 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); - try t.snap("forge-black"); - try t.style("forge-black"); - try t.press("middle", "@NextColor", 1); - try t.release("middle", "@NextColor", 1); - try t.stable(700, 10000); - try t.snap("forge-soft"); - try t.style("forge-soft"); - try t.press("middle", "@NextColor", 1); - try t.release("middle", "@NextColor", 1); - try t.stable(700, 10000); - try t.snap("orchard-black"); - try t.style("orchard-black"); - try t.press("middle", "@NextColor", 1); - try t.release("middle", "@NextColor", 1); - try t.stable(700, 10000); try t.snap("acme"); try t.style("acme"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); - try t.snap("lapis"); - try t.style("lapis"); + try t.snap("atelier"); + try t.style("atelier"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); @@ -120,7 +149,6 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); - // After orchard_black: acme and lapis, then the first faithful ports. try t.snap("solarized-dark"); try t.style("solarized-dark"); try t.done(); @@ -138,10 +166,10 @@ fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { // running it and stopping. There is still no preview state, nothing to confirm // and nothing to cancel: the row you ran is the theme you have. // -// The whole ring is in the buffer, in sections: the fifteen native themes, -// acme and lapis, the faithful ports a family at a time, the legacy helix and -// dark, then everything exported from the vendored helix .toml and zed .json -// files, sorted. The colors below are +// The whole ring is in the buffer, in sections (DESIGN.md E): pardes's own, +// those after a classic, acme's, the faithful ports a family at a time, the +// captured helix, then everything imported from the vendored helix .toml and +// zed .json files, a family at a time and the lone ones last, sorted. The colors below are // read with snapstyle, so this proves the generated themes are real data and // not just names in a list. fn themesel(gpa: std.mem.Allocator, exe: [:0]const u8) !void { @@ -159,66 +187,77 @@ fn themesel(gpa: std.mem.Allocator, exe: [:0]const u8) !void { // fresh output buffer is where the walk's ring starts, so the first n goes // into the list and every one after it carries on down it. try t.key("space t t"); - try t.wait(10000, "Theme orchard"); + try t.wait(10000, "Theme dark"); try t.stable(700, 15000); try t.snap("list"); - // n selects row 1 whole and Tab runs it: `Theme orchard`, which is already the - // boot theme, so only the selection moves. That is the honest first step — an - // idempotent command has to be safe to run. + // n selects row 1 whole and Tab runs it: `Theme dark`, the ring's first; + // the theme changes under the cursor one row at a time, a section's + // heading and its blank line skipped (Output.isWalkRow). + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-dark"); + try t.style("step-dark"); + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-light"); + try t.style("step-light"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-orchard"); try t.style("step-orchard"); - // ...and now the theme really does change under the cursor, one row at a time try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-dusk"); - try t.style("step-dusk"); - // Selection alone can skip rows without previewing or applying their themes. - // Four steps reach atelier, the Acme homage; Tab then applies it. - try t.key("space j n"); + try t.snap("step-orchard-black"); + try t.style("step-orchard-black"); try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-ink"); + try t.style("step-ink"); try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-mono"); + try t.style("step-mono"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-atelier"); - try t.style("step-atelier"); + try t.snap("step-okabe"); + try t.style("step-okabe"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-forge"); - try t.style("step-forge"); + try t.snap("step-sepia"); + try t.style("step-sepia"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-lagoon"); - try t.style("step-lagoon"); + try t.snap("step-paper"); + try t.style("step-paper"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-solarium"); - try t.style("step-solarium"); + try t.snap("step-daybreak"); + try t.style("step-daybreak"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-spectrum"); - try t.style("step-spectrum"); + try t.snap("step-dusk"); + try t.style("step-dusk"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-harvest"); - try t.style("step-harvest"); + try t.snap("step-lapis"); + try t.style("step-lapis"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-clay"); - try t.style("step-clay"); - // The three native contrast variants precede acme and lapis, and then the first - // ported family's section. Its heading - // and blank separator are not stops in the n/N command walk. + try t.snap("step-forge"); + try t.style("step-forge"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); @@ -232,8 +271,28 @@ fn themesel(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-orchard-black"); - try t.style("step-orchard-black"); + try t.snap("step-lagoon"); + try t.style("step-lagoon"); + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-solarium"); + try t.style("step-solarium"); + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-spectrum"); + try t.style("step-spectrum"); + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-harvest"); + try t.style("step-harvest"); + try t.key("space j n"); + try t.key("tab"); + try t.stable(700, 15000); + try t.snap("step-clay"); + try t.style("step-clay"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); @@ -242,17 +301,13 @@ fn themesel(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); - try t.snap("step-lapis"); - try t.style("step-lapis"); + try t.snap("step-atelier"); + try t.style("step-atelier"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-dark-plus"); try t.style("step-dark-plus"); - // across the Visual Studio Code section into Solarized: a section heading and - // its blank line are skipped like the first. (The imported half, past the - // legacy section, is sorted by name, so the ring is the same everywhere - // whatever order the directory read handed the files over in.) try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); diff --git a/tools/gen_themes.zig b/tools/gen_themes.zig index c369b744..62aafcf5 100644 --- a/tools/gen_themes.zig +++ b/tools/gen_themes.zig @@ -124,8 +124,12 @@ pub fn main(init: std.process.Init) !void { t.hit = f.hit; } // sorted, so the ring's tail is the same on every machine whatever order - // the directory happened to be read in - std.mem.sort(Theme, themes.items, {}, byName); + // the directory happened to be read in: a family at a time (a name's + // first word, two themes or more), the lone ones after every family, so + // the picker heads each family once (colors.zig `import_heads`) + var families: std.StringHashMapUnmanaged(u32) = .empty; + for (themes.items) |t| (try families.getOrPutValue(arena, family(t.name), 0)).value_ptr.* += 1; + std.mem.sort(Theme, themes.items, &families, byFamily); var dir = try std.Io.Dir.cwd().openDir(io, args[1], .{}); defer dir.close(io); @@ -150,7 +154,14 @@ fn write(io: std.Io, dir: std.Io.Dir, arena: std.mem.Allocator, stem: []const u8 try file.writeStreamingAll(io, text); } -fn byName(_: void, a: Theme, b: Theme) bool { +fn family(name: []const u8) []const u8 { + return name[0 .. std.mem.indexOfScalar(u8, name, '_') orelse name.len]; +} + +fn byFamily(families: *const std.StringHashMapUnmanaged(u32), a: Theme, b: Theme) bool { + const lone_a = families.get(family(a.name)).? < 2; + const lone_b = families.get(family(b.name)).? < 2; + if (lone_a != lone_b) return lone_b; return std.mem.order(u8, a.name, b.name) == .lt; } -- cgit v1.3 From 77b22e7c7623696feb52292bb86839870e20050d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 04:37:03 -0300 Subject: themes, vendor, colors, gen_themes, exec, ctl, dump: DESIGN.md E's 44 themes retired, each name standing for its successor wherever it is still read (the themes programme's L7; DESIGN.md E, F): GONE: 28 helix sources (base16_default_light, base16_terminal, base16_transparent, bogster_light, cyan_light, eldritch_transparent, gruvbox-material, hex_lavender, hex_poison, ingrid, iroaseta, nord_light, nyxvamp-transparent, peachpuff, the six helix seoul256s, term16_dark, term16_light, tokyonight, ttox, ttox_soft, vesper-transparent, zed_onedark, zed_onelight), zed's ayu.json and gruvbox.json (every variant in them retired: ayu_dark/light/mirage_zed, the six gruvbox_*_zed) and their licences (ayu.LICENSE, gruvbox.LICENSE: zed's, covering those files alone; helix's licences each cover a kept theme), seoul256's 238, 239, 252 and 253 (their rows, their citations, their lines in its G4 block); vendor/themes/base/ holds the retired three kept themes inherit from (ayu_dark_helix, hex_steel, nord_helix; the designer's list named seven, but no kept theme inherits seoul256_dark/_light, term16_dark or zed_onedark once their children retire), passed to the generator as `base=` (build/core.zig `vendoredThemes` per directory), read for `inherits`, never rung; THE SUCCESSORS: `colors.retired`, 44 names and the kept one each stands for (the kept twin, the nearest kept seoul256 step, dark or light for the terminal-colour themes, the default where there is none: ingrid), read by `successorOf`: a `Theme` (an init file's line, a click, a /ctl write) naming one wears its successor and says so once, as a notice: "Theme gruvbox_dark_zed was retired: gruvbox instead" (exec.applySettingBuiltin); /ctl takes such a write (ctl.zig); a dump or Restore naming one restores its successor (`colors.restoredIndex`, dump.zig's two readers, which said the same loop twice; one this build has nothing of keeps the theme in effect as before, else the default by name, where it was index 0, dark's now); an unknown name keeps today's path and words; THE RING TEST'S LIST: empty, so gone (`ring_expected` and its bookkeeping: every theme in the ring passes every floor it is held to, or the test names it); RUN (TEST FIRST): colors.zig "a retired theme's name stands for its successor in an init file and a dump, said once; an unknown one leaves the default, in today's words" (an init `Theme gruvbox_dark_zed`, `Theme TTOX` (any case), `Theme ingrid` and `Theme no-such-theme`: gruvbox, dark, orchard and orchard, each with its one message; a dump of a session in acme with `ttox` put in for its theme's name, as an older build's: restored in dark): fails on L5 (gruvbox_dark_zed still in the ring, worn as itself), passes now; "every retired theme's successor is in the ring, and no retired name is" (44); the ring test: 245 of 245 themes pass every floor (289 at L5, 44 retired); "seoul256's eight backgrounds ring in their order"; the G4 test holds every port's file; core-test 1142/1315 (173 skipped: L5's 1140/1313 + the two retirement tests); OUTSIDE my files: build/core.zig (`vendoredThemes` per directory, the base arguments), core/exec.zig (`Theme`'s retired branch, 7 lines), core/ninep/ctl.zig (1 line), core/dump.zig (its two readers, `restoredIndex`); the dump's bytes and layout unchanged and a name in this build's ring restored as before (restoredIndex's first loop is the old one), so a join or a restore within a build never reaches the new branches: no fuzz or soak Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- build/core.zig | 9 +- core/colors.zig | 167 +- core/dump.zig | 10 +- core/exec.zig | 7 + core/ninep/ctl.zig | 2 +- core/themes/seoul256.zig | 78 +- tools/gen_themes.zig | 12 +- vendor/themes/ayu.LICENSE | 21 - vendor/themes/ayu.json | 1228 --------------- vendor/themes/ayu_dark_helix.toml | 92 -- vendor/themes/base/ayu_dark_helix.toml | 92 ++ vendor/themes/base/hex_steel.toml | 127 ++ vendor/themes/base/nord_helix.toml | 199 +++ vendor/themes/base16_default_light.toml | 79 - vendor/themes/base16_terminal.toml | 55 - vendor/themes/base16_transparent.toml | 84 - vendor/themes/bogster_light.toml | 103 -- vendor/themes/cyan_light.toml | 5 - vendor/themes/eldritch_transparent.toml | 7 - vendor/themes/gruvbox-material.toml | 6 - vendor/themes/gruvbox.LICENSE | 21 - vendor/themes/gruvbox.json | 2539 ------------------------------- vendor/themes/hex_lavender.toml | 41 - vendor/themes/hex_poison.toml | 41 - vendor/themes/hex_steel.toml | 127 -- vendor/themes/ingrid.toml | 77 - vendor/themes/iroaseta.toml | 162 -- vendor/themes/nord_helix.toml | 199 --- vendor/themes/nord_light.toml | 90 -- vendor/themes/nyxvamp-transparent.toml | 54 - vendor/themes/peachpuff.toml | 66 - vendor/themes/seoul256-dark-hard.toml | 16 - vendor/themes/seoul256-dark-soft.toml | 15 - vendor/themes/seoul256-dark.toml | 161 -- vendor/themes/seoul256-light-hard.toml | 16 - vendor/themes/seoul256-light-soft.toml | 16 - vendor/themes/seoul256-light.toml | 51 - vendor/themes/term16_dark.toml | 80 - vendor/themes/term16_light.toml | 85 -- vendor/themes/tokyonight.toml | 136 -- vendor/themes/ttox.toml | 33 - vendor/themes/ttox_soft.toml | 37 - vendor/themes/vesper-transparent.toml | 25 - vendor/themes/zed_onedark.toml | 114 -- vendor/themes/zed_onelight.toml | 62 - 45 files changed, 575 insertions(+), 6072 deletions(-) delete mode 100644 vendor/themes/ayu.LICENSE delete mode 100644 vendor/themes/ayu.json delete mode 100644 vendor/themes/ayu_dark_helix.toml create mode 100644 vendor/themes/base/ayu_dark_helix.toml create mode 100644 vendor/themes/base/hex_steel.toml create mode 100644 vendor/themes/base/nord_helix.toml delete mode 100644 vendor/themes/base16_default_light.toml delete mode 100644 vendor/themes/base16_terminal.toml delete mode 100644 vendor/themes/base16_transparent.toml delete mode 100644 vendor/themes/bogster_light.toml delete mode 100644 vendor/themes/cyan_light.toml delete mode 100644 vendor/themes/eldritch_transparent.toml delete mode 100644 vendor/themes/gruvbox-material.toml delete mode 100644 vendor/themes/gruvbox.LICENSE delete mode 100644 vendor/themes/gruvbox.json delete mode 100644 vendor/themes/hex_lavender.toml delete mode 100644 vendor/themes/hex_poison.toml delete mode 100644 vendor/themes/hex_steel.toml delete mode 100644 vendor/themes/ingrid.toml delete mode 100644 vendor/themes/iroaseta.toml delete mode 100644 vendor/themes/nord_helix.toml delete mode 100644 vendor/themes/nord_light.toml delete mode 100644 vendor/themes/nyxvamp-transparent.toml delete mode 100644 vendor/themes/peachpuff.toml delete mode 100644 vendor/themes/seoul256-dark-hard.toml delete mode 100644 vendor/themes/seoul256-dark-soft.toml delete mode 100644 vendor/themes/seoul256-dark.toml delete mode 100644 vendor/themes/seoul256-light-hard.toml delete mode 100644 vendor/themes/seoul256-light-soft.toml delete mode 100644 vendor/themes/seoul256-light.toml delete mode 100644 vendor/themes/term16_dark.toml delete mode 100644 vendor/themes/term16_light.toml delete mode 100644 vendor/themes/tokyonight.toml delete mode 100644 vendor/themes/ttox.toml delete mode 100644 vendor/themes/ttox_soft.toml delete mode 100644 vendor/themes/vesper-transparent.toml delete mode 100644 vendor/themes/zed_onedark.toml delete mode 100644 vendor/themes/zed_onelight.toml (limited to 'tools') diff --git a/build/core.zig b/build/core.zig index f9cb450f..c787fdc8 100644 --- a/build/core.zig +++ b/build/core.zig @@ -131,9 +131,11 @@ fn patchesHash(b: *std.Build, io: std.Io) u64 { return h; } -fn vendoredThemes(b: *std.Build, io: std.Io) []const []const u8 { +/// The theme sources in `sub` of vendor/themes, sorted: the ring's (`.`), +/// or the retired ones kept themes inherit from (`base`, read, never rung). +fn vendoredThemes(b: *std.Build, io: std.Io, sub: []const u8) []const []const u8 { var names: std.ArrayList([]const u8) = .empty; - var dir = b.root.root_dir.handle.openDir(io, "vendor/themes", .{ .iterate = true }) catch @panic("open vendor/themes"); + var dir = b.root.root_dir.handle.openDir(io, b.pathJoin(&.{ "vendor/themes", sub }), .{ .iterate = true }) catch @panic("open vendor/themes"); defer dir.close(io); var it = dir.iterate(); while (it.next(io) catch @panic("read vendor/themes")) |e| { @@ -161,7 +163,8 @@ pub fn generatedThemes(b: *std.Build, io: std.Io, target: std.Build.ResolvedTarg }); const run_theme_gen = b.addRunArtifact(theme_gen); const themes_out = run_theme_gen.addOutputDirectoryArg("themes"); - for (vendoredThemes(b, io)) |name| run_theme_gen.addFileArg(b.path(b.fmt("vendor/themes/{s}", .{name}))); + for (vendoredThemes(b, io, ".")) |name| run_theme_gen.addFileArg(b.path(b.fmt("vendor/themes/{s}", .{name}))); + for (vendoredThemes(b, io, "base")) |name| run_theme_gen.addPrefixedFileArg("base=", b.path(b.fmt("vendor/themes/base/{s}", .{name}))); return b.createModule(.{ .target = target, .optimize = optimize, diff --git a/core/colors.zig b/core/colors.zig index 9091760f..960123e2 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -1092,7 +1092,7 @@ pub const Grounds = struct { } }; -/// One family, its twelve backgrounds a theme each (`curated`). +/// One family, its eight backgrounds a theme each (`curated`). const seoul256 = @import("themes/seoul256.zig"); const curated = struct { @@ -1156,10 +1156,6 @@ const curated = struct { pub const seoul256_dark_235 = seoul256.dark(235); pub const seoul256_dark_236 = seoul256.dark(236); pub const seoul256_dark_237 = seoul256.dark(237); - pub const seoul256_dark_238 = seoul256.dark(238); - pub const seoul256_dark_239 = seoul256.dark(239); - pub const seoul256_light_252 = seoul256.light(252); - pub const seoul256_light_253 = seoul256.light(253); pub const seoul256_light_254 = seoul256.light(254); pub const seoul256_light_255 = seoul256.light(255); pub const seoul256_light_256 = seoul256.light(256); @@ -1271,6 +1267,71 @@ const theme_groups = [_]ThemeGroup{ /// The theme a session starts in, by name: never a place in the ring. pub const default_theme = indexOfTheme("orchard"); +/// The themes retired (DESIGN.md E, under the user's ruling of 2026-11-25) +/// and the kept one each stands for where its name is still read: an init +/// file's `Theme`, a /ctl write, a dump; null, the default. +const retired = [_]struct { []const u8, ?[]const u8 }{ + .{ "seoul256_dark_238", "seoul256_dark_237" }, + .{ "seoul256_dark_239", "seoul256_dark_237" }, + .{ "seoul256_light_252", "seoul256_light_254" }, + .{ "seoul256_light_253", "seoul256_light_254" }, + .{ "ayu_dark_helix", "ayu_dark" }, + .{ "ayu_dark_zed", "ayu_dark" }, + .{ "ayu_light_zed", "ayu_light" }, + .{ "ayu_mirage_zed", "ayu_mirage" }, + .{ "base16_default_light", "base16_default_dark" }, + .{ "base16_terminal", "dark" }, + .{ "base16_transparent", "base16_default_dark" }, + .{ "bogster_light", "bogster" }, + .{ "cyan_light", "jetbrains_cyan_light" }, + .{ "eldritch_transparent", "eldritch" }, + .{ "gruvbox_dark_hard_zed", "gruvbox_dark_hard" }, + .{ "gruvbox_dark_soft_zed", "gruvbox_dark_soft" }, + .{ "gruvbox_dark_zed", "gruvbox" }, + .{ "gruvbox_light_hard_zed", "gruvbox_light_hard" }, + .{ "gruvbox_light_soft_zed", "gruvbox_light_soft" }, + .{ "gruvbox_light_zed", "gruvbox_light" }, + .{ "gruvbox_material", "gruvbox_material_dark_medium" }, + .{ "hex_lavender", "hex_toxic" }, + .{ "hex_poison", "hex_toxic" }, + .{ "hex_steel", "hex_toxic" }, + .{ "ingrid", null }, + .{ "iroaseta", "ao" }, + .{ "nord_helix", "nord" }, + .{ "nord_light", "nord" }, + .{ "nyxvamp_transparent", "nyxvamp_veil" }, + .{ "peachpuff", "dark" }, + .{ "seoul256_dark", "seoul256_dark_235" }, + .{ "seoul256_dark_hard", "seoul256_dark_233" }, + .{ "seoul256_dark_soft", "seoul256_dark_237" }, + .{ "seoul256_light", "seoul256_light_254" }, + .{ "seoul256_light_hard", "seoul256_light_256" }, + .{ "seoul256_light_soft", "seoul256_light_254" }, + .{ "term16_dark", "dark" }, + .{ "term16_light", "light" }, + .{ "tokyonight", "tokyonight_night" }, + .{ "ttox", "dark" }, + .{ "ttox_soft", "dark" }, + .{ "vesper_transparent", "vesper" }, + .{ "zed_onedark", "one_dark_zed" }, + .{ "zed_onelight", "one_light_zed" }, +}; + +/// The ring's place for the kept theme a retired `name` stands for, +/// whatever its case. +pub fn successorOf(name: []const u8) ?usize { + for (retired) |r| if (std.ascii.eqlIgnoreCase(r[0], name)) return if (r[1]) |kept| themeIndex(kept).? else default_theme; + return null; +} + +/// The theme a dump naming `name` restores: that one, a retired one's +/// successor, else the one in effect (`was`) where this build has it, else +/// the default. +pub fn restoredIndex(name: []const u8, was: usize) usize { + for (themes, 0..) |t, i| if (std.mem.eql(u8, t.name, name)) return i; + return successorOf(name) orelse if (was < themes.len) was else default_theme; +} + fn indexOfTheme(comptime name: []const u8) usize { return comptime blk: { @setEvalBranchQuota(100000); @@ -2030,11 +2091,10 @@ test "the picker's sections run in ring order and cover it" { for (themes[lone + 1 ..], lone + 1..) |_, i| try std.testing.expectEqual(null, groupAt(i)); } -test "seoul256's twelve backgrounds ring in their order, after Catppuccin and before Zenbones" { +test "seoul256's eight backgrounds ring in their order, after Catppuccin and before Zenbones" { const names = [_][]const u8{ - "seoul256_dark_233", "seoul256_dark_234", "seoul256_dark_235", "seoul256_dark_236", - "seoul256_dark_237", "seoul256_dark_238", "seoul256_dark_239", "seoul256_light_252", - "seoul256_light_253", "seoul256_light_254", "seoul256_light_255", "seoul256_light_256", + "seoul256_dark_233", "seoul256_dark_234", "seoul256_dark_235", "seoul256_dark_236", + "seoul256_dark_237", "seoul256_light_254", "seoul256_light_255", "seoul256_light_256", }; const first = indexOfTheme("seoul256_dark_233"); for (names, themes[first..][0..names.len]) |name, t| try std.testing.expectEqualStrings(name, t.name); @@ -2658,21 +2718,6 @@ fn ringFailures(th: *const Theme, c: *const Chrome, designed_here: bool) std.Enu return f; } -/// The themes that fail a check they are held to until the line that fixes -/// them lands (DESIGN.md E1, F): the list shrinks as each does, and a theme -/// on it that passes fails the test, so it is taken off. -const ring_expected = [_]struct { []const u8, []const u8 }{ - // L7: retired. - .{ "seoul256_dark_238", "L7: retired" }, - .{ "seoul256_dark_239", "L7: retired" }, - .{ "seoul256_light_252", "L7: retired" }, - .{ "seoul256_light_253", "L7: retired" }, - .{ "hex_lavender", "L7: retired" }, - .{ "hex_poison", "L7: retired" }, - .{ "hex_steel", "L7: retired" }, - .{ "ingrid", "L7: retired" }, -}; - /// The soft natives: their text 4.5-7:1 by design, held at AA, never the /// professional 7:1, and never retuned (the coordinator's ruling; solarium /// is the user's). @@ -2684,7 +2729,6 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati const ports = comptime indexOfTheme("dark_plus"); const helix = comptime indexOfTheme("helix"); var passing: usize = 0; - var wrong: usize = 0; for (&themes, 0..) |*th, i| { const c = Chrome.of(th); // The original's own (B1.5): never moved. @@ -2707,24 +2751,17 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati if (check.original() and !ours and !(std.mem.startsWith(u8, @tagName(check), "ansi") and th.ansi == null)) continue; held.insert(check); } - const expected = for (ring_expected) |e| { - if (std.mem.eql(u8, e[0], th.name)) break true; - } else false; - if (held.count() == 0) passing += 1; - if (held.count() > 0 and !expected) { - wrong += 1; - std.debug.print("{s} fails:", .{th.name}); - var failed = held.iterator(); - while (failed.next()) |check| std.debug.print(" {s}", .{@tagName(check)}); - std.debug.print("\n", .{}); - } - if (held.count() == 0 and expected) { - wrong += 1; - std.debug.print("{s} passes now: take it off ring_expected\n", .{th.name}); + if (held.count() == 0) { + passing += 1; + continue; } + std.debug.print("{s} fails:", .{th.name}); + var failed = held.iterator(); + while (failed.next()) |check| std.debug.print(" {s}", .{@tagName(check)}); + std.debug.print("\n", .{}); } - std.debug.print("ring floors: {d} of {d} themes pass; {d} on the expected list\n", .{ passing, themes.len, ring_expected.len }); - try std.testing.expectEqual(0, wrong); + std.debug.print("ring floors: {d} of {d} themes pass\n", .{ passing, themes.len }); + try std.testing.expectEqual(themes.len, passing); } /// A faithful port's own colours pardes moves where they miss a floor: its @@ -2873,3 +2910,51 @@ test "a theme file in the old names, a user's own or an older DumpThemes', and D try std.testing.expect(!loadThemeFile(p, p.theme_file_generation, ".{ .name = \"x\", .page = null, .txet = null }")); try std.testing.expectEqualStrings("one_dark_zed", p.theme().name); } + +test "a retired theme's name stands for its successor in an init file and a dump, said once; an unknown one leaves the default, in today's words (DESIGN.md E)" { + const gpa = std.testing.allocator; + const Said = struct { + fn count(p: *const Pardes, needle: []const u8) usize { + var n: usize = 0; + for (p.messages.log[0..p.messages.len]) |m| { + if (std.mem.indexOf(u8, m.text[0..m.len], needle) != null) n += 1; + } + return n; + } + }; + for ([_][3][]const u8{ + .{ "gruvbox_dark_zed", "gruvbox", "Theme gruvbox_dark_zed was retired: gruvbox instead" }, + .{ "TTOX", "dark", "Theme TTOX was retired: dark instead" }, + // a retired one with no kept twin: the default + .{ "ingrid", "orchard", "Theme ingrid was retired: orchard instead" }, + .{ "no-such-theme", "orchard", "Theme: no theme \"no-such-theme\"; like it: " }, + }) |case| { + const line = try std.fmt.allocPrint(gpa, "Theme {s}\n", .{case[0]}); + defer gpa.free(line); + const p = try Pardes.init(gpa, .{ .tty_only = true, .startup_config = line }); + defer p.deinit(); + try std.testing.expectEqualStrings(case[1], p.theme().name); + try std.testing.expectEqual(1, Said.count(p, case[2])); + } + // A dump naming one (this build writes none: a dump of an older one, + // its theme's name put in): its successor. + const source = try Pardes.init(gpa, .{ .tty_only = true, .startup_config = "Theme acme\n" }); + defer source.deinit(); + try @import("dump.zig").dumpState(source); + const bytes = try gpa.dupe(u8, source.dump_out.?); + defer gpa.free(bytes); + const at = std.mem.indexOf(u8, bytes, "acme").?; + try std.testing.expect(std.mem.indexOfPos(u8, bytes, at + 4, "acme") == null); + @memcpy(bytes[at..][0..4], "ttox"); + const restored = try @import("dump.zig").initFromDump(gpa, .{ .tty_only = true }, bytes); + defer restored.deinit(); + try std.testing.expectEqualStrings("dark", restored.theme().name); +} + +test "every retired theme's successor is in the ring, and no retired name is" { + for (retired) |r| { + try std.testing.expectEqual(null, themeIndex(r[0])); + if (r[1]) |kept| try std.testing.expect(themeIndex(kept) != null); + } + try std.testing.expectEqual(44, retired.len); +} diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..69eda35e 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -422,10 +422,8 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: const was = try l.get(OnDisk); if (on_disk) |out| out.* = was; const theme = try l.get([]const u8); - // This build's place for that theme; one it has not, its first. - p.settings.theme = for (colors.themes, 0..) |t, i| { - if (std.mem.eql(u8, t.name, theme)) break i; - } else if (p.settings.theme < colors.themes.len) p.settings.theme else 0; + // This build's place for that theme, a retired one's successor's. + p.settings.theme = colors.restoredIndex(theme, p.settings.theme); // A mount this process was started with stands; one of the same name // to elsewhere is refused, never silently put over it. for (mounts) |m| { @@ -515,9 +513,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* if (on_disk) |out| out.* = was; const theme: []const u8 = if (try walk.Get.member(root, "theme")) |c| try l.get([]const u8, c) else ""; defer gpa.free(theme); - p.settings.theme = for (colors.themes, 0..) |t, i| { - if (std.mem.eql(u8, t.name, theme)) break i; - } else if (p.settings.theme < colors.themes.len) p.settings.theme else 0; + p.settings.theme = colors.restoredIndex(theme, p.settings.theme); for (mounts) |m| { const existing = for (p.fs.mounts.items) |e| { if (std.mem.eql(u8, e.name, m.name)) break e; diff --git a/core/exec.zig b/core/exec.zig index a56c17f9..44cfea64 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -1008,6 +1008,13 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Settings.Setting, arg: ?[ .theme => { const want = std.mem.trim(u8, arg orelse return, " \t\r\n"); if (colors.themeIndex(want)) |i| return colors.setThemeIndex(p, i); + // A retired theme's name (DESIGN.md E): its successor, said. + if (colors.successorOf(want)) |i| { + colors.setThemeIndex(p, i); + var said: pardes.Kind.Buf(128) = .{}; + _ = pardes.Messages.say(p, .notice, v.active, said.print("Theme {s} was retired: {s} instead", .{ want[0..@min(want.len, 40)], colors.themes[i].name })); + return; + } // A failure is said, the init file's too (applyStartupConfig // logs it with its line): never silent. // All of it within the 128 bytes a 9P error carries, so a write diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 2411b20f..80d1176c 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -555,7 +555,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? if (arg.len == 0 and builtins.registry.requiresArg(b)) return refuse(p, req, "wrong #args in control message", line); const setting = config.Settings.find(word) orelse return null; const takes = switch (setting.action) { - .theme => if (pardes.colors.themeIndex(arg) != null) true else { + .theme => if (pardes.colors.themeIndex(arg) != null or pardes.colors.successorOf(arg) != null) true else { // `refuse` quotes the line after it, all in the 128 bytes an // Rerror carries: the names get what is left. const head = "bad value in control message; like it: "; diff --git a/core/themes/seoul256.zig b/core/themes/seoul256.zig index 0c4c17ab..5940d485 100644 --- a/core/themes/seoul256.zig +++ b/core/themes/seoul256.zig @@ -1,7 +1,8 @@ //! Seoul256 (junegunn/seoul256.vim), as close to the original as pardes -//! can draw it: its dark style at each of its backgrounds 233 to 239 and its -//! light one at 252 to 256, a theme each (`dark`, `light`; colors.zig rings -//! them as seoul256_