summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 10:45:49 -0300
committerGabriel Schneider <[email protected]>2026-11-04 10:48:35 -0300
commita0ec419725ebb4094d811f5206eb0d95bbc5add0 (patch)
treefddf0fd9e4bd3e6861348133bbb71c315ad4206c
parent52bfa3f2aa8f8158d4d7ca720d81ea0c654f94bf (diff)
downloadpardes-a0ec419725ebb4094d811f5206eb0d95bbc5add0.tar.gz
pardes-a0ec419725ebb4094d811f5206eb0d95bbc5add0.zip
test: src/pardes.zig's three window-mode tests through the 9P tree alone, in test/behaviour/modes.zig (guide.typ's Modes): Ctrl-w outlining the pane with the keyboard (its tag in the outline's colour, each box its letter), h j k l moving only the outline, Enter, Esc (after SPC w), : (its tag the keyboard's) and a letter giving a pane the keyboard, other keys changing nothing; d deleting the outlined pane (between two it waits for k or j, Esc taking it back; the rows and the outline going to the pane that took them, one neighbour closing at once), c collapsing and restoring it (the ctl read's collapsed), the mode staying on until Enter; window keys walking from the top pane up to its column's tag (normal mode, w moving its caret), across columns and back to the caret it had, up to the workspace tag, down again, and : back to the body; each checked to fail against a break (h j k l moving the keyboard too, a letter choosing nothing, the outline's tint not painted, the outline dropped after d, c not collapsing, k past a column's top pane doing nothing)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/pardes.zig151
-rw-r--r--test/behaviour/modes.zig157
2 files changed, 157 insertions, 151 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 70bcf7c9..ba09b3b6 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -3133,45 +3133,6 @@ test "s in a header selects in the header's own text" {
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
}
-test "window keys walk from a pane up through the column and workspace tags and back" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
- defer p.deinit();
- _ = try p.setTestFile("body\n");
- p.newColumn(0);
- p.newScratchIn(0, p.activeColumn().?);
- p.sync();
- p.active = p.col_panes[0][0];
- const window = struct {
- fn key(core: *Pardes, letter: u21) void {
- core.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- core.update(.{ .key = .{ .cp = letter } });
- }
- };
- // Up from the top pane: its column's tag, in normal mode; `:` there is
- // the way back to the body.
- window.key(p, 'k');
- try std.testing.expect(p.header_focus and p.header_column.? == 0);
- try std.testing.expectEqual(Text.Mode.normal, p.col_tags[0].mode);
- p.update(.{ .key = .{ .cp = 'w' } });
- try std.testing.expect(p.col_tags[0].cur_col > 0);
- const remembered = p.col_tags[0].cur_col;
- window.key(p, 'l');
- try std.testing.expect(p.header_focus and p.header_column.? == 1);
- window.key(p, 'h');
- try std.testing.expectEqual(remembered, p.col_tags[0].cur_col);
- window.key(p, 'k');
- try std.testing.expect(p.header_focus and p.header_column == null);
- window.key(p, 'j');
- try std.testing.expect(p.header_focus and p.header_column.? == 0);
- window.key(p, 'j');
- try std.testing.expect(!p.header_focus);
- try std.testing.expectEqual(p.col_panes[0][0], p.active);
- window.key(p, 'k');
- p.update(.{ .key = .{ .cp = ':' } });
- try std.testing.expect(!p.header_focus and p.panes[p.active].?.focus == .body);
- try std.testing.expectEqualStrings("body\n", p.panes[0].?.file.?.content);
-}
-
pub const Mouse = struct {
/// The host has inverted a compact body layer. Physical col/row still
/// route pane chrome; these coordinates address the pane's logical text.
@@ -8409,63 +8370,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" {
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
}
-test "window mode moves an outline and focuses it on Enter, Esc or a label" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 });
- defer p.deinit();
- _ = try p.setTestFile("left\n");
- _ = try p.newShell(1, "");
- try std.testing.expect(layout.splitColumn(p, 0, 1, false));
- p.newScratchBelow(1);
- p.sync();
- const lower = for (p.panes, 0..) |slot, id| {
- if (slot != null and id > 1) break id;
- } else return error.TestExpectedScratch;
- p.active = 0;
- // Ctrl-w enters it; h/j/k/l move only the outline.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
- p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
- try std.testing.expect(p.window_pick != null and p.window_pick.? != 0);
- p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- try std.testing.expectEqual(@as(?usize, lower), p.window_pick);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(lower, p.active);
- try std.testing.expect(p.window_pick == null);
- // SPC w enters it too, and Esc also leaves it on the outlined pane.
- p.update(.{ .key = .{ .cp = ' ', .text = " " } });
- p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
- p.update(.{ .key = .{ .cp = 'h', .text = "h" } });
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expect(p.window_pick == null);
- // Other keys change nothing.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = '!', .text = "!" } });
- try std.testing.expectEqual(@as(?usize, 0), p.window_pick);
- p.update(.{ .key = .{ .cp = Key.escape } });
- // `:` focuses the outlined pane's tag.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'l', .text = "l" } });
- p.update(.{ .key = .{ .cp = ':', .text = ":" } });
- try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag);
- p.update(.{ .key = .{ .cp = Key.escape } });
- // A label goes straight there: the left column's pane is "a".
- try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
- p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- // Painted: the outlined tag's band in the selection colour, each pane's
- // letter in its tag's box.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Window"));
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- const shown = try p.render(arena.allocator());
- try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg);
- const box = shown.at(p.rects[0].x, p.tagTop(p.panes[0].?, p.rects[0]));
- try std.testing.expectEqualStrings("a", box.text[0..box.len]);
-}
-
test "the Del question shows only once its delay is up: a quick SPC d j never sees it" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
@@ -8516,61 +8420,6 @@ test "the Del question shows only once its delay is up: a quick SPC d j never se
try std.testing.expect(p.panes[mid] == null);
}
-test "window mode d deletes the outlined pane and asks k or j, c collapses it, and the mode stays" {
- if (platform == .web) return;
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
- defer p.deinit();
- p.settings.placement = .pardes; // the neighbours below are what is under test
- const top = p.active;
- p.newScratchBelow(top);
- const mid = p.active;
- p.newScratchBelow(mid);
- const low = p.active;
- p.sync();
- const h = [_]u16{ p.rects[top].h, p.rects[mid].h, p.rects[low].h };
- // Neither key is a pane's label.
- try std.testing.expect(std.mem.indexOfAny(u8, layout.window_labels, "hjkldc") == null);
-
- // Ctrl-w from the bottom pane, the outline up to the middle one.
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'k', .text = "k" } });
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- // c folds the outlined pane to its tag and back, the mode staying.
- p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
- try std.testing.expect(p.panes[mid].?.collapsed);
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
- try std.testing.expect(!p.panes[mid].?.collapsed);
- p.sync();
- try std.testing.expectEqual(h[1], p.rects[mid].h);
-
- // d with panes above and below asks, as SPC d does; Esc takes it back
- // and the outline stays where it was.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[mid].?.prompt);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(p.panes[mid] != null and p.panes[mid].?.prompt == .none);
- try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
- // j: the pane below takes the rows, and the outline goes with them.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- p.sync();
- try std.testing.expect(p.panes[mid] == null);
- try std.testing.expectEqual(h[0], p.rects[top].h);
- try std.testing.expectEqual(h[1] + h[2], p.rects[low].h);
- try std.testing.expectEqual(@as(?usize, low), p.window_pick);
- // With one neighbour there is nothing to ask: d closes it at once,
- // the outline on the pane that grew.
- p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
- p.sync();
- try std.testing.expect(p.panes[low] == null);
- try std.testing.expectEqual(@as(?usize, top), p.window_pick);
- // Enter leaves the mode on it.
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(p.window_pick == null);
- try std.testing.expectEqual(top, p.active);
-}
-
test "raw tty Ctrl-B switches to editor mode without sending child input" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index dde3ffb6..f29a4b56 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -102,3 +102,160 @@ test "modes: Esc back into a file leaves its view where it was, and a look centr
const drawn_at = line - try topLine(&s, "/test.txt");
try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1);
}
+
+/// Three panes named /a.txt (left column), /b.txt over /c.txt (right),
+/// the keyboard on /a.txt; their serials.
+fn threePanes(s: *Session) ![3]u32 {
+ const a = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{a}), "/a.txt\n");
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ const b = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{b}), "New\n");
+ const c = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{b}), "/b.txt\n");
+ try s.write(s.at("/pane/{d}/name", .{c}), "/c.txt\n");
+ try s.write("/focus", s.at("{d}\n", .{a}));
+ return .{ a, b, c };
+}
+
+/// The panes whose tag (`name Save`) is drawn in `lit`, the outline's colour.
+fn outlined(s: *Session, lit: []const u8, names: []const []const u8) ![]const u8 {
+ var found: []const u8 = "";
+ for (names) |name| {
+ const x, const y = try s.where(s.at("{s} Save", .{name}));
+ if (std.mem.eql(u8, lit, try s.bg(x, y))) found = s.at("{s}{s}", .{ found, name });
+ }
+ return found;
+}
+
+test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, : or a pane's letter gives it the keyboard" {
+ var s = try Session.initFile(std.testing.allocator, "left\n");
+ defer s.deinit();
+ const a, const b, const c = try threePanes(&s);
+ const names = &[_][]const u8{ "/a.txt", "/b.txt", "/c.txt" };
+ try s.keys("\x17");
+ const x, const y = try s.where("/a.txt Save");
+ const lit = try s.bg(x, y);
+ try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names));
+ // Each pane's box shows its letter: the left column's is a.
+ try std.testing.expectEqualStrings("a /a.txt", (try s.screen())[y * 81 ..][0.."a /a.txt".len]);
+ try s.keys("l");
+ try std.testing.expectEqualStrings("/b.txt", try outlined(&s, lit, names));
+ try s.keys("j");
+ try std.testing.expectEqualStrings("/c.txt", try outlined(&s, lit, names));
+ try expectEqual(a, try s.focused());
+ try s.keys("\n");
+ try expectEqual(c, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, names));
+ // SPC w enters it too, and Esc leaves it on the outlined pane.
+ try s.keys(" wh\x1b");
+ try expectEqual(a, try s.focused());
+ // Other keys change nothing.
+ try s.keys("\x17!");
+ try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names));
+ try s.keys("\x1b");
+ // `:` gives the outlined pane's tag the keyboard.
+ try s.keys("\x17l:");
+ try expectEqual(b, try s.focused());
+ try expectEqual((try s.where("/b.txt Save"))[1], (try s.cursor()).?[1]);
+ try s.keys("\x1b");
+ // A letter goes straight there.
+ try s.keys("\x17a");
+ try expectEqual(a, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, names));
+}
+
+fn listed(s: *Session, n: u32) !bool {
+ var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (rows.next()) |row| if (std.mem.startsWith(u8, row, s.at("{d} ", .{n}))) return true;
+ return false;
+}
+
+test "modes: in window mode d deletes the outlined pane, asking k or j between two, c collapses it, and the mode stays on" {
+ var s = try Session.initFile(std.testing.allocator, "top\n");
+ defer s.deinit();
+ // The neighbours below are what is under test: each New right under its asker.
+ try s.write("/ctl", "Placement pardes\n");
+ const top = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{top}), "New\n");
+ const mid = try s.focused();
+ try s.write(s.at("/pane/{d}/exec", .{mid}), "New\n");
+ const low = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n");
+ try s.write(s.at("/pane/{d}/name", .{low}), "/low\n");
+ const names = &[_][]const u8{ "/test.txt", "/mid", "/low" };
+ const row_top = (try s.where("/test.txt Save"))[1];
+ const row_mid = (try s.where("/mid Save"))[1];
+ const row_low = (try s.where("/low Save"))[1];
+ // From the bottom pane, the outline up to the middle one.
+ const mx, const my = try s.where("/mid Save");
+ const plain = try s.bg(mx, my);
+ try s.keys("\x17k");
+ const lit = try s.bg(mx, my);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ // c folds it to its tag and back, the mode staying.
+ try s.keys("c");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") != null);
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ try s.keys("c");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") == null);
+ try expectEqual(row_low, (try s.where("/low Save"))[1]);
+ // d between two panes asks, as SPC d does; Esc takes it back, the
+ // outline where it was.
+ try s.keys("d\x1b");
+ try std.testing.expect(try listed(&s, mid));
+ try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names));
+ // j: the pane below takes the rows, and the outline goes with them.
+ try s.keys("dj");
+ try std.testing.expect(!try listed(&s, mid));
+ try expectEqual(row_top, (try s.where("/test.txt Save"))[1]);
+ try expectEqual(row_mid, (try s.where("/low Save"))[1]);
+ try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" }));
+ // With one neighbour nothing is asked: d closes it, the outline on the
+ // pane that grew.
+ try s.keys("d");
+ try std.testing.expect(!try listed(&s, low));
+ try std.testing.expectEqualStrings("/test.txt", try outlined(&s, lit, &.{"/test.txt"}));
+ // Enter leaves the mode on it.
+ try s.keys("\n");
+ try expectEqual(top, try s.focused());
+ try std.testing.expectEqualStrings("", try outlined(&s, lit, &.{"/test.txt"}));
+}
+
+test "modes: window keys walk from a pane up through its column's tag and the workspace's, across, and back down" {
+ var s = try Session.initFile(std.testing.allocator, "body\n");
+ defer s.deinit();
+ const a = try s.focused();
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ try s.write("/focus", s.at("{d}\n", .{a}));
+ const right = 40; // two columns on 80 cells: the right one's first
+ // Up from the top pane: its column's tag, in normal mode (w moves).
+ try s.keys("\x17k");
+ try s.expect("/focus", "");
+ const x0, const y0 = (try s.cursor()).?;
+ try expectEqual(@as(usize, 1), y0);
+ try std.testing.expect(x0 < right);
+ try s.keys("w");
+ const remembered = (try s.cursor()).?;
+ try std.testing.expect(remembered[0] > x0);
+ // Across to the right column's tag, and back to where the caret was.
+ try s.keys("\x17l");
+ try std.testing.expect((try s.cursor()).?[0] >= right);
+ try s.keys("\x17h");
+ try expectEqual(remembered, (try s.cursor()).?);
+ // Up again: the workspace tag; down, the column's, then the pane.
+ try s.keys("\x17k");
+ try expectEqual(@as(usize, 0), (try s.cursor()).?[1]);
+ try s.keys("\x17j");
+ try expectEqual(@as(usize, 1), (try s.cursor()).?[1]);
+ try s.keys("\x17j");
+ try expectEqual(a, try s.focused());
+ // `:` in a column's tag is the way back to the body.
+ try s.keys("\x17k:");
+ try expectEqual(a, try s.focused());
+ try expectEqual((try s.where("body"))[1], (try s.cursor()).?[1]);
+ try s.expect(s.at("/pane/{d}/body", .{a}), "body\n");
+}