From 68a74ec034a24c9b016497880e375f291498ae5f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 10:49:56 -0300 Subject: A terminal's new directory is a rename in the log, and its ctl counts its body The log said new N / and later del N for a terminal, with no rename in between, though a terminal is named by its directory. setCwd now logs the rename once the pane has been announced. A terminal's ctl line gave body length 0 while its body reads its history; it now counts that history (without keeping a copy). Co-Authored-By: Claude Opus 5.5 --- src/ninep/ctl.zig | 3 ++- src/ninep/pty.zig | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src/ninep') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 5fe04f5c..c1f78bab 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -156,7 +156,8 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{ pane.serial, pane_files.tagOf(p, pane).len, - pane_files.bodyOf(pane).len, + // A terminal's body is its history, read whole on an open's first read. + if (pane.isTerminal()) panes.Terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len, @as(u32, 0), @intFromBool(pane_files.dirtyOf(pane)), pane.cols, diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 0a55df94..50d14624 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -849,6 +849,35 @@ test "a run's answer says cut when its output's start is gone, and reads a bound try testing.expectEqualStrings("error out of memory\n", sh.answered(p, node, h, into)); } +test "a terminal's ctl counts its body, and a new directory is a rename in the log" { + const gpa = testing.allocator; + const p = try withTerm(gpa); + defer p.deinit(); + const serial = serialOf(p); + p.update(.{ .output = .{ .pane = 0, .bytes = "some history\r\nmore" } }); + while (p.nextEffect()) |_| {} + const opened = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .body) }); + const body_len = call(p, .{ .tag = 2, .op = .read, .node = Node.of(serial, .body), .handle = opened.reply.handle, .size = 1 << 16 }).bytes.len; + _ = call(p, .{ .tag = 3, .op = .release, .node = Node.of(serial, .body), .handle = opened.reply.handle }); + try testing.expect(body_len > 0); + var fields = std.mem.tokenizeScalar(u8, rd(p, Node.of(serial, .ctl), 0, 4096).bytes, ' '); + _ = fields.next(); + _ = fields.next(); + try testing.expectEqual(body_len, try std.fmt.parseInt(usize, fields.next().?, 10)); + + const log = @intFromEnum(tree.TopFile.log); + const f = call(p, .{ .tag = 4, .op = .open, .node = log }).reply.handle; + const frozen = call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len; + _ = call(p, .{ .tag = 6, .op = .write, .node = log, .handle = f, .data = "follow" }); + p.setCwd(0, "/somewhere/else"); + var want: [64]u8 = undefined; + try testing.expectEqualStrings( + try std.fmt.bufPrint(&want, "rename {d} /somewhere/else\n", .{serial}), + call(p, .{ .tag = 7, .op = .read, .node = log, .handle = f, .off = frozen, .size = 4096 }).bytes, + ); + _ = call(p, .{ .tag = 8, .op = .release, .node = log, .handle = f }); +} + test "closing a terminal pane asks its shell to hang up the pty" { const p = try withTerm(testing.allocator); defer p.deinit(); -- cgit v1.3