diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 01:40:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 02:12:25 -0300 |
| commit | df964ae2f14d21a4799d52a07abfe3b2bef3c65e (patch) | |
| tree | be3880fb9a7b0ab8874d49a69923898b4677e42a /test/terminal.zig | |
| parent | e793644c7192a96ae2e39e072708b059edafaeeb (diff) | |
| download | pardes-df964ae2f14d21a4799d52a07abfe3b2bef3c65e.tar.gz pardes-df964ae2f14d21a4799d52a07abfe3b2bef3c65e.zip | |
ansi, Term, term/terminal, abi/term: a terminal's colours from the chrome (the themes programme's L2d; DESIGN.md R1, R14, R15, B6): the paint and the filter take the page, its text, its dim ink and the sixteen the theme resolved once a theme change (`Chrome.page`, `Chrome.ansi`), never the theme's own fields: a theme with no sixteen of its own draws a program's in the ones worked out for it (R14: its own hues within 30 degrees, else canonical ones, held 4.5:1 on its page), where the cells named an index and each frontend drew its own palette (the tty the host's, the window ghostty's, the Mac Tango: three for one index); a theme that leaves its page to the host (`dark`) leaves page, text and sixteen to a tty as before (`Ink.host`), and in a window draws the null page, its text and its sixteen (R1, R14: "the window uses its ansi"); the filter's base is that sixteen and its 256 targets ghostty's generator over it, made once a theme (FilterPalette, keyed by the theme's values: no reimplemented generator, no per-frame make), where the base for a theme without a palette was made of its roles (ANSI 1 the keyword, 5 the selection, 13 its ink: C1's surfaces.md §3.10) and the page of `dark` was its tag (`ink.bg orelse ink.tag_bg`, #2c2a3e under a #121212 window: §3.1); SGR faint on the page's text is the page's dim ink (R15: the text toward the page to 3.5:1, so as faint on a light page as on a dark one), where a tty halved its brightness toward black and a window took 60 % of it (faint on a coloured ink stays the frontend's, L2e's); Ink is {fg, bg, dim, ansi, host} (abi/term.zig: `tag_fg`, `tag_bg`, `palette` and `base` deleted), ansi.inkOf takes the core (its chrome and its view's frontend); RUN (TEST FIRST): test/terminal.zig "a theme that leaves its page to the host (`dark`) draws a terminal's page, text, faint and sixteen as the null page and its own in a window, and leaves them to a tty; its filter keys to that page, never its tag": in a window a plain cell on #121212 in dark's text, SGR 31 in `ansi[1]`, SGR 2 in `page.dim` and not faint; in a tty `.default`, index 1, faint; the filter's page the null page and its ink the text: on the base the window's cells are `.default`, index 1 and faint and the filter's page dark's tag (the old Ink had no page to give: `ink.bg orelse ink.tag_bg`); the Filter tests re-pinned to the chrome: helix's SGR 31 raw is its resolved `ansi[1]` (was index 1), the `F` cell's faint on the page's text its dim ink (was the text, faint), a reversed explicit cell's ink the chrome's page, the in-place custom theme now a ThemeFile's way (its sixteen changed and its chrome worked out: finishThemeInitialization) where it poked the keyword the old base mapped to ANSI 1, the theme loops by setThemeIndex (they set `settings.theme` under a chrome worked out for another) and with `dark` among them; test/panes.zig's TerminalTests that assert a program's raw indices (an edit buffer sliding rows and their colours, a combining mark, an emoji prompt, a swallowed row, an emptied buffer, the overlay in tty mode, colours never taken from rows below the viewport: seven failed on helix's indices now its resolved sixteen, and the last would have kept passing while proving nothing) take `dark` in a tty, which leaves the sixteen to the host as helix's missing palette did; the wide glyph's last column keeps helix (a page of its own, so the body draws every cell) and asks its resolved red; goldens re-recorded: load.golden row 7 and headersweep-restored.golden rows 6, 14, 15 and 21: the `── restored history ──` banner (SGR 2, terminal.zig's restored_banner) in orchard's page dim ink #666f68 where the tty drew #e5eee5 faint, and the blank cells after it on its row the same fg (vaxis erases the rest of a row in its last SGR; nothing drawn there); pagercolor.golden, theme.golden and themesel.golden unchanged (every native and ported theme in them has its sixteen); GATES: core-test 1123/1296 (173 skipped), term-test 17/17, pane-test 184/185 (1 skipped: base 183/184, +1 the dark test), process-test 145 of 147 and the two re-recorded (3 skipped); load 3.4 to 7.8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'test/terminal.zig')
| -rw-r--r-- | test/terminal.zig | 103 |
1 files changed, 74 insertions, 29 deletions
diff --git a/test/terminal.zig b/test/terminal.zig index 5cf853e7..1168fac7 100644 --- a/test/terminal.zig +++ b/test/terminal.zig @@ -269,7 +269,8 @@ test "rows asked for after a pane's cached rows were dropped, before the sweep, test "terminal Filter keys indexed truecolor OSC and background-only cells through the theme" { const testing = std.testing; - // Raw index assertions require a theme that inherits the ANSI palette. + // A theme with no sixteen of its own (helix): a program's sixteen drawn + // in the ones worked out for it (DESIGN.md R14), the rest as they are. const p = try Pardes.init(testing.allocator, .{ .startup_config = "Theme helix\n", .tty_only = true, .cols = 18, .rows = 7 }); defer p.deinit(); while (p.nextEffect()) |_| {} @@ -295,7 +296,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu const body_y = p.bodyTop(pane, r); const raw = try p.render(frame.allocator()); - try testing.expectEqual(plain.Color{ .index = 1 }, raw.at(tx, body_y).style.fg); + try testing.expectEqual(plain.Color{ .rgb = p.chrome().ansi[1] }, raw.at(tx, body_y).style.fg); try testing.expectEqual(plain.Color{ .index = 196 }, raw.at(tx + 1, body_y).style.fg); try testing.expectEqual(plain.Color{ .rgb = .{ 255, 0, 0 } }, raw.at(tx + 2, body_y).style.fg); @@ -303,7 +304,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu _ = frame.reset(.retain_capacity); const filtered = try p.render(frame.allocator()); var expected_cache: FilterPalette = .{}; - const expected = filterPalette(&expected_cache, &ansi.inkOf(p.theme())); + const expected = filterPalette(&expected_cache, &ansi.inkOf(p)); try testing.expectEqual(asPardesColor(asGhostRgb(expected[1])), filtered.at(tx, body_y).style.fg); try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), filtered.at(tx + 1, body_y).style.fg); try testing.expectEqual(filtered.at(tx + 1, body_y).style.fg, filtered.at(tx + 2, body_y).style.fg); @@ -312,7 +313,9 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu const attrs = filtered.at(tx + 5, body_y).style; try testing.expect(attrs.bold); - try testing.expect(attrs.dim); + // Faint on the page's text: the page's dim ink (DESIGN.md R15). + try testing.expect(!attrs.dim); + try testing.expectEqual(plain.Color{ .rgb = p.chrome().page.dim }, attrs.fg); try testing.expect(attrs.italic); try testing.expect(attrs.blink); try testing.expect(attrs.reverse); @@ -374,7 +377,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), reversed_blank.bg); const reversed_explicit = reversed.at(tx, body_y).style; try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), reversed_explicit.bg); - try testing.expectEqual(plain.Color{ .rgb = p.theme().bg.? }, reversed_explicit.fg); + try testing.expectEqual(plain.Color{ .rgb = p.chrome().page.ground }, reversed_explicit.fg); try testing.expect(!std.meta.eql(reversed_explicit.fg, reversed_explicit.bg)); p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5l" } }); @@ -384,31 +387,74 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), unreversed_blank.fg); try testing.expectEqual(asPardesColor(asGhostRgb(expected[59])), unreversed_blank.bg); - // The cache is keyed by values, not a theme name. Replacing a custom - // theme in place immediately recolours already-rendered indexed cells. + // The cache is keyed by values, not a theme name. A custom theme of the + // same name with another sixteen, its chrome worked out (as a + // ThemeFile's load does), recolours already-rendered indexed cells. p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]104;1\x1b\\" } }); var custom = p.theme().*; custom.name = try p.gpa.dupe(u8, "same-name"); - custom.palette = null; - custom.kw = .{ 1, 2, 3 }; + custom.palette = pardes.colors.xterm[0..16].*; + custom.palette.?[1] = .{ 1, 2, 3 }; p.custom_theme = custom; + pardes.colors.finishThemeInitialization(p); _ = frame.reset(.retain_capacity); const custom_first = try p.render(frame.allocator()); try testing.expectEqual(plain.Color{ .rgb = .{ 1, 2, 3 } }, custom_first.at(tx, body_y).style.fg); - if (p.custom_theme) |*theme| theme.kw = .{ 4, 5, 6 }; + if (p.custom_theme) |*theme| theme.palette.?[1] = .{ 4, 5, 6 }; + pardes.colors.finishThemeInitialization(p); _ = frame.reset(.retain_capacity); const custom_second = try p.render(frame.allocator()); try testing.expectEqual(plain.Color{ .rgb = .{ 4, 5, 6 } }, custom_second.at(tx, body_y).style.fg); } +test "a theme that leaves its page to the host (`dark`) draws a terminal's page, text, faint and sixteen as the null page and its own in a window, and leaves them to a tty; its filter keys to that page, never its tag (DESIGN.md R1, R14, R15)" { + const testing = std.testing; + for ([_]bool{ false, true }) |windowed| { + const p = try Pardes.init(testing.allocator, .{ .startup_config = "Theme dark\n", .tty_only = true, .cols = 18, .rows = 7, .windowed = windowed }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + const pane = p.panes[0].?; + pane.tag_expanded = false; + pane.tty_filter = false; + p.update(.{ .output = .{ .pane = .at(0), .bytes = "A\x1b[31mB\x1b[0;2mC" } }); + p.sync(); + var frame = std.heap.ArenaAllocator.init(testing.allocator); + defer frame.deinit(); + const r = p.view().rects[0]; + const tx = r.x + config.GUTTER; + const body_y = p.bodyTop(pane, r); + const s = try p.render(frame.allocator()); + const c = p.chrome(); + try testing.expect(c.host_page); + const plain_cell = s.at(tx, body_y).style; + const red = s.at(tx + 1, body_y).style; + const faint = s.at(tx + 2, body_y).style; + if (windowed) { + try testing.expectEqual(plain.Color{ .rgb = pardes.colors.null_page }, plain_cell.bg); + try testing.expectEqual(plain.Color{ .rgb = c.page.text }, plain_cell.fg); + try testing.expectEqual(plain.Color{ .rgb = c.ansi[1] }, red.fg); + try testing.expectEqual(plain.Color{ .rgb = c.page.dim }, faint.fg); + try testing.expect(!faint.dim); + } else { + try testing.expect(plain_cell.bg == .default and plain_cell.fg == .default); + try testing.expectEqual(plain.Color{ .index = 1 }, red.fg); + try testing.expect(faint.dim and faint.fg == .default); + } + var cache: FilterPalette = .{}; + const f = filterOf(&ansi.inkOf(p), &cache, &of(pane.terminal.?).vt); + try testing.expectEqual(pardes.colors.null_page, f.theme_bg); + try testing.expectEqual(c.page.text, f.theme_fg); + } +} + test "terminal Filter keeps extended keys dark-to-light on a light theme" { const p = try Pardes.init(std.testing.allocator, .{ .startup_config = "Theme acme\n", .tty_only = true }); defer p.deinit(); try std.testing.expectEqualStrings("acme", p.theme().name); var cache: FilterPalette = .{}; - const palette = filterPalette(&cache, &ansi.inkOf(p.theme())); - try std.testing.expect(asGhostRgb(palette[16]).eql(asGhostRgb(p.theme().fg.?))); - try std.testing.expect(asGhostRgb(palette[231]).eql(asGhostRgb(p.theme().bg.?))); + const palette = filterPalette(&cache, &ansi.inkOf(p)); + try std.testing.expect(asGhostRgb(palette[16]).eql(asGhostRgb(p.chrome().page.text))); + try std.testing.expect(asGhostRgb(palette[231]).eql(asGhostRgb(p.chrome().page.ground))); } test "terminal Filter preserves exact palette-null light theme default roles" { @@ -423,6 +469,7 @@ test "terminal Filter preserves exact palette-null light theme default roles" { light.fg = .{ 0x38, 0x38, 0x38 }; light.palette = null; p.custom_theme = light; + pardes.colors.finishThemeInitialization(p); const pane = p.panes[0].?; try testing.expectEqual(@as(?GColor.RGB, null), of(pane.terminal.?).vt.colorForXterm(.{ .dynamic = .foreground })); @@ -453,25 +500,23 @@ test "terminal Filter maps the default roles before it maps anything else" { const pane = p.panes[0].?; try testing.expect(pane.tty_filter); - // Native dark/light palettes plus legacy helix/dark/acme, including - // the null-page fallback that only the legacy dark theme exercises. - for (0..9) |t| { - p.settings.theme = @intCast(t); - const stage_one = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt); - // `dark` declares no background of its own, which is exactly why the - // resolver reads the tag colours as the fallback rather than `.?`. - const theme = p.theme(); - try testing.expect(asGhostRgb(stage_one.theme_bg).eql(asGhostRgb(theme.bg orelse theme.tag_bg))); - try testing.expect(asGhostRgb(stage_one.theme_fg).eql(asGhostRgb(theme.fg orelse theme.tag_fg))); + // The first nine of the ring, dark and light, and `dark`, whose page is + // the host's: its filter keys to the null page, never its tag. + for ([_]usize{ 0, 1, 2, 3, 4, 5, 6, 7, 8, pardes.colors.themeIndex("dark").? }) |t| { + pardes.colors.setThemeIndex(p, t); + const stage_one = filterOf(&ansi.inkOf(p), &p.tty_filter_palette, &of(pane.terminal.?).vt); + const page = p.chrome().page; + try testing.expect(asGhostRgb(stage_one.theme_bg).eql(asGhostRgb(page.ground))); + try testing.expect(asGhostRgb(stage_one.theme_fg).eql(asGhostRgb(page.text))); // With no OSC 11 in play the mapped page IS that anchor, and the // fallback is the other one: a background never contrasts with itself. try testing.expect(asGhostRgb(stage_one.default_bg).eql(asGhostRgb(stage_one.theme_bg))); try testing.expect(asGhostRgb(stage_one.fallback_fg).eql(asGhostRgb(stage_one.theme_fg))); } - p.settings.theme = 0; + pardes.colors.setThemeIndex(p, 0); p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]11;#5f5f5f\x1b\\" } }); - var moved = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt); + var moved = filterOf(&ansi.inkOf(p), &p.tty_filter_palette, &of(pane.terminal.?).vt); try testing.expect(!asGhostRgb(moved.default_bg).eql(asGhostRgb(moved.theme_bg))); try testing.expect(asGhostRgb(moved.default_bg).eql(keyedRgb(&moved, .{ .r = 0x5f, .g = 0x5f, .b = 0x5f }))); } @@ -495,8 +540,8 @@ test "terminal Filter refuses a foreground that would collapse onto the page" { const body_y = p.bodyTop(pane, r); for (0..9) |t| { - p.settings.theme = @intCast(t); - var fc = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt); + pardes.colors.setThemeIndex(p, t); + var fc = filterOf(&ansi.inkOf(p), &p.tty_filter_palette, &of(pane.terminal.?).vt); const page = asPardesColor(asGhostRgb(fc.default_bg)); const rescued = asPardesColor(asGhostRgb(fc.fallback_fg)); _ = frame.reset(.retain_capacity); @@ -547,8 +592,8 @@ test "terminal Filter holds every projected foreground off the page" { const pane = p.panes[0].?; for (0..9) |t| { - p.settings.theme = @intCast(t); - var fc = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt); + pardes.colors.setThemeIndex(p, t); + var fc = filterOf(&ansi.inkOf(p), &p.tty_filter_palette, &of(pane.terminal.?).vt); var refused: usize = 0; for (fc.target, 0..) |projected_triple, slot| { const projected = asGhostRgb(projected_triple); |
