diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 250 |
1 files changed, 165 insertions, 85 deletions
diff --git a/core/Core.zig b/core/Core.zig index 9cd58c50..3a2e1f51 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1004,24 +1004,11 @@ fn setLastDumpInner(p: *Pardes, path: []const u8) void { ctlfs.events.notePath(p, "dump", path); } -/// The workspace tag's `Restore <path>` names `path` from now on: the -/// default's does by itself, and one the tag was edited around (its own -/// text) has the old path swapped, never left pointing at a dump that is -/// not the last. +/// The window row's `Restore <path>` names `path` from now on: a computed +/// word (UX K'2, tagline.headerWords), never the user's text. pub fn pointRestoreAt(p: *Pardes, path: []const u8) void { const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(p.view().active), "Restore", err); - if (p.last_dump) |old| { - if (p.global_tag.own) |own| swap: { - const a = p.scratch.allocator(); - const was = std.fmt.allocPrint(a, "Restore {s}", .{old}) catch break :swap; - if (std.mem.indexOf(u8, own, was) == null) break :swap; - const now = std.fmt.allocPrint(a, "Restore {s}", .{path}) catch break :swap; - const swapped = std.mem.replaceOwned(u8, p.gpa, own, was, now) catch break :swap; - p.gpa.free(own); - p.global_tag.own = swapped; - } - p.gpa.free(old); - } + if (p.last_dump) |old| p.gpa.free(old); p.last_dump = copy; } @@ -1170,14 +1157,13 @@ fn acknowledgeShellInner(p: *Pardes, id: Pane.Id, executable: []const u8, prompt pane.greeted = false; pane.had_shell = true; pane.fs.unmarked = !prompt_marks; - // The tag's Term word names the shell the host ran, and a click - // on it (`Term+fish`) opens another of the same. + // The tag's text names the shell the host ran (tagline.defaultTail), + // and a click on it (`Term+fish`) opens another of the same. if (pane.command == null) { // A shell given as a path keeps it: its bare name would find // nothing, or another program, on the usual paths. const base = if (pane.shell) |given| (if (std.mem.indexOfScalar(u8, given, '/') != null) given else std.Io.Dir.path.basename(executable)) else std.Io.Dir.path.basename(executable); - const rest = tagline.terminal_pane_tail[" Term".len..]; - if (std.fmt.bufPrint(&pane.shell_tail, " Term+{s}{s}", .{ base, rest })) |tail| { + if (std.fmt.bufPrint(&pane.shell_tail, "Term+{s}", .{base})) |tail| { pane.shell_tail_len = @intCast(tail.len); } else |_| {} } @@ -1347,6 +1333,8 @@ pub fn toView(p: *Pardes, k: View.Id) void { if (k.index() == p.live) return; const taped = pardes.tape.enter(p, .{ .to_view = k }); defer pardes.tape.leave(p, taped); + // A terminal the going view sizes takes the size its inputs left it. + p.sizeTerminals(); Views.to(p, k.index()); } @@ -1665,6 +1653,7 @@ pub fn settle(p: *Pardes) void { // ...and the last line of an open closed with no newline after it. ctlfs.runClosedLines(p); while (p.nextQueued()) |ev| p.update(ev); + p.sizeTerminals(); while (p.nextEffect()) |e| p.perform(e); turn.bump(&turn.epoch); } @@ -1845,7 +1834,9 @@ fn updateInner(p: *Pardes, ev: Event) void { pardes.panes.Query.produceAll(p, ev == .tick, ev == .key); pardes.Pick.produceAll(p, ev == .tick); _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept }); - p.sync(); + // Laid out; its terminals are sized when the burst it came in is + // (`settle`, `sizeTerminals`). + p.layOut(); p.fsReport(); ctlfs.events.announce(p); } @@ -1967,8 +1958,41 @@ pub fn saveRecent(p: *Pardes) void { } /// Recompute geometry, push grid-size changes to each emulator and pty, -/// fire deferred greetings. +/// fire deferred greetings: a step of its own (a 9P request's, a view's). pub fn sync(p: *Pardes) void { + p.layOut(); + p.sizeTerminals(); +} + +/// Each terminal's emulator and pty at the size its pane is laid out to, +/// once a step and its burst of inputs (`settle`), never once a key: a +/// size the keys of one burst give and take back (a level borrowing a +/// shell's rows, the next key giving them back) reaches neither. Every +/// reflow clears the prompt line under the cursor for the shell to draw +/// again (ghostty's Screen.resize, `shell_redraws_prompt`), and the shell, +/// told twice, reads its size once, finds the one it had and draws +/// nothing: the prompt was gone until it next printed one. The emulator's +/// own size says what it was given; the view that sizes a terminal +/// (`sizes`) has its size. +pub fn sizeTerminals(p: *Pardes) void { + for (p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const state = pane.terminal orelse continue; + if (!p.sizes(pane)) continue; + const grid = pardes.Term.grid(state); + if (grid.cols == pane.cols and grid.len == pane.rows) continue; + pane.resizeGrid(p, pane.cols, pane.rows); + p.shell_rows.markStale(pane); // reflow moved every row + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); + pane.fs.winsize = null; + } +} + +/// The step's geometry: each pane's rect, tag rows and size (a terminal's +/// emulator and pty follow once a burst: `sizeTerminals`), its bands, and +/// the deferred greetings. What a step lays out in its middle, to read the +/// geometry after (a picker's first preview), is laid out with this. +pub fn layOut(p: *Pardes) void { const v = p.view(); while (p.unplaced.findFirstSet()) |id| { p.unplaced.unset(id); @@ -1981,7 +2005,9 @@ pub fn sync(p: *Pardes) void { // A file opened or closed this step: the kept list follows. p.saveRecent(); tagline.flattenHeaders(p); - if (p.headerColumn() != null and layout.columnBarHeight(p) == 0) { + // A column's tag with no row to be in lets the keyboard go; a lone + // column's keeps it in the window row (UX K'2). + if (p.headerColumn() != null and layout.columnBarHeight(p) == 0 and !layout.columnInWindowRow(p)) { tagline.exitHeader(p); } pardes.panes.reapPanes(p); @@ -2021,7 +2047,7 @@ pub fn sync(p: *Pardes) void { const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null; // The tag's cursor and selections are offsets in its text at rest: // a head shown over its own text moves none of them (UX D1). - const at_rest = if (pardes.Trail.outOfRest(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; + const at_rest = if (pardes.Trail.outOfRest(p, pane) or pardes.TagState.asks(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; const lead = if (at_rest) |made| made.len else pane.tag_lead; if (lead != pane.tag_lead) { const t = &pane.tag; @@ -2083,14 +2109,6 @@ pub fn sync(p: *Pardes) void { if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0)) and (!pane.isTerminal() or p.sizes(pane))) { - // doc panes have no pty/emulator grid to reflow; just record - // the size so bodyText renders the right number of rows - if (pane.isTerminal()) { - pane.resizeGrid(p, cols, rows); - p.shell_rows.markStale(pane); // reflow moved every row - p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); - pane.fs.winsize = null; - } pane.cols = cols; pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; @@ -2544,25 +2562,30 @@ test "topbar hover highlights exactly the executable word" { defer frame.deinit(); _ = try p.render(frame.allocator()); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } }); - _ = frame.reset(.retain_capacity); - const hovered = try p.render(frame.allocator()); - for (0.."Newcol".len) |col| { - const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0); - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg); - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg); - } - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg); + // Each side of the window row (UX K'2): the lone column's `New`, then + // the window's `Find`. + const words = tagline.windowRow(p).words; + for ([_]struct { at: u16, len: u16 }{ .{ .at = TAG_TEXT_INSET, .len = "New".len }, .{ .at = words, .len = "Find".len } }) |word| { + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + 1, .row = 0 } }); + _ = frame.reset(.retain_capacity); + const hovered = try p.render(frame.allocator()); + for (0..word.len) |col| { + const cell = hovered.at(word.at + @as(u16, @intCast(col)), 0); + try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg); + try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg); + } + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(word.at + word.len, 0).style.bg); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } }); - _ = frame.reset(.retain_capacity); - const whitespace = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg); + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + word.len, .row = 0 } }); + _ = frame.reset(.retain_capacity); + const whitespace = try p.render(frame.allocator()); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(word.at + 1, 0).style.bg); + } p.update(.pointer_leave); _ = frame.reset(.retain_capacity); const left = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(words + 1, 0).style.bg); } test "pane-tag Exec prefers Term and argument builtins before shell fallback" { @@ -2573,9 +2596,10 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { while (p.nextEffect()) |_| {} // initial shell spawn/geometry p.acknowledgeShell(.at(0), "/bin/sh", false); - // The Term word names the shell the host ran, and opens another of it. + // The Term word names the shell the host ran, and opens another of it: + // the tag's text after its computed Del (UX K'3). const pane = p.panes[0].?; - try std.testing.expectEqualStrings(" Term+sh" ++ tagline.terminal_pane_tail[" Term".len..], tagline.curTail(pane)); + try std.testing.expectEqualStrings("Term+sh", tagline.curTail(pane)); const tag_x = p.view().rects[0].x + TAG_TEXT_INSET; const tag_y = p.view().rects[0].y; @@ -2602,10 +2626,11 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { // Argument-taking builtins use the same gesture path: a tag sweep is the // complete command line, and Theme consumes its tail without a PTY write. if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = try p.gpa.dupe(u8, " Theme dark"); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = tag_x + 1, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .drag, .col = tag_x + 10, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = tag_x + 10, .row = tag_y } }); + pane.tag.own = try p.gpa.dupe(u8, "Theme dark"); + const theme_x = tag_x + @as(u16, @intCast(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "Theme dark").?)); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = theme_x, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .drag, .col = theme_x + 9, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = theme_x + 9, .row = tag_y } }); try std.testing.expectEqualStrings("dark", p.theme().name); while (p.nextEffect()) |effect| switch (effect) { .write => return error.ArgumentBuiltinFellThroughToPty, @@ -2621,9 +2646,10 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { // A word absent from the builtin vocabulary takes the fallback, including // the terminating carriage return expected by the shell prompt. if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = try p.gpa.dupe(u8, " DefinitelyNotABuiltin"); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = tag_x + 1, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = tag_x + 1, .row = tag_y } }); + pane.tag.own = try p.gpa.dupe(u8, "DefinitelyNotABuiltin"); + const word_x = tag_x + @as(u16, @intCast(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "Definitely").?)) + 1; + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = word_x, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = word_x, .row = tag_y } }); var sent: [256]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -2695,12 +2721,14 @@ test "TreeContext command and custom tag survive a workspace round trip" { defer p.deinit(); const pane = try p.setTestFile("pub fn main() void {}\n"); try std.testing.expect(!pardes.panes.File.supportsContext(pane)); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(pane)); + try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.kindTail(pane)); const path = try p.gpa.dupe(u8, "/test.zig"); p.gpa.free(pane.file.?.path); pane.file.?.path = path; if (!pardes.panes.File.supportsContext(pane)) return error.SkipZigTest; - try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.curTail(pane)); + // TreeContext is a word of its kind's (`:`'s, UX K'4), not its tag's. + try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.kindTail(pane)); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "TreeContext") == null); try std.testing.expect(!pane.file.?.tree_context); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext on")); try std.testing.expect(pane.file.?.tree_context); @@ -2761,7 +2789,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane" const pager_id = try pardes.panes.Output.openPager(p, 0, "/tmp"); const pager_pane = p.panes[pager_id].?; try testing.expect(pager_pane.tty_filter); - try testing.expectEqualStrings(tagline.pager_pane_tail, tagline.curTail(pager_pane)); + try testing.expectEqualStrings(" Filter Del", tagline.computedWords(pager_pane)); try testing.expectEqual(@as(u16, 0), pardes.panes.File.gutterWidth(pager_pane)); try testing.expect(p.executeBuiltinLine(pager_id, "Filter")); try testing.expect(!pager_pane.tty_filter); @@ -2791,7 +2819,9 @@ test "compact tag commands stay beside their own prefix across layout changes" { defer gpa.free(above_tag); const below_tag = try tagline.tagText(p, p.scratch.allocator(), below); try std.testing.expect(below_tag.len > above_tag.len); - const tail = tagline.terminal_pane_tail; + // Its computed Del, the blank before its own text (UX K'1), and that + // text: Term, its shell not yet named. + const tail = " Del Term"; try std.testing.expectEqualStrings(tail, above_tag[above_tag.len - tail.len ..]); try std.testing.expectEqual(above.cwdSlice().len + tail.len, above_tag.len); @@ -2803,7 +2833,7 @@ 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)); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); while (p.nextEffect()) |_| {} - try std.testing.expectEqualStrings(tail, tagline.curTail(below)); + try std.testing.expectEqualStrings("Term", tagline.curTail(below)); try below.appendTag(" lots and lots of typing out here"); try std.testing.expectEqual(above_tag.len, (try tagline.tagText(p, p.scratch.allocator(), above)).len); @@ -3075,7 +3105,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe try std.testing.expect(p.executeBuiltinLine(1, "Repl PY")); var idbuf: [48]u8 = undefined; try std.testing.expectEqualStrings("python-a", exec.replId(&idbuf, p.panes[1].?)); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, p.panes[1].?), " python-a")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), p.panes[1].?), " python-a")); Sent.drain(p); // A click on the file's body, a single word: typed into the REPL. @@ -3278,7 +3308,7 @@ test "a Term started by a shell's path keeps the path in its Term+ word" { try std.testing.expect(p.executeBuiltinLine(0, "Term /bin/sh")); try std.testing.expect(p.view().active != 0); p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+/bin/sh ")); + try std.testing.expectEqualStrings("Term+/bin/sh", tagline.curTail(p.panes[p.view().active].?)); } test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell" { @@ -3304,7 +3334,7 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" { try std.testing.expect(p.view().active != 0); try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+sh ")); + try std.testing.expectEqualStrings("Term+sh", tagline.curTail(p.panes[p.view().active].?)); p.view().active = 0; // A shell that is not there is said, not quietly replaced, and the // pane that asked gets no shell of its own. @@ -3344,7 +3374,7 @@ test "a command pane shows how its command ended, and the next command there run } var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) running")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make -j8) running")); // Running, a second command goes to a pane of its own. const other = exec.execute(p, 1, "ls") orelse return error.NoCommandPane; try std.testing.expect(other != dst); @@ -3362,7 +3392,7 @@ test "a command pane shows how its command ended, and the next command there run try std.testing.expect(p.panes[dst] == pane and !pane.command_pty); try std.testing.expect(p.panes[dst] == pane); try std.testing.expect(pane.command_done); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) exit 2")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make -j8) exit 2")); // Kill leaves a finished one be. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) return error.SignalledAFinishedCommand; @@ -3384,7 +3414,7 @@ test "a command pane shows how its command ended, and the next command there run const ended = std.mem.indexOf(u8, body, "exit 2") orelse return error.ExitLost; const next = std.mem.indexOf(u8, body, "% make test") orelse return error.NoSeparator; try std.testing.expect(said < ended and ended < next); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make test) running")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make test) running")); // Kill stops a running one: its whole process group, SIGTERM. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); var signalled = false; @@ -3745,18 +3775,17 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null); } -test "the workspace tag's Restore word names the last dump, the tag edited around it or not, across a Restore too" { +test "the window row's Restore word names the last dump, the user's text after it, across a Restore too (UX K'2)" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); defer p.deinit(); p.setLastDump("/tmp/a.zon"); - // The tag edited: its own text holds the Restore word as it was then. - p.global_tag.own = try p.gpa.dupe(u8, try std.fmt.allocPrint(p.scratch.allocator(), "{s} Mine", .{tagline.headerDefault(p, .workspace)})); + p.global_tag.own = try p.gpa.dupe(u8, "Mine"); p.setLastDump("/tmp/b.zon"); - try std.testing.expect(std.mem.indexOf(u8, p.global_tag.own.?, "Restore /tmp/b.zon Mine") != null); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/b.zon Mine", tagline.topbar(p)); try dump.dumpState(p); const restored = try dump.restore(p, p.dump_out.?, "/tmp/c.zon"); defer restored.deinit(); - try std.testing.expect(std.mem.indexOf(u8, restored.global_tag.own.?, "Restore /tmp/c.zon Mine") != null); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/c.zon Mine", tagline.topbar(restored)); try std.testing.expectEqualStrings("/tmp/c.zon", restored.last_dump.?); } @@ -3765,27 +3794,45 @@ test "editable workspace and column tags are typed into and persist" { defer p.deinit(); _ = try p.setTestFile("untouched\n"); p.presented(); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); + // One column: its tag in the window row, no column row (UX K'2). + try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); + const words = tagline.windowRow(p).words; // a sweep over a header is its selection, the caret where it ended - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = words, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = words + 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = words + 6, .row = 0 } }); try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6); - // A clicked header is in normal mode: `a` types after the sweep's - // last character, the blank it ended on. + // A clicked header is in normal mode: `a` types after the sweep's last + // character, in the computed words: refused, they are no one's. p.update(.{ .key = .{ .cp = 'a', .text = "a" } }); p.update(.{ .key = .{ .cp = 'H', .text = "Help " } }); - try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol")); + try std.testing.expect(p.global_tag.own == null); p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); + // After them, the user's text. + const end: u16 = @intCast(words + "Find Grep Newcol Help Exit ".len); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = end, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = end, .row = 0 } }); + p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); + p.update(.{ .key = .{ .cp = 'H', .text = "Help " } }); + try std.testing.expectEqualStrings("Help ", p.global_tag.own.?); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Help ", tagline.topbar(p)); + p.update(.{ .key = .{ .cp = Key.escape } }); + // The column's tag, at the window row's left: typed into, it has the + // user's text and the column row comes for it; emptied, it goes. + const own: u16 = TAG_TEXT_INSET + "New Term ".len; + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = own, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = own, .row = 0 } }); + try std.testing.expectEqual(@as(?usize, 0), p.headerColumn()); p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); p.update(.{ .key = .{ .cp = 'é', .text = "é" } }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "éNew")); + try std.testing.expectEqualStrings("New Term é", tagline.columnTag(p, 0)); + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "New")); + try std.testing.expectEqualStrings("New Term ", tagline.columnTag(p, 0)); + try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); + try std.testing.expectEqual(@as(?usize, 0), p.headerColumn()); p.update(.{ .paste = "Grep " }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "Grep New")); + try std.testing.expectEqualStrings("New Term Grep ", tagline.columnTag(p, 0)); try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); try dump.dumpState(p); const restored = try dump.restore(p, p.dump_out.?, "test"); @@ -3797,7 +3844,7 @@ test "editable workspace and column tags are typed into and persist" { try dump.dumpState(p); const empty = try dump.restore(p, p.dump_out.?, "test"); defer empty.deinit(); - try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0)); + try std.testing.expectEqualStrings("New Term ", tagline.columnTag(empty, 0)); } test "column tag first-cell execution keeps New local to the clicked column" { @@ -3825,6 +3872,7 @@ test "a screen too short for the column row releases a column tag's focus withou defer p.deinit(); const pane = try p.setTestFile("unchanged body\n"); p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Help"); + p.sync(); p.presented(); const shown = p.view().rects[0]; try std.testing.expectEqual(TOPBAR_H + COLBAR_H, shown.y); @@ -3838,7 +3886,7 @@ test "a screen too short for the column row releases a column tag's focus withou try std.testing.expect(p.view().header == null and p.headerColumn() == null); p.update(.{ .resize = .{ .cols = 60, .rows = 12 } }); try std.testing.expectEqual(shown, p.view().rects[0]); - try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0)); + try std.testing.expectEqualStrings("New Term New Help", tagline.columnTag(p, 0)); try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } @@ -4186,6 +4234,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; try std.testing.expect(sp.isTerminal()); @@ -4252,6 +4301,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ @@ -4297,3 +4347,33 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" test "every allocation failure during boot is a clean OutOfMemory" { try std.testing.checkAllAllocationFailures(std.testing.allocator, bootAndTearDown, .{}); } + +test "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty: its prompt line stays (M1's ttyhelp row 3)" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell's emulator + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 31, .boot = .tty }); + defer p.deinit(); + const shell = p.panes[0].?; + // bash's prompt as pardes's marks draw it (dev/Shell.zig bash_rc), + // the cursor at its input. + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + const below = p.view().cols[0].panes[1]; + p.view().active = below; + p.settle(); + const rows = shell.rows; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const body_layer = @import("body_layer.zig"); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); + // `?`'s level takes rows of the shell's (layout.floorRows), `tutor` + // narrows it to one leaf and gives them back: keys of one burst, one + // settle after them, as a frontend takes a read of them. + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + p.update(.{ .key = .{ .cp = '?', .text = "?" } }); + try std.testing.expect(shell.rows < rows); + for ("tutor") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); + try std.testing.expectEqual(rows, shell.rows); + // Its pty told nothing: no SIGWINCH for a size it had. + while (p.nextEffect()) |e| try std.testing.expect(e != .resize_pty); + p.settle(); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); +} |
