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/ctl.zig | |
| 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/ctl.zig')
| -rw-r--r-- | core/ninep/ctl.zig | 70 |
1 files changed, 35 insertions, 35 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")); } |
