diff options
Diffstat (limited to 'core/ninep')
| -rw-r--r-- | core/ninep/cols.zig | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/core/ninep/cols.zig b/core/ninep/cols.zig index 88d8ef88..c84017a7 100644 --- a/core/ninep/cols.zig +++ b/core/ninep/cols.zig @@ -79,7 +79,7 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply { if (pending) p.fs.header_trunc_pending = null; return tree.failText(req.tag, E.INVAL, why); } - const had = if (pending) 0 else headerText(p, serial).?.len; + const had = if (pending) 0 else if (t.own) |own| own.len else 0; // A rewrite drops its one trailing newline: `echo <4096 bytes> > tag` // is 4096 bytes of tag, and fits. const rewrite = pending or p.fs.header_rewrite == rewriteKey(serial); @@ -89,7 +89,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply { return tree.failText(req.tag, E.NOSPC, pardes.ctlfs.pane.e_tag_over); } applyTruncation(p, serial); - const was = headerText(p, serial).?; + // Its own text grows, after the computed words (UX K'1). + const was: []const u8 = t.own orelse ""; var data = req.data; const rewriting = p.fs.header_rewrite == rewriteKey(serial); // A newline held from the write before goes in once more text follows. @@ -106,8 +107,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply { return .{ .tag = req.tag, .written = @intCast(req.data.len) }; } -/// Truncating clears it, as a pane tag's `cleartag`: its default words go -/// too, and `u` in it brings them back. +/// Truncating clears it, as a pane tag's `cleartag`: its own text goes, +/// its computed words stay, and `u` in it brings the text back. pub fn truncate(p: *Pardes, serial: ?u32) tree.Status { if (header(p, serial) == null) return .err; // Done with the write after it, which may yet be refused. @@ -128,8 +129,9 @@ fn clear(p: *Pardes, serial: ?u32) tree.Status { const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked if (t.own) |own| p.gpa.free(own); t.own = empty; + // what is left is the computed words; the cursor goes after them t.cur_row = 0; - t.cur_col = 0; + t.cur_col = @intCast(tagline.headerWords(p, t.what).len + 1); p.fs.header_rewrite = rewriteKey(serial); p.fs.header_held = false; return .ok; @@ -548,19 +550,21 @@ test "a column's tag and the workspace's read, replace and append as a pane tag try testing.expectEqual(E.NOENT, th.look_up(p, col_dir, "777").errno()); const tag = Node.ofCol(serial, .tag); try testing.expectEqual(tree.Status.ok, th.look_up(p, Node.ofCol(serial, .dir), "tag").reply.status); - try testing.expectEqualStrings("New Term Find Grep Joincol Delcol", th.rd(p, tag, 0, 4096).bytes); - // `echo Make > tag`: cleared, then the newline ending the write dropped. + // Its computed words (UX K'2), a blank, and its own text: none yet. + try testing.expectEqualStrings("New Term ", th.rd(p, tag, 0, 4096).bytes); + // `echo Make > tag`: its own text cleared, then the newline ending the + // write dropped; the computed words stay. _ = th.call(p, .{ .tag = 1, .op = .setattr, .node = tag, .truncate = true }); _ = th.wr(p, tag, "Make\n"); - try testing.expectEqualStrings("Make", th.rd(p, tag, 0, 4096).bytes); + try testing.expectEqualStrings("New Term Make", th.rd(p, tag, 0, 4096).bytes); _ = th.call(p, .{ .tag = 2, .op = .release, .node = tag }); // `>>` appends; a newline in a one-line tag is a space. _ = th.wr(p, tag, " Lint\nNow"); - try testing.expectEqualStrings("Make Lint Now", th.rd(p, tag, 0, 4096).bytes); + try testing.expectEqualStrings("New Term Make Lint Now", th.rd(p, tag, 0, 4096).bytes); const top = @backingInt(tree.TopFile.tag); _ = th.call(p, .{ .tag = 3, .op = .setattr, .node = top, .truncate = true }); _ = th.wr(p, top, "Newcol Exit\n"); - try testing.expectEqualStrings("Newcol Exit", tagline.topbar(p)); + try testing.expectEqualStrings("Find Grep Newcol Help Exit Newcol Exit", tagline.topbar(p)); } test "a focus write makes its pane's column the active one: layout says so and pane/new goes there" { |
