summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/ninep
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/addr.zig8
-rw-r--r--src/ninep/cols.zig64
-rw-r--r--src/ninep/ctl.zig237
-rw-r--r--src/ninep/events.zig38
-rw-r--r--src/ninep/pane.zig19
-rw-r--r--src/ninep/pty.zig11
-rw-r--r--src/ninep/screen.zig6
-rw-r--r--src/ninep/testing.zig4
-rw-r--r--src/ninep/tree.zig132
9 files changed, 274 insertions, 245 deletions
diff --git a/src/ninep/addr.zig b/src/ninep/addr.zig
index b78c46e7..86d2d49e 100644
--- a/src/ninep/addr.zig
+++ b/src/ninep/addr.zig
@@ -638,15 +638,15 @@ test "the address language, form by form" {
}
// Each failure says which it is.
for ([_][2][]const u8{
- .{ "zzz", e_syntax }, .{ "/nomatch/", e_no_match }, .{ "99", e_range },
- .{ "#999", e_range }, .{ "/a[/", e_regexp }, .{ "/(a/", e_regexp },
- .{ "/*a/", e_regexp }, .{ "99:1", e_range }, .{ "2:0", e_col_zero },
+ .{ "zzz", e_syntax }, .{ "/nomatch/", e_no_match }, .{ "99", e_range },
+ .{ "#999", e_range }, .{ "/a[/", e_regexp }, .{ "/(a/", e_regexp },
+ .{ "/*a/", e_regexp }, .{ "99:1", e_range }, .{ "2:0", e_col_zero },
}) |c| {
_ = th.wr(p, addr, "#0");
try testing.expectEqualStrings(c[1], th.wr(p, addr, c[0]).reply.ename);
}
- const nested = "," ** 4096;
+ const nested = &@as([4096]u8, @splat(','));
_ = th.wr(p, addr, "#0");
try testing.expectEqual(E.INVAL, th.wr(p, addr, nested).errno());
}
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index e3b456ba..6f5bee23 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -34,7 +34,7 @@ pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void {
const active = activeColumn(p);
for (0..p.ncol) |c| {
try w.print("{d} {d} {d} {d} {s} {s}", .{
- layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c],
+ layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c],
if (active == c) "current" else "notcurrent", if (p.col_n[c] == 0) "empty" else "full",
});
for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
@@ -229,8 +229,8 @@ test "Joincol is refused when the joined column cannot give each pane its tag an
const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 12 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const ctl = @intFromEnum(tree.TopFile.ctl);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const ctl = @backingInt(tree.TopFile.ctl);
+ const focus = @backingInt(tree.TopFile.focus);
// Two panes in the first column, then a second column of two.
const a = try th.newPane(p);
_ = a;
@@ -257,10 +257,10 @@ test "pane/new takes rows from a pane in another column before refusing ENOSPC"
while (p.nextEffect()) |_| {}
const first = p.panes[p.active].?.serial;
// A second column holding one tall pane.
- try testing.expectEqual(tree.Status.ok, th.wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, th.wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status);
const tall = try th.newPane(p);
const tall_col = layout.findPane(p, p.paneBySerial(tall).?).?.col;
- const focus = @intFromEnum(tree.TopFile.focus);
+ const focus = @backingInt(tree.TopFile.focus);
var digits: [16]u8 = undefined;
// From the first column, until pane/new is refused.
var moved = false;
@@ -288,18 +288,18 @@ test "exactly 4096 bytes written with echo's newline after a truncation fit ever
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = th.serialOf(p);
- const text = "w" ** 4096 ++ "\n";
- for ([_]u64{ tree.Node.of(serial, .tag), tree.Node.ofCol(layout.columnSerial(p, 0), .tag), @intFromEnum(tree.TopFile.tag) }) |node| {
+ const text = &@as([4096]u8, @splat('w')) ++ "\n";
+ for ([_]u64{ tree.Node.of(serial, .tag), tree.Node.ofCol(layout.columnSerial(p, 0), .tag), @backingInt(tree.TopFile.tag) }) |node| {
_ = th.call(p, .{ .tag = 1, .op = .setattr, .node = node, .truncate = true });
const h = th.call(p, .{ .tag = 2, .op = .open, .node = node, .omode = 1 }).reply.handle;
const r = th.call(p, .{ .tag = 3, .op = .write, .node = node, .handle = h, .data = text });
try testing.expectEqual(tree.Status.ok, r.reply.status);
_ = th.call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h, .opened = true });
- try testing.expect(std.mem.endsWith(u8, th.rd(p, node, 0, 1 << 16).bytes, "w" ** 4096));
+ try testing.expect(std.mem.endsWith(u8, th.rd(p, node, 0, 1 << 16).bytes, &@as([4096]u8, @splat('w'))));
// One more byte is over.
_ = th.call(p, .{ .tag = 5, .op = .setattr, .node = node, .truncate = true });
const h2 = th.call(p, .{ .tag = 6, .op = .open, .node = node, .omode = 1 }).reply.handle;
- try testing.expectEqual(E.NOSPC, th.call(p, .{ .tag = 7, .op = .write, .node = node, .handle = h2, .data = "w" ** 4097 ++ "\n" }).errno());
+ try testing.expectEqual(E.NOSPC, th.call(p, .{ .tag = 7, .op = .write, .node = node, .handle = h2, .data = &@as([4097]u8, @splat('w')) ++ "\n" }).errno());
_ = th.call(p, .{ .tag = 8, .op = .release, .node = node, .handle = h2, .opened = true });
}
}
@@ -316,12 +316,12 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe
for (p.col_panes[col][0..p.col_n[col]]) |k| {
const each = p.panes[k].?;
if (each.tag.own) |old| p.gpa.free(old);
- each.tag.own = try p.gpa.dupe(u8, "word " ** 60);
+ each.tag.own = try p.gpa.dupe(u8, std.mem.asBytes(&@as([60][5]u8, @splat("word ".*))));
}
try testing.expect(p.col_n[col] >= 2);
p.sync();
- const ctl = @intFromEnum(tree.TopFile.ctl);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const ctl = @backingInt(tree.TopFile.ctl);
+ const focus = @backingInt(tree.TopFile.focus);
var digits: [16]u8 = undefined;
const own = try std.fmt.bufPrint(&digits, "{d}\n", .{pane.serial});
var refused = false;
@@ -349,7 +349,7 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe
test "a tagexec word that makes, acts on and focuses no pane reads back nothing" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status);
try testing.expectEqualStrings("", th.rd(p, tagexec, 0, 64).bytes);
// A column's New makes one, and answers it.
@@ -362,7 +362,7 @@ test "a tagexec word that makes, acts on and focuses no pane reads back nothing"
test "New written to a column's ctl reads back the new pane alone, as its exec does" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_exec = @intFromEnum(tree.TopFile.exec);
+ const root_exec = @backingInt(tree.TopFile.exec);
_ = th.wr(p, root_exec, "Msg before\n");
const ctl_node = tree.Node.ofCol(layout.columnSerial(p, 0), .ctl);
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl_node, "New\n").reply.status);
@@ -390,7 +390,7 @@ test "a pane's word written to /tagexec or a column's exec is refused, and acts
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
- for ([_]u64{ @intFromEnum(tree.TopFile.tagexec), col_exec }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| {
for ([_][]const u8{ "Undo\n", "Msg hi\n", "Redo\n" }) |line| {
const refused = th.wr(p, node, line);
try testing.expectEqual(E.INVAL, refused.errno());
@@ -411,7 +411,7 @@ test "Help and Find at /tagexec act in the session's directory, not the keyboard
const session = buf[0..try tmp.dir.realPath(testing.io, &buf)];
@memcpy(p.session_dir[0..session.len], session);
p.session_dir_len = @intCast(session.len);
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| {
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status);
const made = p.panes[p.active].?.file.?.path;
@@ -427,7 +427,7 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se
const term = p.panes[p.active].?;
try testing.expect(pardes.exec.takesCommandLine(p, p.active));
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
- for ([_]u64{ @intFromEnum(tree.TopFile.tagexec), col_exec }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| {
p.active = p.paneBySerial(term.serial).?;
const before = p.next_serial;
const r = th.wr(p, node, "echo from-the-tag\n");
@@ -443,7 +443,7 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se
test "New and Tty run at /tagexec and a column's exec, with no pane at all too" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
for ([_]u64{ tagexec, col_exec }) |node| for ([_][]const u8{ "New\n", "Tty\n" }) |line| {
const before = p.next_serial;
@@ -469,7 +469,7 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in
const Builtin = pardes.builtins.registry.Builtin();
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
for ([_]struct { node: u64, own: []const u8 }{
- .{ .node = @intFromEnum(tree.TopFile.tagexec), .own = pardes.config.topbar_str },
+ .{ .node = @backingInt(tree.TopFile.tagexec), .own = pardes.config.topbar_str },
.{ .node = col_exec, .own = tagline.column_tag_default },
}) |tag_file| {
var checked: usize = 0;
@@ -517,7 +517,7 @@ test "layout lists each column's place, panes and state, and the active one" {
const first_serial = layout.columnSerial(p, 0);
const new_serial = layout.columnSerial(p, 1);
try testing.expect(first_serial != new_serial);
- const layout_node = @intFromEnum(tree.TopFile.layout);
+ const layout_node = @backingInt(tree.TopFile.layout);
const text = th.rd(p, layout_node, 0, 4096).bytes;
var want: [256]u8 = undefined;
const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.col_x[0], p.col_w[0], p.panes[0].?.serial });
@@ -528,19 +528,19 @@ test "layout lists each column's place, panes and state, and the active one" {
try testing.expect(text.len > 0);
try testing.expectEqual(@as(u64, 0), th.call(p, .{ .tag = 1, .op = .getattr, .node = layout_node }).reply.attr.size); // generated by each read
// /index says which column each pane is in, by its serial, last.
- try testing.expect(std.mem.endsWith(u8, th.rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, try std.fmt.bufPrint(&want, " {d}\n", .{first_serial})));
+ try testing.expect(std.mem.endsWith(u8, th.rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, try std.fmt.bufPrint(&want, " {d}\n", .{first_serial})));
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "newcol {d}\n", .{new_serial})));
// A column that closes takes its name with it; the others keep theirs.
try p.removeColumn(1);
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "delcol {d}\n", .{new_serial})));
- try testing.expectEqual(E.NOENT, th.look_up(p, @intFromEnum(tree.TopFile.col), try std.fmt.bufPrint(&want, "{d}", .{new_serial})).errno());
+ try testing.expectEqual(E.NOENT, th.look_up(p, @backingInt(tree.TopFile.col), try std.fmt.bufPrint(&want, "{d}", .{new_serial})).errno());
try testing.expectEqual(first_serial, layout.columnSerial(p, 0));
}
test "a column's tag and the workspace's read, replace and append as a pane tag does, on one line" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const col_dir = @intFromEnum(tree.TopFile.col);
+ const col_dir = @backingInt(tree.TopFile.col);
const serial = layout.columnSerial(p, 0);
var name: [16]u8 = undefined;
try testing.expectEqual(tree.Status.ok, th.look_up(p, col_dir, try std.fmt.bufPrint(&name, "{d}", .{serial})).reply.status);
@@ -557,7 +557,7 @@ test "a column's tag and the workspace's read, replace and append as a pane 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);
- const top = @intFromEnum(tree.TopFile.tag);
+ 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));
@@ -574,11 +574,11 @@ test "a focus write makes its pane's column the active one: layout says so and p
p.sync();
try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.col);
var digits: [16]u8 = undefined;
- _ = th.wr(p, @intFromEnum(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
+ _ = th.wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
var want: [32]u8 = undefined;
- const text = th.rd(p, @intFromEnum(tree.TopFile.layout), 0, 4096).bytes;
+ const text = th.rd(p, @backingInt(tree.TopFile.layout), 0, 4096).bytes;
try testing.expect(std.mem.endsWith(u8, text, try std.fmt.bufPrint(&want, "active {d}\n", .{layout.columnSerial(p, 0)})));
- const made = th.call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(tree.TopFile.new) }).reply.handle;
+ const made = th.call(p, .{ .tag = 1, .op = .open, .node = @backingInt(tree.TopFile.new) }).reply.handle;
try testing.expectEqual(@as(usize, 0), layout.findPane(p, p.paneBySerial(made).?).?.col);
}
}
@@ -588,9 +588,9 @@ test "a refused write after a truncation leaves every kind of tag as it was, and
defer p.deinit();
const serial = th.serialOf(p);
const col = layout.columnSerial(p, 0);
- const big = "w" ** (limits.max_tag_tail + 1);
+ const big = &@as([limits.max_tag_tail + 1]u8, @splat('w'));
// Each tag: a truncating open, then a write too long: nothing changes.
- for ([_]u64{ Node.of(serial, .tag), Node.ofCol(col, .tag), @intFromEnum(tree.TopFile.tag) }) |node| {
+ for ([_]u64{ Node.of(serial, .tag), Node.ofCol(col, .tag), @backingInt(tree.TopFile.tag) }) |node| {
_ = th.wr(p, node, " Mine");
const before = try testing.allocator.dupe(u8, th.rd(p, node, 0, 1 << 16).bytes);
defer testing.allocator.free(before);
@@ -651,13 +651,13 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on
try testing.expectEqual(@as(?usize, 0), layout.columnBySerial(p, right));
try testing.expect(std.mem.endsWith(u8, headerText(p, right).?, " Mine"));
// The root's ctl points a column word at the column's own.
- try testing.expect(std.mem.endsWith(u8, th.wr(p, @intFromEnum(tree.TopFile.ctl), "Delcol\n").reply.ename, "write it to col/<serial>/ctl"));
+ try testing.expect(std.mem.endsWith(u8, th.wr(p, @backingInt(tree.TopFile.ctl), "Delcol\n").reply.ename, "write it to col/<serial>/ctl"));
}
test "tagexec runs a word as a click in the workspace tag; exec files read back what they touched; their messages are the session's" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const tagexec = @intFromEnum(tree.TopFile.tagexec);
+ const tagexec = @backingInt(tree.TopFile.tagexec);
try testing.expectEqual(tree.Status.ok, th.look_up(p, tree.root, "tagexec").reply.status);
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status);
try testing.expectEqual(@as(usize, 2), p.ncol);
@@ -680,7 +680,7 @@ test "a word run from the workspace's or a column's tag runs in the session's di
defer p.deinit();
const session = p.sessionDir();
try testing.expect(!std.mem.eql(u8, session, pardes.Pardes.paneDir(p.panes[0].?))); // the file is elsewhere
- const dirs = [_]u64{ @intFromEnum(tree.TopFile.tagexec), Node.ofCol(layout.columnSerial(p, 0), .exec) };
+ const dirs = [_]u64{ @backingInt(tree.TopFile.tagexec), Node.ofCol(layout.columnSerial(p, 0), .exec) };
for (dirs) |node| {
try testing.expectEqual(tree.Status.ok, th.wr(p, node, "true\n").reply.status);
const made = p.paneBySerial(p.fs.results[0]).?;
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 105de07c..733d9c8e 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -554,6 +554,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
.font => config.Runtime.FontSpec.parse(arg) != null,
// Bare, it says the width, as from a pane's exec.
.tab => arg.len == 0 or (std.fmt.parseInt(u16, arg, 10) catch 0) -% 1 < 16,
+ .callstack_depth => arg.len == 0 or (std.fmt.parseInt(u8, arg, 10) catch 0) -% 1 < pardes.lsp.callstack_max_depth,
else => probe: {
var probe = p.settings;
break :probe probe.apply(setting, if (arg.len > 0) arg else null);
@@ -662,6 +663,7 @@ pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer)
.motion => try w.print("{s} {s}\n", .{ word, @tagName(s.motion) }),
.inactive_dim => try w.print("{s} {d}\n", .{ word, s.inactive_dim }),
.grip_width => try w.print("{s} {d}\n", .{ word, s.grip_width }),
+ .callstack_depth => try w.print("{s} {d}\n", .{ word, s.callstack_depth }),
.tab => try w.print("{s} {d}\n", .{ word, s.tab }),
}
}
@@ -682,7 +684,7 @@ pub fn readRoot(p: *Pardes, req: Req) Reply {
}
/// /pager, `pardes -`'s: the directory written (empty, or not absolute: the
-/// session's) gets its one +Pager, made or emptied; the serial is what a
+/// session's) gets a new +Pager; the serial is what a
/// read of this same open answers, never another client's. What the open
/// writes after that line is the text, held by tree.zig for `fillPager`.
pub fn writePager(p: *Pardes, req: Req) Reply {
@@ -742,6 +744,17 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM
panes.File.setContent(p, f, page.text);
f.pager_spans = page.spans;
f.saved_revision = f.revision;
+ // A diff paged (`git show`, difftui's patches): its hunks stacked in a
+ // +Diff (DiffLook hunks) in the +Pager's place, the +Pager closed. The
+ // keyboard stays where it was, as a page's.
+ if (f.pager_diff and p.settings.diff_look == .hunks) {
+ const keyboard = p.active;
+ if (panes.Output.openDiff(p, id, f.path, f.content)) |hid| {
+ // ponytail: the text is gone with it; Diff on the +Diff says no such file.
+ p.removePane(id, hid) catch {};
+ } else |_| {}
+ if (p.panes[keyboard] != null) p.active = keyboard;
+ }
}
/// The editor's step: the text of /pager opens closed unread goes in.
@@ -1265,15 +1278,15 @@ const withFile = th.withFile;
const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
-const root_status = @intFromEnum(tree.TopFile.status);
-const root_look = @intFromEnum(tree.TopFile.look);
-const root_exec = @intFromEnum(tree.TopFile.exec);
+const root_status = @backingInt(tree.TopFile.status);
+const root_look = @backingInt(tree.TopFile.look);
+const root_exec = @backingInt(tree.TopFile.exec);
test "a control character in a write to any ctl refuses the whole write, and a quoted line shows a tab as a blank" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const col = layout.columnSerial(p, 0);
- for ([_]u64{ @intFromEnum(tree.TopFile.ctl), Node.of(serialOf(p), .ctl), Node.ofCol(col, .ctl) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.ctl), Node.of(serialOf(p), .ctl), Node.ofCol(col, .ctl) }) |node| {
const r = wr(p, node, "Wrap off\nbo\x01gus\n");
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectEqualStrings(e_control, r.reply.ename);
@@ -1313,7 +1326,7 @@ test "pane ctl read is acme's fields -- index's five, width in cells, font, tab
test "commands lists every builtin with its argument and the ctl that takes it" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const node = @intFromEnum(tree.TopFile.commands);
+ const node = @backingInt(tree.TopFile.commands);
const listed = rd(p, node, 0, 1 << 16);
try testing.expectEqual(@as(u64, listed.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size);
try testing.expectEqual(E.PERM, wr(p, node, "Del\n").errno());
@@ -1360,7 +1373,7 @@ test "focus reads the pane with the keyboard, and a serial written to it moves t
defer p.deinit();
const first = serialOf(p);
const second = try th.newPane(p);
- const focus = @intFromEnum(tree.TopFile.focus);
+ const focus = @backingInt(tree.TopFile.focus);
var line: [16]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{second}), rd(p, focus, 0, 64).bytes);
try testing.expectEqual(@as(u64, rd(p, focus, 0, 64).bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size);
@@ -1435,7 +1448,7 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const first = rd(p, root_ctl, 0, 1 << 16);
try testing.expectEqual(Status.ok, first.reply.status);
const settings = try gpa.dupe(u8, first.bytes);
@@ -1443,6 +1456,8 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi
try testing.expectEqual(@as(u64, settings.len), call(p, .{ .tag = 1, .op = .getattr, .node = root_ctl }).reply.attr.size);
try testing.expect(std.mem.indexOf(u8, settings, "Verbose on\n") != null);
try testing.expect(std.mem.indexOf(u8, settings, "LocationsConfig ") != null);
+ try testing.expect(std.mem.indexOf(u8, settings, "CallstackDepth 8\n") != null);
+ try testing.expectEqual(Status.ok, wr(p, root_ctl, "CallstackDepth").reply.status);
// Settings only: nothing /status or the DumpConfig window says.
try testing.expect(std.mem.indexOf(u8, settings, "Platform") == null);
try testing.expect(std.mem.indexOf(u8, settings, "requested") == null);
@@ -1485,7 +1500,6 @@ test "the root ctl reads the settings as a write takes them, and takes the sessi
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Verbose off").reply.status);
}
-
test "a second lock is refused until the holder unlocks or closes, and binds nobody else" {
const p = try withFile(testing.allocator, "one\ntwo\n");
defer p.deinit();
@@ -1562,7 +1576,7 @@ test "a write of an Edit block carries it whole, to a pane's ctl, the root's ctl
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Edit ,x/foo/{\ni/[/\na/]/\n}\n").reply.status);
try testing.expectEqualStrings("[foo] x\n[foo] y\n", rd(p, body, 0, 64).bytes);
p.active = p.paneBySerial(serial).?;
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Edit ,x/\\[/{\nc/</\n}\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Edit ,x/\\[/{\nc/</\n}\n").reply.status);
try testing.expectEqualStrings("<foo] x\n<foo] y\n", rd(p, body, 0, 64).bytes);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Edit $a\nend\n.\n").reply.status);
try testing.expectEqualStrings("<foo] x\n<foo] y\nend\n", rd(p, body, 0, 64).bytes);
@@ -1590,11 +1604,11 @@ test "a message from a root ctl write is the session's in the log" {
defer p.deinit();
p.update(.tick); // the pane's `new` is logged before the log is opened
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 8192 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Kill\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Kill\n").reply.status);
// What it said, the session's; its own words name it, so its Verbose
// announcement gives way to them.
try testing.expectEqualStrings("msg - Kill: nothing running\n", call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .off = frozen, .size = 4096 }).bytes);
@@ -1648,7 +1662,7 @@ test "the root look's file:/re/ goes on from the dot, and a miss leaves the dot
const p = try withFile(gpa, "foo x foo y\nfoo\n");
defer p.deinit();
const dot = Node.of(serialOf(p), .dot);
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
var line: [256]u8 = undefined;
const path = p.panes[0].?.file.?.path;
const again = try std.fmt.bufPrint(&line, "{s}:/foo/\n", .{path});
@@ -1664,14 +1678,14 @@ test "a look's miss repeats the path whole up to 256 bytes, then gives up its mi
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt";
var line: [512]u8 = undefined;
_ = wr(p, root, try std.fmt.bufPrint(&line, "{s}\n", .{long}));
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&line, "look: no match for \"{s}\"\n", .{long})));
- const huge = "é" ** 150; // 300 bytes: its middle cut to fit 256, between characters
+ const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters
_ = wr(p, root, huge ++ "\n");
- try testing.expect(th.logHas(p, "look: no match for \"" ++ "é" ** 63 ++ "…" ++ "é" ** 63 ++ "\"\n"));
+ try testing.expect(th.logHas(p, "look: no match for \"" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "…" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "\"\n"));
}
test "exec runs a builtin at the pane and records the pane it acted on" {
@@ -1913,7 +1927,7 @@ test "Zerox makes a second pane on one buffer: one text, undo and dirty state, i
const a = p.panes[0].?;
const b = p.panes[twin_id].?;
// Both in the index, each its serial, one name.
- const index = rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes;
+ const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
try testing.expectEqual(@as(usize, 2), std.mem.count(u8, index, "/z.txt"));
// b's cursor on `three`; a line written above it in a moves it down.
b.body.cur_row = 2;
@@ -2028,7 +2042,7 @@ test "Zerox twins dump their text once and come back on one buffer from a Restor
defer p.deinit();
const first = serialOf(p);
_ = wr(p, Node.of(first, .name), "/tmp/pardes-zerox-dump.txt\n");
- _ = wr(p, Node.of(first, .body), "unsaved " ** 64 ++ "\n");
+ _ = wr(p, Node.of(first, .body), std.mem.asBytes(&@as([64][8]u8, @splat("unsaved ".*))) ++ "\n");
try testing.expect(p.executeBuiltinLine(0, "Zerox"));
try testing.expect(p.executeBuiltinLine(0, "Zerox"));
try pardes.dump.dumpState(p);
@@ -2057,7 +2071,7 @@ test "a bad Tab width and a bad Incl directory are refused invalid, changing not
defer config.tab_now = config.tab_width;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
for ([_][]const u8{ "Tab 0\n", "Tab 17\n", "Tab x\n" }) |line| {
try testing.expectEqual(E.INVAL, wr(p, root_ctl, line).errno());
// Run from a pane, as a tag click runs it: said invalid too.
@@ -2140,7 +2154,7 @@ test "round 39's small refusals: one name an open, small scratches unasked, twin
tree.runClosedLines(p);
try testing.expectEqualStrings("/tmp/pardes-one.txt", pane.file.?.path);
// Bare Tab on the root ctl says the width, as from a pane.
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Tab\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Tab\n").reply.status);
// Errnos a mount reads from the words.
_ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(p.executeBuiltinLine(0, "Get"));
@@ -2217,7 +2231,7 @@ test "Mount with no dial is wrong #args, and a dial that is no address says bad
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const bare = wr(p, root_ctl, "Mount work\n");
try testing.expectEqual(E.INVAL, bare.errno());
try testing.expectStringStartsWith(bare.reply.ename, "wrong #args");
@@ -2259,7 +2273,8 @@ test "a builtin for one kind of pane is refused on another, and still acts on it
.{ "Petscii\n", "Petscii: only an image or a terminal pane takes it" },
.{ "Palette\n", "Palette: only an image pane takes it" },
.{ "Ascii\n", "Ascii: only an image pane takes it" },
- .{ "Filter\n", "Filter: only a terminal pane takes it" },
+ .{ "Filter\n", "Filter: only a terminal or a +Pager pane takes it" },
+ .{ "Diff\n", "Diff: only a diff or a +Diff pane takes it" },
.{ "Togglettymode\n", "Togglettymode: only a terminal pane takes it" },
};
for (cases) |case| {
@@ -2312,7 +2327,7 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane'
const serial = serialOf(p);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/pardes-no-such-dir-zz/x.txt\n").reply.status);
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "edited\n").reply.status);
- try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status);
+ try testing.expectEqual(Status.err, wr(p, @backingInt(tree.TopFile.ctl), "Exit\n").reply.status);
const unsaved = for (p.panes) |slot| {
const pane = slot orelse continue;
const f = pane.file orelse continue;
@@ -2343,7 +2358,7 @@ test "a look at a file it may not read fails the write naming the file" {
test "Pager is a setting of the root ctl: pardes by default, off taken, anything else refused with its choices" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "Pager pardes\n") != null);
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Pager off\n").reply.status);
try testing.expectEqual(config.Runtime.Pager.off, p.settings.pager);
@@ -2354,7 +2369,7 @@ test "Pager is a setting of the root ctl: pardes by default, off taken, anything
test "a bad setting value is quoted, so two different bad values log as two records, never one counted twice" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
_ = wr(p, root_ctl, "Verbose maybe\n");
_ = wr(p, root_ctl, "Verbose nope\n");
try testing.expect(th.logHas(p, "takes on, off \"maybe\"\n"));
@@ -2480,14 +2495,14 @@ test "look and exec read back what the last command touched, a ctl write's too"
const made = p.panes[p.active].?.serial;
try testing.expect(made != serial);
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes);
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
// A ctl write that makes nothing names the pane it ran at.
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Verbose off\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Verbose off\n").reply.status);
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes);
// Closed, it is no pane to go to: a fresh read of look is empty.
try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .ctl), "Del\n").reply.status);
try testing.expect(p.paneBySerial(made) == null);
- try testing.expectEqualStrings("", rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
}
test "a builtin's Verbose announcement is logged only when it succeeds, its failure said now or by the host later" {
@@ -2554,7 +2569,7 @@ test "an error's words give the errno a mount reads: EINVAL for what is malforme
test "DumpConfig's whole report writes back to the root ctl, line by line, with no error" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpConfig\n").reply.status);
const report = for (p.panes) |slot| {
const pane = slot orelse continue;
@@ -2580,7 +2595,7 @@ test "a Restore asks again for the ThemeFile the dump names, as a /ctl write of
const p = try withFile(gpa, "x\n");
defer p.deinit();
const good = "/tmp/pardes-restored-theme.zon";
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "ThemeFile " ++ good ++ "\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "ThemeFile " ++ good ++ "\n");
var custom = pardes.themes[0];
custom.name = "restored";
var encoded: std.Io.Writer.Allocating = .init(gpa);
@@ -2608,7 +2623,7 @@ test "a ThemeFile that fails to load changes nothing: the root ctl still names t
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
// None loaded: a failed one leaves Theme as it was.
_ = wr(p, root_ctl, "ThemeFile /tmp/pardes-no-such-theme.zon\n");
pardes.colors.failThemeFile(p, p.theme_file_generation, error.FileNotFound);
@@ -2634,7 +2649,7 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path,
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const path = "/tmp/pardes-mine-theme.zon";
try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status);
var custom = pardes.themes[0];
@@ -2668,7 +2683,7 @@ test "Joincol with no column to the right and Theme with no such theme say so" {
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const joined = wr(p, root_ctl, "Joincol\n");
try testing.expectEqual(tree.Status.err, joined.reply.status);
try testing.expectStringStartsWith(joined.reply.ename, "Joincol: no column to the right");
@@ -2717,10 +2732,10 @@ test "a look after Newcol fills the empty column the keyboard is on" {
var line: [4200]u8 = undefined;
// Newcol makes an empty column and gives its tag the keyboard; no pane
// has it, so focus reads empty.
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n").reply.status);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status);
try testing.expectEqual(@as(usize, 0), p.col_n[p.ncol - 1]);
- try testing.expectEqualStrings("", rd(p, @intFromEnum(tree.TopFile.focus), 0, 64).bytes);
- try testing.expectEqual(tree.Status.ok, wr(p, @intFromEnum(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status);
+ try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.focus), 0, 64).bytes);
+ try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.look), try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{at})).reply.status);
try testing.expectEqual(@as(usize, 1), p.col_n[p.ncol - 1]);
try testing.expectEqual(p.active, p.col_panes[p.ncol - 1][0]);
}
@@ -2793,7 +2808,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line_buf: [4200]u8 = undefined;
const line = try std.fmt.bufPrint(&line_buf, "Restore {s}/notes.txt\n", .{dir});
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, line);
try testing.expectEqual(E.IO, refused.errno());
try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: line 1: ") != null);
@@ -2813,7 +2828,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
if (!builtins.capabilities.lift) {
try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename);
try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename);
@@ -2838,7 +2853,7 @@ test "a setting this frontend cannot show says GUI-only, and DumpDir reads back
test "Shell refuses a path that is no executable, and bare it goes back to the default" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, "Shell /nonexistent/zzsh\n");
try testing.expectEqual(Status.err, refused.reply.status);
try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "Shell: shell \"/nonexistent/zzsh\" not found") != null);
@@ -2861,9 +2876,9 @@ test "a builtin that fails a ctl write logs only its err, so the same failure ag
defer p.deinit();
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
- const ctl_node = @intFromEnum(tree.TopFile.ctl);
+ const ctl_node = @backingInt(tree.TopFile.ctl);
for (0..3) |_| try testing.expectEqual(Status.err, wr(p, ctl_node, "Unmount zzz\n").reply.status);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
try testing.expect(std.mem.endsWith(u8, text, "err - ctl: Unmount: no such mount zzz (x3)\n"));
@@ -2874,7 +2889,7 @@ test "a builtin that fails a ctl write logs only its err, so the same failure ag
test "an exec line over the command limit fails the write and says the limit; a builtin's may be longer" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const long = "echo " ++ "y" ** pardes.exec.command_max ++ "\n";
+ const long = "echo " ++ &@as([pardes.exec.command_max]u8, @splat('y')) ++ "\n";
const refused = wr(p, root_exec, long);
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectEqualStrings(e_too_long, refused.reply.ename);
@@ -2882,7 +2897,7 @@ test "an exec line over the command limit fails the write and says the limit; a
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: a command line is at most 1024 bytes", .{serialOf(p)})));
try testing.expectEqualStrings(e_control, wr(p, root_exec, "echo a\x01b\n").reply.ename);
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: it holds", .{serialOf(p)})));
- try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ "z" ** 1100 ++ "\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n").reply.status);
}
test "Edit's p and = never fail for want of room for +Errors: the text is logged instead" {
@@ -2901,7 +2916,7 @@ test "Edit's p and = never fail for want of room for +Errors: the text is logged
test "size sets the screen of a session no frontend is attached to, and only of one" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "size 120 40\n").errno()); // a frontend's
p.unattended = true;
try testing.expectEqual(Status.ok, wr(p, root_ctl, "size 120 40\n").reply.status);
@@ -2923,7 +2938,7 @@ test "size sets the screen of a session no frontend is attached to, and only of
test "Mount dials its peer and fails, mounting nothing, when none answers; a look through a peer gone says dial failed" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
const dead = "/tmp/pardes-test-no-such-peer.sock";
// A socket path not there is said so; one there that does not answer
// (a directory here) is a dial that failed.
@@ -2941,7 +2956,7 @@ test "Mount dials its peer and fails, mounting nothing, when none answers; a loo
try testing.expectEqualStrings("get: /n/away/f.txt: dial failed: no answer", got.reply.ename);
// Mounted when it answered, gone since: a look through it says so.
try p.fs.mounts.append(p.gpa, .{ .name = try p.gpa.dupe(u8, "gone"), .dial = try p.gpa.dupe(u8, dead) });
- const looked = wr(p, @intFromEnum(tree.TopFile.look), "/n/gone/f.txt\n");
+ const looked = wr(p, @backingInt(tree.TopFile.look), "/n/gone/f.txt\n");
try testing.expect(looked.errno() != 0);
try testing.expect(th.logHas(p, "look: /n/gone/f.txt: dial failed: no answer"));
}
@@ -2991,7 +3006,7 @@ test "Tty in a directory that is not there fails and makes no pane; a shell that
test "a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @intFromEnum(tree.TopFile.tagexec) }) |node| {
+ for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @backingInt(tree.TopFile.tagexec) }) |node| {
const refused = wr(p, node, "Mount\n");
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectEqualStrings("wrong #args in control message \"Mount\"", refused.reply.ename);
@@ -3055,7 +3070,7 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir
test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const refused = wr(p, @intFromEnum(tree.TopFile.ctl), "Unmount nothere\n");
+ const refused = wr(p, @backingInt(tree.TopFile.ctl), "Unmount nothere\n");
try testing.expectEqual(E.NOENT, refused.errno());
try testing.expectStringStartsWith(refused.reply.ename, "Unmount: no such mount nothere");
}
@@ -3092,7 +3107,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it
while (p.nextEffect()) |_| {}
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.look), "/tmp\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.look), "/tmp\n").reply.status);
var typed_into = false;
while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) {
typed_into = true;
@@ -3322,7 +3337,7 @@ test "+Unsaved drops a pane once it has closed" {
const b = try th.newPane(p);
_ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n");
_ = wr(p, Node.of(b, .body), "edited\n");
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status);
var listed: ?*pardes.Pane = null;
for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) {
@@ -3403,7 +3418,7 @@ test "with no pane at all, the root look opens its file and the root exec runs i
}
};
try Empty.all(p);
- const look_node = @intFromEnum(tree.TopFile.look);
+ const look_node = @backingInt(tree.TopFile.look);
try testing.expectEqual(Status.ok, wr(p, look_node, "f.txt\n").reply.status);
var want: [4200]u8 = undefined;
const path = try std.fmt.bufPrint(&want, "{s}/f.txt", .{session});
@@ -3418,7 +3433,7 @@ test "with no pane at all, the root look opens its file and the root exec runs i
try testing.expectEqual(@as(usize, 0), scratches);
try Empty.all(p);
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.exec), "echo hi\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.exec), "echo hi\n").reply.status);
const made = p.panes[p.anyPane().?].?;
try testing.expect(made.command != null);
try testing.expectEqualStrings(session, made.cwdSlice());
@@ -3439,7 +3454,7 @@ test "a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" {
test "Kill with a name and nothing running says so and does not fail, as bare Kill does" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Kill zzz\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Kill zzz\n");
try testing.expectEqual(Status.ok, r.reply.status);
try testing.expect(th.logHas(p, "Kill: nothing running"));
}
@@ -3505,7 +3520,7 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as
p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } });
while (p.nextEffect()) |_| {}
var digits: [16]u8 = undefined;
- const moved = wr(p, @intFromEnum(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
+ const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
try testing.expectEqual(Status.ok, moved.reply.status);
try testing.expectEqual(shells[1], p.active);
try testing.expectEqualStrings("\x1b[O\x1b[I", moved.pty_buf[0..moved.pty_len]);
@@ -3522,7 +3537,7 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r
var buf: [4096]u8 = undefined;
const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)];
try testing.expect(p.settings.dump_dir.set(dir));
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "Restore x.dump.zon\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Restore x.dump.zon\n").reply.status);
var want: [4200]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{s}/x.dump.zon", .{dir}), p.restore_req.?);
}
@@ -3532,11 +3547,11 @@ test "a line starting with # runs as nothing at an exec or a ctl, silently" {
defer p.deinit();
const serial = serialOf(p);
// The setup's own announcements are made by the first write's update.
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "# settle\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "# settle\n");
const before = p.next_serial;
const log_before = try pardes.ctlfs.events.freezeLog(p);
defer p.gpa.free(log_before.bytes);
- for ([_]u64{ @intFromEnum(tree.TopFile.exec), Node.of(serial, .exec), @intFromEnum(tree.TopFile.ctl), Node.of(serial, .ctl), Node.ofCol(layout.columnSerial(p, 0), .ctl) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec), @backingInt(tree.TopFile.ctl), Node.of(serial, .ctl), Node.ofCol(layout.columnSerial(p, 0), .ctl) }) |node| {
try testing.expectEqual(Status.ok, wr(p, node, "# Platform: tty\n # indented too\n").reply.status);
}
try testing.expectEqual(before, p.next_serial);
@@ -3560,7 +3575,7 @@ test "a builtin that takes no argument, written with one to an exec, is refused
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- for ([_]u64{ @intFromEnum(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
+ for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| {
const r = wr(p, node, line);
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectStringStartsWith(r.reply.ename, "wrong #args in control message");
@@ -3666,7 +3681,7 @@ test "every EINVAL a write gets says why, in its err record too; DEL is a contro
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log, .omode = 2 }).reply.handle;
const Case = struct { node: u64, data: []const u8, words: []const u8, handle: u32 = 0 };
for ([_]Case{
@@ -3689,19 +3704,19 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt
defer p.deinit();
const term = p.paneBySerial(serialOf(p)).?;
p.setCwd(term, "/tmp/two\nlines\x07\x7f\xc2\x85\xff");
- const index = rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes;
+ const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
// Each byte as itself, so the name decodes to what it is.
try testing.expect(std.mem.indexOf(u8, index, "/tmp/two\\nlines\\x07\\x7f\\xc2\\x85\\xff ") != null);
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, "\n"));
try testing.expect(index.len > 0);
- try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(tree.TopFile.index) }).reply.attr.size);
+ try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(tree.TopFile.index) }).reply.attr.size);
// Its tag never carries the raw newline either.
const tag = rd(p, Node.of(serialOf(p), .tag), 0, 4096).bytes;
try testing.expect(std.mem.indexOf(u8, tag, "/tmp/two\\nlines") != null);
// A backslash of the name's own is doubled: `\n` written in a name
// reads back unlike a newline.
p.setCwd(term, "/tmp/back\\nslash");
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null);
}
test "a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" {
@@ -3752,7 +3767,7 @@ test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENO
test "a tag write refuses NUL and the other control characters" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- for ([_]u64{ @intFromEnum(tree.TopFile.tag), tree.Node.ofCol(pardes.layout.columnSerial(p, 0), .tag), Node.of(serialOf(p), .tag) }) |node| {
+ for ([_]u64{ @backingInt(tree.TopFile.tag), tree.Node.ofCol(pardes.layout.columnSerial(p, 0), .tag), Node.of(serialOf(p), .tag) }) |node| {
const refused = wr(p, node, " a\x00b");
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectStringStartsWith(refused.reply.ename, "invalid tag text");
@@ -3801,7 +3816,7 @@ test "a column takes panes until their documented minimums fill it, not until no
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const new = @intFromEnum(tree.TopFile.new);
+ const new = @backingInt(tree.TopFile.new);
while (call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status == .ok) p.sync();
p.sync();
const avail = p.screen_h - (p.topBarHeight() + p.columnBarHeight());
@@ -3899,18 +3914,18 @@ test "a closed file is found again: Recent and /recent list it closed, a look at
const opened = p.active;
try testing.expectEqualStrings(a, p.panes[opened].?.file.?.path);
var want: [4300]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{a})) != null);
// Another file, so the jumplist has somewhere to come back from.
try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir})).reply.status);
p.sync();
try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[opened].?.serial, .ctl), "Del\n").reply.status);
p.sync();
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "closed {s}\n", .{a})) != null);
// Recent lists it, closed, at its dot; a look at the row opens it there.
try testing.expectEqual(Status.ok, wr(p, root_exec, "Recent\n").reply.status);
const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
const at = std.mem.indexOf(u8, rows.file.?.content, try std.fmt.bufPrint(&want, "{s}:3:", .{a})).?;
- const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
+ const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
try testing.expect(std.mem.endsWith(u8, row, " (closed)"));
try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), try std.fmt.bufPrint(&line, "{s}\n", .{row[0 .. row.len - " (closed)".len]})).reply.status);
p.sync();
@@ -3998,8 +4013,8 @@ test "Back and Forward written to exec keep to the focused file, and JumpScope a
defer p.deinit();
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "row\n" ** 100 });
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "row\n" ** 100 });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))) });
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line: [4200]u8 = undefined;
@@ -4031,8 +4046,8 @@ test "Back and Forward written to exec keep to the focused file, and JumpScope a
.{ .word = "Forward", .file = "/b.txt", .line = 80 },
.{ .word = "Forward", .file = "/a.txt", .line = 80 },
});
- try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.ctl), "JumpScope all\n").reply.status);
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.ctl), 0, 8192).bytes, "JumpScope all\n") != null);
+ try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "JumpScope all\n").reply.status);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.ctl), 0, 8192).bytes, "JumpScope all\n") != null);
try walk(p, &.{
.{ .word = "Back", .file = "/b.txt", .line = 80 },
.{ .word = "Back", .file = "/a.txt", .line = 40 },
@@ -4088,14 +4103,14 @@ test "a new file saved shows in /recent, open, while it is" {
try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Save\n").reply.status);
p.perform(.{ .save_file = .{ .pane = @intCast(p.paneBySerial(made).?) } });
var want: [4300]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null);
+ try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null);
}
test "/recent shows a name as /index does, a newline in it escaped" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.recent.opened(p.recentGpa(), "/tmp/a\nb\\c");
- const text = rd(p, @intFromEnum(tree.TopFile.recent), 0, 8192).bytes;
+ const text = rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes;
try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\\\\c\n") != null);
}
@@ -4149,11 +4164,11 @@ test "a remembered place is clamped to the file as it is now, its selection's tw
_ = wr(p, root_exec, "Recent\n");
const rows = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
const at = std.mem.indexOf(u8, rows.file.?.content, "c.txt:").?;
- const row = rows.file.?.content[at .. std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
+ const row = rows.file.?.content[at..std.mem.indexOfScalarPos(u8, rows.file.?.content, at, '\n').?];
// Both ends are in the row, a range.
try testing.expect(std.mem.indexOfScalar(u8, row, '-') != null);
var full: [4400]u8 = undefined;
- const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0 .. std.mem.indexOfScalar(u8, row, ' ').?] });
+ const loc = try std.fmt.bufPrint(&full, "{s}/{s}\n", .{ dir, row[0..std.mem.indexOfScalar(u8, row, ' ').?] });
// A look at it opens the file, never a miss, clamped to its last line.
try testing.expectEqual(Status.ok, wr(p, Node.of(rows.serial, .look), loc).reply.status);
p.sync();
@@ -4177,8 +4192,8 @@ test "size is monotonic: growing is never refused, and a size once taken is take
defer p.deinit();
while (p.nextEffect()) |_| {}
p.unattended = true;
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
- const new = @intFromEnum(tree.TopFile.new);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
+ const new = @backingInt(tree.TopFile.new);
// The dogfood's repro: Newcol, three pane/new, a Tty, then pane/new
// until a column has no room (ENOSPC).
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Newcol\n").reply.status);
@@ -4269,7 +4284,7 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge
var want: [32]u8 = undefined;
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "changed {d}\n", .{serial})));
// Exit and get still ask about the edits.
- try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status);
+ try testing.expectEqual(Status.err, wr(p, @backingInt(tree.TopFile.ctl), "Exit\n").reply.status);
try testing.expect(std.mem.indexOf(u8, wr(p, Node.of(serial, .ctl), "get\n").reply.ename, "Modified") != null);
// Save warns once before overwriting the newer file, then writes.
const first = wr(p, Node.of(serial, .ctl), "Save\n");
@@ -4314,7 +4329,7 @@ test "a looked word is found in its own pane, next place after the dot, wrapping
test "every word's /commands description is its own doc comment's first sentence, no citation" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const listed = rd(p, @intFromEnum(tree.TopFile.commands), 0, 1 << 16).bytes;
+ const listed = rd(p, @backingInt(tree.TopFile.commands), 0, 1 << 16).bytes;
for ([_][]const u8{
"\nRepl arg pane -- Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run.\n",
"\nJoincol root -- Fold the active pane's column into the one on its right, keeping its panes.\n",
@@ -4340,7 +4355,7 @@ test "every word's /commands description is its own doc comment's first sentence
undescribed += 1;
continue;
};
- const word = line[0 .. std.mem.indexOfScalar(u8, line, ' ').?];
+ const word = line[0..std.mem.indexOfScalar(u8, line, ' ').?];
if (config.Runtime.find(word)) |setting| {
try testing.expect(std.mem.endsWith(u8, line, setting.doc));
continue;
@@ -4360,7 +4375,7 @@ test "Newcol at the column cap fails the write and says the cap" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.update(.{ .resize = .{ .cols = 4000, .rows = 30 } });
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
while (p.ncol < pardes.MAX_COLS) {
// From the widest column's tag, so no column gets too narrow first.
p.sync();
@@ -4389,7 +4404,7 @@ test "Save on a terminal asked over 9P is an ask in the log, answered with a pat
try testing.expect(p.panes[id].?.prompt == .save);
// Again: the one open stands, one ask in the log.
_ = wr(p, Node.of(serial, .tagexec), "Save\n");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes, "save path\n"));
_ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
@@ -4415,7 +4430,7 @@ test "get names the path it could not read, logs the edits it threw away, and a
pardes.panes.File.deleted(p, 0);
pardes.panes.File.deleted(p, 0);
var rec: [32]u8 = undefined;
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(@as(usize, 1), std.mem.count(u8, call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes, try std.fmt.bufPrint(&rec, "changed {d} deleted\n", .{serial})));
_ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
@@ -4427,12 +4442,12 @@ test "a builtin that fails through exec, tagexec or a column's exec fails the wr
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
const serial = serialOf(p);
- for ([_]u64{ root_exec, Node.of(serial, .exec), @intFromEnum(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| {
+ for ([_]u64{ root_exec, Node.of(serial, .exec), @backingInt(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| {
const failed = wr(p, node, "Unmount zzz\n");
try testing.expectEqual(Status.err, failed.reply.status);
try testing.expect(std.mem.indexOf(u8, failed.reply.ename, "Unmount: no such mount zzz") != null);
}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
try testing.expect(std.mem.indexOf(u8, text, "msg ") == null);
@@ -4444,11 +4459,11 @@ test "a builtin that fails through exec, tagexec or a column's exec fails the wr
// A control character is refused with its reason.
try testing.expectEqualStrings(e_control, wr(p, root_exec, "Msg a\x01b\n").reply.ename);
// A look miss: one err, no msg.
- _ = wr(p, @intFromEnum(tree.TopFile.look), "zzqqnotthere\n");
+ _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\""));
try testing.expect(!th.logHas(p, "msg 1 Look: no match"));
// The same miss again is that record counted, as any repeated err is.
- _ = wr(p, @intFromEnum(tree.TopFile.look), "zzqqnotthere\n");
+ _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n");
try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\" (x2)\n"));
}
@@ -4469,7 +4484,7 @@ test "@p<serial>:<address> takes any sam address; a miss and an unknown serial a
const p = try withFile(testing.allocator, "foo x foo y\nbar\n");
defer p.deinit();
const serial = serialOf(p);
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
const dot = Node.of(serial, .dot);
const Case = struct { addr: []const u8, want: []const u8 };
for ([_]Case{
@@ -4530,7 +4545,7 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select
const id = p.paneBySerial(serial).?;
p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one\r\ntwo MARK three\r\n" } });
const pane = p.panes[id].?;
- const root = @intFromEnum(tree.TopFile.look);
+ const root = @backingInt(tree.TopFile.look);
var line: [64]u8 = undefined;
try testing.expectEqual(Status.ok, wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:0/MARK/\n", .{serial})).reply.status);
try testing.expectEqual(@as(i32, 1), pane.body.cur_row);
@@ -4562,7 +4577,7 @@ test "a bad command inside an Edit block written whole is named, not the } after
test "a refused Delcol changes nothing: no pane, no focus" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Newcol\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n");
const made = try th.newPane(p);
_ = wr(p, Node.of(made, .name), "/tmp/pardes-delcol-refused.txt\n");
_ = wr(p, Node.of(made, .body), "edit\n");
@@ -4585,8 +4600,8 @@ test "a refused Delcol changes nothing: no pane, no focus" {
test "pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const pager = @intFromEnum(tree.TopFile.pager);
- const exec = @intFromEnum(tree.TopFile.exec);
+ const pager = @backingInt(tree.TopFile.pager);
+ const exec = @backingInt(tree.TopFile.exec);
const asked = call(p, .{ .tag = 1, .op = .open, .node = pager, .omode = 2 }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = pager, .handle = asked, .data = "/tmp\n" }).reply.status);
const paged = for (p.panes) |slot| {
@@ -4608,10 +4623,15 @@ test "pager answers its +Pager on the open that asked, whatever another client e
try testing.expectEqual(E.INVAL, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = refused, .data = "relative\n" }).errno());
try testing.expectEqualStrings("", call(p, .{ .tag = 9, .op = .read, .node = pager, .handle = refused, .size = 64 }).bytes);
_ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = refused, .opened = true });
- // Resolved: `/tmp/../tmp/.` is /tmp's +Pager, the one made above.
+ // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the
+ // one made above, which keeps its page.
const resolved = call(p, .{ .tag = 11, .op = .open, .node = pager, .omode = 2 }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 12, .op = .write, .node = pager, .handle = resolved, .data = "/tmp/../tmp/.\n" }).reply.status);
- try testing.expectEqualStrings(want, call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes);
+ const second = call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes;
+ try testing.expect(!std.mem.eql(u8, want, second));
+ const second_pane = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trim(u8, second, "\n"), 10)).?].?;
+ try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path);
+ try testing.expect(p.paneBySerial(paged) != null);
_ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true });
// One that may not be written is refused, permission denied.
try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno());
@@ -4634,7 +4654,7 @@ test "pager answers its +Pager on the open that asked, whatever another client e
test "what a /pager open writes after its directory is the text: plain in the body, its colours the pane's, clean, in by the read" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const pager = @intFromEnum(tree.TopFile.pager);
+ const pager = @backingInt(tree.TopFile.pager);
const asked = call(p, .{ .tag = 1, .op = .open, .node = pager, .omode = 2 }).reply.handle;
// The directory and the text's start in one write, escapes and all, a
// second line no directory; the rest in writes after it.
@@ -4668,15 +4688,24 @@ test "what a /pager open writes after its directory is the text: plain in the bo
// PagerColor off, and an open closed with no read: the same text, plain,
// in at the editor's next step (a close through a mount never waits).
p.settings.pager_color = false;
+ const kept = try testing.allocator.dupe(u8, f.content);
+ defer testing.allocator.free(kept);
const shut = call(p, .{ .tag = 7, .op = .open, .node = pager, .omode = 1 }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = shut, .data = "/tmp\n" }).reply.status);
try testing.expectEqual(Status.ok, call(p, .{ .tag = 9, .op = .write, .node = pager, .handle = shut, .data = "\x1b[1;32mgreen\x1b[m\n" }).reply.status);
_ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = shut, .opened = true });
- try testing.expectEqualStrings("", f.content);
+ // A new +Pager: the first keeps its page.
+ try testing.expectEqualStrings(kept, f.content);
+ const next = for (p.panes) |slot| {
+ const other = slot orelse continue;
+ if (other == pn) continue;
+ if (other.file) |*of| if (std.mem.eql(u8, of.path, "/tmp/+Pager")) break of;
+ } else return error.NoPager;
+ try testing.expectEqualStrings("", next.content);
fillClosedPagers(p);
- try testing.expectEqualStrings("green\n", f.content);
- try testing.expectEqual(@as(usize, 0), f.pager_spans.len);
- try testing.expectEqual(f.revision, f.saved_revision);
+ try testing.expectEqualStrings("green\n", next.content);
+ try testing.expectEqual(@as(usize, 0), next.pager_spans.len);
+ try testing.expectEqual(next.revision, next.saved_revision);
}
test "a command pane an exec open was answered is leased to it while it stays open: another client's command gets a pane of its own" {
@@ -4784,7 +4813,7 @@ test "a second LookWord list look in a directory refills its +Search rather than
const path = try std.fmt.bufPrint(&path_buf, "{s}/words.txt", .{dir});
const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 });
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "LookWord list\n");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "LookWord list\n");
pardes.look.lookAt(p, 0, "alpha");
pardes.look.lookAt(p, 0, "beta");
var searches: usize = 0;
@@ -4958,7 +4987,7 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const root_ctl = @intFromEnum(tree.TopFile.ctl);
+ const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir dumps\n").errno());
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno());
try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpDir /tmp/pardes-dumps-test\n").reply.status);
@@ -4970,7 +4999,7 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
test "a Mount dial with a network it does not know is a bad dial address, EINVAL" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer nowhere!x\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer nowhere!x\n");
try testing.expectEqual(E.INVAL, r.errno());
try testing.expectStringStartsWith(r.reply.ename, "Mount: bad dial address: nowhere!x");
}
@@ -5028,11 +5057,11 @@ test "a Mount of a socket path that is not there says no such socket, ENOENT" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const r = wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer unix!/tmp/pardes-surely-no-socket\n");
+ const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer unix!/tmp/pardes-surely-no-socket\n");
try testing.expectEqual(E.NOENT, r.errno());
try testing.expect(std.mem.indexOf(u8, r.reply.ename, "no such socket") != null);
try testing.expectEqual(@as(usize, 0), p.fs.mounts.items.len);
- try testing.expectEqual(E.INVAL, wr(p, @intFromEnum(tree.TopFile.ctl), "Mount peer rel/x.sock\n").errno());
+ try testing.expectEqual(E.INVAL, wr(p, @backingInt(tree.TopFile.ctl), "Mount peer rel/x.sock\n").errno());
}
test "the init file reads past a BOM, and every line it fails is a notice and an err, never silent" {
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 3910ac05..78788c3c 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -542,7 +542,7 @@ pub const Action = enum(u8) {
tag_exec = 'x',
pub fn char(a: Action) u8 {
- return @intFromEnum(a);
+ return @backingInt(a);
}
pub fn fromChar(c: u8) ?Action {
@@ -550,7 +550,7 @@ pub const Action = enum(u8) {
}
pub fn onTag(a: Action) bool {
- return @intFromEnum(a) >= 'a';
+ return @backingInt(a) >= 'a';
}
};
@@ -889,7 +889,7 @@ test "a stream read at an offset inside its last answer gets the rest of it agai
defer p.deinit();
p.update(.tick);
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen: u64 = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 8192 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
@@ -897,7 +897,7 @@ test "a stream read at an offset inside its last answer gets the rest of it agai
notePath(p, "dump", "/b");
const Read = struct {
fn at(pp: *Pardes, h: u32, off: u64) []const u8 {
- return call(pp, .{ .tag = 4, .op = .read, .node = @intFromEnum(tree.TopFile.log), .handle = h, .off = off, .size = 128 }).bytes;
+ return call(pp, .{ .tag = 4, .op = .read, .node = @backingInt(tree.TopFile.log), .handle = h, .off = off, .size = 128 }).bytes;
}
};
try testing.expectEqualStrings("dump /a\n", Read.at(p, f, frozen));
@@ -938,7 +938,7 @@ test "event records are acme's bytes, one per read, and .again when empty" {
try testing.expectEqualStrings("ML0 ", rd(p, event, 0, 4).bytes);
try testing.expectEqualStrings("3 4 3 one\n", rd(p, event, 0, 4096).bytes);
- const big = "z" ** max_record_text;
+ const big = &@as([max_record_text]u8, @splat('z'));
_ = noteAction(p, 0, .body_exec, 0, max_record_text, 0, big);
try testing.expectEqualStrings("MX0 256 0 0 \n", rd(p, event, 0, 4096).bytes);
@@ -1130,7 +1130,7 @@ test "writing an event record back performs the action it names" {
// A look written back sets what look reads back.
_ = wr(p, event, "FL0 3\n");
var want_serial: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want_serial, "{d}\n", .{serial}), rd(p, @intFromEnum(tree.TopFile.look), 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want_serial, "{d}\n", .{serial}), rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes);
// Well formed but past the text: said so, not "bad event syntax".
try testing.expectEqualStrings("range past end of body", wr(p, event, "MX0 999\n").reply.ename);
@@ -1144,7 +1144,7 @@ test "the log records whether or not anyone reads, and an open that follows wait
const gpa = testing.allocator;
const p = try withFile(gpa, "logged\n");
defer p.deinit();
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
var expected: [4200]u8 = undefined;
// Nobody holds /log open, and the pane is recorded anyway.
@@ -1256,21 +1256,21 @@ test "a refused or failed write is an err record in the log, saying which file a
p.update(.tick); // the pane's `new` is logged before the log is opened
while (p.nextEffect()) |_| {}
const serial = serialOf(p);
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
var want: [128]u8 = undefined;
const next = struct {
fn record(pp: *Pardes, h: u32, off: usize) []const u8 {
- return call(pp, .{ .tag = 4, .op = .read, .node = @intFromEnum(tree.TopFile.log), .handle = h, .off = off, .size = 4096 }).bytes;
+ return call(pp, .{ .tag = 4, .op = .read, .node = @backingInt(tree.TopFile.log), .handle = h, .off = off, .size = 4096 }).bytes;
}
};
_ = wr(p, Node.of(serial, .addr), "/nowhere/");
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "err {d} addr: no match for regexp\n", .{serial}), next.record(p, f, frozen));
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus");
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Bogus");
try testing.expectEqualStrings("err - ctl: unknown control message \"Bogus\"\n", next.record(p, f, frozen));
- _ = wr(p, @intFromEnum(tree.TopFile.focus), "99999");
+ _ = wr(p, @backingInt(tree.TopFile.focus), "99999");
try testing.expectEqualStrings("err - focus: no such pane\n", next.record(p, f, frozen));
// A write that succeeds says nothing.
_ = wr(p, Node.of(serial, .addr), "#0");
@@ -1373,7 +1373,7 @@ test "opens of the log share the open records, and a closed one frees its record
const gpa = testing.allocator;
const p = try withFile(gpa, "x\n");
defer p.deinit();
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
var handles: [tree.open_slots]u32 = undefined;
for (&handles) |*h| h.* = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(E.NFILE, call(p, .{ .tag = 2, .op = .open, .node = log }).errno());
@@ -1388,7 +1388,7 @@ test "opens of the log share the open records, and a closed one frees its record
test "a click in the body reports the offsets of the word it takes, so the record can be written back" {
const config = @import("../config.zig");
const gpa = testing.allocator;
- const text = "alpha qty beta\n qty\n\tqty\ndef f(qty): return qty.x\n" ++ "w" ** 100 ++ " qty\n";
+ const text = "alpha qty beta\n qty\n\tqty\ndef f(qty): return qty.x\n" ++ &@as([100]u8, @splat('w')) ++ " qty\n";
const p = try withFile(gpa, text);
defer p.deinit();
// A scratch made over 9P, clicked while another pane has the keyboard.
@@ -1447,7 +1447,7 @@ test "follow new skips what the log held and waits for what comes after" {
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
p.setMessage(0, "before the open");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = log, .handle = h, .data = "follow new\n" }).reply.status);
try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = log, .handle = h, .size = 4096 }).reply.status);
@@ -1459,9 +1459,9 @@ test "follow new skips what the log held and waits for what comes after" {
test "a long msg record is cut between words at its cap, with an ellipsis" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const long = "word " ** 60; // 300 bytes
+ const long = std.mem.asBytes(&@as([60][5]u8, @splat("word ".*))); // 300 bytes
_ = wr(p, Node.of(serialOf(p), .ctl), "Msg " ++ long ++ "\n");
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
const at = std.mem.lastIndexOf(u8, text, "msg ").?;
@@ -1485,8 +1485,8 @@ test "a record is one line of UTF-8: DEL and C1 are spaces, bytes not UTF-8 are
test "a long err record keeps its end, its middle given up to an ellipsis" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus" ++ "abcdefgh" ** 40 ++ "\n");
- const log = @intFromEnum(tree.TopFile.log);
+ _ = wr(p, @backingInt(tree.TopFile.ctl), "Bogus" ++ std.mem.asBytes(&@as([40][8]u8, @splat("abcdefgh".*))) ++ "\n");
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
const at = std.mem.lastIndexOf(u8, text, "err - ctl: ").?;
@@ -1500,7 +1500,7 @@ test "a long err record keeps its end, its middle given up to an ellipsis" {
test "two failures that agree only in what their records cut are two records, not one counted" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const long = "why " ** 80;
+ const long = std.mem.asBytes(&@as([80][4]u8, @splat("why ".*)));
p.setMessage(0, long ++ "first");
p.setMessage(0, long ++ "second");
try testing.expect(!th.logHas(p, "(x2)"));
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 3b70d62f..dc104e4b 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -1104,7 +1104,7 @@ test "index lists serial kind dirty flag and name, and stats 0, a view generated
const p = try withFile(gpa, "hello\nthere\n");
defer p.deinit();
const pane = p.panes[0].?;
- const index = @intFromEnum(tree.TopFile.index);
+ const index = @backingInt(tree.TopFile.index);
const a = rd(p, index, 0, 4096);
try testing.expectEqual(Status.ok, a.reply.status);
@@ -1138,7 +1138,7 @@ test "a terminal is listed as term with its directory as name" {
var want: [64]u8 = undefined;
try testing.expect(std.mem.indexOf(
u8,
- rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes,
+ rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes,
try std.fmt.bufPrint(&want, "{d} term 0 /work/dir {d}\n", .{ pane.serial, columnOf(p, 0) }),
) != null);
try testing.expectEqualStrings("/work/dir\n", rd(p, Node.of(pane.serial, .name), 0, 4096).bytes);
@@ -1427,7 +1427,7 @@ test "a tag write past the limit is refused whole, naming the limit" {
const tag = Node.of(serialOf(p), .tag);
const before = try testing.allocator.dupe(u8, rd(p, tag, 0, 1 << 16).bytes);
defer testing.allocator.free(before);
- const big = "w" ** (limits.max_tag_tail + 10);
+ const big = &@as([limits.max_tag_tail + 10]u8, @splat('w'));
const r = wr(p, tag, big);
try testing.expectEqual(E.NOSPC, r.errno());
// `no space` is what 9ns maps to ENOSPC, so a shell through a mount
@@ -1549,20 +1549,21 @@ test "a name with a component over 255 bytes is refused, and a long path's faile
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const serial = serialOf(p);
- const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ "c" ** 256 ++ "/f.txt\n");
+ const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n");
try testing.expectEqual(E.INVAL, refused.errno());
try testing.expectEqualStrings("invalid file name: a component over 255 bytes", refused.reply.ename);
- try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ "c" ** 255 ++ "\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([255]u8, @splat('c')) ++ "\n").reply.status);
// Held with no newline, it is refused by that write, not at the close.
const held = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .name), .omode = 1 }).reply.handle;
- try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ "e" ** 256 }).errno());
+ try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ &@as([256]u8, @splat('e')) }).errno());
_ = call(p, .{ .tag = 3, .op = .release, .node = Node.of(serial, .name), .handle = held, .opened = true });
try testing.expectEqual(@as(usize, 0), p.fs.closed_lines.items.len);
// A Save of a 3000-byte path the host refuses: the waiting write's
// reason is at the end, the path giving up its middle.
// (Under /tmp: under / a user's Save is refused permission, not
// missing.)
- const long = "/tmp/nonexistent-pardes-root/" ++ ("d" ** 200 ++ "/") ** 15 ++ "f.txt";
+ const segment = &@as([200]u8, @splat('d')) ++ "/";
+ const long = "/tmp/nonexistent-pardes-root/" ++ std.mem.asBytes(&@as([15][201]u8, @splat(segment.*))) ++ "f.txt";
const id = p.paneBySerial(serial).?;
try nameBuffer(p, id, long, false);
p.fs.late_failure_len = 0;
@@ -1750,8 +1751,8 @@ test "name refreshes cached syntax for unchanged contents" {
try testing.expectEqual(Status.ok, wr(p, Node.of(pane.serial, .name), "renamed.zig\n").reply.status);
panes.File.refreshHighlights(p);
try testing.expect(pane.file.?.highlights.len >= 2);
- try testing.expectEqual(@intFromEnum(pardes.syntax.Syn.keyword), pane.file.?.highlights[0]);
- try testing.expectEqual(@intFromEnum(pardes.syntax.Syn.keyword), pane.file.?.highlights[1]);
+ try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[0]);
+ try testing.expectEqual(@backingInt(pardes.syntax.Syn.keyword), pane.file.?.highlights[1]);
try testing.expectEqualStrings("fn check() void {}\n", pane.file.?.content);
}
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index c58cf676..d80f7175 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -893,7 +893,7 @@ test "a shell that exits under a run answers its status, and the log says exit b
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
p.update(.{ .output = .{ .pane = 0, .bytes = prompt } });
while (p.nextEffect()) |_| {}
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" });
@@ -984,7 +984,6 @@ test "a run's answer says cut when its output's start is gone, and reads a bound
var got = sh.answered(p, node, h, into);
try testing.expectEqualStrings("exit 0\nafter\n", got);
-
// A resize between its start and end reflows the pins with the text.
h = sh.send(p, node);
sh.put(p, c ++ "one\r\ntwo\r\n");
@@ -1044,12 +1043,12 @@ test "a run's answer says cut when its output's start is gone, and reads a bound
const q = try withTerm(gpa);
defer q.deinit();
const kept = q.panes[0].?;
- kept.terminal.?.vt.screens.get(.primary).?.pages.explicit_max_size = 1;
+ kept.terminal.?.vt.screens.get(.primary).?.pages.limits.set(.bytes, 1);
const run = Node.of(serialOf(q), .pty_run);
sh.put(q, prompt);
h = sh.send(q, run);
sh.put(q, c);
- const lines = "pruned\r\n" ** 64;
+ const lines = std.mem.asBytes(&@as([64][8]u8, @splat("pruned\r\n".*)));
var fed: usize = 0;
while (!kept.terminal.?.stream.handler.out_start.?.garbage) : (fed += 1) {
if (fed == 1000) return error.TestUnexpectedResult;
@@ -1092,7 +1091,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l
_ = fields.next();
try testing.expectEqual(body_len, try std.fmt.parseInt(usize, fields.next().?, 10));
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(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" });
@@ -1146,7 +1145,7 @@ test "a run's answer longer than its room is cut, its newline kept" {
var slot: Run = .{};
const p = try th.withTerm(testing.allocator);
defer p.deinit();
- answer(p, &slot, "busy: {s} is running", .{"x" ** 200});
+ answer(p, &slot, "busy: {s} is running", .{&@as([200]u8, @splat('x'))});
try testing.expectEqual(slot.answer.len, slot.len);
try testing.expectEqual(@as(u8, '\n'), slot.answer[slot.len - 1]);
}
diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig
index b991c3e4..ba676ded 100644
--- a/src/ninep/screen.zig
+++ b/src/ninep/screen.zig
@@ -95,7 +95,7 @@ const withTerm = th.withTerm;
const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
-const screen_node = @intFromEnum(tree.TopFile.screen);
+const screen_node = @backingInt(tree.TopFile.screen);
test "listener addresses are readable canonical dials with bounded partial reads" {
const gpa = testing.allocator;
@@ -111,7 +111,7 @@ test "listener addresses are readable canonical dials with bounded partial reads
try testing.expectEqualStrings(expected, bytes);
try testing.expectError(error.ReadOnlyFilesystem, fs.write(p, path, ""));
}
- const node = @intFromEnum(tree.TopFile.listeners);
+ const node = @backingInt(tree.TopFile.listeners);
var off: usize = 0;
while (off < expected.len) {
const part = rd(p, node, off, 3);
@@ -333,7 +333,7 @@ test "a terminal's body is its logical lines: a row the terminal wrapped is join
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const pane = p.panes[0].?;
- const long = "w" ** 50 ++ "x" ** 150; // wider than the pane: it wraps
+ const long = &@as([50]u8, @splat('w')) ++ &@as([150]u8, @splat('x')); // wider than the pane: it wraps
try testing.expect(long.len > pane.cols);
p.update(.{ .output = .{ .pane = 0, .bytes = long ++ "\r\nnext" } });
while (p.nextEffect()) |_| {}
diff --git a/src/ninep/testing.zig b/src/ninep/testing.zig
index a35a9cf0..ec665130 100644
--- a/src/ninep/testing.zig
+++ b/src/ninep/testing.zig
@@ -71,7 +71,7 @@ pub fn logHas(p: *Pardes, needle: []const u8) bool {
/// How many times the log, read whole from a fresh open, holds `needle`.
pub fn logCount(p: *Pardes, needle: []const u8) usize {
- const log = @intFromEnum(tree.TopFile.log);
+ const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
defer _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
@@ -95,7 +95,7 @@ pub fn look_up(p: *Pardes, dir: u64, name: []const u8) Answer {
/// The open is what makes the pane; the handle it answers is the serial, which
/// is also what a read of that fid reports.
pub fn newPane(p: *Pardes) !u32 {
- const made = call(p, .{ .tag = 8, .op = .open, .node = @intFromEnum(tree.TopFile.new) });
+ const made = call(p, .{ .tag = 8, .op = .open, .node = @backingInt(tree.TopFile.new) });
if (made.reply.status != .ok or made.reply.handle == 0) return error.NoPane;
return made.reply.handle;
}
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 8d3c599f..59ef5ef4 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -115,7 +115,7 @@ pub fn changesPane(p: *Pardes, req: Req) bool {
return switch (req.op) {
.write => true,
.setattr => truncates(req),
- .open => req.node == @intFromEnum(TopFile.new),
+ .open => req.node == @backingInt(TopFile.new),
.release => req.remove or holdsLines(p, req) or holdsPage(p, req),
.read => holdsPage(p, req),
.lookup, .getattr, .readdir => false,
@@ -258,7 +258,7 @@ pub const TopFile = enum(u5) {
/// The files opened lately, closed ones too, a line each:
/// `open|closed <path>`, most recent first.
recent,
- /// `pardes -`'s: a directory written, its +Pager made or emptied; a
+ /// `pardes -`'s: a directory written, a new +Pager made there; a
/// read of the same open answers its serial.
pager,
@@ -279,7 +279,7 @@ pub const TopFile = enum(u5) {
}
};
-pub const root: u64 = @intFromEnum(TopFile.root);
+pub const root: u64 = @backingInt(TopFile.root);
/// Declaration order is readdir order.
pub const PaneFile = enum(u5) {
@@ -363,11 +363,11 @@ pub const Node = packed struct(u64) {
pub fn of(serial: u32, file: PaneFile) u64 {
std.debug.assert(serial != 0);
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = serial });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = serial });
}
pub fn ofCol(serial: u32, file: ColFile) u64 {
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = col_bit | @as(u59, serial) });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = col_bit | @as(u59, serial) });
}
pub fn target(node: u64) ?Target {
@@ -424,9 +424,9 @@ pub fn resolveSelf(p: *Pardes, path: []const u8) ?u64 {
// `new` is reached in /pane, where the panes it makes are.
const top = std.meta.stringToEnum(TopFile, first) orelse return sources.node(normalized);
if (top == .root or top == .new or top == .pane or parts.next() != null) return null;
- return @intFromEnum(top);
+ return @backingInt(top);
}
- const next = parts.next() orelse return @intFromEnum(TopFile.pane);
+ const next = parts.next() orelse return @backingInt(TopFile.pane);
// `new` is served on the wire but deliberately unreachable from an editor
// path: this resolves Look targets and hover previews, and a preview that
// opened `new` to see what was there would make a pane per hover.
@@ -509,7 +509,7 @@ pub fn fitErr(text: []const u8, out: []u8) []const u8 {
test "a reason past 128 bytes keeps its end: the path in it gives up its middle" {
var out: [128]u8 = undefined;
- const long = "Save /home/someone/projects/" ++ "deep/" ** 30 ++ "file.txt: no such directory";
+ const long = "Save /home/someone/projects/" ++ std.mem.asBytes(&@as([30][5]u8, @splat("deep/".*))) ++ "file.txt: no such directory";
const fit = fitErr(long, &out);
try testing.expect(fit.len <= 128);
try testing.expect(std.mem.startsWith(u8, fit, "Save /home/someone/"));
@@ -517,7 +517,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle"
try testing.expect(std.mem.indexOf(u8, fit, "…") != null);
try testing.expect(std.unicode.utf8ValidateSlice(fit));
// No path: the whole text's middle goes, the end stays.
- const words = "why " ** 40 ++ "the reason";
+ const words = std.mem.asBytes(&@as([40][4]u8, @splat("why ".*))) ++ "the reason";
try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason"));
try testing.expectEqualStrings("short", fitErr("short", &out));
// Through the tree: a look at a long ./ name not there, a miss, says
@@ -525,7 +525,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle"
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
var line: [512]u8 = undefined;
- const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{"no-such-dir/" ** 20}));
+ const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{std.mem.asBytes(&@as([20][12]u8, @splat("no-such-dir/".*)))}));
try testing.expectEqual(Status.ok, r.reply.status);
try testing.expect(th.logHas(p, "x.txt: no such file"));
}
@@ -606,7 +606,7 @@ fn attrOf(p: *Pardes, target: Target) ?Reply.Attr {
switch (target) {
.top => |f| return .{
.name = f.fileName(),
- .node = @intFromEnum(f),
+ .node = @backingInt(f),
.dir = f.dir(),
.mode = f.mode(),
.size = topSize(p, f),
@@ -695,11 +695,11 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
const parent: u64 = switch (target) {
.top => |top| if (top.dir()) root else return Reply.fail(req.tag, E.NOTDIR),
.pane => |t| switch (t.file) {
- .dir => @intFromEnum(TopFile.pane),
+ .dir => @backingInt(TopFile.pane),
.pty => Node.of(t.serial, .dir),
else => return Reply.fail(req.tag, E.NOTDIR),
},
- .col => |c| if (c.file == .dir) @intFromEnum(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
+ .col => |c| if (c.file == .dir) @backingInt(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
};
return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent });
}
@@ -709,12 +709,12 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
.root => root: {
if (std.mem.eql(u8, name, "os")) return fs.osHandle(p, .{ .tag = req.tag, .op = .getattr, .node = fs.os_root });
// `new` is reached in /pane, where the panes it makes are.
- if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @intFromEnum(t);
+ if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @backingInt(t);
if (sources.node(name)) |n| return sources.handle(p, .{ .tag = req.tag, .op = .getattr, .node = n });
return Reply.fail(req.tag, E.NOENT);
},
.pane => pane: {
- if (std.mem.eql(u8, name, new_pane)) break :pane @intFromEnum(TopFile.new);
+ if (std.mem.eql(u8, name, new_pane)) break :pane @backingInt(TopFile.new);
// A pane directory is its serial, in decimal digits and never 0.
if (name.len > 10) return Reply.fail(req.tag, E.NOENT);
for (name) |c| if (c < '0' or c > '9') return Reply.fail(req.tag, E.NOENT);
@@ -778,13 +778,13 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
// The guide, then what describes the session, then the
// files that act, then the directories.
inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(t), t.dir(), t.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName());
}
if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os");
sources.stage(p, out, "", &skip);
},
.pane => {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(TopFile.new), false, TopFile.new.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(TopFile.new), false, TopFile.new.fileName());
var last: u32 = 0;
while (nextSerialAfter(p, last)) |serial| {
last = serial;
@@ -1380,7 +1380,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for ([_]TopFile{ .index, .layout, .recent, .ctl }) |file| {
- const node = @intFromEnum(file);
+ const node = @backingInt(file);
const whole = try testing.allocator.dupe(u8, th.rd(p, node, 0, 1 << 16).bytes);
defer testing.allocator.free(whole);
const h = th.call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle;
@@ -1391,7 +1391,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
// Something changes between the chunks.
const made = try th.newPane(p);
_ = th.wr(p, Node.of(made, .name), "/tmp/pardes-frozen-listing.txt\n");
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose off\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose off\n");
while (true) {
const more = th.call(p, .{ .tag = 2, .op = .read, .node = node, .handle = h, .off = got.items.len, .size = 7 }).bytes;
if (more.len == 0) break;
@@ -1399,7 +1399,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
}
_ = th.call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
try testing.expectEqualStrings(whole, got.items);
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose on\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose on\n");
}
}
@@ -1420,7 +1420,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
} });
try testing.expect(p.look_hover_wait != null);
const body = Node.of(serialOf(p), .body);
- const screen_node = @intFromEnum(TopFile.screen);
+ const screen_node = @backingInt(TopFile.screen);
for (0..2) |phase| {
if (phase == 1) {
for (0..delay) |_| p.update(.tick);
@@ -1431,7 +1431,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
const requests = [_]Req{
.{ .tag = 1, .op = .lookup, .node = root, .data = "screen" },
.{ .tag = 1, .op = .lookup, .node = root, .data = "status" },
- .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.pane) },
+ .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.pane) },
.{ .tag = 2, .op = .getattr, .node = body },
.{ .tag = 3, .op = .open, .node = body },
.{ .tag = 4, .op = .read, .node = body, .size = 5 },
@@ -1460,14 +1460,14 @@ test "log stats 0 however much it holds, a stream as acme's generated files are"
defer p.deinit();
_ = th.wr(p, Node.of(th.serialOf(p), .exec), "Msg a record for the log\n");
try testing.expect(th.logHas(p, "a record for the log"));
- try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.log) }).reply.attr.size);
+ try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.log) }).reply.attr.size);
}
test "filesystem pane creation and truncation cancel Look hover" {
const requests = [_]Req{
// Opening `new` is what makes a pane now; walking to it makes none,
// and so must leave a pending hover alone.
- .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) },
+ .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) },
.{ .tag = 3, .op = .setattr, .node = 0, .truncate = true },
};
for (requests) |request| {
@@ -1494,17 +1494,17 @@ test "README names every file the tree serves" {
return false;
}
};
- inline for (@typeInfo(TopFile).@"enum".fields) |f| {
- const t: TopFile = @enumFromInt(f.value);
+ inline for (@typeInfo(TopFile).@"enum".field_values) |value| {
+ const t: TopFile = @fromBackingInt(@intCast(value));
if (t != .root and !words.has(t.fileName())) {
std.debug.print("README does not mention /{s}\n", .{t.fileName()});
return error.Undocumented;
}
}
- inline for (@typeInfo(PaneFile).@"enum".fields) |f| {
- const t: PaneFile = @enumFromInt(f.value);
+ inline for (@typeInfo(PaneFile).@"enum".field_values) |value| {
+ const t: PaneFile = @fromBackingInt(@intCast(value));
const ok = if (t == .dir) true else if (t.inPty() and t != .pty)
- std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @enumFromInt(f.value)).fileName()) != null
+ std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @fromBackingInt(@intCast(value))).fileName()) != null
else
words.has(t.fileName());
if (!ok) {
@@ -1532,8 +1532,8 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqualStrings(name, top[i].name);
try testing.expectEqual(i >= 16, top[i].dir);
}
- try testing.expectEqual(@intFromEnum(TopFile.pane), top[16].node);
- try testing.expectEqual(@intFromEnum(TopFile.col), top[17].node);
+ try testing.expectEqual(@backingInt(TopFile.pane), top[16].node);
+ try testing.expectEqual(@backingInt(TopFile.col), top[17].node);
try testing.expectEqual(fs.os_root, top[18].node);
var idbuf: [16]u8 = undefined;
try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null);
@@ -1556,7 +1556,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = entry.node }).reply.status);
try testing.expectEqual(before, p.next_serial);
}
- const panes_dir = rdir(p, @intFromEnum(TopFile.pane), 0);
+ const panes_dir = rdir(p, @backingInt(TopFile.pane), 0);
const listed = th.dirents(panes_dir.bytes, &buf);
var idname: [16]u8 = undefined;
const own = th.nameAt(listed, try std.fmt.bufPrint(&idname, "{d}", .{serial})).?;
@@ -1567,16 +1567,16 @@ test "readdir lists the root and a pane directory without creating anything" {
// client that stats every name a listing gave it inert.
const shown = th.nameAt(listed, new_pane).?;
try testing.expect(!shown.dir);
- try testing.expectEqual(Status.ok, look_up(p, @intFromEnum(TopFile.pane), new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, look_up(p, @backingInt(TopFile.pane), new_pane).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
const dir = rdir(p, Node.of(serial, .dir), 0);
const files = th.dirents(dir.bytes, &buf);
try testing.expectEqual(@as(usize, 18), files.len);
for ([_][]const u8{
- "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
- "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
+ "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
+ "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
}, 0..) |name, i|
try testing.expectEqualStrings(name, files[i].name);
try testing.expect(th.nameAt(files, ".") == null);
@@ -1590,7 +1590,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(before, p.next_serial);
try testing.expectEqual(E.NOTDIR, rdir(p, Node.of(serial, .body), 0).errno());
- try testing.expectEqual(E.NOTDIR, rdir(p, @intFromEnum(TopFile.index), 0).errno());
+ try testing.expectEqual(E.NOTDIR, rdir(p, @backingInt(TopFile.index), 0).errno());
}
test "lookup resolves top files, pane serials and pane files" {
@@ -1599,7 +1599,7 @@ test "lookup resolves top files, pane serials and pane files" {
defer p.deinit();
const serial = serialOf(p);
- try testing.expectEqual(@as(u64, @intFromEnum(TopFile.index)), look_up(p, root, "index").reply.attr.node);
+ try testing.expectEqual(@as(u64, @backingInt(TopFile.index)), look_up(p, root, "index").reply.attr.node);
try testing.expect(!look_up(p, root, "status").reply.attr.dir);
try testing.expectEqual(@as(u16, 0o444), look_up(p, root, "status").reply.attr.mode);
try testing.expectEqual(@as(u16, 0o666), look_up(p, root, "look").reply.attr.mode);
@@ -1609,17 +1609,17 @@ test "lookup resolves top files, pane serials and pane files" {
try testing.expectEqual(E.NOENT, look_up(p, root, "nosuchthing").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "self").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "cons").errno());
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "x").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "x").errno());
var idbuf: [16]u8 = undefined;
const serial_name = try std.fmt.bufPrint(&idbuf, "{d}", .{serial});
try testing.expectEqual(E.NOENT, look_up(p, root, serial_name).errno());
- const dir = look_up(p, @intFromEnum(TopFile.pane), serial_name);
+ const dir = look_up(p, @backingInt(TopFile.pane), serial_name);
try testing.expectEqual(Node.of(serial, .dir), dir.reply.attr.node);
try testing.expect(dir.reply.attr.dir);
try testing.expectEqualStrings(serial_name, dir.reply.attr.name);
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "99999").errno());
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "0").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "99999").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "0").errno());
const body = look_up(p, Node.of(serial, .dir), "body");
try testing.expectEqual(Node.of(serial, .body), body.reply.attr.node);
@@ -1636,19 +1636,19 @@ test "opening /pane/new makes a pane and removing one closes it" {
const p = try withFile(gpa, "first\n");
defer p.deinit();
const before = p.next_serial;
- const panes_dir = @intFromEnum(TopFile.pane);
+ const panes_dir = @backingInt(TopFile.pane);
// Browsing /pane creates nothing, and neither does walking or stat-ing
// `new` itself: only an open does. That is what lets `new` be listed at
// all, since `ls -l` stats every name a listing handed it.
try testing.expectEqual(Status.ok, rdir(p, panes_dir, 0).reply.status);
try testing.expectEqual(Status.ok, look_up(p, panes_dir, new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
// The open makes the pane and hands back its serial; the read only
// observes, so two reads of one fid answer the same pane.
- const made = call(p, .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const made = call(p, .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, made.reply.status);
try testing.expectEqual(before + 1, p.next_serial);
const serial = before + 1;
@@ -1656,7 +1656,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
var expected: [16]u8 = undefined;
const want = try std.fmt.bufPrint(&expected, "{d}\n", .{serial});
for (0..2) |_| {
- const answer = call(p, .{ .tag = 3, .op = .read, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .size = 64 });
+ const answer = call(p, .{ .tag = 3, .op = .read, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .size = 64 });
try testing.expectEqualStrings(want, answer.bytes);
}
@@ -1670,10 +1670,10 @@ test "opening /pane/new makes a pane and removing one closes it" {
// A second open is a second pane, and releasing a clone fid leaves the
// pane it made standing.
- const second = call(p, .{ .tag = 4, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const second = call(p, .{ .tag = 4, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, second.reply.status);
try testing.expect(second.reply.handle != made.reply.handle);
- _ = call(p, .{ .tag = 5, .op = .release, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .opened = true });
+ _ = call(p, .{ .tag = 5, .op = .release, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .opened = true });
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqualStrings("hi", p.panes[id].?.file.?.content);
@@ -1691,7 +1691,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
// Tremove closes the pane it names, and nothing else in the tree.
try testing.expectEqual(E.PERM, th.rmdir(p, Node.of(serial, .body)).errno());
- try testing.expectEqual(E.PERM, th.rmdir(p, @intFromEnum(TopFile.index)).errno());
+ try testing.expectEqual(E.PERM, th.rmdir(p, @backingInt(TopFile.index)).errno());
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqual(Status.ok, th.rmdir(p, Node.of(serial, .dir)).reply.status);
try testing.expect(p.paneBySerial(serial) == null);
@@ -1702,7 +1702,7 @@ test "every open that holds something is one record, named by its handle only on
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const serial = serialOf(p);
- const log = @intFromEnum(TopFile.log);
+ const log = @backingInt(TopFile.log);
const event = Node.of(serial, .event);
const run = Node.of(serial, .pty_run);
const logged = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
@@ -1731,15 +1731,15 @@ test "directories walk to their parents" {
defer p.deinit();
for ([_]struct { node: u64, parent: u64 }{
.{ .node = root, .parent = root },
- .{ .node = @intFromEnum(TopFile.pane), .parent = root },
- .{ .node = Node.of(serialOf(p), .dir), .parent = @intFromEnum(TopFile.pane) },
+ .{ .node = @backingInt(TopFile.pane), .parent = root },
+ .{ .node = Node.of(serialOf(p), .dir), .parent = @backingInt(TopFile.pane) },
.{ .node = fs.os_root, .parent = root },
}) |case| {
const result = look_up(p, case.node, "..");
try testing.expectEqual(Status.ok, result.reply.status);
try testing.expectEqual(case.parent, result.reply.attr.node);
}
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "..").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "..").errno());
try testing.expectEqual(E.NOTDIR, look_up(p, Node.of(serialOf(p), .body), "..").errno());
}
@@ -1750,10 +1750,10 @@ test "editor paths resolve to the same nodes the wire serves" {
var path: [64]u8 = undefined;
try testing.expectEqual(root, resolveSelf(p, "").?);
try testing.expectEqual(root, resolveSelf(p, "/./pane/../").?);
- try testing.expectEqual(@intFromEnum(TopFile.index), resolveSelf(p, "index").?);
- try testing.expectEqual(@intFromEnum(TopFile.status), resolveSelf(p, "status").?);
+ try testing.expectEqual(@backingInt(TopFile.index), resolveSelf(p, "index").?);
+ try testing.expectEqual(@backingInt(TopFile.status), resolveSelf(p, "status").?);
try testing.expect(resolveSelf(p, "new") == null);
- try testing.expectEqual(@intFromEnum(TopFile.pane), resolveSelf(p, "pane").?);
+ try testing.expectEqual(@backingInt(TopFile.pane), resolveSelf(p, "pane").?);
try testing.expectEqual(Node.of(serial, .dir), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}", .{serial})).?);
try testing.expectEqual(Node.of(serial, .sel), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/sel", .{serial})).?);
try testing.expect(resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/pty/ctl", .{serial})) == null);
@@ -1802,7 +1802,7 @@ test "random placements, refused or not, leave no pane under its tag and two row
const action = r.uintLessThan(u8, 8);
switch (action) {
0 => _ = th.wr(p, Node.of(at, .exec), "New\n"),
- 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }),
+ 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }),
2 => _ = th.wr(p, Node.of(at, .exec), "Newcol\n"),
3 => _ = th.wr(p, Node.of(at, .exec), "Edit =\n"),
4 => _ = th.wr(p, Node.of(at, .exec), "Tty\n"),
@@ -1825,7 +1825,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
// Tall enough that the column holds every pane at its tag and two rows,
// and wide enough that each tag, the session directory's +New, is one.
p.update(.{ .resize = .{ .cols = 400, .rows = pardes.MAX_PANES * 4 } });
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
while (p.freeSlot() != null) try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status);
var want: [64]u8 = undefined;
const said = try std.fmt.bufPrint(&want, "no space for a pane: {d} max", .{pardes.MAX_PANES});
@@ -1842,7 +1842,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line: [4200]u8 = undefined;
- const look_node = @intFromEnum(TopFile.look);
+ const look_node = @backingInt(TopFile.look);
const looked = th.wr(p, look_node, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(looked.errno() != 0);
try testing.expect(std.mem.indexOf(u8, looked.reply.ename, said) != null);
@@ -1859,7 +1859,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
test "nothing a mount's close or a no-op truncate sends waits on the editor: a held line runs at its next step" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
// `> exec` truncates nothing; `> body` does.
try testing.expect(!needsQuiet(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
try testing.expect(!changesPane(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
@@ -1877,7 +1877,7 @@ test "nothing a mount's close or a no-op truncate sends waits on the editor: a h
test "a command line cut across writes runs once whole, and the last runs at release; an Edit block waits for its end" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const h = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 1 }).reply.handle;
try testing.expect(h != 0);
// Each piece fills its Twrite (a client's one write cut at msize).
@@ -1908,12 +1908,12 @@ test "a refused open, create or remove says why in words and logs no err; a refu
const serial = serialOf(p);
// pane/new is read, never written: a write is refused, and is no
// failure the log tells of.
- const new = th.wr(p, @intFromEnum(TopFile.new), "x\n");
+ const new = th.wr(p, @backingInt(TopFile.new), "x\n");
try testing.expectEqual(Status.err, new.reply.status);
try testing.expectEqualStrings("permission denied", new.reply.ename);
const made = call(p, .{ .tag = 2, .op = .open, .node = Node.of(serial, .body), .create = true });
try testing.expectEqualStrings("permission denied", made.reply.ename);
- const gone = th.rmdir(p, @intFromEnum(TopFile.index));
+ const gone = th.rmdir(p, @backingInt(TopFile.index));
try testing.expectEqual(Status.err, gone.reply.status);
try testing.expect(gone.reply.ename.len > 0 and !std.ascii.isUpper(gone.reply.ename[0]));
// An OTRUNC open's truncation of data after a failed addr: refused, no err.
@@ -1963,7 +1963,7 @@ test "a write with no newline waits for its newline or the close, whatever its s
test "look and exec read back what their own open's write touched; a fresh open reads the session's last" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const first = p.panes[0].?.serial;
const mine = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
const theirs = call(p, .{ .tag = 2, .op = .open, .node = exec, .omode = 2 }).reply.handle;
@@ -2015,7 +2015,7 @@ test "a rename of a pane's directory or file is refused as not permitted" {
test "no placement leaves a pane shorter than its tag and two rows; a full column refuses the next" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
var made: usize = 1;
const refused = while (made < pardes.MAX_PANES) : (made += 1) {
const a = call(p, .{ .tag = 1, .op = .open, .node = new });
@@ -2080,7 +2080,7 @@ test "a pane made from pane/new goes last in its column, even when the last pane
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for (0..3) |_| {
- const made = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }).reply.handle;
+ const made = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }).reply.handle;
p.sync();
try testing.expectEqual(made, p.panes[p.col_panes[0][p.col_n[0] - 1]].?.serial);
}