diff options
Diffstat (limited to 'core/colors.zig')
| -rw-r--r-- | core/colors.zig | 808 |
1 files changed, 492 insertions, 316 deletions
diff --git a/core/colors.zig b/core/colors.zig index eefb2b67..6c83f5c8 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -3,6 +3,7 @@ //! themes programme's), theme files, and switching themes at runtime. //! What a theme says is theme_schema.zig's. const pardes = @import("root.zig"); +const builtin = @import("builtin"); const schema = @import("theme_schema.zig"); pub const Theme = schema.Theme; pub const LegacyTheme = schema.LegacyTheme; @@ -85,7 +86,7 @@ pub const separator_floor: f32 = 1.5; /// the GUI's default ground, and a dark terminal's. pub const null_page: [3]u8 = .{ 18, 18, 18 }; /// The ink of a theme with none, on a dark page and on a light one. -const null_text: [3]u8 = .{ 0xcc, 0xcc, 0xcc }; +pub const null_text: [3]u8 = .{ 0xcc, 0xcc, 0xcc }; const null_text_light: [3]u8 = .{ 0x22, 0x22, 0x22 }; fn separatorOf(th: *const LegacyTheme) [3]u8 { const base = th.border orelse th.scroll_track; @@ -552,10 +553,13 @@ pub const Chrome = struct { selection_secondary: [3]u8, /// The pointer buttons' sweeps: select, exec, look (acme's meanings). sweeps: [3]Theme.Sweep, - /// Search: a hit's ground, and the current one's ground and ink. + /// Search: a hit's ground, and the current one's ground and ink; a + /// search's last places while its field is no regex, dimmed: the page + /// halfway toward the hit (as `selection_secondary` is the selection's). hit: [3]u8, hit_current: [3]u8, hit_current_text: [3]u8, + hit_faint: [3]u8, add: Diff, del: Diff, /// The Changes layer's lanes, a pin each (`lanes_len` of them), and @@ -584,8 +588,10 @@ pub const Chrome = struct { /// user's, a path, `Keep`), word (computed command words: the text /// toward the ground to 4.5:1, H), dim (hints, meta, forward steps), /// rule (spines), key (the accent: keys, `▶`, the walked word), match - /// (a query's letters), the four severities, and a selection rebuilt - /// on it with its own. + /// (a query's letters), kind (a symbol's kind mark in a list, `t`, + /// `f`: the keyword's hue, which spells a kind in the text, held on the + /// ground and on its selection, a list's cursor row), the four + /// severities, and a selection rebuilt on it with its own. pub const Inks = struct { ground: [3]u8, text: [3]u8, @@ -594,6 +600,7 @@ pub const Chrome = struct { rule: [3]u8, key: [3]u8, match: [3]u8, + kind: [3]u8, severity: [4][3]u8, selection: Selection, }; @@ -696,12 +703,17 @@ pub const Chrome = struct { }; const severity = severitiesOn(page, text, candidates, null); - // R8: the hits' hue and grounds. + // R8: the hits' hue and grounds; a theme's own where it is a ground + // you see and the text reads on: 1.5:1 off the page, or, where the + // text leaves no room for that (no ground 1.5:1 off keeps it its + // floor), 1.1:1 with 0.08 OKLab (R0). const ink_floor = @min(text_floor, contrast(text, page) * 0.9); - const own_hit: ?[3]u8 = if (th.hit) |own| - (if (contrast(own, page) >= hit_floor - 0.01 and contrast(text, own) >= ink_floor - 0.01) own else null) - else - null; + const own_hit: ?[3]u8 = if (th.hit) |own| own: { + const off = contrast(own, page); + const no_room = contrast(text, page) < hit_floor * ink_floor; + const seen = off >= hit_floor - 0.01 or (no_room and off >= 1.1 and oklabDistance(labOf(own), labOf(page)) >= 0.08); + break :own if (seen and contrast(text, own) >= ink_floor - 0.01) own else null; + } else null; var hue = severity[1]; if (own_hit) |own| { hue = own; @@ -725,6 +737,7 @@ pub const Chrome = struct { // ink (vim's IncSearch): room for it in every theme. c.hit_current = hold(hue, &.{page}, text_floor); c.hit_current_text = page; + c.hit_faint = mixOklab(page, c.hit, 0.5); // Every ground's inks; on the tags and the status row, the // tag's selection rebuilt on each where it stands too near it. @@ -791,6 +804,11 @@ pub const Chrome = struct { // R10: the lanes (the accents but green and red, hue-sorted) and // churn's steps from the line numbers' ink to the deleted hue. c.lanes_len = lanesOf(.{ ansi[3], ansi[4], ansi[5], ansi[6], th.number, th.keyword }, .{ th.deleted orelse ansi[1], th.added orelse ansi[2] }, &c.lanes); + // A theme with no accent (a grey one) draws its lanes in one grey. + if (c.lanes_len == 0) { + c.lanes[0] = c.line_number; + c.lanes_len = 1; + } for (&c.heat, 1..) |*h, k| h.* = mixOklab(c.line_number, th.deleted orelse ansi[1], @as(f32, @floatFromInt(k)) / 8); return c; } @@ -971,6 +989,7 @@ fn groundInks(th: *const Theme, ground: [3]u8, text: [3]u8, sel: [3]u8, sel_text .rule = line.toward(Chrome.rule_ink), .key = hold(th.accent, &.{ground}, Chrome.text_floor), .match = hold(hue, &.{ground}, Chrome.text_floor), + .kind = hold(th.keyword, &.{ ground, sel }, Chrome.text_floor), .severity = severity, .selection = .{ .ground = sel, @@ -1044,42 +1063,28 @@ fn hsvApart(a: [3]u8, b: [3]u8) f32 { } /// The ink a syntax class is drawn in; a byte of none keeps its text's own. -pub fn synInk(th: *const LegacyTheme, sy: @import("syntax.zig").Syn) ?[3]u8 { +pub fn synInk(th: *const Theme, sy: @import("syntax.zig").Syn) ?[3]u8 { return switch (sy) { .none => null, - .keyword => th.kw, - .string => th.str, - .number => th.num, + .keyword => th.keyword, + .string => th.string, + .number => th.number, .comment => th.comment, }; } /// The grounds a style byte's high bits name (syntax.ground_add and the -/// rest) in a theme: a row added or removed on a ground a little way from -/// the page toward the theme's green or red (its own ANSI ones where it has -/// a palette), a stronger one, a faint one, and the row's marker in that -/// hue, pushed toward the ink until it reads on the row's ground. Syntax -/// colours are drawn over a ground unchanged. +/// rest) in a theme, for the library: its chrome's added and deleted rows +/// (R10). Syntax colours are drawn over a ground unchanged. pub const Grounds = struct { add: Ground, del: Ground, - pub const Ground = struct { row: [3]u8, emph: [3]u8, line: [3]u8, ink: [3]u8 }; - - pub fn of(th: *const LegacyTheme) Grounds { - const page = th.bg orelse th.tag_bg; - const ink = th.fg orelse th.tag_fg; - const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 }; - const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e }; - return .{ .add = ground(page, ink, green), .del = ground(page, ink, red) }; - } + pub const Ground = Chrome.Diff; - fn ground(page: [3]u8, ink: [3]u8, hue: [3]u8) Ground { - const row = mixOklab(page, hue, 0.18); - var marker = hue; - var step: usize = 0; - while (step < 4 and contrast(marker, row) < 3) : (step += 1) marker = mixOklab(marker, ink, 0.4); - return .{ .row = row, .emph = mixOklab(page, hue, 0.28), .line = mixOklab(page, hue, 0.07), .ink = marker }; + pub fn of(th: *const Theme) Grounds { + const c = Chrome.of(th); + return .{ .add = c.add, .del = c.del }; } /// The ground of a byte's hue, if it has one. @@ -1091,27 +1096,37 @@ 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 { + // 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/ // <name>.zig says where each value came from): `theme_groups`. pub const dark_plus = @import("themes/dark_plus.zig"); @@ -1145,10 +1160,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); @@ -1177,24 +1188,25 @@ 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 in the old names: each file's -/// `theme`, a field it leaves out its default. -fn fold(comptime C: type) [@typeInfo(C).@"struct".decl_names.len]LegacyTheme { +/// A struct of theme files as themes: each file's `theme`, a field it +/// leaves out its default. +fn fold(comptime C: type) [@typeInfo(C).@"struct".decl_names.len]Theme { comptime { @setEvalBranchQuota(400000); - var out: [@typeInfo(C).@"struct".decl_names.len]LegacyTheme = undefined; - const theme_info = @typeInfo(LegacyTheme).@"struct"; + var out: [@typeInfo(C).@"struct".decl_names.len]Theme = undefined; + const theme_info = @typeInfo(Theme).@"struct"; for (@typeInfo(C).@"struct".decl_names, 0..) |d, i| { - var t: LegacyTheme = undefined; + var t: Theme = undefined; const source = @field(C, d).theme; + for (@typeInfo(@TypeOf(source)).@"struct".field_names) |name| if (!@hasField(Theme, name)) + @compileError("theme " ++ d ++ " has no field " ++ name ++ " (core/theme_schema.zig)"); for (theme_info.field_names, theme_info.field_types, theme_info.field_attrs) |name, T, attrs| { @field(t, name) = if (@hasField(@TypeOf(source), name)) - @field(source, name) + as(T, @field(source, name)) else if (attrs.defaultValue(T)) |value| value else @@ -1206,30 +1218,40 @@ fn fold(comptime C: type) [@typeInfo(C).@"struct".decl_names.len]LegacyTheme { } } -/// The ring in the old names: what `Pardes.theme()` hands the surfaces -/// that still read a theme's own fields, until they read `Chrome` (the -/// themes programme's L2 lines). -pub const legacy_themes = fold(curated) ++ fold(@import("generated_themes")); +/// A theme file's literal as the field's type: a struct field by field +/// (acme's sweeps), which a literal's own struct type does not coerce to. +fn as(comptime T: type, comptime value: anytype) T { + return switch (@typeInfo(T)) { + .optional => |o| if (@TypeOf(value) == @TypeOf(null)) null else as(o.child, value), + .array => |a| blk: { + var out: T = undefined; + for (&out, 0..) |*e, i| e.* = as(a.child, value[i]); + break :blk out; + }, + .@"struct" => blk: { + var out: T = undefined; + for (@typeInfo(T).@"struct".field_names) |name| @field(out, name) = as(@FieldType(T, name), @field(value, name)); + break :blk out; + }, + else => value, + }; +} + /// The ring: pardes's own (`native_count` of them), then the imported. -/// The files still speak the old names: renamed here, at comptime. -pub const themes: [legacy_themes.len]Theme = blk: { - @setEvalBranchQuota(400000); - var out: [legacy_themes.len]Theme = undefined; - for (&out, legacy_themes) |*t, old| t.* = .fromLegacy(old); - break :blk out; -}; +pub const themes = fold(curated) ++ fold(@import("generated_themes")); /// The first `native_count` of `themes` are pardes's own; the rest imported. 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" }, @@ -1243,9 +1265,77 @@ 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"); + +/// 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); @@ -1257,12 +1347,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; + return if (index >= native_count) import_heads[index - native_count] else null; } -/// Original and classic-inspired Pardes palettes precede retained imports. -pub const native_theme_count = 15; +/// 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) @@ -1288,17 +1404,13 @@ pub const ChromeTheme = struct { border: [3]u8, empty_col: [3]u8, search_bg: [3]u8, - search_fg: [3]u8, tag_reading_bg: [3]u8, diagnostic_error: [3]u8, diagnostic_warning: [3]u8, - diagnostic_info: [3]u8, - diagnostic_hint: [3]u8, box: [3]u8, box_dim: [3]u8, column_box: [3]u8, column_box_dim: [3]u8, - lineno: [3]u8, scroll_track: [3]u8, scroll_thumb: [3]u8, roles: Roles, @@ -1307,14 +1419,25 @@ pub const ChromeTheme = struct { /// the surfaces that still read them until they do (the themes /// programme's L2 lines), so no frame moves before its surface does. resolved: Chrome, + /// The theme in the old names (`Pardes.theme()`), for what still reads + /// a theme's own fields: a ThemeFile in them, itself; any other theme's + /// filled from its chrome where the new names derive (`viewOf`). + view: LegacyTheme, /// A theme in the old names' chrome. pub fn fromTheme(th: *const LegacyTheme) ChromeTheme { - return .of(&.fromLegacy(th.*), th); + return .of(&.fromLegacy(th.*), th, .of(&.fromLegacy(th.*))); + } + + /// A theme in the new names' chrome: the ring's, a ThemeFile's. + pub fn ofTheme(theme: *const Theme) ChromeTheme { + const resolved: Chrome = .of(theme); + return .of(theme, &viewOf(theme, &resolved), resolved); } - /// A theme's chrome, from the theme and its old names' view. - pub fn of(theme: *const Theme, th: *const LegacyTheme) ChromeTheme { + /// A theme's chrome, from the theme, its old names' view and what B4 + /// derives of it. + fn of(theme: *const Theme, th: *const LegacyTheme, resolved: Chrome) ChromeTheme { const active_bg = focusTint(th); const active_fg = th.tag_active_fg orelse th.tag_fg; // A name is always tinted: a theme that names no tint gets one of @@ -1336,26 +1459,45 @@ pub const ChromeTheme = struct { .border = separatorOf(th), .empty_col = th.empty_col orelse separatorOf(th), .search_bg = th.search_bg orelse th.sel_bg, - .search_fg = th.search_fg orelse th.sel_fg, .tag_reading_bg = reading, // A theme's error ink, else its palette's red (UX E3). .diagnostic_error = th.diagnostic_error orelse if (th.palette) |pal| pal[1] else (th.fg orelse th.tag_fg), .diagnostic_warning = th.diagnostic_warning orelse (th.fg orelse th.tag_fg), - .diagnostic_info = th.diagnostic_info orelse (th.fg orelse th.tag_fg), - .diagnostic_hint = th.diagnostic_hint orelse (th.fg orelse th.tag_fg), - .box = th.box, + // The focused grip the chrome's (the accent held 3:1, R6). + .box = resolved.grip.focus, .box_dim = th.box_dim, .column_box = th.column_box orelse th.num, .column_box_dim = th.column_box_dim orelse mix(th.column_box orelse th.num, th.tag_bg), - .lineno = th.lineno, .scroll_track = th.scroll_track, .scroll_thumb = th.scroll_thumb, .roles = .of(th, th.tag_bg, active_bg, reading), - .resolved = .of(theme), + .resolved = resolved, + .view = th.*, }; } }; +/// A theme in the new names as the old names say it: the fields they +/// require and the new ones derive, from its chrome. `box_dim`, a resting +/// grip's fill: the tag's own ground where the theme rings its grips itself +/// (acme's clean button, R6), else the resting ring. The focused name the +/// chrome's, unless it lands on the theme's own focused ink, which the old +/// surfaces draw unheld (ferra's #fecdb2): then the plain tag's. +fn viewOf(theme: *const Theme, r: *const Chrome) LegacyTheme { + const fill = if (theme.grip_ring != null) r.tag[0].ground else r.grip.ring; + const own_focus_ink = theme.tag_focus_text orelse theme.tag_text; + const focused_name = if (std.mem.eql(u8, &r.name[1], &own_focus_ink)) r.name[0] else r.name[1]; + return theme.toLegacy(.{ + .sel_fg = r.page.selection.text, + .lineno = r.line_number, + .scroll_track = r.rail, + .scroll_thumb = r.rail_thumb, + .box_dim = fill, + .tag_active_name_fg = focused_name, + .column_box_dim = r.grip.column_rest, + }); +} + /// A tag's ground in the walk UI (UX DESIGN.md D4): the plain tag's, the /// focused one's tint, a reading pane's tint, focused or not (its ink is /// the focused tag's while it has the keyboard). @@ -1381,10 +1523,6 @@ pub const Roles = struct { /// The letters a query matched: an ink, never a ground, 4.5:1 on every /// tag ground and on the selection. match: [3]u8, - /// The body's places and a preview's landing line, and the current - /// one (its matched span): grounds off the page, its ink on them 4.5:1. - hit: [3]u8, - hit_current: [3]u8, /// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and /// the page. err: [3]u8, @@ -1397,8 +1535,6 @@ pub const Roles = struct { pub const rule_floor: f32 = 1.8; pub const rule_ceiling: f32 = 2.5; pub const ink_floor: f32 = 4.5; - pub const hit_floor: f32 = 1.5; - pub const hit_current_floor: f32 = 1.9; pub const reading_distance: f32 = 0.04; pub fn on(r: *const Roles, ground: TagGround) *const RoleInks { @@ -1430,20 +1566,6 @@ pub const Roles = struct { r.key = pushAway(th.box, &tag_grounds, ink_floor); r.match = pushAway(matchHue(th), &tag_grounds, ink_floor); const page = th.bg orelse null_page; - const body_ink = th.fg orelse th.tag_fg; - const dark = relativeLuminance(page) < 0.18; - // The theme's search ground where it stands off the page and the - // body reads on it; else the page a little way toward its hue (the - // warm accent's without one). The current one as far past the hit - // as 32 % is past 18 % (38 past 22 on a light page). - const hue = th.search_bg orelse th.num; - const own = th.search_bg != null and contrast(hue, page) >= hit_floor and contrast(body_ink, hue) >= ink_floor; - const at: f32 = if (own) 1 else if (dark) 0.18 else 0.22; - r.hit = if (own) hue else hitOf(page, hue, body_ink, at, hit_floor); - const past: f32 = if (dark) 0.32 / 0.18 else 0.38 / 0.22; - r.hit_current = hitOf(page, hue, body_ink, at * past, hit_current_floor); - // Never fainter than the hit, where the ink holds both short. - if (contrast(r.hit_current, page) < contrast(r.hit, page)) r.hit_current = r.hit; const message_grounds = [_][3]u8{ plain, focused, reading, page }; const ink = th.fg orelse th.tag_fg; r.err = pushAway(th.diagnostic_error orelse if (th.palette) |pal| pal[1] else ink, &message_grounds, ink_floor); @@ -1546,48 +1668,6 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 { return best; } -/// A ground off `page` toward `hue` at `t` (past 1, beyond the hue, as far -/// as the gamut goes), held where the body's `ink` reads on it at 4.5:1 -/// (or its own on the page, where that is less); on toward the hue, the -/// least way that stands off the page at `floor`, where the ink still -/// reads on it; else moved on toward the ink until it stands off the page -/// at `floor`, as far as the ink allows. -fn hitOf(page: [3]u8, hue: [3]u8, ink: [3]u8, t: f32, floor: f32) [3]u8 { - const a = toOklab(page); - const b = toOklab(hue); - const ink_floor = @min(Roles.ink_floor, contrast(ink, page)); - var k = t; - var c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k }); - while (contrast(ink, c) < ink_floor and k > 0) { - k -= t / 50; - c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k }); - } - // Found by halves, seven mixes: the nearer the hue, the further off - // the page (UX E7 7b: a landing line 1.5:1, its span 1.9:1). - if (contrast(c, page) < floor and k < 1 and contrast(hue, page) >= floor) { - var lo = k; - var hi: f32 = 1; - var far = hue; - for (0..7) |_| { - const mid = (lo + hi) / 2; - const m = fromOklab(.{ a[0] + (b[0] - a[0]) * mid, a[1] + (b[1] - a[1]) * mid, a[2] + (b[2] - a[2]) * mid }); - if (contrast(m, page) < floor) lo = mid else { - hi = mid; - far = m; - } - } - if (contrast(ink, far) >= ink_floor) c = far; - } - const start = c; - var step: f32 = 1; - while (contrast(c, page) < floor and step <= 50) : (step += 1) { - const next = mixOklab(start, ink, step / 100); - if (contrast(ink, next) < ink_floor) break; - c = next; - } - return c; -} - /// A reading pane's tag (UX DESIGN.md D4): the theme's own where it stands /// off the tag, else the tag shifted toward paper yellow by 0.04 in OKLab /// and lighter by half that on a dark tag (darker on a light), so it reads @@ -1765,27 +1845,27 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8) bool { // user's own, an older DumpThemes') is read in them and renamed; its // old names' view is the file itself. var theme: Theme = undefined; - var view: LegacyTheme = undefined; + var chrome: ChromeTheme = undefined; if (inOldNames(source)) { - view = std.zon.parse.fromSlice(LegacyTheme, options) catch |err| return zonFailed(p, request, err, &diagnostics); + const view = std.zon.parse.fromSlice(LegacyTheme, options) catch |err| return zonFailed(p, request, err, &diagnostics); + chrome = .fromTheme(&view); theme = .fromLegacy(view); } else { theme = std.zon.parse.fromSlice(Theme, options) catch |err| return zonFailed(p, request, err, &diagnostics); - const r = Chrome.of(&theme); - view = theme.toLegacy(.{ .sel_fg = r.page.selection.text, .lineno = r.line_number, .scroll_track = r.rail, .scroll_thumb = r.rail_thumb, .box_dim = r.grip.ring }); + chrome = .ofTheme(&theme); } if (theme.name.len == 0 or theme.name.len > 255) { themeFileError(p, request, error.InvalidThemeName); return false; } + var view = chrome.view; view.name = p.gpa.dupe(u8, theme.name) catch |err| { themeFileError(p, request, err); return false; }; - theme.name = view.name; + chrome.view.name = view.name; - p.theme_chrome = .of(&theme, &view); - p.body_chrome = .{ .theme = view, .chrome = p.theme_chrome }; + p.theme_chrome = chrome; const old = p.custom_theme; p.custom_theme = view; if (old) |theme_value| p.gpa.free(theme_value.name); @@ -1822,13 +1902,9 @@ fn inOldNames(source: [:0]const u8) bool { } /// The session's theme's chrome, at its start (Pardes.init, a Restore): -/// never one the window previews (`previewTheme`); the body's copy of it -/// (Core.bodyChrome's, keyed by the theme) made with it, not again at the -/// first frame. +/// never one the window previews (`previewTheme`). pub fn finishThemeInitialization(p: *Pardes) void { - const theme = if (p.custom_theme) |*custom| custom else &legacy_themes[p.settings.theme]; - p.theme_chrome = if (p.custom_theme != null) .fromTheme(theme) else .of(&themes[p.settings.theme], theme); - p.body_chrome = .{ .theme = theme.*, .chrome = p.theme_chrome }; + p.theme_chrome = if (p.custom_theme) |*custom| .fromTheme(custom) else .ofTheme(&themes[p.settings.theme]); } /// Themes near `name`, a line of them, for a Theme given a name there is @@ -1908,16 +1984,14 @@ pub fn previewTheme(p: *Pardes, index: ?usize) void { if (i >= themes.len) return; if (p.theme_preview) |had| if (had == i) return; p.theme_preview = @intCast(i); - p.preview_chrome = .of(&themes[i], &legacy_themes[i]); - p.body_chrome = .{ .theme = legacy_themes[i], .chrome = p.preview_chrome }; + p.preview_chrome = .ofTheme(&themes[i]); } pub fn setThemeIndex(p: *Pardes, index: usize) void { if (index >= themes.len or (p.custom_theme == null and p.theme_file_path.get().len == 0 and index == @as(usize, p.settings.theme))) return; - p.theme_chrome = .of(&themes[index], &legacy_themes[index]); - p.body_chrome = .{ .theme = legacy_themes[index], .chrome = p.theme_chrome }; + p.theme_chrome = .ofTheme(&themes[index]); if (p.custom_theme) |theme_value| { p.custom_theme = null; p.gpa.free(theme_value.name); @@ -1932,13 +2006,14 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void { } test "every native theme's separators stand off its page, and its focus tint off its tag" { - for (legacy_themes[0..native_count]) |*theme| { + for (themes[0..native_count]) |*ring_theme| { + const view = ChromeTheme.ofTheme(ring_theme).view; + const theme = &view; 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. @@ -1949,9 +2024,11 @@ 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 (legacy_themes[first..last]) |*th| { + for (themes[first..last]) |*ring_theme| { + const view = ChromeTheme.ofTheme(ring_theme).view; + const th = &view; const chrome = ChromeTheme.fromTheme(th); const page = th.bg.?; // Written out already adjusted: the run-time lift and push leave @@ -1972,11 +2049,8 @@ test "every faithful port meets pardes's chrome floors in its own colours, with } test "a derived separator or tint keeps the theme's own when it already stands off" { - const forge = &legacy_themes[ - for (legacy_themes[0..native_count], 0..) |t, i| { - if (std.mem.eql(u8, t.name, "forge")) break i; - } else unreachable - ]; + const view = ChromeTheme.ofTheme(&themes[comptime indexOfTheme("forge")]).view; + const forge = &view; const chrome = ChromeTheme.fromTheme(forge); try std.testing.expectEqual(forge.border.?, chrome.border); // forge's own tint is 1.23:1 off its tag: pushed on the way it leans. @@ -2006,22 +2080,34 @@ 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" { +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, legacy_themes[first..][0..names.len]) |name, t| try std.testing.expectEqualStrings(name, t.name); - try std.testing.expectEqualStrings("catppuccin_mocha", legacy_themes[first - 1].name); - try std.testing.expectEqualStrings("zenbones_light", legacy_themes[first + names.len].name); + for (names, themes[first..][0..names.len]) |name, t| try std.testing.expectEqualStrings(name, t.name); + try std.testing.expectEqualStrings("catppuccin_mocha", themes[first - 1].name); + try std.testing.expectEqualStrings("zenbones_light", themes[first + names.len].name); } test "a theme hint drops whole names to fit, never cutting one" { @@ -2087,7 +2173,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 }; @@ -2107,8 +2193,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(legacy_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, @@ -2118,16 +2204,13 @@ 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 (legacy_themes[0..names.len], names) |th, name| { - 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{ - th.fg.?, th.kw, th.str, th.num, th.comment, - chrome.diagnostic_error, chrome.diagnostic_warning, chrome.diagnostic_info, chrome.diagnostic_hint, - }; + th.fg.?, th.kw, th.str, th.num, th.comment, + } ++ chrome.resolved.page.severity; for (text_colors) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum); // Gutters are orientation aids, not source text: stay visible without // competing with comments or pulling attention away from the body. @@ -2147,20 +2230,25 @@ test "native themes keep text and UI roles readable on their own surfaces" { try std.testing.expect(contrast(chrome.tag_active_bg, th.tag_bg) <= 1.6); try std.testing.expect(contrast(chrome.tag_active_fg, th.tag_fg) <= 1.6); try std.testing.expect(contrast(th.sel_fg, th.sel_bg) >= minimum); - try std.testing.expect(contrast(chrome.search_fg, chrome.search_bg) >= minimum); + try std.testing.expect(contrast(chrome.resolved.hit_current_text, chrome.resolved.hit_current) >= Chrome.text_floor); // ANSI black can intentionally match the page (for backgrounds). All // other ANSI foregrounds, including bright black, remain legible. for (th.palette.?[1..]) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum); } } +/// 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 (legacy_themes[0..native_theme_count]) |th| { - try std.testing.expect(th.tag_name_fg != null and th.tag_active_name_fg != null); - const chrome = ChromeTheme.fromTheme(&th); - const pairs = [2][2][3]u8{ - .{ chrome.tag_fg, chrome.tag_name_fg }, - .{ chrome.tag_active_fg, chrome.tag_active_name_fg }, + 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{ + .{ th.tag_text, th.tag_name.? }, }; for (pairs) |pair| { const base = toOklab(pair[0]); @@ -2180,7 +2268,8 @@ test "native filename tints change hue without changing perceived lightness" { } test "native dark palettes choose near-black or deliberately soft contrast" { - for (legacy_themes[0..native_theme_count]) |th| { + 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"); @@ -2193,12 +2282,12 @@ test "native dark palettes choose near-black or deliberately soft contrast" { } } const forge = curated.forge.theme; - try std.testing.expectEqual(forge.bg[0], forge.bg[1]); + try std.testing.expectEqual(forge.page[0], forge.page[1]); // Forge chrome is cool-neutral, never the old green-over-blue mint cast. - for ([_][3]u8{ forge.tag_bg, forge.tag_active_bg, forge.box, forge.border }) |rgb| + for ([_][3]u8{ forge.tag, forge.tag_focus, forge.accent, forge.rule }) |rgb| try std.testing.expect(rgb[2] >= rgb[1]); - try std.testing.expectEqual([3]u8{ 0, 0, 0 }, @as([3]u8, curated.forge_black.theme.bg)); - try std.testing.expectEqual([3]u8{ 0, 0, 0 }, @as([3]u8, curated.orchard_black.theme.bg)); + try std.testing.expectEqual([3]u8{ 0, 0, 0 }, @as([3]u8, curated.forge_black.theme.page)); + try std.testing.expectEqual([3]u8{ 0, 0, 0 }, @as([3]u8, curated.orchard_black.theme.page)); } test "line numbers stay quiet without a current-line tag background" { @@ -2208,11 +2297,12 @@ 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 = legacy_themes[0]; + 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 }; p.custom_theme = custom; + finishThemeInitialization(p); p.sync(); const x = p.view().rects[0].x + config.GUTTER; const y = p.view().rects[0].y + BOX_H; @@ -2222,10 +2312,13 @@ test "line numbers stay quiet without a current-line tag background" { try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, surface.at(x, y).style.bg); try std.testing.expect(surface.at(x, y).style.bold); try std.testing.expect(!surface.at(x, y + 1).style.bold); - // Old ThemeFile palettes need no new field, and do not regain the block. + // Old ThemeFile palettes need no new field: the current number is the + // text toward the page to 4.5:1 (R12), and the block not regained. p.custom_theme.?.lineno_active = null; + finishThemeInitialization(p); const fallback = try p.render(p.scratch.allocator()); - try std.testing.expectEqual(Color{ .rgb = .{ 70, 70, 70 } }, fallback.at(x, y).style.fg); + try std.testing.expectEqual(Color{ .rgb = p.chrome().line_number_current }, fallback.at(x, y).style.fg); + try std.testing.expect(contrast(p.chrome().line_number_current, custom.bg.?) >= Chrome.text_floor - 0.05); try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, fallback.at(x, y).style.bg); try std.testing.expect(fallback.at(x, y).style.bold); // Moving the caret clears the previous cue; editing the tag parks it. @@ -2242,14 +2335,16 @@ test "legacy ThemeFile documents inherit Pardes UI roles without new fields" { @setEvalBranchQuota(10000); var encoded: std.Io.Writer.Allocating = .init(std.testing.allocator); defer encoded.deinit(); - try std.zon.stringify.serialize(curated.helix.theme, .{ .whitespace = false }, &encoded.writer); - // helix without the focused tag's pair it has since gained: a document - // written before those fields existed. + try std.zon.stringify.serialize(ChromeTheme.ofTheme(&themes[comptime indexOfTheme("helix")]).view, .{ .whitespace = false }, &encoded.writer); + // helix without the focused tag's pair it has since gained, and the + // names' and column grip's dim fills: a document written before those + // fields existed. var legacy: std.ArrayList(u8) = .empty; defer legacy.deinit(std.testing.allocator); var rest: []const u8 = encoded.written(); while (true) { - const at = @min(std.mem.indexOf(u8, rest, ".tag_active_bg") orelse rest.len, std.mem.indexOf(u8, rest, ".tag_active_fg") orelse rest.len); + var at = rest.len; + for ([_][]const u8{ ".tag_active_bg", ".tag_active_fg", ".tag_active_name_fg", ".column_box_dim" }) |field| at = @min(at, std.mem.indexOf(u8, rest, field) orelse rest.len); try legacy.appendSlice(std.testing.allocator, rest[0..at]); if (at == rest.len) break; rest = rest[at + std.mem.indexOfScalar(u8, rest[at..], '}').? + 1 ..]; @@ -2279,12 +2374,11 @@ test "legacy ThemeFile documents inherit Pardes UI roles without new fields" { } test "column grip colors remain distinct from pane grips across native themes" { - for (legacy_themes[0..native_theme_count]) |th| { - try std.testing.expect(th.column_box != null and th.column_box_dim != null); - const chrome = ChromeTheme.fromTheme(&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{ - .{ chrome.box, chrome.column_box }, - .{ chrome.box_dim, chrome.column_box_dim }, + .{ th.accent, th.column_grip.? }, }) |pair| { var distance: u32 = 0; for (pair[0], pair[1]) |a, b| { @@ -2294,7 +2388,7 @@ test "column grip colors remain distinct from pane grips across native themes" { try std.testing.expect(distance >= 30 * 30); } } - var custom = legacy_themes[0]; + var custom = ChromeTheme.ofTheme(&themes[default_theme]).view; custom.column_box = .{ 90, 130, 170 }; custom.column_box_dim = null; var chrome = ChromeTheme.fromTheme(&custom); @@ -2306,7 +2400,7 @@ test "column grip colors remain distinct from pane grips across native themes" { } test "custom filename tints preserve optional active fallback precedence" { - var theme = legacy_themes[0]; + var theme = ChromeTheme.ofTheme(&themes[default_theme]).view; theme.tag_name_fg = null; theme.tag_active_name_fg = null; var chrome = ChromeTheme.fromTheme(&theme); @@ -2328,14 +2422,18 @@ test "custom filename tints preserve optional active fallback precedence" { } test "every theme tints its names off the tag's ink, and they read on both grounds" { - for (&legacy_themes) |*th| { - const chrome = ChromeTheme.fromTheme(th); + for (&themes) |*th| { + const c = Chrome.of(th); const pairs = [2][3][3]u8{ - .{ chrome.tag_fg, chrome.tag_name_fg, chrome.tag_bg }, - .{ chrome.tag_active_fg, chrome.tag_active_name_fg, chrome.tag_active_bg }, + .{ c.tag[0].text, c.name[0], c.tag[0].ground }, + .{ c.tag[1].text, c.name[1], c.tag[1].ground }, }; for (pairs) |pair| { const ink, const name, const ground = pair; + // An ink held to the end of the gamut (white or black, H's 7:1 + // on a mid-grey tag: ao's, modus_vivendi's) has no hue at its + // lightness: the name is the ink. + if (std.mem.eql(u8, &name, &ink) and (std.mem.eql(u8, &ink, &@as([3]u8, @splat(255))) or std.mem.eql(u8, &ink, &@as([3]u8, @splat(0))))) continue; const apart = oklabDistance(toOklab(ink), toOklab(name)); const floor = nameTintFloor(ink, ground); if (apart < name_tint_distance or contrast(name, ground) < floor - 0.01) @@ -2363,12 +2461,13 @@ test "every theme's walk UI roles meet their floors on every ground they are dra var checks: std.ArrayList(Check) = .empty; defer checks.deinit(a); var failed: usize = 0; - for (&legacy_themes) |*th| { + for (&themes) |*ring_theme| { + const view = ChromeTheme.ofTheme(ring_theme).view; + const th = &view; checks.clearRetainingCapacity(); const chrome = ChromeTheme.fromTheme(th); const r = &chrome.roles; const page = th.bg orelse null_page; - const body_ink = th.fg orelse th.tag_fg; const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page }; for (r.tag ++ r.selected ++ [1]RoleInks{r.notice}) |inks| { @@ -2395,15 +2494,6 @@ test "every theme's walk UI roles meet their floors on every ground they are dra try checks.append(a, .{ .what = "reading", .got = oklabDistance(toOklab(chrome.tag_reading_bg), toOklab(th.tag_bg)), .floor = Roles.reading_distance }); for ([_][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }) |ink| try checks.append(a, .{ .what = "text on reading", .got = contrast(ink, chrome.tag_reading_bg), .floor = @min(7, contrast(ink, th.tag_bg)) - 0.02 }); - const ink_floor = @min(Roles.ink_floor, contrast(body_ink, page)); - // A preview's landing line 1.5:1 off the page, its matched span (the - // current hit) a step stronger, 1.9:1 (UX E7 7b: 1.29 read as faint). - for ([_][3]u8{ r.hit, r.hit_current }, [_]f32{ 1.5, 1.9 }) |ground, floor| { - const on = contrast(body_ink, ground); - try checks.append(a, .{ .what = "hit", .got = contrast(ground, page), .floor = if (on < ink_floor + 0.3) 0 else floor }); - try checks.append(a, .{ .what = "ink on hit", .got = on, .floor = ink_floor - 0.01 }); - } - try checks.append(a, .{ .what = "current over hit", .got = contrast(r.hit_current, page) - contrast(r.hit, page), .floor = 0 }); for (checks.items) |c| if (c.got < c.floor - 0.005) { failed += 1; std.debug.print("{s}: {s} {d:.2} under {d:.2}\n", .{ th.name, c.what, c.got, c.floor }); @@ -2417,12 +2507,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 @@ -2515,7 +2607,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 { @@ -2602,7 +2694,15 @@ 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))); - f.setPresent(.diff, @min(contrast(c.add.row, page), contrast(c.del.row, page)) < 1.1 or de(c.add.row, c.del.row) < 0.05); + // 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 (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; for (c.ansi[1..], 1..) |a, i| { ansi_least = @min(ansi_least, contrast(a, page)); @@ -2620,54 +2720,30 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { const t = contrast(g.text, g.ground); var low = (n > 0 and t < @min(4.5, reach(g.ground))) or contrast(g.dim, g.ground) < @min(3, t) - 0.01; for ([2][3]u8{ g.key, g.match } ++ g.severity) |i| low = low or contrast(i, g.ground) < @min(4.5, reach(g.ground)); + // The kind mark on the ground and on its selection, a list's + // cursor row: one ink for both, 4.5:1 where the keyword's hue + // reaches it there (held to the end of light, a hue keeps a trace + // of itself: #000100 on solarized_dark's grey tag reads 4.49). + const both = [2][3]u8{ g.ground, g.selection.ground }; + const most = leastContrast(hold(th.keyword, &both, 21), &both); + low = low or leastContrast(g.kind, &both) < @min(4.5, most) - 0.01; low = low or contrast(g.selection.text, g.selection.ground) < @min(4.5, reach(g.selection.ground)); if (low) f.insert(.inks); } 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 }{ - // L3 (core/themes): the overrides DESIGN.md E1 names. - .{ "acme", "L3: its own sixteen where pardes's picks read under 3:1 (ANSI 10, 14)" }, - .{ "solarized_dark", "L3: `hit` and `added`/`deleted` of its own" }, - .{ "solarized_light", "L3: `hit` of its own" }, - .{ "seoul256_light_254", "L3: `hit` of its own" }, - .{ "seoul256_light_255", "L3: `hit` of its own" }, - // 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. - .{ "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" }, - // 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; for (&themes, 0..) |*th, i| { const c = Chrome.of(th); // The original's own (B1.5): never moved. @@ -2676,58 +2752,110 @@ 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); } - 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\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 +/// indicators and grounds (B1.6, G4: only that colour, and its file says +/// so); its text, syntax, comments and sixteen never move (the ring test). +/// Each with the ground it is held on, for the words its file says. +fn portMoves(th: *const Theme, c: *const Chrome) [12]struct { role: []const u8, own: ?[3]u8, got: [3]u8, on: [3]u8 } { + const page = c.page.ground; + return .{ + .{ .role = "tag ground", .own = th.tag, .got = c.tag[0].ground, .on = page }, + .{ .role = "focused tag ground", .own = th.tag_focus, .got = c.tag[1].ground, .on = c.tag[0].ground }, + .{ .role = "focused grip", .own = th.accent, .got = c.grip.focus, .on = c.tag[1].ground }, + .{ .role = "grip ring", .own = th.grip_ring, .got = c.grip.ring, .on = c.tag[0].ground }, + .{ .role = "unsaved grip", .own = th.dirty, .got = c.grip.dirty, .on = c.tag[0].ground }, + .{ .role = "selection", .own = th.selection, .got = c.page.selection.ground, .on = page }, + .{ .role = "selection text", .own = th.selection_text, .got = c.page.selection.text, .on = c.page.selection.ground }, + .{ .role = "search hit", .own = th.hit, .got = c.hit, .on = page }, + .{ .role = "error", .own = th.@"error", .got = c.page.severity[0], .on = page }, + .{ .role = "warning", .own = th.warning, .got = c.page.severity[1], .on = page }, + .{ .role = "info", .own = th.info, .got = c.page.severity[2], .on = page }, + .{ .role = "hint", .own = th.hint, .got = c.page.severity[3], .on = page }, + }; +} + +test "every faithful port's file says each of its own colours pardes moves to meet a floor (DESIGN.md G4)" { + const first = comptime indexOfTheme("dark_plus"); + const last = comptime indexOfTheme("doom_one_light"); + var unsaid: usize = 0; + inline for (@typeInfo(curated).@"struct".decl_names[first .. last + 1], first..) |d, i| { + const file = comptime if (std.mem.startsWith(u8, d, "seoul256_")) "seoul256" else d; + const source = @embedFile("themes/" ++ file ++ ".zig"); + const c = Chrome.of(&themes[i]); + for (portMoves(&themes[i], &c)) |m| if (m.own) |own| if (!std.mem.eql(u8, &own, &m.got)) { + var buf: [64]u8 = undefined; + const said = try std.fmt.bufPrint(&buf, "{s} #{x:0>2}{x:0>2}{x:0>2} -> #{x:0>2}{x:0>2}{x:0>2}", .{ m.role, own[0], own[1], own[2], m.got[0], m.got[1], m.got[2] }); + if (std.mem.indexOf(u8, source, said) == null) { + unsaid += 1; + std.debug.print("unsaid\t{s}\t{s}\t{s}\t{d:.2}\t{d:.2}\n", .{ themes[i].name, file, said, contrast(own, m.on), contrast(m.got, m.on) }); + } + }; } - 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); + try std.testing.expectEqual(0, unsaid); } -test "the whole ring resolves in 150 ms of CPU, no theme in over 0.5 ms (Debug)" { - const io = std.testing.io; - var total: i96 = 0; - var worst: i96 = 0; +/// B9's budget, about 0.5 ms a theme and the ring in 150 ms on an idle +/// machine (Debug), in user-space instructions, which a loaded machine does +/// not move: Chrome.of retires about 7 a nanosecond here (the ring's 304 M +/// in 42 ms of an idle CPU, 2026-11-26). +const theme_instructions: u64 = 3_500_000; +const ring_instructions: u64 = 1_050_000_000; + +test "the whole ring resolves within B9's budget, about 0.5 ms a theme and 150 ms in all on an idle machine, counted in instructions (Debug)" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + const linux = std.os.linux; + var attr: linux.perf_event_attr = .{ .type = .HARDWARE, .config = @intFromEnum(linux.PERF.COUNT.HW.INSTRUCTIONS), .flags = .{ .exclude_kernel = true, .exclude_hv = true } }; + const rc = linux.perf_event_open(&attr, 0, -1, -1, 0); + // No counter here (a container, perf_event_paranoid 3): nothing to count. + if (linux.errno(rc) != .SUCCESS) return error.SkipZigTest; + const fd: i32 = @intCast(rc); + defer _ = linux.close(fd); + var total: u64 = 0; + var worst: u64 = 0; var worst_at: usize = 0; for (&themes, 0..) |*th, i| { - // The least of five: a theme's own cost, not a page fault's. - var least: i96 = std.math.maxInt(i96); - for (0..5) |_| { - const start = std.Io.Clock.cpu_thread.now(io); - var c = Chrome.of(th); - std.mem.doNotOptimizeAway(&c); - least = @min(least, start.durationTo(std.Io.Clock.cpu_thread.now(io)).toNanoseconds()); - } - total += least; - if (least > worst) { - worst = least; + var before: u64 = 0; + var after: u64 = 0; + _ = linux.read(fd, std.mem.asBytes(&before), 8); + var c = Chrome.of(th); + std.mem.doNotOptimizeAway(&c); + _ = linux.read(fd, std.mem.asBytes(&after), 8); + total += after - before; + if (after - before > worst) { + worst = after - before; worst_at = i; } } - std.debug.print("ring resolved in {d} us, the slowest {s} in {d} us\n", .{ @divTrunc(total, 1000), themes[worst_at].name, @divTrunc(worst, 1000) }); - try std.testing.expect(total < 150 * std.time.ns_per_ms); - try std.testing.expect(worst <= std.time.ns_per_ms / 2); + std.debug.print("ring resolved in {d} instructions, the most {s}'s {d}\n", .{ total, themes[worst_at].name, worst }); + try std.testing.expect(total < ring_instructions); + try std.testing.expect(worst <= theme_instructions); } test "a theme file in the old names, a user's own or an older DumpThemes', and DumpThemes' now in the new names, load to the same Chrome" { @@ -2797,3 +2925,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); +} |
