From d0e36bb453526af64349a4eb2335b86c94bea56d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 16:03:52 -0300 Subject: core: a pane's slot and a view's slot are two types, `Pane.Id` and `View.Id` (P21, pardes-ids change 1; the user, reading the tape's inputs: "why the id is an u8 though?", and "the id to be typed too"): each a distinct non-exhaustive `enum(u8)` (`pub const Id` inside `Pane` in core/panes.zig and inside `Pardes.View` in core/Core.zig, side by side with the thing whose slot it is), with the one conversion each way the boundary needs, named once: `Id.at(i)` the id of a slot the core holds (`@fromBackingInt(@intCast(i))`, so a slot past a byte panics in a safe build) and `id.index()` the slot as a `u8` (which widens to the `usize` half the core indexes with, so no caller casts); nothing uses them yet; one test at the end of core/views.zig, "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" (an enum coerces only into itself, so it shows the two are distinct, a byte each and non-exhaustive, and every slot round-trips; a probe that assigned a `View.Id` to a `Pane.Id` failed to compile with "expected type 'panes.Pane.Id', found 'Core.View.Id'"); 46 lines added in three files, no line changed; nothing a step runs is touched, so the frame and perf gate was not run on it and the semantics word does not move (313a99190b93a8c5); gate (load 5 to 10, a drat build beside): tui core-test 841/984 (143 skipped), shell-test 1020/1023, gui unit-test 1618/1622 (the perf check's BaselineHarnessMismatch, the base's 1617/1621 with it), each the base's plus this test Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Core.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index 769d16cd..85087b11 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -89,6 +89,21 @@ const Pardes = @This(); /// its focus, its pointer and gestures, its jumps, its key prefixes. pub const View = struct { pub const replica = .{ .len = .{ .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } } }; + /// A view's slot in `Pardes.views`, as it crosses the core's edge: an + /// entry's argument or answer, the wire's welcome. A type of its own, + /// so a pane's slot (`Pane.Id`) is not taken for it; the core's own + /// view indexes (`live`, views.zig) keep their integers. + pub const Id = enum(u8) { + _, + /// The id of slot `k`, a slot the core holds. + pub fn at(k: usize) Id { + return @fromBackingInt(@intCast(k)); + } + /// The slot, to index the core's views with. + pub fn index(id: Id) u8 { + return @backingInt(id); + } + }; screen_w: u16 = 0, screen_h: u16 = 0, -- cgit v1.3 From 78d94c4a62ec3f4039a475b637ff6a60649fde52 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 16:41:27 -0300 Subject: core: the entries that take or answer a slot take and answer its type (P21, pardes-ids change 2): a pane's slot is `Pane.Id` in the twelve entries that took it, six as `usize` (setCwd, acknowledgeShell, setMessage, setStatus, reportError, noteLateFailure) and six as `u8` (readerFailed, shellFailed, restartFailed, saveFailed, reloadWatchedFile, File.deleted), and in what adoptShell answers (`?Pane.Id`); a view's slot is `View.Id` in closeView, leaveView, awayView, rejoinView and the hand-written toView (its `to_view` variant is `Pardes.View.Id` now, and its replay arm unchanged) and in what openView answers (`?View.Id`); the tape's other variants follow their inners' types with no edit (`Args`); each inner converts where its body indexes (`id.index()`), passes the id itself to another entry, and the core's own code stays integers; every caller converts at its own line, `p.reportError(.at(id), ..)` (the decl literal of the parameter's type), 514 calls in 56 files written by a script that refuses any path outside the workspace (`.scratch/sketch/reorg/pardes-ids/wrap.py`), 46 `.index()`; nothing the compiler caught was a pane's slot passed as a view's or the reverse: what it caught were a script's wrong guesses (Editor.reportError(err) and macos.zig's own reloadWatchedFile, same names, undone) and the integers a view's id met (views.zig's tests, replica.zig's Authority and Peers.join, host_io's Adoption); in files another agent is in, each conversion on the line that was there: core/Kind.zig 5 lines, core/Addon.zig 4, core/replica.zig 23 (Authority.openView and join, closeView/toView/awayView/rejoinView/leaveView calls, Peers.join's `openView`, tests), test/replicas.zig 1; the tape's records are smaller (a `usize` is a byte in six inputs) and its shape moves, so the semantics word moves, 313a99190b93a8c5 -> c47ecf638b3f4b9f; test/perf.zig untouched (its harness id does not move); the Mac: runtime/macos.zig 16 call lines, abi/pardes.h unchanged; 581 lines changed in 56 files, no line added. Gate (load 4 to 28: a drat build and other agents' gates beside): tui core-test 841/984 (143 skipped), shell-test 1020/1023, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds of 70 steps, 0 failures, process-test lspcomplete and lspcompletemoved (the base's), gui unit-test 1618/1622 (BaselineHarnessMismatch, the base's); replicas --clients 5 (TMPDIR /tmp/claude-1000/ids, alternated with the base twice, both pass both times): diverged 0, unequal 0 at rtt 30, 80, 207, deltas checked/wrong 1811/0, 1838/0, 1715/0, quiet checks 567/0, 650/0, 544/0, stops not on may_wait 0 (its corpus-through-a-client scene fails at step 21 as on the base with that TMPDIR); two earlier runs of this tree under a load of 10 to 28 ended in a leak of Places' compiled regex (Places.derive from Query.produce) and one rtt-207 run in an assertion in mouse.kindMouse's clamp during a client's speculation, the leak not seen in the eight runs of this tree after them (the full soak, each rtt alone, single seeds), the assertion not in the two full runs after it, and neither in three full runs of the base (by reading neither touches a slot: in the report); daemon.py plain, --far, --games, --window-clients, --upgrade both ways against pardes-tree's base prefix pass; test/cross_replay.py (tui records, gui replays): 27 digests agree in each of three replicas; rollback-bench runs; the macOS library for Linux and aarch64-macos and the FreeBSD cross-build build; frames (gpu/ids-2 against tree1) 77/77 byte-identical in Debug, unit-test 1618/1622 there too, perfab corpus2x -0.059% (session noise 0.134%, threshold 0.4%), pictures identical in all 10 runs, perfops 97 counts within 0.1% (largest image-frame on longline +0.0274%), key-down on medium 10,040,104 -> 10,039,959 an operation (-0.0014%), render on medium 11,455,764 -> 11,455,707 (-0.0005%) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Addon.zig | 8 +-- core/Core.zig | 142 ++++++++++++++++++++++++------------------------ core/Db.zig | 2 +- core/Dir.zig | 10 ++-- core/Editor.zig | 2 +- core/Effect.zig | 24 ++++---- core/File.zig | 16 +++--- core/Handover.zig | 12 ++-- core/Jump.zig | 4 +- core/Kind.zig | 10 ++-- core/Messages.zig | 60 ++++++++++---------- core/Output.zig | 6 +- core/Pipe.zig | 30 +++++----- core/Plumb.zig | 10 ++-- core/Query.zig | 62 ++++++++++----------- core/Store.zig | 6 +- core/Stream.zig | 4 +- core/builtins.zig | 106 ++++++++++++++++++------------------ core/colors.zig | 8 +-- core/draw.zig | 6 +- core/dump.zig | 4 +- core/edit.zig | 10 ++-- core/edit_cmd.zig | 46 ++++++++-------- core/exec.zig | 46 ++++++++-------- core/fs.zig | 4 +- core/hunks.zig | 8 +-- core/keys.zig | 24 ++++---- core/layout.zig | 4 +- core/look.zig | 50 ++++++++--------- core/lsp/Ask.zig | 16 +++--- core/mouse.zig | 14 ++--- core/ninep/ctl.zig | 42 +++++++------- core/ninep/events.zig | 22 ++++---- core/ninep/pane.zig | 4 +- core/ninep/pty.zig | 8 +-- core/normal.zig | 8 +-- core/panes.zig | 30 +++++----- core/replica.zig | 46 ++++++++-------- core/rollback.zig | 4 +- core/selection_pipe.zig | 4 +- core/tagline.zig | 16 +++--- core/tape.zig | 2 +- core/views.zig | 52 +++++++++--------- dev/Lsp.zig | 4 +- dev/file_watch.zig | 16 +++--- dev/gui/gui.zig | 30 +++++----- dev/host_io.zig | 20 +++---- dev/tui/tui.zig | 24 ++++---- runtime/9p_io.zig | 12 ++-- runtime/addon_test.zig | 2 +- runtime/macos.zig | 32 +++++------ runtime/upgrade.zig | 6 +- test/fs_namespace.zig | 2 +- test/panes.zig | 16 +++--- test/replicas.zig | 2 +- test/session.zig | 4 +- 56 files changed, 581 insertions(+), 581 deletions(-) (limited to 'core/Core.zig') diff --git a/core/Addon.zig b/core/Addon.zig index d52462e0..e84b122b 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -716,7 +716,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { var w: std.Io.Writer = .fixed(&said); w.writeAll("addons:") catch {}; for (p.kinds.kinds[0..p.kinds.n]) |*e| if (!e.refused) w.print(" {s} {d}", .{ e.nameOf(), e.version }) catch {}; - return p.setMessage(id, w.buffered()); + return p.setMessage(.at(id), w.buffered()); } const takes = "Addon takes load , unload or reload "; const sp = std.mem.indexOfAny(u8, a, " \t") orelse return p.reportFailure(id, takes); @@ -739,7 +739,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { const gone = std.fmt.bufPrint(&said, "Addon unload: {s} is gone", .{rest}) catch "Addon unload"; p.kinds.drop(k); release(p, hash); - p.setMessage(id, gone); + p.setMessage(.at(id), gone); } fn release(p: *Pardes, hash: [32]u8) void { @@ -767,7 +767,7 @@ pub fn landed(p: *Pardes, op: Op, pane: u8, l: Loaded) void { return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s}: {s}", .{ base, why.slice() }) catch "Addon reload: refused"); } const n = openPanes(p, l.name); - return p.setMessage(id, std.fmt.bufPrint(&said, "Addon reload: {s} {d}, {d} pane{s}", .{ l.name, l.version, n, if (n == 1) "" else "s" }) catch "Addon reload"); + return p.setMessage(.at(id), std.fmt.bufPrint(&said, "Addon reload: {s} {d}, {d} pane{s}", .{ l.name, l.version, n, if (n == 1) "" else "s" }) catch "Addon reload"); } // A load of a path refused before tries it afresh. var i: u8 = 0; @@ -779,7 +779,7 @@ pub fn landed(p: *Pardes, op: Op, pane: u8, l: Loaded) void { return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon load: {s}: {s}", .{ base, why }) catch "Addon load: refused"); } const n = reopenWaiting(p, l.name); - p.setMessage(id, std.fmt.bufPrint(&said, "Addon load: {s} {d}{s}", .{ l.name, l.version, if (n > 0) ", its panes back" else "" }) catch "Addon load"); + p.setMessage(.at(id), std.fmt.bufPrint(&said, "Addon load: {s} {d}{s}", .{ l.name, l.version, if (n > 0) ", its panes back" else "" }) catch "Addon load"); } /// The panes of kind `name` that waited for it (placeholders), opened. diff --git a/core/Core.zig b/core/Core.zig index 85087b11..e3238a6e 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -883,7 +883,7 @@ pub fn deinit(p: *Pardes) void { /// last pane's Del, the host's own end (its terminal hung up, its window /// closed). A dump that fails is said as Exit's, in the log. pub fn endSession(p: *Pardes) void { - pardes.dump.dumpExit(p) catch |err| p.reportError(p.view().active, "Exit", err); + pardes.dump.dumpExit(p) catch |err| p.reportError(.at(p.view().active), "Exit", err); p.quit = true; } @@ -900,7 +900,7 @@ fn setLastDumpInner(p: *Pardes, path: []const u8) void { /// text) has the old path swapped, never left pointing at a dump that is /// not the last. pub fn pointRestoreAt(p: *Pardes, path: []const u8) void { - const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(p.view().active, "Restore", err); + const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(p.view().active), "Restore", err); if (p.last_dump) |old| { if (p.global_tag.own) |own| swap: { const a = p.scratch.allocator(); @@ -974,19 +974,19 @@ pub fn writeRoom(p: *const Pardes, id: usize) usize { pub fn parkPendingWrite(p: *Pardes, id: usize, bytes: []const u8) void { if (p.pending_write_bytes + bytes.len > limits.pending_write_cap) { var said: [128]u8 = undefined; - return p.setMessage(id, std.fmt.bufPrint(&said, "write: {d} bytes for the program dropped, past the {d} MiB that may wait for it", .{ bytes.len, limits.pending_write_cap >> 20 }) catch unreachable); // two numbers fit 128 + return p.setMessage(.at(id), std.fmt.bufPrint(&said, "write: {d} bytes for the program dropped, past the {d} MiB that may wait for it", .{ bytes.len, limits.pending_write_cap >> 20 }) catch unreachable); // two numbers fit 128 } if (p.pending_write[id]) |*pw| { // Compact what the drain already sent before growing: a burst that // arrives in pieces must not keep re-copying bytes nobody wants. const keep = pw.bytes.len - pw.off; - const grown = p.gpa.alloc(u8, keep + bytes.len) catch |err| return p.reportError(id, "write", err); + const grown = p.gpa.alloc(u8, keep + bytes.len) catch |err| return p.reportError(.at(id), "write", err); @memcpy(grown[0..keep], pw.bytes[pw.off..]); @memcpy(grown[keep..], bytes); p.gpa.free(pw.bytes); pw.* = .{ .bytes = grown }; } else { - p.pending_write[id] = .{ .bytes = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(id, "write", err) }; + p.pending_write[id] = .{ .bytes = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(.at(id), "write", err) }; } p.pending_write_bytes += bytes.len; } @@ -994,8 +994,8 @@ pub fn parkPendingWrite(p: *Pardes, id: usize, bytes: []const u8) void { /// The shell reports the spawned pane's working directory (and later cwd /// changes it observes, e.g. via /proc//cwd before each frame). pub const setCwd = pardes.tape.taped(setCwdInner); -fn setCwdInner(p: *Pardes, id: usize, cwd: []const u8) void { - const pane = p.panes[id] orelse return; +fn setCwdInner(p: *Pardes, id: Pane.Id, cwd: []const u8) void { + const pane = p.panes[id.index()] orelse return; // A command pane stays the directory's it was run for (newCommand). if (pane.command != null) return; const cur = switch (pane.cwd) { @@ -1012,7 +1012,7 @@ fn setCwdInner(p: *Pardes, id: usize, cwd: []const u8) void { // shell saying it is there is no new name. const same_name = cur.len == 0 and std.mem.eql(u8, cwd, p.sessionDir()); pane.setOwnedCwd(cwd) catch |err| return p.reportError(id, "directory", err); - if (look.lookHoverPane(p) == id) look.cancelLookHover(p); + if (look.lookHoverPane(p) == id.index()) look.cancelLookHover(p); // A terminal is named by its directory, so /log hears it renamed; one // not announced yet is announced under the new name. if (pane.isTerminal() and !same_name) ctlfs.events.noteLog(p, .rename, pane); @@ -1029,7 +1029,7 @@ pub fn shellBin(p: *const Pardes) []const u8 { /// or null with no room. An input, as every host write into the core /// is: a replica of the session makes the same pane. pub const adoptShell = pardes.tape.taped(adoptShellInner); -fn adoptShellInner(p: *Pardes) ?u8 { +fn adoptShellInner(p: *Pardes) ?Pane.Id { var newest: u32 = 0; for (p.panes) |slot| if (slot) |pn| { newest = @max(newest, pn.serial); @@ -1037,7 +1037,7 @@ fn adoptShellInner(p: *Pardes) ?u8 { _ = p.executeBuiltinLine(p.view().active, "Term"); for (p.panes, 0..) |slot, id| if (slot) |pn| if (pn.serial > newest and pn.isTerminal()) { pn.greet = false; - return @intCast(id); + return .at(id); }; return null; } @@ -1045,15 +1045,15 @@ fn adoptShellInner(p: *Pardes) ?u8 { /// A terminal's reader failed (no end of file: the host closed its pty): /// its pane takes keys again, and why is said. pub const readerFailed = pardes.tape.taped(readerFailedInner); -fn readerFailedInner(p: *Pardes, id: u8, err: anyerror) void { - const pane = p.panes[id] orelse return; +fn readerFailedInner(p: *Pardes, id: Pane.Id, err: anyerror) void { + const pane = p.panes[id.index()] orelse return; pane.body.mode = .normal; p.reportError(id, "terminal reader", err); } pub const acknowledgeShell = pardes.tape.taped(acknowledgeShellInner); -fn acknowledgeShellInner(p: *Pardes, id: usize, executable: []const u8, prompt_marks: bool) void { - if (id < MAX_PANES) if (p.panes[id]) |pane| { +fn acknowledgeShellInner(p: *Pardes, id: Pane.Id, executable: []const u8, prompt_marks: bool) void { + if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| { ctlfs.pty.shellGone(p, pane, true); // a respawn replaced whatever ran pane.shell_failed = false; pane.had_shell = true; @@ -1072,12 +1072,12 @@ fn acknowledgeShellInner(p: *Pardes, id: usize, executable: []const u8, prompt_m }; // The lines queued for it go when it can take them: at its first // prompt, or now when it draws no marks to wait for. - if (id < MAX_PANES) if (p.panes[id]) |pane| if (pane.isTerminal() and pane.pending_command.wait == .spawn) { + if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| if (pane.isTerminal() and pane.pending_command.wait == .spawn) { if (prompt_marks) { pane.pending_command.wait = .input; } else { pane.greet = false; - pane.releasePendingCommand(p, id, true); + pane.releasePendingCommand(p, id.index(), true); } }; if (p.settings.shell.effective.set(executable)) @@ -1161,7 +1161,7 @@ pub inline fn view(p: anytype) if (@typeInfo(@TypeOf(p)).pointer.attrs.@"const") /// `pardes --attach`ed), as the live one is laid out; null at /// Views.max. Not live until `toView`. pub const openView = pardes.tape.taped(openViewInner); -fn openViewInner(p: *Pardes) ?u8 { +fn openViewInner(p: *Pardes) ?View.Id { // Every view taken: one kept for a client that has not come back // for it (Views.away) goes first. ponytail: no timer lets one go; // until its place is wanted it costs a parked slot, and a terminal @@ -1176,14 +1176,14 @@ fn openViewInner(p: *Pardes) ?u8 { // loaded from a dump has no queue (Replica.initDump). p.settle(); p.needs_frame = true; - return Views.open(p); + return .at(Views.open(p) orelse return null); } /// The client of view `k` gone: its view goes, the others stay. The /// last one stays the session's own. pub const closeView = pardes.tape.taped(closeViewInner); -fn closeViewInner(p: *Pardes, k: u8) void { - Views.close(p, k); +fn closeViewInner(p: *Pardes, k: View.Id) void { + Views.close(p, k.index()); p.sync(); // What its sync queued (a terminal it sized, sized again) done here, // in its own unit on every side: the session's next pump is another @@ -1196,8 +1196,8 @@ fn closeViewInner(p: *Pardes, k: u8) void { /// goes, and the session's own is laid out as it was (Views.closeKeeping), /// which the client's rejoin copies. Settled as `closeView` is. pub const leaveView = pardes.tape.taped(leaveViewInner); -fn leaveViewInner(p: *Pardes, k: u8) void { - Views.closeKeeping(p, k); +fn leaveViewInner(p: *Pardes, k: View.Id) void { + Views.closeKeeping(p, k.index()); p.sync(); p.settle(); } @@ -1205,29 +1205,29 @@ fn leaveViewInner(p: *Pardes, k: u8) void { /// The client of view `k` gone, to join again for it (an Upgrade's /// rejoin, a divergence's): its view kept as it is (Views.away). pub const awayView = pardes.tape.taped(awayViewInner); -fn awayViewInner(p: *Pardes, k: u8) void { - Views.away(p, k); +fn awayViewInner(p: *Pardes, k: View.Id) void { + Views.away(p, k.index()); } /// A client back for view `k`, kept for it (`awayView`): its own again, /// as it left it; false when it was let go meanwhile. Settled as /// `openView` is, for the join's dump next. pub const rejoinView = pardes.tape.taped(rejoinViewInner); -fn rejoinViewInner(p: *Pardes, k: u8) bool { - if (!Views.isAway(p, k)) return false; - p.views_away &= ~(@as(u8, 1) << @intCast(k)); +fn rejoinViewInner(p: *Pardes, k: View.Id) bool { + if (!Views.isAway(p, k.index())) return false; + p.views_away &= ~(@as(u8, 1) << @intCast(k.index())); p.settle(); p.needs_frame = true; return true; } /// Into view `k`, before the input its client sent. -pub fn toView(p: *Pardes, k: u8) void { +pub fn toView(p: *Pardes, k: View.Id) void { // By hand, not `taped`: the live view asked again records nothing (a frontend asks before every input). - if (k == p.live) return; + if (k.index() == p.live) return; const taped = pardes.tape.enter(p, .{ .to_view = k }); defer pardes.tape.leave(p, taped); - Views.to(p, k); + Views.to(p, k.index()); } /// Something changed the core without going through `update` -- a watched @@ -1239,10 +1239,10 @@ fn invalidateInner(p: *Pardes) void { } pub const reloadWatchedFile = pardes.tape.taped(reloadWatchedFileInner); -fn reloadWatchedFileInner(p: *Pardes, id: u8, bytes: []const u8) bool { +fn reloadWatchedFileInner(p: *Pardes, id: Pane.Id, bytes: []const u8) bool { p.invalidate(); - look.invalidateLookHover(p, id); - const applied = p.applyWatchedFileChanged(id, bytes); + look.invalidateLookHover(p, id.index()); + const applied = p.applyWatchedFileChanged(id.index(), bytes); _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept }); p.sync(); return applied; @@ -1341,31 +1341,31 @@ pub fn hostKillJob(p: *const Pardes, id: usize) bool { /// on it, or written to it from now on, hears `error shell gone` /// rather than wait for a prompt that never comes. pub const shellFailed = pardes.tape.taped(shellFailedInner); -fn shellFailedInner(p: *Pardes, id: u8, err: anyerror) void { - const pane = p.panes[id] orelse return; +fn shellFailedInner(p: *Pardes, id: Pane.Id, err: anyerror) void { + const pane = p.panes[id.index()] orelse return; pane.shell_failed = true; ctlfs.pty.shellGone(p, pane, false); - p.sayShellFailure(id, err); + p.sayShellFailure(id.index(), err); // A command that never started ended: `exit 127`, as a shell says of // a command it could not run, so a follower waiting on its exit // hears one, its tag stops saying it runs, and Kill finds nothing. if (pane.command != null and !pane.command_done) { pane.command_pty = false; - pane.commandDone(p, id, 127); + pane.commandDone(p, id.index(), 127); } else if (pane.command == null and !pane.had_shell) { // A Term whose shell never ran: no dead pane left behind; the // write that asked for it has failed with why. A terminal whose // shell was started again (pty/ctl exec) keeps its pane. - p.unplaced.set(id); + p.unplaced.set(id.index()); } } /// A shell started again in a terminal whose shell runs (pty/ctl's /// exec) did not start: the host kept the running one, so only said. pub const restartFailed = pardes.tape.taped(restartFailedInner); -fn restartFailedInner(p: *Pardes, id: u8, err: anyerror) void { - if (p.panes[id] == null) return; - p.sayShellFailure(id, err); +fn restartFailedInner(p: *Pardes, id: Pane.Id, err: anyerror) void { + if (p.panes[id.index()] == null) return; + p.sayShellFailure(id.index(), err); } fn sayShellFailure(p: *Pardes, id: u8, err: anyerror) void { @@ -1379,11 +1379,11 @@ fn sayShellFailure(p: *Pardes, id: u8, err: anyerror) void { const name = p.tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); p.reportFailure(id, if (name) |n| said.print("shell: interpreter {s} not found", .{n}) else "shell: interpreter not found"); } else { - p.reportError(id, "shell", err); + p.reportError(.at(id), "shell", err); } // A 9P write that asked for the shell (pty/ctl's exec), waiting on // it, fails with what was said, as a failed Save's does. - p.noteLateFailure(id); + p.noteLateFailure(.at(id)); } /// The program the shell's `#!` names that is not there, in `out`. @@ -1406,8 +1406,8 @@ fn parentTrouble(tape: *pardes.tape.Tape, path: []const u8, err: anyerror) struc } pub const saveFailed = pardes.tape.taped(saveFailedInner); -fn saveFailedInner(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { - if (p.panes[id]) |pane| if (pane.file) |*f| { +fn saveFailedInner(p: *Pardes, id: Pane.Id, path: []const u8, err: anyerror) void { + if (p.panes[id.index()]) |pane| if (pane.file) |*f| { // The `-%` spelling fs.zig already uses for "make this dirty". f.saved_revision = f.revision -% 1; }; @@ -1416,9 +1416,9 @@ fn saveFailedInner(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { // a mount reads as ENOENT; EACCES when one above refuses. const parent = parentTrouble(p.tape, path, err); if (parent.denied) - p.reportFailure(id, what.print("Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]})) + p.reportFailure(id.index(), what.print("Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]})) else if (parent.missing) - p.reportFailure(id, what.print("Save {s}: no such directory", .{path[0..@min(path.len, limits.host_path_cap)]})) + p.reportFailure(id.index(), what.print("Save {s}: no such directory", .{path[0..@min(path.len, limits.host_path_cap)]})) else p.reportError(id, what.print("Save {s}", .{path[0..@min(path.len, limits.host_path_cap)]}), err); p.noteLateFailure(id); @@ -1443,10 +1443,10 @@ fn dumpFailedInner(p: *Pardes, path: []const u8, err: anyerror) void { else if (parent.missing) p.reportFailure(v.active, said.print("{s}: no such directory", .{operation})) else - p.reportError(v.active, operation, err); + p.reportError(.at(v.active), operation, err); // In the words the message row has, so the write's err is the one // record of it (its msg goes: 9p_io, dropMessage). - p.noteLateFailure(v.active); + p.noteLateFailure(.at(v.active)); } pub fn fsPayload(p: *const Pardes, r: ctlfs.Reply) []const u8 { @@ -1683,7 +1683,7 @@ fn updateInner(p: *Pardes, ev: Event) void { pane.command_pty = false; } else p.removePane(e.pane, null) catch |err| { pane.body.mode = .normal; - p.reportError(e.pane, "terminal exited; Del retries close", err); + p.reportError(.at(e.pane), "terminal exited; Del retries close", err); }, .lsp_resp => |r| @import("lsp/Ask.zig").lspResponse(p, r.id, r.rows), .pipe_resp => |r| Pipe.pipeResponse(p, r.id, r.success, r.outputs, r.failure), @@ -1698,12 +1698,12 @@ fn updateInner(p: *Pardes, ev: Event) void { .mouse => |m| mouse.handleMouse(p, m), .paste => |bytes| { p.typedInto(); - edit.applyPaste(p, bytes) catch |err| p.reportError(v.active, "paste", err); + edit.applyPaste(p, bytes) catch |err| p.reportError(.at(v.active), "paste", err); }, .command => |line| _ = p.executeBuiltinLine(v.active, line), .focus => |focused| { v.window_focused = focused; - if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(v.active, newer_build_words); + if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(.at(v.active), newer_build_words); }, .handed => |h| p.handover.finish(p, h.seq, h.to, h.failure), .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*), @@ -1812,12 +1812,12 @@ pub const SavePath = Effect.Buf(effect_path_cap); /// What was said of a failure just now on pane `id` is also the waiting /// 9P write's (9p_io, `fs.late_failure`). pub const noteLateFailure = pardes.tape.taped(noteLateFailureInner); -fn noteLateFailureInner(p: *Pardes, id: usize) void { +fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void { // Said by reportFailure just now: its words fitted whole, the // reason kept; else what the message row has. const said = if (p.fs.said_at == p.fs.failures and p.fs.said_len > 0) p.fs.said[0..p.fs.said_len] - else if (p.panes[id]) |pane| pane.msg[0..pane.msg_len] else return; + else if (p.panes[id.index()]) |pane| pane.msg[0..pane.msg_len] else return; const kept = @import("Messages.zig").clip(said, p.fs.late_failure.len); @memcpy(p.fs.late_failure[0..kept.len], kept); p.fs.late_failure_len = @intCast(kept.len); @@ -1846,7 +1846,7 @@ fn windowOpacityDoneInner(p: *Pardes, applied: u8, failure: ?[]const u8) void { // the same command will arm a new request. p.settings.window_opacity = applied; var buf: pardes.Kind.Buf(240 + 16) = .{}; - p.setMessage(p.view().active, buf.print("WindowOpacity: {s}", .{reason})); + p.setMessage(.at(p.view().active), buf.print("WindowOpacity: {s}", .{reason})); } /// What changed written out, at the end of a step and at the end. @@ -1864,7 +1864,7 @@ pub fn sync(p: *Pardes) void { // again: one logged or answered names this pane for good. Its // rows, if it had any, go where a closed pane's go; no other // pane moves (a pane dragged short keeps its rows). - if (p.panes[id] != null) p.removePane(id, null) catch |err| p.reportError(v.active, "open", err); + if (p.panes[id] != null) p.removePane(id, null) catch |err| p.reportError(.at(v.active), "open", err); } // A file opened or closed this step: the kept list follows. p.saveRecent(); @@ -2405,7 +2405,7 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} // initial shell spawn/geometry - p.acknowledgeShell(0, "/bin/sh", false); + p.acknowledgeShell(.at(0), "/bin/sh", false); // The Term word names the shell the host ran, and opens another of it. const pane = p.panes[0].?; @@ -2635,7 +2635,7 @@ test "compact tag commands stay beside their own prefix across layout changes" { const f = layout.findPane(p, p.view().active).?; layout.insert(p, f.col, f.idx + 1, below_id); layout.splitBelow(p, p.view().active, below); - p.setCwd(below_id, "/a/deep/dir/whose/name/eats/the/right/pad/the/end/of/its/own/tagline"); + p.setCwd(.at(below_id), "/a/deep/dir/whose/name/eats/the/right/pad/the/end/of/its/own/tagline"); p.sync(); while (p.nextEffect()) |_| {} @@ -2673,7 +2673,7 @@ test "Term spawns a raw shell in the caller's directory" { const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} - p.setCwd(0, "/tmp/newtty-dir"); + p.setCwd(.at(0), "/tmp/newtty-dir"); try std.testing.expect(p.executeBuiltinLine(0, "Term")); const free = p.view().active; @@ -2771,10 +2771,10 @@ test "unknown Exec from a document runs as a command pane in its directory, type const p = try Pardes.init(gpa, .{}); defer p.deinit(); while (p.nextEffect()) |_| {} - p.acknowledgeShell(0, "/bin/sh", false); + p.acknowledgeShell(.at(0), "/bin/sh", false); // A terminal free at a prompt in the same directory is not borrowed. - p.setCwd(0, "/tmp/pardes-image-dir"); + p.setCwd(.at(0), "/tmp/pardes-image-dir"); const image_doc = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-image-dir/pic.ppm", null); try std.testing.expectEqualStrings("/tmp/pardes-image-dir", Pardes.paneDir(image_doc)); const dst = exec.execute(p, 1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun; @@ -2800,7 +2800,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty defer p.deinit(); while (p.nextEffect()) |_| {} - p.setCwd(0, "/tmp/pardes-taken"); + p.setCwd(.at(0), "/tmp/pardes-taken"); // vim, a pager, an agent: the host answers that this pane's tty is no // longer the prompt pardes forked var host: FakeTtyQuery = .{}; @@ -3110,7 +3110,7 @@ test "a restored terminal's tag names neither the REPL it was nor the shell it h const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); while (p.nextEffect()) |_| {} - p.acknowledgeShell(0, "/usr/bin/fish", true); + p.acknowledgeShell(.at(0), "/usr/bin/fish", true); var host: FakeTtyQuery = .{}; host.install(p); try std.testing.expect(p.executeBuiltinLine(0, "Repl python")); @@ -3131,7 +3131,7 @@ test "a Term started by a shell's path keeps the path in its Term+ word" { while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Term /bin/sh")); try std.testing.expect(p.view().active != 0); - p.acknowledgeShell(p.view().active, "/bin/sh", false); + p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+/bin/sh ")); } @@ -3157,7 +3157,7 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" { try std.testing.expect(p.executeBuiltinLine(0, "Term+sh")); try std.testing.expect(p.view().active != 0); try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); - p.acknowledgeShell(p.view().active, "/bin/sh", false); + p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+sh ")); p.view().active = 0; // A shell that is not there is said, not quietly replaced, and the @@ -3184,7 +3184,7 @@ test "a command pane shows how its command ended, and the next command there run const p = try Pardes.init(gpa, .{}); defer p.deinit(); while (p.nextEffect()) |_| {} - p.setCwd(0, "/tmp/pardes-cmd"); + p.setCwd(.at(0), "/tmp/pardes-cmd"); _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); const dst = exec.execute(p, 1, "make -j8") orelse return error.NoCommandPane; @@ -3283,9 +3283,9 @@ test "a terminal its program gave back takes command lines again" { const p = try Pardes.init(gpa, .{}); defer p.deinit(); while (p.nextEffect()) |_| {} - p.acknowledgeShell(0, "/bin/sh", false); + p.acknowledgeShell(.at(0), "/bin/sh", false); - p.setCwd(0, "/tmp/pardes-taken-flip"); + p.setCwd(.at(0), "/tmp/pardes-taken-flip"); var host: FakeTtyQuery = .{}; host.install(p); host.taken[0] = true; @@ -3321,9 +3321,9 @@ test "the host is asked about a tty only where a command line is about to go" { var host: FakeTtyQuery = .{}; host.install(p); - p.setCwd(0, "/tmp/pardes-lazy-a"); - p.setCwd(1, "/tmp/pardes-lazy-b"); - p.setCwd(2, "/tmp/pardes-lazy-c"); + p.setCwd(.at(0), "/tmp/pardes-lazy-a"); + p.setCwd(.at(1), "/tmp/pardes-lazy-b"); + p.setCwd(.at(2), "/tmp/pardes-lazy-c"); _ = try p.render(frame.allocator()); p.update(.{ .key = .{ .cp = 'x' } }); diff --git a/core/Db.zig b/core/Db.zig index cbeee5fb..254eb4a7 100644 --- a/core/Db.zig +++ b/core/Db.zig @@ -329,7 +329,7 @@ fn importRecent(p: *Pardes, dir: []const u8) void { var path_buf: [4200]u8 = undefined; if (dir.len + "/recent".len >= std.Io.Dir.max_path_bytes) { var said: [160]u8 = undefined; - return p.setMessage(p.view().active, std.fmt.bufPrint(&said, "Recent: the files before the state file were not read: their directory's path is {d} bytes, too long", .{dir.len}) catch unreachable); // a number fits 160 + return p.setMessage(.at(p.view().active), std.fmt.bufPrint(&said, "Recent: the files before the state file were not read: their directory's path is {d} bytes, too long", .{dir.len}) catch unreachable); // a number fits 160 } pardes.turn.yield(); const listed = std.Io.Dir.cwd().readFileAlloc(io, std.fmt.bufPrint(&path_buf, "{s}/recent", .{dir}) catch "", gpa, .limited(recent_max)) catch null; diff --git a/core/Dir.zig b/core/Dir.zig index 3c74d704..a82887fb 100644 --- a/core/Dir.zig +++ b/core/Dir.zig @@ -184,7 +184,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void { const name = (if (std.mem.endsWith(u8, dir, "/")) p.gpa.dupe(u8, dir) else - std.mem.concat(p.gpa, u8, &.{ dir, "/" })) catch |err| return p.reportError(from, "look", err); + std.mem.concat(p.gpa, u8, &.{ dir, "/" })) catch |err| return p.reportError(.at(from), "look", err); for (p.panes, 0..) |slot, i| { const pane = slot orelse continue; const f = pane.file orelse continue; @@ -196,14 +196,14 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void { const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit const names = read(p.tape, p.gpa, dir) catch |err| { p.gpa.free(name); - return p.reportError(from, what, err); + return p.reportError(.at(from), what, err); }; const free = p.freeSlot() orelse { p.gpa.free(name); p.gpa.free(names); - return p.reportError(from, "look", error.NoPaneSlots); + return p.reportError(.at(from), "look", error.NoPaneSlots); }; - const pane = open(p, free, name, names) catch |err| return p.reportError(from, "look", err); + const pane = open(p, free, name, names) catch |err| return p.reportError(.at(from), "look", err); const failures = p.fs.failures; layout.placeNew(p, from, from, free, .doc); // Refused a place: that is the look's one failure. @@ -240,7 +240,7 @@ pub fn show(p: *Pardes, from: usize, id: usize) void { var said: [limits.host_path_cap + 16]u8 = undefined; const name = pane.file.?.path; const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit - refresh(p, id) catch |err| return p.reportError(from, what, err); + refresh(p, id) catch |err| return p.reportError(.at(from), what, err); // Closed while the turn was out: nothing to give the keyboard to. const now = p.panes[id] orelse return; if (now.serial == serial) p.view().active = id; diff --git a/core/Editor.zig b/core/Editor.zig index 82c93640..9781d857 100644 --- a/core/Editor.zig +++ b/core/Editor.zig @@ -80,5 +80,5 @@ pub fn reportError(e: Editor, err: anyerror) void { e.failed.* = true; return; } - e.p.reportError(e.p.view().active, "edit", err); + e.p.reportError(.at(e.p.view().active), "edit", err); } diff --git a/core/Effect.zig b/core/Effect.zig index bc952b8b..f0e18335 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -184,7 +184,7 @@ fn performInner(p: *Pardes, e: Effect) void { return; } if (!pane.isTerminal()) return; - const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err); + const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(.at(st.pane), "Save", err); defer p.gpa.free(text); if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still| ctlfs.events.noteLogAs(p, .save, still, st.path.slice()); @@ -259,7 +259,7 @@ fn performInner(p: *Pardes, e: Effect) void { .detach => |d| if (v.detach) |f| f(p.host.ctx) else - p.reportError(d.pane, "detach", error.NotAttached), + p.reportError(.at(d.pane), "detach", error.NotAttached), // dlopen is the same on every host, so none has a method of its // own; a replica's core holds no library (what it brought comes in // the event this taped). @@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/"); // The in-process filesystem reports the same way a real host does, // so an OOM there leaves the pane dirty rather than looking saved. - if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(id, path, error.OutOfMemory); + if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; @@ -298,7 +298,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void { const pane = p.panes[id] orelse return; const f = if (pane.file) |*file| file else return; - const owned = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "Save", err); + const owned = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(id), "Save", err); p.gpa.free(f.path); f.path = owned; f.output = null; @@ -358,7 +358,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file while (p.nextEffect()) |_| {} const source: usize = 2; - p.setCwd(source, "/tmp/pardes-save-dir"); + p.setCwd(.at(source), "/tmp/pardes-save-dir"); try std.testing.expect(p.executeBuiltinLine(source, "New")); const id = p.view().active; const np = p.panes[id].?; @@ -391,7 +391,7 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - p.setCwd(0, "/tmp/pardes-tty-save"); + p.setCwd(.at(0), "/tmp/pardes-tty-save"); p.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } }); while (p.nextEffect()) |_| {} @@ -422,7 +422,7 @@ test "Save on an output buffer writes its rows out and leaves the buffer alone" while (p.nextEffect()) |_| {} const source: usize = 2; - p.setCwd(source, "/tmp/pardes-output-save"); + p.setCwd(.at(source), "/tmp/pardes-output-save"); try std.testing.expect(p.executeBuiltinLine(source, "Help")); p.sync(); // the frame boundary that gives the new pane its geometry while (p.nextEffect()) |_| {} @@ -473,7 +473,7 @@ test "Save takes the path as an argument, relative to the pane's own directory" defer p.deinit(); while (p.nextEffect()) |_| {} const pane = p.panes[0].?; - p.setCwd(0, "/tmp/pardes-arg-save"); + p.setCwd(.at(0), "/tmp/pardes-arg-save"); p.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } }); while (p.nextEffect()) |_| {} @@ -512,7 +512,7 @@ test "a save the host could not do leaves the pane dirty" { const Refusing = struct { fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void { const core: *Pardes = @ptrCast(@alignCast(ctx.?)); - core.saveFailed(pane, "/x/y.txt", error.PermissionDenied); + core.saveFailed(.at(pane), "/x/y.txt", error.PermissionDenied); } }; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -576,7 +576,7 @@ test "saves armed in one batch stay with their own panes" { const tty_id = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(tty_id, "/tmp/pardes-batch"); - p.setCwd(tty_id, "/tmp/pardes-batch"); + p.setCwd(.at(tty_id), "/tmp/pardes-batch"); p.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } }); const file = try p.setTestFile("file text\n"); const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane; @@ -659,7 +659,7 @@ test "a save path that names no file is refused before anything is rewritten" { while (p.nextEffect()) |_| {} const source: usize = 2; - p.setCwd(source, "/tmp/pardes-refuse"); + p.setCwd(.at(source), "/tmp/pardes-refuse"); try std.testing.expect(p.executeBuiltinLine(source, "New")); const id = p.view().active; const scratch = p.panes[id].?; @@ -689,7 +689,7 @@ test "a Save the host could not do logs no save record" { const vtable: Host.VTable = .{ .write_file = write }; fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void { const f: *@This() = @ptrCast(@alignCast(ctx.?)); - f.core.saveFailed(pane, path, error.AccessDenied); + f.core.saveFailed(.at(pane), path, error.AccessDenied); } }; var host: Failing = .{ .core = p }; diff --git a/core/File.zig b/core/File.zig index 820447ac..8337b833 100644 --- a/core/File.zig +++ b/core/File.zig @@ -786,7 +786,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who f.syntax_dirty = true; if (f.pager) f.pager_diff = looksLikeDiff(f.content[0..@min(new_len, 64 * 1024)]); if (undo_gone) for (p.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.file) |*state| if (state == f) p.setMessage(id, "undo keeps the last two texts replaced whole: the steps before them are gone"); + if (slot) |pane| if (pane.file) |*state| if (state == f) p.setMessage(.at(id), "undo keeps the last two texts replaced whole: the steps before them are gone"); }; for (twins[0..ntwins], 0..) |id, i| { const t = p.panes[id].?; @@ -1287,9 +1287,9 @@ fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { if (slot == pane) break i; } else return; // nameBuffer frees nothing of `path`: it keeps the name it ends. - const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "undo", err); + const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(id), "undo", err); defer p.gpa.free(back); - pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(id, "undo", err); + pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(.at(id), "undo", err); history.gen = snap.gen; f.saved_hash = snap.saved_hash; f.saved_len = snap.saved_len; @@ -1464,8 +1464,8 @@ const Gap = struct { /// ` deleted on disk (Save writes it again)`, logged `changed /// deleted`. pub const deleted = pardes.tape.taped(deletedInner); -fn deletedInner(p: *Pardes, id: u8) void { - const pane = p.panes[id] orelse return; +fn deletedInner(p: *Pardes, id: Pane.Id) void { + const pane = p.panes[id.index()] orelse return; const f = if (pane.file) |*file| file else return; if (f.disk_gone) return; f.disk_gone = true; @@ -1497,7 +1497,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { f.disk_newer = disk; f.disk_newer_warned = false; var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{}; - p.setMessage(id, said.print("{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]})); + p.setMessage(.at(id), said.print("{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]})); var rec: [16]u8 = undefined; pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d}", .{pane.serial}) catch unreachable); // a u32 fits 16 return; @@ -1506,8 +1506,8 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { // Logged as the dirty case is, with what became of it. var rec: [32]u8 = undefined; pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch unreachable); // a u32 fits 32 - pushUndo(p, pane) catch |err| return p.reportError(id, "reload", err); - const new = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(id, "reload", err); + pushUndo(p, pane) catch |err| return p.reportError(.at(id), "reload", err); + const new = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(.at(id), "reload", err); setContent(p, f, new); f.saved_revision = f.revision; restoreSnap(p.settings.tab, pane, f, .{ .cur_row = pane.body.cur_row, .cur_col = pane.body.cur_col, .vsel = pane.body.vsel }); diff --git a/core/Handover.zig b/core/Handover.zig index 5347fb95..bcf42c31 100644 --- a/core/Handover.zig +++ b/core/Handover.zig @@ -110,15 +110,15 @@ pub fn begin(h: *Handover, p: *Pardes, carried: Kind, at: usize) void { }, } const said = if (carried == .pane) at else ids[0]; - if (h.flying) return p.setMessage(said, "a pane is already on its way to another window"); + if (h.flying) return p.setMessage(.at(said), "a pane is already on its way to another window"); for (ids[0..n]) |id| { const pane = p.panes[id] orelse return; - if (pane.file == null) return p.setMessage(said, if (pane.isTerminal()) + if (pane.file == null) return p.setMessage(.at(said), if (pane.isTerminal()) "a terminal stays in its window: its shell is this window's child" else "only text panes go to another window, for now"); } - const bytes = dumpCarried(p, carried, at, ids[0..n], h.seq +% 1) catch |err| return p.reportError(said, "handover", err); + const bytes = dumpCarried(p, carried, at, ids[0..n], h.seq +% 1) catch |err| return p.reportError(.at(said), "handover", err); h.deinit(p.gpa); h.bytes = bytes; h.seq +%= 1; @@ -131,7 +131,7 @@ pub fn begin(h: *Handover, p: *Pardes, carried: Kind, at: usize) void { h.serials[i] = pane.serial; h.revisions[i] = pane.file.?.revision; } - p.setMessage(said, if (carried == .pane) "to a new window…" else "the column, to a new window…"); + p.setMessage(.at(said), if (carried == .pane) "to a new window…" else "the column, to a new window…"); p.emit(.{ .hand_over = .{ .seq = h.seq } }); } @@ -171,14 +171,14 @@ pub fn finish(h: *Handover, p: *Pardes, seq: u32, to: []const u8, failure: ?[]co } p.removePane(id, null) catch |err| { kept += 1; - p.reportError(id, "handover", err); + p.reportError(.at(id), "handover", err); }; } if (h.carried == .column) if (layout.columnBySerial(p, h.column_serial)) |c| { if (v.cols[c].n == 0 and v.ncol > 1) layout.dropColumn(p, c); }; layout.compute(p); - p.setMessage(v.active, if (kept == 0) + p.setMessage(.at(v.active), if (kept == 0) std.fmt.bufPrint(&buf, "moved to {s}", .{to}) catch "moved" else std.fmt.bufPrint(&buf, "copied to {s}; edited on the way, kept here too", .{to}) catch "copied"); diff --git a/core/Jump.zig b/core/Jump.zig index 6d12495e..26b3c4d9 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -267,7 +267,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { const older = delta < 0; // At an end of the list: said, not a step that silently does nothing. if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n)) - return p.setMessage(v.active, if (older) "Back: nothing further back" else "Forward: nothing further on"); + return p.setMessage(.at(v.active), if (older) "Back: nothing further back" else "Forward: nothing further on"); var next = if (older) v.jumps.cur - 1 else v.jumps.cur + 1; // A terminal or a scratch has no file to keep to: the step is global. if (p.panes[v.active]) |here| if (Pardes.recentPlace(here)) |place| if (place.path.len > 0) { @@ -298,7 +298,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { // stuck on one that cannot open. if (found == null or !Pardes.recentKeeps(p.tape, found.?.path)) { var said: Kind.Buf(recent_path_cap + 32) = .{}; - if (found) |e| p.setMessage(v.active, said.print("{s}: deleted, skipped", .{e.path[0..@min(e.path.len, recent_path_cap)]})); + if (found) |e| p.setMessage(.at(v.active), said.print("{s}: deleted, skipped", .{e.path[0..@min(e.path.len, recent_path_cap)]})); const hash = j.path_hash; var w: usize = 0; var cur = v.jumps.cur; diff --git a/core/Kind.zig b/core/Kind.zig index 13ef8edd..05a813f3 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -1013,7 +1013,7 @@ const Call = struct { return o; }; const p = cl.p orelse return o; - if (o.said.len > 0) if (o.err) p.reportFailure(cl.id, o.said) else p.setMessage(cl.id, o.said); + if (o.said.len > 0) if (o.err) p.reportFailure(cl.id, o.said) else p.setMessage(.at(cl.id), o.said); if (o.pane_name.len > 0) textPane(p, cl.id, cl.slot, o.pane_name, o.pane_text); if (o.look.len > 0) @import("look.zig").lookAt(p, cl.id, o.look); if (o.exec.len > 0) @import("mouse.zig").dispatchPointerBuiltin(p, cl.id, pardes.config.exec_cmd, o.exec, null); @@ -1052,8 +1052,8 @@ fn moreFound(p: *Pardes, id: usize, rows: []const u8) void { const rp = p.panes[pane.search_pane orelse return] orelse return; const rf = if (rp.file) |*f| f else return; const o = if (rf.output) |*x| x else return; - const content = std.mem.concat(p.gpa, u8, &.{ rf.content, rows }) catch |err| return p.reportError(id, "found", err); - pardes.panes.Output.fillResults(p, id, std.Io.Dir.path.dirname(rf.path) orelse p.sessionDir(), .search, o.arg(), content, null) catch |err| p.reportError(id, "found", err); + const content = std.mem.concat(p.gpa, u8, &.{ rf.content, rows }) catch |err| return p.reportError(.at(id), "found", err); + pardes.panes.Output.fillResults(p, id, std.Io.Dir.path.dirname(rf.path) orelse p.sessionDir(), .search, o.arg(), content, null) catch |err| p.reportError(.at(id), "found", err); } fn same(o: Outcome) Outcome { @@ -1299,8 +1299,8 @@ pub var seed_base: u64 = 0; /// kind's pane, a Look of one going to its kind (look.zig lookKind). fn textPane(p: *Pardes, id: usize, slot: *const Slot, name: []const u8, text: []const u8) void { const dir = std.Io.Dir.path.dirname(slot.path) orelse p.sessionDir(); - const content = p.gpa.dupe(u8, text) catch |err| return p.reportError(id, name, err); - pardes.panes.Output.fillResults(p, id, dir, .kind, name, content, null) catch |err| p.reportError(id, name, err); + const content = p.gpa.dupe(u8, text) catch |err| return p.reportError(.at(id), name, err); + pardes.panes.Output.fillResults(p, id, dir, .kind, name, content, null) catch |err| p.reportError(.at(id), name, err); } /// A kind for tests of the core's side of a kind's pane, no library: a diff --git a/core/Messages.zig b/core/Messages.zig index 767eb297..1fb232c7 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -127,14 +127,14 @@ pub const Message = struct { /// A status updates the message line in place (a progress count does not /// pile up); a message is an event, and stacks. pub const setStatus = pardes.tape.taped(setStatusInner); -fn setStatusInner(p: *Pardes, id: usize, text: []const u8) void { - showMessage(p, id, text, false); +fn setStatusInner(p: *Pardes, id: Pane.Id, text: []const u8) void { + showMessage(p, id.index(), text, false); } pub const setMessage = pardes.tape.taped(setMessageInner); -fn setMessageInner(p: *Pardes, id: usize, text: []const u8) void { - logMessage(p, id, text); - showMessage(p, id, text, true); +fn setMessageInner(p: *Pardes, id: Pane.Id, text: []const u8) void { + logMessage(p, id.index(), text); + showMessage(p, id.index(), text, true); } fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { @@ -346,7 +346,7 @@ pub fn dialReason(err: anyerror) ?[]const u8 { } pub const reportError = pardes.tape.taped(reportErrorInner); -fn reportErrorInner(p: *Pardes, id: usize, operation: []const u8, err: anyerror) void { +fn reportErrorInner(p: *Pardes, id: Pane.Id, operation: []const u8, err: anyerror) void { // Room for an operation naming the longest path and the reason after // it: a shorter one cut the reason off (`Save /long…`), and the reason // is what a failure is for. Where it must be shorter, the path gives. @@ -356,7 +356,7 @@ fn reportErrorInner(p: *Pardes, id: usize, operation: []const u8, err: anyerror) // A peer out of reach says so, not the error's name (`dial`). if (dialReason(err)) |why| { w.print("dial failed: {s}", .{why}) catch {}; - return reportFailure(p, id, w.buffered()); + return reportFailure(p, id.index(), w.buffered()); } // Every route that opens a pane says the cap the same way. if (err == error.NoPaneSlots or err == error.NoPaneRoom) { @@ -368,11 +368,11 @@ fn reportErrorInner(p: *Pardes, id: usize, operation: []const u8, err: anyerror) p.fs.no_pane_slot = true; @memcpy(p.fs.ename[0..w.buffered().len], w.buffered()); p.fs.no_pane_slot_len = @intCast(w.buffered().len); - return reportFailure(p, id, w.buffered()); + return reportFailure(p, id.index(), w.buffered()); } var words: [128]u8 = undefined; w.writeAll(errorWords(err, &words)) catch {}; - reportFailure(p, id, w.buffered()); + reportFailure(p, id.index(), w.buffered()); } /// An error in a person's words, never its Zig name: the few that read @@ -444,9 +444,9 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { if (failing_write) { p.fs.unlogged = true; defer p.fs.unlogged = false; - return setMessage(p, id, text); + return setMessage(p, .at(id), text); } - setMessage(p, id, text); + setMessage(p, .at(id), text); } /// The one place that decides which transient lines a pane is showing and @@ -536,9 +536,9 @@ test "the message log keeps what the row forgets, and collapses repeats" { const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); - setMessage(p, 0, "14:32:07 saved /x.zig"); - setMessage(p, 0, "14:32:09 saved /x.zig"); // same event, later clock - setMessage(p, 0, "save: AccessDenied"); + setMessage(p, .at(0), "14:32:07 saved /x.zig"); + setMessage(p, .at(0), "14:32:09 saved /x.zig"); // same event, later clock + setMessage(p, .at(0), "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 2), p.messages.len); const first = p.messages.at(0).?; @@ -553,19 +553,19 @@ test "the message log keeps what the row forgets, and collapses repeats" { // failure must not be recorded as another's. p.newScratchBelow(0); const other = p.view().active; - setMessage(p, other, "save: AccessDenied"); + setMessage(p, .at(other), "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 3), p.messages.len); try std.testing.expectEqual(p.panes[other].?.serial, p.messages.at(2).?.serial); // Progress is NOT logged: it arrives several times a second for a whole // index and would push everything else out (`setStatus`). - setStatus(p, 0, "14:32:10 lsp rust-analyzer: Indexing 47%"); + setStatus(p, .at(0), "14:32:10 lsp rust-analyzer: Indexing 47%"); try std.testing.expectEqual(@as(usize, 3), p.messages.len); // The ring wraps rather than grows, and still reads oldest-first. for (0..limits.message_log + 5) |i| { var buf: [32]u8 = undefined; - setMessage(p, 0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); + setMessage(p, .at(0), std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); } try std.testing.expectEqual(@as(usize, limits.message_log), p.messages.len); try std.testing.expectEqualStrings("line 5", p.messages.at(0).?.slice()); @@ -621,8 +621,8 @@ test "with no frontend attached a message goes once it has lingered, on the cloc const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = p.panes[p.view().active].?; - p.setMessage(p.view().active, "said"); - p.setMessage(p.view().active, "said again"); + p.setMessage(.at(p.view().active), "said"); + p.setMessage(.at(p.view().active), "said again"); // Attached: it waits for input, however long. pane.msg_said_ms -= 60_000; p.update(.tick); @@ -638,7 +638,7 @@ test "with no frontend attached a message goes once it has lingered, on the cloc try std.testing.expectEqual(@as(u16, 0), pane.msg_len); try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); // A fresh one stays until its linger is up. - p.setMessage(p.view().active, "fresh"); + p.setMessage(.at(p.view().active), "fresh"); p.update(.tick); try std.testing.expect(pane.msg_len > 0); } @@ -679,7 +679,7 @@ test "a message lingers past the input that dismisses it, and goes" { try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again")); try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - setStatus(p, p.view().active, "progress 50%"); + setStatus(p, .at(p.view().active), "progress 50%"); try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); try std.testing.expectEqualStrings("progress 50%", pane.msg[0..pane.msg_len]); try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); @@ -695,10 +695,10 @@ test "messages stack, oldest on top, each on its own timing" { // `Verbose off` announced itself before it took effect. pane.msg_len = 0; pane.msg_life = .{}; - setMessage(p, p.view().active, "first"); + setMessage(p, .at(p.view().active), "first"); try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); // A second message stacks under the first instead of replacing it. - setMessage(p, p.view().active, "second"); + setMessage(p, .at(p.view().active), "second"); try std.testing.expectEqual(@as(u8, 1), pane.msg_older_len); try std.testing.expectEqualStrings("first", pane.msg_older[0].slice()); try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]); @@ -711,7 +711,7 @@ test "messages stack, oldest on top, each on its own timing" { try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase); try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); p.update(.tick); - setMessage(p, p.view().active, "third"); + setMessage(p, .at(p.view().active), "third"); try std.testing.expectEqual(@as(u8, 2), pane.msg_older_len); p.update(.{ .key = .{ .cp = 'h' } }); const linger = messageFrames(p.settings.message_linger_ms); @@ -724,24 +724,24 @@ test "messages stack, oldest on top, each on its own timing" { try std.testing.expectEqual(@as(u16, 0), pane.msg_len); try std.testing.expect(!p.animationActive()); // A status ticking in place does not pile up. - setStatus(p, p.view().active, "lsp 10%"); - setStatus(p, p.view().active, "lsp 20%"); + setStatus(p, .at(p.view().active), "lsp 10%"); + setStatus(p, .at(p.view().active), "lsp 20%"); try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); // Lines keep their rows: when the top one leaves, the one under it does // not move up, and the next message fills the gap instead. - setMessage(p, p.view().active, "top"); - setMessage(p, p.view().active, "under"); + setMessage(p, .at(p.view().active), "top"); + setMessage(p, .at(p.view().active), "under"); try std.testing.expectEqual(@as(u8, 0), pane.msg_older[0].slot); try std.testing.expectEqual(@as(u8, 1), pane.msg_slot); pane.removeOlderMessage(0); collectNotices(p, pane, p.view().rects[p.view().active], p.view().active); try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]); try std.testing.expectEqual(@as(u8, 2), pane.notices.span()); - setMessage(p, p.view().active, "fills"); + setMessage(p, .at(p.view().active), "fills"); try std.testing.expectEqual(@as(u8, 0), pane.msg_slot); try std.testing.expectEqual(@as(u8, 1), pane.msg_older[0].slot); // The stack keeps the newest few. - for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, p.view().active, text); + for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, .at(p.view().active), text); try std.testing.expectEqual(@as(u8, Pane.message_stack), pane.msg_older_len); try std.testing.expectEqualStrings("b", pane.msg_older[0].slice()); try std.testing.expectEqualStrings("e", pane.msg[0..pane.msg_len]); diff --git a/core/Output.zig b/core/Output.zig index 750baf8f..3ac9f521 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -452,7 +452,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c } File.setRows(p, rf, result_rows) catch |err| { locations.freeRows(p.gpa, result_rows); - p.reportError(id, "rows", err); + p.reportError(.at(id), "rows", err); }; p.view().active = id; if (traits(from).steps) { @@ -472,7 +472,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c } File.setRows(p, &np.file.?, result_rows) catch |err| { locations.freeRows(p.gpa, result_rows); - p.reportError(id, "rows", err); + p.reportError(.at(id), "rows", err); }; layout.placeNew(p, id, id, free, .doc); p.view().active = id; @@ -603,7 +603,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { // goes in the session's, where a look from it can still resolve. const dir = if (pardes.filesystem.localPath(own)) |local| (if (exec.kindOf(p.tape, local) == .directory) own else p.sessionDir()) else own; const free = p.freeSlot() orelse return p.gpa.free(content); - _ = open(p, free, dir, .unsaved, "", content) catch |err| return p.reportError(id, "+Unsaved", err); + _ = open(p, free, dir, .unsaved, "", content) catch |err| return p.reportError(.at(id), "+Unsaved", err); layout.placeNew(p, id, id, free, .doc); p.view().active = id; } diff --git a/core/Pipe.zig b/core/Pipe.zig index 85329971..cf61b78f 100644 --- a/core/Pipe.zig +++ b/core/Pipe.zig @@ -95,7 +95,7 @@ pub fn submitPipe(p: *Pardes, id: usize) void { const f = pane.file orelse return; if (!panes.Output.fileTraits(f.output).saves) return; } - const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(id, "pipe", err); + const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(id), "pipe", err); const how = switch (pane.prompt) { .pipe => |pipe| pipe, else => return, @@ -166,16 +166,16 @@ fn pipeFailed(p: *Pardes, wait: *const PendingPipe, failure: ?selection_pipe.Fai var out: std.Io.Writer.Allocating = .init(p.gpa); defer out.deinit(); const w = &out.writer; - w.print("| {s}\n\n", .{wait.command}) catch |err| return p.reportError(wait.pane, "pipe", err); + w.print("| {s}\n\n", .{wait.command}) catch |err| return p.reportError(.at(wait.pane), "pipe", err); if (wait.inputs.len > 1) if (failure) |fail| - w.print("selection {d} of {d}: ", .{ fail.index + 1, wait.inputs.len }) catch |err| return p.reportError(wait.pane, "pipe", err); - writeFailure(w, failure) catch |err| return p.reportError(wait.pane, "pipe", err); - const content = out.toOwnedSlice() catch |err| return p.reportError(wait.pane, "pipe", err); + w.print("selection {d} of {d}: ", .{ fail.index + 1, wait.inputs.len }) catch |err| return p.reportError(.at(wait.pane), "pipe", err); + writeFailure(w, failure) catch |err| return p.reportError(.at(wait.pane), "pipe", err); + const content = out.toOwnedSlice() catch |err| return p.reportError(.at(wait.pane), "pipe", err); const was = p.view().active; panes.Output.openErrors(p, wait.pane, content) catch |err| { p.gpa.free(content); // Nowhere to put the report is itself worth one line. - p.reportError(wait.pane, "pipe", err); + p.reportError(.at(wait.pane), "pipe", err); return; }; if (p.panes[was] != null) p.view().active = was; @@ -259,13 +259,13 @@ pub fn pipeResponse( .workspace => &p.global_tag, .input => return, }; - const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(wait.pane, "pipe", err); + const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(wait.pane), "pipe", err); const changed = if (t.what == .body) changed: { const f = pane.file orelse return; if (!panes.Output.fileTraits(f.output).saves) return; break :changed f.revision != wait.revision; } else std.hash.Wyhash.hash(0, content) != wait.sum; - if (changed) return p.reportError(wait.pane, "pipe", error.FileChangedWhileFiltering); + if (changed) return p.reportError(.at(wait.pane), "pipe", error.FileChangedWhileFiltering); if (wait.how == .ignore) return; if (wait.how == .keep) { @@ -296,14 +296,14 @@ pub fn pipeResponse( const cut = pipeCut(&wait, content, i) orelse return; const output = pipeOutput(&wait, outputs, content, i); if (output.len > selection_pipe.max_stdout_bytes) - return p.setMessage(wait.pane, std.fmt.bufPrint(&said, "pipe: an output of {d} bytes, past {d}: the text is left as it was", .{ output.len, selection_pipe.max_stdout_bytes }) catch unreachable); // two numbers fit 128 + return p.setMessage(.at(wait.pane), std.fmt.bufPrint(&said, "pipe: an output of {d} bytes, past {d}: the text is left as it was", .{ output.len, selection_pipe.max_stdout_bytes }) catch unreachable); // two numbers fit 128 total_output += output.len; // each under 1 MiB, at most max_selections of them if (total_output > selection_pipe.max_total_stdout_bytes) - return p.setMessage(wait.pane, std.fmt.bufPrint(&said, "pipe: {d} bytes of output in all, past {d}: the text is left as it was", .{ total_output, selection_pipe.max_total_stdout_bytes }) catch unreachable); // two numbers fit 128 - if (i > 0 and cut.lo < ops[i - 1].q1) return p.setMessage(wait.pane, "pipe: the selections overlap: the text is left as it was"); + return p.setMessage(.at(wait.pane), std.fmt.bufPrint(&said, "pipe: {d} bytes of output in all, past {d}: the text is left as it was", .{ total_output, selection_pipe.max_total_stdout_bytes }) catch unreachable); // two numbers fit 128 + if (i > 0 and cut.lo < ops[i - 1].q1) return p.setMessage(.at(wait.pane), "pipe: the selections overlap: the text is left as it was"); ops[i] = .{ .q0 = @intCast(cut.lo), .q1 = @intCast(cut.hi), .text = output }; } - const replacement = sam.apply(p.gpa, content, ops[0..n]) catch |err| return p.reportError(wait.pane, "pipe", err); + const replacement = sam.apply(p.gpa, content, ops[0..n]) catch |err| return p.reportError(.at(wait.pane), "pipe", err); var new_ranges: [panes.Text.max_selections]modal.Selection = undefined; var delta: isize = 0; for (ops[0..n], wait.ranges[0..n], new_ranges[0..n]) |op, range, *moved| { @@ -316,10 +316,10 @@ pub fn pipeResponse( // One async request is one history transaction, even at 64 cursors. edit.pushUndo(p.editor(), t) catch |err| { p.gpa.free(replacement); - return p.reportError(wait.pane, "pipe", err); + return p.reportError(.at(wait.pane), "pipe", err); }; - edit.setEditText(p.editor(), t, replacement) catch |err| return p.reportError(wait.pane, "pipe", err); - const now = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(wait.pane, "pipe", err); + edit.setEditText(p.editor(), t, replacement) catch |err| return p.reportError(.at(wait.pane), "pipe", err); + const now = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(wait.pane), "pipe", err); t.setRanges(p.settings.tab, now, new_ranges[0..n], &.{}, wait.primary, wait.explicit); t.select = false; t.show(p.settings.tab); diff --git a/core/Plumb.zig b/core/Plumb.zig index fdb7ad8c..406e7dd8 100644 --- a/core/Plumb.zig +++ b/core/Plumb.zig @@ -1001,7 +1001,7 @@ fn deliver(s: *Send, id: usize, port: Port, m: *const Msg) Sent { if (relative) m.wdir else "", if (relative) "/" else "", m.data, if (addr.len > 0) ":" else "", addr, }) catch { - p.reportError(id, "plumb", error.OutOfMemory); + p.reportError(.at(id), "plumb", error.OutOfMemory); return .done; }; const was = p.look_text; @@ -1025,10 +1025,10 @@ fn show(s: *Send, id: usize, m: *const Msg, diff: bool) void { const named = std.mem.eql(u8, filename, if (p.panes[id]) |pn| (if (pn.file) |f| f.path else "") else ""); const shown: usize = if (named) id else shown: { const name = if (filename.len > 0) filename else "+Plumbed"; - const free = p.freeSlot() orelse return p.reportError(id, "plumb", error.NoPaneSlots); + const free = p.freeSlot() orelse return p.reportError(.at(id), "plumb", error.NoPaneSlots); pardes.panes.newScratchFor(p, id, .scratch); const made = p.panes[free] orelse return; - @import("ninep/pane.zig").nameBuffer(p, free, name, false) catch |err| return p.reportError(id, "plumb", err); + @import("ninep/pane.zig").nameBuffer(p, free, name, false) catch |err| return p.reportError(.at(id), "plumb", err); const f = &made.file.?; _ = pardes.panes.File.replace(p, f, 0, f.content.len, m.data); f.saved_revision = f.revision; @@ -1075,8 +1075,8 @@ fn openInKind(s: *Send, id: usize, k: u8, m: *const Msg) void { p.view().active = i; return; }; - const free = p.freeSlot() orelse return p.reportError(id, "plumb", error.NoPaneSlots); - const made = Kind.openFile(p, free, k, path) catch |err| return p.reportError(id, path, err); + const free = p.freeSlot() orelse return p.reportError(.at(id), "plumb", error.NoPaneSlots); + const made = Kind.openFile(p, free, k, path) catch |err| return p.reportError(.at(id), path, err); if (made.addon.?.refused.len > 0) { made.vweight = 0; p.unplaced.set(free); diff --git a/core/Query.zig b/core/Query.zig index ce83a6ac..784e6af4 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -248,7 +248,7 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo if (focus) toLineOne(p, from); return; } - const line = std.mem.concat(p.scratch.allocator(), u8, &.{ wordOf(source), if (source == .text) "" else " ", arg }) catch |err| return p.reportError(from, "search", err); + const line = std.mem.concat(p.scratch.allocator(), u8, &.{ wordOf(source), if (source == .text) "" else " ", arg }) catch |err| return p.reportError(.at(from), "search", err); var id: usize = undefined; const existing = ofOwner(p, owner.serial); if (existing) |reused| { @@ -259,7 +259,7 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo if (q.frozen and q.saved == null) q.saved = save(p, rp, q) catch null; q.frozen = false; const f = &rp.file.?; - const new = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch |err| return p.reportError(from, "search", err); + const new = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch |err| return p.reportError(.at(from), "search", err); File.setContent(p, f, new); q.reset(p); if (rp.collapsed) layout.toggleCollapse(p, id); @@ -286,18 +286,18 @@ pub const born_rows: u16 = 8; fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize { const owner = p.panes[owner_id] orelse return null; const free = p.freeSlot() orelse { - p.reportError(owner_id, "search", error.NoPaneSlots); + p.reportError(.at(owner_id), "search", error.NoPaneSlots); return null; }; const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(owner); const content = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return null; const np = Output.open(p, free, dir, .search, "", content) catch |err| { p.gpa.free(content); - p.reportError(owner_id, "search", err); + p.reportError(.at(owner_id), "search", err); return null; }; const q = p.gpa.create(Query) catch { - p.reportError(owner_id, "search", error.OutOfMemory); + p.reportError(.at(owner_id), "search", error.OutOfMemory); return null; }; q.* = .{ .owner = owner.serial }; @@ -343,7 +343,7 @@ pub fn toLineOne(p: *Pardes, id: usize) void { t.nsel = 0; t.cur_pinned = true; rp.query.?.seen_row = 0; - edit.enterInsert(p.editor(), t, .line_end, 1) catch |err| return p.reportError(id, "query", err); + edit.enterInsert(p.editor(), t, .line_end, 1) catch |err| return p.reportError(.at(id), "query", err); showCurrent(rp); } @@ -562,7 +562,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { const asked = parse(line); if (changed) { const was = q.source; - const new_asked = p.gpa.dupe(u8, line) catch |err| return p.reportError(id, "search", err); + const new_asked = p.gpa.dupe(u8, line) catch |err| return p.reportError(.at(id), "search", err); p.gpa.free(q.asked); q.asked = new_asked; q.made_gen = std.math.maxInt(u64); @@ -615,7 +615,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { q.waited = 0; q.made_gen = gen; q.made_rev = of_.revision; - makeTextRows(p, id, oid, false) catch |err| p.reportError(id, "search", err); + makeTextRows(p, id, oid, false) catch |err| p.reportError(.at(id), "search", err); }, .all => { if (changed) for (p.panes) |slot| { @@ -634,13 +634,13 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { if (gen == q.made_gen and !changed) return; if (!changed and !tick) return; q.made_gen = gen; - makeAllRows(p, id) catch |err| p.reportError(id, "search", err); + makeAllRows(p, id) catch |err| p.reportError(.at(id), "search", err); }, .find, .recent, .panes, .symbols => { if (changed) q.names.typed(p.gpa, a.pat) else if (q.names.busy()) q.names.rescore(p.gpa); if (q.names.gen == q.made_gen and !changed) return; q.made_gen = q.names.gen; - makeNameRows(p, id) catch |err| p.reportError(id, "search", err); + makeNameRows(p, id) catch |err| p.reportError(.at(id), "search", err); }, .grep => { const dir = std.Io.Dir.path.dirname(f.path) orelse "/"; @@ -653,7 +653,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { // On the disk engine's worker, once the typing pauses. // A script's (a 9P write): run to its end before it answers. if (a.pat.len > 0) { - Stream.query(p, rp.serial, .grep, a.pat, dir, if (p.fs.serving) .now else .typed) catch |err| return p.reportError(id, "search", err); + Stream.query(p, rp.serial, .grep, a.pat, dir, if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(id), "search", err); if (p.fs.serving) Stream.step(p); } else if (p.stream.target == rp.serial) { _ = p.stream.stop(); @@ -664,7 +664,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { const gen: u64 = (@as(u64, q.grep_gen) << 32) | (q.found.items.len << 1) | @intFromBool(searching); if (gen == q.made_gen and !changed) return; q.made_gen = gen; - makeGrepRows(p, id, false) catch |err| p.reportError(id, "search", err); + makeGrepRows(p, id, false) catch |err| p.reportError(.at(id), "search", err); }, .refs, .defs, .impls, .diagnostics => { if (changed and q.lsp_rows.len == 0) { @@ -681,7 +681,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { return noteRows(p, id, " asked of the language server...\n"); } if (!changed) return; - makeListRows(p, id, a.pat) catch |err| p.reportError(id, "search", err); + makeListRows(p, id, a.pat) catch |err| p.reportError(.at(id), "search", err); }, } } @@ -713,7 +713,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz // The files under the directory, listed once on the disk engine's // worker (rg --files, else the walk); each keystroke scores them. .find => { - Stream.query(p, rp.serial, .files, "", dir, .now) catch |err| return p.reportError(id, "search", err); + Stream.query(p, rp.serial, .files, "", dir, .now) catch |err| return p.reportError(.at(id), "search", err); if (p.fs.serving) Stream.step(p); }, .recent => { @@ -812,7 +812,7 @@ fn noteRows(p: *Pardes, id: usize, note: []const u8) void { const rp = p.panes[id].?; const q = rp.query.?; q.items.clearRetainingCapacity(); - q.items.append(p.gpa, .{ .kind = .note }) catch |err| return p.reportError(id, "search", err); + q.items.append(p.gpa, .{ .kind = .note }) catch |err| return p.reportError(.at(id), "search", err); q.current = null; q.total = 0; q.k = 0; @@ -820,7 +820,7 @@ fn noteRows(p: *Pardes, id: usize, note: []const u8) void { var out: std.ArrayList(u8) = .empty; defer out.deinit(p.gpa); var rows: std.ArrayList(locations.Row) = .empty; - writeRow(p, &out, &rows, note[0 .. note.len - 1], .{ .kind = .context, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0 }) catch |err| return p.reportError(id, "search", err); + writeRow(p, &out, &rows, note[0 .. note.len - 1], .{ .kind = .context, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0 }) catch |err| return p.reportError(.at(id), "search", err); setRows(p, rp, &out, &rows); } @@ -865,7 +865,7 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList( } File.setRows(p, f, meta) catch |err| { locations.freeRows(p.gpa, meta); - if (p.paneBySerial(rp.serial)) |id| p.reportError(id, "rows", err); + if (p.paneBySerial(rp.serial)) |id| p.reportError(.at(id), "rows", err); }; if (f.pager_spans.len > 0) p.gpa.free(f.pager_spans); f.pager_spans = &.{}; @@ -1299,12 +1299,12 @@ pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) v const qid = id orelse return; const rp = p.panes[qid].?; const q = rp.query.?; - const copy = p.gpa.dupe(u8, rows) catch |err| return p.reportError(qid, "search", err); + const copy = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(qid), "search", err); p.gpa.free(q.lsp_rows); q.lsp_rows = copy; const line = lineOne(rp.file.?.content); const a = parse(line) orelse return; - makeListRows(p, qid, a.pat) catch |err| p.reportError(qid, "search", err); + makeListRows(p, qid, a.pat) catch |err| p.reportError(.at(qid), "search", err); // Diagnostics are a jump (]d): the keyboard stays on the place in the // text. The others are a list answered, not a query typed: the keyboard // on the current row in normal mode (j, k, n, N step, Enter lands, Esc @@ -1533,7 +1533,7 @@ pub fn step(p: *Pardes, id: usize, delta: i32) void { const in_window = for (q.items.items) |it| { if (it.kind == .hit and it.hit == q.grep_at) break true; } else false; - if (!in_window) makeGrepRows(p, id, q.frozen) catch |err| p.reportError(id, "search", err); + if (!in_window) makeGrepRows(p, id, q.frozen) catch |err| p.reportError(.at(id), "search", err); for (q.items.items, 0..) |it, i| if (it.kind == .hit and it.hit == q.grep_at) return setCurrent(p, id, i, true); return; } @@ -1652,7 +1652,7 @@ fn makePreview(p: *Pardes, qid: usize, rows: u16, giver: usize) ?usize { }; layout.compute(p); if (!layout.attachFrom(p, qid, free, rows, giver)) { - p.removePane(free, qid) catch |err| p.reportError(qid, "query", err); + p.removePane(free, qid) catch |err| p.reportError(.at(qid), "query", err); return null; } rp.query.?.preview = np.serial; @@ -1782,14 +1782,14 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void { // The whole list now, once, every place found: a result from here. if (set.started and set.from == rp.serial) { set.fill(p, owner, std.math.maxInt(usize), @import("regexp.zig").Regex.budget); - makeTextRows(p, id, oid, true) catch |err| p.reportError(id, "search", err); + makeTextRows(p, id, oid, true) catch |err| p.reportError(.at(id), "search", err); } if (set.started and set.from == rp.serial) { if (set.literal) { var escaped: std.ArrayList(u8) = .empty; - normal.appendSearchLiteral(&escaped, p.scratch.allocator(), set.pattern) catch |err| return p.reportError(id, "search", err); - p.registers.put(p.gpa, '/', escaped.items, 0, 1, true) catch |err| return p.reportError(id, "search", err); - } else p.registers.put(p.gpa, '/', set.pattern, 0, 1, true) catch |err| return p.reportError(id, "search", err); + normal.appendSearchLiteral(&escaped, p.scratch.allocator(), set.pattern) catch |err| return p.reportError(.at(id), "search", err); + p.registers.put(p.gpa, '/', escaped.items, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err); + } else p.registers.put(p.gpa, '/', set.pattern, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err); p.registers.last_search = '/'; set.provenance = .search; } @@ -1846,7 +1846,7 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void { return; }; // A Grep's whole list, now it is a result. - if (q.source == .grep) makeGrepRows(p, id, true) catch |err| p.reportError(id, "search", err); + if (q.source == .grep) makeGrepRows(p, id, true) catch |err| p.reportError(.at(id), "search", err); var buf: [4096 + 64]u8 = undefined; const address = if (meta.at.line > 0) std.fmt.bufPrint(&buf, "{s}:{d}:{d}", .{ meta.path, meta.at.line, meta.at.col }) catch meta.path @@ -1888,14 +1888,14 @@ pub fn cancel(p: *Pardes, id: usize) void { // go to the text whose rows they were. if (previewOf(p, id)) |pid| { p.panes[pid].?.attached_to = null; - p.removePane(pid, owner_id) catch |err| p.reportError(id, "query", err); + p.removePane(pid, owner_id) catch |err| p.reportError(.at(id), "query", err); q.preview = 0; } const f = &rp.file.?; File.setContent(p, f, s.content); File.setRows(p, f, s.rows) catch |err| { locations.freeRows(p.gpa, s.rows); - p.reportError(id, "query", err); + p.reportError(.at(id), "query", err); }; p.gpa.free(q.asked); q.asked = s.asked; @@ -1921,10 +1921,10 @@ pub fn cancel(p: *Pardes, id: usize) void { // Attached, its rows go back to its owner; else to its own column's. const attached = layout.ownerOf(p, id) != null; if (owner_id) |oid| { - p.removePane(id, if (attached) oid else null) catch |err| p.reportError(id, "query", err); + p.removePane(id, if (attached) oid else null) catch |err| p.reportError(.at(id), "query", err); p.view().active = oid; if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col); - } else p.removePane(id, null) catch |err| p.reportError(id, "query", err); + } else p.removePane(id, null) catch |err| p.reportError(.at(id), "query", err); } /// A parse of pane `serial`'s text came back (Stream.receiveParse): its @@ -2026,7 +2026,7 @@ pub fn clampEdit(p: *Pardes, t: *panes.Text, old: []const u8, new: []u8) ?[]u8 { if (span.head > end or (span.head == end and old_to > end and put.len == 0 and end < old.len)) { t.refused = true; if (t.pane()) |pane| if (panes.paneIdOf(p, pane)) |id| - p.setMessage(id, "the rows are line 1's: edit the query (Enter keeps them as text)"); + p.setMessage(.at(id), "the rows are line 1's: edit the query (Enter keeps them as text)"); return null; } // From inside line 1 into the rows: what it put in, flat, and what is diff --git a/core/Store.zig b/core/Store.zig index 0c46e7d9..82e3c5bf 100644 --- a/core/Store.zig +++ b/core/Store.zig @@ -194,11 +194,11 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool { // This session's: a replica has the authority's (`tape.authority`). const place = p.tape.authority(record, .{ s, serial }) orelse return false; const free = p.freeSlot() orelse { - p.reportError(from, "Panes", error.NoPaneSlots); + p.reportError(.at(from), "Panes", error.NoPaneSlots); return false; }; _ = dump.loadPane(p, free, place.body) catch |err| { - p.reportError(from, "Panes", err); + p.reportError(.at(from), "Panes", err); return false; }; const owner = if (place.owner != 0) p.paneBySerial(place.owner) else null; @@ -211,7 +211,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool { false; if (!placed) layout.placeNew(p, from, from, free, .doc); if (layout.findPane(p, free) == null) { - p.removePane(free, null) catch |err| p.reportError(from, "reopen", err); + p.removePane(free, null) catch |err| p.reportError(.at(from), "reopen", err); return false; } // No room anywhere: refused, it closes at the step's end, still listed. diff --git a/core/Stream.zig b/core/Stream.zig index 2d7cd018..74c8128a 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -602,7 +602,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an s.cancelTask(); const job = makeJob(gpa, s) catch |err| { s.state = .failed; - return p.reportError(p.view().active, "search", err); + return p.reportError(.at(p.view().active), "search", err); }; const future = io.concurrent(work, .{ io, job, ctx, sink }) catch { // No worker to be had: it runs here, on the loop. @@ -645,7 +645,7 @@ pub fn runHere(p: *Pardes, gen: u32) void { if (gen != s.gen or s.state != .searching) return; const job = makeJob(p.gpa, s) catch |err| { s.state = .failed; - return p.reportError(p.view().active, "search", err); + return p.reportError(.at(p.view().active), "search", err); }; defer job.deinit(); job.waits = false; diff --git a/core/builtins.zig b/core/builtins.zig index 7add3d9c..ca13bd59 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -458,7 +458,7 @@ pub const Kill = struct { if (names.len > 0 and running) c.p.reportFailure(c.id, "Kill: no running command has that first word") else - c.p.setMessage(c.id, "Kill: nothing running"); + c.p.setMessage(.at(c.id), "Kill: nothing running"); } }; @@ -477,7 +477,7 @@ pub const Dump = struct { to = path; } // Never a Dump said done that wrote nothing: its failure is said. - dump.dumpTo(c.p, to) catch |err| c.p.reportError(c.id, "Dump", err); + dump.dumpTo(c.p, to) catch |err| c.p.reportError(.at(c.id), "Dump", err); } }; @@ -578,7 +578,7 @@ pub const Mount = struct { c.p.fs.mount(c.p.gpa, name, dial) catch |err| { var said: pardes.Kind.Buf(200) = .{}; if (err == error.BadDial) return c.p.reportFailure(c.id, said.print("Mount: bad dial address: {s} (unix!/path, /path, tcp!!, or a session name)", .{dial[0..@min(dial.len, 100)]})); - return c.p.reportError(c.id, "Mount", err); + return c.p.reportError(.at(c.id), "Mount", err); }; // A socket path that is not there: said so (ENOENT), not a dial // that went unanswered. @@ -600,7 +600,7 @@ pub const Mount = struct { c.p.gpa.free(gone.dial); } var what: pardes.Kind.Buf(160) = .{}; - return c.p.reportError(c.id, what.print("Mount {s} {s}", .{ name[0..@min(name.len, 32)], dial }), err); + return c.p.reportError(.at(c.id), what.print("Mount {s} {s}", .{ name[0..@min(name.len, 32)], dial }), err); }; } }; @@ -612,15 +612,15 @@ pub const Unmount = struct { pub const requires_arg = true; pub fn run(c: Ctx) void { var args = std.mem.tokenizeAny(u8, c.arg orelse "", " \t"); - const name = args.next() orelse return c.p.reportError(c.id, "Unmount name", error.MissingArgument); - if (args.next() != null) return c.p.reportError(c.id, "Unmount name", error.TooManyArguments); + const name = args.next() orelse return c.p.reportError(.at(c.id), "Unmount name", error.MissingArgument); + if (args.next() != null) return c.p.reportError(.at(c.id), "Unmount name", error.TooManyArguments); pardes.filesystem.unmount(c.p, name) catch |err| { // "no such": the words 9ns reads as ENOENT. if (err == error.NotMounted) { var said: pardes.Kind.Buf(96) = .{}; return c.p.reportFailure(c.id, said.print("Unmount: no such mount {s}", .{name})); } - return c.p.reportError(c.id, "Unmount", err); + return c.p.reportError(.at(c.id), "Unmount", err); }; } }; @@ -634,9 +634,9 @@ pub const Msg = struct { pub const quiet = true; // it IS the message row pub fn run(c: Ctx) void { if (c.arg) |text| - c.p.setMessage(c.id, text) + c.p.setMessage(.at(c.id), text) else - c.p.reportError(c.id, comptime word(@This()), error.NoMessage); + c.p.reportError(.at(c.id), comptime word(@This()), error.NoMessage); } }; @@ -653,7 +653,7 @@ pub const Themes = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.themes_buffer, .steps = true, .commands = true }; pub fn run(c: Ctx) void { - panes.Output.openThemes(c.p, c.id) catch |err| c.p.reportError(c.id, "themes", err); + panes.Output.openThemes(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "themes", err); } }; @@ -679,7 +679,7 @@ pub const DumpThemes = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { if (c.p.configDir() == null) { - c.p.reportError(c.id, "dump themes", error.NoConfigDirectory); + c.p.reportError(.at(c.id), "dump themes", error.NoConfigDirectory); return; } c.p.emit(.{ .dump_themes = .{ .pane = @intCast(c.id) } }); @@ -694,7 +694,7 @@ pub const Fonts = struct { pub const gui_only = true; pub const in_window = true; pub fn run(c: Ctx) void { - panes.Output.openFonts(c.p, c.id) catch |err| c.p.reportError(c.id, "fonts", err); + panes.Output.openFonts(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "fonts", err); } }; @@ -709,7 +709,7 @@ pub const TreeContext = struct { const file = &c.pane.file.?; const arg = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); const on = if (arg.len == 0) !file.tree_context else if (std.mem.eql(u8, arg, "on")) true else if (std.mem.eql(u8, arg, "off")) false else { - c.p.reportError(c.id, "TreeContext", error.ExpectedOnOrOff); + c.p.reportError(.at(c.id), "TreeContext", error.ExpectedOnOrOff); return; }; file.tree_context = on; @@ -845,7 +845,7 @@ pub const Get = struct { } if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it"); var home_buf: [4096]u8 = undefined; - const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), c.p.expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(c.id, "Get", err); + const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), c.p.expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(.at(c.id), "Get", err); // A file that is not there, or a directory, is said before unsaved // edits are asked about: there would be nothing to load over them. if (typed.len > 0) if (@import("fs.zig").localPath(path)) |local| { @@ -896,7 +896,7 @@ pub const Incl = struct { if (std.mem.eql(u8, typed, "-")) { for (p.incl.items) |dir| p.gpa.free(dir); p.incl.clearRetainingCapacity(); - return p.setMessage(c.id, "Incl: none"); + return p.setMessage(.at(c.id), "Incl: none"); } // All checked before any is taken: `-` clears, alone; a directory // is absolute (or ~) and there. @@ -918,24 +918,24 @@ pub const Incl = struct { var words = std.mem.tokenizeAny(u8, typed, " \t"); while (words.next()) |dir_word| { var home_buf: [4096]u8 = undefined; - const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), p.expandHome(dir_word, &home_buf) }) catch |err| return p.reportError(c.id, "Incl", err); + const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), p.expandHome(dir_word, &home_buf) }) catch |err| return p.reportError(.at(c.id), "Incl", err); if (!std.Io.Dir.path.isAbsolute(full)) return p.reportFailure(c.id, "Incl: invalid directory"); for (p.incl.items) |dir| { if (std.mem.eql(u8, dir, full)) break; } else { - const copy = p.gpa.dupe(u8, full) catch |err| return p.reportError(c.id, "Incl", err); + const copy = p.gpa.dupe(u8, full) catch |err| return p.reportError(.at(c.id), "Incl", err); p.incl.append(p.gpa, copy) catch |err| { p.gpa.free(copy); - return p.reportError(c.id, "Incl", err); + return p.reportError(.at(c.id), "Incl", err); }; } } if (typed.len > 0) return; var list: std.Io.Writer.Allocating = .init(p.scratch.allocator()); - list.writer.writeAll("Incl:") catch |err| return p.reportError(c.id, "Incl", err); - for (p.incl.items) |dir| list.writer.print(" {s}", .{dir}) catch |err| return p.reportError(c.id, "Incl", err); - if (p.incl.items.len == 0) list.writer.writeAll(" none") catch |err| return p.reportError(c.id, "Incl", err); - p.setMessage(c.id, list.written()); + list.writer.writeAll("Incl:") catch |err| return p.reportError(.at(c.id), "Incl", err); + for (p.incl.items) |dir| list.writer.print(" {s}", .{dir}) catch |err| return p.reportError(.at(c.id), "Incl", err); + if (p.incl.items.len == 0) list.writer.writeAll(" none") catch |err| return p.reportError(.at(c.id), "Incl", err); + p.setMessage(.at(c.id), list.written()); } }; @@ -961,8 +961,8 @@ pub const Zerox = struct { if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Zerox: " ++ @import("edit_cmd.zig").e_busy); const f = c.pane.file orelse return c.p.reportFailure(c.id, "Zerox: only a file pane takes it"); if (f.output != null or f.listing != null or f.mini != null) return c.p.reportFailure(c.id, "Zerox: only a file pane takes it"); - const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Zerox", error.NoPaneSlots); - _ = panes.File.zerox(c.p, c.id, free) catch |err| return c.p.reportError(c.id, "Zerox", err); + const free = c.p.freeSlot() orelse return c.p.reportError(.at(c.id), "Zerox", error.NoPaneSlots); + _ = panes.File.zerox(c.p, c.id, free) catch |err| return c.p.reportError(.at(c.id), "Zerox", err); layout.placeNew(c.p, c.id, c.id, free, .doc); } }; @@ -1022,7 +1022,7 @@ pub const Del = struct { // about once, and the same Del again, nothing edited since, closes. if (warnModifiedIn(c, .Del, .{ .pane = c.id })) return; // An attachment's rows go back to its owner: nothing to ask. - if (layout.ownerOf(c.p, c.id)) |owner| return c.p.removePane(c.id, owner) catch |err| c.p.reportError(c.id, "close", err); + if (layout.ownerOf(c.p, c.id)) |owner| return c.p.removePane(c.id, owner) catch |err| c.p.reportError(.at(c.id), "close", err); const at = layout.findPane(c.p, c.id); const above = if (at) |f| layout.expandedNeighbor(c.p, f.col, f.idx, .above) else null; // An owner's attachments close with it: below is past them. @@ -1052,7 +1052,7 @@ pub const Del = struct { if (c.pane.msg_announcement) c.pane.msg_len = 0; return; } - c.p.removePane(c.id, to) catch |err| return c.p.reportError(c.id, "close", err); + c.p.removePane(c.id, to) catch |err| return c.p.reportError(.at(c.id), "close", err); } }; @@ -1110,8 +1110,8 @@ pub const Edit = struct { pub const Undo = struct { pub fn run(c: Ctx) void { if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Undo: " ++ @import("edit_cmd.zig").e_busy); - if (c.pane.file) |f| if (f.history.journal.done == 0) return c.p.setMessage(c.id, "Undo: nothing to undo"); - edit.undoStep(c.p.editor(), &c.pane.body, true) catch |err| c.p.reportError(c.id, "Undo", err); + if (c.pane.file) |f| if (f.history.journal.done == 0) return c.p.setMessage(.at(c.id), "Undo: nothing to undo"); + edit.undoStep(c.p.editor(), &c.pane.body, true) catch |err| c.p.reportError(.at(c.id), "Undo", err); } }; @@ -1119,8 +1119,8 @@ pub const Undo = struct { pub const Redo = struct { pub fn run(c: Ctx) void { if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Redo: " ++ @import("edit_cmd.zig").e_busy); - if (c.pane.file) |f| if (f.history.journal.done == f.history.journal.steps.items.len) return c.p.setMessage(c.id, "Redo: nothing to redo"); - edit.undoStep(c.p.editor(), &c.pane.body, false) catch |err| c.p.reportError(c.id, "Redo", err); + if (c.pane.file) |f| if (f.history.journal.done == f.history.journal.steps.items.len) return c.p.setMessage(.at(c.id), "Redo: nothing to redo"); + edit.undoStep(c.p.editor(), &c.pane.body, false) catch |err| c.p.reportError(.at(c.id), "Redo", err); } }; @@ -1150,7 +1150,7 @@ pub const Delcol = struct { // acme's Delcol refuses a column with unsaved text (exec.c delcol, // cols.c colclean), once: the next Delcol closes it. if (warnModifiedIn(c, .Delcol, .{ .column = col })) return; - layout.removeColumn(c.p, col) catch |err| c.p.reportError(c.id, "close column", err); + layout.removeColumn(c.p, col) catch |err| c.p.reportError(.at(c.id), "close column", err); } }; @@ -1216,12 +1216,12 @@ pub const Repl = struct { var buf: pardes.Kind.Buf(320) = .{}; var idbuf: [48]u8 = undefined; if (arg.len == 0) { - if (pane.repl == null) return c.p.setMessage(c.id, "Repl: not bound"); - return c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); + if (pane.repl == null) return c.p.setMessage(.at(c.id), "Repl: not bound"); + return c.p.setMessage(.at(c.id), buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); } if (std.mem.eql(u8, arg, "-")) { pane.repl = null; - return c.p.setMessage(c.id, "Repl: unbound"); + return c.p.setMessage(.at(c.id), "Repl: unbound"); } const manifest = @import("grammar_manifest.zig"); const grammars = manifest.all; @@ -1252,7 +1252,7 @@ pub const Repl = struct { return c.p.reportFailure(c.id, w.buffered()); }; if (pane.repl) |r| if (r.lang == lang) - return c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); + return c.p.setMessage(.at(c.id), buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); // The lowest letter no other REPL of the language has: freed ones // come back. var letter: u8 = 'a'; @@ -1266,7 +1266,7 @@ pub const Repl = struct { if (letter > 'z') return c.p.reportFailure(c.id, "Repl: every letter of the language is taken"); pane.repl = .{ .lang = lang, .letter = letter }; pane.repl_warned = false; - c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); + c.p.setMessage(.at(c.id), buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)})); } }; @@ -1289,8 +1289,8 @@ pub const Joincol = struct { pub const Tutor = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { - const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Tutor", error.NoPaneSlots); - _ = panes.openTutorView(c.p, free) catch |err| return c.p.reportError(c.id, "Tutor", err); + const free = c.p.freeSlot() orelse return c.p.reportError(.at(c.id), "Tutor", error.NoPaneSlots); + _ = panes.openTutorView(c.p, free) catch |err| return c.p.reportError(.at(c.id), "Tutor", err); layout.placeNew(c.p, c.id, c.id, free, .doc); // a doc like any other } }; @@ -1300,7 +1300,7 @@ pub const Help = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.help_buffer }; pub fn run(c: Ctx) void { - panes.Output.openHelp(c.p, c.id, "") catch |err| c.p.reportError(c.id, "help", err); + panes.Output.openHelp(c.p, c.id, "") catch |err| c.p.reportError(.at(c.id), "help", err); } }; @@ -1331,10 +1331,10 @@ fn openConfigFile(c: Ctx, name: []const u8, path: []const u8, initial: []const u } if (real != null) return look.lookAt(c.p, c.id, path); // Not there yet: a pane named for it, which Save makes. - const free = c.p.freeSlot() orelse return c.p.reportError(c.id, name, error.NoPaneSlots); + const free = c.p.freeSlot() orelse return c.p.reportError(.at(c.id), name, error.NoPaneSlots); panes.newScratchFor(c.p, c.id, .scratch); const made = c.p.panes[free] orelse return; - @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, name, err); + @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(.at(c.id), name, err); if (initial.len > 0) if (made.file) |*f| { _ = panes.File.replace(c.p, f, 0, f.content.len, initial); }; @@ -1347,7 +1347,7 @@ pub const DumpConfig = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.dump_config_buffer }; pub fn run(c: Ctx) void { - panes.Output.openConfig(c.p, c.id) catch |err| c.p.reportError(c.id, "config", err); + panes.Output.openConfig(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "config", err); } }; @@ -1360,14 +1360,14 @@ pub const LocationsConfig = struct { pub fn run(c: Ctx) void { const argument = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); const next = c.p.locations_config.parse(argument) catch |err| { - c.p.reportError(c.id, "LocationsConfig", err); + c.p.reportError(.at(c.id), "LocationsConfig", err); return; }; c.p.locations_config = next; // Bare, it is a question, and the window is the answer. With arguments // it is a setting, and a setting that opens a window is noise. if (argument.len != 0) return; - report(c) catch |err| c.p.reportError(c.id, "LocationsConfig", err); + report(c) catch |err| c.p.reportError(.at(c.id), "LocationsConfig", err); } fn report(c: Ctx) !void { @@ -1387,7 +1387,7 @@ pub const Messages = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.messages_buffer }; pub fn run(c: Ctx) void { - panes.Output.openMessages(c.p, c.id) catch |err| c.p.reportError(c.id, "messages", err); + panes.Output.openMessages(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "messages", err); } }; @@ -1399,7 +1399,7 @@ pub const Build = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.build_buffer }; pub fn run(c: Ctx) void { - panes.Output.openBuild(c.p, c.id) catch |err| c.p.reportError(c.id, "build", err); + panes.Output.openBuild(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "build", err); } }; @@ -1409,7 +1409,7 @@ pub const Changelog = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.changelog_buffer }; pub fn run(c: Ctx) void { - panes.Output.openChangelog(c.p, c.id) catch |err| c.p.reportError(c.id, "changelog", err); + panes.Output.openChangelog(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "changelog", err); } }; @@ -1421,7 +1421,7 @@ pub const Mini = struct { pub fn run(c: Ctx) void { panes.mini.open(c.p, c.id, c.arg orelse "") catch |err| - c.p.reportError(c.id, "Mini", err); + c.p.reportError(.at(c.id), "Mini", err); } }; @@ -1577,8 +1577,8 @@ pub const Follow = struct { }; if (!f.follow and last != c.id) return c.p.reportFailure(c.id, "Follow: this text has a chain: Follow on one of its panes"); const col = (layout.findPane(c.p, last) orelse return c.p.reportFailure(c.id, "Follow: the pane is not laid out")).col; - const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Follow", error.NoPaneSlots); - const made = panes.File.zerox(c.p, c.id, free) catch |err| return c.p.reportError(c.id, "Follow", err); + const free = c.p.freeSlot() orelse return c.p.reportError(.at(c.id), "Follow", error.NoPaneSlots); + const made = panes.File.zerox(c.p, c.id, free) catch |err| return c.p.reportError(.at(c.id), "Follow", err); const keep = v.active; if (col + 1 < v.ncol) { c.p.exec_column = col + 1; @@ -1596,7 +1596,7 @@ pub const Follow = struct { made.file.?.follow = true; c.pane.follow_scroll = f.scroll; made.follow_scroll = made.file.?.scroll; - made.appendTag(" Unfollow") catch |err| c.p.reportError(c.id, "Follow", err); + made.appendTag(" Unfollow") catch |err| c.p.reportError(.at(c.id), "Follow", err); } }; @@ -1694,7 +1694,7 @@ pub const History = struct { panes.Output.openHistory(c.p, c.id) catch |err| switch (err) { error.NoStateFile => c.p.reportFailure(c.id, "History: no state file to list (DumpDir)"), error.NoDumps => c.p.reportFailure(c.id, "History: no dumps yet"), - else => c.p.reportError(c.id, "History", err), + else => c.p.reportError(.at(c.id), "History", err), }; } }; @@ -1704,7 +1704,7 @@ pub const Jumplist = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { - panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(c.id, "jumplist", err); + panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "jumplist", err); } }; diff --git a/core/colors.zig b/core/colors.zig index 3ca8a44e..4825ea3f 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -606,14 +606,14 @@ fn nextThemeFileGeneration(p: *Pardes) u32 { pub fn requestThemeFile(p: *Pardes, id: usize, argument: []const u8) void { const input = std.mem.trim(u8, argument, " \t\r\n"); if (input.len == 0 or !std.mem.endsWith(u8, input, ".zon")) { - p.reportError(id, "theme file", error.InvalidThemePath); + p.reportError(.at(id), "theme file", error.InvalidThemePath); return; } const absolute = std.Io.Dir.path.isAbsolute(input); const config_dir = if (absolute) null else p.configDir(); if (!absolute and config_dir == null) { - p.reportError(id, "theme file", error.NoConfigDirectory); + p.reportError(.at(id), "theme file", error.NoConfigDirectory); return; } @@ -622,12 +622,12 @@ pub fn requestThemeFile(p: *Pardes, id: usize, argument: []const u8) void { const dir = config_dir.?; const separator = if (dir.len > 0 and dir[dir.len - 1] != std.Io.Dir.path.sep) std.Io.Dir.path.sep_str else ""; break :path std.fmt.bufPrint(&joined, "{s}{s}{s}", .{ dir, separator, input }) catch { - p.reportError(id, "theme file", error.PathTooLong); + p.reportError(.at(id), "theme file", error.PathTooLong); return; }; }; if (!p.theme_file_path.set(resolved)) { - p.reportError(id, "theme file", error.PathTooLong); + p.reportError(.at(id), "theme file", error.PathTooLong); return; } p.theme_file_pane = @intCast(@min(id, MAX_PANES - 1)); diff --git a/core/draw.zig b/core/draw.zig index dac6673e..4d48e925 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -979,7 +979,7 @@ test "every theme draws a file's name, a +Errors and a Term word in a tint, neve _ = try p.setTestFile("text\n"); try std.testing.expect(p.executeBuiltinLine(0, "Term+sh")); const terminal = p.view().active; - p.acknowledgeShell(terminal, "/bin/sh", false); + p.acknowledgeShell(.at(terminal), "/bin/sh", false); try @import("Output.zig").openErrors(p, 0, try gpa.dupe(u8, "oops\n")); while (p.nextEffect()) |_| {} const errors = for (p.panes, 0..) |slot, id| { @@ -1172,7 +1172,7 @@ test "a notice wider than its band, as a shader's compile error is, draws its en const long = std.mem.asBytes(&@as([3][126]u8, @splat("Shader /home/someone/shaders/test_shadertoy_invalid.glsl: error: Linking fragment stage: No function definition (body) found: ".*))); for ([_][]const u8{ "Msg " ++ long, "" }) |line| { // The Msg builtin, and the path a failed compile takes (Post.zig). - if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, line)) else p.setMessage(p.view().active, long); + if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, line)) else p.setMessage(.at(p.view().active), long); p.sync(); for (0..30) |_| p.update(.tick); _ = arena.reset(.retain_capacity); @@ -1220,7 +1220,7 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev 1, 2 => { text.clearRetainingCapacity(); for (0..random.uintAtMost(usize, 60)) |_| try text.appendSlice(std.testing.allocator, words[random.uintLessThan(usize, words.len)]); - if (random.boolean()) p.setMessage(p.view().active, text.items) else { + if (random.boolean()) p.setMessage(.at(p.view().active), text.items) else { const line = try std.fmt.allocPrint(arena.allocator(), "Msg {s}", .{text.items}); _ = p.executeBuiltinLine(p.view().active, line); } diff --git a/core/dump.zig b/core/dump.zig index 6f143daa..3b5ed421 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -583,7 +583,7 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ if (notes.items.len > 0) { const first = notes.items[0 .. std.mem.indexOfScalar(u8, notes.items, '\n') orelse notes.items.len]; var buf: [320]u8 = undefined; - p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read"); + p.setMessage(.at(p.view().active), std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read"); } return p; } @@ -694,7 +694,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool // Its file gone from disk since the dump: its text is nowhere else, so // it is said deleted, and Del, Exit and Restore ask first. One never on // disk (a name not yet saved) comes back as it was. - if (was_on_disk and !onDisk(p.tape, pane)) pardes.panes.File.deleted(p, @intCast(id)); + if (was_on_disk and !onDisk(p.tape, pane)) pardes.panes.File.deleted(p, .at(id)); } // ---- one pane to and from a dump: the store's, a handover's ---- diff --git a/core/edit.zig b/core/edit.zig index d91620c4..214e83a8 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -110,7 +110,7 @@ pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void { /// (Term.paste). pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) void { if (text.len == 0) return; - const cp = p.scratch.allocator().dupe(u8, text) catch |err| return p.reportError(id, "paste", err); + const cp = p.scratch.allocator().dupe(u8, text) catch |err| return p.reportError(.at(id), "paste", err); for (panes.Term.paste(pane.terminal, cp)) |part| if (part.len > 0) p.emitWrite(id, part); } @@ -122,7 +122,7 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void { const bytes = if (whole.len > limit) whole[0..modal.graphemeStart(whole, limit)] else whole; if (whole.len > limit) { var said: pardes.Kind.Buf(96) = .{}; - p.setMessage(v.active, said.print("paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024})); + p.setMessage(.at(v.active), said.print("paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024})); } // A prompt answering for a header takes the paste, as it takes keys. const asking = if (p.panes[v.active]) |active| active.prompt != .none else false; @@ -184,7 +184,7 @@ pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void { defer v.register = named; // A kind's pane: what it has selected (Kind.Slot.selection). if (pane.addon) |k| { - if (k.selection.len > 0) setYank(p.editor(), k.selection) catch |err| p.reportError(p.view().active, "yank", err); + if (k.selection.len > 0) setYank(p.editor(), k.selection) catch |err| p.reportError(.at(p.view().active), "yank", err); return; } if (pane.body.nsel > 0 and !main_only) { @@ -192,7 +192,7 @@ pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void { } else { const others = pane.body.nsel; pane.body.nsel = 0; - normalYank(p.editor(), &pane.body) catch |err| p.reportError(p.view().active, "edit", err); + normalYank(p.editor(), &pane.body) catch |err| p.reportError(.at(p.view().active), "edit", err); pane.body.nsel = others; } } @@ -643,7 +643,7 @@ fn editText(e: Editor, t: *Text, lo: i32, hi: i32, col: i32) Error!?panes.EditTe // with Tab or B2, gone when the program draws again. Said at its first // edit, so it never looks like an edit that was lost. if (fresh) for (e.p.panes, 0..) |slot, id| if (slot == pane) - e.p.setMessage(id, "a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program)"); + e.p.setMessage(.at(id), "a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program)"); return .{ .text = pane.ovl.?.text, .row0 = pane.ovl.?.row }; } diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig index 495ec786..43006503 100644 --- a/core/edit_cmd.zig +++ b/core/edit_cmd.zig @@ -151,7 +151,7 @@ fn fileOf(arena: std.mem.Allocator, pane: *panes.Pane, id: usize) !sam.File { pub fn run(p: *Pardes, id: usize, command: []const u8) void { const pane = p.panes[id] orelse return; if (ninep_pane.fileOf(pane) == null) return p.reportFailure(id, "Edit: only a text pane is edited"); - const pd = p.gpa.create(Pending) catch |err| return p.reportError(id, "Edit", err); + const pd = p.gpa.create(Pending) catch |err| return p.reportError(.at(id), "Edit", err); pd.* = .{ .arena = .init(p.gpa), .origin = id, .origin_serial = pane.serial }; var keep = false; defer if (!keep) pd.deinit(p.gpa); @@ -163,7 +163,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { for (p.panes, 0..) |slot, i| { const q = slot orelse continue; if (q.file == null) continue; - files.append(arena, fileOf(arena, q, i) catch |err| return p.reportError(id, "Edit", err)) catch |err| return p.reportError(id, "Edit", err); + files.append(arena, fileOf(arena, q, i) catch |err| return p.reportError(.at(id), "Edit", err)) catch |err| return p.reportError(.at(id), "Edit", err); } std.mem.sort(sam.File, files.items, p, struct { fn before(core: *Pardes, a: sam.File, b: sam.File) bool { @@ -179,7 +179,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { var text: pardes.Kind.Buf(260) = .{}; const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet, .home = p.sessionHome(), .tape = p.tape }, &why) catch |err| switch (err) { error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})), - error.OutOfMemory => return p.reportError(id, "Edit", err), + error.OutOfMemory => return p.reportError(.at(id), "Edit", err), }; // acme's Edit blocks the editor while its commands run; here the editor // goes on, and so does any Edit that runs no command and leaves alone @@ -198,13 +198,13 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { } } if (res.undo != 0) { - for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0) catch |err| return p.reportError(id, "Edit", err); + for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0) catch |err| return p.reportError(.at(id), "Edit", err); return; } pd.res = res; // What each file was, to know at the end that it still is. - pd.serials = arena.alloc(u32, res.files.len) catch |err| return p.reportError(id, "Edit", err); - pd.revisions = arena.alloc(u32, res.files.len) catch |err| return p.reportError(id, "Edit", err); + pd.serials = arena.alloc(u32, res.files.len) catch |err| return p.reportError(.at(id), "Edit", err); + pd.revisions = arena.alloc(u32, res.files.len) catch |err| return p.reportError(.at(id), "Edit", err); for (res.files, 0..) |f, i| { const q = p.panes[f.id].?; pd.serials[i] = q.serial; @@ -216,14 +216,14 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { // text may change while they run, and the Edit is then refused), in // its file's directory. const n = res.jobs.len; - const commands = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); - const cwds = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); - const inputs = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); + const commands = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); + const cwds = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); + const inputs = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); for (res.jobs, 0..) |job, i| { const f = res.files[job.file]; commands[i] = job.command; - cwds[i] = arena.dupe(u8, Pardes.paneDir(p.panes[f.id].?)) catch |err| return p.reportError(id, "Edit", err); - inputs[i] = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(id, "Edit", err); + cwds[i] = arena.dupe(u8, Pardes.paneDir(p.panes[f.id].?)) catch |err| return p.reportError(.at(id), "Edit", err); + inputs[i] = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(.at(id), "Edit", err); } p.pipe.seq +%= 1; pd.id = p.pipe.seq; @@ -234,7 +234,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { .inputs = inputs, .commands = commands, .cwds = cwds, - .shell = arena.dupe(u8, p.shellBin()) catch |err| return p.reportError(id, "Edit", err), + .shell = arena.dupe(u8, p.shellBin()) catch |err| return p.reportError(.at(id), "Edit", err), .token = selection_pipe.newToken(), // What a pane's command is given: $PARDES_MOUNT, $PARDES_9P, // $PARDES_PID, $winid as the Edit's pane. @@ -285,7 +285,7 @@ pub fn cancel(p: *Pardes) void { p.pipe.edit_run = null; selection_pipe.stop(pd.request.token); if (p.panes[pd.origin]) |pane| if (pane.serial == pd.origin_serial) - p.setMessage(pd.origin, "Edit: interrupted; nothing changed"); + p.setMessage(.at(pd.origin), "Edit: interrupted; nothing changed"); pd.deinit(p.gpa); } @@ -376,10 +376,10 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { } pf.disk_newer = null; }; - const path = p.gpa.dupe(u8, wr.path) catch |err| return p.reportError(at, "Edit", err); + const path = p.gpa.dupe(u8, wr.path) catch |err| return p.reportError(.at(at), "Edit", err); const bytes = p.gpa.dupe(u8, wr.bytes) catch |err| { p.gpa.free(path); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; const own = std.mem.eql(u8, wr.path, pane.file.?.path); p.pipe.writes.append(p.gpa, .{ @@ -394,7 +394,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { }) catch |err| { p.gpa.free(path); p.gpa.free(bytes); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; } if (res.writes.len > 0) p.emit(.edit_write); @@ -406,18 +406,18 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { o.text = outputs[j]; }; if (ops.len > 0) { - const new = sam.apply(p.gpa, pf.content, ops) catch |err| return p.reportError(at, "Edit", err); + const new = sam.apply(p.gpa, pf.content, ops) catch |err| return p.reportError(.at(at), "Edit", err); // `s/a/a/` changes nothing: no undo step, no new revision. if (std.mem.eql(u8, new, pf.content)) p.gpa.free(new) else { panes.File.pushUndo(p, pane) catch |err| { p.gpa.free(new); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; panes.File.setContent(p, pf, new); } } if (ops.len > 0 or f.moved) ninep_pane.setDot(p.settings.tab, pane, sam.moveDot(f.dot, ops)); - if (f.renamed) ninep_pane.nameBuffer(p, f.id, f.name, false) catch |err| p.reportError(f.id, "Edit", err); + if (f.renamed) ninep_pane.nameBuffer(p, f.id, f.name, false) catch |err| p.reportError(.at(f.id), "Edit", err); } // What was printed, `>`'s output in its place among it. if (res.printed.len > 0 or outputs.len > 0) { @@ -426,11 +426,11 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { var from: usize = 0; for (res.jobs, 0..) |job, j| { if (job.c != '>') continue; - out.appendSlice(p.gpa, res.printed[from..job.at]) catch |err| return p.reportError(at, "Edit", err); - out.appendSlice(p.gpa, outputs[j]) catch |err| return p.reportError(at, "Edit", err); + out.appendSlice(p.gpa, res.printed[from..job.at]) catch |err| return p.reportError(.at(at), "Edit", err); + out.appendSlice(p.gpa, outputs[j]) catch |err| return p.reportError(.at(at), "Edit", err); from = job.at; } - out.appendSlice(p.gpa, res.printed[from..]) catch |err| return p.reportError(at, "Edit", err); + out.appendSlice(p.gpa, res.printed[from..]) catch |err| return p.reportError(.at(at), "Edit", err); // Printed, the keyboard stays where it was: a +Errors made for it // does not take it, so the next Edit lands where this one did. const was = p.view().active; @@ -447,7 +447,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { if (!f.close) continue; const pane = p.panes[f.id] orelse continue; if (builtins.warnModifiedIn(.{ .p = p, .pane = pane, .id = f.id, .txt = "", .arg = null }, .Del, .{ .pane = f.id })) continue; - p.removePane(f.id, null) catch |err| p.reportError(f.id, "Edit", err); + p.removePane(f.id, null) catch |err| p.reportError(.at(f.id), "Edit", err); } } diff --git a/core/exec.zig b/core/exec.zig index 0e09e175..6a8ef6d8 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -329,14 +329,14 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { const pane = p.panes[id] orelse return; if (path.len == 0 or path[path.len - 1] == '/' or std.mem.indexOfScalar(u8, path, '\n') != null) - return p.reportError(id, "save", error.NoFilename); + return p.reportError(.at(id), "save", error.NoFilename); var home_buf: [4096]u8 = undefined; const full = std.Io.Dir.path.resolvePosix( p.scratch.allocator(), &.{ Pardes.paneDir(pane), p.expandHome(path, &home_buf) }, - ) catch |err| return p.reportError(id, "save", err); - if (!std.Io.Dir.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory); - if (full.len > Pardes.SavePath.cap) return p.reportError(id, "save", error.PathTooLong); + ) catch |err| return p.reportError(.at(id), "save", err); + if (!std.Io.Dir.path.isAbsolute(full)) return p.reportError(.at(id), "save", error.NoDirectory); + if (full.len > Pardes.SavePath.cap) return p.reportError(.at(id), "save", error.PathTooLong); const f = if (pane.file) |*file| file else { // a terminal writes its scrollback; an image and a PDF have nothing // of their own that is unwritten, so they have nothing to write @@ -382,7 +382,7 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane { return null; } const free = p.freeSlot() orelse { - p.reportError(from, "Term", error.NoPaneSlots); + p.reportError(.at(from), "Term", error.NoPaneSlots); return null; }; const nt = p.newShell(free, dir) catch |err| { @@ -390,14 +390,14 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane { p.reportFailure(from, std.fmt.comptimePrint("Term: its directory is longer than a path may be ({d} bytes)", .{pardes.memory.limits.host_path_cap})); return null; } - p.reportError(from, "Term", err); + p.reportError(.at(from), "Term", err); return null; }; nt.greet = true; nt.body.mode = .tty; layout.placeNew(p, from, from, free, .shell); if (refusedPlacement(p, free)) { - p.reportError(from, "Term", error.NoPaneRoom); + p.reportError(.at(from), "Term", error.NoPaneRoom); return null; } return nt; @@ -411,7 +411,7 @@ fn refusedPlacement(p: *Pardes, id: usize) bool { p.unplaced.unset(id); // It held no weight (layout.placeNew put every pane's rows back as they // were): nothing else moves, a pane dragged short included. - p.removePane(id, null) catch |err| p.reportError(id, "open", err); + p.removePane(id, null) catch |err| p.reportError(.at(id), "open", err); return true; } @@ -471,7 +471,7 @@ const Routed = union(enum) { none, sent: usize, asked }; pub fn replGone(p: *Pardes, from: usize, repl: *const Pane) Routed { var idbuf: [48]u8 = undefined; var said: pardes.Kind.Buf(128) = .{}; - p.setMessage(from, said.print("Repl: {s} has no program running; nothing sent", .{replId(&idbuf, repl)})); + p.setMessage(.at(from), said.print("Repl: {s} has no program running; nothing sent", .{replId(&idbuf, repl)})); return .asked; } @@ -572,7 +572,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { // Lines end in \n alone (a \r\n would give Python a blank line that // ends its block), and no ESC or other control byte but a tab goes: an // ESC[201~ in the text would end a bracketed paste early. - const clean = p.scratch.allocator().alloc(u8, text.len) catch |err| return p.reportError(from, "Repl", err); + const clean = p.scratch.allocator().alloc(u8, text.len) catch |err| return p.reportError(.at(from), "Repl", err); var n: usize = 0; for (text, 0..) |c, i| { if (c == '\r') { @@ -585,7 +585,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { // paste, or with half a block. if (n + 16 > p.writeRoom(to)) { var said: pardes.Kind.Buf(128) = .{}; - return p.setMessage(from, said.print("Repl: {d} bytes is more than can be sent at once; send less", .{n})); + return p.setMessage(.at(from), said.print("Repl: {d} bytes is more than can be sent at once; send less", .{n})); } const pasted = panes.Term.modes(dst.terminal).bracketed_paste; edit.typeToTty(p, to, dst, clean[0..n]); @@ -615,10 +615,10 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { { dst.repl_warned = true; var warn: pardes.Kind.Buf(128) = .{}; - p.setMessage(from, warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id})); + p.setMessage(.at(from), warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id})); } var said: pardes.Kind.Buf(64) = .{}; - p.setMessage(from, said.print("\u{2192} {s}", .{id})); + p.setMessage(.at(from), said.print("\u{2192} {s}", .{id})); src.msg_sent = true; var rec: [96]u8 = undefined; pardes.ctlfs.events.notePath(p, "send", std.fmt.bufPrint(&rec, "{d} {d} {s}", .{ src.serial, dst.serial, id }) catch return); @@ -710,7 +710,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi }; pane.noteCommand(cmd); if (pane.queuePendingCommand(cmd) catch |err| { - p.reportError(id, "queue command", err); + p.reportError(.at(id), "queue command", err); return id; }) return id; p.emitWrite(id, cmd); @@ -754,7 +754,7 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { if (reuse) |id| { const pane = p.panes[id].?; const owned = p.gpa.dupe(u8, line) catch |err| { - p.reportError(from, "exec", err); + p.reportError(.at(from), "exec", err); return null; }; p.gpa.free(pane.command.?); @@ -778,18 +778,18 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { return id; } const free = p.freeSlot() orelse { - p.reportError(from, "exec", error.NoPaneSlots); + p.reportError(.at(from), "exec", error.NoPaneSlots); return null; }; const pane = panes.newCommand(p, free, dir, line) catch |err| { - p.reportError(from, "exec", err); + p.reportError(.at(from), "exec", err); return null; }; pane.command_from = winid(p, src); echoCommand(p, pane, line); layout.placeNew(p, from, from, free, .command); if (refusedPlacement(p, free)) { - p.reportError(from, "exec", error.NoPaneRoom); + p.reportError(.at(from), "exec", error.NoPaneRoom); return null; } pane.noteRun(p, "run", line); @@ -982,7 +982,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? // row's only, never /log's: a msg record is something said. if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { p.fs.unlogged = true; - p.setMessage(id, @tagName(b)); + p.setMessage(.at(id), @tagName(b)); p.fs.unlogged = false; pane.msg_announcement = true; } @@ -1032,7 +1032,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] p.settings.shell.pending = true; if (!p.announce) return; var said: pardes.Kind.Buf(320) = .{}; - return p.setMessage(v.active, said.print("Shell: the default again, {s} ($SHELL, else /bin/sh)", .{p.sessionShell()[0..@min(p.sessionShell().len, 256)]})); + return p.setMessage(.at(v.active), said.print("Shell: the default again, {s} ($SHELL, else /bin/sh)", .{p.sessionShell()[0..@min(p.sessionShell().len, 256)]})); } var why: [320]u8 = undefined; if (pardes.tape.site(.shell, null, @import("dev").host_io.Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| { @@ -1044,7 +1044,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] // Bare, each says its value, as acme's Tab says the width. inline .tab, .callstack_depth => |_, tag| if (arg == null) { var said: pardes.Kind.Buf(40) = .{}; - return p.setMessage(v.active, said.print("{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) })); + return p.setMessage(.at(v.active), said.print("{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) })); } else if (!p.settings.apply(p.tape, setting, arg, p.sessionHome())) { var said: pardes.Kind.Buf(96) = .{}; p.reportFailure(v.active, said.print("{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? })); @@ -1090,10 +1090,10 @@ pub fn runWord(p: *Pardes, id: usize, w: *const pardes.Kind.Word, line: []const if (w.arg == pardes.Kind.c.PA_ARG_NONE and arg.len > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "{s} takes no argument", .{name}) catch name); if (w.arg == pardes.Kind.c.PA_ARG_REQUIRED and arg.len == 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "{s} needs an argument", .{name}) catch name); if (w.opens != 0) { - const free = p.freeSlot() orelse return p.reportError(id, name, error.NoPaneSlots); + const free = p.freeSlot() orelse return p.reportError(.at(id), name, error.NoPaneSlots); var path_buf: [4096]u8 = undefined; const path = if (arg.len == 0 or std.Io.Dir.path.isAbsolute(arg)) arg else std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/"), arg }) catch arg; - const made = (if (path.len > 0) pardes.Kind.openFile(p, free, w.kind, path) else pardes.Kind.open(p, free, w.kind, null, null)) catch |err| return p.reportError(id, name, err); + const made = (if (path.len > 0) pardes.Kind.openFile(p, free, w.kind, path) else pardes.Kind.open(p, free, w.kind, null, null)) catch |err| return p.reportError(.at(id), name, err); if (made.addon.?.refused.len > 0) { made.vweight = 0; p.unplaced.set(free); diff --git a/core/fs.zig b/core/fs.zig index 27c28c9a..a79aa55c 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -1132,11 +1132,11 @@ test "unmount refuses pane paths inherited directories and queued save targets" pane.file.?.path = try gpa.dupe(u8, "/n/peer2/file"); const slot = p.freeSlot().?; const shell = try p.newShell(slot, "/n/peer/dir"); - p.setCwd(slot, "/n/peer/dir"); + p.setCwd(.at(slot), "/n/peer/dir"); try std.testing.expectError(error.MountInUse, unmount(p, "peer")); pane.cwd = .{ .inherited = shell }; try std.testing.expectError(error.MountInUse, unmount(p, "peer")); - p.setCwd(slot, "/"); + p.setCwd(.at(slot), "/"); while (p.nextEffect()) |_| {} p.emit(.{ .save_text = .{ .pane = 0, .serial = pane.serial, .path = .from("/n/peer/pending") } }); try std.testing.expectError(error.MountInUse, unmount(p, "peer")); diff --git a/core/hunks.zig b/core/hunks.zig index a7d8e6cb..837d2a52 100644 --- a/core/hunks.zig +++ b/core/hunks.zig @@ -625,7 +625,7 @@ pub fn word(c: pardes.builtins.Ctx) void { if (diffSource(p, f)) |source| return showDiffText(p, c.id, source); _ = openDiff(p, c.id, f.path, f.content) catch |err| switch (err) { error.NoHunks => p.reportFailure(c.id, "Diff: no hunk in it"), - else => p.reportError(c.id, "hunks", err), + else => p.reportError(.at(c.id), "hunks", err), }; return; } @@ -647,14 +647,14 @@ pub fn word(c: pardes.builtins.Ctx) void { const path = if (arg[0] == '/') arg else std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, Pardes.paneDir(c.pane), "/"), arg }) catch arg; const bytes = pardes.filesystem.read(p, path) catch |err| { if (p.plumb_declined != null) return declined(p, c.id, ""); - return p.reportError(c.id, path, err); + return p.reportError(.at(c.id), path, err); }; defer p.gpa.free(bytes); p.view().active = openDiff(p, c.id, path, bytes) catch |err| switch (err) { error.NoHunks => return declined(p, c.id, "Diff: no hunk in it"), else => { if (p.plumb_declined != null) return declined(p, c.id, ""); - return p.reportError(c.id, "hunks", err); + return p.reportError(.at(c.id), "hunks", err); }, }; } @@ -685,7 +685,7 @@ pub fn paged(p: *Pardes, id: usize) void { const keyboard = p.view().active; if (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 |err| p.reportError(id, "pager", err); + p.removePane(id, hid) catch |err| p.reportError(.at(id), "pager", err); } else |_| {} if (p.panes[keyboard] != null) p.view().active = keyboard; } diff --git a/core/keys.zig b/core/keys.zig index 5a3ad10f..2f63d045 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -43,7 +43,7 @@ pub fn cycleMode(p: *Pardes, id: usize) void { pane.body.mode = .normal; pane.body.normal.clear(); }, - .normal => edit.enterInsert(p.editor(), &pane.body, .at, 1) catch |err| p.reportError(id, "edit", err), + .normal => edit.enterInsert(p.editor(), &pane.body, .at, 1) catch |err| p.reportError(.at(id), "edit", err), .insert => { edit.exitInsert(p.editor(), &pane.body); if (pane.isTerminal()) enterTty(p, id); @@ -88,7 +88,7 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void { var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa); var out: std.Io.Writer.Allocating = .init(first.allocator()); defer out.deinit(); - panes.Term.key(state, key, &out.writer) catch |err| return p.reportError(id, "key", err); + panes.Term.key(state, key, &out.writer) catch |err| return p.reportError(.at(id), "key", err); if (out.written().len > 0) p.emitWrite(id, out.written()); } @@ -177,7 +177,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool { exec.sendToRepl(p, id, to, ask.text); return true; }; - p.setMessage(id, "Repl: the REPL chosen is gone; nothing sent"); + p.setMessage(.at(id), "Repl: the REPL chosen is gone; nothing sent"); }, .del_side => { asked.prompt = .none; @@ -194,7 +194,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool { pub fn handleKey(p: *Pardes, key: Key) void { // A double-click is two clicks with nothing between them. p.view().last_click = null; - if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); + if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err); // A question waiting on a pane takes the next key, whatever mode the // pane or a header edit is in: that key is its answer. for (p.panes, 0..) |slot, id| { @@ -298,8 +298,8 @@ pub fn handleKey(p: *Pardes, key: Key) void { // global window ops (any mode): Alt-n new terminal below, Alt-c move // the active terminal into a fresh column if (hit(key, config.new_shell_below)) { - const free = p.freeSlot() orelse return p.reportError(p.view().active, "Term", error.NoPaneSlots); - const nt = p.newShell(free, "") catch |err| return p.reportError(p.view().active, "Term", err); + const free = p.freeSlot() orelse return p.reportError(.at(p.view().active), "Term", error.NoPaneSlots); + const nt = p.newShell(free, "") catch |err| return p.reportError(.at(p.view().active), "Term", err); nt.greet = true; // From a tag, as a 9P new is: acme's t->w == nil. layout.placeNew(p, p.view().active, if (p.view().header != null) null else p.view().active, free, .shell); @@ -339,7 +339,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { } if (hit(key, config.escape) or pending) { pane.input.mode = .normal; - p.setMessage(p.view().active, "name drafted: Enter renames the buffer, Esc drops the draft"); + p.setMessage(.at(p.view().active), "name drafted: Enter renames the buffer, Esc drops the draft"); return; } edit.handleInsert(p.editor(), &pane.input, key); @@ -381,7 +381,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { if (t.what != .body) { // An explicit selection, else the word under the cursor in the // text as it is shown: a tag's prefix is part of what a word is. - const shown = p.scratch.allocator().dupe(u8, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(p.view().active, "exec", err)) catch |err| return p.reportError(p.view().active, "exec", err); + const shown = p.scratch.allocator().dupe(u8, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "exec", err)) catch |err| return p.reportError(.at(p.view().active), "exec", err); const range = t.primaryRange(shown, 0); const lo = @min(range.anchor, range.head); const hi = @max(range.anchor, range.head); @@ -451,17 +451,17 @@ pub fn handleKey(p: *Pardes, key: Key) void { const m = &p.macro; switch (was) { .normal => { - Macro.append(&m.command, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); + Macro.append(&m.command, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err); if (t.mode == .insert) { m.last_insert.clearRetainingCapacity(); - m.last_insert.appendSlice(p.gpa, m.command.items) catch |err| p.reportError(p.view().active, "macro", err); + m.last_insert.appendSlice(p.gpa, m.command.items) catch |err| p.reportError(.at(p.view().active), "macro", err); m.typed_from = m.last_insert.items.len; m.inserting = true; m.command.clearRetainingCapacity(); } else if (std.meta.eql(t.normal, modal.Normal.State{})) m.command.clearRetainingCapacity(); }, .insert => if (m.inserting) { - Macro.append(&m.last_insert, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); + Macro.append(&m.last_insert, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err); if (t.mode != .insert) m.inserting = false; }, .tty => {}, @@ -483,7 +483,7 @@ fn leaderKey(p: *Pardes, key: Key) void { const c: u8 = @intCast(key.cp); if (c == config.leader_help) { panes.Output.openHelp(p, v.active, v.leader_keys[0..p.view().leader_n]) catch |err| - p.reportError(v.active, "help", err); + p.reportError(.at(v.active), "help", err); return; } if (v.leader_n >= v.leader_keys.len) return; diff --git a/core/layout.zig b/core/layout.zig index 0c17191c..6ce0845f 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -929,7 +929,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // back as they were. p.panes[id].?.vweight = 0; // No pane anywhere can give it rows: pane/new is refused. - if (kind == .fs) p.reportError(from, "placement", error.NoPaneRoom); + if (kind == .fs) p.reportError(.at(from), "placement", error.NoPaneRoom); return; } } else { @@ -938,7 +938,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // its column's rows come back as they were, none rounded off. p.panes[id].?.vweight = 0; p.unplaced.set(id); - p.reportError(from, "placement", error.NoPaneRoom); + p.reportError(.at(from), "placement", error.NoPaneRoom); return; } } diff --git a/core/look.zig b/core/look.zig index e075bbae..b2a7b945 100644 --- a/core/look.zig +++ b/core/look.zig @@ -311,7 +311,7 @@ pub fn submitSearch(p: *Pardes, id: usize) void { if (normal.selRegexArmed(pane)) |a| { // helix keeps the pattern in `/` if (a.pat.len > 0) { - p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(id, "search", err); + p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err); p.registers.last_search = '/'; } return if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode); @@ -321,10 +321,10 @@ pub fn submitSearch(p: *Pardes, id: usize) void { if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]); if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]); // A PDF's `/` and a terminal's: a text's is its query pane (Query.zig). - _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err); + _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(.at(id), "search", err); var pattern: std.ArrayList(u8) = .empty; - normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(id, "search", err); - p.registers.put(p.gpa, '/', pattern.items, 0, 1, true) catch |err| return p.reportError(id, "search", err); + normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(.at(id), "search", err); + p.registers.put(p.gpa, '/', pattern.items, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err); p.registers.last_search = '/'; lookFirstHit(p, id); } @@ -756,7 +756,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke } fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { - const text = edit.flatSurface(p.editor(), &pane.body) catch |err| return p.reportError(p.view().active, "look", err); + const text = edit.flatSurface(p.editor(), &pane.body) catch |err| return p.reportError(.at(p.view().active), "look", err); // saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a // 1-based zero is the same nothing an absent number is const acol: i32 = @intCast(at.col -| 1); @@ -952,7 +952,7 @@ fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void { var msg: Kind.Buf(miss_path_cap + 72) = .{}; // Shown on the pane; logged once, as the err below, not a msg too. p.fs.unlogged = true; - p.setMessage(id, msg.print("Look: {s}", .{why})); + p.setMessage(.at(id), msg.print("Look: {s}", .{why})); p.fs.unlogged = false; const serial = if (p.panes[id]) |pane| pane.serial else 0; var rec: Kind.Buf(miss_path_cap + 96) = .{}; @@ -1047,7 +1047,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: p.word_look = true; defer p.word_look = false; const rows = runSearch(p, id, text, .cursor, false) catch |err| { - p.reportError(id, "search", err); + p.reportError(.at(id), "search", err); return; }; if (rows == 0) { @@ -1123,7 +1123,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { var placed: Kind.Buf(miss_path_cap + "…".len + 24) = .{}; const place = placed.print("{s}:{d}", .{ name, line }); if (!opened_here) return missedLine(p, target, place, line); - p.removePane(target, null) catch |err| p.reportError(id, "look", err); + p.removePane(target, null) catch |err| p.reportError(.at(id), "look", err); if (p.panes[id] != null) v.active = id; return missedLine(p, id, place, line); } else |_| {} @@ -1163,7 +1163,7 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened: if (opened) { var kept: [miss_path_cap + "…".len]u8 = undefined; @memcpy(kept[0..name.len], name); - p.removePane(target, null) catch |err| p.reportError(id, "look", err); + p.removePane(target, null) catch |err| p.reportError(.at(id), "look", err); if (p.panes[id] != null) p.view().active = id; return missed(p, id, "{s} {s}", .{ kept[0..name.len], if (said.len > 0) said.slice() else "is no text to address" }); } @@ -1179,7 +1179,7 @@ fn spotText(at: Spot, buf: *[41]u8) []const u8 { fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void { var kept: [miss_path_cap + "…".len]u8 = undefined; @memcpy(kept[0..name.len], name); - p.removePane(opened, null) catch |err| p.reportError(id, "look", err); + p.removePane(opened, null) catch |err| p.reportError(.at(id), "look", err); if (p.panes[id] != null) p.view().active = id; missed(p, id, "{s}: {s}", .{ kept[0..name.len], why }); } @@ -1197,8 +1197,8 @@ fn lookTerminalAddress(p: *Pardes, id: usize, target: usize, expr: []const u8) v var dot: u32 = 0; for (lines, 0..) |ln, i| { if (i == row) dot = @intCast(text.items.len + @min(ln.len, @as(usize, @intCast(@max(0, pane.body.cur_col))))); - text.appendSlice(arena, ln) catch |err| return p.reportError(id, "look", err); - text.append(arena, '\n') catch |err| return p.reportError(id, "look", err); + text.appendSlice(arena, ln) catch |err| return p.reportError(.at(id), "look", err); + text.append(arena, '\n') catch |err| return p.reportError(.at(id), "look", err); } var a: Addr = .{ .text = text.items, .lim = null, .expr = expr }; const r = a.address(.{ .q0 = dot, .q1 = dot }) orelse return missed(p, id, "{s}", .{a.err}); @@ -1266,7 +1266,7 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { if (at.line > n or at.end_line > n) { var said: Kind.Buf(miss_path_cap + 64) = .{}; var cut: [miss_path_cap + "…".len]u8 = undefined; - p.setMessage(id, said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n })); + p.setMessage(.at(id), said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n })); } } @@ -1393,7 +1393,7 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, const shown = p.panes[p.view().active] orelse return; const f = if (shown.file) |*file| file else return; if (at.line > panes.File.nlines(p.gpa, f)) { - if (opened) |free| p.removePane(free, null) catch |err| p.reportError(id, "look", err); + if (opened) |free| p.removePane(free, null) catch |err| p.reportError(.at(id), "look", err); if (p.panes[before] != null) p.view().active = before; return missedLine(p, id, path, at.line); } @@ -1415,7 +1415,7 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { /// A file that is there but would not open: said with its path, `look: /// : permission denied`, the path cut in its middle when long. fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void { - if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err); + if (@import("Messages.zig").dialReason(err) != null) return p.reportError(.at(id), path, err); var cut: [miss_path_cap + "…".len]u8 = undefined; // Not there, on a peer's mount as on this host: a miss, the write // answered, as any path to no file is. @@ -1423,7 +1423,7 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void { if (err == error.FileNotFound or err == error.NotFound or remote_missing) return missed(p, id, "{s}: no such file", .{missText(path, &cut)}); var said: Kind.Buf(miss_path_cap + 16) = .{}; - p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err); + p.reportError(.at(id), said.print("look: {s}", .{missText(path, &cut)}), err); } pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { @@ -1468,7 +1468,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { break :looked operand; }; // The operand may borrow selected terminal/PDF text released below. - const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(id, "look", err); + const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(.at(id), "look", err); // A trailing `:` (`a.txt:2:3:`, as a compiler's message ends) is no // part of the place, as a click's expansion leaves it off. const bare = std.mem.trimEnd(u8, std.mem.trim(u8, txt, " \t\r\n"), ":"); @@ -1586,7 +1586,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { const before = v.active; var opened: ?usize = null; if (!focusPaneByPath(p, target.path, target.at)) { - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots); const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return lookOpenFailed(p, id, target.path, err); if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); @@ -1624,7 +1624,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false); return; } - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots); const made = Kind.openFile(p, free, target.kind, target.path) catch |err| return lookOpenFailed(p, id, target.path, err); // One its kind refuses (an image corrupt, truncated, not what @@ -1975,19 +1975,19 @@ test "cwd changes cancel only the affected pane's Look hover" { const first = p.panes[0] orelse return error.MissingFirstPane; const other = p.panes[1] orelse return error.MissingOtherPane; - p.setCwd(0, "/work/first"); - p.setCwd(1, "/work/other"); + p.setCwd(.at(0), "/work/first"); + p.setCwd(.at(1), "/work/other"); p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = first.serial }; // Hosts poll cwd every frame. An unchanged answer is observational and a // change reported for another pane cannot invalidate this pane's operand. - p.setCwd(0, "/work/first"); + p.setCwd(.at(0), "/work/first"); try std.testing.expect(p.look_hover_wait != null); - p.setCwd(1, "/work/elsewhere"); + p.setCwd(.at(1), "/work/elsewhere"); try std.testing.expect(p.look_hover_wait != null); try std.testing.expectEqual(other.serial, p.panes[1].?.serial); - p.setCwd(0, "/work/changed"); + p.setCwd(.at(0), "/work/changed"); try std.testing.expect(p.look_hover_wait == null); try std.testing.expect(p.look_hover_preview == null); } @@ -2671,7 +2671,7 @@ test "Plumb: a look sends what it looks at, the rules written first: a rule's wo const opened = p.view().active; try std.testing.expect(opened != 0); p.view().active = 0; - p.setMessage(0, "before"); + p.setMessage(.at(0), "before"); lookAt(p, 0, pic); try std.testing.expectEqual(opened, p.view().active); try std.testing.expectEqualStrings("before", pane.msg[0..pane.msg_len]); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index f00942b0..df6a058a 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -275,7 +275,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { // Whatever fails from here -- no answer, nothing found, no room for // its pane -- fails a 9P write that asked it too. const failures = p.fs.failures; - defer if (p.fs.failures != failures) p.noteLateFailure(w.pane); + defer if (p.fs.failures != failures) p.noteLateFailure(.at(w.pane)); var said: pardes.Kind.Buf(256) = .{}; const rows = response orelse return p.reportFailure(w.pane, said.print("{s}: the language server did not answer", .{lspWord(w.kind)})); @@ -296,7 +296,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { if (applyLspEdits(p, pane, w.revision, edits)) { var buf: pardes.Kind.Buf(64) = .{}; const verb: []const u8 = if (w.kind == .rename) "renamed" else "formatted"; - p.setMessage(w.pane, buf.print("{s} {d} range(s)", .{ verb, edits.len })); + p.setMessage(.at(w.pane), buf.print("{s} {d} range(s)", .{ verb, edits.len })); } return; } @@ -308,13 +308,13 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { } if (rows.len == 0) { if (w.kind == .completion and pane.body.mode == .insert and pane.body.nsel == 0 and - pane.body.cur_row == w.row and pane.body.cur_col == w.col) edit.insertTab(p.editor(), &pane.body) catch |err| return p.reportError(w.pane, "complete", err); + pane.body.cur_row == w.row and pane.body.cur_col == w.col) edit.insertTab(p.editor(), &pane.body) catch |err| return p.reportError(.at(w.pane), "complete", err); // Nothing found fails, but for a file with no diagnostics, // which is no failure, and a completion's Tab. const none: ?[]const u8 = switch (w.kind) { .completion, .format => null, .rename => "nothing here to rename", - .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, said.print("{s}: none", .{lspWord(w.kind)})), + .diagnostics, .workspace_diagnostics => return p.setMessage(.at(w.pane), said.print("{s}: none", .{lspWord(w.kind)})), .incoming_calls => "callers not found", .outgoing_calls => "callees not found", .hover => "nothing to show: not found", @@ -351,7 +351,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { }; if (listing and !p.look_missed) { var where: pardes.Kind.Buf(300) = .{}; - p.setMessage(v.active, where.print("{s}: the one, {s}", .{ lspWord(w.kind), place })); + p.setMessage(.at(v.active), where.print("{s}: the one, {s}", .{ lspWord(w.kind), place })); } return; } @@ -372,11 +372,11 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { return; }; const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); - const content = p.gpa.dupe(u8, rows) catch |err| return p.reportError(w.pane, lspWord(w.kind), err); + const content = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(w.pane), lspWord(w.kind), err); const serial_before = p.next_serial; p.fs.refilled = null; panes.Output.fillResults(p, w.pane, dir, from, w.arg.slice(), content, null) catch |err| { - p.reportError(w.pane, "language response", err); + p.reportError(.at(w.pane), "language response", err); return; }; if (rows.len >= 1 << 20) memory.trim(); @@ -401,7 +401,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { // Rows that only name a file the server left alone (lsp_client // renameEdits) are no edits. const unrenamed = std.mem.count(u8, rows, ", which the server did not rename\n"); - p.setMessage(w.pane, if (unrenamed > 0) + p.setMessage(.at(w.pane), if (unrenamed > 0) said_buf.print("Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed}) else said_buf.print("Rename: {d} edit(s) across files, previewed, not applied", .{nrows})); diff --git a/core/mouse.zig b/core/mouse.zig index 6fb97787..0ff4c7e3 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -91,7 +91,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const v = p.view(); const column = sweep.column(p) catch return; // error.Gone: its column closed under the sweep const t = if (column) |c| &v.col_tags[c] else &p.global_tag; - const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(v.active, "edit", err); + const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(v.active), "edit", err); const swept = sweep.span(text.len); const selected = if (swept.lo < swept.hi) text[swept.lo..swept.hi] else click: { const line = std.mem.count(u8, text[0..swept.lo], "\n"); @@ -103,7 +103,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const under = if (tagline.wordBoundsAtCol(bar, at)) |b| bar[b.lo..b.hi] else ""; break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else under) else under; }; - const word = p.scratch.allocator().dupe(u8, selected) catch |err| return p.reportError(v.active, "edit", err); + const word = p.scratch.allocator().dupe(u8, selected) catch |err| return p.reportError(.at(v.active), "edit", err); tagline.exitHeader(p); // A column tag's command acts on that column, empty or not. p.exec_column = column; @@ -821,7 +821,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // acme 1-2 / 1-3: the execute (Cut) or look (Paste) button // tapped while the select button holds a selection drag if (v.drag == .select and v.drag.select.button == config.select_button) { - chordCutPaste(p, m.button == config.exec_button) catch |err| p.reportError(v.active, "edit", err); + chordCutPaste(p, m.button == config.exec_button) catch |err| p.reportError(.at(v.active), "edit", err); return; } // acme 2-3 / 3-2: tapping the OTHER of execute/look during @@ -1089,7 +1089,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { if (rows.len == 0) return; const forward = gesture.r1 > gesture.r0 or (gesture.r1 == gesture.r0 and gesture.c1 >= gesture.c0); const endpoint = rows[if (forward) rows.len - 1 else 0]; - const body = body_layer.bodyText(p.settings.tab, p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "select", err); + const body = body_layer.bodyText(p.settings.tab, p.scratch.allocator(), pane) catch |err| return p.reportError(.at(p.view().active), "select", err); const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - @as(i32, @intCast(panes.Term.grid(pane.terminal).offset))))); const byte = if (forward) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo; pane.body.cur_row = pane.surfRow(endpoint.row); @@ -1107,7 +1107,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { pane.body.restore_cursor = false; pane.body.sticky_col = -1; pane.body.normal.clear(); - edit.setYank(p.editor(), text) catch |err| p.reportError(p.view().active, "yank", err); + edit.setYank(p.editor(), text) catch |err| p.reportError(.at(p.view().active), "yank", err); } /// acme's double-click (text.c:881 textselect, plan9port text.c:1407 @@ -1124,7 +1124,7 @@ fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, co const c = prev orelse return; if (c.id != id or c.on_tag != on_tag or c.row != row or c.col != col or now - c.ms > 500) return; v.last_click = null; - const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(v.active, "edit", err); + const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(v.active), "edit", err); const q = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); const r = edit.doubleClickRange(text, q); if (r[1] <= r[0]) return; @@ -1213,7 +1213,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { } return; } - if (dragged and s.anchor == null) edit.capturePointerSelection(p, pane, sel_slot) catch |err| p.reportError(s.id, "select", err); + if (dragged and s.anchor == null) edit.capturePointerSelection(p, pane, sel_slot) catch |err| p.reportError(.at(s.id), "select", err); if (dragged and pane.body.mode == .tty) mirrorTtySelection(p, pane); const body_vis = sl.r1 - @as(i32, pane.tag_rows); if (body_vis >= 0 and pane.body.mode != .tty) { diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index a4f16597..cf68fa76 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 } @@ -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 = "$ " } }); // 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,7 +2000,7 @@ 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.setCwd(.at(term), "/tmp"); p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); while (p.nextEffect()) |_| {} var count: usize = 0; @@ -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); @@ -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); @@ -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; @@ -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..76765535 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; @@ -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..96f2a6bf 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -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); @@ -799,7 +799,7 @@ 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 } }); var sent_late: [16]u8 = undefined; @@ -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/normal.zig b/core/normal.zig index 66df9608..43f55bdc 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -355,7 +355,7 @@ pub fn jumpKey(p: *Pardes, pane: *Pane, t: *Text, key: Key) void { defer pane.jump.clearRetainingCapacity(); if (chosen >= pane.jump.items.len) return; const r = pane.jump.items[chosen]; - const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(p.view().active, "edit", err); + const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "edit", err); if (!t.select) return t.setRange(p.settings.tab, text, 0, .{ .anchor = @min(r.anchor, r.head), .head = @max(r.anchor, r.head) }, true); // select mode stretches the primary to the word (helix Movement::Extend) const pr = t.primaryRange(text, 0); @@ -597,7 +597,7 @@ fn searchStep(e: Editor, t: *Text, text: []const u8, forward: bool, count: u32) const name = if (e.register.* != 0) e.register.* else e.registers.last_search; const pat = e.registers.value(name, 0) orelse return; var re = SearchRegex.compile(e.scratch, pat) catch { - e.p.setMessage(v.active, "invalid search pattern"); + e.p.setMessage(.at(v.active), "invalid search pattern"); return; }; var hay = text; @@ -620,7 +620,7 @@ fn searchStep(e: Editor, t: *Text, text: []const u8, forward: bool, count: u32) wrapped = true; break :blk lastMatch(&re, hay, from, hay.len); }) orelse { - e.p.setMessage(v.active, "no more matches"); + e.p.setMessage(.at(v.active), "no more matches"); return; }; if (found.end == 0) return; @@ -635,7 +635,7 @@ fn searchStep(e: Editor, t: *Text, text: []const u8, forward: bool, count: u32) ranges[got.pri] = next; t.setRanges(e.tab, text, ranges[0..got.n], &.{}, got.pri, true); } - if (wrapped) e.p.setMessage(v.active, "wrapped around document"); + if (wrapped) e.p.setMessage(.at(v.active), "wrapped around document"); } t.show(e.tab); } diff --git a/core/panes.zig b/core/panes.zig index dd36839a..7ea479b9 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -716,7 +716,7 @@ pub const Pane = struct { // A replica's emulator is what the authority's deltas make it; what // pardes keeps over it moves as the authority's feed told it. if (tape.screenReplica()) { - if (has_positions and pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(id, positions_lost); + if (has_positions and pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost); return; } // Sticky bottom, as every other terminal does it: output drags the @@ -728,7 +728,7 @@ pub const Pane = struct { Term.cellPixels(state, p.view().cell_pixels.w, p.view().cell_pixels.h); if (!has_positions) { _ = Term.feed(state, bytes, &.{}, &.{}, &.{}); - } else if (pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(id, positions_lost); + } else if (pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost); p.shell_rows.markStale(pane); if (pane.body.mode == .tty and at_bottom) pane.followOutput(); } @@ -1078,7 +1078,7 @@ pub const Pane = struct { // failure is worth the pane. if (pane.command_pages) { pane.command_pages = false; - if (status == 0) return p.removePane(id, null) catch |err| p.reportError(id, "close", err); + if (status == 0) return p.removePane(id, null) catch |err| p.reportError(.at(id), "close", err); } var buf: [16]u8 = undefined; const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 @@ -1350,8 +1350,8 @@ pub fn newScratchBelow(p: *Pardes, from_id: usize) void { /// A scratch for New (`.scratch`) or 9P's pane/new (`.fs`). pub fn newScratchFor(p: *Pardes, from_id: usize, kind: layout.NewPane) void { - const free = p.freeSlot() orelse return p.reportError(from_id, "New", error.NoPaneSlots); - _ = newScratch(p, from_id, free, kind) catch |err| return p.reportError(from_id, "New", err); + const free = p.freeSlot() orelse return p.reportError(.at(from_id), "New", error.NoPaneSlots); + _ = newScratch(p, from_id, free, kind) catch |err| return p.reportError(.at(from_id), "New", err); layout.placeNew(p, from_id, from_id, free, kind); } @@ -1529,7 +1529,7 @@ pub fn startPrompt(p: *Pardes, pane: *Pane, t: *Text, request: union(enum) { // directory for the name to be typed onto. const dir = if (request == .save) paneDir(pane) else ""; const slash: []const u8 = if (request == .save and (dir.len == 0 or dir[dir.len - 1] != '/')) "/" else ""; - const answer = std.mem.concat(p.gpa, u8, &.{ marker, dir, slash }) catch |err| return p.reportError(p.view().active, "prompt", err); + const answer = std.mem.concat(p.gpa, u8, &.{ marker, dir, slash }) catch |err| return p.reportError(.at(p.view().active), "prompt", err); // The keyboard comes back to the text answered for; a prompt for // the body takes it out of a tag or header. switch (t.what) { @@ -1584,7 +1584,7 @@ test "owned cwd preserves long paths aliases and failed updates" { var path: [3072]u8 = @splat('d'); path[0] = '/'; for (1..12) |i| path[i * 256] = '/'; - p.setCwd(0, &path); + p.setCwd(.at(0), &path); try std.testing.expectEqualStrings(&path, pane.cwdSlice()); try std.testing.expect(pane.cwdSlice().ptr != &path); const original = pane.cwdSlice(); @@ -1609,15 +1609,15 @@ test "owned cwd preserves long paths aliases and failed updates" { const current = pane.cwdSlice(); allocator.fail_index = allocator.alloc_index; - p.setCwd(0, "/replacement"); + p.setCwd(.at(0), "/replacement"); try std.testing.expectEqual(current.ptr, pane.cwdSlice().ptr); try std.testing.expectEqualStrings(&path, pane.cwdSlice()); try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "out of memory") != null); allocator.fail_index = std.math.maxInt(usize); - p.setCwd(0, "/replacement"); + p.setCwd(.at(0), "/replacement"); try std.testing.expectEqualStrings("/replacement", pane.cwdSlice()); const allocations = allocator.allocations; - p.setCwd(0, "/replacement"); + p.setCwd(.at(0), "/replacement"); try std.testing.expectEqual(allocations, allocator.allocations); pane.clearCwd(); try std.testing.expect(pane.cwd == .none); @@ -1678,8 +1678,8 @@ test "owned cwd column close allocates every copy before removing any pane" { var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{}); const p = try Pardes.init(allocator.allocator(), .{ .shells = 3, .cols = 100, .rows = 30 }); defer p.deinit(); - p.setCwd(0, "/first"); - p.setCwd(1, "/second"); + p.setCwd(.at(0), "/first"); + p.setCwd(.at(1), "/second"); const first_child = try p.newDocPane(3); const second_child = try p.newDocPane(4); first_child.cwd = .{ .inherited = p.panes[0].? }; @@ -1706,7 +1706,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" { var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{}); const p = try Pardes.init(allocator.allocator(), .{ .tty_only = true }); defer p.deinit(); - p.setCwd(0, "/exited"); + p.setCwd(.at(0), "/exited"); const parent = p.panes[0].?; p.newScratchBelow(0); const child = p.panes[p.view().active].?; @@ -1800,7 +1800,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" { while (p.nextEffect()) |_| {} const source: usize = 2; // the right column; active starts in the left - p.setCwd(source, "/tmp/pardes-scratch-dir"); + p.setCwd(.at(source), "/tmp/pardes-scratch-dir"); const source_col = layout.findPane(p, source).?.col; try std.testing.expect(p.executeBuiltinLine(source, "New")); @@ -1814,7 +1814,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" { try std.testing.expectEqual(@as(usize, 0), np.file.?.content.len); // its directory is a LIVE link to the opener, not a snapshot taken at New try std.testing.expectEqualStrings("/tmp/pardes-scratch-dir", Pardes.paneDir(np)); - p.setCwd(source, "/tmp/pardes-moved"); + p.setCwd(.at(source), "/tmp/pardes-moved"); try std.testing.expectEqualStrings("/tmp/pardes-moved", Pardes.paneDir(np)); try p.removePane(source, null); p.sync(); diff --git a/core/replica.zig b/core/replica.zig index fb3a81c4..625153d1 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -233,7 +233,7 @@ pub const Authority = struct { pub fn own(a: *Authority, ev: pardes.Event) ![]const u8 { std.debug.assert(a.batched == 0); const was = Stepping.begin(&a.t, null); - a.core.toView(0); + a.core.toView(.at(0)); was.end(); return a.local(ev); } @@ -276,9 +276,9 @@ pub const Authority = struct { }; a.core.pump(a.host) catch {}; was.end(); - a.view_of[client] = k; + a.view_of[client] = k.index(); a.seq += 1; - return .{ .view = k, .unit = try a.unit(0, a.seq) }; + return .{ .view = k.index(), .unit = try a.unit(0, a.seq) }; } /// A client joining as `Peers.join` takes one: its view kept for it @@ -290,8 +290,8 @@ pub const Authority = struct { std.debug.assert(a.batched == 0); const was = Stepping.begin(&a.t, null); defer was.end(); - const again = if (back) |v| a.core.rejoinView(v) else false; - const k = (if (again) back else a.core.openView()) orelse return null; + const again = if (back) |v| a.core.rejoinView(.at(v)) else false; + const k = (if (again) back else if (a.core.openView()) |o| o.index() else null) orelse return null; a.core.undrawn |= @as(u8, 1) << @intCast(k); a.view_of[client] = k; a.seq += 1; @@ -320,7 +320,7 @@ pub const Authority = struct { const was = Stepping.begin(&a.t, null); const k = a.view_of[client]; a.core.undrawn &= ~(@as(u8, 1) << @intCast(k)); - if (again) a.core.awayView(k) else a.core.closeView(k); + if (again) a.core.awayView(.at(k)) else a.core.closeView(.at(k)); was.end(); a.seq += 1; return a.unit(0, a.seq); @@ -330,7 +330,7 @@ pub const Authority = struct { pub fn closeView(a: *Authority, client: u16) ![]const u8 { std.debug.assert(a.batched == 0); const was = Stepping.begin(&a.t, null); - a.core.closeView(a.view_of[client]); + a.core.closeView(.at(a.view_of[client])); was.end(); a.seq += 1; return a.unit(0, a.seq); @@ -342,7 +342,7 @@ pub const Authority = struct { std.debug.assert(a.batched == 0); const in = parseInput(msg) orelse return error.BadInput; const was = Stepping.begin(&a.t, null); - a.core.toView(a.view_of[in.client]); + a.core.toView(.at(a.view_of[in.client])); a.t.stamp = stampOf(in); a.core.update(in.event); a.core.step(); @@ -1127,7 +1127,7 @@ pub const Replica = struct { tape.beginSpeculation(&r.t); // The time it was sent with, every time it is applied. r.t.guess = p.guess; - c.toView(r.view); + c.toView(.at(r.view)); // Input into a terminal: what reaches its program (a key in tty // mode, a paste, a mouse report) is a pty write, the authority's, // and stops here (phase 6 predicts its echo). The rest (pardes's @@ -2162,7 +2162,7 @@ pub const Peers = struct { // The terminals as this step reads them, then the step, the rows // it read, its unit (part B terminal notes' order). ps.screensOut(core, .flush); - core.toView(peer.view); + core.toView(.at(peer.view)); ps.t.stamp = stampOf(in); core.update(in.event); core.step(); @@ -2234,8 +2234,8 @@ pub const Peers = struct { // link's end (posted by that link's reader, microseconds after the // bye; the redial is a dial and the daemon's hand-over later) finds // its view not kept yet, and takes a new one. - const back = if (joining.view) |v| core.rejoinView(v) else false; - const k = (if (back) joining.view else core.openView()) orelse { + const back = if (joining.view) |v| core.rejoinView(.at(v)) else false; + const k = (if (back) joining.view else if (core.openView()) |o| o.index() else null) orelse { core.unattended = ps.count() == 0 and ps.detached; if (ps.count() == 0) ps.stop(core); return daemon.refuseReplica(fd, "that session has as many views as it takes"); @@ -2251,7 +2251,7 @@ pub const Peers = struct { const bytes = pardes.dump.dumpJoin(core, &blobs) catch |err| { blobs.deinit(core.gpa); core.undrawn &= ~(@as(u8, 1) << @intCast(k)); - core.closeView(k); + core.closeView(.at(k)); ps.unit(0, ps.seq); if (ps.count() == 0) ps.stop(core); var why: [96]u8 = undefined; @@ -2284,7 +2284,7 @@ pub const Peers = struct { if (ps.threads and (peer.writer == null or peer.reader == null)) { ps.letGo(peer); core.undrawn &= ~(@as(u8, 1) << @intCast(k)); - core.closeView(k); + core.closeView(.at(k)); ps.unit(0, ps.seq); return; } @@ -2321,7 +2321,7 @@ pub const Peers = struct { /// session no one else watches leaves the session its layout, for a /// client that comes after to find. fn closeViewOf(ps: *Peers, core: *Pardes, peer: *Peer, again: bool) void { - if (again) core.awayView(peer.view) else if (ps.count() == 0 and ps.detached) core.leaveView(peer.view) else core.closeView(peer.view); + if (again) core.awayView(.at(peer.view)) else if (ps.count() == 0 and ps.detached) core.leaveView(.at(peer.view)) else core.closeView(.at(peer.view)); } /// Its threads ended and joined, its link closed. @@ -3916,7 +3916,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, try deliver(a, &screens, peer, r, .flush); { const was = Stepping.begin(&a.t, null); - a.core.toView(0); + a.core.toView(.at(0)); a.core.update(.{ .key = .{ .cp = 'k', .text = "k" } }); a.core.step(); was.end(); @@ -4249,9 +4249,9 @@ test "a host's Adopt and a terminal reader's failure are inputs: a replica makes // What tui.zig's and gui.zig's adoptShell and a failed reader do between // steps: they wrote the core straight, and every client joined again. const host = Stepping.begin(&a.t, null); - const id = a.core.adoptShell().?; + const id = a.core.adoptShell().?.index(); try std.testing.expect(a.core.panes[id].?.isTerminal() and !a.core.panes[id].?.greet); - a.core.readerFailed(id, error.InputOutput); + a.core.readerFailed(.at(id), error.InputOutput); a.core.pump(a.host) catch {}; host.end(); a.seq += 1; @@ -4570,7 +4570,7 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize // It leaves: the terminal is the first view's size again, its pty's // resize queued for the next pump; and a client joins at that boundary. var was = Stepping.begin(&a.t, null); - a.core.closeView(opened.view); + a.core.closeView(.at(opened.view)); was.end(); old.confirm(try a.unit(0, 100)); // The client left idle takes its copy ahead (Replica.ready): of a core @@ -4580,7 +4580,7 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize const k = a.core.openView() orelse return error.NoView; was.end(); old.confirm(try a.unit(0, 101)); - const joiner = try joinedNow(a, 3, k); + const joiner = try joinedNow(a, 3, k.index()); defer joiner.deinit(); try std.testing.expectEqual(digestOf(a), joiner.digest()); // The next pump's unit, every client's. @@ -4607,13 +4607,13 @@ test "a client that diverged joins again for its view: kept for it meanwhile, it const made = a.core.view().active; // Its bye says it joins again: its view is kept, as every replica keeps it. var was = Stepping.begin(&a.t, null); - a.core.awayView(opened.view); + a.core.awayView(.at(opened.view)); was.end(); old.confirm(try a.unit(0, 100)); try agrees(a, old); // Back for it: its own, its pane in it, in the dump it loads. was = Stepping.begin(&a.t, null); - try std.testing.expect(a.core.rejoinView(opened.view)); + try std.testing.expect(a.core.rejoinView(.at(opened.view))); was.end(); old.confirm(try a.unit(0, 101)); const back = try joinedNow(a, 3, opened.view); @@ -5092,7 +5092,7 @@ const SeenHost = struct { fn setClipboard(ctx: ?*anyopaque, _: []const u8) void { const h = of(ctx); h.yanked += 1; - if (h.tell) h.core.?.setMessage(h.core.?.view().active, "yanked"); + if (h.tell) h.core.?.setMessage(.at(h.core.?.view().active), "yanked"); } fn readClipboard(ctx: ?*anyopaque) void { of(ctx).asked += 1; diff --git a/core/rollback.zig b/core/rollback.zig index 53c7b210..3d5ab921 100644 --- a/core/rollback.zig +++ b/core/rollback.zig @@ -682,8 +682,8 @@ test "a view's slot, live or drawn outside a step (a replica's own, another live const text = "the column tag of view 0, its own"; p.view().col_tags[0].own = try gpa.dupe(u8, text); if (drawn) try pardes.views.within(p, 1, {}, Read.read) else { - p.toView(1); - p.toView(0); + p.toView(.at(1)); + p.toView(.at(0)); } // The live view drops it, and its memory is another's: something the // copy has no business saving. diff --git a/core/selection_pipe.zig b/core/selection_pipe.zig index c33cf913..6ac3ecfc 100644 --- a/core/selection_pipe.zig +++ b/core/selection_pipe.zig @@ -223,12 +223,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, tasks: *T const view = core.pipe.pipeRequest(id) orelse return; const job = Job.copy(gpa, view) catch |err| { core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return core.reportError(core.view().active, "pipe", err); + return core.reportError(.at(core.view().active), "pipe", err); }; const future = io.concurrent(work, .{ io, gpa, job, ctx, sink }) catch |err| { job.deinit(gpa); core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return core.reportError(core.view().active, "pipe", err); + return core.reportError(.at(core.view().active), "pipe", err); }; std.debug.assert(tasks.add(.{ .id = id, .future = future })); } diff --git a/core/tagline.zig b/core/tagline.zig index d0525a84..456a6b6e 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -90,7 +90,7 @@ pub fn revealHeader(p: *Pardes) void { v.header_top = 0; return; }; - const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(v.active, "tag", err); + const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(v.active), "tag", err); const cur: usize = @intCast(@max(0, t.cur_row)); const rows: usize = if (p.headerColumn() != null) layout.columnBarHeight(p) else p.topBarHeight(); if (cur < v.header_top) v.header_top = cur; @@ -220,7 +220,7 @@ pub fn tagText(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { /// it starts on Save, so that `:` and the execute key write the file. pub fn enterTag(p: *Pardes, pane: *Pane) void { const t = &pane.tag; - const whole = tagText(p, p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "tag", err); + const whole = tagText(p, p.scratch.allocator(), pane) catch |err| return p.reportError(.at(p.view().active), "tag", err); if (!t.cur_pinned) { // Save is looked for in the tag's own text, after the prefix. const lead = whole.len - curTail(pane).len; @@ -374,7 +374,7 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { pub fn draftName(p: *Pardes, pane: *Pane, col: usize) void { const f = pane.file orelse return; if (!panes.Output.fileTraits(f.output).saves) return; - const name = p.gpa.dupe(u8, f.path) catch |err| return p.reportError(p.view().active, "name", err); + const name = p.gpa.dupe(u8, f.path) catch |err| return p.reportError(.at(p.view().active), "name", err); pane.closePrompt(); pane.prompt = .name; pane.prompt_view = p.live; @@ -388,20 +388,20 @@ pub fn commitTagName(p: *Pardes, pane: *Pane) bool { const id = panes.paneIdOf(p, pane) orelse return false; const name = pane.input.own orelse ""; if (name.len == 0 or name[name.len - 1] == '/' or !std.unicode.utf8ValidateSlice(name)) { - p.reportError(id, "name", error.InvalidName); + p.reportError(.at(id), "name", error.InvalidName); return false; } for (name) |byte| if (byte < ' ') { - p.reportError(id, "name", error.InvalidName); + p.reportError(.at(id), "name", error.InvalidName); return false; }; var home_buf: [4096]u8 = undefined; const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(pane), p.expandHome(name, &home_buf) }) catch |err| { - p.reportError(id, "name", err); + p.reportError(.at(id), "name", err); return false; }; ctlfs.pane.nameBuffer(p, id, full, true) catch |err| { - p.reportError(id, "name", err); + p.reportError(.at(id), "name", err); return false; }; pane.closePrompt(); @@ -424,7 +424,7 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { p.view().header = if (column) |c| .{ .column = c } else .workspace; if (column) |c| p.setActiveColumn(c); const t = focusedHeader(p) orelse return exitHeader(p); - takeKeyboard(t, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(p.view().active, "tag", err)); + takeKeyboard(t, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "tag", err)); } /// The span a header's selection covers on line `row` of its text, in diff --git a/core/tape.zig b/core/tape.zig index e0bc95e7..00486666 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -78,7 +78,7 @@ pub const Input = union(enum) { leave_view: Args(Pardes.leaveView), away_view: Args(Pardes.awayView), rejoin_view: Args(Pardes.rejoinView), - to_view: u8, + to_view: Pardes.View.Id, /// What a window says of its font and its opacity (gui.zig). take_font_request: Args(Pardes.takeFontRequest), observe_font: Args(Pardes.observeFont), diff --git a/core/views.zig b/core/views.zig index ee061964..a8bf8e60 100644 --- a/core/views.zig +++ b/core/views.zig @@ -579,25 +579,25 @@ test "each view has its own cursor and scroll, and an edit in one is in the othe const text = try numbered(gpa, 200); defer gpa.free(text); const pane = try p.setTestFile(text); - try testing.expectEqual(@as(?u8, 1), p.openView()); + try testing.expectEqual(@as(?View.Id, .at(1)), p.openView()); cursorTo(p, pane, 119); const scrolled = pane.file.?.scroll; try testing.expect(scrolled > 0); // The other view is where the session was when it came. - p.toView(1); + p.toView(.at(1)); try testing.expectEqual(@as(i32, 0), pane.body.cur_row); try testing.expectEqual(@as(usize, 0), pane.file.?.scroll); typeKeys(p, "ix"); escape(p); try testing.expectEqual(Text.Mode.normal, pane.body.mode); - p.toView(0); + p.toView(.at(0)); try testing.expectEqual(@as(i32, 119), pane.body.cur_row); try testing.expectEqual(scrolled, pane.file.?.scroll); try testing.expect(std.mem.startsWith(u8, pane.file.?.content, "xline 1\n")); // Its mode is its own: insert here leaves the other in normal. typeKeys(p, "i"); try testing.expectEqual(Text.Mode.insert, pane.body.mode); - p.toView(1); + p.toView(.at(1)); try testing.expectEqual(Text.Mode.normal, pane.body.mode); } @@ -614,7 +614,7 @@ test "each view has its own layout and focus over the same panes" { const made = p.view().active; try testing.expect(made != 0); try testing.expectEqual(ncol + 1, p.view().ncol); - p.toView(0); + p.toView(.at(0)); try testing.expectEqual(ncol, p.view().ncol); try testing.expectEqual(@as(usize, 0), p.view().active); try testing.expect(layout.findPane(p, made) == null); @@ -663,15 +663,15 @@ test "a terminal shown at two sizes takes the size of the view that typed into i p.update(.{ .key = .{ .cp = Key.right } }); try testing.expect(term.cols > small[0] and term.rows > small[1]); const big = .{ term.cols, term.rows }; - p.toView(0); + p.toView(.at(0)); p.sync(); try testing.expectEqual(big, .{ term.cols, term.rows }); p.update(.{ .key = .{ .cp = Key.right } }); try testing.expectEqual(small, .{ term.cols, term.rows }); // That view gone, the one left sizes it. p.toView(k); - p.closeView(0); - try testing.expectEqual(k, p.live); + p.closeView(.at(0)); + try testing.expectEqual(k.index(), p.live); try testing.expectEqual(big, .{ term.cols, term.rows }); } @@ -691,18 +691,18 @@ test "a view closing leaves the others as they were" { typeKeys(p, "xy"); p.toView(a); cursorTo(p, pane, 70); - p.toView(0); + p.toView(.at(0)); cursorTo(p, pane, 10); const ncol = p.view().ncol; // The live one closing: the session goes into another. p.toView(b); p.closeView(b); - try testing.expect(p.live != b); + try testing.expect(p.live != b.index()); try testing.expectEqual(@as(usize, 2), count(p)); p.toView(a); try testing.expectEqual(@as(i32, 70), pane.body.cur_row); - p.closeView(0); - try testing.expectEqual(a, p.live); + p.closeView(.at(0)); + try testing.expectEqual(a.index(), p.live); try testing.expectEqual(ncol, p.view().ncol); // The last stays. p.closeView(a); @@ -749,7 +749,7 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien defer p.deinit(); _ = try p.setTestFile("one\ntwo\n"); // Two clients, each a pane of its own in its own view. - const ks: [2]u8 = .{ p.openView().?, p.openView().? }; + const ks: [2]View.Id = .{ p.openView().?, p.openView().? }; var made: [2]usize = undefined; for (ks, &made) |k, *m| { p.toView(k); @@ -767,7 +767,7 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien const q = try pardes.dump.load(gpa, opts, bytes, null); defer q.deinit(); for (ks, made, 0..) |k, m, i| { - try testing.expect(isAway(q, k)); + try testing.expect(isAway(q, k.index())); try testing.expect(q.rejoinView(k)); q.toView(k); try testing.expectEqual(m, q.view().active); @@ -776,10 +776,10 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien } try testing.expect(!q.rejoinView(ks[0])); // A client that never comes back: its view goes when a join has no room. - p.toView(0); - try testing.expectEqual(@as(?u8, 3), p.openView()); + p.toView(.at(0)); + try testing.expectEqual(@as(?View.Id, .at(3)), p.openView()); try testing.expectEqual(ks[0], p.openView()); - try testing.expect(!isAway(p, ks[0]) and isAway(p, ks[1])); + try testing.expect(!isAway(p, ks[0].index()) and isAway(p, ks[1].index())); } test "drawing another view leaves the live one as it was, to the digest" { @@ -793,10 +793,10 @@ test "drawing another view leaves the live one as it was, to the digest" { p.toView(k); cursorTo(p, pane, 60); typeKeys(p, "dd"); - p.toView(0); + p.toView(.at(0)); cursorTo(p, pane, 95); const before = pardes.walk.digest(Pardes, p); - _ = try drawOne(p, k, .{ .ctx = null, .f = null }); + _ = try drawOne(p, k.index(), .{ .ctx = null, .f = null }); try testing.expectEqual(@as(u8, 0), p.live); try testing.expectEqual(before, pardes.walk.digest(Pardes, p)); p.toView(k); @@ -812,9 +812,9 @@ test "a view drawn while another is live keeps its own cursors" { p.toView(k); p.update(.{ .key = .{ .cp = 'C', .text = "C" } }); try testing.expectEqual(@as(u16, 1), pane.body.nsel); - p.toView(0); + p.toView(.at(0)); const before = pardes.walk.digest(Pardes, p); - _ = try drawOne(p, k, .{ .ctx = null, .f = null }); + _ = try drawOne(p, k.index(), .{ .ctx = null, .f = null }); try testing.expectEqual(before, pardes.walk.digest(Pardes, p)); p.toView(k); try testing.expectEqual(@as(u16, 1), pane.body.nsel); @@ -831,7 +831,7 @@ test "a view not live keeps its place in a text another view edits" { p.toView(k); cursorTo(p, pane, 100); const scrolled = pane.file.?.scroll; - p.toView(0); + p.toView(.at(0)); // Three lines put above it, one taken below it. typeKeys(p, "xyppp"); cursorTo(p, pane, 150); @@ -862,7 +862,7 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" { p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); // Sized for the tall view, it fits there whole: nothing is passed over. try testing.expectEqual(@as(u16, 0), term.pan); - p.toView(0); + p.toView(.at(0)); p.sync(); try testing.expectEqual(rows, term.rows); try testing.expect(term.pan > 0); @@ -897,7 +897,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o cursorTo(p, pane, 119); p.toView(k); p.update(.{ .command = "Newcol" }); - p.toView(0); + p.toView(.at(0)); p.toView(k); cursorTo(p, pane, 30); const ncol = p.view().ncol; @@ -910,7 +910,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o defer gpa.free(again); try testing.expectEqualSlices(u8, bytes, again); const lp = loaded.panes[id].?; - loaded.toView(0); + loaded.toView(.at(0)); try testing.expectEqual(@as(i32, 119), lp.body.cur_row); try testing.expectEqual(ncol - 1, loaded.view().ncol); loaded.toView(k); @@ -923,7 +923,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o try testing.expectEqual(@as(u8, 0), one.live); try testing.expectEqual(ncol, one.view().ncol); try testing.expectEqual(@as(i32, 30), one.panes[id].?.body.cur_row); - try testing.expectEqual(@as(?u8, 1), one.openView()); + try testing.expectEqual(@as(?View.Id, .at(1)), one.openView()); } test "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" { diff --git a/dev/Lsp.zig b/dev/Lsp.zig index edc99eeb..d7f11bfe 100644 --- a/dev/Lsp.zig +++ b/dev/Lsp.zig @@ -118,12 +118,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T } const job = snapshot(gpa, core, req) catch |err| { core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return core.reportError(req.pane, "lsp", err); + return core.reportError(.at(req.pane), "lsp", err); }; const future = io.concurrent(work, .{ io, gpa, job, ctx, deliver }) catch |err| { job.free(gpa); core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return core.reportError(req.pane, "lsp", err); + return core.reportError(.at(req.pane), "lsp", err); }; task.* = .{ .id = req.id, .future = future }; } diff --git a/dev/file_watch.zig b/dev/file_watch.zig index 9d868e07..a02ad272 100644 --- a/dev/file_watch.zig +++ b/dev/file_watch.zig @@ -459,7 +459,7 @@ pub fn reloadPane( if (pane.file) |file| { const bytes = filesystem.read(core, file.path) catch |err| { // Gone from under the pane: said once, the text kept. - if (err == error.FileNotFound and watched.existed == std.hash.Wyhash.hash(0, file.path)) pardes.panes.File.deleted(core, @intCast(id)); + if (err == error.FileNotFound and watched.existed == std.hash.Wyhash.hash(0, file.path)) pardes.panes.File.deleted(core, .at(id)); return false; }; if (watches[id]) |*live| live.existed = std.hash.Wyhash.hash(0, file.path); @@ -477,7 +477,7 @@ pub fn reloadPane( }; return false; } - if (!core.reloadWatchedFile(@intCast(id), bytes)) return false; + if (!core.reloadWatchedFile(.at(id), bytes)) return false; const current = core.panes[id] orelse return false; if (current.serial != watched.serial) return false; const current_file = current.file orelse return false; @@ -488,7 +488,7 @@ pub fn reloadPane( } if (announce) { var msg_buf: [256]u8 = undefined; - core.setMessage(id, message.stamp(&msg_buf, "reloaded", current_file.path)); + core.setMessage(.at(id), message.stamp(&msg_buf, "reloaded", current_file.path)); } return false; } @@ -510,7 +510,7 @@ pub fn reloadPane( .text => {}, } // Its kind reads the file again (Kind.fileChanged): on the tape, no bytes. - if (!core.reloadWatchedFile(@intCast(id), &.{})) return false; + if (!core.reloadWatchedFile(.at(id), &.{})) return false; const current = core.panes[id] orelse return false; if (current.serial != watched.serial) return false; const current_path = kindPath(current) orelse return false; @@ -522,7 +522,7 @@ pub fn reloadPane( } if (announce) { var msg_buf: [256]u8 = undefined; - core.setMessage(id, message.stamp(&msg_buf, "reloaded", current_path)); + core.setMessage(.at(id), message.stamp(&msg_buf, "reloaded", current_path)); } return false; } @@ -611,12 +611,12 @@ pub fn applyThemeEffect( const pane = request.pane; const bytes = filesystem.readFile(&pardes.tape.none, gpa, request.path) catch |err| { colors.failThemeFile(core, generation, err); - core.noteLateFailure(pane); + core.noteLateFailure(.at(pane)); return false; }; defer gpa.free(bytes); if (!colors.loadThemeFile(core, generation, bytes)) { - core.noteLateFailure(pane); + core.noteLateFailure(.at(pane)); return false; } const hash = std.hash.Wyhash.hash(0, bytes); @@ -659,7 +659,7 @@ pub fn reloadTheme( live.generation = .{ .text = hash }; if (announce) { var msg_buf: [256]u8 = undefined; - core.setMessage(request.pane, message.stamp(&msg_buf, "reloaded theme", request.path)); + core.setMessage(.at(request.pane), message.stamp(&msg_buf, "reloaded theme", request.path)); } return false; } diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 798368e3..3d050bbf 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -2548,7 +2548,7 @@ const Shell = struct { /// last. True when it was not, and is now. fn windowView(s: *Shell) bool { if (s.core.live == s.gview or !pardes.views.isOpen(s.core, s.gview)) return false; - s.core.toView(s.gview); + s.core.toView(.at(s.gview)); return true; } @@ -2680,7 +2680,7 @@ const Shell = struct { s.gview = s.core.live; for (0..pardes.views.max) |i| { const k: u8 = @intCast(i); - if (k != s.gview and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.core.closeView(k); + if (k != s.gview and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.core.closeView(.at(k)); } } @@ -2759,7 +2759,7 @@ const Shell = struct { if (s.gens[e.pane] == e.gen) eof: { if (e.failure) |err| { s.closePty(e.pane); - s.core.readerFailed(e.pane, err); + s.core.readerFailed(.at(e.pane), err); break :eof; } const pt = if (s.ptys[e.pane]) |*pt| pt else { @@ -2789,7 +2789,7 @@ const Shell = struct { }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; - s.core.setStatus(s.core.view().active, message.stamp(&mbuf, "lsp", text)); + s.core.setStatus(.at(s.core.view().active), message.stamp(&mbuf, "lsp", text)); s.lsp_allocator.free(text); }, .pipe => |response_value| { @@ -3334,25 +3334,25 @@ fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| { - if (running) return s.core.restartFailed(pane, err); - return s.core.shellFailed(pane, err); + if (running) return s.core.restartFailed(.at(pane), err); + return s.core.shellFailed(.at(pane), err); }; s.closePty(pane); if (s.ptys[pane] != null) { _ = libc.close(child.file.handle); host_io.retireShell(child.pid); - return s.core.reportError(pane, "shell", error.WorkersBusy); + return s.core.reportError(.at(pane), "shell", error.WorkersBusy); } s.gens[pane] +%= 1; const command = s.core.panes[pane].?.command != null; const pt: Pty = .{ .fd = child.file.handle, .pid = child.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } }; s.ptys[pane] = pt; var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(pane, wd); + if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); if (!s.threads_ok) return; s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| { s.closePty(pane); - return s.core.reportError(pane, "terminal reader", err); + return s.core.reportError(.at(pane), "terminal reader", err); }; } @@ -3363,16 +3363,16 @@ fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void { s.gens[pane] +%= 1; s.ptys[pane] = .{ .fd = a.fd, .pid = a.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{} }; var exe_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - s.core.acknowledgeShell(pane, host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid)); + s.core.acknowledgeShell(.at(pane), host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid)); var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(pane, wd); + if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 }; _ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny)); if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1)); if (!s.threads_ok) return; s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| { s.closePty(pane); - return s.core.reportError(pane, "terminal reader", err); + return s.core.reportError(.at(pane), "terminal reader", err); }; } @@ -3501,14 +3501,14 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { const s = shellOf(ctx); if (s.threads_ok) return s.queue.startLsp(s.core, req); s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); + s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable); } fn pipe(ctx: ?*anyopaque, id: u32) void { const s = shellOf(ctx); if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, s.pipe_tasks, id, s.queue, Queue.pushPipe); s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable); + s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable); } /// A draw (api.draw) on a worker, as a job is. @@ -3579,7 +3579,7 @@ fn handOver(ctx: ?*anyopaque, seq: u32, bytes: []const u8) void { fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void { for (ptys, 0..) |slot, id| if (slot) |pt| { var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.ttyCwd(pt.pid, pt.fd, core.settings.shell.effective.get(), &lbuf)) |cwd| core.setCwd(id, cwd); + if (host_io.ttyCwd(pt.pid, pt.fd, core.settings.shell.effective.get(), &lbuf)) |cwd| core.setCwd(.at(id), cwd); }; } diff --git a/dev/host_io.zig b/dev/host_io.zig index 377263a4..2ee7c47e 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -54,12 +54,12 @@ pub fn stopWorkers() void { pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes { peers.dropAll(core); const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| { - core.reportError(core.view().active, "Restore", err); + core.reportError(.at(core.view().active), "Restore", err); return null; }; defer gpa.free(bytes); const nc = pardes.dump.restore(core, bytes, path) catch |err| { - core.reportError(core.view().active, "Restore", err); + core.reportError(.at(core.view().active), "Restore", err); return null; }; file_watch.unwatchAll(inotify_fd, watches); @@ -93,13 +93,13 @@ pub const Adoptions = struct { pub fn adoptShell(a: *Adoptions, core: *pardes.Pardes, pid: libc.pid_t, fd: c_int) void { if (pid == 0) { var buf: pardes.Kind.Buf(96) = .{}; - return core.setMessage(core.view().active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else buf.print("Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" })); + return core.setMessage(.at(core.view().active), if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else buf.print("Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" })); } if (a.len < a.list.len) { a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null }; a.len += 1; if (core.adoptShell()) |id| { - a.list[a.len - 1].pane = id; + a.list[a.len - 1].pane = id.index(); a.taken += 1; return; } @@ -108,7 +108,7 @@ pub const Adoptions = struct { // No room for it: its master goes, and the shell with this session. _ = libc.close(fd); var buf: pardes.Kind.Buf(96) = .{}; - core.setMessage(core.view().active, buf.print("Adopt: no room for shell {d}; it ends with this session", .{pid})); + core.setMessage(.at(core.view().active), buf.print("Adopt: no room for shell {d}; it ends with this session", .{pid})); } /// The adopted shell pane `pane`'s spawn takes, off the list. @@ -549,7 +549,7 @@ pub fn forkShell( // The daemon keeps a dup: this session killed outright never hangs the // shell up (daemon.zig). @import("runtime").daemon.pty(pid, master); - if (core) |c| c.acknowledgeShell(pane, std.mem.span(spawn.path), one_line == null and spawn.argv[1] != null); + if (core) |c| c.acknowledgeShell(.at(pane), std.mem.span(spawn.path), one_line == null and spawn.argv[1] != null); return .{ .file = .{ .handle = master, .flags = .{ .nonblocking = false } }, .pid = pid }; } @@ -1481,7 +1481,7 @@ fn sleepMs(ms: i64) void { /// change), and "saved" said on the pane. pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, path: []const u8, bytes: []const u8) void { filesystem.write(core, path, bytes) catch |err| - return core.saveFailed(pane, path, err); + return core.saveFailed(.at(pane), path, err); if (core.panes[pane]) |pn| if (pn.file) |f| if (std.mem.eql(u8, f.path, path)) { if (watches[pane]) |*w| if (w.serial == pn.serial) switch (w.generation) { .text => w.generation = .{ .text = std.hash.Wyhash.hash(0, bytes) }, @@ -1489,7 +1489,7 @@ pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, pat }; }; var mbuf: [256]u8 = undefined; - core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "saved", path)); + core.setMessage(.at(pane), pardes.Messages.Message.stamp(&mbuf, "saved", path)); // The init file, saved here (Config): its settings take effect now. pardes.exec.reapplyInitFile(core, path, bytes); // The plumbing file (Plumb): its rules in force now. @@ -1527,12 +1527,12 @@ pub fn writeDump(core: *pardes.Pardes, bytes: []const u8) void { pub fn dumpThemes(core: *pardes.Pardes, io: std.Io, gpa: std.mem.Allocator, pane: u8) void { const config_dir = core.opts.config_dir orelse return; const out_dir = pardes.config.User.dumpThemes(io, gpa, config_dir, pardes.themes) catch |err| { - core.reportError(pane, "dump themes", err); + core.reportError(.at(pane), "dump themes", err); return; }; defer gpa.free(out_dir); var mbuf: [256]u8 = undefined; - core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "dumped themes", out_dir)); + core.setMessage(.at(pane), pardes.Messages.Message.stamp(&mbuf, "dumped themes", out_dir)); } pub const PtyTests = struct { diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 70ea3295..48b5d3d1 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1500,7 +1500,7 @@ const Shell = struct { if (t.stub >= 0) daemon.tellStub(t.stub, "d{s}", .{daemon.name()}); } if (rec.fresh) return; - for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k)); + for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(.at(k)); } fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { @@ -1673,7 +1673,7 @@ const Shell = struct { // The terminal's input goes into its view. switch (event) { .key_press, .mouse, .paste, .paste_start, .paste_end, .winsize, .focus_in, .focus_out, .quit => { - if (s.local() and s.client == null) core.toView(s.own); + if (s.local() and s.client == null) core.toView(.at(s.own)); }, else => {}, } @@ -1807,7 +1807,7 @@ const Shell = struct { }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; - core.setStatus(core.view().active, message.stamp(&mbuf, "lsp", text)); + core.setStatus(.at(core.view().active), message.stamp(&mbuf, "lsp", text)); s.lsp_gpa.free(text); }, .pipe_done => |response_value| { @@ -1851,7 +1851,7 @@ const Shell = struct { if (!sc.on or sc.vx.state.in_band_resize) return; const ws = sc.tty.getWinsize() catch return; if (sc.size) |was| if (std.meta.eql(was, ws)) return; - if (s.client == null) s.core.toView(s.own); + if (s.client == null) s.core.toView(.at(s.own)); s.resized(sc, ws); } @@ -1885,7 +1885,7 @@ const Shell = struct { }; for (&s.ptys, 0..) |*slot, id| if (slot.*) |pt| { var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(id, cwd); + if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(.at(id), cwd); }; const sc = s.term() orelse return; @@ -2035,8 +2035,8 @@ const Shell = struct { // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| { - if (running) return s.core.restartFailed(pane, err); - return s.core.shellFailed(pane, err); + if (running) return s.core.restartFailed(.at(pane), err); + return s.core.shellFailed(.at(pane), err); }; closePty(ctx, pane); // a shell still in the slot goes, reaped s.gens[pane] +%= 1; @@ -2046,7 +2046,7 @@ const Shell = struct { // Only a shell given no directory is asked where it is: one given a // directory is named by it already (newShell), and asked now, before // its chdir, it would answer this process's, a rename to undo. - if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(pane, wd); + if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); if (s.threads_ok) { if (s.ptys[pane]) |*pt| { pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader; @@ -2062,9 +2062,9 @@ const Shell = struct { const file: std.Io.File = .{ .handle = a.fd, .flags = .{ .nonblocking = false } }; s.ptys[pane] = .{ .file = file, .pid = a.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{} }; var exe_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - s.core.acknowledgeShell(pane, host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid)); + s.core.acknowledgeShell(.at(pane), host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid)); var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(pane, wd); + if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 }; _ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny)); if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1)); @@ -2185,7 +2185,7 @@ const Shell = struct { const s = of(ctx); if (!s.threads_ok) { s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); + return s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable); } host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows); } @@ -2199,7 +2199,7 @@ const Shell = struct { const s = of(ctx); if (!s.threads_ok) { s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable); + return s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable); } selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe); } diff --git a/runtime/9p_io.zig b/runtime/9p_io.zig index ef4ecfdd..bcb0f81b 100644 --- a/runtime/9p_io.zig +++ b/runtime/9p_io.zig @@ -1109,7 +1109,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes) ?*Listene // unreachable: a u32 is at most 10 digits const fallback = std.fmt.bufPrint(&name, "{d}", .{@as(u32, @intCast(libc.getpid()))}) catch unreachable; return listen(io, gpa, core, core.opts.ninep_name, fallback, core.opts.ninep_tcp) catch { - if (refusal.len > 0) core.setMessage(0, refusal) else core.reportError(0, "9p listener", error.ListenFailed); + if (refusal.len > 0) core.setMessage(.at(0), refusal) else core.reportError(.at(0), "9p listener", error.ListenFailed); return null; }; } @@ -2647,7 +2647,7 @@ test "a held read is answered when the log has news, and a flushed one spends no try s.flush(); try heldNow.count(p, 2); pardes.turn.wake(); - p.setMessage(0, "after the flush"); + p.setMessage(.at(0), "after the flush"); pardes.turn.rest(); try heldNow.count(p, 1); pardes.turn.wake(); @@ -2670,7 +2670,7 @@ test "a held read is answered when the log has news, and a flushed one spends no try testing.expectEqual(second, refused.tag); try testing.expectEqualStrings(pardes.ctlfs.e_in_use, refused.result.fail); pardes.turn.wake(); - p.setMessage(0, "while held"); + p.setMessage(.at(0), "while held"); const retry_all = pardes.turn.parked; pardes.turn.rest(); try testing.expect(!retry_all); @@ -2698,9 +2698,9 @@ test "a held read is answered when the log has news, and a flushed one spends no try s.flush(); try heldNow.count(p, 1); pardes.turn.wake(); - p.setMessage(0, "queued one"); - p.setMessage(0, "queued two"); - p.setMessage(0, "queued three"); + p.setMessage(.at(0), "queued one"); + p.setMessage(.at(0), "queued two"); + p.setMessage(.at(0), "queued three"); l.reset(p); pardes.turn.rest(); const cut = try s.settle(); diff --git a/runtime/addon_test.zig b/runtime/addon_test.zig index a08237fc..a37a2262 100644 --- a/runtime/addon_test.zig +++ b/runtime/addon_test.zig @@ -121,7 +121,7 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons if (is(verb, "view")) { const n = std.fmt.parseInt(u8, arg[0..@min(1, arg.len)], 10) catch 1; while (n > 1 and !pardes.views.isOpen(p, n - 1)) _ = p.openView() orelse break; - if (pardes.views.isOpen(p, n -| 1)) p.toView(n -| 1); + if (pardes.views.isOpen(p, n -| 1)) p.toView(.at(n -| 1)); } p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.endsWith(u8, arg, "on") } }); } else if (is(verb, "dump")) { diff --git a/runtime/macos.zig b/runtime/macos.zig index 4f8bd709..3a00210d 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -385,7 +385,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { while (core.nextEffect()) |effect| core.perform(effect); st.started = true; - if (st.ninep) |listener| listener.watch(st, wakeNinep) catch |err| core.reportError(0, "9p wake", err); + if (st.ninep) |listener| listener.watch(st, wakeNinep) catch |err| core.reportError(.at(0), "9p wake", err); for (&st.ptys, 0..) |*slot, id| if (slot.*) |*pt| startReader(st, pt, @intCast(id)); pardes.lsp.setStatusSink(&st.inbox, Inbox.lspStatus); @@ -593,7 +593,7 @@ fn refreshCwds(ctx: ?*anyopaque) void { stale.* = false; const pt = st.ptys[id] orelse continue; var buf: [1024]u8 = undefined; - if (host_io.ttyCwd(pt.pid, pt.file.handle, st.core.settings.shell.effective.get(), &buf)) |wd| st.core.setCwd(id, wd); + if (host_io.ttyCwd(pt.pid, pt.file.handle, st.core.settings.shell.effective.get(), &buf)) |wd| st.core.setCwd(.at(id), wd); } } @@ -682,7 +682,7 @@ fn reloadWatchedTheme(st: *State, announce: bool) bool { live.retries_left = 0; if (announce) { var mbuf: [256]u8 = undefined; - st.core.setMessage(request.pane, message.stamp(&mbuf, "reloaded theme", request.path)); + st.core.setMessage(.at(request.pane), message.stamp(&mbuf, "reloaded theme", request.path)); } return true; } @@ -711,7 +711,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool { defer st.core.gpa.free(bytes); const hash = std.hash.Wyhash.hash(0, bytes); if (hash == old_hash) break :text .no_change; - if (!st.core.reloadWatchedFile(pane, bytes)) { + if (!st.core.reloadWatchedFile(.at(pane), bytes)) { retryWatchedFile(st, pane, generation); break :text .no_change; } @@ -732,7 +732,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool { break :pdf .no_change; }; if (old_identity) |old| if (old.eql(before)) break :pdf .no_change; - if (!st.core.reloadWatchedFile(pane, &.{})) { + if (!st.core.reloadWatchedFile(.at(pane), &.{})) { retryWatchedFile(st, pane, generation); break :pdf .no_change; } @@ -759,7 +759,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool { }; if (result == .committed and announce) { var mbuf: [256]u8 = undefined; - st.core.setMessage(pane, message.stamp(&mbuf, "reloaded", watched.path)); + st.core.setMessage(.at(pane), message.stamp(&mbuf, "reloaded", watched.path)); } return result != .no_change; } @@ -817,7 +817,7 @@ fn drainInbox(st: *State) bool { }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; - st.core.setStatus(st.core.view().active, message.stamp(&mbuf, "lsp", text)); + st.core.setStatus(.at(st.core.view().active), message.stamp(&mbuf, "lsp", text)); }, .pipe => |value| { st.core.update(.{ .pipe_resp = .{ @@ -874,12 +874,12 @@ fn restoreCore(st: *State) bool { if (st.core.quit) return false; const path = st.core.takeRestore() orelse return false; const bytes = dump.restoreBytes(st.core, st.gpa, path) catch |err| { - st.core.reportError(st.core.view().active, "Restore", err); + st.core.reportError(.at(st.core.view().active), "Restore", err); return false; }; defer st.gpa.free(bytes); const replacement = dump.restore(st.core, bytes, path) catch |err| { - st.core.reportError(st.core.view().active, "Restore", err); + st.core.reportError(.at(st.core.view().active), "Restore", err); return false; }; if (st.inbox.lsp_task) |*task| { @@ -1655,8 +1655,8 @@ fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { // start leaves the running one be (pty/ctl's exec). const running = st.ptys[pane] != null; const child = host_io.forkShell(core, pane, &st.prompt_rcs, core.shellBin(), cwd, core.view().screen_h, core.view().screen_w) catch |err| { - if (running) return core.restartFailed(pane, err); - return core.shellFailed(pane, err); + if (running) return core.restartFailed(.at(pane), err); + return core.shellFailed(.at(pane), err); }; reap(st, pane); st.gens[pane] +%= 1; @@ -1673,7 +1673,7 @@ fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { // Only a shell given no directory is asked where it is: one given a // directory is named by it already (newShell), and asked now, before // its chdir, it would answer this process's, a rename to undo. - if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| core.setCwd(pane, wd); + if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| core.setCwd(.at(pane), wd); if (st.started) if (st.ptys[pane]) |*pt| startReader(st, pt, pane); } @@ -1710,10 +1710,10 @@ fn killJob(ctx: ?*anyopaque, pane: u8) bool { fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void { const st = hostState(ctx); filesystem.write(st.core, path, bytes) catch |err| - return st.core.saveFailed(pane, path, err); + return st.core.saveFailed(.at(pane), path, err); st.file_watches.restampText(pane, path, std.hash.Wyhash.hash(0, bytes)); var mbuf: [256]u8 = undefined; - st.core.setMessage(pane, message.stamp(&mbuf, "saved", path)); + st.core.setMessage(.at(pane), message.stamp(&mbuf, "saved", path)); } fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { @@ -1739,12 +1739,12 @@ fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { const st = hostState(ctx); const config_dir = st.core.opts.config_dir orelse return; const out_dir = pardes.config.User.dumpThemes(st.io, st.gpa, config_dir, pardes.themes) catch |err| { - st.core.reportError(pane, "dump themes", err); + st.core.reportError(.at(pane), "dump themes", err); return; }; defer st.gpa.free(out_dir); var mbuf: [256]u8 = undefined; - st.core.setMessage(pane, message.stamp(&mbuf, "dumped themes", out_dir)); + st.core.setMessage(.at(pane), message.stamp(&mbuf, "dumped themes", out_dir)); } fn setClipboard(ctx: ?*anyopaque, text: []const u8) void { diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 6ee5d29c..77928dd0 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -77,7 +77,7 @@ fn inodeOf(path: [:0]const u8) ?u64 { /// rebuilding (a stat). ponytail: explicit only, no watch and no automatic /// upgrade. pub fn noticeNewer(core: *pardes.Pardes) void { - if (newer()) core.setMessage(core.view().active, pardes.newer_build_words); + if (newer()) core.setMessage(.at(core.view().active), pardes.newer_build_words); } /// Whether to say a newer build is installed now (`noticeNewer`): the @@ -413,7 +413,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op // keep its blocks for as long as this session runs. if (rec.old >= 0) _ = libc.close(rec.old); rec.old = -1; - p.setMessage(p.view().active, if (rec.refused.len > 0) + p.setMessage(.at(p.view().active), if (rec.refused.len > 0) std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before" else "Upgrade: now " ++ version_line); @@ -435,7 +435,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op var o = opts; o.load_path = null; const p = try pardes.Pardes.init(core_gpa, o); - p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore"); + p.setMessage(.at(p.view().active), std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore"); return p; } } diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig index fa6657eb..ef5dec60 100644 --- a/test/fs_namespace.zig +++ b/test/fs_namespace.zig @@ -256,7 +256,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation" const p = try pardes.Pardes.init(allocator.allocator(), .{ .tty_only = true }); defer p.deinit(); const source = try p.setTestFile("source body\n"); - p.setCwd(0, "/source/directory"); + p.setCwd(.at(0), "/source/directory"); while (p.nextEffect()) |_| {} var path: [128]u8 = undefined; const name = try std.fmt.bufPrint(&path, "/virtual/pane/{d}/body", .{source.serial}); diff --git a/test/panes.zig b/test/panes.zig index 407f2c3c..022d672c 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -1416,7 +1416,7 @@ test "Save rearms renamed file watches only after a successful write" { const h: *@This() = @ptrCast(@alignCast(ctx.?)); switch (h.result) { .success => {}, - .failure => h.core.saveFailed(id, "save", error.PermissionDenied), + .failure => h.core.saveFailed(.at(id), "save", error.PermissionDenied), .edited => h.core.panes[id].?.file.?.revision +%= 1, .replaced => { const replacement = h.core.setTestFile("replacement\n") catch |err| { @@ -1486,7 +1486,7 @@ test "Save on a scratch does not watch a path the host could not create" { const Refusing = struct { fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); - p.saveFailed(id, "save", error.PermissionDenied); + p.saveFailed(.at(id), "save", error.PermissionDenied); } }; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); @@ -1520,7 +1520,7 @@ test "a failed Save to another name leaves a clean named file clean" { const Refusing = struct { fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); - p.saveFailed(id, "save", error.AccessDenied); + p.saveFailed(.at(id), "save", error.AccessDenied); } }; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); @@ -2500,7 +2500,7 @@ const TerminalTests = struct { else => {}, }; - p.acknowledgeShell(0, "/bin/bash", true); + p.acknowledgeShell(.at(0), "/bin/bash", true); while (p.nextEffect()) |effect| switch (effect) { .write => return error.CommandEscapedBeforePrompt, else => {}, @@ -2533,7 +2533,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} try std.testing.expect(pane.greet); - p.acknowledgeShell(0, "/bin/sh", false); + p.acknowledgeShell(.at(0), "/bin/sh", false); try std.testing.expect(!pane.greet); try std.testing.expectEqual(.none, pane.pending_command.wait); p.update(.{ .output = .{ .pane = 0, .bytes = "plain prompt$ " } }); @@ -4077,7 +4077,7 @@ const PdfAddon = struct { // Another file under its name (an outline's three pages): opened // again, on the page it can still be on, as height-fitted. try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", p.scratch.allocator(), .unlimited) }); - try std.testing.expect(p.reloadWatchedFile(@intCast(id), &.{})); + try std.testing.expect(p.reloadWatchedFile(.at(id), &.{})); p.update(.tick); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); @@ -4225,7 +4225,7 @@ const PdfAddon = struct { defer arena.deinit(); var at: [2][8][4]u32 = @splat(@splat(@splat(0))); for ([_]*Pardes{ a.core, win.core() }, [_]u8{ 0, k.view }, &at) |core, view, *rows| { - core.toView(view); + core.toView(.at(view)); var n: usize = 0; for ((try core.render(arena.allocator())).placements.items) |pl| if (pl.pane == id and pl.raster.w > 1 and n < rows.len) { rows[n] = if (pl.at) |x| .{ x.y, x.h, pl.src.y, pl.src.h } else .{ 0, 0, pl.src.y, pl.src.h }; @@ -4285,7 +4285,7 @@ const PdfAddon = struct { try std.testing.expect(first.len > 0); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); - win.core().toView(c.view); + win.core().toView(.at(c.view)); const s = try win.core().render(arena.allocator()); const r = win.core().view().rects[c.id]; var row: [512]u8 = undefined; diff --git a/test/replicas.zig b/test/replicas.zig index 7f7ca0b3..88881dd7 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -1393,7 +1393,7 @@ const Soak = struct { s.clock(); var buf: [64]u8 = undefined; const ev = nextEvent(s.random, &buf, s.aim, s.looks, &s.own_script); - core.toView(0); + core.toView(.at(0)); core.update(ev); s.own_left -= 1; if (s.own_left > 0) try s.net.send(.{ .at = m.at + typistGap(s.random), .n = 0, .kind = .own, .who = 0, .bytes = &.{} }) else s.typing -= 1; diff --git a/test/session.zig b/test/session.zig index 844ea2fe..bf118533 100644 --- a/test/session.zig +++ b/test/session.zig @@ -368,9 +368,9 @@ pub const Session = struct { const p = pardesOf(s); const gpa = p.gpa; const name = p.takeRestore() orelse return; - const bytes = pardes.dump.restoreBytes(p, gpa, name) catch |err| return p.reportError(p.view().active, "Restore", err); + const bytes = pardes.dump.restoreBytes(p, gpa, name) catch |err| return p.reportError(.at(p.view().active), "Restore", err); defer gpa.free(bytes); - const nc = pardes.dump.restore(p, bytes, name) catch |err| return p.reportError(p.view().active, "Restore", err); + const nc = pardes.dump.restore(p, bytes, name) catch |err| return p.reportError(.at(p.view().active), "Restore", err); p.deinit(); s.core = nc; s.drain(); -- cgit v1.3 From bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 18:35:16 -0300 Subject: core, dev: what carries a slot across the core's edge carries its type (P21, pardes-ids change 3): `Pane.Id` in Event's six variants that carry a pane (output, eof, exited, file_changed, addon, job), in the fourteen effects that do (spawn, write, resize_pty, signal_pty, close_pty, start, save_file, save_text, lsp, watch, dump_themes, detach, addon, job), in the fourteen Host functions that take one (dev/Host.zig: adopt, upgrade, spawn, pty_write, pty_resize, pty_signal, close_pty, tty_taken, fg_name, kill_job, write_file, watch_file, dump_themes, job; tape.zig's Wrap follows with no edit), in the device messages that carry one into the core (the inbox's output and eof and the five reader functions that make them, dev/Lsp.zig's Request, host_io's Adoption and Adoptions.take, which hold what adoptShell answered); `View.Id` in abi/wire.zig's welcome.view (its bytes on the wire unchanged: one byte, hand-encoded, `.at(takeByte())`/`writeByte(view.index())`); every producer converts at its own line (`.pane = .at(id)`, a script that refuses any path outside the workspace, `fields.py`), every consumer where it indexes or compares (`o.pane.index()`), every Host implementer at its own first line (`fn spawn(ctx, id: pardes.Pane.Id, ..) { const pane = id.index(); ..}`: the terminal's 14, the window's 14, the Mac's 10, and the tests' hosts), and an id that went integer and back is passed through whole (`s.core.readerFailed(e.pane, err)`); the compiler caught no pane's slot passed as a view's or the reverse, only integers meeting the type; kept integers on purpose: KindJob.pane (core/Kind.zig, another agent's, reads it four times; converted at KindJob's and Effect's lines), the Watch table (file_watch: its last slot is the theme's, no pane), the hello's view and the replica's Peer/Joined/Replica views (core/replica.zig, another agent's), the C ABI's `pardes_watch_changed(uint8_t pane)` (abi/pardes.h unchanged; runtime/macos.zig converts at its Host functions); in files another agent is in, each conversion on the line that was there: core/Kind.zig 2 lines, core/Addon.zig 4, core/replica.zig 31 (the welcome's view, 3 test hosts, test literals), test/replicas.zig 12 (4 host functions with their first lines, 1 signature, the welcome's view, 5 literals); the tape's shape moves (Event is update's input), so the semantics word moves, c47ecf638b3f4b9f -> 38b5ae573b965550; test/perf.zig follows on 6 lines its Event and effect literals forced, so its harness id moves, be7cc504010471bc -> 1ed95030eb768eae (unit-test's perf check was BaselineHarnessMismatch already); 607 lines added, 562 deleted in 48 files. Gate (load 4 to 8): tui core-test 841/984 (143 skipped), shell-test 1020/1023, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds of 70 steps, 0 failures, process-test lspcomplete and lspcompletemoved (the base's; hscroll failed once and passed on the runner's retry), gui unit-test 1618/1622 (BaselineHarnessMismatch, the base's); replicas --clients 5 (TMPDIR /tmp/claude-1000/ids): diverged 0, unequal 0 at rtt 30, 80, 207, deltas checked/wrong 1811/0, 1838/0, 1660/0, quiet checks 567/0, 650/0, 655/0, stops not on may_wait 0 (corpus through a client fails at step 21 as on the base with that TMPDIR); daemon.py plain, --far, --games, --window-clients, --upgrade both ways against pardes-tree's base prefix pass (the semantics words differ: the upgrade carries the session by its dump); test/cross_replay.py (tui records, gui replays): 27 digests agree in each of three replicas; rollback-bench runs; the macOS library for Linux and aarch64-macos and the FreeBSD cross-build build; frames (gpu/ids-3 against tree1) 77/77 byte-identical in Debug, unit-test 1618/1622 there, perfab corpus2x -0.021% (session noise 0.036%, threshold 0.4%), pictures identical in all 10 runs, perfops 97 counts within 0.1% (largest image-frame on longline +0.0231%), key-down on medium 10,040,108 -> 10,039,990 an operation (-0.0012%), render on medium 11,455,765 -> 11,455,683 (-0.0007%), terminal on all +0.0030% Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 6 +- core/Addon.zig | 8 +-- core/Core.zig | 128 +++++++++++++++++++++-------------------- core/Effect.zig | 88 ++++++++++++++-------------- core/Event.zig | 13 +++-- core/File.zig | 8 +-- core/Jump.zig | 4 +- core/Kind.zig | 4 +- core/Plumb.zig | 2 +- core/Query.zig | 2 +- core/builtins.zig | 18 +++--- core/dump.zig | 4 +- core/echo.zig | 4 +- core/edit.zig | 6 +- core/exec.zig | 6 +- core/fs.zig | 4 +- core/keys.zig | 2 +- core/look.zig | 8 +-- core/lsp/Ask.zig | 4 +- core/mouse.zig | 14 ++--- core/ninep/ctl.zig | 28 ++++----- core/ninep/pane.zig | 4 +- core/ninep/pty.zig | 34 +++++------ core/ninep/screen.zig | 10 ++-- core/ninep/testing.zig | 6 +- core/panes.zig | 8 +-- core/replica.zig | 57 +++++++++--------- core/root.zig | 2 +- core/views.zig | 2 +- dev/Host.zig | 28 ++++----- dev/Inbox.zig | 28 ++++----- dev/KindJob.zig | 2 +- dev/Lsp.zig | 26 ++++----- dev/file_watch.zig | 6 +- dev/gui/gui.zig | 126 ++++++++++++++++++++++------------------ dev/host_io.zig | 52 ++++++++--------- dev/tui/tui.zig | 72 +++++++++++++---------- runtime/macos.zig | 63 +++++++++++--------- test/fs_namespace.zig | 4 +- test/hxdiff.zig | 2 +- test/kitty.zig | 4 +- test/output.zig | 6 +- test/panes.zig | 150 ++++++++++++++++++++++++------------------------ test/perf.zig | 12 ++-- test/replicas.zig | 26 +++++---- test/rollback_bench.zig | 2 +- test/session.zig | 4 +- test/terminal.zig | 72 +++++++++++------------ 48 files changed, 607 insertions(+), 562 deletions(-) (limited to 'core/Core.zig') diff --git a/abi/wire.zig b/abi/wire.zig index cf3daf2e..b2d32033 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -194,7 +194,7 @@ pub const ServerMsg = union(ServerTag) { /// dump that follows is, and the session's offset from UTC (a replica /// guesses the session's time of day). A far client is told how many /// blobs the dump holds (`blobs`). - welcome: struct { pid: u32, session: []const u8, client: u16 = 0, view: u8 = 0, dump_len: u64 = 0, gmtoff: i32 = 0, digest: u64 = 0, semantics: u64 = 0, blobs: u32 = 0 }, + welcome: struct { pid: u32, session: []const u8, client: u16 = 0, view: pardes.Pardes.View.Id = .at(0), dump_len: u64 = 0, gmtoff: i32 = 0, digest: u64 = 0, semantics: u64 = 0, blobs: u32 = 0 }, refused: []const u8, pong: u64, dump: []const u8, @@ -223,7 +223,7 @@ pub fn decodeServer(tag: u8, payload: []const u8) Error!ServerMsg { .pid = try r.takeInt(u32, .little), .session = try r.take(try r.takeInt(u16, .little)), .client = try r.takeInt(u16, .little), - .view = try r.takeByte(), + .view = .at(try r.takeByte()), .dump_len = try r.takeInt(u64, .little), .gmtoff = try r.takeInt(i32, .little), .digest = try r.takeInt(u64, .little), @@ -252,7 +252,7 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 { try w.writeInt(u32, h.pid, .little); try putSlice16(&w, h.session); try w.writeInt(u16, h.client, .little); - try w.writeByte(h.view); + try w.writeByte(h.view.index()); try w.writeInt(u64, h.dump_len, .little); try w.writeInt(i32, h.gmtoff, .little); try w.writeInt(u64, h.digest, .little); diff --git a/core/Addon.zig b/core/Addon.zig index e84b122b..cb3dbf54 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -69,7 +69,7 @@ pub fn perform(p: *Pardes, op: Op, pane: u8, arg: []const u8) void { var words: [64]LoadedWord = undefined; var why: Why = .{}; const l = readLoaded(arg, &words, &why); - p.update(.{ .addon = .{ .op = op, .pane = pane, .kind = &l } }); + p.update(.{ .addon = .{ .op = op, .pane = .at(pane), .kind = &l } }); } /// What a load reads off the library at `path` (held): the `addon` @@ -727,12 +727,12 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { const dir = std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/"); const path = if (std.Io.Dir.path.isAbsolute(rest)) rest else std.fmt.bufPrint(&target, "{s}/{s}", .{ dir, rest }) catch return p.reportFailure(id, "Addon: that path is too long"); if (path.len > pardes.effect_path_cap) return p.reportFailure(id, "Addon: that path is too long"); - return p.emit(.{ .addon = .{ .op = .load, .pane = @intCast(id), .arg = .from(path) } }); + return p.emit(.{ .addon = .{ .op = .load, .pane = .at(id), .arg = .from(path) } }); } const k = p.kinds.byName(rest) orelse return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon {t}: no addon brought kind {s}", .{ op, rest }) catch takes); const e = &p.kinds.kinds[k]; if (op == .reload and std.mem.eql(u8, e.path.slice(), "builtin")) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s} is built into this pardes", .{rest}) catch takes); - if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = @intCast(id), .arg = .from(e.path.slice()) } }); + if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = .at(id), .arg = .from(e.path.slice()) } }); const n = openPanes(p, rest); if (n > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon unload: {d} {s} pane{s} open", .{ n, rest, if (n == 1) " is" else "s are" }) catch takes); const hash = e.hash; @@ -743,7 +743,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { } fn release(p: *Pardes, hash: [32]u8) void { - p.emit(.{ .addon = .{ .op = .release, .pane = 0, .arg = .from(&hash) } }); + p.emit(.{ .addon = .{ .op = .release, .pane = .at(0), .arg = .from(&hash) } }); } pub fn openPanes(p: *const Pardes, name: []const u8) usize { diff --git a/core/Core.zig b/core/Core.zig index e3238a6e..282094b3 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -956,7 +956,7 @@ pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void { if (p.pending_write[id] == null) { while (off < bytes.len and p.effects_len < p.effects.len) { const n = @min(bytes.len - off, effect_write_cap); - p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(bytes[off .. off + n]) } }); + p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(bytes[off .. off + n]) } }); off += n; } } @@ -1278,7 +1278,7 @@ fn refillPendingWrites(p: *Pardes) void { // a copy's cursor and re-send the same chunk for ever. const pw = if (slot.*) |*live| live else break; const n = @min(pw.bytes.len - pw.off, effect_write_cap); - p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } }); + p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } }); pw.off += n; p.pending_write_bytes -= n; if (pw.off == pw.bytes.len) { @@ -1324,17 +1324,17 @@ fn nextQueued(p: *Pardes) ?Event { pub fn hostForegroundName(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 { const f = p.host.vtable.fg_name orelse return null; - return f(p.host.ctx, @intCast(id), buf); + return f(p.host.ctx, .at(id), buf); } pub fn hostTtyTaken(p: *const Pardes, id: usize) bool { const f = p.host.vtable.tty_taken orelse return false; - return f(p.host.ctx, @intCast(id)); + return f(p.host.ctx, .at(id)); } pub fn hostKillJob(p: *const Pardes, id: usize) bool { const f = p.host.vtable.kill_job orelse return false; - return f(p.host.ctx, @intCast(id)); + return f(p.host.ctx, .at(id)); } /// A terminal whose shell could not be started: said, and a run waiting @@ -1626,8 +1626,8 @@ fn updateInner(p: *Pardes, ev: Event) void { const hover_stays = switch (ev) { .tick, .search => true, .mouse => |m| m.button == .none and m.kind == .motion, - .output => |o| look.lookHoverPane(p) != o.pane, - .file_changed => |changed| look.lookHoverPane(p) != changed.pane, + .output => |o| look.lookHoverPane(p) != o.pane.index(), + .file_changed => |changed| look.lookHoverPane(p) != changed.pane.index(), else => false, }; if (!hover_stays) { @@ -1665,30 +1665,30 @@ fn updateInner(p: *Pardes, ev: Event) void { p.resize_count += 1; }, .output => |o| { - const pane = p.panes[o.pane] orelse return; + const pane = p.panes[o.pane.index()] orelse return; pane.shell_spoke = true; - ctlfs.events.notePtyOutput(p, o.pane, o.bytes); + ctlfs.events.notePtyOutput(p, o.pane.index(), o.bytes); pane.feedOutput(p, o.bytes); - ctlfs.pty.noteMarks(p, o.pane, pane); - exec.flushReplEnter(p, o.pane, true); + ctlfs.pty.noteMarks(p, o.pane.index(), pane); + exec.flushReplEnter(p, o.pane.index(), true); }, - .exited => |e| if (p.panes[e.pane]) |pane| { + .exited => |e| if (p.panes[e.pane.index()]) |pane| { if (pane.command == null) ctlfs.pty.shellExited(p, pane, e.status) else if (!pane.command_done) - pane.commandDone(p, e.pane, e.status); + pane.commandDone(p, e.pane.index(), e.status); }, - .eof => |e| if (p.panes[e.pane]) |pane| if (pane.command != null) { + .eof => |e| if (p.panes[e.pane.index()]) |pane| if (pane.command != null) { // Output is over; the command is over when its child exits. pane.command_pty = false; - } else p.removePane(e.pane, null) catch |err| { + } else p.removePane(e.pane.index(), null) catch |err| { pane.body.mode = .normal; - p.reportError(.at(e.pane), "terminal exited; Del retries close", err); + p.reportError(e.pane, "terminal exited; Del retries close", err); }, .lsp_resp => |r| @import("lsp/Ask.zig").lspResponse(p, r.id, r.rows), .pipe_resp => |r| Pipe.pipeResponse(p, r.id, r.success, r.outputs, r.failure), .search => |b| Stream.receive(p, &b), - .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane, fc.bytes), + .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane.index(), fc.bytes), .key => |key| { p.can_ask = true; defer p.can_ask = false; @@ -1706,8 +1706,8 @@ fn updateInner(p: *Pardes, ev: Event) void { if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(.at(v.active), newer_build_words); }, .handed => |h| p.handover.finish(p, h.seq, h.to, h.failure), - .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*), - .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes), + .addon => |a| pardes.Addon.landed(p, a.op, a.pane.index(), a.kind.*), + .job => |j| pardes.Kind.jobDone(p, j.pane.index(), j.serial, j.token, j.gen, j.bytes), .frontend => |f| { v.frontend = f; }, @@ -1960,7 +1960,7 @@ pub fn sync(p: *Pardes) void { if (pane.isTerminal()) { pane.resizeGrid(cols, rows); p.shell_rows.markStale(pane); // reflow moved every row - 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 = null; } pane.cols = cols; @@ -1987,7 +1987,7 @@ pub fn sync(p: *Pardes) void { .wait => {}, .never => pane.greet = false, .now => { - p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = pane.cols, .rows = pane.rows } }); + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); p.emitWrite(id, "ls\r"); pane.greet = false; }, @@ -2333,7 +2333,8 @@ const FakeTtyQuery = struct { p.host = .{ .ctx = f, .vtable = &vtable }; } - fn answer(ctx: ?*anyopaque, pane: u8) bool { + fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const f: *FakeTtyQuery = @ptrCast(@alignCast(ctx.?)); f.asked += 1; return f.taken[pane]; @@ -2462,7 +2463,7 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - try std.testing.expectEqual(@as(u8, 0), w.pane); + try std.testing.expectEqual(0, w.pane.index()); try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len); @memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice()); sent_len += w.bytes.slice().len; @@ -2684,7 +2685,7 @@ test "Term spawns a raw shell in the caller's directory" { var found = false; while (p.nextEffect()) |effect| switch (effect) { - .spawn => |s| if (@as(usize, s.pane) == free) { + .spawn => |s| if (s.pane.index() == free) { try std.testing.expectEqualStrings("/tmp/newtty-dir", s.cwd.slice()); found = true; }, @@ -2708,11 +2709,11 @@ test "a terminal respawned into a closed pane's slot hangs the old shell up firs var closed = false; var spawned = false; while (p.nextEffect()) |effect| switch (effect) { - .close_pty => |c| if (c.pane == slot) { + .close_pty => |c| if (c.pane.index() == slot) { try std.testing.expect(!spawned); closed = true; }, - .spawn => |s| if (s.pane == slot) { + .spawn => |s| if (s.pane.index() == slot) { spawned = true; }, else => {}, @@ -2784,7 +2785,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type var spawned = false; while (p.nextEffect()) |effect| switch (effect) { .write => return error.TypedIntoATerminal, - .spawn => |sp| if (sp.pane == dst) { + .spawn => |sp| if (sp.pane.index() == dst) { try std.testing.expectEqualStrings("/tmp/pardes-image-dir", sp.cwd.slice()); spawned = true; }, @@ -2815,7 +2816,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty var spawned = false; while (p.nextEffect()) |effect| switch (effect) { .write => return error.WroteACommandLineIntoATerminal, - .spawn => |sp| if (sp.pane == dst) { + .spawn => |sp| if (sp.pane.index() == dst) { // ...in the directory the command was about, the taken pane's own try std.testing.expectEqualStrings("/tmp/pardes-taken", sp.cwd.slice()); spawned = true; @@ -2843,7 +2844,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 0 } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 0 } }); _ = exec.execute(p, 1, two); while (p.nextEffect()) |_| {} _ = try p.render(frame.allocator()); @@ -2863,7 +2864,8 @@ test "a spawn is for the pane it was made for, not whatever took the slot since" var command: [32]u8 = undefined; var core: *Pardes = undefined; const vtable: Host.VTable = .{ .spawn = spawn }; - fn spawn(_: ?*anyopaque, pane: u8, _: []const u8) void { + fn spawn(_: ?*anyopaque, id: pardes.Pane.Id, _: []const u8) void { + const pane = id.index(); spawns += 1; const line = core.panes[pane].?.command.?; @memcpy(command[0..line.len], line); @@ -2901,8 +2903,8 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe spawned = false; while (pp.nextEffect()) |effect| switch (effect) { .write => |w| { - @memcpy(to[w.pane][len[w.pane]..][0..w.bytes.slice().len], w.bytes.slice()); - len[w.pane] += w.bytes.slice().len; + @memcpy(to[w.pane.index()][len[w.pane.index()]..][0..w.bytes.slice().len], w.bytes.slice()); + len[w.pane.index()] += w.bytes.slice().len; }, .spawn => spawned = true, else => {}, @@ -2960,12 +2962,12 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe try std.testing.expectEqualStrings("a = 1\rb = [201~2\r", Sent.said(1)); // Into a REPL that takes a bracketed paste (3.13's), the Enter waits // for the REPL to answer the paste: read with it, it would be part of it. - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004h" } }); Sent.drain(p); _ = exec.executeFrom(p, 0, "print(1)", true); Sent.drain(p); try std.testing.expectEqualStrings("\x1b[200~print(1)\x1b[201~", Sent.said(1)); - p.update(.{ .output = .{ .pane = 1, .bytes = "print(1)" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "print(1)" } }); Sent.drain(p); // Python's echo only restarts a short wait: the Enter goes once the // echo of the whole paste has gone quiet. @@ -2991,7 +2993,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe p.update(.tick); Sent.drain(p); try std.testing.expectEqualStrings("\r", Sent.said(1)); - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004l" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004l" } }); Sent.len[1] = 0; // A block left open by its indented last line gets the blank line that // ends it: a second Enter. @@ -3095,7 +3097,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe _ = try pardes.panes.newCommand(p, cmd, "", "python3"); try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python")); try std.testing.expect(p.panes[cmd].?.repl != null); - p.update(.{ .exited = .{ .pane = @intCast(cmd), .status = 0 } }); + p.update(.{ .exited = .{ .pane = .at(cmd), .status = 0 } }); try std.testing.expect(p.panes[cmd].?.repl == null); try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python")); try std.testing.expect(p.panes[cmd].?.repl == null); @@ -3203,32 +3205,32 @@ test "a command pane shows how its command ended, and the next command there run const other = exec.execute(p, 1, "ls") orelse return error.NoCommandPane; try std.testing.expect(other != dst); while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "compiled\r\n" } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "compiled\r\n" } }); // Its exit comes first, a job it left still printing: done, and not // the next command's until its pty closes. - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); try std.testing.expect(pane.command_done and pane.command_pty); const busy = exec.execute(p, 1, "true") orelse return error.NoCommandPane; try std.testing.expect(busy != dst); while (p.nextEffect()) |_| {} // Its output ending: now it may be reused. - p.update(.{ .eof = .{ .pane = @intCast(dst) } }); + p.update(.{ .eof = .{ .pane = .at(dst) } }); try std.testing.expect(p.panes[dst] == pane and !pane.command_pty); try std.testing.expect(p.panes[dst] == pane); try std.testing.expect(pane.command_done); try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) exit 2")); // Kill leaves a finished one be. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); - while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) return error.SignalledAFinishedCommand; + while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) return error.SignalledAFinishedCommand; // A program that crashed out of its full screen leaves the emulator // in its modes; the next command starts clear of them. - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } }); try std.testing.expect(pardes.Term.modes(pane.terminal).bracketed_paste); // Done, the directory's next command runs there, below what it showed. try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "make test")); try std.testing.expect(!pardes.Term.modes(pane.terminal).bracketed_paste); var respawned = false; - while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane == dst) { + while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane.index() == dst) { respawned = true; }; try std.testing.expect(respawned); @@ -3242,7 +3244,7 @@ test "a command pane shows how its command ended, and the next command there run // Kill stops a running one: its whole process group, SIGTERM. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); var signalled = false; - while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) { + while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) { try std.testing.expectEqual(PtySignal.term, effect.signal_pty.sig); signalled = true; }; @@ -3260,7 +3262,7 @@ test "a command pane shows how its command ended, and the next command there run const Count = struct { var signals: usize = 0; const vtable: Host.VTable = .{ .pty_signal = signal }; - fn signal(_: ?*anyopaque, _: u8, _: PtySignal) void { + fn signal(_: ?*anyopaque, _: pardes.Pane.Id, _: PtySignal) void { signals += 1; } }; @@ -3300,7 +3302,7 @@ test "a terminal its program gave back takes command lines again" { var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - try std.testing.expectEqual(@as(u8, 0), w.pane); + try std.testing.expectEqual(0, w.pane.index()); try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len); @memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice()); sent_len += w.bytes.slice().len; @@ -3360,7 +3362,7 @@ test "a host with no methods at all is a complete in-process pardes" { // the absent child is SILENT: the bytes are dropped, and nothing appears // on the pane's screen to suggest a program answered const before = pardes.Term.grid(p.panes[0].?.terminal).cursor_y; - p.perform(.{ .write = .{ .pane = 0, .bytes = .from("ls\r") } }); + p.perform(.{ .write = .{ .pane = .at(0), .bytes = .from("ls\r") } }); try std.testing.expectEqual(before, pardes.Term.grid(p.panes[0].?.terminal).cursor_y); // the clipboard round-trips through the in-process one @@ -3374,11 +3376,11 @@ test "a host with no methods at all is a complete in-process pardes" { for (p.panes, 0..) |slot, i| if (slot == doc) { doc_id = @intCast(i); }; - p.perform(.{ .save_file = .{ .pane = doc_id } }); + p.perform(.{ .save_file = .{ .pane = .at(doc_id) } }); try std.testing.expectEqualStrings("body\n", p.fallback.files.get(doc.file.?.path).?); // a language backend nobody supplied answers nothing rather than hanging - p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = doc_id, .offset = 0, .arg = .{} } }); + p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = .at(doc_id), .offset = 0, .arg = .{} } }); p.perform(.quit); try std.testing.expect(p.quit); @@ -3775,7 +3777,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "abc" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abc" } }); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const visible = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; @@ -3784,7 +3786,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" try std.testing.expectEqual(rect.x + config.GUTTER + 3, visible.x); try std.testing.expectEqual(body_y, visible.y); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } }); try std.testing.expect((try p.render(frame.allocator())).cursor == null); pane.body.mode = .normal; pane.body.cur_pinned = true; @@ -3800,13 +3802,13 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" pane.body.mode = .tty; try std.testing.expect((try p.render(frame.allocator())).cursor == null); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } }); const alternate = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(rect.x + config.GUTTER + 4, alternate.x); try std.testing.expectEqual(body_y + 1, alternate.y); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } }); try std.testing.expect((try p.render(frame.allocator())).cursor == null); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l\x1b[?25h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l\x1b[?25h" } }); const returned = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(visible.x, returned.x); try std.testing.expectEqual(visible.y, returned.y); @@ -3820,8 +3822,8 @@ test "raw terminal cursor follows its active row only while that row is visible" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .tty; - for (0..60) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "row\r\n" } }); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;4H" } }); + for (0..60) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "row\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3;4H" } }); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const live = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; @@ -3881,7 +3883,7 @@ test "tty output follows only from the bottom" { for (0..60) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); const bottom = pardes.Term.grid(sp.terminal).offset; @@ -3894,7 +3896,7 @@ test "tty output follows only from the bottom" { try std.testing.expect(parked < bottom); for (60..70) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); try std.testing.expectEqual(parked, pardes.Term.grid(sp.terminal).offset); @@ -3906,7 +3908,7 @@ test "tty output follows only from the bottom" { // ...and from there output follows again. const live = pardes.Term.grid(sp.terminal).offset; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = "tail\r\n" } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = "tail\r\n" } }); p.sync(); try std.testing.expect(pardes.Term.grid(sp.terminal).offset > live); } @@ -3976,7 +3978,7 @@ test "a bracketed paste larger than the ring still closes its bracket" { _ = test_api.ptyBytes(p, null, buf); pardes.keys.enterTty(p, 0); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); try std.testing.expect(pardes.Term.modes(p.panes[0].?.terminal).bracketed_paste); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @@ -4007,7 +4009,7 @@ test "a terminal's answer to its program waits behind the paste still queued for // host takes one write off, and the program asks where its cursor is. const taken = p.nextEffect().?; const off = if (taken == .write) taken.write.bytes.len else 0; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[6n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[6n" } }); const got = test_api.ptyBytes(p, null, buf); // The whole paste first, then the answer, `CSI row ; col R`, whole. try std.testing.expectEqualSlices(u8, text[off..], got[0 .. text.len - off]); @@ -4047,7 +4049,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { // Exactly what an OSC 133 shell draws: prompt, then the marker that says // the rest of this row is the user's, then what they typed. One grid row. p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\grep -rn TODO src/", } }); p.sync(); @@ -4091,7 +4093,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { // ...and a prompt with nothing typed at it yet is all chrome, so the whole // row goes, which is what it has always done. p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\r\n\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\", } }); p.sync(); @@ -4109,7 +4111,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\x1b]133;A;cl=line\x1b\\prompt> \x1b]133;B\x1b\\0123456789", } }); p.sync(); diff --git a/core/Effect.zig b/core/Effect.zig index f0e18335..7166294f 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -37,29 +37,29 @@ pub const Effect = union(enum) { /// A child for the pane in slot `pane` -- the one whose serial is /// `serial`: a pane closed and its slot taken before the effect is /// performed is not the one it was for (perform). - spawn: struct { pane: u8, serial: u32, cwd: Buf(effect_path_cap) }, - write: struct { pane: u8, bytes: Buf(effect_write_cap) }, - resize_pty: struct { pane: u8, cols: u16, rows: u16 }, + spawn: struct { pane: Pane.Id, serial: u32, cwd: Buf(effect_path_cap) }, + write: struct { pane: Pane.Id, bytes: Buf(effect_write_cap) }, + resize_pty: struct { pane: Pane.Id, cols: u16, rows: u16 }, /// For the pane whose serial is `serial`, as `spawn` is (perform). - signal_pty: struct { pane: u8, serial: u32, sig: PtySignal }, + signal_pty: struct { pane: Pane.Id, serial: u32, sig: PtySignal }, /// The terminal pane in this slot is gone: the shell hangs up its pty /// and ends the shell, rather than leave it running with nobody to read. - close_pty: struct { pane: u8 }, + close_pty: struct { pane: Pane.Id }, open_link: Buf(256), /// A program a plumbing rule starts (Plumb.run): its directory, then /// its argv, each ended by a NUL. A failure to start it is said at /// pane `pane`. - start: struct { pane: u8, line: Buf(effect_path_cap) }, + start: struct { pane: Pane.Id, line: Buf(effect_path_cap) }, /// write this pane's file content to its path; the shell reads both off /// the core (content is unbounded, effects are fixed-size values) - save_file: struct { pane: u8 }, - save_text: struct { pane: u8, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, + save_file: struct { pane: Pane.Id }, + save_text: struct { pane: Pane.Id, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, write_dump, set_clipboard, read_clipboard, /// `arg` up to 128 bytes, or for `explain` the query it explains, /// ` `. - lsp: struct { id: u32, kind: lsp.Kind, pane: u8, offset: u32, arg: Buf(160) }, + lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) }, /// Snapshot the matching request with pipeRequest(id), then run it away /// from the UI/event loop and answer with pipe_resp. pipe: struct { id: u32 }, @@ -71,19 +71,19 @@ pub const Effect = union(enum) { hand_over: struct { seq: u32 }, /// Write what an Edit's `w` took (`Pipe.writes`), in order. edit_write, - watch: struct { pane: u8, on: bool, mode: WatchMode = .reconcile }, + watch: struct { pane: Pane.Id, on: bool, mode: WatchMode = .reconcile }, theme_file: struct { generation: u32, on: bool }, /// Write the build-time theme ring below the per-user config directory. /// The pane receives the completion/error message from the native host. - dump_themes: struct { pane: u8 }, - detach: struct { pane: u8 }, + dump_themes: struct { pane: Pane.Id }, + detach: struct { pane: Pane.Id }, /// An addon loaded, let go, or let go and loaded again (Addon.zig): /// `arg` its path, or for unload its kind's name. Answered by an /// `addon` event. - addon: struct { op: @import("Addon.zig").Op, pane: u8, arg: Buf(effect_path_cap) }, + addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, arg: Buf(effect_path_cap) }, /// A kind's job for the host's workers (host_io.Job), answered by a /// `job` event. - job: struct { pane: u8, serial: u32, token: u32 }, + job: struct { pane: Pane.Id, serial: u32, token: u32 }, quit, pub fn Buf(comptime n: usize) type { @@ -120,8 +120,8 @@ fn performInner(p: *Pardes, e: Effect) void { switch (e) { // The host reads the pane (its command, its shell) as it forks, // so the slot must still hold the pane the spawn was for. - .spawn => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane] orelse "") else s.cwd.slice()) else { - p.fallback.spawned[s.pane] = true; + .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else { + p.fallback.spawned[s.pane.index()] = true; }, // A pane with no child is silent: nothing invents output on its // screen, and the bytes are dropped rather than transcribed. @@ -129,7 +129,7 @@ fn performInner(p: *Pardes, e: Effect) void { .resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows), // A signal for a pane that closed, its slot retaken in the same // step, would reach another pane's child. - .signal_pty => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), + .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), .close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane), // The view's frontend opens it, yanks and pastes, on its own // machine (View.yanks); the host here only for a view no client @@ -149,17 +149,17 @@ fn performInner(p: *Pardes, e: Effect) void { _ = words.next(); // its directory const prog = words.next() orelse ""; var said: pardes.Kind.Buf(160) = .{}; - p.reportFailure(st.pane, said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); + p.reportFailure(st.pane.index(), said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); }, .save_file => |sf| { - const pane = p.panes[sf.pane] orelse return; + const pane = p.panes[sf.pane.index()] orelse return; const f = if (pane.file) |*file| file else return; const was = f.saved_revision; f.saved_revision = f.revision; // A save the host could not do (saveFailed) is its err // record alone, not a `save`, and changes nothing: a clean // file stays clean. - const saved_pane = writeChecked(p, sf.pane, pane.serial, f.path, f.content, was) orelse return; + const saved_pane = writeChecked(p, sf.pane.index(), pane.serial, f.path, f.content, was) orelse return; const saved = if (saved_pane.file) |*file| file else return; // Edited while it was written: what is on disk is not this. if (saved.saved_revision != saved.revision) return; @@ -174,19 +174,19 @@ fn performInner(p: *Pardes, e: Effect) void { p.emit(.{ .watch = .{ .pane = sf.pane, .on = true } }); }, .save_text => |st| { - const pane = p.panes[st.pane] orelse return; + const pane = p.panes[st.pane.index()] orelse return; if (pane.serial != st.serial) return; // a recycled slot: not ours if (pane.file) |*f| { // Failed, it changes nothing: not the name, not dirty. - const after = writeChecked(p, st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; + const after = writeChecked(p, st.pane.index(), st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; if (after.file == null) return; - if (st.promote) promoteSaved(p, st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); + if (st.promote) promoteSaved(p, st.pane.index(), st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); return; } if (!pane.isTerminal()) return; - const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(.at(st.pane), "Save", err); + const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err); defer p.gpa.free(text); - if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still| + if (writeChecked(p, st.pane.index(), st.serial, st.path.slice(), text, 0)) |still| ctlfs.events.noteLogAs(p, .save, still, st.path.slice()); }, .write_dump => { @@ -249,22 +249,22 @@ fn performInner(p: *Pardes, e: Effect) void { }, .watch => |w| if (v.watch_file) |f| { // What a watch is about: a real file, or a kind's (a PDF's). - const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; + const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; f(p.host.ctx, w.pane, path, w.on, w.mode); } else { - p.fallback.watched[w.pane] = w.on; + p.fallback.watched[w.pane.index()] = w.on; }, .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), .dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane), .detach => |d| if (v.detach) |f| f(p.host.ctx) else - p.reportError(.at(d.pane), "detach", error.NotAttached), + p.reportError(d.pane, "detach", error.NotAttached), // dlopen is the same on every host, so none has a method of its // own; a replica's core holds no library (what it brought comes in // the event this taped). - .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()), - .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token), + .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()), + .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token), // the loop's own condition; a host tears down after its own loop .quit => p.endSession(), } @@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/"); // The in-process filesystem reports the same way a real host does, // so an OOM there leaves the pane dirty rather than looking saved. - if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); + if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; @@ -312,7 +312,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void { ctlfs.events.noteLog(p, .save, pane); p.recent.opened(p.recentGpa(), f.path); if (filesystem.localPath(f.path) != null) - p.emit(.{ .watch = .{ .pane = id, .on = true } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 { @@ -343,7 +343,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not .detach => |d| break d, else => {}, } else return error.NoDetachAsked; - try std.testing.expectEqual(@as(u8, 0), asked.pane); + try std.testing.expectEqual(0, asked.pane.index()); p.perform(.{ .detach = asked }); const pane = p.panes[0].?; @@ -376,7 +376,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file // The write asked for, the pane is the file once it is done. var saved = false; while (p.nextEffect()) |effect| { - if (effect == .save_text and @as(usize, effect.save_text.pane) == id) saved = true; + if (effect == .save_text and effect.save_text.pane.index() == id) saved = true; p.perform(effect); } try std.testing.expect(saved); @@ -392,7 +392,7 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-tty-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello scrollback\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Save")); @@ -474,7 +474,7 @@ test "Save takes the path as an argument, relative to the pane's own directory" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-arg-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "typed and gone\r\n" } }); while (p.nextEffect()) |_| {} var buf: [256]u8 = undefined; @@ -510,9 +510,9 @@ test "Save takes the path as an argument, relative to the pane's own directory" test "a save the host could not do leaves the pane dirty" { const gpa = std.testing.allocator; const Refusing = struct { - fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void { + fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const core: *Pardes = @ptrCast(@alignCast(ctx.?)); - core.saveFailed(.at(pane), "/x/y.txt", error.PermissionDenied); + core.saveFailed(id, "/x/y.txt", error.PermissionDenied); } }; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -577,7 +577,7 @@ test "saves armed in one batch stay with their own panes" { const tty_id = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(tty_id, "/tmp/pardes-batch"); p.setCwd(.at(tty_id), "/tmp/pardes-batch"); - p.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(tty_id), .bytes = "shell text\r\n" } }); const file = try p.setTestFile("file text\n"); const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane; try std.testing.expect(shell.isTerminal()); @@ -606,7 +606,7 @@ test "a save whose pane is gone before the drain writes nothing" { const doomed = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(doomed, "/tmp/pardes-gone"); - p.update(.{ .output = .{ .pane = @intCast(doomed), .bytes = "doomed text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(doomed), .bytes = "doomed text\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(shell.isTerminal()); @@ -687,19 +687,19 @@ test "a Save the host could not do logs no save record" { const Failing = struct { core: *Pardes, const vtable: Host.VTable = .{ .write_file = write }; - fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, _: []const u8) void { const f: *@This() = @ptrCast(@alignCast(ctx.?)); - f.core.saveFailed(.at(pane), path, error.AccessDenied); + f.core.saveFailed(id, path, error.AccessDenied); } }; var host: Failing = .{ .core = p }; p.host = .{ .ctx = &host, .vtable = &Failing.vtable }; _ = th.wr(p, ctlfs.Node.of(p.panes[0].?.serial, .body), "more\n"); - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(!th.logHas(p, "\nsave ")); try std.testing.expect(p.panes[0].?.file.?.saved_revision != p.panes[0].?.file.?.revision); // With the host's write done, it is logged. p.host = .{}; - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(th.logHas(p, "\nsave ")); } diff --git a/core/Event.zig b/core/Event.zig index faea73cc..9988eede 100644 --- a/core/Event.zig +++ b/core/Event.zig @@ -3,6 +3,7 @@ const config = @import("config.zig"); const selection_pipe = @import("selection_pipe.zig"); const Stream = @import("Stream.zig"); +const Pane = @import("panes.zig").Pane; const Layer = @import("Layer.zig"); const RowMetrics = Layer.Metrics; const TagHit = Layer.TagHit; @@ -78,14 +79,14 @@ pub const Event = union(enum) { cell_pixels: CellPixels = .{}, row_metrics: ?RowMetrics = null, }, - output: struct { pane: u8, bytes: []const u8 }, + output: struct { pane: Pane.Id, bytes: []const u8 }, /// The pane's pty reached end of file: its output is over. An /// interactive terminal closes; a command pane waits for `exited`. - eof: struct { pane: u8, status: ?u8 = null }, + eof: struct { pane: Pane.Id, status: ?u8 = null }, /// A command pane's child exited, with this status (null: unknown). It /// is the command's end, whatever still holds its pty (a job it left in /// the background prints on until end of file). - exited: struct { pane: u8, status: ?u8 }, + exited: struct { pane: Pane.Id, status: ?u8 }, lsp_resp: struct { id: u32, rows: ?[]const u8 }, pipe_resp: struct { id: u32, @@ -93,7 +94,7 @@ pub const Event = union(enum) { outputs: []const []const u8, failure: ?selection_pipe.Failure = null, }, - file_changed: struct { pane: u8, bytes: []const u8 }, + file_changed: struct { pane: Pane.Id, bytes: []const u8 }, /// A disk search's batch (Stream.zig), borrowed for the step. search: Stream.Batch, paste: []const u8, @@ -112,10 +113,10 @@ pub const Event = union(enum) { frontend: Frontend, /// What the host's `addon` effect read off a library, or why not /// (Addon.landed). Borrowed for the step. - addon: struct { op: @import("Addon.zig").Op, pane: u8, kind: *const @import("Kind.zig").Loaded }, + addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, kind: *const @import("Kind.zig").Loaded }, /// A kind's job answered (host_io.Job), at its kind's generation then. /// Borrowed for the step. - job: struct { pane: u8, serial: u32, token: u32, gen: u32, bytes: []const u8 }, + job: struct { pane: Pane.Id, serial: u32, token: u32, gen: u32, bytes: []const u8 }, tick, }; diff --git a/core/File.zig b/core/File.zig index 8337b833..c336b1b8 100644 --- a/core/File.zig +++ b/core/File.zig @@ -581,13 +581,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane { pane.body.cur_pinned = true; pane.body.cur_row = @intCast(scroll); p.installPane(id, pane); - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return pane; } pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void { if (file.output == null) for (p.panes, 0..) |slot, id| { - if (slot == pane) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); + if (slot == pane) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); }; // A twin's text, undo and shared index stay with the twins left. var twins: [pardes.MAX_PANES]usize = undefined; @@ -991,7 +991,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane { pane.body.cur_row = src.body.cur_row; pane.body.cur_col = src.body.cur_col; pane.body.cur_pinned = true; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(to), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(to), .on = true } }); return pane; } @@ -1296,7 +1296,7 @@ fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; f.disk_newer = null; f.disk_newer_warned = false; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } pub fn restoreSnap(tab: u16, pane: *Pane, f: *State, snap: Text.Place) void { diff --git a/core/Jump.zig b/core/Jump.zig index 26b3c4d9..66dbd2b6 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -404,11 +404,11 @@ test "jump history terminal rectangle follows output and clears on reflow" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true }); defer p.deinit(); const pane = p.panes[0].?; - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha bravo\r\nsecond line\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha bravo\r\nsecond line\r\n" } }); pane.sel[0] = .{ .state = .done, .c0 = 0, .c1 = 4, .r0 = BOX_H, .r1 = BOX_H }; try edit.capturePointerSelection(p, pane, 0); try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0])); - for (0..40) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "more output\r\n" } }); + for (0..40) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "more output\r\n" } }); try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0])); pane.resizeGrid(pane.cols - 1, pane.rows); try std.testing.expect(pane.pointerSelection(pane.sel[0]) == null); diff --git a/core/Kind.zig b/core/Kind.zig index 05a813f3..7641c2d1 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -278,7 +278,7 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) _ = reopen(p, id, s, bytes); // Its file watched, as a text's is: changed on disk, it opens again // from it (fileChanged); retirePane lets the watch go. - if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return pane; } @@ -995,7 +995,7 @@ const Call = struct { for (o.jobs) |token| if (token != 0) { cl.slot.tokens = token; }; - if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } }); + if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = .at(cl.id), .serial = pane.serial, .token = token } }); for (o.cancels) |token| if (token != 0) { for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) { cl.slot.gpa.free(job.in); diff --git a/core/Plumb.zig b/core/Plumb.zig index 406e7dd8..aeebfc64 100644 --- a/core/Plumb.zig +++ b/core/Plumb.zig @@ -969,7 +969,7 @@ fn run(p: *Pardes, id: usize, wdir: []const u8, argv: []const []const u8) ?[]con start.data[start.len + w.len] = 0; start.len += @intCast(w.len + 1); }; - p.emit(.{ .start = .{ .pane = @intCast(id), .line = start } }); + p.emit(.{ .start = .{ .pane = .at(id), .line = start } }); return null; } diff --git a/core/Query.zig b/core/Query.zig index 784e6af4..dacc11a1 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1756,7 +1756,7 @@ fn promote(p: *Pardes, qid: usize, id: usize) void { f.syntax_dirty = true; pane.attached_to = null; if (f.on_disk) p.recent.opened(p.recentGpa(), f.path); - if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); pardes.ctlfs.events.noteLog(p, .rename, pane); p.panes[qid].?.query.?.preview = 0; } diff --git a/core/builtins.zig b/core/builtins.zig index ca13bd59..6f37e86d 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -447,7 +447,7 @@ pub const Kill = struct { // the marks say is running is the one signalled, not whatever // runs by then. if (command != null) { - c.p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = .term } }); + c.p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = .term } }); stopped = true; } else if (c.p.hostKillJob(id)) stopped = true else jobless = true; } @@ -537,7 +537,7 @@ pub const Detach = struct { pub const scope: Scope = .session; pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { - c.p.emit(.{ .detach = .{ .pane = @intCast(c.id) } }); + c.p.emit(.{ .detach = .{ .pane = .at(c.id) } }); } }; @@ -548,7 +548,7 @@ pub const Adopt = struct { pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { const adopt = c.p.host.vtable.adopt orelse return c.p.reportFailure(c.id, "Adopt: no pardes daemon is keeping shells for this session"); - adopt(c.p.host.ctx, @intCast(c.id)); + adopt(c.p.host.ctx, .at(c.id)); } }; @@ -560,7 +560,7 @@ pub const Upgrade = struct { pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { const upgrade = c.p.host.vtable.upgrade orelse return c.p.reportFailure(c.id, "Upgrade: this pardes cannot move to another build in place"); - upgrade(c.p.host.ctx, @intCast(c.id)); + upgrade(c.p.host.ctx, .at(c.id)); } }; @@ -682,7 +682,7 @@ pub const DumpThemes = struct { c.p.reportError(.at(c.id), "dump themes", error.NoConfigDirectory); return; } - c.p.emit(.{ .dump_themes = .{ .pane = @intCast(c.id) } }); + c.p.emit(.{ .dump_themes = .{ .pane = .at(c.id) } }); } }; @@ -2011,7 +2011,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc const term = p.view().active; try std.testing.expect(p.panes[term].?.isTerminal()); const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = prompt } }); while (p.nextEffect()) |_| {} // The host the core asks: how many it was asked to stop, and whether // their shells run jobs in groups of their own. @@ -2019,7 +2019,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc var asked: usize = 0; var job_control = true; const vtable: pardes.Host.VTable = .{ .kill_job = answer }; - fn answer(_: ?*anyopaque, _: u8) bool { + fn answer(_: ?*anyopaque, _: pardes.Pane.Id) bool { asked += 1; return job_control; } @@ -2037,7 +2037,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc while (p.nextEffect()) |_| {} // Typed but not started yet (no C mark): not running. try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill")); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;C;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;C;aid=pardes\x07" } }); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill ls")); try std.testing.expectEqual(@as(usize, 1), killed.count(p, "Kill ls make")); @@ -2053,7 +2053,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc p.fs.failure_len = 0; killed.job_control = true; // Ended (a D mark): nothing to stop again. - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } }); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill")); } diff --git a/core/dump.zig b/core/dump.zig index 3b5ed421..1616f557 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -651,7 +651,7 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { /// the addon's). fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void { if (pane.addon) |slot| { - if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return reviveSlot(p, id, slot); } if (pane.terminal != null) { @@ -690,7 +690,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool f.content = text; } else |_| {} } - p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); // Its file gone from disk since the dump: its text is nowhere else, so // it is said deleted, and Del, Exit and Restore ask first. One never on // disk (a name not yet saved) comes back as it was. diff --git a/core/echo.zig b/core/echo.zig index 90dcfede..40200696 100644 --- a/core/echo.zig +++ b/core/echo.zig @@ -564,7 +564,7 @@ const Rig = struct { written: std.ArrayListUnmanaged(u8) = .empty, now: u64 = 1_000 * ms, - fn ptyWrite(ctx: ?*anyopaque, _: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, _: pardes.Pane.Id, bytes: []const u8) void { const g: *Rig = @ptrCast(@alignCast(ctx.?)); g.written.appendSlice(testing.allocator, bytes) catch {}; } @@ -601,7 +601,7 @@ const Rig = struct { /// The shell prints `bytes`; the replica gets the unit and the delta. fn prints(g: *Rig, bytes: []const u8) !void { - g.a.output(.{ .output = .{ .pane = g.shell, .bytes = bytes } }); + g.a.output(.{ .output = .{ .pane = .at(g.shell), .bytes = bytes } }); try g.sync(); } diff --git a/core/edit.zig b/core/edit.zig index 214e83a8..0014f681 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -2352,7 +2352,7 @@ test "flat text replacement preserves a terminal fragment origin and direction" if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 }); defer p.deinit(); - p.update(.{ .output = .{ .pane = 0, .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } }); const pane = p.panes[0].?; pane.body.mode = .normal; pane.body.cur_pinned = true; @@ -2487,7 +2487,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont fn f(pp: *Pardes, o: *std.ArrayList(u8)) ![]const u8 { o.clearRetainingCapacity(); while (pp.nextEffect()) |effect| { - if (effect == .write and effect.write.pane == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice()); + if (effect == .write and effect.write.pane.index() == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice()); } return o.items; } @@ -2496,7 +2496,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont try std.testing.expectEqual(.tty, p.panes[0].?.body.mode); p.update(.{ .paste = "echo a\nb\x03\tc" }); try std.testing.expectEqualStrings("echo a\rb \tc", try take(p, &out)); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); _ = try take(p, &out); p.update(.{ .paste = "x\x1b[201~y\n" }); try std.testing.expectEqualStrings("\x1b[200~x [201~y\n\x1b[201~", try take(p, &out)); diff --git a/core/exec.zig b/core/exec.zig index 6a8ef6d8..687faa98 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -322,7 +322,7 @@ pub fn saveFile(p: *Pardes, id: usize) void { } f.disk_newer = null; } - p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); + p.emit(.{ .save_file = .{ .pane = .at(id) } }); } pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { @@ -347,7 +347,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { // Save that fails changes nothing, the name included. if (f.output != null and panes.Output.fileTraits(f.output).saves) { p.emit(.{ .save_text = .{ - .pane = @intCast(id), + .pane = .at(id), .serial = pane.serial, .path = Pardes.SavePath.from(full), .promote = true, @@ -361,7 +361,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { fn askWrite(p: *Pardes, id: usize, serial: u32, path: []const u8) void { p.emit(.{ .save_text = .{ - .pane = @intCast(id), + .pane = .at(id), .serial = serial, .path = Pardes.SavePath.from(path), } }); diff --git a/core/fs.zig b/core/fs.zig index a79aa55c..0a10825d 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -1138,7 +1138,7 @@ test "unmount refuses pane paths inherited directories and queued save targets" try std.testing.expectError(error.MountInUse, unmount(p, "peer")); p.setCwd(.at(slot), "/"); while (p.nextEffect()) |_| {} - p.emit(.{ .save_text = .{ .pane = 0, .serial = pane.serial, .path = .from("/n/peer/pending") } }); + p.emit(.{ .save_text = .{ .pane = .at(0), .serial = pane.serial, .path = .from("/n/peer/pending") } }); try std.testing.expectError(error.MountInUse, unmount(p, "peer")); while (p.nextEffect()) |_| {} try unmount(p, "peer"); @@ -1317,7 +1317,7 @@ test "bounded reads release terminal snapshots after success and size refusal" { const empty = try readLimit(p, path, 0); defer gpa.free(empty); try std.testing.expectEqual(@as(usize, 0), empty.len); - p.update(.{ .output = .{ .pane = 0, .bytes = "limited terminal output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "limited terminal output" } }); const expected = "limited terminal output\n"; // a line ends with its newline const bytes = try readLimit(p, path, expected.len); defer gpa.free(bytes); diff --git a/core/keys.zig b/core/keys.zig index 2f63d045..92e78b0e 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -543,7 +543,7 @@ test "Esc back into a tty leaves its view at the prompt" { // rides the view down and leaves that pin far up in the scrollback. for (0..60) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); const live = pardes.Term.grid(sp.terminal).offset; diff --git a/core/look.zig b/core/look.zig index b2a7b945..f7084079 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1923,7 +1923,7 @@ test "Look hover waits without mutating the pane and input cancels it" { // Background traffic in another pane does not change the text or geometry // under this pointer and must not strand a stationary hover unarmed. - p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } }); + p.update(.{ .output = .{ .pane = .at(other_id), .bytes = "busy\r\n" } }); try std.testing.expect(p.look_hover_preview != null); const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1; @@ -2504,9 +2504,9 @@ test "LookNext in a command pane walks its own file:line places, whoever walked while (p.nextEffect()) |_| {} const dst = exec.execute(p, 0, "make") orelse return error.NoCommandPane; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } }); - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } }); - p.update(.{ .eof = .{ .pane = @intCast(dst) } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); + p.update(.{ .eof = .{ .pane = .at(dst) } }); const cmd = p.panes[dst].?; // A walk last made elsewhere, and another pane with places in it. try std.testing.expect(p.executeBuiltinLine(0, "New")); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index df6a058a..376b093d 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -113,7 +113,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) p.emit(.{ .lsp = .{ .id = p.lsp_ask.seq, .kind = kind, - .pane = @intCast(id), + .pane = .at(id), .offset = @intCast(at), .arg = .from(sent), } }); @@ -445,7 +445,7 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place, try std.testing.expectEqual(lsp.Kind.explain, e.lsp.kind); try std.testing.expectEqualStrings("hover ", e.lsp.arg.slice()); try std.testing.expectEqual(hover_at, e.lsp.offset); - try std.testing.expectEqual(@as(u8, 0), e.lsp.pane); + try std.testing.expectEqual(0, e.lsp.pane.index()); seen = true; }; try std.testing.expect(seen); diff --git a/core/mouse.zig b/core/mouse.zig index 0ff4c7e3..1ef348f8 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -1580,17 +1580,17 @@ test "a wheel over a program that owns it is the program's, in the form it asked .{ .modes = "\x1b[?1007l", .button = .wheel_up, .sent = "" }, }; for (cases) |case| { - p.update(.{ .output = .{ .pane = 0, .bytes = case.modes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } }); _ = pardes.test_api.ptyBytes(p, 0, &out); p.update(.{ .mouse = .{ .button = case.button, .kind = .press, .col = col, .row = row, .ctrl = case.ctrl, .alt = case.alt, .shift = case.shift } }); try std.testing.expectEqualStrings(case.sent, pardes.test_api.ptyBytes(p, 0, &out)); } // A shell on the main screen: the wheel scrolls its scrollback, and // the shell hears nothing. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1l\x1b[?1049l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1l\x1b[?1049l" } }); for (0..40) |i| { var line: [16]u8 = undefined; - p.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); } _ = try p.render(frame.allocator()); _ = pardes.test_api.ptyBytes(p, 0, &out); @@ -1600,7 +1600,7 @@ test "a wheel over a program that owns it is the program's, in the form it asked try std.testing.expect(pane.scroll() != was); // A program tracking the mouse on the main screen: Shift and the // wheel scroll the scrollback, the program hears nothing. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1000h\x1b[?1006h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1000h\x1b[?1006h" } }); _ = pardes.test_api.ptyBytes(p, 0, &out); const tracked = pane.scroll(); p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = col, .row = row, .shift = true } }); @@ -1671,7 +1671,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri } }.f; // htop's modes: clicks in SGR, a release its own `m`. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } }); _ = pardes.test_api.ptyBytes(p, 0, &out); try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press })); try std.testing.expect(p.view().drag == .none); @@ -1713,7 +1713,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri // codex's any-event tracking: a drag once per cell, carried past the // grid's edge and clamped there, and bare moves. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003h" } }); _ = pardes.test_api.ptyBytes(p, 0, &out); try std.testing.expectEqualStrings("\x1b[<35;9;4M", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 })); try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 })); @@ -1737,7 +1737,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri // Legacy X10 bytes: a release is button 3. (Turning 1003 off turns // tracking off, as xterm's one tracking mode goes.) - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } }); _ = pardes.test_api.ptyBytes(p, 0, &out); try std.testing.expectEqualStrings("\x1b[M &$", try send(p, &out, col, row, .{ .button = .left, .kind = .press })); try std.testing.expectEqualStrings("\x1b[M#&$", try send(p, &out, col, row, .{ .button = .left, .kind = .release })); diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index cf68fa76..302b916a 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -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").?); } @@ -1990,7 +1990,7 @@ test "a terminal told the directory it already goes by logs no rename" { const session = p.sessionDir(); 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(.at(term), "/usr"); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial}))); @@ -2001,13 +2001,13 @@ test "a terminal with text typed at its prompt is never typed into: a look at it defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; p.setCwd(.at(term), "/tmp"); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); + 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); @@ -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})); @@ -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); } @@ -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:
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; diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 76765535..8be26602 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -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); diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 96f2a6bf..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; @@ -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()) |_| {} } }; @@ -801,7 +801,7 @@ test "run answers how its command ended once the shell is back at a prompt" { // A respawn before that prompt keeps it waiting for the new shell's. 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; 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; } diff --git a/core/panes.zig b/core/panes.zig index 7ea479b9..b928917a 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1192,8 +1192,8 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void { if (pane.file) |*file| panes.File.leaveTwins(p, file); const watched = (if (pane.file) |f| f.output == null else false) or (if (pane.addon) |k| k.path.len > 0 else false); for (p.panes, 0..) |slot, id| if (slot == pane) { - if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); - if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = @intCast(id) } }); + if (watched) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); + if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = .at(id) } }); // Its pty's end and its emulator are the authority's: a replica's // speculation that closes a terminal waits for it. if (pane.terminal != null) tape.poison("close a terminal"); @@ -1294,7 +1294,7 @@ pub fn emitSpawn(p: *Pardes, id: usize, serial: u32, cwd: []const u8) void { if (p.spawn_dirs[id]) |old| p.gpa.free(old); p.spawn_dirs[id] = null; if (cwd.len > effect_path_cap) p.spawn_dirs[id] = p.gpa.dupe(u8, cwd) catch null; - p.emit(.{ .spawn = .{ .pane = @intCast(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } }); + p.emit(.{ .spawn = .{ .pane = .at(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } }); } /// A command pane: a terminal whose child is `$SHELL -c line` rather @@ -1713,7 +1713,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" { p.sync(); while (p.nextEffect()) |_| {} allocator.fail_index = allocator.alloc_index; - p.update(.{ .eof = .{ .pane = 0 } }); + p.update(.{ .eof = .{ .pane = .at(0) } }); try std.testing.expectEqual(parent, p.panes[0].?); try std.testing.expectEqual(parent, child.cwd.inherited); try std.testing.expectEqual(Text.Mode.normal, parent.body.mode); diff --git a/core/replica.zig b/core/replica.zig index 625153d1..3f04b3bc 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2278,7 +2278,7 @@ pub const Peers = struct { if (ps.next_id == 0) ps.next_id = 1; // The session's digest as dumped, for the joiner to check its load by. const digest = tape.digestOf(core); - peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; + peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null; if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null; if (ps.threads and (peer.writer == null or peer.reader == null)) { @@ -2591,7 +2591,7 @@ fn joinOn(gpa: Allocator, fd: c_int, session: []const u8, why: []u8, have: ?*Hav .welcome => |w| { r.j.pid = w.pid; r.j.client = w.client; - r.j.view = w.view; + r.j.view = w.view.index(); r.j.gmtoff = w.gmtoff; r.j.digest = w.digest; r.j.semantics = w.semantics; @@ -3292,7 +3292,7 @@ const TestHost = struct { /// A host with ptys whose pump polls for a frame, as a client's does. const PtyHost = struct { - fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {} + fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {} fn poll(_: ?*anyopaque) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll }; fn host() pardes.Host { @@ -3729,7 +3729,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st for (0..3) |round| { // The shell prints: its unit rolls the replica back and applies the // key again; then its delta lands, under the new copy. - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); r.confirm((try a.pending()).?); r.settle(); try std.testing.expect(r.copy.held); @@ -3751,7 +3751,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st r.confirm(try a.local(.{ .focus = false })); _ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); try key(r, 'x', &sent); - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -3875,7 +3875,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, // History the replica holds as holes, of lines a narrow grid wraps in // two, which a wider one unwraps. var line: [96]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); r.confirm((try a.pending()).?); // Out of terminal mode in the session's view, which sizes it; then a // client's own view (a copy of it), wider: its first key sizes the @@ -3954,7 +3954,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [64]u8 = undefined; - for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); + for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); r.settle(); @@ -3977,7 +3977,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves // The shell prints while they wait: its unit, then its delta, which // sets the view the authority's (at the bottom still): what was applied // goes on top of it again. - for (0..5) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); + for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4043,7 +4043,7 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [96]u8 = undefined; - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); // Out of the shell's tty mode, in the session's view: keys over its text. @@ -4061,8 +4061,8 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca r.settle(); } // The program redraws the screen: other rows where those keys read. - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[H\x1b[2J" } }); - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4174,7 +4174,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &zon } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &zon } }); const r = try joinedNow(a, 1, 0); defer r.deinit(); try std.testing.expectEqual(digestOf(a), r.digest()); @@ -4703,7 +4703,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli } else return error.NoShell; a.core.view().active = shell; var line: [64]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); const out = try gpa.dupe(u8, (try a.pending()).?); defer gpa.free(out); for ([_]*Replica{ r1, r2 }) |r| r.confirm(out); @@ -4733,7 +4733,7 @@ test "a replica with no code for a kind whose state is not plain shows its pane // replica's core takes the kind's words, never its code. var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } })); r.confirm(try a.local(.{ .command = "Counter" })); try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null); try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client")); @@ -4791,7 +4791,7 @@ test "a kind's place moved in a step of another view's: a replica's key that rea defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // The replica's view opens the kind's pane, and an Esc goes back to // the file (Last): view 0 has the file. const own = try a.openView(1); @@ -4845,7 +4845,7 @@ test "a client joined from a dump numbers a kind's next job as the session does" defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &jobber } }); _ = try a.local(.{ .command = "Jobber" }); for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } }); const id = a.core.view().active; @@ -4864,7 +4864,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // Its replica has no code for the kind: the open's outcome (its place, // `1:0 0`) is the authority's to say. const msg = try gpa.dupe(u8, try r.input(.{ .command = "Placed" })); @@ -4883,7 +4883,7 @@ test "a client joined from a dump tells a kind each view's facts as the session defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }); _ = try a.local(.{ .command = "Placed" }); // A message in its pane: a band over its body, in each view. _ = try a.local(.{ .command = "Placed x" }); @@ -4937,7 +4937,8 @@ const Asker = struct { const BusyHost = struct { var core: ?*Pardes = null; var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity }; - fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(_: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never); } fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void { @@ -4955,7 +4956,7 @@ test "a kind's job answered at once inside its host's call (no worker free) is t defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &asker } })); // The client has its code (as a library of its own found by its scan). r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops; r.confirm(try a.local(.{ .command = "Asker" })); @@ -4981,7 +4982,7 @@ test "a closed terminal with a kitty image brought back on a client: its image d } else return error.NoShell; // A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA // of its own (TerminalImages.converted). - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); r.confirm((try a.pending()).?); // Closed and brought back: the client loads the session's dump of it, // its image with it. @@ -5034,7 +5035,7 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } }); _ = try a.local(.{ .command = "Counter" }); // Joined from the dump: the kind's pane is a line here (no code), its // slot the dump's. @@ -5101,7 +5102,7 @@ const SeenHost = struct { of(ctx).linked += 1; } fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {} - fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {} + fn watchFile(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: bool, _: pardes.WatchMode) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile }; fn host(h: *SeenHost) pardes.Host { return .{ .ctx = h, .vtable = &vtable }; @@ -5256,7 +5257,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd))); var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); // The kind's pane, its +Search (a place a row, as a kind's `/` leaves // it), and a scratch whose words name files in the session's directory // (as a command's output would). @@ -5563,14 +5564,14 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' if (slot) |pane| if (pane.isTerminal()) break id; } else null; if (shell) |id| { - a.output(.{ .output = .{ .pane = @intCast(id), .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(id), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; } _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/mise.toml", .{dir}) }); const file = a.core.view().active; var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); _ = try a.local(.{ .command = "Still" }); const kind = a.core.view().active; try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null); @@ -5670,7 +5671,7 @@ test "a far client's click into a shell whose program asked for focus events is const Told = struct { var bytes: [64]u8 = undefined; var len: usize = 0; - fn write(_: ?*anyopaque, _: u8, b: []const u8) void { + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { @memcpy(bytes[len..][0..b.len], b); len += b.len; } @@ -5682,7 +5683,7 @@ test "a far client's click into a shell whose program asked for focus events is const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); } else return error.NoShell; - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; _ = try a.local(.{ .command = "New" }); var screens: Screens = .init(gpa); diff --git a/core/root.zig b/core/root.zig index 706c833d..681be15d 100644 --- a/core/root.zig +++ b/core/root.zig @@ -221,7 +221,7 @@ pub const test_api = if (@import("builtin").is_test) struct { var n: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - if (pane != null and w.pane != pane.?) continue; + if (pane != null and w.pane.index() != pane.?) continue; const b = w.bytes.slice(); if (n + b.len > buf.len) break; @memcpy(buf[n..][0..b.len], b); diff --git a/core/views.zig b/core/views.zig index a8bf8e60..9985288d 100644 --- a/core/views.zig +++ b/core/views.zig @@ -859,7 +859,7 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" { defer out.deinit(gpa); for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i}); try out.appendSlice(gpa, "LAST$ "); - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = out.items } }); // Sized for the tall view, it fits there whole: nothing is passed over. try testing.expectEqual(@as(u16, 0), term.pan); p.toView(.at(0)); diff --git a/dev/Host.zig b/dev/Host.zig index 1834e52e..24df3895 100644 --- a/dev/Host.zig +++ b/dev/Host.zig @@ -24,30 +24,30 @@ pub const VTable = struct { /// for the daemon to attach again (daemon.zig). detach: ?*const fn (ctx: ?*anyopaque) void = null, /// Adopt: the shells a dead session left, asked of the daemon. - adopt: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null, + adopt: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, /// Upgrade: this process exec'd as the pardes installed since, at /// the step's end (upgrade.zig); `pane` hears why if it cannot be. - upgrade: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null, + upgrade: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, /// Whether a newer pardes is installed at the path this process /// started from, to be said once (upgrade.zig): asked at a focus-in. newer_build: ?*const fn (ctx: ?*anyopaque) bool = null, - spawn: ?*const fn (ctx: ?*anyopaque, pane: u8, cwd: []const u8) void = null, - pty_write: ?*const fn (ctx: ?*anyopaque, pane: u8, bytes: []const u8) void = null, - pty_resize: ?*const fn (ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void = null, - pty_signal: ?*const fn (ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void = null, - close_pty: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null, - tty_taken: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null, + spawn: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cwd: []const u8) void = null, + pty_write: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, bytes: []const u8) void = null, + pty_resize: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cols: u16, rows: u16) void = null, + pty_signal: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, sig: pardes.PtySignal) void = null, + close_pty: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, + tty_taken: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null, /// The name of the program holding the tty, when it is not the /// shell (host_io.foregroundName), in `buf`. - fg_name: ?*const fn (ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 = null, + fg_name: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, buf: []u8) ?[]const u8 = null, /// Answered at once, not queued as an effect: Kill asks while the /// job it saw running is still the one in the tty (host_io.killJob). - kill_job: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null, - write_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void = null, + kill_job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null, + write_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, bytes: []const u8) void = null, write_dump: ?*const fn (ctx: ?*anyopaque, bytes: []const u8) void = null, - watch_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: pardes.WatchMode) void = null, + watch_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, on: bool, mode: pardes.WatchMode) void = null, watch_theme: ?*const fn (ctx: ?*anyopaque, generation: u32, on: bool) void = null, - dump_themes: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null, + dump_themes: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, set_clipboard: ?*const fn (ctx: ?*anyopaque, text: []const u8) void = null, read_clipboard: ?*const fn (ctx: ?*anyopaque) void = null, open_link: ?*const fn (ctx: ?*anyopaque, url: []const u8) void = null, @@ -65,5 +65,5 @@ pub const VTable = struct { /// Run job `token` of the pane in slot `pane` (whose serial is /// `serial`) on a worker (`KindJob`), answering with the `job` event; /// absent, it runs on the loop. - job: ?*const fn (ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void = null, + job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void = null, }; diff --git a/dev/Inbox.zig b/dev/Inbox.zig index d8b14221..ed3a9835 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -8,8 +8,8 @@ const Lsp = host_io.Lsp; const Inbox = @This(); pub const Msg = union(enum) { - output: struct { pane: u8, gen: u32, bytes: []u8 }, - eof: struct { pane: u8, gen: u32, failure: ?anyerror = null }, + output: struct { pane: pardes.Pane.Id, gen: u32, bytes: []u8 }, + eof: struct { pane: pardes.Pane.Id, gen: u32, failure: ?anyerror = null }, lsp: struct { id: u32, rows: ?[]u8 }, lsp_status: []u8, pipe: selection_pipe.Response, @@ -96,18 +96,18 @@ pub fn wake(q: *Inbox) void { if (q.wake_fn) |f| f(q.wake_ctx); } -pub fn acceptReader(q: *Inbox, pane: u8, gen: u32) void { +pub fn acceptReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void { q.lock(); defer q.unlock(); - std.debug.assert(q.readers[pane] == null); - q.readers[pane] = gen; + std.debug.assert(q.readers[pane.index()] == null); + q.readers[pane.index()] = gen; } -pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void { +pub fn cancelReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void { q.lock(); defer q.unlock(); - if (q.readers[pane] != gen) return; - q.readers[pane] = null; + if (q.readers[pane.index()] != gen) return; + q.readers[pane.index()] = null; var i: usize = 0; while (i < q.len) { const msg = q.items[(q.head + i) % q.items.len]; @@ -121,14 +121,14 @@ pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void { q.space.broadcast(q.io); } -pub fn pushOutput(q: *Inbox, pane: u8, gen: u32, bytes: []u8) bool { +pub fn pushOutput(q: *Inbox, pane: pardes.Pane.Id, gen: u32, bytes: []u8) bool { q.lock(); - while (!q.closed and q.readers[pane] == gen and q.len >= output_capacity) { + while (!q.closed and q.readers[pane.index()] == gen and q.len >= output_capacity) { q.waiting += 1; q.space.waitUncancelable(q.io, &q.mutex); q.waiting -= 1; } - if (q.closed or q.readers[pane] != gen) { + if (q.closed or q.readers[pane.index()] != gen) { q.unlock(); q.gpa.free(bytes); return false; @@ -186,7 +186,7 @@ pub fn push(q: *Inbox, m: Msg) void { }, else => { if (m == .eof) { - if (q.readers[m.eof.pane] != m.eof.gen) { + if (q.readers[m.eof.pane.index()] != m.eof.gen) { q.unlock(); return; } @@ -270,13 +270,13 @@ pub fn deinit(q: *Inbox) void { /// A pane's reader: its pty's output pushed as it comes, then its end /// of file; canceled (closePty), it pushes nothing more. -pub fn startReader(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) !std.Io.Future(void) { +pub fn startReader(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) !std.Io.Future(void) { q.acceptReader(pane, gen); errdefer q.cancelReader(pane, gen); return q.io.concurrent(readPty, .{ q, pty, pane, gen }); } -fn readPty(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) void { +fn readPty(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) void { var buf: [0x10000]u8 = undefined; var failure: ?anyerror = null; while (true) { diff --git a/dev/KindJob.zig b/dev/KindJob.zig index c24ad88d..e9cea5b4 100644 --- a/dev/KindJob.zig +++ b/dev/KindJob.zig @@ -48,7 +48,7 @@ pub fn run(j: *KindJob) void { /// Its answer to the core, and it gone. pub fn land(j: *KindJob, p: *pardes.Pardes) void { if (j.draw != null) return pardes.Kind.landDraw(p, j); - p.update(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); + p.update(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); j.drop(); } diff --git a/dev/Lsp.zig b/dev/Lsp.zig index d7f11bfe..4b8bfa03 100644 --- a/dev/Lsp.zig +++ b/dev/Lsp.zig @@ -5,7 +5,7 @@ const filesystem = @import("core").filesystem; pub const Request = struct { id: u32, kind: pardes.lsp.Kind, - pane: u8, + pane: pardes.Pane.Id, offset: u32, arg: []const u8, }; @@ -45,8 +45,8 @@ pub const Job = struct { // Copy before starting a worker; the editor may replace any source slice afterward. pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request) !*Job { - if (req.pane >= core.panes.len) return error.NoPane; - const pane = core.panes[req.pane] orelse return error.NoPane; + if (req.pane.index() >= core.panes.len) return error.NoPane; + const pane = core.panes[req.pane.index()] orelse return error.NoPane; const file = pane.file; const job = try gpa.create(Job); errdefer gpa.destroy(job); @@ -87,7 +87,7 @@ pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request var copied: usize = 0; for (core.panes, 0..) |slot, i| { const other = slot orelse continue; - if (i == req.pane) continue; + if (i == req.pane.index()) continue; const f = other.file orelse continue; if (f.output != null) continue; if (copied + f.content.len > pardes.memory.limits.lsp_snapshot_bytes) continue; @@ -118,12 +118,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T } const job = snapshot(gpa, core, req) catch |err| { core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return core.reportError(.at(req.pane), "lsp", err); + return core.reportError(req.pane, "lsp", err); }; const future = io.concurrent(work, .{ io, gpa, job, ctx, deliver }) catch |err| { job.free(gpa); core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return core.reportError(.at(req.pane), "lsp", err); + return core.reportError(req.pane, "lsp", err); }; task.* = .{ .id = req.id, .future = future }; } @@ -173,7 +173,7 @@ test "a snapshot owns every byte the backend will read" { const job = try snapshot(gpa, core, .{ .id = 7, .kind = .status, - .pane = @intCast(core.view().active), + .pane = .at(core.view().active), .offset = 0, .arg = &needle, }); @@ -202,7 +202,7 @@ test "LSP snapshot frees every partially copied field on allocation failure" { const job = try snapshot(gpa, p, .{ .id = 7, .kind = .hover, - .pane = @intCast(p.view().active), + .pane = .at(p.view().active), .offset = 6, .arg = "query", }); @@ -226,7 +226,7 @@ test "LSP snapshots translate explicit OS paths once and retain virtual names" { const replacement = try gpa.dupe(u8, case.path); gpa.free(pane.file.?.path); pane.file.?.path = replacement; - const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.view().active), .offset = 0, .arg = "" }); + const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = .at(core.view().active), .offset = 0, .arg = "" }); defer job.free(gpa); try std.testing.expectEqualStrings(case.native, job.path); try std.testing.expectEqualStrings(std.Io.Dir.path.dirname(case.native).?, job.root); @@ -247,7 +247,7 @@ test "a pane that is gone yields no job rather than a null deref" { try std.testing.expectError(error.NoPane, snapshot(gpa, core, .{ .id = 1, .kind = .definition, - .pane = empty, + .pane = .at(empty), .offset = 0, .arg = "", })); @@ -272,7 +272,7 @@ test "work consumes the job and hands its rows to the sink" { const job = try snapshot(gpa, core, .{ .id = 42, .kind = .status, - .pane = @intCast(core.view().active), + .pane = .at(core.view().active), .offset = 0, .arg = "", }); @@ -320,7 +320,7 @@ test "LSP edit query failure leaves text and undo untouched before a successful const job = try snapshot(failing.allocator(), core, .{ .id = core.lsp_ask.wait.?.id, .kind = kind, - .pane = @intCast(core.view().active), + .pane = .at(core.view().active), .offset = 6, .arg = "renamed", }); @@ -389,7 +389,7 @@ test "LSP work delivers failure when transferring result ownership cannot alloca } }; const core = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer core.deinit(); - const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" }); + const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" }); var sink: Sink = .{}; work(std.testing.io, gpa, job, &sink, Sink.take); if (sink.rows) |rows| gpa.free(rows); diff --git a/dev/file_watch.zig b/dev/file_watch.zig index a02ad272..84f37c81 100644 --- a/dev/file_watch.zig +++ b/dev/file_watch.zig @@ -706,7 +706,7 @@ test "a restored file is watched again: one clean takes what its file became sin defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 }); var armed = false; while (core.nextEffect()) |effect| switch (effect) { - .watch => |watch| if (watch.pane == id and watch.on) { + .watch => |watch| if (watch.pane.index() == id and watch.on) { _ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode); armed = true; }, @@ -774,7 +774,7 @@ test "ordinary file watches still reconcile changes between open and watch" { defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 }); var armed = false; while (core.nextEffect()) |effect| switch (effect) { - .watch => |watch| if (watch.pane == id and watch.on) { + .watch => |watch| if (watch.pane.index() == id and watch.on) { try std.testing.expectEqual(.reconcile, watch.mode); try std.testing.expect(!applyEffect(core, io, fd, &watches, id, watch.on, watch.mode)); armed = true; @@ -949,7 +949,7 @@ test "a watched file deleted wakes the watch at once, and its pane says so" { var watches: Table = @splat(null); defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 }); while (core.nextEffect()) |effect| switch (effect) { - .watch => |watch| if (watch.pane == id and watch.on) { + .watch => |watch| if (watch.pane.index() == id and watch.on) { _ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode); }, else => {}, diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 3d050bbf..c147c2e2 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1130,7 +1130,7 @@ const Own = struct { pub fn start(o: *Own, l: *Session) !void { for (&o.ptys, 0..) |*slot, id| if (slot.*) |*pt| { - pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), o.gens[id]); + pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), o.gens[id]); }; if (o.inotify_fd >= 0) { o.watch_stop = try stopPipe(); @@ -2485,7 +2485,8 @@ const Shell = struct { took_input: bool = false, held: ?c.SDL_Event = null, - fn closePaneShell(ctx: ?*anyopaque, pane: u8) void { + fn closePaneShell(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); shellOf(ctx).closePty(pane); } @@ -2493,7 +2494,7 @@ const Shell = struct { const pt = if (s.ptys[pane]) |*pt| pt else return; // Out of the queue first, which lets go a reader waiting for room // in it; then its read is canceled (or, at its end, it is joined). - s.queue.cancelReader(pane, s.gens[pane]); + s.queue.cancelReader(.at(pane), s.gens[pane]); if (pt.reader) |*reader| { reader.cancel(s.queue.io); // the Io it was started on (startReader) pt.reader = null; @@ -2603,12 +2604,14 @@ const Shell = struct { return shellOf(ctx).gui != null; } - fn adopt(ctx: ?*anyopaque, pane: u8) void { + fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = shellOf(ctx); s.adoptions.ask(s.core, pane); } - fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void { + fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = shellOf(ctx); if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place"); s.upgrade_asked = pane; @@ -2656,7 +2659,7 @@ const Shell = struct { const failed = upgrade.dumpInto(core, &rec, &at_buf, &why) orelse upgrade.execAs(s.gpa, path, &rec, &at_buf, s.fs, &why); // As it was: its ptys read on. for (s.ptys, 0..) |*slot, id| if (slot.*) |*pt| if (pt.fd >= 0 and pt.reader == null) { - pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), s.gens[id]) catch null; + pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), s.gens[id]) catch null; }; core.reportFailure(pane, failed); } @@ -2751,18 +2754,18 @@ const Shell = struct { var check_files = false; for (msgs.slice()) |m| switch (m) { .output => |o| { - if (s.gens[o.pane] == o.gen) + if (s.gens[o.pane.index()] == o.gen) s.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } }); s.gpa.free(o.bytes); }, .eof => |e| { - if (s.gens[e.pane] == e.gen) eof: { + if (s.gens[e.pane.index()] == e.gen) eof: { if (e.failure) |err| { - s.closePty(e.pane); - s.core.readerFailed(.at(e.pane), err); + s.closePty(e.pane.index()); + s.core.readerFailed(e.pane, err); break :eof; } - const pt = if (s.ptys[e.pane]) |*pt| pt else { + const pt = if (s.ptys[e.pane.index()]) |*pt| pt else { s.core.update(.{ .eof = .{ .pane = e.pane } }); break :eof; }; @@ -2770,15 +2773,15 @@ const Shell = struct { // closing it would hang up one that runs on without it. // Its exit, if it came first, is told now its output is in. if (pt.cmd.watched) { - host_io.commandEof(s.core, s.ptys, e.pane, s, closeWatched); + host_io.commandEof(s.core, s.ptys, e.pane.index(), s, closeWatched); break :eof; } // Unwatched, a command's exit is read here, as its end, // and a shell's, for a run waiting on it and the log. - const unwatched = if (s.core.panes[e.pane]) |pane| pane.command != null else false; + const unwatched = if (s.core.panes[e.pane.index()]) |pane| pane.command != null else false; const status = host_io.exitStatus(pt.pid, 100); if (status != null) pt.pid = 0; // reaped: no shell to retire - s.closePty(e.pane); + s.closePty(e.pane.index()); if (unwatched or status != null) s.core.update(.{ .exited = .{ .pane = e.pane, .status = status } }); s.core.update(.{ .eof = .{ .pane = e.pane } }); } @@ -3327,32 +3330,33 @@ fn guiNow(ctx: ?*anyopaque) u64 { return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } -fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { +fn spawnPane(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void { + const pane = id.index(); const s = shellOf(ctx); - if (s.adoptions.take(pane)) |a| return takeShell(s, pane, a); + if (s.adoptions.take(id)) |a| return takeShell(s, pane, a); // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| { - if (running) return s.core.restartFailed(.at(pane), err); - return s.core.shellFailed(.at(pane), err); + if (running) return s.core.restartFailed(id, err); + return s.core.shellFailed(id, err); }; s.closePty(pane); if (s.ptys[pane] != null) { _ = libc.close(child.file.handle); host_io.retireShell(child.pid); - return s.core.reportError(.at(pane), "shell", error.WorkersBusy); + return s.core.reportError(id, "shell", error.WorkersBusy); } s.gens[pane] +%= 1; const command = s.core.panes[pane].?.command != null; const pt: Pty = .{ .fd = child.file.handle, .pid = child.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } }; s.ptys[pane] = pt; var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined; - if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); + if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(id, wd); if (!s.threads_ok) return; - s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| { + s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, id, s.gens[pane]) catch |err| { s.closePty(pane); - return s.core.reportError(.at(pane), "terminal reader", err); + return s.core.reportError(id, "terminal reader", err); }; } @@ -3368,9 +3372,9 @@ fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void { if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 }; _ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny)); - if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1)); + if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1)); if (!s.threads_ok) return; - s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| { + s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, .at(pane), s.gens[pane]) catch |err| { s.closePty(pane); return s.core.reportError(.at(pane), "terminal reader", err); }; @@ -3397,12 +3401,14 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { } } -fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { +fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { + const pane = id.index(); const s = shellOf(ctx); if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.fd, bytes); } -fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void { +fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void { + const pane = id.index(); const s = shellOf(ctx); if (s.ptys[pane]) |pt| { const ws = host_io.ptyWinsize(s.core, cols, rows); @@ -3410,31 +3416,36 @@ fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void { } } -fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void { +fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void { + const pane = id.index(); const s = shellOf(ctx); // A command whose exit is recorded is reaped: its group may be another's. if (s.ptys[pane]) |pt| if (!pt.cmd.exited) host_io.signalTty(pt.pid, pt.fd, sig, pt.cmd.watched); } -fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool { +fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const s = shellOf(ctx); const pt = s.ptys[pane] orelse return false; return host_io.ttyTaken(pt.pid, pt.fd); } -fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 { +fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 { + const pane = id.index(); const s = shellOf(ctx); const pt = s.ptys[pane] orelse return null; return host_io.foregroundName(pt.pid, pt.fd, buf); } -fn killJob(ctx: ?*anyopaque, pane: u8) bool { +fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const s = shellOf(ctx); const pt = s.ptys[pane] orelse return false; return host_io.killJob(pt.pid, pt.fd); } -fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void { +fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { + const pane = id.index(); const s = shellOf(ctx); host_io.writeFile(s.core, s.watches, pane, path, bytes); } @@ -3443,7 +3454,8 @@ fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { host_io.writeDump(shellOf(ctx).core, bytes); } -fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void { +fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void { + const pane = id.index(); const s = shellOf(ctx); if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, s.watches, pane, on, mode)) s.queue.push(.files_changed); @@ -3461,7 +3473,8 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void { )) s.queue.push(.files_changed); } -fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { +fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = shellOf(ctx); host_io.dumpThemes(s.core, s.io, s.gpa, pane); } @@ -3501,7 +3514,7 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { const s = shellOf(ctx); if (s.threads_ok) return s.queue.startLsp(s.core, req); s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable); + s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } fn pipe(ctx: ?*anyopaque, id: u32) void { @@ -3517,7 +3530,8 @@ fn kindDraw(ctx: ?*anyopaque, j: *host_io.KindJob) bool { return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s.queue, Queue.pushJob); } -fn kindJob(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void { +fn kindJob(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); const s = shellOf(ctx); if (s.threads_ok) return host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s.queue, Queue.pushJob); host_io.KindJob.runHere(s.core, pane, serial, token); @@ -6280,7 +6294,7 @@ test "GUI PTY reader delivers a real shell tail before EOF and joins on close" { const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80); ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial }; - ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1); + ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1); try std.testing.expect(host_io.writeFd(child.file.handle, "printf '\\120\\101\\122\\104\\105\\123\\055\\124\\101\\111\\114'; exit\n")); var bytes: std.ArrayList(u8) = .empty; defer bytes.deinit(gpa); @@ -6317,8 +6331,8 @@ test "GUI PTY Restore joins a real reader waiting for queue space" { try dump.dumpState(core); var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - queue.acceptReader(1, 1); - for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 1, .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } }); + queue.acceptReader(.at(1), 1); + for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(1), .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } }); var ptys: [pardes.MAX_PANES]?Pty = @splat(null); var gens: [pardes.MAX_PANES]u32 = @splat(1); var shell: Shell = undefined; @@ -6331,7 +6345,7 @@ test "GUI PTY Restore joins a real reader waiting for queue space" { const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80); ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial }; - ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1); + ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1); try std.testing.expect(host_io.writeFd(child.file.handle, "printf 'after-full'; exit\n")); try host_io.PtyTests.waitBlocked(&queue); const old_serial = core.panes[0].?.serial; @@ -6345,10 +6359,10 @@ test "GUI PTY Restore joins a real reader waiting for queue space" { try std.testing.expectEqual(@as(usize, 0), queue.waiting); try std.testing.expect(queue.readers[0] == null); try std.testing.expectEqual(@as(c_int, -1), libc.fcntl(child.file.handle, libc.F.GETFD)); - queue.cancelReader(1, 1); - queue.acceptReader(0, gens[0]); - queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } }); - try std.testing.expect(queue.pushOutput(0, gens[0], try gpa.dupe(u8, "fresh"))); + queue.cancelReader(.at(1), 1); + queue.acceptReader(.at(0), gens[0]); + queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } }); + try std.testing.expect(queue.pushOutput(.at(0), gens[0], try gpa.dupe(u8, "fresh"))); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); try std.testing.expectEqual(@as(usize, 1), batch.len); @@ -6373,7 +6387,7 @@ test "GUI PTY deletion joins an idle reader and its shell is reaped by exit" { const rcs: host_io.Shell.PromptFiles = .{}; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80); ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial }; - ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1); + ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1); try core.removePane(0, null); shell.reconcilePtys(); try std.testing.expect(queue.readers[0] == null); @@ -6414,9 +6428,9 @@ test "GUI completion failure survives backlog and leaves the document unchanged" const id = core.lsp_ask.wait.?.id; var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = id }; defer queue.deinit(); - queue.acceptReader(0, 1); + queue.acceptReader(.at(0), 1); for (0..output_capacity) |_| queue.push(.{ .output = .{ - .pane = 0, + .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "output"), } }); @@ -6459,7 +6473,7 @@ test "GUI worker setup failures finish matching LSP and pipe requests" { const req: host_io.Lsp.Request = .{ .id = core.lsp_ask.wait.?.id, .kind = .status, - .pane = @intCast(core.view().active), + .pane = .at(core.view().active), .offset = 0, .arg = "", }; @@ -6560,7 +6574,7 @@ test "the window's function and editing keys reach a terminal as its cursor keys .{ .modes = "", .sym = c.SDLK_UP, .sent = "\x1b[1;1:1A" }, }; for (cases) |case| { - core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } }); while (core.nextEffect()) |_| {} keyDown(&in, case.sym, case.mod); written.clearRetainingCapacity(); @@ -6678,7 +6692,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 { out.clearRetainingCapacity(); while (core_.nextEffect()) |effect| { - if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); + if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); } return out.items; } @@ -6692,7 +6706,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac putClipboard(gpa, "ls\x1b[201~; rm -rf ~\nx"); readClipboard(&shell); try std.testing.expectEqualStrings("ls [201~; rm -rf ~\rx", try take(core, &sent)); - core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); _ = try take(core, &sent); readClipboard(&shell); try std.testing.expectEqualStrings("\x1b[200~ls [201~; rm -rf ~\nx\x1b[201~", try take(core, &sent)); @@ -6774,7 +6788,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 { out.clearRetainingCapacity(); while (core_.nextEffect()) |effect| { - if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); + if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); } return out.items; } @@ -6784,7 +6798,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift const r = core.view().rects[0]; const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 }; const next: MouseCell = .{ .col = mc.col + 1, .row = mc.row }; - core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } }); _ = try take(core, &sent); in.post(.{ .mouse = pointerMouse(.none, .motion, mc, .{}) }); try std.testing.expectEqualStrings("\x1b[<35;6;4M", try take(core, &sent)); @@ -6824,7 +6838,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a fn take(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 { out.clearRetainingCapacity(); while (core_.nextEffect()) |effect| { - if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); + if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice()); } return out.items; } @@ -6834,7 +6848,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a const r = core.view().rects[0]; const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 }; // What codex 0.159's chat sets on start. - core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } }); pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); // A notch up, then a fast turn of three down: each its report, none @@ -6860,14 +6874,14 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a try std.testing.expectEqualStrings("", try Sent.take(core, &sent)); resetScroll(&g); // Its sign-in screen: mouse off, alternate scroll on, so arrow keys. - core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } }); pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); wheelAt(&g, &in, .{ .y = -1, .integer_y = -1 }, mc); try std.testing.expectEqualStrings("\x1b[B", try Sent.take(core, &sent)); // Back on the main screen a shell's wheel is ours: a notch to glide, // nothing to the pty. - core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l" } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l" } }); pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc); diff --git a/dev/host_io.zig b/dev/host_io.zig index 2ee7c47e..f86c3250 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -69,7 +69,7 @@ pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u /// A shell of a dead session the daemon handed this one (Adopt), and the /// terminal pane made for it once there is one. -pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?u8 }; +pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?pardes.Pane.Id }; /// The shells of dead sessions handed this one (Adopt), each waiting for /// the spawn of the terminal pane made for it (`take`). @@ -99,7 +99,7 @@ pub const Adoptions = struct { a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null }; a.len += 1; if (core.adoptShell()) |id| { - a.list[a.len - 1].pane = id.index(); + a.list[a.len - 1].pane = id; a.taken += 1; return; } @@ -112,7 +112,7 @@ pub const Adoptions = struct { } /// The adopted shell pane `pane`'s spawn takes, off the list. - pub fn take(a: *Adoptions, pane: u8) ?Adoption { + pub fn take(a: *Adoptions, pane: pardes.Pane.Id) ?Adoption { for (a.list[0..a.len], 0..) |it, i| if (it.pane == pane) { std.mem.copyForwards(Adoption, a.list[i .. a.len - 1], a.list[i + 1 .. a.len]); a.len -= 1; @@ -1105,7 +1105,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo if (!pt.cmd.watched or !pt.cmd.due()) continue; pt.cmd.told = true; const eof = pt.cmd.eof; - core.update(.{ .exited = .{ .pane = @intCast(id), .status = pt.cmd.status } }); + core.update(.{ .exited = .{ .pane = .at(id), .status = pt.cmd.status } }); if (eof) close(ctx, id); } } @@ -1115,7 +1115,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo pub fn commandEof(core: *pardes.Pardes, ptys: anytype, id: usize, ctx: anytype, comptime close: anytype) void { const pt = slotPty(&ptys[id]) orelse return; pt.cmd.eof = true; - core.update(.{ .eof = .{ .pane = @intCast(id) } }); + core.update(.{ .eof = .{ .pane = .at(id) } }); if (pt.cmd.told) return close(ctx, id); takeExits(core, ptys, ctx, close); } @@ -1549,7 +1549,7 @@ pub const PtyTests = struct { } fn tail(queue: *Inbox, bytes: []u8) void { - if (queue.pushOutput(0, 1, bytes)) queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } }); + if (queue.pushOutput(.at(0), 1, bytes)) queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } }); } }; @@ -2155,9 +2155,9 @@ test "completion survives a full output queue" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 7 }; defer queue.deinit(); - queue.acceptReader(0, 1); + queue.acceptReader(.at(0), 1); for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ - .pane = 0, + .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "output"), } }); @@ -2193,15 +2193,15 @@ test "PTY backpressure retains byte order and tail before EOF" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - queue.acceptReader(0, 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + queue.acceptReader(.at(0), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); const tail = try gpa.dupe(u8, "tail"); var thread: ?std.Thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| { gpa.free(tail); return err; }; defer { - queue.cancelReader(0, 1); + queue.cancelReader(.at(0), 1); if (thread) |owned| owned.join(); } try PtyTests.waitBlocked(&queue); @@ -2227,24 +2227,24 @@ test "PTY backpressure cancellation and close release owned producers" { for ([_]bool{ false, true }) |close| { var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - queue.acceptReader(0, 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + queue.acceptReader(.at(0), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); const tail = try gpa.dupe(u8, "cancelled"); const thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| { gpa.free(tail); return err; }; defer { - queue.cancelReader(0, 1); + queue.cancelReader(.at(0), 1); thread.join(); } try PtyTests.waitBlocked(&queue); - if (close) queue.close() else queue.cancelReader(0, 1); + if (close) queue.close() else queue.cancelReader(.at(0), 1); if (!close) { - queue.acceptReader(0, 2); - queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } }); - try std.testing.expect(queue.pushOutput(0, 2, try gpa.dupe(u8, "replacement"))); - queue.push(.{ .eof = .{ .pane = 0, .gen = 2 } }); + queue.acceptReader(.at(0), 2); + queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } }); + try std.testing.expect(queue.pushOutput(.at(0), 2, try gpa.dupe(u8, "replacement"))); + queue.push(.{ .eof = .{ .pane = .at(0), .gen = 2 } }); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); try std.testing.expectEqual(@as(usize, 2), batch.len); @@ -2258,14 +2258,14 @@ test "PTY EOF reserve cannot evict terminal output" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; defer queue.deinit(); - for (0..pardes.MAX_PANES) |pane| queue.acceptReader(@intCast(pane), 1); - for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); - for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = @intCast(pane), .gen = 1 } }); + for (0..pardes.MAX_PANES) |pane| queue.acceptReader(.at(pane), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } }); + for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = .at(pane), .gen = 1 } }); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); try std.testing.expectEqual(Inbox.capacity, batch.len); for (batch.items[0..Inbox.output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes); - for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane); + for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index()); } test "completions retain their arrival order across LSP and pipes" { @@ -2288,8 +2288,8 @@ test "completion reset frees queued payloads and rejects late LSP workers" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 9 }; defer queue.deinit(); - queue.acceptReader(0, 1); - queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "retained") } }); + queue.acceptReader(.at(0), 1); + queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "retained") } }); queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "current") } }); queue.push(.{ .lsp = .{ .id = 8, .rows = try gpa.dupe(u8, "late old request") } }); try std.testing.expectEqualStrings("current", queue.completions[0].lsp.rows.?); @@ -2343,7 +2343,7 @@ test "LSP query answers, and a newer one cancels it" { defer queue.deinit(); for (0..2) |_| { core.lspRequest(core.view().active, .status, ""); - queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" }); + queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" }); } const last = core.lsp_ask.wait.?.id; queue.lsp_task.?.future.await(io); diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 48b5d3d1..1f6b9a49 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1099,7 +1099,7 @@ const Own = struct { } sh.pipe_tasks.cancelAll(io); for (&sh.gens) |*generation| generation.* +%= 1; - for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, @intCast(pane)); + for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, .at(pane)); // One view, the terminal's (host_io.restoreCore). const live = o.screen; stopInput(io, &live.thread); @@ -1386,7 +1386,8 @@ const Shell = struct { if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why}); } - fn adopt(ctx: ?*anyopaque, pane: u8) void { + fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = of(ctx); s.adoptions.ask(s.core, pane); } @@ -1397,7 +1398,8 @@ const Shell = struct { return of(ctx).client == null and upgrade.newer(); } - fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void { + fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = of(ctx); if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place"); s.upgrade_asked = pane; @@ -1748,7 +1750,7 @@ const Shell = struct { s.output_seen = true; if (pr.id == core.view().active) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); if (s.gens[pr.id] == pr.gen) - core.update(.{ .output = .{ .pane = @intCast(pr.id), .bytes = pr.bytes } }); + core.update(.{ .output = .{ .pane = .at(pr.id), .bytes = pr.bytes } }); s.gpa.free(pr.bytes); // An exit waiting behind this output may be told now. s.takeExits(); @@ -1771,9 +1773,9 @@ const Shell = struct { const status = host_io.exitStatus(pt.pid, 100); if (status == null) host_io.retireShell(pt.pid); s.ptys[e.id] = null; - if (command or status != null) core.update(.{ .exited = .{ .pane = @intCast(e.id), .status = status } }); + if (command or status != null) core.update(.{ .exited = .{ .pane = .at(e.id), .status = status } }); } - core.update(.{ .eof = .{ .pane = @intCast(e.id) } }); + core.update(.{ .eof = .{ .pane = .at(e.id) } }); }, .key_press => |key| if (s.in_paste) { const bytes = vaxis_input.pasteBytes(key); @@ -2028,17 +2030,18 @@ const Shell = struct { tracy.frameMark(); } - fn spawn(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { + fn spawn(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void { + const pane = id.index(); const s = of(ctx); - if (s.adoptions.take(pane)) |a| return s.takeShell(pane, a); + if (s.adoptions.take(id)) |a| return s.takeShell(pane, a); // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| { - if (running) return s.core.restartFailed(.at(pane), err); - return s.core.shellFailed(.at(pane), err); + if (running) return s.core.restartFailed(id, err); + return s.core.shellFailed(id, err); }; - closePty(ctx, pane); // a shell still in the slot goes, reaped + closePty(ctx, id); // a shell still in the slot goes, reaped s.gens[pane] +%= 1; const command = if (s.core.panes[pane]) |pn| pn.command != null else false; s.ptys[pane] = .{ .file = child.file, .pid = child.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } }; @@ -2046,7 +2049,7 @@ const Shell = struct { // Only a shell given no directory is asked where it is: one given a // directory is named by it already (newShell), and asked now, before // its chdir, it would answer this process's, a rename to undo. - if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); + if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(id, wd); if (s.threads_ok) { if (s.ptys[pane]) |*pt| { pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader; @@ -2057,7 +2060,7 @@ const Shell = struct { /// An adopted shell, running already, as pane `pane`'s: told the size /// twice (a size it never had, then the pane's), which makes it redraw. fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void { - closePty(s, pane); + closePty(s, .at(pane)); s.gens[pane] +%= 1; const file: std.Io.File = .{ .handle = a.fd, .flags = .{ .nonblocking = false } }; s.ptys[pane] = .{ .file = file, .pid = a.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{} }; @@ -2067,18 +2070,20 @@ const Shell = struct { if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd); const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 }; _ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny)); - if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1)); + if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1)); if (s.threads_ok) if (s.ptys[pane]) |*pt| { pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader; }; } - fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { + const pane = id.index(); const s = of(ctx); if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.file.handle, bytes); } - fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void { + fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void { + const pane = id.index(); const s = of(ctx); if (s.ptys[pane]) |pt| { const ws = host_io.ptyWinsize(s.core, cols, rows); @@ -2086,7 +2091,8 @@ const Shell = struct { } } - fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void { + fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void { + const pane = id.index(); const s = of(ctx); // A command whose exit is recorded is reaped: its group may be // another's by now. @@ -2096,7 +2102,8 @@ const Shell = struct { /// The pane is gone: hang its pty up, which the kernel passes on to the /// shell as SIGHUP, and retire the shell. Output still in flight /// carries the old generation and is dropped. - fn closePty(ctx: ?*anyopaque, pane: u8) void { + fn closePty(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = of(ctx); var pt = s.ptys[pane] orelse return; s.ptys[pane] = null; @@ -2107,13 +2114,15 @@ const Shell = struct { host_io.retireShell(pt.pid); } - fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool { + fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const s = of(ctx); const pt = s.ptys[pane] orelse return false; return host_io.ttyTaken(pt.pid, pt.file.handle); } - fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 { + fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 { + const pane = id.index(); const s = of(ctx); const pt = s.ptys[pane] orelse return null; return host_io.foregroundName(pt.pid, pt.file.handle, buf); @@ -2130,13 +2139,15 @@ const Shell = struct { s.ptys[id] = null; } - fn killJob(ctx: ?*anyopaque, pane: u8) bool { + fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const s = of(ctx); const pt = s.ptys[pane] orelse return false; return host_io.killJob(pt.pid, pt.file.handle); } - fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void { + fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { + const pane = id.index(); const s = of(ctx); host_io.writeFile(s.core, &s.watches, pane, path, bytes); } @@ -2145,7 +2156,8 @@ const Shell = struct { host_io.writeDump(of(ctx).core, bytes); } - fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void { + fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void { + const pane = id.index(); const s = of(ctx); if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, &s.watches, pane, on, mode)) s.loop.postEvent(.files_changed) catch {}; @@ -2157,7 +2169,8 @@ const Shell = struct { s.loop.postEvent(.files_changed) catch {}; } - fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { + fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const s = of(ctx); host_io.dumpThemes(s.core, s.io, s.gpa, pane); } @@ -2185,7 +2198,7 @@ const Shell = struct { const s = of(ctx); if (!s.threads_ok) { s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable); + return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows); } @@ -2220,7 +2233,8 @@ const Shell = struct { }.deliver); } - fn job(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); const s = of(ctx); if (!s.threads_ok) return host_io.KindJob.runHere(s.core, pane, serial, token); host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s, struct { @@ -2960,7 +2974,7 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell for (0..64 * 64) |i| px[i * 3 ..][0..3].* = .{ 13, 77, 231 }; const enc = try a.alloc(u8, std.base64.standard.Encoder.calcSize(px.len)); _ = std.base64.standard.Encoder.encode(enc, px); - core.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } }); while (core.nextEffect()) |_| {} const s = try core.render(a); try std.testing.expectEqual(@as(usize, 4), s.placements.items.len); @@ -3056,7 +3070,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { const req: host_io.Lsp.Request = .{ .id = core.lsp_ask.wait.?.id, .kind = .status, - .pane = @intCast(core.view().active), + .pane = .at(core.view().active), .offset = 0, .arg = "", }; @@ -3156,7 +3170,7 @@ test "the terminal's keys reach a program as its cursor keys' mode and keyboard .{ .modes = "\x1b[?1l\x1b[>7u", .in = "\x1b[99;5u\x1b[97;3u\x1b[A", .sent = "\x1b[99;5u\x1b[97;3u\x1b[1;1:1A" }, }; for (cases) |case| { - core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } }); while (core.nextEffect()) |_| {} var parser: vaxis.Parser = .{}; var bytes = case.in; diff --git a/runtime/macos.zig b/runtime/macos.zig index 3a00210d..408915da 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -781,31 +781,31 @@ fn drainInbox(st: *State) bool { defer msg.deinit(st.gpa, st.gpa); switch (msg) { .output => |o| { - if (st.gens[o.pane] != o.gen) continue; - st.cwd_stale[o.pane] = true; + if (st.gens[o.pane.index()] != o.gen) continue; + st.cwd_stale[o.pane.index()] = true; st.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } }); }, .eof => |e| { - if (st.gens[e.pane] != e.gen) continue; - if (st.ptys[e.pane]) |*pt| { + if (st.gens[e.pane.index()] != e.gen) continue; + if (st.ptys[e.pane.index()]) |*pt| { // A command's pty stays open until its child has exited: // closing it would hang up one that runs on without it. // Its exit, if it came first, is told now its output is in. if (pt.cmd.watched) { - host_io.commandEof(st.core, &st.ptys, e.pane, st, closeWatched); + host_io.commandEof(st.core, &st.ptys, e.pane.index(), st, closeWatched); continue; } // Unwatched, a command's exit is read here, as its end, // and a shell's, for a run waiting on it and the log. - const command = if (st.core.panes[e.pane]) |pane| pane.command != null else false; + const command = if (st.core.panes[e.pane.index()]) |pane| pane.command != null else false; const status = host_io.exitStatus(pt.pid, 100); if (status != null) pt.pid = 0; // reaped: no shell to retire - reap(st, e.pane); + reap(st, e.pane.index()); if (command or status != null) st.core.update(.{ .exited = .{ .pane = e.pane, .status = status } }); st.core.update(.{ .eof = .{ .pane = e.pane } }); continue; } - reap(st, e.pane); + reap(st, e.pane.index()); st.core.update(.{ .eof = .{ .pane = e.pane } }); }, .lsp => |d| { @@ -1648,15 +1648,16 @@ fn hostState(ctx: ?*anyopaque) *State { return @ptrCast(@alignCast(ctx.?)); } -fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { +fn spawnShell(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void { + const pane = id.index(); const st = hostState(ctx); const core = st.core; // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). const running = st.ptys[pane] != null; const child = host_io.forkShell(core, pane, &st.prompt_rcs, core.shellBin(), cwd, core.view().screen_h, core.view().screen_w) catch |err| { - if (running) return core.restartFailed(.at(pane), err); - return core.shellFailed(.at(pane), err); + if (running) return core.restartFailed(id, err); + return core.shellFailed(id, err); }; reap(st, pane); st.gens[pane] +%= 1; @@ -1673,54 +1674,61 @@ fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { // Only a shell given no directory is asked where it is: one given a // directory is named by it already (newShell), and asked now, before // its chdir, it would answer this process's, a rename to undo. - if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| core.setCwd(.at(pane), wd); + if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| core.setCwd(id, wd); if (st.started) if (st.ptys[pane]) |*pt| startReader(st, pt, pane); } -fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { +fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { + const pane = id.index(); const st = hostState(ctx); if (st.ptys[pane]) |pt| _ = host_io.writeFd(pt.file.handle, bytes); } -fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void { +fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void { + const pane = id.index(); const st = hostState(ctx); const pt = st.ptys[pane] orelse return; const ws: posix.winsize = .{ .row = rows, .col = cols, .xpixel = 0, .ypixel = 0 }; _ = posix.system.ioctl(pt.file.handle, TIOCSWINSZ, @intFromPtr(&ws)); } -fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void { +fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void { + const pane = id.index(); const st = hostState(ctx); // A command whose exit is recorded is reaped: its group may be another's. if (st.ptys[pane]) |pt| if (!pt.cmd.exited) host_io.signalTty(pt.pid, pt.file.handle, sig, pt.cmd.watched); } -fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool { +fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const st = hostState(ctx); const pt = st.ptys[pane] orelse return false; return host_io.ttyTaken(pt.pid, pt.file.handle); } -fn killJob(ctx: ?*anyopaque, pane: u8) bool { +fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const st = hostState(ctx); const pt = st.ptys[pane] orelse return false; return host_io.killJob(pt.pid, pt.file.handle); } -fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void { +fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { + const pane = id.index(); const st = hostState(ctx); filesystem.write(st.core, path, bytes) catch |err| - return st.core.saveFailed(.at(pane), path, err); + return st.core.saveFailed(id, path, err); st.file_watches.restampText(pane, path, std.hash.Wyhash.hash(0, bytes)); var mbuf: [256]u8 = undefined; - st.core.setMessage(.at(pane), message.stamp(&mbuf, "saved", path)); + st.core.setMessage(id, message.stamp(&mbuf, "saved", path)); } fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { host_io.writeDump(hostState(ctx).core, bytes); } -fn watchFile(ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: pardes.WatchMode) void { +fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, on: bool, mode: pardes.WatchMode) void { + const pane = id.index(); const st = hostState(ctx); if (!on or path.len == 0) { const generation = st.file_watches.stop(st.gpa, pane); @@ -1735,16 +1743,16 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void { setThemeFileWatch(st, generation, on); } -fn dumpThemes(ctx: ?*anyopaque, pane: u8) void { +fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void { const st = hostState(ctx); const config_dir = st.core.opts.config_dir orelse return; const out_dir = pardes.config.User.dumpThemes(st.io, st.gpa, config_dir, pardes.themes) catch |err| { - st.core.reportError(.at(pane), "dump themes", err); + st.core.reportError(id, "dump themes", err); return; }; defer st.gpa.free(out_dir); var mbuf: [256]u8 = undefined; - st.core.setMessage(.at(pane), message.stamp(&mbuf, "dumped themes", out_dir)); + st.core.setMessage(id, message.stamp(&mbuf, "dumped themes", out_dir)); } fn setClipboard(ctx: ?*anyopaque, text: []const u8) void { @@ -1764,14 +1772,15 @@ fn openLink(_: ?*anyopaque, url: []const u8) void { } fn startReader(st: *State, pt: *Pty, id: u8) void { - pt.reader = st.inbox.startReader(pt.file, id, pt.gen) catch |err| { + pt.reader = st.inbox.startReader(pt.file, .at(id), pt.gen) catch |err| { log.err("pane {d} has no reader ({t}); it will not show output", .{ id, err }); return; }; } /// The pane is gone: its shell goes with it. -fn closePty(ctx: ?*anyopaque, pane: u8) void { +fn closePty(ctx: ?*anyopaque, id: pardes.Pane.Id) void { + const pane = id.index(); const st = hostState(ctx); if (st.ptys[pane] == null) return; reap(st, pane); @@ -1782,7 +1791,7 @@ fn reap(st: *State, pane: u8) void { var pt = st.ptys[pane] orelse return; st.ptys[pane] = null; // The inbox first: a reader waiting for space there wakes and returns. - st.inbox.cancelReader(pane, pt.gen); + st.inbox.cancelReader(.at(pane), pt.gen); pt.reader.cancel(st.io); _ = libc.close(pt.file.handle); host_io.retireShell(pt.pid); diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig index ef5dec60..ceda8158 100644 --- a/test/fs_namespace.zig +++ b/test/fs_namespace.zig @@ -203,7 +203,7 @@ test "explicit OS file opens and restores keep their names and request watches" try std.testing.expectEqualStrings("const disk = 1;\n", pane.file.?.content); var watched_open = false; while (p.nextEffect()) |effect| if (effect == .watch and effect.watch.on) { - if (effect.watch.pane == opened) watched_open = true; + if (effect.watch.pane.index() == opened) watched_open = true; }; try std.testing.expect(watched_open); // Unsaved, dumped and loaded: its text kept, its file watched again. @@ -216,7 +216,7 @@ test "explicit OS file opens and restores keep their names and request watches" try std.testing.expectEqualStrings("// unsaved\nconst disk = 1;\n", copy.file.?.content); var watched_restore = false; while (restored.nextEffect()) |effect| if (effect == .watch and effect.watch.on) { - if (effect.watch.pane == opened) watched_restore = true; + if (effect.watch.pane.index() == opened) watched_restore = true; }; try std.testing.expect(watched_restore); } diff --git a/test/hxdiff.zig b/test/hxdiff.zig index 01169504..db858561 100644 --- a/test/hxdiff.zig +++ b/test/hxdiff.zig @@ -352,7 +352,7 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result cooked[cooked_i] = ch; cooked_i += 1; } - core.update(.{ .output = .{ .pane = 0, .bytes = cooked } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = cooked } }); pump(core); // leave tty mode the way a live session does: Ctrl-, // then park the cursor at (0,0) — the helix harness's initial diff --git a/test/kitty.zig b/test/kitty.zig index 6db6e8fc..76d97421 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -90,13 +90,13 @@ const Rig = struct { fn drain(r: *Rig) void { while (r.p.nextEffect()) |effect| { - if (effect == .write) r.read[effect.write.pane].appendSlice(gpa, effect.write.bytes.slice()) catch @panic("OOM"); + if (effect == .write) r.read[effect.write.pane.index()].appendSlice(gpa, effect.write.bytes.slice()) catch @panic("OOM"); } } /// One pty read of pane `id`'s output. fn feed(r: *Rig, id: u8, bytes: []const u8) void { - r.p.update(.{ .output = .{ .pane = id, .bytes = bytes } }); + r.p.update(.{ .output = .{ .pane = .at(id), .bytes = bytes } }); r.drain(); } diff --git a/test/output.zig b/test/output.zig index a8a1f239..38e8ba0d 100644 --- a/test/output.zig +++ b/test/output.zig @@ -389,7 +389,7 @@ test "Mini asks for no watch on its pane" { try std.testing.expect(id != 0); try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig")); while (p.nextEffect()) |effect| switch (effect) { - .watch => |watch| try std.testing.expect(watch.pane != id), + .watch => |watch| try std.testing.expect(watch.pane.index() != id), else => {}, }; } @@ -414,7 +414,7 @@ test "Mini dump preserves its exact virtual snapshot and body writes detach colo try std.testing.expectEqualSlices(u8, before.mini.?.colors, mini.file.?.mini.?.colors); try std.testing.expect(before.content.ptr != mini.file.?.content.ptr); while (restored.nextEffect()) |effect| switch (effect) { - .watch => |watch| try std.testing.expect(watch.pane != restored.view().active), + .watch => |watch| try std.testing.expect(watch.pane.index() != restored.view().active), else => {}, }; var body_buf: [128]u8 = undefined; @@ -534,7 +534,7 @@ test "Config with no startup file opens a pane of its name, and Save makes its d try std.testing.expectError(error.FileNotFound, tmp.dir.statFile(std.testing.io, "pardes", .{})); // Save's effect, as a host performs it. try std.testing.expect(p.executeBuiltinLine(opened, "Save")); - p.perform(.{ .save_file = .{ .pane = @intCast(opened) } }); + p.perform(.{ .save_file = .{ .pane = .at(opened) } }); const made = try tmp.dir.statFile(std.testing.io, "pardes", .{}); try std.testing.expectEqual(std.Io.File.Kind.directory, made.kind); } diff --git a/test/panes.zig b/test/panes.zig index 022d672c..dbdbec2f 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -453,7 +453,7 @@ const TtySelectionTests = struct { const pane = p.panes[0].?; pane.tty_filter = false; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha" } }); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -478,7 +478,7 @@ const TtySelectionTests = struct { pane.body.mode = .tty; pane.tty_filter = false; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = if (prompt) + p.update(.{ .output = .{ .pane = .at(0), .bytes = if (prompt) "\x1b]133;A\x07$ \x1b]133;B\x07abc" else "alpha\r\nbravo" } }); @@ -519,7 +519,7 @@ const TtySelectionTests = struct { try noChildInput(p); _ = try p.render(frame.allocator()); try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;C\x07" ++ std.mem.asBytes(&@as([30][12]u8, @splat("\r\nnew output".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;C\x07" ++ std.mem.asBytes(&@as([30][12]u8, @splat("\r\nnew output".*))) } }); _ = try p.render(frame.allocator()); try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); @@ -542,10 +542,10 @@ const TtySelectionTests = struct { } p.update(.tick); while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha\r\nbravo" } }); - p.update(.{ .output = .{ .pane = 1, .bytes = "target> " } }); - if (bracketed) p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004h" } }); - if (reports_mouse) p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?1000h\x1b[?1006h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha\r\nbravo" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "target> " } }); + if (bracketed) p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004h" } }); + if (reports_mouse) p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?1000h\x1b[?1006h" } }); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -569,7 +569,7 @@ const TtySelectionTests = struct { defer written.deinit(); while (p.nextEffect()) |effect| { if (effect == .write) { - try std.testing.expectEqual(@as(u8, 1), effect.write.pane); + try std.testing.expectEqual(1, effect.write.pane.index()); try written.writer.writeAll(effect.write.bytes.slice()); } } @@ -613,7 +613,7 @@ const TtySelectionTests = struct { defer p.deinit(); const pane = p.panes[0].?; try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); - if (bracketed) p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + if (bracketed) p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); try std.testing.expectEqual(bracketed, pardes.Term.modes(pane.terminal).bracketed_paste); try p.registers.put(p.gpa, '"', "one\ntwo", 0, 1, true); // what a `y` anywhere left behind var buf: [256]u8 = undefined; @@ -964,7 +964,7 @@ test "terminal overlay recoloring never materializes unrelated history" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - for (0..1000) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32mcaf\xc3\xa9 \xe7\x95\x8c\x1b[0m\r\n" } }); + for (0..1000) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[32mcaf\xc3\xa9 \xe7\x95\x8c\x1b[0m\r\n" } }); pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 1, .text = try p.gpa.dupe(u8, "edited history") }; var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -1009,7 +1009,7 @@ test "terminal output keeps following new rows after scrollback eviction" { var buf: [64]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "\x1b[32mrow-{d:0>5}\x1b[0m\r\n", .{n}); const previous = pages.scrollbar().total; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); if (pages.scrollbar().total < previous) evictions += 1; } try std.testing.expect(evictions > phase); @@ -1036,7 +1036,7 @@ test "terminal output keeps following new rows after scrollback eviction" { p.update(.{ .key = .{ .cp = 'f', .text = "f" } }); const effect = p.nextEffect() orelse return error.MissingTerminalInput; try std.testing.expectEqual(.write, std.meta.activeTag(effect)); - try std.testing.expectEqual(@as(u8, 0), effect.write.pane); + try std.testing.expectEqual(0, effect.write.pane.index()); try std.testing.expectEqualStrings("f", effect.write.bytes.slice()); try std.testing.expect(p.nextEffect() == null); } @@ -1055,7 +1055,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { while (next < 3000) { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{next}); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); next += 1; if (pages.scrollbar().total > pages.pages.first.?.rows() + pane.rows + 10) break; } @@ -1073,7 +1073,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{n}); const previous = pages.scrollbar().total; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); if (pages.scrollbar().total < previous) { removed = previous + 1 - pages.scrollbar().total; break; @@ -1099,8 +1099,8 @@ test "terminal edits and undo survive partial history clearing and whole-screen const pane = p.panes[0].?; pane.body.mode = .tty; if (action == .reset_alternate) - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h" } }); - p.update(.{ .output = .{ .pane = 0, .bytes = std.mem.asBytes(&@as([40][9]u8, @splat("old row\r\n".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = std.mem.asBytes(&@as([40][9]u8, @splat("old row\r\n".*))) } }); const pages = &pardes.Term.emulatorOf(pane.terminal.?).vt.screens.active.pages; pages.limits.set(.bytes, 64 * 1024); const row: i32 = @as(i32, @intCast(pages.total_rows - pane.rows)) + @@ -1130,7 +1130,7 @@ test "terminal edits and undo survive partial history clearing and whole-screen .reset_primary, .reset_alternate => "\x1bc", .evict_all, .hidden_undo => std.mem.asBytes(&@as([4000][9]u8, @splat("new row\r\n".*))), }; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); const expected: i32 = if (action == .clear_history) 2 else 0; // The copy's top row was in the history ED 3 erased: the copy goes // with it (terminal.zig's rule for rows that are gone), and the @@ -1166,7 +1166,7 @@ test "terminal lower scroll regions do not move edits above them" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "top\r\nsecond\r\nthird" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "top\r\nsecond\r\nthird" } }); pane.ovl = .{ .row = 1, .rows = 1, .text = try gpa.dupe(u8, "unsent") }; pane.body.cur_row = 1; pane.body.cur_pinned = true; @@ -1174,8 +1174,8 @@ test "terminal lower scroll regions do not move edits above them" { const total = pardes.Term.grid(pane.terminal).total; var setup: [64]u8 = undefined; const bytes = try std.fmt.bufPrint(&setup, "\x1b[4;{d}r\x1b[{d};1H", .{ pane.rows, pane.rows }); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); - p.update(.{ .output = .{ .pane = 0, .bytes = std.mem.asBytes(&@as([50][6]u8, @splat("tail\r\n".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = std.mem.asBytes(&@as([50][6]u8, @splat("tail\r\n".*))) } }); try std.testing.expectEqual(total, pardes.Term.grid(pane.terminal).total); try std.testing.expectEqual(@as(i32, 1), pane.ovl.?.row); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); @@ -1198,7 +1198,7 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv while (next < 3000) { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{next}); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); next += 1; if (pages.pages.first != pages.pages.last and pages.pages.last.?.rows() == pages.pages.last.?.capacity().rows) break; @@ -1214,7 +1214,7 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv const old_total = pages.total_rows; var buf: [128]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "new\r\n\x1b[4;{d}r\x1b[{d};1Hregion\r\n", .{ pane.rows, pane.rows }); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); try std.testing.expectEqual(old_total + 1 - removed, pages.total_rows); try std.testing.expectEqual(@as(i32, 2), pane.ovl.?.row); try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); @@ -1412,12 +1412,12 @@ test "Save rearms renamed file watches only after a successful write" { watches: usize = 0, err: ?anyerror = null, - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const h: *@This() = @ptrCast(@alignCast(ctx.?)); switch (h.result) { .success => {}, - .failure => h.core.saveFailed(.at(id), "save", error.PermissionDenied), - .edited => h.core.panes[id].?.file.?.revision +%= 1, + .failure => h.core.saveFailed(id, "save", error.PermissionDenied), + .edited => h.core.panes[id.index()].?.file.?.revision +%= 1, .replaced => { const replacement = h.core.setTestFile("replacement\n") catch |err| { h.err = err; @@ -1427,16 +1427,16 @@ test "Save rearms renamed file watches only after a successful write" { replacement.file.?.saved_revision -%= 1; }, .closed => { - pardes.panes.deinitPane(h.core, h.core.panes[id].?) catch |err| { + pardes.panes.deinitPane(h.core, h.core.panes[id.index()].?) catch |err| { h.err = err; return; }; - h.core.panes[id] = null; + h.core.panes[id.index()] = null; }, } } - fn watch(ctx: ?*anyopaque, _: u8, _: []const u8, on: bool, _: pardes.WatchMode) void { + fn watch(ctx: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, on: bool, _: pardes.WatchMode) void { const h: *@This() = @ptrCast(@alignCast(ctx.?)); if (on) h.watches += 1; } @@ -1484,9 +1484,9 @@ test "Save rearms renamed file watches only after a successful write" { test "Save on a scratch does not watch a path the host could not create" { const Refusing = struct { - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); - p.saveFailed(.at(id), "save", error.PermissionDenied); + p.saveFailed(id, "save", error.PermissionDenied); } }; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); @@ -1518,9 +1518,9 @@ test "Save on a scratch does not watch a path the host could not create" { test "a failed Save to another name leaves a clean named file clean" { const Refusing = struct { - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); - p.saveFailed(.at(id), "save", error.AccessDenied); + p.saveFailed(id, "save", error.AccessDenied); } }; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); @@ -1544,14 +1544,14 @@ test "unplaced terminal panes keep their allocated grid until placement" { const id = p.freeSlot().?; const pane = try p.newShell(id, ""); try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]); - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "unplaced\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "unplaced\r\n" } }); try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]); try std.testing.expectEqual(@as(u16, 100), pane.cols); try std.testing.expectEqual(@as(u16, 30), pane.rows); try std.testing.expectEqual(pane.cols, pardes.Term.emulatorOf(pane.terminal.?).vt.cols); try std.testing.expectEqual(pane.rows, pardes.Term.emulatorOf(pane.terminal.?).vt.rows); while (p.nextEffect()) |effect| { - if (effect == .resize_pty and effect.resize_pty.pane == id) return error.ResizedUnplacedPane; + if (effect == .resize_pty and effect.resize_pty.pane.index() == id) return error.ResizedUnplacedPane; } pardes.layout.insert(p, 0, 1, id); p.update(.tick); @@ -1572,7 +1572,7 @@ test "document panes ignore terminal output without allocating terminal state" { const resizes = allocator.resize_index; allocator.fail_index = allocations; allocator.resize_fail_index = resizes; - p.update(.{ .output = .{ .pane = 0, .bytes = "unrelated PTY output\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "unrelated PTY output\r\n" } }); try std.testing.expect(!allocator.has_induced_failure); try std.testing.expectEqual(allocations, allocator.alloc_index); try std.testing.expectEqual(resizes, allocator.resize_index); @@ -2442,19 +2442,19 @@ const TerminalTests = struct { .write => return error.GreetedBeforeOutput, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "startup banner\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "startup banner\r\n" } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.GreetedBeforePrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;aid=pardes\x07prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;aid=pardes\x07prompt$ " } }); try std.testing.expect(!pardes.Term.prompt(pane.terminal).input_ready); while (p.nextEffect()) |effect| switch (effect) { .write => return error.GreetedDuringPrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;B;aid=pardes\x07" } }); try std.testing.expect(pardes.Term.prompt(pane.terminal).input_ready); var greeted = false; while (p.nextEffect()) |effect| switch (effect) { @@ -2477,9 +2477,9 @@ const TerminalTests = struct { const pane = p.panes[0].?; while (p.nextEffect()) |_| {} p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); - p.update(.{ .output = .{ .pane = 0, .bytes = output } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = output } }); // and a later, quiet prompt changes nothing - p.update(.{ .output = .{ .pane = 0, .bytes = "\r\n\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\r\n\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); while (p.nextEffect()) |effect| switch (effect) { .write => |write| if (std.mem.eql(u8, write.bytes.slice(), "ls\r")) return error.GreetedLate, else => {}, @@ -2505,13 +2505,13 @@ const TerminalTests = struct { .write => return error.CommandEscapedBeforePrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "startup\r\n\x1b]133;A\x07prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "startup\r\n\x1b]133;A\x07prompt$ " } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.CommandEscapedDuringPrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;B\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;B\x07" } }); var sent: [64]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -2536,7 +2536,7 @@ const TerminalTests = struct { p.acknowledgeShell(.at(0), "/bin/sh", false); try std.testing.expect(!pane.greet); try std.testing.expectEqual(.none, pane.pending_command.wait); - p.update(.{ .output = .{ .pane = 0, .bytes = "plain prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "plain prompt$ " } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.UnmarkedGreetingEscaped, else => {}, @@ -2569,7 +2569,7 @@ const TerminalTests = struct { const effect = p.nextEffect() orelse return error.MissingWriteEffect; switch (effect) { .write => |write| { - try std.testing.expectEqual(@as(u8, 0), write.pane); + try std.testing.expectEqual(0, write.pane.index()); try std.testing.expectEqualStrings(expected, write.bytes.slice()); }, else => return error.UnexpectedEffect, @@ -2603,7 +2603,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2658,7 +2658,7 @@ const TerminalTests = struct { // grapheme for that cell, not one per stored codepoint: stepping twice ate // the `A`, and left every colour a cell to the left of its glyph with the // last one stranded on a blank. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32me\u{301}\x1b]133;B\x1b\\\x1b[31mA\x1b[34mB\x1b[35mC" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32me\u{301}\x1b]133;B\x1b\\\x1b[31mA\x1b[34mB\x1b[35mC" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2694,7 +2694,7 @@ const TerminalTests = struct { for (0..60) |i| { var buf: [32]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[4{d}mL{d:0>2}\x1b[0m\r\n", .{ (i % 6) + 1, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; pardes.Term.scroll(pane.terminal.?, -20); @@ -2745,7 +2745,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2782,7 +2782,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2821,7 +2821,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - p.update(.{ .output = .{ .pane = 0, .bytes = payload } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = payload } }); const diffs = try modeStyleDiffs(p, pane, testing.allocator, if (filter) "session filter=on" else "session filter=off"); try testing.expectEqual(@as(usize, 0), diffs); } @@ -2864,7 +2864,7 @@ const TerminalTests = struct { "\x1b]133;A\x1b\\\x1b[32m{s}$ \x1b]133;B\x1b\\\x1b[31mab\x1b[34mcd\x1b[0m", .{prompt}, ); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2923,7 +2923,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - p.update(.{ .output = .{ .pane = 0, .bytes = payload } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = payload } }); const diffs = try modeStyleDiffs(p, pane, testing.allocator, if (filter) "bg filter=on" else "bg filter=off"); try testing.expectEqual(@as(usize, 0), diffs); } @@ -2941,7 +2941,7 @@ const TerminalTests = struct { for (0..60) |i| { var buf: [40]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[3{d}mL{d:0>2}\x1b[0m\r\n", .{ (i % 6) + 1, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3004,7 +3004,7 @@ const TerminalTests = struct { p.sync(); pane.tty_filter = filter; pane.body.mode = mode; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32m\u{754C}\x1b[41m\x1b[K\x1b[7G\x1b[44m\x1b[K\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[32m\u{754C}\x1b[41m\x1b[K\x1b[7G\x1b[44m\x1b[K\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3040,7 +3040,7 @@ const TerminalTests = struct { const pane = p.panes[0].?; pane.tty_filter = false; pane.body.mode = mode; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[41mzzzzzzzzzzzzz\u{754C}\x1b[0m\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[41mzzzzzzzzzzzzz\u{754C}\x1b[0m\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3070,7 +3070,7 @@ const TerminalTests = struct { for (0..40) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mline-{d:0>2}\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; @@ -3124,12 +3124,12 @@ const TerminalTests = struct { const tx = r.x + config.GUTTER; const body_y = bodyY(p, r); - p.update(.{ .output = .{ .pane = 0, .bytes = "plain text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "plain text\r\n" } }); p.shell_rows.stale = true; const before = try p.render(frame.allocator()); const plain = before.at(tx, body_y).style; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } }); p.shell_rows.stale = true; _ = frame.reset(.retain_capacity); const after = try p.render(frame.allocator()); @@ -3153,7 +3153,7 @@ const TerminalTests = struct { for (0..6) |i| { var buf: [40]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}\x1b[0m\r\n", .{ 16 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3192,7 +3192,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31m000\x1b[0m\r\n\x1b[32m111\x1b[0m\r\n\r\n\x1b[34m333\x1b[0m\r\n\x1b[35m444\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31m000\x1b[0m\r\n\x1b[32m111\x1b[0m\r\n\r\n\x1b[34m333\x1b[0m\r\n\x1b[35m444\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3228,7 +3228,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3267,7 +3267,7 @@ const TerminalTests = struct { for (0..6) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d}-abcdefgh\x1b[0m\r\n", .{ 30 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } // One `Z` typed into the middle of row 3's own text. pane.ovl = .{ .row = 3, .rows = 1, .text = try p.gpa.dupe(u8, "row-3-abcZdefgh") }; @@ -3317,7 +3317,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } pane.ovl = .{ .row = 23, @@ -3376,7 +3376,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; @@ -3464,7 +3464,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } // A newline typed at column 0 of row 24, and `WW` typed on the blank row // below the output: the span covers rows 24, 25 and that blank row. @@ -3528,7 +3528,7 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode defer p.deinit(); const pane = p.panes[0].?; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "abcdefghij\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abcdefghij\r\n" } }); for (keys) |cp| p.update(.{ .key = .{ .cp = cp } }); try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal)); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); @@ -3621,7 +3621,7 @@ test "terminal overlays preserve trailing blank styles without coloring inserted while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - p.update(.{ .output = .{ .pane = 0, .bytes = "A\r\n\x1b[41m\x1b[2K\r\n\x1b[42m\x1b[2K\r\n\x1b[44m\x1b[2K\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "A\r\n\x1b[41m\x1b[2K\r\n\x1b[42m\x1b[2K\r\n\x1b[44m\x1b[2K\x1b[0m" } }); pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 3, .text = try gpa.dupe(u8, "A\n\n") }; var frame = std.heap.ArenaAllocator.init(gpa); @@ -3713,7 +3713,7 @@ test "a terminal keeps its tag and two body rows through a squeeze, a drag and a p.sync(); try std.testing.expectEqual(floor, p.view().rects[term].h); var rows: ?u16 = null; - while (p.nextEffect()) |effect| if (effect == .resize_pty and effect.resize_pty.pane == term) { + while (p.nextEffect()) |effect| if (effect == .resize_pty and effect.resize_pty.pane.index() == term) { rows = effect.resize_pty.rows; }; try std.testing.expectEqual(@as(?u16, layout.min_body_rows), rows); @@ -3751,7 +3751,7 @@ const PdfAddon = struct { const j = pardes.host_io.KindJob.take(core, a.pane, a.serial, a.token) orelse continue; defer j.drop(); j.run(); - try land.step(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); + try land.step(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); } } @@ -3760,7 +3760,7 @@ const PdfAddon = struct { items: [16]Asked = undefined, n: usize = 0, fn append(q: *@This(), j: anytype) void { - if (q.n < q.items.len) q.items[q.n] = .{ .pane = j.pane, .serial = j.serial, .token = j.token }; + if (q.n < q.items.len) q.items[q.n] = .{ .pane = j.pane.index(), .serial = j.serial, .token = j.token }; q.n += @intFromBool(q.n < q.items.len); } fn pop(q: *@This()) ?Asked { @@ -3777,7 +3777,7 @@ const PdfAddon = struct { } }.f, .job = struct { - fn f(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn f(_: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void { asked.append(.{ .pane = pane, .serial = serial, .token = token }); } }.f, @@ -3833,7 +3833,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); var buf: [4096]u8 = undefined; const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, "docs/design.pdf", &buf); var line: [4200]u8 = undefined; @@ -3903,7 +3903,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(@import("test_addons").image, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "dot.ppm", .data = "P6\n1 1\n255\n\x01\x02\x03" }); @@ -4202,7 +4202,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); const kind = a.core.kinds.n - 1; win.core().kinds.ops[kind] = a.core.kinds.ops[kind]; const id = try opened(a, land); @@ -4245,7 +4245,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); const kind = a.core.kinds.n - 1; win.core().kinds.ops[kind] = a.core.kinds.ops[kind]; const id = try opened(a, land); diff --git a/test/perf.zig b/test/perf.zig index 17df0bdc..880e6abe 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -732,7 +732,7 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell { const t0 = nowNs(); switch (op) { .render => {}, - .output => core.update(.{ .output = .{ .pane = 0, .bytes = term_chunk } }), + .output => core.update(.{ .output = .{ .pane = .at(0), .bytes = term_chunk } }), .resize_rows => { rows = if (rows == screen_rows) screen_rows - 1 else screen_rows; core.update(.{ .resize = .{ .cols = cols, .rows = rows } }); @@ -782,7 +782,7 @@ fn bootTerm(fx: TermFixture) !*pardes.Pardes { var off: usize = 0; while (off < text.len) { const end = @min(off + 8192, text.len); - core.update(.{ .output = .{ .pane = 0, .bytes = text[off..end] } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = text[off..end] } }); pump(core); off = end; } @@ -925,7 +925,7 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he while (offset < bytes.len) { const stop = @min(offset + 4096, bytes.len); const update_begin = nowNs(); - core.update(.{ .output = .{ .pane = 0, .bytes = bytes[offset..stop] } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = bytes[offset..stop] } }); pump(core); updates[nupdates] = nowNs() - update_begin; nupdates += 1; @@ -1001,7 +1001,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void var offset: usize = 0; while (offset < bytes.len) { const end = @min(offset + 4096, bytes.len); - core.update(.{ .output = .{ .pane = 0, .bytes = bytes[offset..end] } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = bytes[offset..end] } }); pump(core); offset = end; } @@ -1043,7 +1043,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void try checkTerminalTail(core, try core.render(arena.allocator()), batches - 1); core.update(.{ .key = .{ .cp = 'f', .text = "f" } }); const input = core.nextEffect() orelse return error.TerminalInputMissing; - if (input != .write or input.write.pane != 0 or !std.mem.eql(u8, "f", input.write.bytes.slice())) + if (input != .write or input.write.pane.index() != 0 or !std.mem.eql(u8, "f", input.write.bytes.slice())) return error.TerminalInputWrong; if (core.nextEffect() != null) return error.UnexpectedTerminalEffect; std.mem.sort(u64, samples[0..batches], {}, std.sort.asc(u64)); @@ -1063,7 +1063,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void const update = try std.fmt.bufPrint(&update_buffer, "\r\n\x1b[32mTURN {d:0>10} READY\x1b[0m", .{tail_id}); _ = arena.reset(.retain_capacity); const begin = nowNs(); - core.update(.{ .output = .{ .pane = 0, .bytes = update } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = update } }); pump(core); const cursor_row = @as(i32, @intCast(pardes.Term.grid(pane.terminal).offset)) + @as(i32, pardes.Term.grid(pane.terminal).cursor_y); pane.ovl.?.row = if (phase == 0) 0 else cursor_row - 1; diff --git a/test/replicas.zig b/test/replicas.zig index 88881dd7..57b6ff23 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -102,7 +102,8 @@ const Host = struct { return h.draws; } - fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { + const pane = id.index(); const h: *Host = @ptrCast(@alignCast(ctx.?)); h.echo.append(gpa, .{ .pane = pane, .bytes = gpa.dupe(u8, bytes) catch return }) catch {}; } @@ -123,7 +124,8 @@ const Host = struct { /// it at once on the core's side, inside the perform that asked it, /// where no tape records it: a client replays that perform without it). /// At the setup, before any client, at once inside this call. - fn job(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); const h: *Host = @ptrCast(@alignCast(ctx.?)); const j = pardes.host_io.KindJob.take(h.core.?, pane, serial, token) orelse return; if (Draws.go(null, j)) return; @@ -807,7 +809,8 @@ const Soak = struct { return of(ctx).at_frame; } - fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void { + const pane = id.index(); const s = of(ctx); s.echo.append(gpa, .{ .pane = pane, .bytes = gpa.dupe(u8, bytes) catch return }) catch {}; } @@ -827,7 +830,8 @@ const Soak = struct { /// its loop's event (with no `job`, Effect.perform runs it at once on /// the core's side, inside the perform that asked it, where no tape /// records it: a client replays that perform without it). - fn job(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); const core = of(ctx).l.core; const j = pardes.host_io.KindJob.take(core, pane, serial, token) orelse return; if (Draws.go(null, j)) return; @@ -1014,7 +1018,7 @@ const Soak = struct { cl.read_done = false; cl.gen += 1; cl.id = welcome.client; - cl.view = welcome.view; + cl.view = welcome.view.index(); cl.digest = welcome.digest; s.totals.joins += 1; try net.toClient(c, now, .dump, cl.gen, try whole.toOwnedSlice(gpa)); @@ -1185,7 +1189,7 @@ const Soak = struct { // program's output a frame a tick (tui.zig `waitInput`). .echo => { s.clock(); - core.update(.{ .output = .{ .pane = @intCast(m.who), .bytes = m.bytes } }); + core.update(.{ .output = .{ .pane = .at(m.who), .bytes = m.bytes } }); return false; }, .output => { @@ -1205,7 +1209,7 @@ const Soak = struct { if (s.program.at < s.program.bytes.len) try net.send(.{ .at = m.at + if (m.who == 1) @as(u64, 450) else 3_000, .n = 0, .kind = .output, .who = m.who, .bytes = &.{} }) else if (m.who == 1) s.flood_end = m.at; - core.update(.{ .output = .{ .pane = s.shell, .bytes = chunk } }); + core.update(.{ .output = .{ .pane = .at(s.shell), .bytes = chunk } }); took_output = true; }, .frame => { @@ -1271,7 +1275,7 @@ const Soak = struct { // A state job's answer: a step of the session's own. if (j.draw == null) { s.clock(); - core.update(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); + core.update(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); j.drop(); return false; } @@ -2139,7 +2143,7 @@ const EchoHost = struct { return false; } - fn ptyWrite(ctx: ?*anyopaque, _: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, _: pardes.Pane.Id, bytes: []const u8) void { const h: *EchoHost = @ptrCast(@alignCast(ctx.?)); h.writes.append(gpa, .{ .seq = h.current, .bytes = gpa.dupe(u8, bytes) catch return }) catch {}; } @@ -2287,7 +2291,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { // The shell's first prompt. sh.put(prompt_bytes); - a.output(.{ .output = .{ .pane = shell, .bytes = sh.out.items } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = sh.out.items } }); sh.out.clearRetainingCapacity(); var next_step: usize = 0; try push(&queue, &n, .{ .at = corpus.steps.items[0].gap, .n = 0, .kind = .input, .who = 1, .bytes = &.{} }); @@ -2351,7 +2355,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { } sh.key(m.bytes); if (sh.out.items.len > 0) { - a.output(.{ .output = .{ .pane = shell, .bytes = sh.out.items } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = sh.out.items } }); sh.out.clearRetainingCapacity(); if (ty) |k| k.echoed = true; } diff --git a/test/rollback_bench.zig b/test/rollback_bench.zig index d750871e..24203308 100644 --- a/test/rollback_bench.zig +++ b/test/rollback_bench.zig @@ -80,7 +80,7 @@ fn build(s: Session, dir: []const u8, a: std.mem.Allocator) !*pardes.Pardes { var off: usize = 0; while (off < chunk.written().len) { const end = @min(off + 8192, chunk.written().len); - core.update(.{ .output = .{ .pane = 0, .bytes = chunk.written()[off..end] } }); + core.update(.{ .output = .{ .pane = .at(0), .bytes = chunk.written()[off..end] } }); pump(core); off = end; } diff --git a/test/session.zig b/test/session.zig index bf118533..1cbee9df 100644 --- a/test/session.zig +++ b/test/session.zig @@ -288,11 +288,11 @@ pub const Session = struct { .addon => pardesOf(s).perform(e), // A kind's job, here and at once, as the host's worker would; // held while a test holds them (`hold_jobs`). - .job => |j| if (!s.hold_jobs) pardesOf(s).perform(e) else if (pardes.host_io.KindJob.take(pardesOf(s), j.pane, j.serial, j.token)) |taken| s.held.append(pardesOf(s).gpa, taken) catch taken.drop(), + .job => |j| if (!s.hold_jobs) pardesOf(s).perform(e) else if (pardes.host_io.KindJob.take(pardesOf(s), j.pane.index(), j.serial, j.token)) |taken| s.held.append(pardesOf(s).gpa, taken) catch taken.drop(), .lsp => |q| if (s.languages) |io| s.askServer(io, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }), .watch => |w| { if (s.watch_fd < 0) s.watch_fd = pardes.file_watch.init(true); - if (s.watch_fd >= 0) _ = pardes.file_watch.applyEffect(pardesOf(s), std.Io.Threaded.global_single_threaded.io(), s.watch_fd, &s.watches, w.pane, w.on, w.mode); + if (s.watch_fd >= 0) _ = pardes.file_watch.applyEffect(pardesOf(s), std.Io.Threaded.global_single_threaded.io(), s.watch_fd, &s.watches, w.pane.index(), w.on, w.mode); }, else => {}, }; diff --git a/test/terminal.zig b/test/terminal.zig index fafaa605..e6c530d5 100644 --- a/test/terminal.zig +++ b/test/terminal.zig @@ -57,7 +57,7 @@ fn ptyWritesByPane(p: *Pardes, out: *std.ArrayList(u8)) ![]const u8 { var per: [pardes.MAX_PANES]std.ArrayList(u8) = @splat(.empty); defer for (&per) |*b| b.deinit(p.gpa); while (p.nextEffect()) |effect| { - if (effect == .write) try per[effect.write.pane].appendSlice(p.gpa, effect.write.bytes.slice()); + if (effect == .write) try per[effect.write.pane.index()].appendSlice(p.gpa, effect.write.bytes.slice()); } for (per, 0..) |b, id| if (b.items.len > 0) try out.print(p.gpa, "{d}:{s}\n", .{ id, b.items }); return out.items; @@ -163,15 +163,15 @@ test "terminal state keeps parser fragments and sends emulator replies through i const pane = p.panes[0].?; const state = of(pane.terminal.?); try std.testing.expect(state.stream.handler.inner.terminal == &state.vt); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[" } }); while (p.nextEffect()) |effect| { if (effect == .write) return error.PrematureTerminalReply; } - p.update(.{ .output = .{ .pane = 0, .bytes = "6n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "6n" } }); var answers: usize = 0; while (p.nextEffect()) |effect| { if (effect != .write) continue; - try std.testing.expectEqual(@as(u8, 0), effect.write.pane); + try std.testing.expectEqual(0, effect.write.pane.index()); try std.testing.expectEqualStrings("\x1b[1;1R", effect.write.bytes.slice()); answers += 1; } @@ -212,7 +212,7 @@ test "a restored command pane comes back finished, its command not run again" { const cmd = p.freeSlot().?; _ = try panes.newCommand(p, cmd, "/tmp", "make test"); p.panes[cmd].?.feedOutput(p, "ok\r\n"); - p.update(.{ .exited = .{ .pane = @intCast(cmd), .status = 2 } }); + p.update(.{ .exited = .{ .pane = .at(cmd), .status = 2 } }); try pardes.dump.dumpState(p); const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }, p.dump_out.?); defer restored.deinit(); @@ -248,7 +248,7 @@ test "a restored terminal keeps its history above a marker and gets a shell wher defer restored.deinit(); var spawned = false; while (restored.nextEffect()) |effect| switch (effect) { - .spawn => |sp| spawned = sp.pane == 0 and std.mem.eql(u8, sp.cwd.slice(), "/tmp"), + .spawn => |sp| spawned = sp.pane.index() == 0 and std.mem.eql(u8, sp.cwd.slice(), "/tmp"), else => {}, }; try std.testing.expect(spawned); @@ -323,7 +323,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu try testing.expect(pane.tty_filter); pane.tty_filter = false; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mA" ++ + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mA" ++ "\x1b[38;5;196mB" ++ "\x1b[38;2;255;0;0mC" ++ "\x1b[0;48;5;25mD" ++ @@ -384,7 +384,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu } } - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]4;1;#ff0000\x1b\\" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]4;1;#ff0000\x1b\\" } }); const osc_red = of(pane.terminal.?).vt.colorForXterm(.{ .palette = 1 }).?; try testing.expect(osc_red.eql(.{ .r = 255, .g = 0, .b = 0 })); pane.tty_filter = false; @@ -396,7 +396,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu // Dynamic default foreground/background colours key every default cell, // including the otherwise blank end of the row. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]10;#ff0000\x1b\\" ++ + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]10;#ff0000\x1b\\" ++ "\x1b]11;#5f5f5f\x1b\\" } }); const dyn_fg = of(pane.terminal.?).vt.colorForXterm(.{ .dynamic = .foreground }).?; const dyn_bg = of(pane.terminal.?).vt.colorForXterm(.{ .dynamic = .background }).?; @@ -410,7 +410,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu const explicit_before_reverse = dynamic.at(tx, body_y).style.fg; try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), explicit_before_reverse); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } }); _ = frame.reset(.retain_capacity); const reversed = try p.render(frame.allocator()); const reversed_blank = reversed.at(tx + r.w - config.GUTTER - 1, body_y + 2).style; @@ -421,7 +421,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu try testing.expectEqual(plain.Color{ .rgb = p.theme().bg.? }, reversed_explicit.fg); try testing.expect(!std.meta.eql(reversed_explicit.fg, reversed_explicit.bg)); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5l" } }); _ = frame.reset(.retain_capacity); const unreversed = try p.render(frame.allocator()); const unreversed_blank = unreversed.at(tx + r.w - config.GUTTER - 1, body_y + 2).style; @@ -430,7 +430,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu // The cache is keyed by values, not a theme name. Replacing a custom // theme in place immediately recolours already-rendered indexed cells. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]104;1\x1b\\" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]104;1\x1b\\" } }); var custom = p.theme().*; custom.name = try p.gpa.dupe(u8, "same-name"); custom.palette = null; @@ -482,7 +482,7 @@ test "terminal Filter preserves exact palette-null light theme default roles" { try testing.expectEqual(plain.Color{ .rgb = light.fg.? }, ordinary.at(tx, body_y).style.fg); try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, ordinary.at(tx, body_y).style.bg); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } }); _ = frame.reset(.retain_capacity); const reversed = try p.render(frame.allocator()); try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, reversed.at(tx, body_y).style.fg); @@ -514,7 +514,7 @@ test "terminal Filter maps the default roles before it maps anything else" { } p.settings.theme = 0; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]11;#5f5f5f\x1b\\" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]11;#5f5f5f\x1b\\" } }); var moved = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt); try testing.expect(!asGhostRgb(moved.default_bg).eql(asGhostRgb(moved.theme_bg))); try testing.expect(asGhostRgb(moved.default_bg).eql(keyedRgb(&moved, .{ .r = 0x5f, .g = 0x5f, .b = 0x5f }))); @@ -528,7 +528,7 @@ test "terminal Filter refuses a foreground that would collapse onto the page" { const pane = p.panes[0].?; try testing.expect(pane.tty_filter); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[38;2;255;255;255mW" ++ + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[38;2;255;255;255mW" ++ "\x1b[0;30mB" ++ "\x1b[0;31mR" } }); @@ -623,7 +623,7 @@ test "tty ansi colors follow the prompt hug into normal mode" { const pane = p.panes[0].?; pane.tty_filter = false; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32mPP\x1b]133;B\x1b\\\x1b[31mR\x1b[34mB\x1b[0m out" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32mPP\x1b]133;B\x1b\\\x1b[31mR\x1b[34mB\x1b[0m out" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -660,7 +660,7 @@ test "a prompt row hidden end to end paints nothing at all" { p.sync(); pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32maaaaaaaaa\x1b]133;B\x1b\\\x1b[41;36m\u{754C}\x1b[0m\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32maaaaaaaaa\x1b]133;B\x1b\\\x1b[41;36m\u{754C}\x1b[0m\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -686,9 +686,9 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t _ = try ptyWritesByPane(p, &out); p.view().active = 0; // Asking while its pane has the keyboard: told at once that it has. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1004h" } }); try std.testing.expectEqualStrings("0:\x1b[I\n", try ptyWritesByPane(p, &out)); - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?1004h" } }); try std.testing.expectEqualStrings("", try ptyWritesByPane(p, &out)); // A click into the other pane moves the keyboard: out of one, into the // other. @@ -724,7 +724,7 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an defer frame.deinit(); const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;5H" ++ kittyTransmit("c=2,r=1") } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3;5H" ++ kittyTransmit("c=2,r=1") } }); var s = try p.render(frame.allocator()); const places = imagePlaces(s); try std.testing.expectEqual(@as(usize, 1), places.len); @@ -740,20 +740,20 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an try std.testing.expectEqual(plain.RectPx{ .x = 0, .y = 0, .w = 20, .h = 20 }, place.at.?); // Scrolled up by the shell's output, it goes up with the text. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[24;1H\n\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[24;1H\n\n" } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].dst.y); - p.update(.{ .output = .{ .pane = 0, .bytes = "\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\n" } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b_Ga=d,d=A\x1b\\" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b_Ga=d,d=A\x1b\\" } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len); @@ -770,15 +770,15 @@ test "ED 3 takes away a kitty placement whose row it erased: it never comes back defer frame.deinit(); const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } }); const storage = &of(pane.terminal.?).vt.screens.active.kitty_images; try std.testing.expectEqual(@as(usize, 1), storage.placements.count()); // Scrolled into the history, it is not on screen; `clear` (ED 2 then // ED 3) erases that history and the placement with it. - p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(40) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(40) } }); var s = try p.render(frame.allocator()); try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[H\x1b[2J\x1b[3J" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[H\x1b[2J\x1b[3J" } }); try std.testing.expectEqual(@as(usize, 0), storage.placements.count()); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); @@ -791,7 +791,7 @@ test "a finished command's output erased by a later ED 3 is not called whole, an defer p.deinit(); const pane = p.panes[0].?; const marked = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - p.update(.{ .output = .{ .pane = 0, .bytes = marked ++ "\r\n\x1b]133;C;aid=pardes\x07printed\r\n\x1b]133;D;0;aid=pardes\x07" ++ marked } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = marked ++ "\r\n\x1b]133;C;aid=pardes\x07printed\r\n\x1b]133;D;0;aid=pardes\x07" ++ marked } }); const before = try commandOutput(pane.terminal, gpa, 100); defer gpa.free(before.text); try std.testing.expect(before.whole); @@ -799,8 +799,8 @@ test "a finished command's output erased by a later ED 3 is not called whole, an // The command's rows go into the history, and ED 3 erases them: its // pins are `garbage` now (ghostty 1.4), not moved to the screen's top, // where another program's text would be read as its output. - p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } }); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(20) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J" } }); const after = try commandOutput(pane.terminal, gpa, 100); defer gpa.free(after.text); try std.testing.expect(!after.whole); @@ -814,13 +814,13 @@ test "a selection whose row ED 3 erased goes; one on the screen stays" { defer p.deinit(); const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(20) } }); pane.body.mode = .normal; const pages = &of(pane.terminal.?).vt.screens.active.pages; const top: i32 = @intCast(pages.total_rows - pane.rows); const row: i32 = if (in_history) top - 3 else top + 2; pane.body.vsel = .{ .active = true, .row = row, .col = 1 }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J" } }); try std.testing.expectEqual(!in_history, pane.body.vsel.active); if (!in_history) try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.row); } @@ -840,7 +840,7 @@ test "a virtual kitty placement shows through its placeholder cells, which draw // yazi's way: a virtual placement two cells by one, then the two // placeholders, the image's id in their colour, row and column in // their diacritics. - p.update(.{ .output = .{ .pane = 0, .bytes = kittyTransmit("U=1,c=2,r=1,q=2") ++ + p.update(.{ .output = .{ .pane = .at(0), .bytes = kittyTransmit("U=1,c=2,r=1,q=2") ++ "\x1b[2;3H\x1b[38;2;0;0;7m\u{10EEEE}\u{0305}\u{0305}\u{10EEEE}\u{0305}\u{030D}\x1b[39mX" } }); const s = try p.render(frame.allocator()); const places = imagePlaces(s); @@ -864,7 +864,7 @@ test "a terminal's image is a placement whatever the frontend draws, and the Pet defer frame.deinit(); const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = kittyTransmit("c=2,r=1") } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = kittyTransmit("c=2,r=1") } }); const r = p.view().rects[0]; const tx = r.x + config.GUTTER; const y = p.bodyTop(pane, r); @@ -921,7 +921,7 @@ test "a program asking the cell size in pixels (CSI 16 t) is told the shell's" { var out: std.ArrayList(u8) = .empty; defer out.deinit(gpa); _ = try ptyWritesByPane(p, &out); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[16t" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[16t" } }); try std.testing.expectEqualStrings("0:\x1b[6;20;10t\n", try ptyWritesByPane(p, &out)); } @@ -960,7 +960,7 @@ test "a replica's terminal pane draws as its authority's does" { var line: [256]u8 = undefined; for (0..60) |i| { const bytes = try std.fmt.bufPrint(&line, "\x1b[1;3{d}m{d}\x1b[0m 漢字 e\u{301} \x1b[48;2;{d};40;60mbg\x1b[0m and then some text that wraps past the width of the pane\r\n", .{ i % 8, i, i * 4 % 256 }); - a.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + a.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); delta.clearRetainingCapacity(); try testing.expect(try encode(&enc, &tr, &peer, ta, @intCast(i + 1), "", &delta.writer)); peer.ack((try rep.apply(gpa, std.Io.Threaded.global_single_threaded.io(), tb, delta.written())).seq); -- cgit v1.3