summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pardes.zig147
-rw-r--r--test/behaviour.zig2
-rw-r--r--test/behaviour/modes.zig39
-rw-r--r--test/behaviour/panes.zig49
-rw-r--r--test/behaviour/placement.zig24
-rw-r--r--test/behaviour/terminals.zig46
-rw-r--r--test/session.zig5
7 files changed, 165 insertions, 147 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 3d29dfcd..3d6b6e28 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -710,34 +710,6 @@ test "pane-tag Exec prefers Tty and argument builtins before shell fallback" {
try std.testing.expectEqualStrings("DefinitelyNotABuiltin\r", sent[0..sent_len]);
}
-test "Collapse builtin keeps content and restores the pane from its default tag" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("keep this text\n");
- p.sync();
- const height = p.rects[0].h;
- const revision = pane.file.?.revision;
- for ([_][]const u8{ tagline.pane_tail, tagline.file_pane_tail, tagline.pdf_pane_tail, tagline.terminal_pane_tail }) |tail|
- try std.testing.expect(std.mem.endsWith(u8, tail, " Collapse Del"));
-
- try std.testing.expect(p.executeBuiltinLine(0, "Collapse"));
- p.sync();
- try std.testing.expect(pane.collapsed);
- try std.testing.expectEqual(@as(u16, BOX_H), p.rects[0].h);
- try std.testing.expectEqual(@as(f32, @floatFromInt(height)), pane.vweight);
- try std.testing.expectEqual(revision, pane.file.?.revision);
- try std.testing.expectEqualStrings("keep this text\n", pane.file.?.content);
- try std.testing.expect((try p.render(p.scratch.allocator())).cursor == null);
- tagline.enterTag(p, pane);
- const tag_cursor = (try p.render(p.scratch.allocator())).cursor orelse return error.MissingTagCursor;
- try std.testing.expectEqual(p.rects[0].y, tag_cursor.y);
- pane.focus = .body;
- try std.testing.expect(p.executeBuiltinLine(0, "Collapse"));
- p.sync();
- try std.testing.expect(!pane.collapsed);
- try std.testing.expectEqual(height, p.rects[0].h);
-}
-
test "LocationsConfig command reports partial updates and survives restore" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -851,42 +823,6 @@ test "TreeContext command and custom tag survive a workspace round trip" {
try std.testing.expectEqualStrings(" Save Keep Del", tagline.curTail(saved));
}
-test "Togglettymode builtin and keyboard chord share mode transitions including edited tags" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true });
- defer p.deinit();
- const pane = p.panes[0].?;
- try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), " Mode ") != null);
- try pane.appendTag(" Togglettymode");
- try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
- try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
- try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
- p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
- try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
- // The tag has its own mode: the body keeps tty while the tag is typed into.
- tagline.enterTag(p, pane);
- try std.testing.expect(pane.focus == .tag);
- try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
- try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
- try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
- try std.testing.expect(pane.focus == .body);
- tagline.enterTag(p, pane);
- p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
- try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
- try std.testing.expect(pane.focus == .body);
-
- p.acknowledgePanelPresentation(&.{});
- const tag = try tagline.tagText(p, p.scratch.allocator(), pane);
- const x = p.rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(std.mem.indexOf(u8, tag, "Togglettymode").?));
- const y = p.rects[0].y;
- p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = x, .row = y } });
- p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = x, .row = y } });
- try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
- const file = try p.setTestFile("unchanged\n");
- try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
- try std.testing.expectEqual(Text.Mode.normal, file.body.mode);
- try std.testing.expectEqualStrings("unchanged\n", file.file.?.content);
-}
-
test "Filter is ordered after Del and toggles only its terminal or +Pager pane" {
const testing = std.testing;
const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin;
@@ -1259,24 +1195,6 @@ test "first document keeps its originating shell and only opens a column when it
}
}
-test "acme placement: an empty active column takes the new pane whole" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 });
- defer p.deinit();
- try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement);
- p.newColumn(0); // its tag has the keyboard: it is the active column
- tagline.exitHeader(p);
- p.sync();
- // A Look from the shell's text still lands in the active column, as
- // acme's makenewwindow puts it in activecol first (util.c:456).
- _ = try p.openTutorView(1);
- exec.placeNew(p, 0, 0, 1, .doc);
- try std.testing.expectEqualSlices(usize, &.{1}, p.col_panes[1][0..p.col_n[1]]);
- try std.testing.expectEqual(@as(usize, 1), p.active);
- try std.testing.expectEqual(@as(?usize, 1), p.activeColumn());
- // Never a new column.
- try std.testing.expectEqual(@as(usize, 2), p.ncol);
-}
-
test "acme placement: under a pane's text when it has many blank rows, else halving the biggest" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 });
defer p.deinit();
@@ -1419,24 +1337,6 @@ test "BootShell keep leaves the untouched boot shell a dragged document joins; r
}
}
-test "a pane its whole text fits in never scrolls to keep a margin" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 });
- defer p.deinit();
- const pane = try p.setTestFile("one\ntwo\nthree\n");
- // A second pane under it, as acme's placement puts one: right under the
- // three lines, which leaves the file exactly three body rows.
- const below = p.freeSlot().?;
- _ = try p.openTutorView(below);
- exec.placeNew(p, 0, 0, below, .doc);
- p.active = 0;
- p.sync();
- try std.testing.expectEqual(@as(u16, 3), p.rects[0].h - pane.tag_rows);
- for ("jj") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } });
- p.sync();
- try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 0), pane.scroll());
-}
-
test "dragging a column's only pane to another leaves that column in place, empty" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 32 });
defer p.deinit();
@@ -8615,53 +8515,6 @@ test "tty output follows only from the bottom" {
try std.testing.expect(panes.terminal.scrollbar(sp).offset > live);
}
-test "Esc back into a file leaves its view where it was" {
- if (platform == .web) return;
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "src/memory.zig" });
- defer p.deinit();
- // Rows are lines: the centring below counts lines, and a wrapped line
- // above the cursor would push it out of the view it centres.
- p.settings.wrap = false;
- p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
- p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc
- const shell = p.active;
- p.update(.{ .key = .{ .cp = Key.escape } }); // back onto the doc
- p.sync();
- const doc = p.active;
- try std.testing.expect(doc != shell);
- const dp = p.panes[doc].?;
- try std.testing.expect(dp.file != null);
-
- // Ride the cursor down until the view has scrolled: it now sits in the
- // bottom band, which is exactly where a recenter is visible.
- for (0..20) |_| p.update(.{ .key = .{ .cp = 'j' } });
- p.sync();
- const view = dp.file.?.scroll;
- const row = dp.body.cur_row;
- try std.testing.expect(view > 0);
-
- p.update(.{ .key = .{ .cp = Key.escape } }); // out to the shell
- p.sync();
- try std.testing.expectEqual(shell, p.active);
- p.update(.{ .key = .{ .cp = Key.escape } }); // ...and back
- p.sync();
- try std.testing.expectEqual(doc, p.active);
-
- // Nothing moved. The old landing recentred the line under the cursor, so
- // coming back repainted the whole screen to show what was already on it.
- try std.testing.expectEqual(view, dp.file.?.scroll);
- try std.testing.expectEqual(row, dp.body.cur_row);
- // ...and the cursor is still on screen, which is all `.nearest` promises.
- try std.testing.expect(dp.body.cur_row >= @as(i32, @intCast(view)));
- try std.testing.expect(dp.body.cur_row < @as(i32, @intCast(view)) + @as(i32, dp.rows));
-
- // The other arm still centres: a look target, a `:NN`, a search hit.
- look.focusPaneLine(p, doc, .{ .line = @intCast(row + 1), .col = 1 }, .center);
- try std.testing.expect(dp.file.?.scroll != view);
- try std.testing.expectEqual(@as(usize, @intCast(row)) -| @as(usize, dp.rows) / 2, dp.file.?.scroll);
-}
-
test "raw tty Esc backs out and Shift-Esc is the program's Esc" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 902ef520..bec74d89 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -9,6 +9,8 @@ test {
_ = @import("behaviour/modes.zig");
_ = @import("behaviour/other_files.zig");
_ = @import("behaviour/panes.zig");
+ _ = @import("behaviour/placement.zig");
_ = @import("behaviour/root_ctl.zig");
_ = @import("behaviour/tags.zig");
+ _ = @import("behaviour/terminals.zig");
}
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index cdcf1be6..dde3ffb6 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -63,3 +63,42 @@ test "modes: Shift-Esc backs out to the previous pane in every mode, never into
try std.testing.expectEqualStrings("normal", try mode(&s, doc));
try std.testing.expect(doc != try s.focused());
}
+
+/// The first line number drawn under the tag that starts with `tag`.
+fn topLine(s: *Session, tag: []const u8) !usize {
+ const row = (try s.where(tag))[1];
+ var rows = std.mem.splitScalar(u8, try s.screen(), '\n');
+ for (0..row + 1) |_| _ = rows.next();
+ var words = std.mem.tokenizeScalar(u8, rows.next().?, ' ');
+ return std.fmt.parseInt(usize, words.next().?, 10);
+}
+
+test "modes: Esc back into a file leaves its view where it was, and a look centres its line" {
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))));
+ defer s.deinit();
+ const doc = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{doc});
+ try s.keys("\u{F015}n"); // a shell under the doc
+ const shell = try s.focused();
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Ride the cursor down until the view has scrolled.
+ try s.keys(&@as([20]u8, @splat('j')));
+ const top = try topLine(&s, "/test.txt");
+ const at = try s.range(dot);
+ try std.testing.expect(top > 1);
+ try s.keys("\x1b");
+ try expectEqual(shell, try s.focused());
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Nothing moved: the old landing recentred the line under the cursor.
+ try expectEqual(top, try topLine(&s, "/test.txt"));
+ try expectEqual(at, try s.range(dot));
+ // The other arm still centres: a look's `:NN`.
+ const line = 60;
+ try s.write(s.at("/pane/{d}/look", .{doc}), s.at(":{d}\n", .{line}));
+ const rows = (try s.where("Tty Save Mode"))[1] - (try s.where("/test.txt"))[1] - 1;
+ // Drawn mid-pane, a row either way.
+ const drawn_at = line - try topLine(&s, "/test.txt");
+ try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1);
+}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index d0773bfb..149c8da1 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -112,3 +112,52 @@ test "panes: focus on a closed pane goes to the pane that takes its place, not t
try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n");
try std.testing.expectEqual(right_low, try s.focused());
}
+
+test "panes: Collapse keeps the text and folds the pane to its tag, and again restores it" {
+ var s = try Session.initFile(std.testing.allocator, "keep this text\n");
+ defer s.deinit();
+ var t = try Session.initTerm(std.testing.allocator);
+ defer t.deinit();
+ const n = try s.focused();
+ for ([_][]const u8{
+ try s.read(s.at("/pane/{d}/tag", .{n})),
+ try s.read(s.at("/pane/{d}/tag", .{try s.newPane()})),
+ try t.read(t.at("/pane/{d}/tag", .{try t.focused()})),
+ }) |tag| try std.testing.expect(std.mem.endsWith(u8, tag, " Collapse Del"));
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n");
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.write(ctl, "Collapse\n");
+ // Folded to its tag: no text drawn, no cursor in it, the text kept.
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "keep this text") == null);
+ try std.testing.expectEqual(null, try s.cursor());
+ try s.expect(s.at("/pane/{d}/body", .{n}), "keep this text\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+ // Its tag still takes the keyboard, the cursor on the tag's row.
+ try s.keys(":");
+ try std.testing.expectEqual((try s.where("/test.txt"))[1], (try s.cursor()).?[1]);
+ try s.write(ctl, "Collapse\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") == null);
+ try std.testing.expectEqual((try s.where("/test.txt"))[1] + 1, (try s.where("1 keep this text"))[1]);
+}
+
+test "panes: a pane its whole text fits in never scrolls to keep a margin" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ const n = try s.focused();
+ // A second pane under it, as acme's placement puts one: right under the
+ // three lines, which leaves the file exactly three body rows.
+ try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}/f.txt\n", .{at}));
+ try s.write("/focus", s.at("{d}\n", .{n}));
+ try s.keys("jj");
+ const top = (try s.where("/test.txt"))[1];
+ try std.testing.expectEqual(top + 4, (try s.where(at[0..@min(at.len, 20)]))[1]);
+ // On the last line, and line 1 still the first drawn.
+ try std.testing.expectEqual(.{ @as(u32, 8), @as(u32, 8) }, try s.range(s.at("/pane/{d}/dot", .{n})));
+ try std.testing.expectEqual(top + 1, (try s.where("1 one"))[1]);
+}
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
new file mode 100644
index 00000000..350e94f8
--- /dev/null
+++ b/test/behaviour/placement.zig
@@ -0,0 +1,24 @@
+//! docs/typ/reference.typ, Placement <placement>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "placement: an empty active column takes the new pane whole, a look from another column's text too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ // Its tag has the keyboard: it is the active column, and stays so
+ // when Esc gives the keyboard back.
+ try s.write("/ctl", "Newcol\n");
+ try s.keys("\x1b");
+ try std.testing.expectEqual(first, try s.focused());
+ // A look from the first pane's text still lands in the active column,
+ // as acme's makenewwindow puts it in activecol first (util.c:456).
+ try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt\n", .{at}));
+ const made = try s.focused();
+ try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns());
+}
diff --git a/test/behaviour/terminals.zig b/test/behaviour/terminals.zig
new file mode 100644
index 00000000..f6bbdfa0
--- /dev/null
+++ b/test/behaviour/terminals.zig
@@ -0,0 +1,46 @@
+//! docs/typ/guide.typ, Terminals <terminals>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn mode(s: *Session, pane: u32) ![]const u8 {
+ const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane}));
+ const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len;
+ return std.mem.trimEnd(u8, ctl[at..], " ");
+}
+
+test "terminals: Togglettymode and Ctrl-B share the mode's transitions, from the body or its tag, and a text pane refuses it" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/tag", .{n})), " Mode ") != null);
+ try s.write(s.at("/pane/{d}/tag", .{n}), " Togglettymode");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try s.write(ctl, "Togglettymode\n");
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ try s.keys("\x02");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ // The tag has its own mode: the body keeps tty while the tag is typed
+ // into, and either way of toggling gives the body the keyboard back.
+ const tag_row = (try s.where("Togglettymode"))[1];
+ try s.click("Togglettymode", 0, 1);
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try std.testing.expectEqual(tag_row, (try s.cursor()).?[1]);
+ try s.write(ctl, "Togglettymode\n");
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ try std.testing.expect((try s.cursor()).?[1] > tag_row);
+ try s.click("Togglettymode", 0, 1);
+ try s.keys("\x02");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try std.testing.expect((try s.cursor()).?[1] > tag_row);
+ // A middle click on the word in the tag.
+ try s.click("Togglettymode", 0, 2);
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ // A text pane refuses it, normal, its text as it was.
+ const file = try s.newPane();
+ try s.write(s.at("/pane/{d}/body", .{file}), "unchanged\n");
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{file}), "Togglettymode\n");
+ try std.testing.expectEqualStrings("Togglettymode: only a terminal pane takes it", s.said);
+ try std.testing.expectEqualStrings("normal", try mode(&s, file));
+ try s.expect(s.at("/pane/{d}/body", .{file}), "unchanged\n");
+}
diff --git a/test/session.zig b/test/session.zig
index f67f3b25..6d214874 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -220,6 +220,11 @@ pub const Session = struct {
};
return .{ @intCast(c.get("x").?.integer), @intCast(c.get("y").?.integer) };
}
+
+ /// Where `text` is first drawn on /screen, column and row.
+ pub fn where(s: *Session, text: []const u8) !struct { usize, usize } {
+ return s.find(text);
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {