diff options
Diffstat (limited to 'core/colors.zig')
| -rw-r--r-- | core/colors.zig | 488 |
1 files changed, 71 insertions, 417 deletions
diff --git a/core/colors.zig b/core/colors.zig index 711abfad..f89f81cc 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -71,16 +71,10 @@ fn luminanceContrast(x: f32, y: f32) f32 { return (@max(x, y) + 0.05) / (@min(x, y) + 0.05); } -pub fn lerp(a: [3]u8, b: [3]u8, t: f32) [3]u8 { - var out: [3]u8 = undefined; - for (&out, a, b) |*o, x, y| o.* = @intFromFloat(std.math.clamp(@round(@as(f32, @floatFromInt(x)) + (@as(f32, @floatFromInt(y)) - @as(f32, @floatFromInt(x))) * t), 0, 255)); - return out; -} - /// The rules between panes and columns: acme's contrast, black on white. -/// A theme's own border, or its scroll track, as long as it stands off the -/// page by 1.5:1; one that does not (on a near-black page, a dark rule all -/// but vanishes) is lifted toward the text until it does, to 1.6:1. +/// A theme's own rule, or its rail, as long as it stands off the page by +/// 1.5:1; one that does not (on a near-black page, a dark rule all but +/// vanishes) is held until it does, to 1.6:1 (R11, Chrome.separator_lift). pub const separator_floor: f32 = 1.5; /// The page a theme with none (`dark`: the host's own) is judged against: /// the GUI's default ground, and a dark terminal's. @@ -88,46 +82,6 @@ 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. 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; - const page = th.bg orelse null_page; - if (contrast(base, page) >= separator_floor) return base; - const ink = th.fg orelse th.tag_fg; - var t: f32 = 0.05; - while (t <= 1) : (t += 0.05) { - const lifted = lerp(base, ink, t); - if (contrast(lifted, page) >= 1.6) return lifted; - } - return ink; -} - -/// The focused tag's tint, the main focus indicator: a theme's own, pushed -/// further the way it already leans from the plain tag where the two are -/// closer than the floor (1.5:1 on a dark page, where a tint is all that -/// tells the focused tag at a glance; 1.25:1 on a light one), but never so -/// far its text drops below its own contrast or 4.5. A theme with no tint -/// (acme: the grip's button says it) keeps none. -pub const focus_tint_floor: f32 = 1.25; -pub const focus_tint_floor_dark: f32 = 1.5; -pub fn focusTintFloor(th: *const LegacyTheme) f32 { - return if (relativeLuminance(th.bg orelse null_page) < 0.18) focus_tint_floor_dark else focus_tint_floor; -} -fn focusTint(th: *const LegacyTheme) [3]u8 { - const tint = th.tag_active_bg orelse return th.tag_bg; - const floor = focusTintFloor(th); - if (contrast(tint, th.tag_bg) >= floor) return tint; - const ink = th.tag_active_fg orelse th.tag_fg; - const text_floor = @min(contrast(ink, tint), 4.5); - var best = tint; - var k: f32 = 1.1; - while (k <= 12) : (k += 0.1) { - const pushed = lerp(th.tag_bg, tint, k); - if (contrast(ink, pushed) < text_floor) break; - best = pushed; - if (contrast(pushed, th.tag_bg) >= floor) break; - } - return best; -} /// sRGB bytes to OKLab and back (Björn Ottosson's), and a mix in it. fn toOklab(rgb: [3]u8) [3]f32 { @@ -261,12 +215,6 @@ pub fn nameTintFloor(ink: [3]u8, ground: [3]u8) f32 { return @min(4.5, contrast(ink, ground) - 0.5); } -pub fn mix(a: [3]u8, b: [3]u8) [3]u8 { - var out: [3]u8 = undefined; - for (&out, a, b) |*c, x, y| c.* = @intCast((@as(u16, x) + y) / 2); - return out; -} - /// The derivations' OKLab, with no pow (B9's budget): a byte's linear /// light from `to_linear`, and back to a byte by the light where its /// rounding turns. `toOklab` and `fromOklab` (their f32 pow) stay the old @@ -315,6 +263,13 @@ const byte_turns: [255]f32 = blk: { break :blk table; }; +/// The least contrast `ink` has on any of `grounds`. +fn leastContrast(ink: [3]u8, grounds: []const [3]u8) f32 { + var least: f32 = 21; + for (grounds) |g| least = @min(least, contrast(ink, g)); + return least; +} + /// `toward` in the derivations' OKLab. fn towardOf(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 { var line: Line = .init(ink, ground); @@ -1093,29 +1048,6 @@ pub fn synInk(th: *const Theme, sy: @import("syntax.zig").Syn) ?[3]u8 { }; } -/// The grounds a style byte's high bits name (syntax.ground_add and the -/// 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 = Chrome.Diff; - - 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. - pub fn forStyle(g: *const Grounds, style: u8) ?Ground { - const syntax = @import("syntax.zig"); - if (style & syntax.ground_add != 0) return g.add; - if (style & syntax.ground_del != 0) return g.del; - return null; - } -}; - /// One family, its eight backgrounds a theme each (`curated`). const seoul256 = @import("themes/seoul256.zig"); @@ -1412,154 +1344,6 @@ comptime { @compileError("theme name \"" ++ c.name ++ "\" is both ours and generated; rename the vendored source"); } -pub const ChromeTheme = struct { - tag_bg: [3]u8, - tag_fg: [3]u8, - tagline_bg: [3]u8, - tagline_fg: [3]u8, - tag_active_bg: [3]u8, - tag_active_fg: [3]u8, - tag_name_fg: [3]u8, - tag_active_name_fg: [3]u8, - border: [3]u8, - empty_col: [3]u8, - search_bg: [3]u8, - tag_reading_bg: [3]u8, - diagnostic_error: [3]u8, - diagnostic_warning: [3]u8, - box: [3]u8, - box_dim: [3]u8, - column_box: [3]u8, - column_box_dim: [3]u8, - scroll_track: [3]u8, - scroll_thumb: [3]u8, - /// Everything B4 derives (`Chrome`), what the surfaces move to; the - /// fields above are the old derivations' values, kept for - /// 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, .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, 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 - // its own hues, on each ground. One that names only the plain tint - // keeps it when focused too. - const name_fg = th.tag_name_fg orelse (derivedNameTint(theme, th.tag_fg, th.tag_bg) orelse th.tag_fg); - const active_name_fg = th.tag_active_name_fg orelse - (th.tag_name_fg orelse (derivedNameTint(theme, active_fg, active_bg) orelse active_fg)); - const reading = readingOf(th); - return .{ - .tag_bg = th.tag_bg, - .tag_fg = th.tag_fg, - .tagline_bg = th.tagline_bg orelse th.tag_bg, - .tagline_fg = th.tagline_fg orelse th.tag_fg, - .tag_active_bg = active_bg, - .tag_active_fg = active_fg, - .tag_name_fg = name_fg, - .tag_active_name_fg = active_name_fg, - .border = separatorOf(th), - .empty_col = th.empty_col orelse separatorOf(th), - .search_bg = th.search_bg orelse th.sel_bg, - .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), - // 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, - .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, - }); -} - -fn leastContrast(ink: [3]u8, grounds: []const [3]u8) f32 { - var least: f32 = 21; - for (grounds) |g| least = @min(least, contrast(ink, g)); - return least; -} - -/// 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 -/// as a page; then less light, or darker, where its text would lose -/// contrast, and further where the bytes cannot show so small a step (a -/// near-black tag). -fn readingOf(th: *const LegacyTheme) [3]u8 { - const reading_distance = 0.04; - if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= reading_distance) return own; - const tag = toOklab(th.tag_bg); - const paper = toOklab(.{ 0xdc, 0xc8, 0x78 }); - const da = paper[1] - tag[1]; - const db = paper[2] - tag[2]; - const n = @max(@sqrt(da * da + db * db), 1e-6); - const sign: f32 = if (relativeLuminance(th.tag_bg) < 0.18) 1 else -1; - // Away from the text's lightness, where the first lean costs it. - const away: f32 = if (relativeLuminance(th.tag_fg) > relativeLuminance(th.tag_bg)) -1 else 1; - const inks = [2][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }; - var best = th.tag_bg; - var best_text: f32 = -21; - var reach: f32 = reading_distance; - while (reach <= 0.2) : (reach *= 1.25) { - for ([_]f32{ sign * 0.5, 0, away * 0.5, away, away * 1.5 }) |lean| { - const c = fromOklab(.{ tag[0] + lean * reach, tag[1] + da / n * reach, tag[2] + db / n * reach }); - if (oklabDistance(toOklab(c), tag) < reading_distance) continue; - // Each ink by its own floor: 7:1, or what it has on the tag. - var text: f32 = 21; - for (inks) |ink| text = @min(text, contrast(ink, c) - (@min(7, contrast(ink, th.tag_bg)) - 0.01)); - if (text >= 0) return c; - if (text > best_text) { - best = c; - best_text = text; - } - } - } - return best; -} - fn nextThemeFileGeneration(p: *Pardes) u32 { p.theme_file_generation +%= 1; if (p.theme_file_generation == 0) p.theme_file_generation = 1; @@ -1697,32 +1481,23 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8) bool { var diagnostics: std.zon.parse.Diagnostics = undefined; const options: std.zon.parse.Options = .{ .gpa = p.gpa, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics }; // A file in the old names (every one written before 2026-11-25: a - // 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 chrome: ChromeTheme = undefined; - if (inOldNames(source)) { - 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); - chrome = .ofTheme(&theme); - } + // user's own, an older DumpThemes') is read in them and renamed. + var theme: Theme = if (inOldNames(source)) + .fromLegacy(std.zon.parse.fromSlice(LegacyTheme, options) catch |err| return zonFailed(p, request, err, &diagnostics)) + else + std.zon.parse.fromSlice(Theme, options) catch |err| return zonFailed(p, request, err, &diagnostics); 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| { + theme.name = p.gpa.dupe(u8, theme.name) catch |err| { themeFileError(p, request, err); return false; }; - chrome.view.name = view.name; - p.theme_chrome = chrome; + p.theme_chrome = .of(&theme); const old = p.custom_theme; - p.custom_theme = view; + p.custom_theme = theme; if (old) |theme_value| p.gpa.free(theme_value.name); _ = p.theme_file_loaded.set(request.path); _ = p.scratch.reset(.{ .retain_with_limit = pardes.memory.limits.scratch_kept }); @@ -1759,7 +1534,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 { - p.theme_chrome = if (p.custom_theme) |*custom| .fromTheme(custom) else .ofTheme(&themes[p.settings.theme]); + p.theme_chrome = .of(if (p.custom_theme) |*custom| custom else &themes[p.settings.theme]); } /// Themes near `name`, a line of them, for a Theme given a name there is @@ -1839,14 +1614,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 = .ofTheme(&themes[i]); + p.preview_chrome = .of(&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 = .ofTheme(&themes[index]); + p.theme_chrome = .of(&themes[index]); if (p.custom_theme) |theme_value| { p.custom_theme = null; p.gpa.free(theme_value.name); @@ -1860,58 +1635,9 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void { p.settings.theme = @intCast(index); } -test "every native theme's separators stand off its page, and its focus tint off its tag" { - 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 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. - const ink = theme.tag_active_fg orelse theme.tag_fg; - try std.testing.expect(contrast(ink, chrome.tag_active_bg) >= @min(contrast(ink, own), 4.5) - 0.01); - } - } -} - -test "every faithful port meets pardes's chrome floors in its own colours, with nothing left to derive" { - const first = comptime indexOfTheme("dark_plus"); - const last = comptime indexOfTheme("helix"); - 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 - // the file's own values, so what the file says is what is drawn. - try std.testing.expectEqual(th.border.?, chrome.border); - try std.testing.expectEqual(th.tag_active_bg.?, chrome.tag_active_bg); - try std.testing.expect(contrast(th.border.?, page) >= separator_floor); - try std.testing.expect(contrast(th.tag_active_bg.?, th.tag_bg) >= focusTintFloor(th)); - try std.testing.expect(contrast(th.tag_fg, th.tag_bg) >= 4.5); - try std.testing.expect(contrast(th.tag_active_fg.?, th.tag_active_bg.?) >= 4.5); - try std.testing.expect(contrast(th.box_dim, th.tag_bg) >= 1.5); - try std.testing.expect(th.palette != null); - // A status bar of its own reads as tag text does; without one the - // tagline is the tag's. - try std.testing.expect(contrast(chrome.tagline_fg, chrome.tagline_bg) >= 4.5); - if (th.tagline_bg == null) try std.testing.expectEqual(th.tag_bg, chrome.tagline_bg); - } -} - -test "a derived separator or tint keeps the theme's own when it already stands off" { - 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. - try std.testing.expect(!std.meta.eql(forge.tag_active_bg.?, chrome.tag_active_bg)); - for (chrome.tag_active_bg, forge.tag_active_bg.?, forge.tag_bg) |pushed, own, plain| - try std.testing.expect(pushed >= own and own >= plain); +test "a theme's own rule is kept where it already stands off its page" { + const forge = &themes[comptime indexOfTheme("forge")]; + try std.testing.expectEqual(forge.rule.?, Chrome.of(forge).rule); } test "an OKLab fade holds its ends exactly and keeps a mid-way bright" { @@ -1923,7 +1649,7 @@ test "an OKLab fade holds its ends exactly and keeps a mid-way bright" { // OKLab it keeps its lightness. const red: [3]u8 = .{ 255, 0, 0 }; const green: [3]u8 = .{ 0, 200, 0 }; - const srgb_mid = mix(red, green); + const srgb_mid: [3]u8 = .{ 128, 100, 0 }; const lab_mid = mixOklab(red, green, 0.5); try std.testing.expect(relativeLuminance(lab_mid) > relativeLuminance(srgb_mid) * 1.3); } @@ -2037,8 +1763,8 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { try std.zon.stringify.serialize(custom, .{ .whitespace = true }, &encoded.writer); try std.testing.expect(loadThemeFile(p, request_effect.generation, encoded.written())); try std.testing.expectEqualStrings("mine", p.theme().name); - try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().bg); - try std.testing.expectEqual(ChromeTheme.fromTheme(p.theme()), p.chromeTheme().*); + try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().page); + try std.testing.expectEqual(Chrome.of(p.theme()), p.chrome().*); // A half-written save is rejected without disturbing the last good value. try std.testing.expect(!loadThemeFile(p, request_effect.generation, ".{ .name = ")); @@ -2046,7 +1772,7 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" { const said = p.messages.saidBy(p.panes[0].?); try std.testing.expect(std.mem.indexOf(u8, said, ": line 1: ") != null and std.mem.indexOf(u8, said, "parse zon") == null); try std.testing.expectEqualStrings("mine", p.theme().name); - try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().bg); + try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().page); setThemeIndex(p, default_theme); try std.testing.expectEqualStrings(themes[default_theme].name, p.theme().name); @@ -2060,35 +1786,34 @@ 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" { for (designed) |name| { - const th = ChromeTheme.ofTheme(&themes[themeIndex(name).?]).view; - const chrome = ChromeTheme.fromTheme(&th); + const th = &themes[themeIndex(name).?]; + const c = Chrome.of(th); + const page = th.page.?; 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.resolved.page.severity; - for (text_colors) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum); + const text_colors = [_][3]u8{ th.text.?, th.keyword, th.string, th.number, th.comment } ++ c.page.severity; + for (text_colors) |fg| try std.testing.expect(contrast(fg, page) >= minimum); // Gutters are orientation aids, not source text: stay visible without // competing with comments or pulling attention away from the body. - try std.testing.expect(contrast(th.lineno, th.bg.?) >= 2.5); - try std.testing.expect(contrast(th.lineno, th.bg.?) <= 4); - try std.testing.expect(contrast(th.lineno_active.?, th.bg.?) >= contrast(th.lineno, th.bg.?)); - try std.testing.expect(contrast(th.lineno_active.?, th.bg.?) <= 4.5); - try std.testing.expect(contrast(th.comment, th.bg.?) >= 5); - try std.testing.expect(contrast(th.comment, th.bg.?) >= contrast(th.lineno, th.bg.?) + 2); - try std.testing.expect(contrast(th.tag_fg, th.tag_bg) >= minimum); - try std.testing.expect(contrast(chrome.tag_active_fg, chrome.tag_active_bg) >= minimum); - try std.testing.expect(th.tag_name_fg != null); - try std.testing.expect(contrast(chrome.tag_name_fg, th.tag_bg) >= minimum); - try std.testing.expect(contrast(chrome.tag_active_name_fg, chrome.tag_active_bg) >= minimum); + try std.testing.expect(contrast(c.line_number, page) >= 2.5); + try std.testing.expect(contrast(c.line_number, page) <= 4); + try std.testing.expect(contrast(c.line_number_current, page) >= contrast(c.line_number, page)); + try std.testing.expect(contrast(c.line_number_current, page) <= 4.5); + try std.testing.expect(contrast(th.comment, page) >= 5); + try std.testing.expect(contrast(th.comment, page) >= contrast(c.line_number, page) + 2); + try std.testing.expect(th.tag_name != null); + for (c.tag, c.name) |inks, tint| { + try std.testing.expect(contrast(inks.text, inks.ground) >= minimum); + try std.testing.expect(contrast(tint, inks.ground) >= minimum); + } // Focus stays on the same tonal surface, rather than inverting a // whole command strip. Text remains readable in both states. - 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.resolved.hit_current_text, chrome.resolved.hit_current) >= Chrome.text_floor); + try std.testing.expect(contrast(c.tag[1].ground, c.tag[0].ground) <= 1.6); + try std.testing.expect(contrast(c.tag[1].text, c.tag[0].text) <= 1.6); + try std.testing.expect(contrast(c.page.selection.text, c.page.selection.ground) >= minimum); + try std.testing.expect(contrast(c.hit_current_text, c.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); + for (c.ansi[1..]) |fg| try std.testing.expect(contrast(fg, page) >= minimum); } } @@ -2124,16 +1849,16 @@ test "native filename tints change hue without changing perceived lightness" { test "native dark palettes choose near-black or deliberately soft contrast" { for (designed) |name| { - const th = ChromeTheme.ofTheme(&themes[themeIndex(name).?]).view; - if (contrast(th.bg.?, .{ 0, 0, 0 }) > 10) continue; // light paper + const th = &themes[themeIndex(name).?]; + if (contrast(th.page.?, .{ 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"); if (soft) { - try std.testing.expect(contrast(th.fg.?, th.bg.?) >= 4.5); - try std.testing.expect(contrast(th.fg.?, th.bg.?) <= 7); + try std.testing.expect(contrast(th.text.?, th.page.?) >= 4.5); + try std.testing.expect(contrast(th.text.?, th.page.?) <= 7); } else { - for (th.bg.?) |channel| try std.testing.expect(channel <= 0x14); - try std.testing.expect(contrast(th.fg.?, th.bg.?) >= 14); + for (th.page.?) |channel| try std.testing.expect(channel <= 0x14); + try std.testing.expect(contrast(th.text.?, th.page.?) >= 14); } } const forge = curated.forge.theme; @@ -2152,10 +1877,10 @@ 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[default_theme]).view; + var custom = themes[default_theme]; custom.name = try gpa.dupe(u8, "quiet-gutter"); - custom.lineno = .{ 70, 70, 70 }; - custom.lineno_active = .{ 95, 95, 95 }; + custom.line_number = .{ 70, 70, 70 }; + custom.line_number_current = .{ 95, 95, 95 }; p.custom_theme = custom; finishThemeInitialization(p); p.sync(); @@ -2164,17 +1889,17 @@ test "line numbers stay quiet without a current-line tag background" { const surface = try p.render(p.scratch.allocator()); try std.testing.expectEqual(Color{ .rgb = .{ 95, 95, 95 } }, surface.at(x, y).style.fg); try std.testing.expectEqual(Color{ .rgb = .{ 70, 70, 70 } }, surface.at(x, y + 1).style.fg); - try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, surface.at(x, y).style.bg); + try std.testing.expectEqual(Color{ .rgb = custom.page.? }, 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: 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; + p.custom_theme.?.line_number_current = null; finishThemeInitialization(p); const fallback = try p.render(p.scratch.allocator()); 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(contrast(p.chrome().line_number_current, custom.page.?) >= Chrome.text_floor - 0.05); + try std.testing.expectEqual(Color{ .rgb = custom.page.? }, 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. pane.body.cur_row = 1; @@ -2186,48 +1911,6 @@ test "line numbers stay quiet without a current-line tag background" { try std.testing.expect(!tag_edit.at(x, y + 1).style.bold); } -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(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) { - 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 ..]; - rest = std.mem.trimStart(u8, rest, " ,"); - } - const source = try std.testing.allocator.dupeSentinel(u8, legacy.items, 0); - defer std.testing.allocator.free(source); - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - var diagnostics: std.zon.parse.Diagnostics = undefined; - const parsed = try std.zon.parse.fromSlice(LegacyTheme, .{ .gpa = std.testing.allocator, .arena = arena.allocator(), .source = source, .diagnostics = &diagnostics }); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_active_bg); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_name_fg); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.tag_active_name_fg); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.column_box); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.column_box_dim); - try std.testing.expectEqual(@as(?[3]u8, null), parsed.search_bg); - const chrome = ChromeTheme.fromTheme(&parsed); - try std.testing.expectEqual(parsed.tag_bg, chrome.tag_active_bg); - // Its names take a tint of its own hues, never the plain ink. - try std.testing.expect(!std.meta.eql(parsed.tag_fg, chrome.tag_name_fg)); - try std.testing.expect(!std.meta.eql(chrome.tag_active_fg, chrome.tag_active_name_fg)); - try std.testing.expectEqual(parsed.num, chrome.column_box); - try std.testing.expectEqual(mix(parsed.num, parsed.tag_bg), chrome.column_box_dim); - try std.testing.expectEqual(parsed.sel_bg, chrome.search_bg); - try std.testing.expectEqual(parsed.fg.?, chrome.diagnostic_error); -} - test "column grip colors remain distinct from pane grips across native themes" { for (designed) |name| { const th = &themes[themeIndex(name).?]; @@ -2243,37 +1926,6 @@ test "column grip colors remain distinct from pane grips across native themes" { try std.testing.expect(distance >= 30 * 30); } } - var custom = ChromeTheme.ofTheme(&themes[default_theme]).view; - custom.column_box = .{ 90, 130, 170 }; - custom.column_box_dim = null; - var chrome = ChromeTheme.fromTheme(&custom); - try std.testing.expectEqual(custom.column_box.?, chrome.column_box); - try std.testing.expectEqual(mix(custom.column_box.?, custom.tag_bg), chrome.column_box_dim); - custom.column_box_dim = .{ 40, 60, 80 }; - chrome = ChromeTheme.fromTheme(&custom); - try std.testing.expectEqual(custom.column_box_dim.?, chrome.column_box_dim); -} - -test "custom filename tints preserve optional active fallback precedence" { - var theme = ChromeTheme.ofTheme(&themes[default_theme]).view; - theme.tag_name_fg = null; - theme.tag_active_name_fg = null; - var chrome = ChromeTheme.fromTheme(&theme); - // Neither named: each derived, on its own ground. - try std.testing.expectEqual(derivedNameTint(&.fromLegacy(theme), theme.tag_fg, theme.tag_bg).?, chrome.tag_name_fg); - try std.testing.expectEqual(derivedNameTint(&.fromLegacy(theme), theme.tag_active_fg.?, chrome.tag_active_bg).?, chrome.tag_active_name_fg); - theme.tag_name_fg = .{ 120, 130, 140 }; - chrome = ChromeTheme.fromTheme(&theme); - try std.testing.expectEqual(theme.tag_name_fg.?, chrome.tag_name_fg); - try std.testing.expectEqual(theme.tag_name_fg.?, chrome.tag_active_name_fg); - theme.tag_active_name_fg = .{ 150, 160, 170 }; - chrome = ChromeTheme.fromTheme(&theme); - try std.testing.expectEqual(theme.tag_name_fg.?, chrome.tag_name_fg); - try std.testing.expectEqual(theme.tag_active_name_fg.?, chrome.tag_active_name_fg); - theme.tag_name_fg = null; - chrome = ChromeTheme.fromTheme(&theme); - try std.testing.expectEqual(derivedNameTint(&.fromLegacy(theme), theme.tag_fg, theme.tag_bg).?, chrome.tag_name_fg); - try std.testing.expectEqual(theme.tag_active_name_fg.?, chrome.tag_active_name_fg); } test "every theme tints its names off the tag's ink, and they read on both grounds" { @@ -2705,11 +2357,13 @@ test "a theme file in the old names, a user's own or an older DumpThemes', and D requestThemeFile(p, 0, "themes/one_dark_zed_mod.zon"); try std.testing.expect(loadThemeFile(p, p.theme_file_generation, own)); const want = p.chrome().*; - // The old names' view is the file itself, unset fields their defaults. - try std.testing.expectEqual([3]u8{ 70, 75, 87 }, p.theme().box_dim); - try std.testing.expectEqual(@as(?[3]u8, null), p.theme().tag_active_bg); - var old = p.theme().*; - old.name = "one_dark_zed"; + // The file in its old names, unset fields their defaults. + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + var diagnostics: std.zon.parse.Diagnostics = undefined; + const old = try std.zon.parse.fromSlice(LegacyTheme, .{ .gpa = gpa, .arena = arena.allocator(), .source = own, .diagnostics = &diagnostics }); + try std.testing.expectEqual([3]u8{ 70, 75, 87 }, old.box_dim); + try std.testing.expectEqual(@as(?[3]u8, null), old.tag_active_bg); try std.testing.expectEqual(Chrome.of(&.fromLegacy(old)), want); // An older DumpThemes' shape: every old field, the unset ones null. var older: std.Io.Writer.Allocating = .init(gpa); @@ -2726,8 +2380,8 @@ 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, file)); try std.testing.expectEqualStrings("one_dark_zed", p.theme().name); try std.testing.expectEqual(want, p.chrome().*); - // What the old names' readers see of it is what they saw of the file. - for ([_][3]u8{ p.theme().sel_fg, p.theme().tag_bg, p.theme().box, p.theme().lineno, p.theme().scroll_track }, [_][3]u8{ old.sel_fg, old.tag_bg, old.box, old.lineno, old.scroll_track }) |got, was| + // The theme worn is the file's, in the new names. + for ([_][3]u8{ p.theme().tag, p.theme().accent, p.theme().selection, p.theme().keyword }, [_][3]u8{ old.tag_bg, old.box, old.sel_bg, old.kw }) |got, was| try std.testing.expectEqual(was, got); } // A file in the new names with a typo is refused in the new names' words. |
