diff options
56 files changed, 581 insertions, 581 deletions
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 <path>, unload <name> or reload <name>"; 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/<pid>/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 { /// `<file> deleted on disk (Save writes it again)`, logged `changed /// <serial> 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!<numeric-ip>!<port>, 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: /// <path>: 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(); |
