From 137dc2ea4be0fc5baf4cab1d8a757ce426e5cbb2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 21:19:57 -0300 Subject: Views generated by each read stat 0, as acme's do: data, xdata, index, layout, recent and listeners; fs.md says which files have real lengths A stat of index, layout, recent or listeners built the whole view to count it, and data and xdata reported the body's length though a read answers what addr selects. Those now stat 0, as screen and pane/new already did, and fs.md lists the files whose length is real and says to read the rest to the end. Co-Authored-By: Claude Opus 5.5 --- src/ninep/pane.zig | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'src/ninep/pane.zig') diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 14877f0f..3b5f2e6c 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -398,7 +398,9 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 { return switch (f) { // A terminal's body reads its screen and history, as text. .body => if (pane.file == null and pane.isTerminal()) panes.terminal.screenTextLen(pane) else if (pdfText(p, pane)) |t| t.len else bodyOf(pane).len, - .data, .xdata => bodyOf(pane).len, + // What addr selects, generated by each read: no length, as acme's + // data and xdata have none. + .data, .xdata => 0, .tag => tagOf(p, pane).len, .name => nameOf(p, pane).len + 1, .ctl => ctl: { @@ -437,23 +439,6 @@ pub fn columnOf(p: *Pardes, id: usize) u32 { return pardes.layout.columnSerial(p, at.col); } -pub fn indexLen(p: *Pardes) u64 { - var n: u64 = 0; - var last: u32 = 0; - while (tree.nextSerialAfter(p, last)) |serial| { - last = serial; - const pane = p.panes[p.paneBySerial(serial).?].?; - var digits: [16]u8 = undefined; - // unreachable: a u32 serial is at most 10 digits - n += (std.fmt.bufPrint(&digits, "{d}", .{serial}) catch unreachable).len; - var name_buf: [4 * 4096]u8 = undefined; - n += 1 + kindOf(pane).len + 3 + events.shown(nameOf(p, pane), &name_buf).len + 1; - // unreachable: a column index is under 16 digits - n += 1 + (std.fmt.bufPrint(&digits, "{d}", .{columnOf(p, p.paneBySerial(serial).?)}) catch unreachable).len; - } - return n; -} - // ---- reads ---- pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply { @@ -1081,7 +1066,7 @@ const withFile = th.withFile; const serialOf = th.serialOf; const Status = tree.Status; -test "index lists serial kind dirty flag and name and stat reports its length" { +test "index lists serial kind dirty flag and name, and stats 0, a view generated by each read" { const gpa = testing.allocator; const p = try withFile(gpa, "hello\nthere\n"); defer p.deinit(); @@ -1095,7 +1080,7 @@ test "index lists serial kind dirty flag and name and stat reports its length" { try testing.expect(std.mem.indexOf(u8, a.bytes, clean_row) != null); const at = std.mem.indexOf(u8, a.bytes, clean_row).?; const stat = call(p, .{ .tag = 1, .op = .getattr, .node = index }); - try testing.expectEqual(@as(u64, a.bytes.len), stat.reply.attr.size); + try testing.expectEqual(@as(u64, 0), stat.reply.attr.size); try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode); pane.file.?.saved_revision = pane.file.?.revision -% 1; @@ -1107,7 +1092,6 @@ test "index lists serial kind dirty flag and name and stat reports its length" { const serial = try th.newPane(p); const both = rd(p, index, 0, 4096); - try testing.expectEqual(@as(u64, both.bytes.len), indexLen(p)); var expected: [4200]u8 = undefined; const made = p.panes[p.paneBySerial(serial).?].?; try testing.expect(std.mem.endsWith(u8, both.bytes, try std.fmt.bufPrint(&expected, "\n{d} text 0 {s} {d}\n", .{ serial, nameOf(p, made), columnOf(p, p.paneBySerial(serial).?) }))); -- cgit v1.3