diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-08 23:37:38 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-09 01:28:28 -0300 |
| commit | b1769aba4a7c1984ab09bd3c90b69177b14c42d8 (patch) | |
| tree | cd04a96f003658b654244fffb137f483e2ff3384 /test/process/tty_layout.zig | |
| parent | 2c13f29da2441d0e0fb11f11bb7a180054030cc9 (diff) | |
| download | pardes-b1769aba4a7c1984ab09bd3c90b69177b14c42d8.tar.gz pardes-b1769aba4a7c1984ab09bd3c90b69177b14c42d8.zip | |
tests: the columns and layout snapshot scripts (14: colgrip collapse cornerdrag cornerdrag-left delask emptycol layout-close layout-open shrinktag tagalign tagalign2col windownav windowops wheeldrift) are process cases, test/process/tty_layout.zig, their goldens unchanged; checked against the old runner by the tty reading a drag as a motion (the same 7 fail in both); three core breaks (splitBelow at a third, minRows one more, a dropped column's width to its right) fail neither
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/process/tty_layout.zig')
| -rw-r--r-- | test/process/tty_layout.zig | 783 |
1 files changed, 782 insertions, 1 deletions
diff --git a/test/process/tty_layout.zig b/test/process/tty_layout.zig index bd551013..84f76be7 100644 --- a/test/process/tty_layout.zig +++ b/test/process/tty_layout.zig @@ -1,3 +1,784 @@ //! The tty frontend's own cases (test/tty.zig), columns, panes and tags: placement, grips, drags, collapse, the window ops. +const std = @import("std"); +const Tty = @import("../tty.zig").Tty; -pub const cases = .{}; +pub const cases = .{ + .{ "tty layout: colgrip", colgrip }, + .{ "tty layout: collapse", collapse }, + .{ "tty layout: cornerdrag", cornerdrag }, + .{ "tty layout: cornerdrag-left", cornerdrag_left }, + .{ "tty layout: delask", delask }, + .{ "tty layout: emptycol", emptycol }, + .{ "tty layout: layout-close", layout_close }, + .{ "tty layout: layout-open", layout_open }, + .{ "tty layout: shrinktag", shrinktag }, + .{ "tty layout: tagalign", tagalign }, + .{ "tty layout: tagalign2col", tagalign2col }, + .{ "tty layout: windownav", windownav }, + .{ "tty layout: windowops", windowops }, + .{ "tty layout: wheeldrift", wheeldrift }, +}; + +// Column grips: the two cells left of a column tag carry the column. A grabbed +// grip lights, and a rail in its color stands where the column will land. +// The right column is at x 50; its grip is cells 51-52 (1-based) on row 2. +fn colgrip(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "colgrip"); + defer t.deinit(); + try t.file("w.txt", "x"); + try t.start(24, 100, &.{"w.txt"}); + try t.wait(8000, "Newcol Joincol"); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + try t.key("a-n"); + try t.key("a-c"); + try t.stable(700, 15000); + try t.style("rest"); + // held on its own grip: lit, and no rail, since it lands where it is + try t.press("left", "51", 2); + try t.stable(400, 5000); + try t.style("held"); + // dropped short of the left column's middle, the left edge moves: the rail is + // in the seam cell left of where the column's rule will be + try t.drag("left", "41", 2); + try t.stable(400, 5000); + try t.snap("resize-drag"); + try t.style("resize-drag"); + try t.release("left", "41", 2); + try t.stable(700, 15000); + try t.snap("resize-done"); + // carried over the left column's left half it goes first; the window edge + // has no seam, so the rail runs in the gutter's last cell + try t.press("left", "41", 2); + try t.drag("left", "10", 2); + try t.stable(400, 5000); + try t.snap("reorder-drag"); + try t.style("reorder-drag"); + try t.release("left", "10", 2); + try t.stable(700, 15000); + try t.snap("reorder-done"); + try t.done(); +} + +// A default pane-tag command collapses to one row and restores the body. +// Exercise real middle clicks twice, then the tag's own execute key twice: a +// click types into the tag, Esc is its normal mode, and Tab executes there. +fn collapse(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "collapse"); + defer t.deinit(); + try t.file("kept.txt", "KEEP-FIRST\nKEEP-SECOND\nKEEP-THIRD"); + try t.start(25, 160, &.{"kept.txt"}); + try t.wait(8000, "KEEP-THIRD"); + try t.stable(500, 15000); + try t.snap("before"); + try t.press("middle", "@Collapse", 3); + try t.release("middle", "@Collapse", 3); + try t.stable(500, 8000); + try t.snap("middle-collapsed"); + // The terminal remembers its last cursor position even when hidden. The core + // screen explicitly reports null, guarding against a leaked body caret. + try t.snap9p("middle-collapsed-cursor"); + try t.press("middle", "@Collapse", 3); + try t.release("middle", "@Collapse", 3); + try t.wait(8000, "KEEP-THIRD"); + try t.stable(500, 8000); + try t.snap("middle-restored"); + try t.press("left", "@Collapse", 3); + try t.release("left", "@Collapse", 3); + try t.key("esc"); + try t.settle(100); + try t.key("tab"); + try t.stable(500, 8000); + try t.snap("tab-collapsed"); + try t.snap9p("tab-collapsed-cursor"); + try t.press("left", "@Collapse", 3); + try t.release("left", "@Collapse", 3); + try t.key("esc"); + try t.settle(100); + try t.key("tab"); + try t.wait(8000, "KEEP-THIRD"); + try t.stable(500, 8000); + try t.snap("tab-restored"); + // Save via the visible tag; the original bytes must survive all four toggles. + try t.press("middle", "@Save", 3); + try t.release("middle", "@Save", 3); + try t.stable(500, 8000); + try t.snapFile("unchanged", "kept.txt"); + try t.done(); +} + +// corner grabs: where a column edge crosses a pane edge, ONE drag moves both. +// Only the left column's h-splits make a corner — the v handle IS that column's +// last cell, so that is the only pane pair whose horizontal hint runs through +// it, and a corner therefore sits exactly where the two lines visibly cross. +// The layout is windowops': col 0 (x 0, w 50) holds panes 0 (rows 1-15) and 1 +// (rows 16-29), col 1 holds one pane. The corner is col 49, row 15. +fn cornerdrag(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "cornerdrag"); + defer t.deinit(); + try t.file("w.txt", "x"); + try t.start(31, 100, &.{ "-n", "3" }); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + // hover the corner: no hints (columns resize by their grips); the frame + // stays empty + try t.motion("50", 16); + try t.stable(400, 5000); + try t.snap("hover-corner"); + // CONTROL: the same vertical edge ten rows off the crossing is a plain edge. + // The identical diagonal drag moves the column and nothing else — pane 0 still + // ends on row 15, and the preview is one dash, not two + try t.press("left", "50", 7); + try t.drag("left", "30", 25); + try t.stable(400, 5000); + try t.snap("edge-drag"); + try t.release("left", "30", 25); + try t.motion("45", 25); + try t.stable(500, 8000); + try t.snap("edge-done"); + // the corner itself, now at col 0's new last col (29) and still row 15: drag it + // up and to the right and both boundaries follow the one mouse + try t.press("left", "30", 17); + try t.drag("left", "60", 9); + try t.stable(400, 5000); + try t.snap("corner-drag"); + try t.release("left", "60", 9); + try t.motion("45", 25); + try t.stable(500, 8000); + try t.snap("corner-done"); + // clamp interaction, half one: shove the corner off the right edge while + // staying mid-height. The column preview parks at its MINW stop; the row + // preview keeps tracking the mouse exactly + try t.press("left", "60", 9); + try t.drag("left", "99", 21); + try t.stable(400, 5000); + try t.snap("clamp-x"); + // half two, the mirror: below the bottom at mid-width. Now the ROW preview + // parks (the lower pane keeps its tag row) and the COLUMN keeps tracking + try t.drag("left", "60", 31); + try t.stable(400, 5000); + try t.snap("clamp-y"); + try t.release("left", "60", 31); + try t.motion("45", 25); + try t.stable(500, 8000); + try t.snap("clamp-done"); + try t.done(); +} + +// corner grabs on the RIGHT column's side of the v border. The v handle is the +// LEFT column's last cell, so that column's own h hint runs THROUGH it while the +// right column's hints start one cell further right — the crossing there reads as +// a T butting into the junction rather than a full cross, and it is grabbable all +// the same: one drag moves the column edge and the RIGHT column's pane edge. +// Layout: windowops' -n 3 (col 0 x 0 w 50, panes on rows 1-15 and 16-29; col 1 +// x 50 w 50), then focus right and Alt-n so col 1 holds two panes as well, split +// at ITS own row. The two corners on col 49 are then row 16 (col 0's seam, the +// one that already worked) and row 5 (col 1's, the one this script is about). +fn cornerdrag_left(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "cornerdrag-left"); + defer t.deinit(); + try t.file("w.txt", "x"); + try t.start(31, 100, &.{ "-n", "3" }); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + // a second pane in the RIGHT column + try t.key("c-w l enter"); + try t.stable(400, 5000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("right-split"); + // hover col 1's corner: hovering draws no hints any more, so the frame is + // empty; the drags below still show their previews + try t.motion("50", 5); + try t.stable(400, 5000); + try t.snap("hover-corner"); + // CONTROL: col 0's own seam, hovered: no hint either + try t.motion("50", 16); + try t.stable(400, 5000); + try t.snap("hover-left-corner"); + // grab col 1's corner and drag down-left: the column preview and col 1's row + // preview both follow the one mouse, the row dashes lying to the RIGHT of the v + // line because they are the right column's + try t.press("left", "50", 6); + try t.drag("left", "30", 13); + try t.stable(400, 5000); + try t.snap("corner-drag"); + try t.release("left", "30", 13); + try t.motion("45", 25); + try t.stable(500, 8000); + try t.snap("corner-done"); + try t.done(); +} + +// Del from the keyboard on a pane with open panes above AND below asks, on the +// pane's notice band, which one takes its rows: k above, j below, anything else +// keeps the pane. A click, and DelAbove/DelBelow (Del k / Del j), never ask. +fn delask(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "delask"); + defer t.deinit(); + try t.file("top.txt", "top-marker"); + try t.start(36, 100, &.{"top.txt"}); + try t.wait(8000, "top-marker"); + try t.stable(700, 20000); + // two scratch panes below the file, each saying which it is, then focus the + // middle one + try t.key("space f n"); + try t.stable(400, 5000); + try t.key("i"); + try t.send("middle-pane"); + try t.key("esc"); + try t.settle(100); + try t.key("space f n"); + try t.stable(400, 5000); + try t.key("i"); + try t.send("bottom-pane"); + try t.key("esc"); + try t.settle(100); + try t.key("c-w k enter"); + try t.stable(400, 5000); + try t.snap("three"); + // asked, and nothing closes yet; the question goes up on the band only after + // config.del_question_delay_ns (400 ms) with no answer, a hint + try t.key("space d"); + try t.settle(700); + try t.stable(400, 5000); + try t.snap("asked"); + // Esc takes the question back: the pane stays + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("kept"); + // j: the pane below grows over the middle one's rows, the file keeps its own + try t.key("space d"); + try t.stable(400, 5000); + try t.key("j"); + try t.stable(700, 10000); + try t.snap("below-took"); + // a pane under it, and DelBelow (Del j) appended to the middle one's text and + // executed with a click: no question, the pane below takes the rows + try t.key("space f n"); + try t.stable(400, 5000); + try t.key("i"); + try t.send("third-pane"); + try t.key("esc"); + try t.settle(100); + try t.key("c-w k enter"); + try t.stable(400, 5000); + try t.key("A"); + try t.send(" DelBelow"); + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("typed"); + try t.press("middle", "@DelBelow", 21); + try t.release("middle", "@DelBelow", 21); + try t.stable(700, 10000); + try t.snap("below-took-click"); + // a fresh pane at the foot of the column (acme's New takes the bottom half of + // the last pane), and the third one, now between the file and it, closed by a + // middle click on its tag's Del: no question, and the rows go up as they + // always have + try t.press("left", "10", 5); + try t.release("left", "10", 5); + try t.stable(400, 5000); + try t.key("space f n"); + try t.stable(400, 5000); + try t.snap("four"); + try t.press("middle", "@Del", 20); + try t.release("middle", "@Del", 20); + try t.stable(700, 10000); + try t.snap("mouse-del"); + try t.done(); +} + +// A column can hold no pane, as acme's can (cols.c:186). Newcol makes one +// empty, its tag over blank space and holding the keyboard; the next pane +// made while it is the active column fills it whole (makenewwindow, +// util.c:468-469); and a shell that exits there leaves it empty again, the +// keyboard back on its tag. +fn emptycol(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "emptycol"); + defer t.deinit(); + try t.file("notes.txt", "one\ntwo"); + try t.config("Verbose off"); + try t.start(24, 100, &.{"notes.txt"}); + try t.wait(8000, "notes.txt"); + try t.stable(700, 20000); + try t.key("space c n"); + try t.stable(400, 5000); + try t.snap("newcol"); + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("filled"); + try t.key("c-b"); + try t.stable(400, 5000); + try t.send("exit"); + try t.key("enter"); + try t.stable(700, 10000); + try t.snap("emptied"); + try t.done(); +} + +// every pane close hands its space to ONE sibling, the rest of the column +// keeps its sizes: Alt-c move-out, tag Del, and shell exit (pty EOF); an +// emptied column stays, as acme's does, its tag over blank space +fn layout_close(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "layout-close"); + defer t.deinit(); + try t.file("marker.txt", "x"); + try t.start(41, 140, &.{ "-n", "3" }); + try t.wait(8000, "marker.txt"); + try t.stable(700, 20000); + // build a left column of five: Alt-n three times from pane 0 (active follows + // the new pane, each split takes from the freshly split pane only) + try t.press("left", "5", 9); + try t.release("left", "5", 9); + try t.stable(400, 5000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("built"); + // Alt-c: the active (4th) pane moves to a fresh column; the pane above it + // absorbs its rows, the other three keep theirs (columns reflow horizontally) + try t.key("a-c"); + try t.stable(700, 15000); + try t.snap("altc"); + // Del the 2nd pane: source-local column insertion makes this column too narrow + // to expose its tag words, so focus its body and invoke the same pane-scoped + // builtin by chord. With panes above and below, the chord asks which one + // takes the rows: k, the pane above, which also takes the focus. The other + // panes keep their rows. + try t.press("left", "5", 9); + try t.release("left", "5", 9); + try t.stable(400, 5000); + try t.key("space d"); + try t.key("k"); + try t.stable(700, 10000); + try t.snap("del"); + // exit the (now) 2nd shell through its real tty: pty EOF, again only the pane + // above absorbs — and takes the focus too, not the pane that had it before + // this one (the moved-out column) + try t.press("left", "40", 9); + try t.release("left", "40", 9); + try t.stable(400, 5000); + try t.press("left", "5", 24); + try t.release("left", "5", 24); + try t.stable(400, 5000); + try t.key("c-b"); + try t.stable(400, 5000); + try t.send("exit"); + try t.key("enter"); + try t.stable(700, 10000); + try t.snap("exit"); + // exit the moved-out pane's shell: its column stays where it was, empty, the + // keyboard on its tag; the other columns keep their widths + try t.press("left", "40", 9); + try t.release("left", "40", 9); + try t.stable(400, 5000); + try t.key("c-b"); + try t.stable(400, 5000); + try t.send("exit"); + try t.key("enter"); + try t.stable(700, 10000); + try t.snap("colclose"); + try t.done(); +} + +// every pane open splits ONE existing pane, the rest of the column keeps its +// sizes: Alt-n splits the active pane, an execute-spawned command pane for a file's +// dir splits only the bottom pane of the rightmost column. At this narrow +// width the first looked-up file also splits below its source, leaving every +// unrelated pane (including the ones above the source) at its exact rectangle. +fn layout_open(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "layout-open"); + defer t.deinit(); + try t.dir("sub"); + try t.file("sub/f.txt", "echo 'TTY'OK"); + try t.start(31, 100, &.{ "-n", "3" }); + try t.wait(8000, "sub"); + try t.stable(700, 20000); + // give pane 0 (top-left) some content so its content-height split is visible + try t.press("left", "5", 9); + try t.release("left", "5", 9); + try t.stable(400, 5000); + try t.key("i"); + try t.send("echo one; echo two"); + try t.key("enter"); + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("before"); + // Alt-n: new shell below pane 0 — the bottom pane's boundary must not move + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("altn-left"); + // make the right column two panes (Alt-n in a fresh column, trivial split) + try t.press("left", "70", 9); + try t.release("left", "70", 9); + try t.stable(400, 5000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("altn-right"); + // look sub/f.txt from the bottom-left shell: the first doc splits this shell, + // not the top-left pane. Both panes above it and the entire right column stay put. + try t.press("left", "5", 28); + try t.release("left", "5", 28); + try t.stable(400, 5000); + try t.key("i"); + try t.send("sub/f.txt"); + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.press("right", "7", 28); + try t.release("right", "7", 28); + try t.stable(700, 15000); + try t.snap("file-open"); + // execute the file's command (middle drag over line 1): it runs as a command + // pane for sub/, forked at the bottom of the rightmost column, splitting only + // the pane above it + try t.press("middle", "8", 25); + try t.drag("middle", "19", 25); + try t.release("middle", "19", 25); + try t.wait(10000, "TTYOK"); + try t.motion("40", 27); + try t.stable(700, 10000); + try t.snap("ttydir"); + try t.done(); +} + +// a terminal shrinks only to its tag and 2 body rows (a text pane would go +// to its tag alone): the pane below dragged by its grip up to the tag row +// stops there -- a terminal has no rule between panes, so the grip is the +// handle, as acme's button is -- the gutter box still grabs a move, and +// dragging back down restores the body intact +fn shrinktag(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "shrinktag"); + defer t.deinit(); + try t.file("w.txt", "x"); + try t.start(31, 100, &.{ "-n", "3" }); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + // content in pane 0 so the restored body is provably intact + try t.press("left", "5", 9); + try t.release("left", "5", 9); + try t.stable(400, 5000); + try t.key("i"); + try t.send("echo one; echo two"); + try t.key("enter"); + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("before"); + // drag the lower pane's grip up under pane 0's tag row: it keeps 2 body rows + try t.press("left", "1", 18); + try t.drag("left", "1", 3); + try t.release("left", "1", 3); + try t.motion("40", 25); + try t.stable(500, 8000); + try t.snap("shrunk"); + // the shrunk pane's gutter box grabs a move: preview one into the right + // column, abort by releasing over the pane itself + try t.press("left", "1", 3); + try t.drag("left", "70", 9); + try t.stable(400, 5000); + try t.snap("move-preview"); + try t.drag("left", "20", 3); + try t.release("left", "20", 3); + try t.stable(400, 5000); + // re-enlarge: the lower pane's grip, now under pane 0's 2 body rows, pulled + // back down + try t.press("left", "1", 7); + try t.drag("left", "1", 18); + try t.release("left", "1", 18); + try t.motion("40", 25); + try t.stable(500, 8000); + try t.snap("restored"); + // the bottom pane stops at ITS tag and 2 rows too: its grip dragged past the + // bottom + try t.press("left", "1", 18); + try t.drag("left", "1", 31); + try t.release("left", "1", 31); + try t.motion("40", 25); + try t.stable(500, 8000); + try t.snap("bottom-shrunk"); + try t.done(); +} + +// Compact commands stay beside their own prefix regardless of sibling length. +fn tagalign(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "tagalign"); + defer t.deinit(); + try t.dir("deep"); + try t.dir("deep/nested-project-directory"); + try t.file("deep/nested-project-directory/document.txt", "alpha\nbeta\ngamma"); + try t.start(31, 100, &.{"deep/nested-project-directory/document.txt"}); + try t.wait(8000, "Newcol Joincol"); + try t.wait(8000, "document.txt"); + try t.stable(700, 20000); + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("aligned"); + // Clipping never changes underlying tag text or shorter siblings' positions. + try t.resize(31, 87); + try t.stable(400, 5000); + try t.snap("fits"); + try t.resize(31, 86); + try t.stable(400, 5000); + try t.snap("overby1"); + try t.resize(31, 100); + try t.stable(700, 15000); + try t.press("left", "12", 3); + try t.release("left", "12", 3); + try t.stable(400, 5000); + try t.snap("clicked"); + // The click was on the path, so it drafted a name; Esc keeps it pending and + // a second Esc drops the draft. `:` + // then `A` puts the caret after the tag's end, which reveals the complete + // command suffix; a scrolled Del still executes. + try t.resize(31, 70); + try t.key("esc"); + try t.settle(100); + try t.key("esc"); + try t.settle(100); + try t.key(":"); + try t.key("A"); + try t.stable(400, 5000); + try t.snap("revealed"); + try t.press("middle", "@Del", 4); + try t.release("middle", "@Del", 4); + try t.stable(700, 15000); + try t.snap("alone"); + try t.done(); +} + +// Each compact command run follows its own prefix, never a neighboring path. +fn tagalign2col(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "tagalign2col"); + defer t.deinit(); + try t.dir("deep"); + try t.dir("deep/proj"); + try t.file("deep/proj/document.txt", "alpha\nbeta\ngamma"); + try t.start(31, 160, &.{"deep/proj/document.txt"}); + try t.wait(8000, "Newcol Joincol"); + try t.wait(8000, "document.txt"); + try t.stable(700, 20000); + // A shell in a separate right-hand column. + try t.key("a-n"); + try t.key("a-c"); + try t.stable(700, 15000); + try t.key("space w h enter"); + try t.stable(400, 5000); + try t.snap("onecol"); + // A left sibling does not move either existing tag's command text. + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("aligned"); + // Resizing moves the right column as a whole and clips without hidden spaces. + try t.press("left", "80", 11); + try t.drag("left", "100", 11); + try t.release("left", "100", 11); + try t.stable(700, 15000); + try t.snap("widened"); + try t.done(); +} + +// RULE: moving focus is a BUILTIN like any other, so there is ONE +// implementation and every route reaches it. SPC w (as Ctrl-w) is window mode: +// h/j/k/l move an outline by the same geometric nearest pane Left/Down/Up/Right +// use and Enter focuses it — and SPC j j +// plus body-normal Esc run Last, the hop to the pane you were in BEFORE this +// one, whichever kind it was. It reads the focus history the core already keeps +// to hand focus back when a pane closes, and going somewhere is itself recorded, +// which is what makes the hop back the same key. Focus shows up in the golden's +// `cursor=` header: that is the +// ACTIVE pane's cursor, so each snap is named by the pane it should land in. +fn windownav(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "windownav"); + defer t.deinit(); + try t.file("w.txt", "alpha\nbeta\ngamma"); + try t.start(31, 100, &.{"w.txt"}); + try t.wait(8000, "Newcol Joincol"); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + // A FILE boots alone now, so the terminal every hop below needs is opened here: + // Alt-n opens it and focuses it, Alt-c puts it in a column of its own on the + // right, SPC w h Enter comes straight back — which also puts the shell on the stack, + // and Last only ever names a pane that is on it. (`New`/`Newcol` open an empty + // +New scratch now, not a shell.) + try t.key("a-n"); + try t.key("a-c"); + try t.stable(700, 15000); + try t.key("space w h enter"); + try t.stable(400, 5000); + // left column = the file, right column = that shell; the file has focus + try t.snap("start"); + // SPC j j: the pane before this one, which is the shell just opened + try t.key("space j j"); + try t.stable(400, 5000); + try t.snap("to-term"); + // ...and back, because going there made the file the pane before THAT + try t.key("space j j"); + try t.stable(400, 5000); + try t.snap("back-to-file"); + // A bare Esc from a body in normal mode dispatches that SAME builtin: file to + // terminal, then the same key on the normal-mode terminal returns to the file. + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("esc-to-term"); + try t.key("esc"); + try t.settle(100); + try t.stable(400, 5000); + try t.snap("esc-back-to-file"); + // Alt-n: a second shell, below the file — the left column now has two rows + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("altn"); + // SPC w k Enter: up out of that new shell into the file above it + try t.key("space w k enter"); + try t.stable(400, 5000); + try t.snap("up"); + // SPC w l Enter: right, into the launch shell + try t.key("space w l enter"); + try t.stable(400, 5000); + try t.snap("right"); + // SPC w h Enter: left, back into the file column + try t.key("space w h enter"); + try t.stable(400, 5000); + try t.snap("left"); + // SPC w j Enter: down, into the shell under the file + try t.key("space w j enter"); + try t.stable(400, 5000); + try t.snap("down"); + // SPC j j from a terminal: the file, which is where SPC w h Enter left off + try t.key("space j j"); + try t.stable(400, 5000); + try t.snap("toggle-doc"); + // ...and back to the shell just left, not the launch shell in the right column, + // which was focused earlier + try t.key("space j j"); + try t.stable(400, 5000); + try t.snap("toggle-back"); + try t.done(); +} + +// hover (no hints), border drags, grip resize, move drag, Alt-n, Ctrl-w focus (window mode), Debug box +fn windowops(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "windowops"); + defer t.deinit(); + try t.file("w.txt", "x"); + try t.start(31, 100, &.{ "-n", "3" }); + try t.wait(8000, "w.txt"); + try t.stable(700, 20000); + // hover over the left column's last col: no hint, columns resize by their grips + try t.motion("50", 10); + try t.stable(400, 5000); + try t.snap("hover-v"); + // hover over the top-left pane's last row: no hint, a row of text is no handle + try t.motion("20", 16); + try t.stable(400, 5000); + try t.snap("hover-h"); + // drag the vertical border 10 cols left + try t.press("left", "50", 11); + try t.drag("left", "40", 11); + try t.stable(400, 5000); + try t.snap("border-drag"); + try t.release("left", "40", 11); + try t.stable(500, 8000); + try t.snap("border-done"); + // resize the left pair by the lower pane's grip, 4 rows up (a terminal has no + // rule between panes; pane 0's last row is now 13) + try t.press("left", "1", 18); + try t.drag("left", "1", 14); + try t.release("left", "1", 14); + try t.stable(500, 8000); + try t.snap("hborder-done"); + // move pane 1 (its gutter box) into the right column + try t.press("left", "1", 18); + try t.drag("left", "70", 9); + try t.stable(400, 5000); + try t.snap("move-preview"); + try t.release("left", "70", 9); + try t.stable(500, 8000); + try t.snap("moved"); + // Alt-n: a new shell below the active pane + try t.key("a-n"); + try t.stable(700, 15000); + try t.snap("altn"); + // Ctrl-w l Enter: window mode, the outline right, into the pane just moved to + // the right column, and Enter focuses it (windownav covers the leader side, + // SPC w); `h` from here would have nothing to its left to prove. + try t.key("c-w l enter"); + try t.stable(400, 5000); + try t.snap("focus-right"); + // Debug overlay on (topbar middle-click on Debug), then off + try t.press("middle", "@Debug", 1); + try t.release("middle", "@Debug", 1); + try t.stable(400, 8000); + try t.snap("debug-on"); + try t.style("debug-on"); + try t.press("middle", "@Debug", 1); + try t.release("middle", "@Debug", 1); + try t.stable(400, 8000); + try t.snap("debug-off"); + try t.done(); +} + +// the touchpad drift guard (config.wheel_guard_ticks). A two-finger swipe that +// is MEANT to be vertical carries a little sideways drift and the pad turns it +// into wheel_left/wheel_right, so the view used to slide sideways under a plain +// scroll. Every vertical tick re-arms the guard; a horizontal tick spends one +// instead of scrolling. SGR codes are vaxis's: 64/65 = wheel up/down (the +// `wheel` command), 66/67 = wheel RIGHT/left, sent raw as hscroll.snap does. +// The drift ticks here are all rightward on purpose: leftward drift at column 0 +// is clamped away and would prove nothing. +fn wheeldrift(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "wheeldrift"); + defer t.deinit(); + try t.lines("drift.txt", 20, "_0123456789_abcdefghij_ZEND"); + try t.start(17, 70, &.{"drift.txt"}); + try t.wait(8000, "drift.txt"); + try t.stable(700, 20000); + // the guard protects HSCROLL, and hscroll only exists with soft wrap off (a + // wrapped body has nothing off to the right to drift towards), so turn it off + // first — otherwise every sideways tick is a no-op and the test proves nothing + try t.key("space t w"); + try t.stable(400, 5000); + try t.snap("home"); + // a drifting swipe: five ticks down with three sideways ones mixed in. The + // view scrolls DOWN five lines and does not move one column sideways. + try t.wheel("down", "10", 5); + try t.wheel("down", "10", 5); + try t.send("\x1b[<66;10;6M"); + try t.wheel("down", "10", 5); + try t.send("\x1b[<66;10;6M"); + try t.send("\x1b[<66;10;6M"); + try t.wheel("down", "10", 5); + try t.wheel("down", "10", 5); + try t.stable(400, 5000); + try t.snap("drifted"); + // the guard is armed at 3 now, so a DELIBERATE horizontal swipe pays it off + // first: these three ticks still move nothing (without the guard they would + // have shifted the text 12 columns) + try t.send("\x1b[<66;10;6M"); + try t.send("\x1b[<66;10;6M"); + try t.send("\x1b[<66;10;6M"); + try t.stable(400, 5000); + try t.snap("paying"); + // ...and from the fourth tick on it scrolls freely: two ticks, 8 columns + try t.send("\x1b[<66;10;6M"); + try t.send("\x1b[<66;10;6M"); + try t.stable(400, 5000); + try t.snap("moved"); + // vertical again re-arms the guard, so drift is swallowed once more even + // though horizontal was just running + try t.wheel("up", "10", 5); + try t.send("\x1b[<66;10;6M"); + try t.send("\x1b[<66;10;6M"); + try t.stable(400, 5000); + try t.snap("rearmed"); + try t.done(); +} |
