diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-22 09:50:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:24 -0300 |
| commit | a8b457a306a4442975210bcac3f04b56513c61c3 (patch) | |
| tree | 6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/ninep/ctl.zig | |
| parent | a8a1499bdffffc5b6919e24ec957e92fabaf003b (diff) | |
| parent | 7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff) | |
| download | pardes-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/ctl.zig')
| -rw-r--r-- | src/ninep/ctl.zig | 237 |
1 files changed, 133 insertions, 104 deletions
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" { |
