diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 20:31:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 20:31:32 -0300 |
| commit | 0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (patch) | |
| tree | f2e288668decded9276ebc45907f16d651b06f9e /core/ninep | |
| parent | 2ab05b536bc3b063666b5aaab497157adc2a9120 (diff) | |
| parent | bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (diff) | |
| download | pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.tar.gz pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.zip | |
integration: a pane's and a view's slot as types, with the regular-expression fixes and the fixes the real loops asked for: pardes-ids (Pane.Id and View.Id through the entries, the events, the effects, the Host table and the device messages) and pardes-merge21, merged without a textual conflict; one call site written since on the old type follows (core/draw.zig: the twin test's file_changed event, .pane = .at(0)); tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/ninep')
| -rw-r--r-- | core/ninep/ctl.zig | 70 | ||||
| -rw-r--r-- | core/ninep/events.zig | 22 | ||||
| -rw-r--r-- | core/ninep/pane.zig | 8 | ||||
| -rw-r--r-- | core/ninep/pty.zig | 42 | ||||
| -rw-r--r-- | core/ninep/screen.zig | 10 | ||||
| -rw-r--r-- | core/ninep/testing.zig | 6 |
6 files changed, 79 insertions, 79 deletions
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index a4f16597..302b916a 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -228,7 +228,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep } if (p.panes[id] == null) return Reply.fail(req.tag, E.NOENT); defer if (scratch) |s| if (v.active != s) if (p.panes[s]) |sp| if (sp.file) |f| { - if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(s, "exec", err); + if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(.at(s), "exec", err); }; p.fs.ran_at = p.panes[id].?.serial; p.fs.no_pane_slot = false; @@ -724,7 +724,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM /// The editor's step: the text of /pager opens closed unread goes in. pub fn fillClosedPagers(p: *Pardes) void { for (p.fs.pages.items) |*page| { - fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(id, "pager", err); + fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(.at(id), "pager", err); page.bytes.deinit(p.gpa); } p.fs.pages.clearRetainingCapacity(); @@ -1252,7 +1252,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 { if (listed) |content| panes.Output.openUnsaved(p, id, content); var notice: pardes.Kind.Buf(64) = .{}; p.fs.unlogged = true; - p.setMessage(id, notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); + p.setMessage(.at(id), notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); p.fs.unlogged = false; return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch &p.fs.ename; // cut to ename's 320 } @@ -1282,7 +1282,7 @@ pub fn getFile(p: *Pardes, pane: *Pane, path: []const u8) GetError!void { f.disk_newer_warned = false; f.disk_gone = false; f.on_disk = fs.localPath(path) != null; - if (f.on_disk) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (f.on_disk) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } /// What Get and Edit's `e` fail with, as their callers say it (the 9P @@ -1500,7 +1500,7 @@ test "a body write to a terminal is typed input, not a paste, even to a program const term = for (p.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break id; } else return error.SkipZigTest; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b[?2004h" } }); while (p.nextEffect()) |_| {} const w = wr(p, Node.of(p.panes[term].?.serial, .body), "ls\n"); try testing.expectEqual(Status.ok, w.reply.status); @@ -1513,7 +1513,7 @@ test "Save path of a file pane logs a save record naming that path" { const serial = serialOf(p); const saved = wr(p, Node.of(serial, .ctl), "Save /tmp/pardes-save-copy.txt\n"); try testing.expectEqual(Status.ok, saved.reply.status); - p.perform(.{ .save_text = .{ .pane = 0, .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } }); + p.perform(.{ .save_text = .{ .pane = .at(0), .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } }); var want: [64]u8 = undefined; try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "save {d} /tmp/pardes-save-copy.txt\n", .{serial}))); } @@ -1590,7 +1590,7 @@ test "exec Save writes the named file through the host" { const saved = wr(p, Node.of(serial, .exec), "Save\n"); try testing.expectEqual(Status.ok, saved.reply.status); try testing.expect(saved.saved); - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try testing.expect(!pane_files.dirtyOf(pane)); try testing.expectEqualStrings(pane.file.?.content, p.fallback.get("/tmp/renamed.txt").?); } @@ -1638,7 +1638,7 @@ test "a builtin's Verbose announcement is logged only when it succeeds, its fail var save_buf: [64]u8 = undefined; const said_save = try std.fmt.bufPrint(&save_buf, "msg {d} Save\n", .{serial}); _ = wr(p, Node.of(serial, .exec), "Save\n"); - p.saveFailed(@intCast(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied); + p.saveFailed(.at(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied); try testing.expect(!th.logHas(p, said_save)); // One that does what it says keeps its announcement. _ = wr(p, Node.of(serial, .exec), "Undo\n"); @@ -1902,7 +1902,7 @@ test "Term in a directory that is not there fails and makes no pane; a shell tha _ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Term\n").reply.status); const term = p.view().active; - p.shellFailed(@intCast(term), error.FileNotFound); + p.shellFailed(.at(term), error.FileNotFound); const run_node = Node.of(p.panes[term].?.serial, .pty_run); const h = call(p, .{ .tag = 1, .op = .open, .node = run_node, .omode = 2 }).reply.handle; _ = call(p, .{ .tag = 2, .op = .write, .node = run_node, .handle = h, .data = "true\n" }); @@ -1982,17 +1982,17 @@ test "a terminal told the directory it already goes by logs no rename" { p.update(.tick); // announced const term = p.view().active; // The host says where its shell started: where it was already named. - p.setCwd(term, "/tmp"); + p.setCwd(.at(term), "/tmp"); var rec: [32]u8 = undefined; try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial}))); // This process's directory, asked before the shell has said anything // (so before its chdir): not taken. const session = p.sessionDir(); - p.setCwd(term, session); + p.setCwd(.at(term), session); try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial}))); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "$ " } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "$ " } }); // Somewhere else is a rename. - p.setCwd(term, "/usr"); + p.setCwd(.at(term), "/usr"); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial}))); } @@ -2000,14 +2000,14 @@ test "a terminal with text typed at its prompt is never typed into: a look at it const p = try th.withTerm(testing.allocator); defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; - p.setCwd(term, "/tmp"); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); + p.setCwd(.at(term), "/tmp"); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); while (p.nextEffect()) |_| {} var count: usize = 0; for (p.panes) |slot| count += @intFromBool(slot != null); 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) { + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) { typed_into = true; }; try testing.expect(!typed_into); @@ -2016,7 +2016,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it try testing.expectEqual(count + 1, after); // An exec at it runs in a pane of its own, not typed after TYPED. _ = wr(p, Node.of(serialOf(p), .exec), "echo hi\n"); - while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) { + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) { typed_into = true; }; try testing.expect(!typed_into); @@ -2042,7 +2042,7 @@ test "a command line from a missing directory fails ENOENT and makes no pane; a _ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "echo hi\n").reply.status); const cmd = p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, Node.of(serial, .exec), 0, 64).bytes, "\n"), 10)).?; - p.shellFailed(@intCast(cmd), error.FileNotFound); + p.shellFailed(.at(cmd), error.FileNotFound); const pane = p.panes[cmd].?; try testing.expect(pane.command_done); try testing.expectEqual(@as(?u8, 127), pane.command_status); @@ -2057,13 +2057,13 @@ test "pty/ctl exec in a directory that is gone fails ENOENT; a shell that cannot p.host = .{ .vtable = &th.starting }; defer p.host = .{}; const serial = serialOf(p); - p.setCwd(p.paneBySerial(serial).?, "/tmp/pardes-no-such-dir-zz"); + p.setCwd(.at(p.paneBySerial(serial).?), "/tmp/pardes-no-such-dir-zz"); const refused = wr(p, Node.of(serial, .pty_ctl), "exec\n"); try testing.expectEqual(E.NOENT, refused.errno()); try testing.expectStringStartsWith(refused.reply.ename, "exec: /tmp/pardes-no-such-dir-zz: no such directory"); // The host's own failure is the waiting write's (late_failure). p.fs.late_failure_len = 0; - p.shellFailed(@intCast(p.paneBySerial(serial).?), error.AccessDenied); + p.shellFailed(.at(p.paneBySerial(serial).?), error.AccessDenied); try testing.expectEqualStrings("shell: permission denied", p.fs.late_failure[0..p.fs.late_failure_len]); } @@ -2095,14 +2095,14 @@ test "a script whose interpreter is not there: Term refuses it up front, only an // one goes. const id = p.paneBySerial(serial).?; p.panes[id].?.shell = try p.gpa.dupe(u8, try std.fmt.bufPrint(&line, "{s}/bad", .{dir})); - p.setCwd(id, dir); + p.setCwd(.at(id), dir); const exec_refused = wr(p, Node.of(serial, .pty_ctl), "exec\n"); try testing.expectEqual(E.NOENT, exec_refused.errno()); try testing.expectEqualStrings("exec: interpreter /no/such/interp not found", exec_refused.reply.ename); // One the host found could not start (the script changed after): said // with the interpreter's name, and the running shell is not gone. p.fs.late_failure_len = 0; - p.restartFailed(@intCast(id), error.InterpreterNotFound); + p.restartFailed(.at(id), error.InterpreterNotFound); try testing.expectEqualStrings("shell: interpreter /no/such/interp not found", p.fs.late_failure[0..p.fs.late_failure_len]); try testing.expect(!p.panes[id].?.shell_failed); } @@ -2163,7 +2163,7 @@ test "a buffer whose file was deleted on disk is dirty, and Del asks first" { defer p.deinit(); const serial = serialOf(p); try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - pardes.panes.File.deleted(p, @intCast(p.paneBySerial(serial).?)); + pardes.panes.File.deleted(p, .at(p.paneBySerial(serial).?)); try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); try testing.expectEqual(Status.err, wr(p, Node.of(serial, .ctl), "Del\n").reply.status); try testing.expect(p.paneBySerial(serial) != null); @@ -2176,7 +2176,7 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); p.fs.write_waits = true; - p.saveFailed(@intCast(p.view().active), "/nowhere/zz.txt", error.FileNotFound); + p.saveFailed(.at(p.view().active), "/nowhere/zz.txt", error.FileNotFound); p.fs.write_waits = false; try testing.expect(!th.logHas(p, "msg ")); try testing.expect(p.fs.late_failure_len > 0); @@ -2260,8 +2260,8 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as }; try testing.expectEqual(@as(usize, 2), n); p.view().active = shells[0]; - p.update(.{ .output = .{ .pane = @intCast(shells[0]), .bytes = "\x1b[?1004h" } }); - p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(shells[0]), .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(shells[1]), .bytes = "\x1b[?1004h" } }); while (p.nextEffect()) |_| {} var digits: [16]u8 = undefined; const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial})); @@ -2304,7 +2304,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt const p = try th.withTerm(testing.allocator); defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; - p.setCwd(term, "/tmp/two\nlines\x07\x7f\xc2\x85\xff"); + p.setCwd(.at(term), "/tmp/two\nlines\x07\x7f\xc2\x85\xff"); 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); @@ -2344,7 +2344,7 @@ test "a new file saved shows in /recent, open, while it is" { const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; // A host that writes files, as the real ones do. const Writing = struct { - fn write(_: ?*anyopaque, _: u8, path: []const u8, bytes: []const u8) void { + fn write(_: ?*anyopaque, _: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { std.Io.Dir.cwd().writeFile(testing.io, .{ .sub_path = path, .data = bytes }) catch {}; } }; @@ -2357,7 +2357,7 @@ test "a new file saved shows in /recent, open, while it is" { _ = wr(p, Node.of(made, .name), try std.fmt.bufPrint(&name, "{s}\n", .{path})); _ = wr(p, Node.of(made, .body), "fresh\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Save\n").reply.status); - p.perform(.{ .save_file = .{ .pane = @intCast(p.paneBySerial(made).?) } }); + p.perform(.{ .save_file = .{ .pane = .at(p.paneBySerial(made).?) } }); var want: [4300]u8 = undefined; 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); } @@ -2561,8 +2561,8 @@ test "get names the path it could not read, logs the edits it threw away, and a var want: [512]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "get: {s}: no such file", .{path}), missing.reply.ename); // Deleted on disk: said once. - pardes.panes.File.deleted(p, 0); - pardes.panes.File.deleted(p, 0); + pardes.panes.File.deleted(p, .at(0)); + pardes.panes.File.deleted(p, .at(0)); var rec: [32]u8 = undefined; const log = @backingInt(tree.TopFile.log); const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; @@ -2575,7 +2575,7 @@ test "a word written to a raw terminal's look is listed as in normal mode" { defer p.deinit(); const serial = serialOf(p); const id = p.paneBySerial(serial).?; - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one MARK two\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "one MARK two\r\n" } }); p.panes[id].?.body.mode = .tty; try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), "MARK\n").reply.status); const said = std.mem.trimEnd(u8, rd(p, Node.of(serial, .look), 0, 64).bytes, "\n"); @@ -2588,7 +2588,7 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select defer p.deinit(); const serial = serialOf(p); const id = p.paneBySerial(serial).?; - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one\r\ntwo MARK three\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "one\r\ntwo MARK three\r\n" } }); const pane = p.panes[id].?; const root = @backingInt(tree.TopFile.look); var line: [64]u8 = undefined; @@ -2712,10 +2712,10 @@ test "a Save whose directory is missing because one above refuses says permissio defer p.deinit(); // The refusing directory is Linux's /proc/1/root. if (comptime @import("builtin").os.tag == .linux) { - p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound); + p.saveFailed(.at(0), "/proc/1/root/x/f.txt", error.FileNotFound); try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied")); } - p.saveFailed(0, "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound); + p.saveFailed(.at(0), "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound); try testing.expect(th.logHas(p, "no such directory")); } diff --git a/core/ninep/events.zig b/core/ninep/events.zig index 1e740345..93a1187a 100644 --- a/core/ninep/events.zig +++ b/core/ninep/events.zig @@ -1180,7 +1180,7 @@ test "the log records whether or not anyone reads, and an open that follows wait ); // What the editor says is in the same stream, one line even when the // message had several. - p.setMessage(id, "save: two\nlines"); + p.setMessage(.at(id), "save: two\nlines"); try testing.expectEqualStrings( try std.fmt.bufPrint(&expected, "msg {d} save: two lines\n", .{serial}), rdf.next(p, log, fh, frozen).bytes, @@ -1198,7 +1198,7 @@ test "the log records whether or not anyone reads, and an open that follows wait // pieces rather than failing. A repeat the follower waits on, having // read the first, is its own line. const said_by = p.panes[0].?.serial; - p.setMessage(0, "same failure"); + p.setMessage(.at(0), "same failure"); var pieced: [64]u8 = undefined; var got: usize = 0; while (got == 0 or pieced[got - 1] != '\n') { @@ -1207,14 +1207,14 @@ test "the log records whether or not anyone reads, and an open that follows wait got += piece.len; } try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure\n", .{said_by}), pieced[0..got]); - p.setMessage(0, "same failure"); + p.setMessage(.at(0), "same failure"); try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure (x2)\n", .{said_by}), rdf.next(p, log, fh, frozen).bytes); // A follower the ring outran hears how much it missed, then carries on. var filler: [200]u8 = @splat('x'); for (0..p.fs.log.cap / filler.len + 8) |i| { _ = std.fmt.bufPrint(&filler, "{d:0>6}", .{i}) catch unreachable; // a repeat would collapse - p.setMessage(0, &filler); + p.setMessage(.at(0), &filler); } const lost = rdf.next(p, log, fh, frozen).bytes; try testing.expect(std.mem.startsWith(u8, lost, "lost ")); @@ -1226,7 +1226,7 @@ test "the log records whether or not anyone reads, and an open that follows wait // everything else pushed out ahead of it. p.fs.log.cap = 128; var huge: [300]u8 = @splat('y'); - p.setMessage(0, &huge); + p.setMessage(.at(0), &huge); const cut = call(p, .{ .tag = 11, .op = .open, .node = log }); const kept = call(p, .{ .tag = 12, .op = .read, .node = log, .handle = cut.reply.handle, .size = 512 }).bytes; try testing.expectEqual(@as(usize, 124), kept.len); @@ -1328,7 +1328,7 @@ test "a pane named before it is announced has its new under that name, and no re const shell = try p.newShell(free, ""); try testing.expectEqualStrings(p.sessionDir(), pane_files.nameOf(p, shell)); announce(p); - p.setCwd(free, p.sessionDir()); + p.setCwd(.at(free), p.sessionDir()); const after = try freezeLog(p); defer p.gpa.free(after.bytes); try testing.expect(std.mem.indexOf(u8, after.bytes, try std.fmt.bufPrint(&want, "rename {d} ", .{shell.serial})) == null); @@ -1427,12 +1427,12 @@ test "follow new skips what the log held and waits for what comes after" { defer p.deinit(); p.update(.tick); // the pane's `new` is logged first while (p.nextEffect()) |_| {} - p.setMessage(0, "before the open"); + p.setMessage(.at(0), "before the open"); 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); - p.setMessage(0, "after it"); + p.setMessage(.at(0), "after it"); try testing.expect(std.mem.endsWith(u8, call(p, .{ .tag = 4, .op = .read, .node = log, .handle = h, .size = 4096 }).bytes, " after it\n")); _ = call(p, .{ .tag = 5, .op = .release, .node = log, .handle = h }); } @@ -1482,10 +1482,10 @@ test "two failures that agree only in what their records cut are two records, no const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const long = std.mem.asBytes(&@as([80][4]u8, @splat("why ".*))); - p.setMessage(0, long ++ "first"); - p.setMessage(0, long ++ "second"); + p.setMessage(.at(0), long ++ "first"); + p.setMessage(.at(0), long ++ "second"); try testing.expect(!th.logHas(p, "(x2)")); - p.setMessage(0, long ++ "second"); + p.setMessage(.at(0), long ++ "second"); try testing.expect(th.logHas(p, "(x2)")); } diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 96a50703..8be26602 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -693,7 +693,7 @@ pub fn applyTagTruncation(p: *Pardes, pane: *Pane) void { pf.tag_trunc_pending = false; // An edit like a keyboard one: `u` in the tag brings it back. pane.tag.remember(p.gpa, if (pane.tag.own) |own| .{ .text = own } else null) catch |err| - return p.reportError(p.paneBySerial(pane.serial) orelse return, "tag", err); + return p.reportError(.at(p.paneBySerial(pane.serial) orelse return), "tag", err); const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked if (pane.tag.own) |own| p.gpa.free(own); pane.tag.own = empty; @@ -941,7 +941,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) ! f.context.revision = null; pane.geometry_key = 0; look.invalidateLookHover(p, id); - p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); events.noteLog(p, .rename, pane); // A name given: whether a file there is on disk is the disk's to say. f.on_disk = f.output == null and pardes.Pardes.recentKeeps(p.tape, f.path); @@ -1065,7 +1065,7 @@ test "a terminal's body stats as long as it reads" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; try testing.expect(pane.isTerminal()); - p.update(.{ .output = .{ .pane = 0, .bytes = "$ ls\r\nalpha beta\r\n$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "$ ls\r\nalpha beta\r\n$ " } }); const body = Node.of(pane.serial, .body); const whole = rd(p, body, 0, 1 << 16); try testing.expect(whole.bytes.len > 0); @@ -1198,7 +1198,7 @@ test "a long path's failed Save keeps its reason" { const id = p.paneBySerial(serial).?; try nameBuffer(p, id, long, false); p.fs.late_failure_len = 0; - p.saveFailed(@intCast(id), long, error.AccessDenied); + p.saveFailed(.at(id), long, error.AccessDenied); const late = p.fs.late_failure[0..p.fs.late_failure_len]; try testing.expect(std.mem.startsWith(u8, late, "Save /tmp/nonexistent-pardes-root/")); try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory")); diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 0fd75aa2..6f3a8af0 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -96,14 +96,14 @@ fn verb(p: *Pardes, id: usize, line: []const u8, apply: bool) ?[]const u8 { // is refused, never quietly raised. if (rows < pty_rows_min) return e_winsize_rows; if (!apply) return null; - p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } }); + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); pane.fs.winsize = .{ cols, rows }; }, .sig => { const which = signalNamed(words.next() orelse return e_bad_pty_ctl) orelse return e_bad_pty_ctl; if (words.next() != null) return e_bad_pty_ctl; if (!apply) return null; - p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = which } }); + p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = which } }); }, .exec => { if (words.next() != null) return e_bad_pty_ctl; @@ -656,7 +656,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" { const ctl = Node.of(pane.serial, .pty_ctl); var path: [1025]u8 = @splat('d'); path[0] = '/'; - p.setCwd(0, &path); + p.setCwd(.at(0), &path); for ([_][]const u8{ "exec\n", "winsize 100 30\nexec\n", "sig TERM\nexec\n" }) |command| { const result = wr(p, ctl, command); try testing.expectEqual(E.INVAL, result.errno()); @@ -664,7 +664,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" { try testing.expect(result.signal == null and result.winsize == null); } try testing.expectEqualStrings(&path, pane.cwdSlice()); - p.setCwd(0, path[0..pardes.effect_path_cap]); + p.setCwd(.at(0), path[0..pardes.effect_path_cap]); const accepted = wr(p, ctl, "exec\n"); try testing.expectEqual(Status.ok, accepted.reply.status); try testing.expect(accepted.spawned); @@ -709,7 +709,7 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = "unwatched" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "unwatched" } }); while (p.nextEffect()) |_| {} try testing.expectEqual(@as(usize, 0), p.panes[0].?.fs.pty_out.buf.items.len); try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); @@ -724,20 +724,20 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(@as(u16, 0), p.fs.listeners); try testing.expect(p.panes[0].?.fs.readers == 0); - p.update(.{ .output = .{ .pane = 0, .bytes = "hello" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("hello", rd(p, data, 0, 64).bytes); try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = "abcdef" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abcdef" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("ab", rd(p, data, 0, 2).bytes); try testing.expectEqualStrings("cd", rd(p, data, 0, 2).bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "ghi" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "ghi" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("efghi", rd(p, data, 0, 64).bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "orphan" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "orphan" } }); while (p.nextEffect()) |_| {} _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = reader.reply.handle }); try testing.expect(!p.panes[0].?.fs.pty_reader); @@ -750,7 +750,7 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(Status.err, second.reply.status); try testing.expectEqualStrings(tree.e_in_use, second.reply.ename); try testing.expect(p.panes[0].?.fs.pty_reader); - p.update(.{ .output = .{ .pane = 0, .bytes = "still" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "still" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("still", rd(p, data, 0, 64).bytes); } @@ -765,7 +765,7 @@ test "a run waiting for a new terminal's first prompt is the only line typed the const node = Node.of(serialOf(p), .pty_run); const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle; _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" }); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); var sent: [32]u8 = undefined; var len: usize = 0; while (p.nextEffect()) |e| if (e == .write) { @@ -783,7 +783,7 @@ test "run answers how its command ended once the shell is back at a prompt" { const node = Node.of(serialOf(p), .pty_run); const out = struct { fn put(pp: *Pardes, bytes: []const u8) void { - pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); while (pp.nextEffect()) |_| {} } }; @@ -799,9 +799,9 @@ test "run answers how its command ended once the shell is back at a prompt" { try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status); try testing.expect(std.mem.endsWith(u8, rd(p, status, 0, 64).bytes, " 1\n")); // A respawn before that prompt keeps it waiting for the new shell's. - p.acknowledgeShell(0, "/bin/sh", true); + p.acknowledgeShell(.at(0), "/bin/sh", true); try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } }); var sent_late: [16]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |e| if (e == .write) { @@ -909,7 +909,7 @@ test "a shell that exits under a run answers its status, and the log says exit b const serial = serialOf(p); const node = Node.of(serial, .pty_run); const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - p.update(.{ .output = .{ .pane = 0, .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } }); while (p.nextEffect()) |_| {} const log = @backingInt(tree.TopFile.log); const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; @@ -918,9 +918,9 @@ test "a shell that exits under a run answers its status, and the log says exit b const r = call(p, .{ .tag = 4, .op = .open, .node = node }); _ = call(p, .{ .tag = 5, .op = .write, .node = node, .handle = r.reply.handle, .data = "echo bye; exit 3\n" }); - p.update(.{ .output = .{ .pane = 0, .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } }); - p.update(.{ .exited = .{ .pane = 0, .status = 3 } }); - p.update(.{ .eof = .{ .pane = 0 } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(0), .status = 3 } }); + p.update(.{ .eof = .{ .pane = .at(0) } }); while (p.nextEffect()) |_| {} try testing.expect(p.paneBySerial(serial) == null); try testing.expectEqualStrings("exit 3\nbye\n", call(p, .{ .tag = 6, .op = .read, .node = node, .handle = r.reply.handle, .size = 64 }).bytes); @@ -969,7 +969,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound const pane = p.panes[0].?; const sh = struct { fn put(pp: *Pardes, bytes: []const u8) void { - pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); while (pp.nextEffect()) |_| {} } fn send(pp: *Pardes, n: u64) u32 { @@ -1099,7 +1099,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l const p = try withTerm(gpa); defer p.deinit(); const serial = serialOf(p); - p.update(.{ .output = .{ .pane = 0, .bytes = "some history\r\nmore" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "some history\r\nmore" } }); while (p.nextEffect()) |_| {} const opened = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .body) }); const body_len = call(p, .{ .tag = 2, .op = .read, .node = Node.of(serial, .body), .handle = opened.reply.handle, .size = 1 << 16 }).bytes.len; @@ -1114,7 +1114,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l const f = call(p, .{ .tag = 4, .op = .open, .node = log }).reply.handle; const frozen = call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len; _ = call(p, .{ .tag = 6, .op = .write, .node = log, .handle = f, .data = "follow" }); - p.setCwd(0, "/somewhere/else"); + p.setCwd(.at(0), "/somewhere/else"); var want: [64]u8 = undefined; try testing.expectEqualStrings( try std.fmt.bufPrint(&want, "rename {d} /somewhere/else\n", .{serial}), diff --git a/core/ninep/screen.zig b/core/ninep/screen.zig index cd3c73b6..1e2791b1 100644 --- a/core/ninep/screen.zig +++ b/core/ninep/screen.zig @@ -124,7 +124,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" { const p = try withTerm(gpa); defer p.deinit(); const node = Node.of(serialOf(p), .body); - p.update(.{ .output = .{ .pane = 0, .bytes = "old caf\xc3\xa9\r\nold tail" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "old caf\xc3\xa9\r\nold tail" } }); while (p.nextEffect()) |_| {} const original = try pardes.Term.scrollback(p.panes[0].?.terminal, gpa); defer gpa.free(original); @@ -132,7 +132,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" { try testing.expectEqual(Status.ok, opened.reply.status); const first = call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 3 }); try testing.expectEqualStrings(original[0..3], first.bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } }); while (p.nextEffect()) |_| {} var offset: usize = 3; while (offset < original.len) { @@ -154,7 +154,7 @@ test "an empty terminal body snapshot stays empty while output continues" { const opened = call(p, .{ .tag = 1, .op = .open, .node = node }); try testing.expectEqualStrings("", call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes); try testing.expect(p.fs.opens[opened.reply.handle - 1].what.snapshot != null); - p.update(.{ .output = .{ .pane = 0, .bytes = "new output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "new output" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("", call(p, .{ .tag = 3, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes); _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = opened.reply.handle }); @@ -182,7 +182,7 @@ test "terminal body snapshots are lazy bounded and released after the pane close const scratch = try th.newPane(p); const scratch_id = p.paneBySerial(scratch).?; try testing.expect(p.panes[scratch_id].?.file != null); - p.update(.{ .output = .{ .pane = 0, .bytes = "latest output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "latest output" } }); while (p.nextEffect()) |_| {} var failing = std.testing.FailingAllocator.init(gpa, .{ .fail_index = 0 }); p.gpa = failing.allocator(); @@ -298,7 +298,7 @@ test "a terminal's body is its logical lines: a row the terminal wrapped is join const pane = p.panes[0].?; 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" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = long ++ "\r\nnext" } }); while (p.nextEffect()) |_| {} const node = Node.of(pane.serial, .body); const body = th.rd(p, node, 0, 4096).bytes; diff --git a/core/ninep/testing.zig b/core/ninep/testing.zig index 23a9199f..cf75d80d 100644 --- a/core/ninep/testing.zig +++ b/core/ninep/testing.zig @@ -153,15 +153,15 @@ pub fn nameAt(list: []const Dirent, want: []const u8) ?Dirent { /// none. pub const starting: pardes.Host.VTable = .{ .spawn = startNothing }; -fn startNothing(_: ?*anyopaque, _: u8, _: []const u8) void {} +fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} pub const FakeTty = struct { taken: bool, pub const vtable: pardes.Host.VTable = .{ .tty_taken = answer }; - fn answer(ctx: ?*anyopaque, pane: u8) bool { - _ = pane; + fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + _ = id; const f: *FakeTty = @ptrCast(@alignCast(ctx.?)); return f.taken; } |
