diff options
Diffstat (limited to 'core/colors.zig')
| -rw-r--r-- | core/colors.zig | 270 |
1 files changed, 180 insertions, 90 deletions
diff --git a/core/colors.zig b/core/colors.zig index 44a2d415..ed82b731 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -700,12 +700,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; @@ -1054,12 +1059,12 @@ 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, }; } @@ -1073,8 +1078,8 @@ pub const Grounds = struct { pub const Ground = Chrome.Diff; - pub fn of(th: *const LegacyTheme) Grounds { - const c = Chrome.of(&.fromLegacy(th.*)); + pub fn of(th: *const Theme) Grounds { + const c = Chrome.of(th); return .{ .add = c.add, .del = c.del }; } @@ -1178,19 +1183,21 @@ const curated = struct { 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 @@ -1202,18 +1209,27 @@ 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; @@ -1299,14 +1315,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's chrome, from the theme and its old names' view. - pub fn of(theme: *const Theme, th: *const LegacyTheme) ChromeTheme { + /// 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, 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 @@ -1332,18 +1359,37 @@ pub const ChromeTheme = struct { // 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), - .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), .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. +fn viewOf(theme: *const Theme, r: *const Chrome) LegacyTheme { + const fill = if (theme.grip_ring != null) r.tag[0].ground else r.grip.ring; + 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 = r.name[1], + .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). @@ -1691,26 +1737,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.theme_chrome = chrome; const old = p.custom_theme; p.custom_theme = view; if (old) |theme_value| p.gpa.free(theme_value.name); @@ -1749,8 +1796,7 @@ 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`). 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.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 @@ -1830,14 +1876,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.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.theme_chrome = .ofTheme(&themes[index]); if (p.custom_theme) |theme_value| { p.custom_theme = null; p.gpa.free(theme_value.name); @@ -1852,7 +1898,9 @@ 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); @@ -1871,7 +1919,9 @@ 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 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 @@ -1892,11 +1942,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. @@ -1939,9 +1986,9 @@ test "seoul256's twelve backgrounds ring in their order, after Catppuccin and be "seoul256_light_253", "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" { @@ -2028,7 +2075,7 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { 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); + try std.testing.expectEqualStrings(themes[0].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, @@ -2040,7 +2087,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 (legacy_themes[0..names.len], names) |th, name| { + for (themes[0..names.len], names) |own, name| { + const th = ChromeTheme.ofTheme(&own).view; try std.testing.expectEqualStrings(name, th.name); 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; @@ -2074,12 +2122,11 @@ test "native themes keep text and UI roles readable on their own surfaces" { } 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 (themes[0..native_theme_count]) |*th| { + // 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]); @@ -2099,7 +2146,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 (themes[0..native_theme_count]) |ring_theme| { + const th = ChromeTheme.ofTheme(&ring_theme).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"); @@ -2112,12 +2160,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" { @@ -2127,7 +2175,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 = legacy_themes[0]; + var custom = ChromeTheme.ofTheme(&themes[0]).view; custom.name = try gpa.dupe(u8, "quiet-gutter"); custom.lineno = .{ 70, 70, 70 }; custom.lineno_active = .{ 95, 95, 95 }; @@ -2165,14 +2213,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 ..]; @@ -2202,12 +2252,10 @@ 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 (themes[0..native_theme_count]) |*th| { + // 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| { @@ -2217,7 +2265,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[0]).view; custom.column_box = .{ 90, 130, 170 }; custom.column_box_dim = null; var chrome = ChromeTheme.fromTheme(&custom); @@ -2229,7 +2277,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[0]).view; theme.tag_name_fg = null; theme.tag_active_name_fg = null; var chrome = ChromeTheme.fromTheme(&theme); @@ -2251,14 +2299,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) @@ -2286,7 +2338,9 @@ 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; @@ -2550,12 +2604,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 }{ - // 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`" }, @@ -2625,6 +2673,48 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati try std.testing.expectEqual(0, wrong); } +/// 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) }); + } + }; + } + try std.testing.expectEqual(0, unsaid); +} + /// 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 |
