//! The tty frontend's own cases (test/tty.zig), colours: themes, syntax, markup, a pager's SGR, the cursor line. const std = @import("std"); const Tty = @import("../tty.zig").Tty; pub const cases = .{ .{ "tty themes: theme", theme }, .{ "tty themes: themesel", themesel }, .{ "tty themes: syntax", syntax }, .{ "tty themes: markup", markup }, .{ "tty themes: pagercolor", pagercolor }, .{ "tty themes: cursorline", cursorline }, }; // Native Pardes themes lead the ring. Capture both text and cell styles so // every palette proves the editor, tags and embedded terminal share its colors. // The legacy helix/dark/acme choices stay reachable, followed by generated data. fn theme(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "theme"); defer t.deinit(); try t.file("t.txt", "x"); try t.start(31, 100, &.{ "-n", "3" }); try t.wait(8000, "t.txt"); try t.stable(700, 20000); // NextColor is no default word of the workspace tag: typed onto its end try t.press("left", "99", 1); try t.release("left", "99", 1); try t.key("i"); try t.key("space"); try t.send("NextColor"); try t.key("esc"); try t.settle(100); try t.stable(700, 10000); try t.snap("orchard"); try t.style("orchard"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("dusk"); try t.style("dusk"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("ink"); try t.style("ink"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("paper"); try t.style("paper"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("daybreak"); try t.style("daybreak"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("atelier"); try t.style("atelier"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("forge"); try t.style("forge"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("lagoon"); try t.style("lagoon"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("solarium"); try t.style("solarium"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("spectrum"); try t.style("spectrum"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("harvest"); try t.style("harvest"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("clay"); try t.style("clay"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("forge-black"); try t.style("forge-black"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("forge-soft"); try t.style("forge-soft"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("orchard-black"); try t.style("orchard-black"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("acme"); try t.style("acme"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("lapis"); try t.style("lapis"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); try t.snap("dark-plus"); try t.style("dark-plus"); try t.press("middle", "@NextColor", 1); try t.release("middle", "@NextColor", 1); try t.stable(700, 10000); // After orchard_black: acme and lapis, then the first faithful ports. try t.snap("solarized-dark"); try t.style("solarized-dark"); try t.done(); } // RULE: a results buffer is a list of things you can RUN, and its traits say // what a ROW IS. Every list before this one held LOCATIONS — a row with a // `path:LINE:COL` word inside it — so n/N select that word and Enter Looks it. // `SPC t t` (Themes) opens the first one whose rows are COMMANDS: `Theme // `, exactly the line you would type, with no path in it to pick out, so // n/N select the WHOLE ROW. One motion, two grains, and the same split either // way — the step only SELECTS, and Tab (Exec, or the middle button, which is // the same builtin) is what RUNS what it left. Walking the list therefore // wears nothing as you pass; the theme changes on the Tab, and picking one is // running it and stopping. There is still no preview state, nothing to confirm // and nothing to cancel: the row you ran is the theme you have. // // The whole ring is in the buffer, in sections: the fifteen native themes, // acme and lapis, the faithful ports a family at a time, the legacy helix and // dark, then everything exported from the vendored helix .toml and zed .json // files, sorted. The colors below are // read with snapstyle, so this proves the generated themes are real data and // not just names in a list. fn themesel(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "themesel"); defer t.deinit(); try t.lines("t.txt", 40, ""); try t.start(31, 100, &.{"t.txt"}); try t.wait(8000, "t.txt"); try t.stable(700, 20000); try t.snap("boot"); // SPC t t: the list lands below the pane that asked, focus stays HERE — but a // fresh output buffer is where the walk's ring starts, so the first n goes // into the list and every one after it carries on down it. try t.key("space t t"); try t.wait(10000, "Theme orchard"); try t.stable(700, 15000); try t.snap("list"); // n selects row 1 whole and Tab runs it: `Theme orchard`, which is already the // boot theme, so only the selection moves. That is the honest first step — an // idempotent command has to be safe to run. try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-orchard"); try t.style("step-orchard"); // ...and now the theme really does change under the cursor, one row at a time try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-dusk"); try t.style("step-dusk"); // Selection alone can skip rows without previewing or applying their themes. // Four steps reach atelier, the Acme homage; Tab then applies it. try t.key("space j n"); try t.key("space j n"); try t.key("space j n"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-atelier"); try t.style("step-atelier"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-forge"); try t.style("step-forge"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-lagoon"); try t.style("step-lagoon"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-solarium"); try t.style("step-solarium"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-spectrum"); try t.style("step-spectrum"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-harvest"); try t.style("step-harvest"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-clay"); try t.style("step-clay"); // The three native contrast variants precede acme and lapis, and then the first // ported family's section. Its heading // and blank separator are not stops in the n/N command walk. try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-forge-black"); try t.style("step-forge-black"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-forge-soft"); try t.style("step-forge-soft"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-orchard-black"); try t.style("step-orchard-black"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-acme"); try t.style("step-acme"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-lapis"); try t.style("step-lapis"); try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-dark-plus"); try t.style("step-dark-plus"); // across the Visual Studio Code section into Solarized: a section heading and // its blank line are skipped like the first. (The imported half, past the // legacy section, is sorted by name, so the ring is the same everywhere // whatever order the directory read handed the files over in.) try t.key("space j n"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-solarized-dark"); try t.style("step-solarized-dark"); // N walks back the same way — it is the exact inverse of n — and the Tab after // it runs the row it lands on, so the theme rewinds too try t.key("space j p"); try t.key("tab"); try t.stable(700, 15000); try t.snap("step-back"); try t.style("step-back"); // PICKING is just stopping: the theme the last Tab ran is still on, and the // list is closed with an explicit Del. No window move is needed to get there — // the walk lands IN the pane it steps, so the cursor has been in the list // since the first n. Body-normal Esc is Last, so it deliberately leaves this // document-like output buffer open. // ...and the WHOLE ring is in there: `ge` to the last line, which // only reaches `Theme zenburn` if nothing truncated the buffer on the way in. It // is an ordinary file pane, so it scrolls like one; a motion runs nothing and // neither does a step, so no theme changes here and the one the last Tab chose // is still on. try t.key("g e"); try t.stable(700, 15000); try t.snap("tail"); try t.key("space d"); try t.settle(100); try t.stable(700, 15000); try t.snap("picked"); try t.style("picked"); try t.done(); } // tree-sitter: open a .zig file, keyword/string/number/comment colors on; // edit re-highlights fn syntax(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "syntax"); defer t.deinit(); try t.file("demo.zig", "const std = @import(\"std\"); // greet\npub fn main() void {\n var x: u32 = 42;\n _ = x;\n}"); try t.start(31, 150, &.{ "-n", "3" }); try t.wait(8000, "demo.zig"); try t.stable(700, 20000); try t.press("left", "5", 9); try t.release("left", "5", 9); try t.stable(400, 5000); try t.key("i"); try t.send("demo.zig"); try t.key("esc"); try t.settle(100); try t.press("right", "6", 9); try t.release("right", "6", 9); try t.wait(10000, "@import"); try t.stable(700, 15000); try t.snap("zig-open"); try t.style("zig-open"); try t.done(); } // markup: the two prose grammars. Typst paints headings and the `#` code sigil // in the keyword colour, bold in the bold-attribute slot, italics and raw spans // in their own; markdown needs a SECOND grammar (markdown_inline) to see bold // and italics at all, and both languages inject a tagged code block's language fn markup(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "markup"); defer t.deinit(); try t.file("paper.typ", "= Typst heading\n\nProse with *bold* and _italic_ words, a `raw` span,\nand #emph[call] plus #let n = 42\n\n```zig\nfn widget() u8 { return 99; }\n```\n"); try t.file("notes.md", "# Markdown heading with *italic*\n\nProse with **bold**, *italic* and an `inline` span.\n\n```zig\nfn gadget() u8 { return 77; }\n```\n"); try t.start(25, 92, &.{"paper.typ"}); try t.wait(8000, "Typst heading"); try t.wait(8000, "widget"); try t.stable(700, 20000); try t.snap("typst"); try t.style("typst"); try t.start(25, 92, &.{"notes.md"}); try t.wait(8000, "Markdown heading"); try t.wait(8000, "gadget"); try t.stable(700, 20000); try t.snap("markdown"); try t.style("markdown"); try t.done(); } // `pardes -` keeps a program's colours: its SGR // becomes the +Pager's own colours over the plain text (red through the // theme's palette, truecolor as given, bold and underline, a man page's // overstrike), and every other escape (the OSC title) is dropped. The // needles waited for are split by escapes in the typed line, so only the // paged text holds them. fn pagercolor(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "pagercolor"); defer t.deinit(); try t.start(50, 100, &.{}); try t.wait(8000, "$"); try t.stable(700, 20000); try t.send("printf '\\033]0;title\\007\\033[31mred\\033[m \\033[1;32mbold green\\033[m \\033[38;2;200;100;0mrgb\\033[m \\033[4mul\\033[m N\\bNA\\bAM\\bME\\bE _\\bu_\\bs plain\\n' | $(readlink /proc/$PPID/exe) -"); try t.key("enter"); try t.wait(20000, "red bold green"); try t.stable(700, 20000); try t.snap("pager"); try t.style("pager-colours"); // A coloured diff: the rows pardes tints as added or removed are drawn as // its own diff, and git's colours stay on the rest (the bold header, the // cyan hunk line, the yellow commit line). try t.send("printf '\\033[33mcommit 0123\\033[33mabc\\033[m\\n\\033[1mdiff --git a/x b/x\\033[m\\n\\033[1m--- a/x\\033[m\\n\\033[1m+++ b/x\\033[m\\n\\033[36m@@ -1 +1 @@\\033[m\\n\\033[31m-old\\033[m\\n\\033[32m+new\\033[m\\n' | $(readlink /proc/$PPID/exe) -"); try t.key("enter"); try t.wait(20000, "0123abc"); try t.stable(700, 20000); try t.snap("pager-diff"); try t.style("pager-diff-colours"); try t.done(); } // cursor-line gutter: the line number on the cursor's row gets quiet bold ink // and follows modal movement (gg to the top, then jjj down three lines) fn cursorline(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var t = try Tty.init(gpa, exe, "cursorline"); defer t.deinit(); try t.lines("cur.txt", 20, ""); try t.start(31, 150, &.{ "-n", "3" }); try t.wait(8000, "cur.txt"); try t.stable(700, 20000); try t.press("left", "5", 9); try t.release("left", "5", 9); try t.stable(400, 5000); try t.key("i"); try t.send("cur.txt"); try t.key("esc"); try t.settle(100); try t.stable(400, 5000); try t.press("right", "6", 9); try t.release("right", "6", 9); try t.stable(700, 15000); try t.key("g g"); try t.stable(400, 5000); try t.snap("top"); try t.style("top"); try t.key("j j j"); try t.stable(400, 5000); try t.snap("down3"); try t.style("down3"); try t.done(); }