diff options
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 626 |
1 files changed, 0 insertions, 626 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index ff64cb9f..b47119c4 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; @@ -978,29 +914,6 @@ test "compact tag commands stay beside their own prefix across layout changes" { try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); } -test "Joincol folds the active column into its right neighbor, keeping its panes" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - - const right = p.freeSlot().?; - _ = try p.newShell(right, ""); - try std.testing.expect(layout.splitColumn(p, 0, right, false)); - while (p.nextEffect()) |_| {} - try std.testing.expectEqual(@as(usize, 2), p.ncol); - - p.active = 0; // the left column is current - layout.joinCol(p, 0); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - const lf = layout.findPane(p, 0) orelse return error.LostLeftPane; - const rf = layout.findPane(p, right) orelse return error.LostRightPane; - try std.testing.expectEqual(lf.col, rf.col); - - layout.joinCol(p, 0); // no right neighbor left: inert - try std.testing.expectEqual(@as(usize, 1), p.ncol); -} - test "Tty spawns a raw shell in the caller's directory" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -1282,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(); @@ -1373,38 +1268,6 @@ test "acme placement: a pane made from the middle of a column moves only the one try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h); } -test "acme placement: New and 9P's new take the bottom half of the last pane" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - p.newScratchBelow(p.active); - const last = p.active; - p.sync(); - const was = p.rects[last]; - p.newScratchFor(last, .fs); - const made = p.active; - p.sync(); - try std.testing.expectEqual(layout.findPane(p, last).?.idx + 1, layout.findPane(p, made).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[made].y + p.rects[made].h); - try std.testing.expect(p.rects[made].y > was.y + BOX_H); -} - -test "Placement pardes brings back the old rules, and says so in DumpConfig" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); - defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement pardes")); - try std.testing.expectEqual(config.Runtime.Placement.pardes, p.settings.placement); - const top = p.active; - p.sync(); - const was = p.rects[top]; - p.newScratchBelow(top); - p.sync(); - // Directly under the asking pane, as New always put it. - try std.testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.idx); - try std.testing.expectEqual(was.y + was.h, p.rects[p.active].y + p.rects[p.active].h); - try std.testing.expect(p.executeBuiltinLine(p.active, "Placement")); - try std.testing.expectEqual(config.Runtime.Placement.acme, p.settings.placement); -} - test "an empty column shows its theme's empty_col under its tag: acme's white, else the border" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 20 }); defer p.deinit(); @@ -1442,24 +1305,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(); @@ -1485,31 +1330,6 @@ test "dragging a column's only pane to another leaves that column in place, empt try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); } -test "pane defaults keep creation of scratch panes in column tags" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - for ([_][]const u8{ tagline.pane_tail, tagline.file_pane_tail, tagline.pdf_pane_tail, tagline.terminal_pane_tail, config.topbar_str }) |tag| { - var words = std.mem.tokenizeScalar(u8, tag, ' '); - while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New")); - } - try std.testing.expectEqualStrings("New Tty Find Grep Joincol Delcol", tagline.columnTag(p, 0)); -} - -test "an unsaved file's tag is its name alone: the grip, not a mark, says it is unsaved" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = try p.setTestFile("before\n"); - const clean = try tagline.tagText(p, p.scratch.allocator(), pane); - panes.File.setContent(p, &pane.file.?, try gpa.dupe(u8, "after\n")); - const dirty = try tagline.tagText(p, p.scratch.allocator(), pane); - try std.testing.expectEqualStrings(clean, dirty); - try std.testing.expect(std.mem.indexOf(u8, dirty, " *") == null); - // The dirty file and index's flag still say it. - try std.testing.expect(ctlfs.pane.dirtyOf(pane)); -} - test "unknown Exec from a document runs as a command pane in its directory, typed into no terminal" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); @@ -2766,18 +2586,6 @@ test "a host with no methods at all is a complete in-process pardes" { try std.testing.expect(p.quit); } -test "a builtin that needs a pane reports capacity failure when every slot is full" { - const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - for (0..MAX_PANES) |id| if (p.panes[id] == null) { - _ = try p.newDocPane(id); - }; - const help = std.meta.stringToEnum(Builtin, "Help") orelse return error.MissingHelpBuiltin; - exec.runBuiltin(p, help, 0, "", null); - try std.testing.expect(std.mem.indexOf(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "help: no space for a pane") != null); -} - test "Font keeps requested and acknowledged faces as separate plain state" { if (comptime !font_picker) return; // there is no Font builtin on tty or web const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); @@ -2866,26 +2674,6 @@ test "Font size suffix reaches native request and invalid input leaves it intact try std.testing.expectEqual(@as(u16, 1850), p.settings.font.effective_size_hundredths); } -test "Pet command is SDL-only optional and validates its argument" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer p.deinit(); - try std.testing.expectEqual(.off, p.settings.pet); - if (comptime platform != .gui) { - // A terminal's view has the word and takes it not. - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.off, p.settings.pet); - return; - } - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet cat")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet dog")); - try std.testing.expectEqual(.cat, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet frog")); - try std.testing.expectEqual(.frog, p.settings.pet); - try std.testing.expect(p.executeBuiltinLine(p.active, "Pet off")); - try std.testing.expectEqual(.off, p.settings.pet); -} - test "startup config overrides restored styling before initFromDump returns" { const source = try Pardes.init(std.testing.allocator, .{ .startup_config = "Theme dark\n" }); defer source.deinit(); @@ -3213,33 +3001,6 @@ fn pardes_ctlfs_ctlText(p: *Pardes, pane: *Pane) []const u8 { return th.rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; } -test "a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true }); - defer p.deinit(); - const pane = try p.setTestFile("x\n"); - for ([_]bool{ true, false }) |enter| { - tagline.enterTag(p, pane); - pane.tag.mode = .insert; - pane.tag.cur_row = 0; - pane.tag.cur_col = 1; - p.update(.{ .key = .{ .cp = 'z', .text = "z" } }); - try std.testing.expect(pane.prompt == .name); - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt == .name); - // A stray key changes nothing while it waits. - p.update(.{ .key = .{ .cp = 'q', .text = "q" } }); - if (enter) { - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } else { - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.prompt != .name); - try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path); - } - } -} - test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); @@ -3345,21 +3106,6 @@ test "editable workspace and column tags are typed into and persist" { try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0)); } -test "column tags follow their column through split and close" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("left\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "Left Find"); - _ = exec.execute(p, 0, "Newcol"); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqualStrings("Left Find", tagline.columnTag(p, 0)); - p.col_tags[1].own = try p.gpa.dupe(u8, "Right Grep"); - p.active = p.col_panes[0][0]; - layout.joinCol(p, 0); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqualStrings("Right Grep", tagline.columnTag(p, 0)); -} - test "column tags render edit hover and scroll from the column edge" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20, .tty_only = true }); defer p.deinit(); @@ -3437,43 +3183,6 @@ test "column tag first-cell execution keeps New local to the clicked column" { try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); } -test "header clicks beyond text append and long UTF-8 tags reveal their caret" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = 'x', .text = " extended" } }); - try std.testing.expectEqualStrings("New extended", tagline.columnTag(p, 0)); - p.update(.{ .paste = " 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界" }); - const frame = try p.render(p.scratch.allocator()); - try std.testing.expect(p.header_scroll > 0); - try std.testing.expect(frame.cursor != null); - try std.testing.expectEqual(TOPBAR_H, frame.cursor.?.y); - try std.testing.expect(frame.cursor.?.x < p.screen_w); - p.update(.{ .key = .{ .cp = Key.home } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.header_scroll); -} - -test "a newline typed into a column tag is a space: the tag stays one row" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New"); - p.acknowledgePanelPresentation(&.{}); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 40, .row = TOPBAR_H } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.update(.{ .key = .{ .cp = 'S', .text = "Snarf" } }); - _ = try p.render(p.scratch.allocator()); - try std.testing.expectEqualStrings("New Snarf", tagline.columnTag(p, 0)); - try std.testing.expectEqual(COLBAR_H, p.columnBarHeight()); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y); -} - test "tiny screens keep pane space before adding a column tag" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 8, .rows = 2, .tty_only = true }); defer p.deinit(); @@ -3504,18 +3213,6 @@ test "a screen too short for the column row releases a column tag's focus withou try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } -test "a header's execute key runs the word under its cursor and lets go of the keyboard first" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Dump").?); - p.update(.{ .key = .{ .cp = Key.tab } }); - try std.testing.expect(!p.header_focus); - try std.testing.expect(p.dump_out != null); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); -} - test "s in a header selects in the header's own text" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); defer p.deinit(); @@ -3535,20 +3232,6 @@ test "s in a header selects in the header's own text" { try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } -test "Enter in a header runs the word under its cursor, as the execute key does" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 12, .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("body\n"); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - tagline.enterHeader(p, null); - p.global_tag.cur_col = @intCast(std.mem.indexOf(u8, config.topbar_str, "Newcol").?); - p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - // and the workspace tag lets go of the keyboard: the new, empty - // column's tag has it - try std.testing.expect(p.header_focus and p.header_column.? == 1); -} - 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(); @@ -8320,31 +8003,6 @@ pub const Pardes = struct { } }; -test "Esc alternates between two panes of the SAME kind" { - if (platform == .web) return; - const gpa = std.testing.allocator; - var cwdbuf: [4096]u8 = undefined; - const cwd = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwdbuf, cwdbuf.len) orelse return))); - var pathbuf: [4096]u8 = undefined; - const boot = try std.fmt.bufPrint(&pathbuf, "{s}/mise.toml", .{cwd}); - - const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 40, .file = boot }); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 40 } }); - const a = p.active; - exec.runBuiltin(p, .Look, a, "", "build.zig"); - p.sync(); - const b = p.active; - try std.testing.expect(b != a); - try std.testing.expect(!p.panes[a].?.isTerminal() and !p.panes[b].?.isTerminal()); - - for (0..6) |_| { - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqual(if (was == a) b else a, p.active); - } -} - test "a boot file that will not open boots an errors pane rather than failing the launch" { if (platform == .web) return; const gpa = std.testing.allocator; @@ -8609,62 +8267,6 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro try std.testing.expect(pane.prompt == .none and pane.input.own == null); } -test "Newcol makes an empty column, and the next pane made from its tag fills it" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); - defer p.deinit(); - const first = p.active; - const panes_before = p.col_n[0]; - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); - try std.testing.expectEqual(panes_before, p.col_n[0]); - // The keyboard is on the new column's tag; no pane has it. - try std.testing.expect(p.header_focus and p.header_column.? == 1); - try std.testing.expectEqual(first, p.active); - p.sync(); - try std.testing.expect(p.executeBuiltinLine(first, "Tty")); - const shell = p.active; - try std.testing.expect(shell != first); - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - try std.testing.expectEqual(shell, p.col_panes[1][0]); - try std.testing.expect(!p.header_focus); - - // The next Tty splits as it always has: nothing is empty any more. - p.sync(); - try std.testing.expect(p.executeBuiltinLine(shell, "Tty")); - try std.testing.expectEqual(@as(usize, 2), p.col_n[1]); -} - -test "a column tag's command acts on that column" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); - defer p.deinit(); - const first = p.active; - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expectEqual(@as(usize, 3), p.ncol); - p.sync(); - // New from the middle column's tag lands in it, not below `first`. - p.exec_column = 1; - try std.testing.expect(p.executeBuiltinLine(first, "New")); - p.exec_column = null; - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - try std.testing.expectEqual(p.active, p.col_panes[1][0]); - // Delcol from the empty right column's tag closes that one. - p.exec_column = 2; - try std.testing.expect(p.executeBuiltinLine(first, "Delcol")); - p.exec_column = null; - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 1), p.col_n[1]); - // A pane's own Delcol closes its column whatever tag has the keyboard. - try std.testing.expect(p.executeBuiltinLine(first, "Newcol")); - try std.testing.expect(p.header_focus); - try std.testing.expect(p.executeBuiltinLine(p.col_panes[1][0], "Delcol")); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); -} - test "Del from a key asks which neighbour takes the rows; nothing else asks" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 }); @@ -8780,101 +8382,6 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { try std.testing.expect(p.panes[low] == null); } -test "a Look that finds nothing says so" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - p.newScratchBelow(p.active); - const id = p.active; - p.sync(); - look.lookAt(p, id, "/no/such/zzqq"); - try std.testing.expectEqualStrings("Look: no match for \"/no/such/zzqq\"", p.panes[id].?.msg[0..p.panes[id].?.msg_len]); -} - -test "focus on a closed pane goes to the pane that takes its place, not the one focused before" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); - defer p.deinit(); - const shell = p.active; - p.newColumn(shell); - p.newScratchIn(shell, p.activeColumn().?); - const right = p.active; - p.sync(); - p.newScratchBelow(shell); - const low = p.active; - p.sync(); - // The dogfood case: `right` was focused just before `low`, but `shell` - // grows into `low`'s rows, so `shell` gets the focus. - try std.testing.expect(p.executeBuiltinLine(low, "Del")); - p.sync(); - try std.testing.expect(p.panes[low] == null); - try std.testing.expectEqual(shell, p.active); - - // Closing a pane that has no focus leaves the focus where it is. - p.newScratchBelow(shell); - const other = p.active; - p.sync(); - p.active = right; - p.sync(); - try std.testing.expect(p.executeBuiltinLine(other, "Del")); - try std.testing.expectEqual(right, p.active); - - // Delcol: the column that takes the width holds, level with the closed - // pane, the pane that takes its place; `right` was focused just before. - p.newScratchBelow(right); - const right_low = p.active; - p.newScratchBelow(shell); - const left_low = p.active; - p.active = right; - p.sync(); - p.active = left_low; - p.sync(); - try p.removeColumn(layout.findPane(p, left_low).?.col); - p.sync(); - try std.testing.expectEqual(right_low, p.active); -} - -test "closing the last pane in a column leaves the column empty, its tag focused" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 }); - defer p.deinit(); - const shell = p.active; - p.newColumn(shell); - p.newScratchIn(shell, p.activeColumn().?); - const lone = p.active; - try std.testing.expect(lone != shell); - try std.testing.expectEqual(@as(usize, 2), p.ncol); - const at = layout.findPane(p, lone).?; - try std.testing.expectEqual(@as(usize, 1), p.col_n[at.col]); - p.sync(); - - try p.removePane(lone, null); - p.sync(); - - // The column outlives the pane, as acme's does: still two columns, the - // emptied one with no pane and the keyboard on its tag. - try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[at.col]); - try std.testing.expect(p.panes[lone] == null); - try std.testing.expect(p.header_focus and p.header_column.? == at.col); - try std.testing.expectEqual(shell, p.active); - try std.testing.expect(!p.quit); - - // Down from it goes nowhere: nothing is below. - try std.testing.expect(p.executeBuiltinLine(shell, "Down")); - try std.testing.expect(p.header_focus and p.header_column.? == at.col); - - // ...and Delcol is what actually takes the column away. - try p.removeColumn(at.col); - p.sync(); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqual(shell, p.active); - - // The session's last pane closing ends it. - try p.removePane(shell, null); - try std.testing.expect(p.quit); -} - test "the bare tty startup opens a text pane under the shell, unfocused" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .boot = .tty }); @@ -8944,53 +8451,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" }); @@ -9048,43 +8508,6 @@ test "with ProgramEsc raw tty Escape only leaves at a shell prompt" { try std.testing.expectEqual(Text.Mode.tty, pane.body.mode); } -test "Shift-Esc backs out to the previous pane in every mode, never into raw" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; - const sp = p.panes[shell].?; - // A terminal in normal mode: out, still normal, never raw. - if (sp.body.mode == .tty) p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(Text.Mode.normal, sp.body.mode); - // A text pane in insert mode: out of insert, and out of the pane. - const doc = p.panes[0].?; - p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); - try std.testing.expectEqual(Text.Mode.insert, doc.body.mode); - p.update(.{ .key = .{ .cp = Key.escape, .shift = true } }); - try std.testing.expectEqual(Text.Mode.normal, doc.body.mode); - try std.testing.expect(p.active != 0); -} - -test "Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { - if (platform == .web) return; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer p.deinit(); - p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a pane to go back to - for ([_]?usize{ 0, null }) |column| { - tagline.enterHeader(p, column); - try std.testing.expect(tagline.focusedHeader(p) != null); - const was = p.active; - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(tagline.focusedHeader(p) == null); - try std.testing.expect(p.active != was); - } -} - 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(); @@ -10026,27 +9449,6 @@ test "core animation keeps wall time at 60, 120 and 144 Hz and across a stall" { try std.testing.expectEqual(@as(?u64, null), p.nextWake()); } -test "a pane closed while its question stands ends the question in the log" { - const th = @import("ninep/testing.zig"); - const p = try th.withFile(std.testing.allocator, "x\n"); - defer p.deinit(); - p.settings.placement = .pardes; - p.newScratchBelow(0); - const closing = p.active; - p.newScratchBelow(closing); - p.sync(); - p.active = closing; // a middle pane: Del from a key asks which side - const serial = p.panes[closing].?.serial; - p.update(.{ .key = .{ .cp = ' ' } }); - p.update(.{ .key = .{ .cp = 'd' } }); - try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[closing].?.prompt); - // A bare answer says what this question takes. - try std.testing.expectEqualStrings("answer takes k j or -", th.wr(p, ctlfs.Node.of(serial, .ctl), "answer\n").reply.ename); - try p.removePane(closing, null); - var want: [64]u8 = undefined; - try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} -\ndel {d}", .{ serial, serial }))); -} - test "a Save the host could not do logs no save record" { const th = @import("ninep/testing.zig"); const p = try th.withFile(std.testing.allocator, "x\n"); @@ -10070,31 +9472,3 @@ test "a Save the host could not do logs no save record" { p.perform(.{ .save_file = .{ .pane = 0 } }); try std.testing.expect(th.logHas(p, "\nsave ")); } - -test "Delcol on the last column leaves the window, drawn and typed into, and Newcol starts it again" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - while (p.ncol > 0) { - p.exec_column = 0; - _ = p.executeBuiltinLine(p.active, "Delcol"); - p.exec_column = null; - p.sync(); - } - try std.testing.expect(!p.quit); - try std.testing.expect(p.anyPane() == null); - // Drawn, and keys go to the workspace tag. - _ = try p.render(p.frame_arena.allocator()); - p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); - p.update(.{ .key = .{ .cp = Key.enter } }); - p.sync(); - _ = try p.render(p.frame_arena.allocator()); - try std.testing.expect(!p.quit); - _ = p.executeBuiltinLine(p.active, "Newcol"); - p.sync(); - try std.testing.expectEqual(@as(usize, 1), p.ncol); - _ = p.executeBuiltinLine(p.active, "New"); - p.sync(); - try std.testing.expect(p.anyPane() != null); - _ = try p.render(p.frame_arena.allocator()); -} |
