summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
committerGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
commit0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (patch)
treef2e288668decded9276ebc45907f16d651b06f9e /core
parent2ab05b536bc3b063666b5aaab497157adc2a9120 (diff)
parentbf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (diff)
downloadpardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.tar.gz
pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.zip
integration: a pane's and a view's slot as types, with the regular-expression fixes and the fixes the real loops asked for: pardes-ids (Pane.Id and View.Id through the entries, the events, the effects, the Host table and the device messages) and pardes-merge21, merged without a textual conflict; one call site written since on the old type follows (core/draw.zig: the twin test's file_changed event, .pane = .at(0)); tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/Addon.zig16
-rw-r--r--core/Core.zig281
-rw-r--r--core/Db.zig2
-rw-r--r--core/Dir.zig10
-rw-r--r--core/Editor.zig2
-rw-r--r--core/Effect.zig98
-rw-r--r--core/Event.zig13
-rw-r--r--core/File.zig24
-rw-r--r--core/Handover.zig12
-rw-r--r--core/Jump.zig8
-rw-r--r--core/Kind.zig14
-rw-r--r--core/Messages.zig60
-rw-r--r--core/Output.zig6
-rw-r--r--core/Pipe.zig30
-rw-r--r--core/Plumb.zig12
-rw-r--r--core/Query.zig64
-rw-r--r--core/Store.zig6
-rw-r--r--core/Stream.zig4
-rw-r--r--core/builtins.zig124
-rw-r--r--core/colors.zig8
-rw-r--r--core/draw.zig8
-rw-r--r--core/dump.zig8
-rw-r--r--core/echo.zig4
-rw-r--r--core/edit.zig16
-rw-r--r--core/edit_cmd.zig46
-rw-r--r--core/exec.zig52
-rw-r--r--core/fs.zig8
-rw-r--r--core/hunks.zig8
-rw-r--r--core/keys.zig26
-rw-r--r--core/layout.zig4
-rw-r--r--core/look.zig58
-rw-r--r--core/lsp/Ask.zig20
-rw-r--r--core/mouse.zig28
-rw-r--r--core/ninep/ctl.zig70
-rw-r--r--core/ninep/events.zig22
-rw-r--r--core/ninep/pane.zig8
-rw-r--r--core/ninep/pty.zig42
-rw-r--r--core/ninep/screen.zig10
-rw-r--r--core/ninep/testing.zig6
-rw-r--r--core/normal.zig8
-rw-r--r--core/panes.zig53
-rw-r--r--core/replica.zig103
-rw-r--r--core/rollback.zig4
-rw-r--r--core/root.zig2
-rw-r--r--core/selection_pipe.zig4
-rw-r--r--core/tagline.zig16
-rw-r--r--core/tape.zig2
-rw-r--r--core/views.zig70
48 files changed, 775 insertions, 725 deletions
diff --git a/core/Addon.zig b/core/Addon.zig
index 54d1da00..ec2f796a 100644
--- a/core/Addon.zig
+++ b/core/Addon.zig
@@ -69,7 +69,7 @@ pub fn perform(p: *Pardes, op: Op, pane: u8, arg: []const u8) void {
var words: [64]LoadedWord = undefined;
var why: Why = .{};
const l = readLoaded(arg, &words, &why);
- p.update(.{ .addon = .{ .op = op, .pane = pane, .kind = &l } });
+ p.update(.{ .addon = .{ .op = op, .pane = .at(pane), .kind = &l } });
}
/// What a load reads off the library at `path` (held): the `addon`
@@ -734,7 +734,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);
@@ -745,23 +745,23 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void {
const dir = std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/");
const path = if (std.Io.Dir.path.isAbsolute(rest)) rest else std.fmt.bufPrint(&target, "{s}/{s}", .{ dir, rest }) catch return p.reportFailure(id, "Addon: that path is too long");
if (path.len > pardes.effect_path_cap) return p.reportFailure(id, "Addon: that path is too long");
- return p.emit(.{ .addon = .{ .op = .load, .pane = @intCast(id), .arg = .from(path) } });
+ return p.emit(.{ .addon = .{ .op = .load, .pane = .at(id), .arg = .from(path) } });
}
const k = p.kinds.byName(rest) orelse return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon {t}: no addon brought kind {s}", .{ op, rest }) catch takes);
const e = &p.kinds.kinds[k];
if (op == .reload and std.mem.eql(u8, e.path.slice(), "builtin")) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s} is built into this pardes", .{rest}) catch takes);
- if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = @intCast(id), .arg = .from(e.path.slice()) } });
+ if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = .at(id), .arg = .from(e.path.slice()) } });
const n = openPanes(p, rest);
if (n > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon unload: {d} {s} pane{s} open", .{ n, rest, if (n == 1) " is" else "s are" }) catch takes);
const hash = e.hash;
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 {
- p.emit(.{ .addon = .{ .op = .release, .pane = 0, .arg = .from(&hash) } });
+ p.emit(.{ .addon = .{ .op = .release, .pane = .at(0), .arg = .from(&hash) } });
}
pub fn openPanes(p: *const Pardes, name: []const u8) usize {
@@ -785,7 +785,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;
@@ -797,7 +797,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 d1cf1d94..d5a990e2 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -89,6 +89,21 @@ const Pardes = @This();
/// its focus, its pointer and gestures, its jumps, its key prefixes.
pub const View = struct {
pub const replica = .{ .len = .{ .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } } };
+ /// A view's slot in `Pardes.views`, as it crosses the core's edge: an
+ /// entry's argument or answer, the wire's welcome. A type of its own,
+ /// so a pane's slot (`Pane.Id`) is not taken for it; the core's own
+ /// view indexes (`live`, views.zig) keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `k`, a slot the core holds.
+ pub fn at(k: usize) Id {
+ return @fromBackingInt(@intCast(k));
+ }
+ /// The slot, to index the core's views with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
screen_w: u16 = 0,
screen_h: u16 = 0,
@@ -868,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;
}
@@ -885,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();
@@ -941,7 +956,7 @@ pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void {
if (p.pending_write[id] == null) {
while (off < bytes.len and p.effects_len < p.effects.len) {
const n = @min(bytes.len - off, effect_write_cap);
- p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(bytes[off .. off + n]) } });
+ p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(bytes[off .. off + n]) } });
off += n;
}
}
@@ -959,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;
}
@@ -979,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) {
@@ -997,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);
@@ -1014,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);
@@ -1022,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;
}
@@ -1030,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;
@@ -1057,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))
@@ -1146,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
@@ -1161,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
@@ -1181,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();
}
@@ -1190,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
@@ -1224,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;
@@ -1263,7 +1278,7 @@ fn refillPendingWrites(p: *Pardes) void {
// a copy's cursor and re-send the same chunk for ever.
const pw = if (slot.*) |*live| live else break;
const n = @min(pw.bytes.len - pw.off, effect_write_cap);
- p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } });
+ p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } });
pw.off += n;
p.pending_write_bytes -= n;
if (pw.off == pw.bytes.len) {
@@ -1309,48 +1324,48 @@ fn nextQueued(p: *Pardes) ?Event {
pub fn hostForegroundName(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 {
const f = p.host.vtable.fg_name orelse return null;
- return f(p.host.ctx, @intCast(id), buf);
+ return f(p.host.ctx, .at(id), buf);
}
pub fn hostTtyTaken(p: *const Pardes, id: usize) bool {
const f = p.host.vtable.tty_taken orelse return false;
- return f(p.host.ctx, @intCast(id));
+ return f(p.host.ctx, .at(id));
}
pub fn hostKillJob(p: *const Pardes, id: usize) bool {
const f = p.host.vtable.kill_job orelse return false;
- return f(p.host.ctx, @intCast(id));
+ return f(p.host.ctx, .at(id));
}
/// A terminal whose shell could not be started: said, and a run waiting
/// 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 {
@@ -1364,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`.
@@ -1391,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;
};
@@ -1401,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);
@@ -1428,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 {
@@ -1615,8 +1630,8 @@ fn updateInner(p: *Pardes, ev: Event) void {
const hover_stays = switch (ev) {
.tick, .search => true,
.mouse => |m| m.button == .none and m.kind == .motion,
- .output => |o| look.lookHoverPane(p) != o.pane,
- .file_changed => |changed| look.lookHoverPane(p) != changed.pane,
+ .output => |o| look.lookHoverPane(p) != o.pane.index(),
+ .file_changed => |changed| look.lookHoverPane(p) != changed.pane.index(),
else => false,
};
if (!hover_stays) {
@@ -1653,30 +1668,30 @@ fn updateInner(p: *Pardes, ev: Event) void {
p.resize_count += 1;
},
.output => |o| {
- const pane = p.panes[o.pane] orelse return;
+ const pane = p.panes[o.pane.index()] orelse return;
pane.shell_spoke = true;
- ctlfs.events.notePtyOutput(p, o.pane, o.bytes);
+ ctlfs.events.notePtyOutput(p, o.pane.index(), o.bytes);
pane.feedOutput(p, o.bytes);
- ctlfs.pty.noteMarks(p, o.pane, pane);
- exec.flushReplEnter(p, o.pane, true);
+ ctlfs.pty.noteMarks(p, o.pane.index(), pane);
+ exec.flushReplEnter(p, o.pane.index(), true);
},
- .exited => |e| if (p.panes[e.pane]) |pane| {
+ .exited => |e| if (p.panes[e.pane.index()]) |pane| {
if (pane.command == null)
ctlfs.pty.shellExited(p, pane, e.status)
else if (!pane.command_done)
- pane.commandDone(p, e.pane, e.status);
+ pane.commandDone(p, e.pane.index(), e.status);
},
- .eof => |e| if (p.panes[e.pane]) |pane| if (pane.command != null) {
+ .eof => |e| if (p.panes[e.pane.index()]) |pane| if (pane.command != null) {
// Output is over; the command is over when its child exits.
pane.command_pty = false;
- } else p.removePane(e.pane, null) catch |err| {
+ } else p.removePane(e.pane.index(), null) catch |err| {
pane.body.mode = .normal;
p.reportError(e.pane, "terminal exited; Del retries close", err);
},
.lsp_resp => |r| @import("lsp/Ask.zig").lspResponse(p, r.id, r.rows),
.pipe_resp => |r| Pipe.pipeResponse(p, r.id, r.success, r.outputs, r.failure),
.search => |b| Stream.receive(p, &b),
- .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane, fc.bytes),
+ .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane.index(), fc.bytes),
.key => |key| {
p.can_ask = true;
defer p.can_ask = false;
@@ -1686,16 +1701,16 @@ 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.*),
- .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes),
+ .addon => |a| pardes.Addon.landed(p, a.op, a.pane.index(), a.kind.*),
+ .job => |j| pardes.Kind.jobDone(p, j.pane.index(), j.serial, j.token, j.gen, j.bytes),
.frontend => |f| {
v.frontend = f;
},
@@ -1800,12 +1815,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);
@@ -1835,7 +1850,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.
@@ -1853,7 +1868,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();
@@ -1949,7 +1964,7 @@ pub fn sync(p: *Pardes) void {
if (pane.isTerminal()) {
pane.resizeGrid(cols, rows);
p.shell_rows.markStale(pane); // reflow moved every row
- p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } });
+ p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } });
pane.fs.winsize = null;
}
pane.cols = cols;
@@ -1976,7 +1991,7 @@ pub fn sync(p: *Pardes) void {
.wait => {},
.never => pane.greet = false,
.now => {
- p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = pane.cols, .rows = pane.rows } });
+ p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } });
p.emitWrite(id, "ls\r");
pane.greet = false;
},
@@ -2320,7 +2335,8 @@ const FakeTtyQuery = struct {
p.host = .{ .ctx = f, .vtable = &vtable };
}
- fn answer(ctx: ?*anyopaque, pane: u8) bool {
+ fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const f: *FakeTtyQuery = @ptrCast(@alignCast(ctx.?));
f.asked += 1;
return f.taken[pane];
@@ -2392,7 +2408,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].?;
@@ -2449,7 +2465,7 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" {
var sent_len: usize = 0;
while (p.nextEffect()) |effect| switch (effect) {
.write => |w| {
- try std.testing.expectEqual(@as(u8, 0), w.pane);
+ try std.testing.expectEqual(0, w.pane.index());
try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len);
@memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice());
sent_len += w.bytes.slice().len;
@@ -2622,7 +2638,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()) |_| {}
@@ -2660,7 +2676,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;
@@ -2671,7 +2687,7 @@ test "Term spawns a raw shell in the caller's directory" {
var found = false;
while (p.nextEffect()) |effect| switch (effect) {
- .spawn => |s| if (@as(usize, s.pane) == free) {
+ .spawn => |s| if (s.pane.index() == free) {
try std.testing.expectEqualStrings("/tmp/newtty-dir", s.cwd.slice());
found = true;
},
@@ -2695,11 +2711,11 @@ test "a terminal respawned into a closed pane's slot hangs the old shell up firs
var closed = false;
var spawned = false;
while (p.nextEffect()) |effect| switch (effect) {
- .close_pty => |c| if (c.pane == slot) {
+ .close_pty => |c| if (c.pane.index() == slot) {
try std.testing.expect(!spawned);
closed = true;
},
- .spawn => |s| if (s.pane == slot) {
+ .spawn => |s| if (s.pane.index() == slot) {
spawned = true;
},
else => {},
@@ -2758,10 +2774,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;
@@ -2771,7 +2787,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type
var spawned = false;
while (p.nextEffect()) |effect| switch (effect) {
.write => return error.TypedIntoATerminal,
- .spawn => |sp| if (sp.pane == dst) {
+ .spawn => |sp| if (sp.pane.index() == dst) {
try std.testing.expectEqualStrings("/tmp/pardes-image-dir", sp.cwd.slice());
spawned = true;
},
@@ -2787,7 +2803,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 = .{};
@@ -2802,7 +2818,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty
var spawned = false;
while (p.nextEffect()) |effect| switch (effect) {
.write => return error.WroteACommandLineIntoATerminal,
- .spawn => |sp| if (sp.pane == dst) {
+ .spawn => |sp| if (sp.pane.index() == dst) {
// ...in the directory the command was about, the taken pane's own
try std.testing.expectEqualStrings("/tmp/pardes-taken", sp.cwd.slice());
spawned = true;
@@ -2830,7 +2846,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 0 } });
+ p.update(.{ .exited = .{ .pane = .at(dst), .status = 0 } });
_ = exec.execute(p, 1, two);
while (p.nextEffect()) |_| {}
_ = try p.render(frame.allocator());
@@ -2850,7 +2866,8 @@ test "a spawn is for the pane it was made for, not whatever took the slot since"
var command: [32]u8 = undefined;
var core: *Pardes = undefined;
const vtable: Host.VTable = .{ .spawn = spawn };
- fn spawn(_: ?*anyopaque, pane: u8, _: []const u8) void {
+ fn spawn(_: ?*anyopaque, id: pardes.Pane.Id, _: []const u8) void {
+ const pane = id.index();
spawns += 1;
const line = core.panes[pane].?.command.?;
@memcpy(command[0..line.len], line);
@@ -2888,8 +2905,8 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
spawned = false;
while (pp.nextEffect()) |effect| switch (effect) {
.write => |w| {
- @memcpy(to[w.pane][len[w.pane]..][0..w.bytes.slice().len], w.bytes.slice());
- len[w.pane] += w.bytes.slice().len;
+ @memcpy(to[w.pane.index()][len[w.pane.index()]..][0..w.bytes.slice().len], w.bytes.slice());
+ len[w.pane.index()] += w.bytes.slice().len;
},
.spawn => spawned = true,
else => {},
@@ -2947,12 +2964,12 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expectEqualStrings("a = 1\rb = [201~2\r", Sent.said(1));
// Into a REPL that takes a bracketed paste (3.13's), the Enter waits
// for the REPL to answer the paste: read with it, it would be part of it.
- p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004h" } });
+ p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004h" } });
Sent.drain(p);
_ = exec.executeFrom(p, 0, "print(1)", true);
Sent.drain(p);
try std.testing.expectEqualStrings("\x1b[200~print(1)\x1b[201~", Sent.said(1));
- p.update(.{ .output = .{ .pane = 1, .bytes = "print(1)" } });
+ p.update(.{ .output = .{ .pane = .at(1), .bytes = "print(1)" } });
Sent.drain(p);
// Python's echo only restarts a short wait: the Enter goes once the
// echo of the whole paste has gone quiet.
@@ -2978,7 +2995,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
p.update(.tick);
Sent.drain(p);
try std.testing.expectEqualStrings("\r", Sent.said(1));
- p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004l" } });
+ p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004l" } });
Sent.len[1] = 0;
// A block left open by its indented last line gets the blank line that
// ends it: a second Enter.
@@ -3082,7 +3099,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
_ = try pardes.panes.newCommand(p, cmd, "", "python3");
try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python"));
try std.testing.expect(p.panes[cmd].?.repl != null);
- p.update(.{ .exited = .{ .pane = @intCast(cmd), .status = 0 } });
+ p.update(.{ .exited = .{ .pane = .at(cmd), .status = 0 } });
try std.testing.expect(p.panes[cmd].?.repl == null);
try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python"));
try std.testing.expect(p.panes[cmd].?.repl == null);
@@ -3097,7 +3114,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"));
@@ -3118,7 +3135,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 "));
}
@@ -3144,7 +3161,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
@@ -3171,7 +3188,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;
@@ -3190,32 +3207,32 @@ test "a command pane shows how its command ended, and the next command there run
const other = exec.execute(p, 1, "ls") orelse return error.NoCommandPane;
try std.testing.expect(other != dst);
while (p.nextEffect()) |_| {}
- p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "compiled\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(dst), .bytes = "compiled\r\n" } });
// Its exit comes first, a job it left still printing: done, and not
// the next command's until its pty closes.
- p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } });
+ p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } });
try std.testing.expect(pane.command_done and pane.command_pty);
const busy = exec.execute(p, 1, "true") orelse return error.NoCommandPane;
try std.testing.expect(busy != dst);
while (p.nextEffect()) |_| {}
// Its output ending: now it may be reused.
- p.update(.{ .eof = .{ .pane = @intCast(dst) } });
+ p.update(.{ .eof = .{ .pane = .at(dst) } });
try std.testing.expect(p.panes[dst] == pane and !pane.command_pty);
try std.testing.expect(p.panes[dst] == pane);
try std.testing.expect(pane.command_done);
try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) exit 2"));
// Kill leaves a finished one be.
try std.testing.expect(p.executeBuiltinLine(0, "Kill make"));
- while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) return error.SignalledAFinishedCommand;
+ while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) return error.SignalledAFinishedCommand;
// A program that crashed out of its full screen leaves the emulator
// in its modes; the next command starts clear of them.
- p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } });
+ p.update(.{ .output = .{ .pane = .at(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } });
try std.testing.expect(pardes.Term.modes(pane.terminal).bracketed_paste);
// Done, the directory's next command runs there, below what it showed.
try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "make test"));
try std.testing.expect(!pardes.Term.modes(pane.terminal).bracketed_paste);
var respawned = false;
- while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane == dst) {
+ while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane.index() == dst) {
respawned = true;
};
try std.testing.expect(respawned);
@@ -3229,7 +3246,7 @@ test "a command pane shows how its command ended, and the next command there run
// Kill stops a running one: its whole process group, SIGTERM.
try std.testing.expect(p.executeBuiltinLine(0, "Kill make"));
var signalled = false;
- while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) {
+ while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) {
try std.testing.expectEqual(PtySignal.term, effect.signal_pty.sig);
signalled = true;
};
@@ -3247,7 +3264,7 @@ test "a command pane shows how its command ended, and the next command there run
const Count = struct {
var signals: usize = 0;
const vtable: Host.VTable = .{ .pty_signal = signal };
- fn signal(_: ?*anyopaque, _: u8, _: PtySignal) void {
+ fn signal(_: ?*anyopaque, _: pardes.Pane.Id, _: PtySignal) void {
signals += 1;
}
};
@@ -3270,9 +3287,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;
@@ -3287,7 +3304,7 @@ test "a terminal its program gave back takes command lines again" {
var sent_len: usize = 0;
while (p.nextEffect()) |effect| switch (effect) {
.write => |w| {
- try std.testing.expectEqual(@as(u8, 0), w.pane);
+ try std.testing.expectEqual(0, w.pane.index());
try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len);
@memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice());
sent_len += w.bytes.slice().len;
@@ -3308,9 +3325,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' } });
@@ -3347,7 +3364,7 @@ test "a host with no methods at all is a complete in-process pardes" {
// the absent child is SILENT: the bytes are dropped, and nothing appears
// on the pane's screen to suggest a program answered
const before = pardes.Term.grid(p.panes[0].?.terminal).cursor_y;
- p.perform(.{ .write = .{ .pane = 0, .bytes = .from("ls\r") } });
+ p.perform(.{ .write = .{ .pane = .at(0), .bytes = .from("ls\r") } });
try std.testing.expectEqual(before, pardes.Term.grid(p.panes[0].?.terminal).cursor_y);
// the clipboard round-trips through the in-process one
@@ -3361,11 +3378,11 @@ test "a host with no methods at all is a complete in-process pardes" {
for (p.panes, 0..) |slot, i| if (slot == doc) {
doc_id = @intCast(i);
};
- p.perform(.{ .save_file = .{ .pane = doc_id } });
+ p.perform(.{ .save_file = .{ .pane = .at(doc_id) } });
try std.testing.expectEqualStrings("body\n", p.fallback.files.get(doc.file.?.path).?);
// a language backend nobody supplied answers nothing rather than hanging
- p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = doc_id, .offset = 0, .arg = .{} } });
+ p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = .at(doc_id), .offset = 0, .arg = .{} } });
p.perform(.quit);
try std.testing.expect(p.quit);
@@ -3762,7 +3779,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors"
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
pane.body.mode = .tty;
- p.update(.{ .output = .{ .pane = 0, .bytes = "abc" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "abc" } });
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const visible = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
@@ -3771,7 +3788,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors"
try std.testing.expectEqual(rect.x + config.GUTTER + 3, visible.x);
try std.testing.expectEqual(body_y, visible.y);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } });
try std.testing.expect((try p.render(frame.allocator())).cursor == null);
pane.body.mode = .normal;
pane.body.cur_pinned = true;
@@ -3787,13 +3804,13 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors"
pane.body.mode = .tty;
try std.testing.expect((try p.render(frame.allocator())).cursor == null);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } });
const alternate = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
try std.testing.expectEqual(rect.x + config.GUTTER + 4, alternate.x);
try std.testing.expectEqual(body_y + 1, alternate.y);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } });
try std.testing.expect((try p.render(frame.allocator())).cursor == null);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l\x1b[?25h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l\x1b[?25h" } });
const returned = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
try std.testing.expectEqual(visible.x, returned.x);
try std.testing.expectEqual(visible.y, returned.y);
@@ -3807,8 +3824,8 @@ test "raw terminal cursor follows its active row only while that row is visible"
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
pane.body.mode = .tty;
- for (0..60) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "row\r\n" } });
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;4H" } });
+ for (0..60) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "row\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3;4H" } });
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const live = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor;
@@ -3868,7 +3885,7 @@ test "tty output follows only from the bottom" {
for (0..60) |i| {
var buf: [32]u8 = undefined;
- p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
+ p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
}
p.sync();
const bottom = pardes.Term.grid(sp.terminal).offset;
@@ -3881,7 +3898,7 @@ test "tty output follows only from the bottom" {
try std.testing.expect(parked < bottom);
for (60..70) |i| {
var buf: [32]u8 = undefined;
- p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
+ p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
}
p.sync();
try std.testing.expectEqual(parked, pardes.Term.grid(sp.terminal).offset);
@@ -3893,7 +3910,7 @@ test "tty output follows only from the bottom" {
// ...and from there output follows again.
const live = pardes.Term.grid(sp.terminal).offset;
- p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = "tail\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(shell), .bytes = "tail\r\n" } });
p.sync();
try std.testing.expect(pardes.Term.grid(sp.terminal).offset > live);
}
@@ -3963,7 +3980,7 @@ test "a bracketed paste larger than the ring still closes its bracket" {
_ = test_api.ptyBytes(p, null, buf);
pardes.keys.enterTty(p, 0);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } });
try std.testing.expect(pardes.Term.modes(p.panes[0].?.terminal).bracketed_paste);
const text = try gpa.alloc(u8, 1536 * 1024);
defer gpa.free(text);
@@ -3994,7 +4011,7 @@ test "a terminal's answer to its program waits behind the paste still queued for
// host takes one write off, and the program asks where its cursor is.
const taken = p.nextEffect().?;
const off = if (taken == .write) taken.write.bytes.len else 0;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[6n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[6n" } });
const got = test_api.ptyBytes(p, null, buf);
// The whole paste first, then the answer, `CSI row ; col R`, whole.
try std.testing.expectEqualSlices(u8, text[off..], got[0 .. text.len - off]);
@@ -4034,7 +4051,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" {
// Exactly what an OSC 133 shell draws: prompt, then the marker that says
// the rest of this row is the user's, then what they typed. One grid row.
p.update(.{ .output = .{
- .pane = @intCast(shell),
+ .pane = .at(shell),
.bytes = "\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\grep -rn TODO src/",
} });
p.sync();
@@ -4078,7 +4095,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" {
// ...and a prompt with nothing typed at it yet is all chrome, so the whole
// row goes, which is what it has always done.
p.update(.{ .output = .{
- .pane = @intCast(shell),
+ .pane = .at(shell),
.bytes = "\r\n\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\",
} });
p.sync();
@@ -4096,7 +4113,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt"
const shell = p.view().active;
const sp = p.panes[shell].?;
p.update(.{ .output = .{
- .pane = @intCast(shell),
+ .pane = .at(shell),
.bytes = "\x1b]133;A;cl=line\x1b\\prompt> \x1b]133;B\x1b\\0123456789",
} });
p.sync();
diff --git a/core/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..7166294f 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -37,29 +37,29 @@ pub const Effect = union(enum) {
/// A child for the pane in slot `pane` -- the one whose serial is
/// `serial`: a pane closed and its slot taken before the effect is
/// performed is not the one it was for (perform).
- spawn: struct { pane: u8, serial: u32, cwd: Buf(effect_path_cap) },
- write: struct { pane: u8, bytes: Buf(effect_write_cap) },
- resize_pty: struct { pane: u8, cols: u16, rows: u16 },
+ spawn: struct { pane: Pane.Id, serial: u32, cwd: Buf(effect_path_cap) },
+ write: struct { pane: Pane.Id, bytes: Buf(effect_write_cap) },
+ resize_pty: struct { pane: Pane.Id, cols: u16, rows: u16 },
/// For the pane whose serial is `serial`, as `spawn` is (perform).
- signal_pty: struct { pane: u8, serial: u32, sig: PtySignal },
+ signal_pty: struct { pane: Pane.Id, serial: u32, sig: PtySignal },
/// The terminal pane in this slot is gone: the shell hangs up its pty
/// and ends the shell, rather than leave it running with nobody to read.
- close_pty: struct { pane: u8 },
+ close_pty: struct { pane: Pane.Id },
open_link: Buf(256),
/// A program a plumbing rule starts (Plumb.run): its directory, then
/// its argv, each ended by a NUL. A failure to start it is said at
/// pane `pane`.
- start: struct { pane: u8, line: Buf(effect_path_cap) },
+ start: struct { pane: Pane.Id, line: Buf(effect_path_cap) },
/// write this pane's file content to its path; the shell reads both off
/// the core (content is unbounded, effects are fixed-size values)
- save_file: struct { pane: u8 },
- save_text: struct { pane: u8, serial: u32, path: Buf(effect_path_cap), promote: bool = false },
+ save_file: struct { pane: Pane.Id },
+ save_text: struct { pane: Pane.Id, serial: u32, path: Buf(effect_path_cap), promote: bool = false },
write_dump,
set_clipboard,
read_clipboard,
/// `arg` up to 128 bytes, or for `explain` the query it explains,
/// `<kind> <arg>`.
- lsp: struct { id: u32, kind: lsp.Kind, pane: u8, offset: u32, arg: Buf(160) },
+ lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) },
/// Snapshot the matching request with pipeRequest(id), then run it away
/// from the UI/event loop and answer with pipe_resp.
pipe: struct { id: u32 },
@@ -71,19 +71,19 @@ pub const Effect = union(enum) {
hand_over: struct { seq: u32 },
/// Write what an Edit's `w` took (`Pipe.writes`), in order.
edit_write,
- watch: struct { pane: u8, on: bool, mode: WatchMode = .reconcile },
+ watch: struct { pane: Pane.Id, on: bool, mode: WatchMode = .reconcile },
theme_file: struct { generation: u32, on: bool },
/// Write the build-time theme ring below the per-user config directory.
/// The pane receives the completion/error message from the native host.
- dump_themes: struct { pane: u8 },
- detach: struct { pane: u8 },
+ dump_themes: struct { pane: Pane.Id },
+ detach: struct { pane: Pane.Id },
/// An addon loaded, let go, or let go and loaded again (Addon.zig):
/// `arg` its path, or for unload its kind's name. Answered by an
/// `addon` event.
- addon: struct { op: @import("Addon.zig").Op, pane: u8, arg: Buf(effect_path_cap) },
+ addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, arg: Buf(effect_path_cap) },
/// A kind's job for the host's workers (host_io.Job), answered by a
/// `job` event.
- job: struct { pane: u8, serial: u32, token: u32 },
+ job: struct { pane: Pane.Id, serial: u32, token: u32 },
quit,
pub fn Buf(comptime n: usize) type {
@@ -120,8 +120,8 @@ fn performInner(p: *Pardes, e: Effect) void {
switch (e) {
// The host reads the pane (its command, its shell) as it forks,
// so the slot must still hold the pane the spawn was for.
- .spawn => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane] orelse "") else s.cwd.slice()) else {
- p.fallback.spawned[s.pane] = true;
+ .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else {
+ p.fallback.spawned[s.pane.index()] = true;
},
// A pane with no child is silent: nothing invents output on its
// screen, and the bytes are dropped rather than transcribed.
@@ -129,7 +129,7 @@ fn performInner(p: *Pardes, e: Effect) void {
.resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows),
// A signal for a pane that closed, its slot retaken in the same
// step, would reach another pane's child.
- .signal_pty => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig),
+ .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig),
.close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane),
// The view's frontend opens it, yanks and pastes, on its own
// machine (View.yanks); the host here only for a view no client
@@ -149,17 +149,17 @@ fn performInner(p: *Pardes, e: Effect) void {
_ = words.next(); // its directory
const prog = words.next() orelse "";
var said: pardes.Kind.Buf(160) = .{};
- p.reportFailure(st.pane, said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w }));
+ p.reportFailure(st.pane.index(), said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w }));
},
.save_file => |sf| {
- const pane = p.panes[sf.pane] orelse return;
+ const pane = p.panes[sf.pane.index()] orelse return;
const f = if (pane.file) |*file| file else return;
const was = f.saved_revision;
f.saved_revision = f.revision;
// A save the host could not do (saveFailed) is its err
// record alone, not a `save`, and changes nothing: a clean
// file stays clean.
- const saved_pane = writeChecked(p, sf.pane, pane.serial, f.path, f.content, was) orelse return;
+ const saved_pane = writeChecked(p, sf.pane.index(), pane.serial, f.path, f.content, was) orelse return;
const saved = if (saved_pane.file) |*file| file else return;
// Edited while it was written: what is on disk is not this.
if (saved.saved_revision != saved.revision) return;
@@ -174,19 +174,19 @@ fn performInner(p: *Pardes, e: Effect) void {
p.emit(.{ .watch = .{ .pane = sf.pane, .on = true } });
},
.save_text => |st| {
- const pane = p.panes[st.pane] orelse return;
+ const pane = p.panes[st.pane.index()] orelse return;
if (pane.serial != st.serial) return; // a recycled slot: not ours
if (pane.file) |*f| {
// Failed, it changes nothing: not the name, not dirty.
- const after = writeChecked(p, st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return;
+ const after = writeChecked(p, st.pane.index(), st.serial, st.path.slice(), f.content, f.saved_revision) orelse return;
if (after.file == null) return;
- if (st.promote) promoteSaved(p, st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice());
+ if (st.promote) promoteSaved(p, st.pane.index(), st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice());
return;
}
if (!pane.isTerminal()) return;
const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err);
defer p.gpa.free(text);
- if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still|
+ if (writeChecked(p, st.pane.index(), st.serial, st.path.slice(), text, 0)) |still|
ctlfs.events.noteLogAs(p, .save, still, st.path.slice());
},
.write_dump => {
@@ -249,10 +249,10 @@ fn performInner(p: *Pardes, e: Effect) void {
},
.watch => |w| if (v.watch_file) |f| {
// What a watch is about: a real file, or a kind's (a PDF's).
- const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else "";
+ const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else "";
f(p.host.ctx, w.pane, path, w.on, w.mode);
} else {
- p.fallback.watched[w.pane] = w.on;
+ p.fallback.watched[w.pane.index()] = w.on;
},
.theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on),
.dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane),
@@ -263,8 +263,8 @@ fn performInner(p: *Pardes, e: Effect) void {
// dlopen is the same on every host, so none has a method of its
// own; a replica's core holds no library (what it brought comes in
// the event this taped).
- .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()),
- .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token),
+ .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()),
+ .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token),
// the loop's own condition; a host tears down after its own loop
.quit => p.endSession(),
}
@@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []
if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/");
// The in-process filesystem reports the same way a real host does,
// so an OOM there leaves the pane dirty rather than looking saved.
- if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(id, path, error.OutOfMemory);
+ if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory);
const pane = p.panes[id] orelse return null;
if (pane.serial != serial) return null;
if (p.fs.failures == failures) return pane;
@@ -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;
@@ -312,7 +312,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void {
ctlfs.events.noteLog(p, .save, pane);
p.recent.opened(p.recentGpa(), f.path);
if (filesystem.localPath(f.path) != null)
- p.emit(.{ .watch = .{ .pane = id, .on = true } });
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
}
fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 {
@@ -343,7 +343,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not
.detach => |d| break d,
else => {},
} else return error.NoDetachAsked;
- try std.testing.expectEqual(@as(u8, 0), asked.pane);
+ try std.testing.expectEqual(0, asked.pane.index());
p.perform(.{ .detach = asked });
const pane = p.panes[0].?;
@@ -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].?;
@@ -376,7 +376,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file
// The write asked for, the pane is the file once it is done.
var saved = false;
while (p.nextEffect()) |effect| {
- if (effect == .save_text and @as(usize, effect.save_text.pane) == id) saved = true;
+ if (effect == .save_text and effect.save_text.pane.index() == id) saved = true;
p.perform(effect);
}
try std.testing.expect(saved);
@@ -391,8 +391,8 @@ 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.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } });
+ p.setCwd(.at(0), "/tmp/pardes-tty-save");
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello scrollback\r\n" } });
while (p.nextEffect()) |_| {}
try std.testing.expect(p.executeBuiltinLine(0, "Save"));
@@ -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,8 +473,8 @@ 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.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } });
+ p.setCwd(.at(0), "/tmp/pardes-arg-save");
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "typed and gone\r\n" } });
while (p.nextEffect()) |_| {}
var buf: [256]u8 = undefined;
@@ -510,9 +510,9 @@ test "Save takes the path as an argument, relative to the pane's own directory"
test "a save the host could not do leaves the pane dirty" {
const gpa = std.testing.allocator;
const Refusing = struct {
- fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void {
+ fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void {
const core: *Pardes = @ptrCast(@alignCast(ctx.?));
- core.saveFailed(pane, "/x/y.txt", error.PermissionDenied);
+ core.saveFailed(id, "/x/y.txt", error.PermissionDenied);
}
};
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
@@ -576,8 +576,8 @@ 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.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } });
+ p.setCwd(.at(tty_id), "/tmp/pardes-batch");
+ p.update(.{ .output = .{ .pane = .at(tty_id), .bytes = "shell text\r\n" } });
const file = try p.setTestFile("file text\n");
const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane;
try std.testing.expect(shell.isTerminal());
@@ -606,7 +606,7 @@ test "a save whose pane is gone before the drain writes nothing" {
const doomed = p.freeSlot() orelse return error.NoPaneSlots;
const shell = try p.newShell(doomed, "/tmp/pardes-gone");
- p.update(.{ .output = .{ .pane = @intCast(doomed), .bytes = "doomed text\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(doomed), .bytes = "doomed text\r\n" } });
while (p.nextEffect()) |_| {}
try std.testing.expect(shell.isTerminal());
@@ -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].?;
@@ -687,19 +687,19 @@ test "a Save the host could not do logs no save record" {
const Failing = struct {
core: *Pardes,
const vtable: Host.VTable = .{ .write_file = write };
- fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void {
+ fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, _: []const u8) void {
const f: *@This() = @ptrCast(@alignCast(ctx.?));
- f.core.saveFailed(pane, path, error.AccessDenied);
+ f.core.saveFailed(id, path, error.AccessDenied);
}
};
var host: Failing = .{ .core = p };
p.host = .{ .ctx = &host, .vtable = &Failing.vtable };
_ = th.wr(p, ctlfs.Node.of(p.panes[0].?.serial, .body), "more\n");
- p.perform(.{ .save_file = .{ .pane = 0 } });
+ p.perform(.{ .save_file = .{ .pane = .at(0) } });
try std.testing.expect(!th.logHas(p, "\nsave "));
try std.testing.expect(p.panes[0].?.file.?.saved_revision != p.panes[0].?.file.?.revision);
// With the host's write done, it is logged.
p.host = .{};
- p.perform(.{ .save_file = .{ .pane = 0 } });
+ p.perform(.{ .save_file = .{ .pane = .at(0) } });
try std.testing.expect(th.logHas(p, "\nsave "));
}
diff --git a/core/Event.zig b/core/Event.zig
index faea73cc..9988eede 100644
--- a/core/Event.zig
+++ b/core/Event.zig
@@ -3,6 +3,7 @@
const config = @import("config.zig");
const selection_pipe = @import("selection_pipe.zig");
const Stream = @import("Stream.zig");
+const Pane = @import("panes.zig").Pane;
const Layer = @import("Layer.zig");
const RowMetrics = Layer.Metrics;
const TagHit = Layer.TagHit;
@@ -78,14 +79,14 @@ pub const Event = union(enum) {
cell_pixels: CellPixels = .{},
row_metrics: ?RowMetrics = null,
},
- output: struct { pane: u8, bytes: []const u8 },
+ output: struct { pane: Pane.Id, bytes: []const u8 },
/// The pane's pty reached end of file: its output is over. An
/// interactive terminal closes; a command pane waits for `exited`.
- eof: struct { pane: u8, status: ?u8 = null },
+ eof: struct { pane: Pane.Id, status: ?u8 = null },
/// A command pane's child exited, with this status (null: unknown). It
/// is the command's end, whatever still holds its pty (a job it left in
/// the background prints on until end of file).
- exited: struct { pane: u8, status: ?u8 },
+ exited: struct { pane: Pane.Id, status: ?u8 },
lsp_resp: struct { id: u32, rows: ?[]const u8 },
pipe_resp: struct {
id: u32,
@@ -93,7 +94,7 @@ pub const Event = union(enum) {
outputs: []const []const u8,
failure: ?selection_pipe.Failure = null,
},
- file_changed: struct { pane: u8, bytes: []const u8 },
+ file_changed: struct { pane: Pane.Id, bytes: []const u8 },
/// A disk search's batch (Stream.zig), borrowed for the step.
search: Stream.Batch,
paste: []const u8,
@@ -112,10 +113,10 @@ pub const Event = union(enum) {
frontend: Frontend,
/// What the host's `addon` effect read off a library, or why not
/// (Addon.landed). Borrowed for the step.
- addon: struct { op: @import("Addon.zig").Op, pane: u8, kind: *const @import("Kind.zig").Loaded },
+ addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, kind: *const @import("Kind.zig").Loaded },
/// A kind's job answered (host_io.Job), at its kind's generation then.
/// Borrowed for the step.
- job: struct { pane: u8, serial: u32, token: u32, gen: u32, bytes: []const u8 },
+ job: struct { pane: Pane.Id, serial: u32, token: u32, gen: u32, bytes: []const u8 },
tick,
};
diff --git a/core/File.zig b/core/File.zig
index c9ee6b71..020985da 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -581,13 +581,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
pane.body.cur_pinned = true;
pane.body.cur_row = @intCast(scroll);
p.installPane(id, pane);
- if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
return pane;
}
pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void {
if (file.output == null) for (p.panes, 0..) |slot, id| {
- if (slot == pane) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
+ if (slot == pane) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } });
};
// A twin's text, undo and shared index stay with the twins left.
var twins: [pardes.MAX_PANES]usize = undefined;
@@ -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].?;
@@ -991,7 +991,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane {
pane.body.cur_row = src.body.cur_row;
pane.body.cur_col = src.body.cur_col;
pane.body.cur_pinned = true;
- if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(to), .on = true } });
+ if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(to), .on = true } });
return pane;
}
@@ -1287,16 +1287,16 @@ 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;
f.saved_revision = if (snap.clean) f.revision else f.revision -% 1;
f.disk_newer = null;
f.disk_newer_warned = false;
- if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
}
pub fn restoreSnap(tab: u16, pane: *Pane, f: *State, snap: Text.Place) void {
@@ -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..66dbd2b6 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;
@@ -404,11 +404,11 @@ test "jump history terminal rectangle follows output and clears on reflow" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true });
defer p.deinit();
const pane = p.panes[0].?;
- p.update(.{ .output = .{ .pane = 0, .bytes = "alpha bravo\r\nsecond line\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha bravo\r\nsecond line\r\n" } });
pane.sel[0] = .{ .state = .done, .c0 = 0, .c1 = 4, .r0 = BOX_H, .r1 = BOX_H };
try edit.capturePointerSelection(p, pane, 0);
try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0]));
- for (0..40) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "more output\r\n" } });
+ for (0..40) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "more output\r\n" } });
try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0]));
pane.resizeGrid(pane.cols - 1, pane.rows);
try std.testing.expect(pane.pointerSelection(pane.sel[0]) == null);
diff --git a/core/Kind.zig b/core/Kind.zig
index 13ef8edd..7641c2d1 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -278,7 +278,7 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8)
_ = reopen(p, id, s, bytes);
// Its file watched, as a text's is: changed on disk, it opens again
// from it (fileChanged); retirePane lets the watch go.
- if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
return pane;
}
@@ -995,7 +995,7 @@ const Call = struct {
for (o.jobs) |token| if (token != 0) {
cl.slot.tokens = token;
};
- if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } });
+ if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = .at(cl.id), .serial = pane.serial, .token = token } });
for (o.cancels) |token| if (token != 0) {
for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) {
cl.slot.gpa.free(job.in);
@@ -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..aeebfc64 100644
--- a/core/Plumb.zig
+++ b/core/Plumb.zig
@@ -969,7 +969,7 @@ fn run(p: *Pardes, id: usize, wdir: []const u8, argv: []const []const u8) ?[]con
start.data[start.len + w.len] = 0;
start.len += @intCast(w.len + 1);
};
- p.emit(.{ .start = .{ .pane = @intCast(id), .line = start } });
+ p.emit(.{ .start = .{ .pane = .at(id), .line = start } });
return null;
}
@@ -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..dacc11a1 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;
@@ -1756,7 +1756,7 @@ fn promote(p: *Pardes, qid: usize, id: usize) void {
f.syntax_dirty = true;
pane.attached_to = null;
if (f.on_disk) p.recent.opened(p.recentGpa(), f.path);
- if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
pardes.ctlfs.events.noteLog(p, .rename, pane);
p.panes[qid].?.query.?.preview = 0;
}
@@ -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..6f37e86d 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -447,7 +447,7 @@ pub const Kill = struct {
// the marks say is running is the one signalled, not whatever
// runs by then.
if (command != null) {
- c.p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = .term } });
+ c.p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = .term } });
stopped = true;
} else if (c.p.hostKillJob(id)) stopped = true else jobless = true;
}
@@ -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);
}
};
@@ -537,7 +537,7 @@ pub const Detach = struct {
pub const scope: Scope = .session;
pub const enabled = pardes.can_attach;
pub fn run(c: Ctx) void {
- c.p.emit(.{ .detach = .{ .pane = @intCast(c.id) } });
+ c.p.emit(.{ .detach = .{ .pane = .at(c.id) } });
}
};
@@ -548,7 +548,7 @@ pub const Adopt = struct {
pub const enabled = pardes.can_attach;
pub fn run(c: Ctx) void {
const adopt = c.p.host.vtable.adopt orelse return c.p.reportFailure(c.id, "Adopt: no pardes daemon is keeping shells for this session");
- adopt(c.p.host.ctx, @intCast(c.id));
+ adopt(c.p.host.ctx, .at(c.id));
}
};
@@ -560,7 +560,7 @@ pub const Upgrade = struct {
pub const enabled = pardes.can_attach;
pub fn run(c: Ctx) void {
const upgrade = c.p.host.vtable.upgrade orelse return c.p.reportFailure(c.id, "Upgrade: this pardes cannot move to another build in place");
- upgrade(c.p.host.ctx, @intCast(c.id));
+ upgrade(c.p.host.ctx, .at(c.id));
}
};
@@ -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,10 +679,10 @@ 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) } });
+ c.p.emit(.{ .dump_themes = .{ .pane = .at(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);
}
};
@@ -2011,7 +2011,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
const term = p.view().active;
try std.testing.expect(p.panes[term].?.isTerminal());
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = prompt } });
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = prompt } });
while (p.nextEffect()) |_| {}
// The host the core asks: how many it was asked to stop, and whether
// their shells run jobs in groups of their own.
@@ -2019,7 +2019,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
var asked: usize = 0;
var job_control = true;
const vtable: pardes.Host.VTable = .{ .kill_job = answer };
- fn answer(_: ?*anyopaque, _: u8) bool {
+ fn answer(_: ?*anyopaque, _: pardes.Pane.Id) bool {
asked += 1;
return job_control;
}
@@ -2037,7 +2037,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
while (p.nextEffect()) |_| {}
// Typed but not started yet (no C mark): not running.
try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill"));
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;C;aid=pardes\x07" } });
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;C;aid=pardes\x07" } });
while (p.nextEffect()) |_| {}
try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill ls"));
try std.testing.expectEqual(@as(usize, 1), killed.count(p, "Kill ls make"));
@@ -2053,7 +2053,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
p.fs.failure_len = 0;
killed.job_control = true;
// Ended (a D mark): nothing to stop again.
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } });
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } });
while (p.nextEffect()) |_| {}
try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill"));
}
diff --git a/core/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 88011373..5ff31af6 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);
}
@@ -1412,7 +1412,7 @@ test "a frame changes nothing a step reads: a core drawing after every input and
8 => .{ .command = commands[random.uintLessThan(usize, commands.len)] },
9 => .{ .paste = "| new | row |\n" },
// The text changed on disk: a step changes it whole.
- 10 => .{ .file_changed = .{ .pane = 0, .bytes = text.items[0 .. text.items.len - random.uintLessThan(usize, 40)] } },
+ 10 => .{ .file_changed = .{ .pane = .at(0), .bytes = text.items[0 .. text.items.len - random.uintLessThan(usize, 40)] } },
else => blk: {
now += random.uintLessThan(u64, 2 * std.time.ns_per_s);
break :blk .tick;
diff --git a/core/dump.zig b/core/dump.zig
index 6f143daa..1616f557 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;
}
@@ -651,7 +651,7 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void {
/// the addon's).
fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void {
if (pane.addon) |slot| {
- if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
return reviveSlot(p, id, slot);
}
if (pane.terminal != null) {
@@ -690,11 +690,11 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
f.content = text;
} else |_| {}
}
- p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
- 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/echo.zig b/core/echo.zig
index 90dcfede..40200696 100644
--- a/core/echo.zig
+++ b/core/echo.zig
@@ -564,7 +564,7 @@ const Rig = struct {
written: std.ArrayListUnmanaged(u8) = .empty,
now: u64 = 1_000 * ms,
- fn ptyWrite(ctx: ?*anyopaque, _: u8, bytes: []const u8) void {
+ fn ptyWrite(ctx: ?*anyopaque, _: pardes.Pane.Id, bytes: []const u8) void {
const g: *Rig = @ptrCast(@alignCast(ctx.?));
g.written.appendSlice(testing.allocator, bytes) catch {};
}
@@ -601,7 +601,7 @@ const Rig = struct {
/// The shell prints `bytes`; the replica gets the unit and the delta.
fn prints(g: *Rig, bytes: []const u8) !void {
- g.a.output(.{ .output = .{ .pane = g.shell, .bytes = bytes } });
+ g.a.output(.{ .output = .{ .pane = .at(g.shell), .bytes = bytes } });
try g.sync();
}
diff --git a/core/edit.zig b/core/edit.zig
index d91620c4..0014f681 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 };
}
@@ -2352,7 +2352,7 @@ test "flat text replacement preserves a terminal fragment origin and direction"
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
defer p.deinit();
- p.update(.{ .output = .{ .pane = 0, .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } });
const pane = p.panes[0].?;
pane.body.mode = .normal;
pane.body.cur_pinned = true;
@@ -2487,7 +2487,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont
fn f(pp: *Pardes, o: *std.ArrayList(u8)) ![]const u8 {
o.clearRetainingCapacity();
while (pp.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice());
}
return o.items;
}
@@ -2496,7 +2496,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont
try std.testing.expectEqual(.tty, p.panes[0].?.body.mode);
p.update(.{ .paste = "echo a\nb\x03\tc" });
try std.testing.expectEqualStrings("echo a\rb \tc", try take(p, &out));
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } });
_ = try take(p, &out);
p.update(.{ .paste = "x\x1b[201~y\n" });
try std.testing.expectEqualStrings("\x1b[200~x [201~y\n\x1b[201~", try take(p, &out));
diff --git a/core/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..687faa98 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -322,21 +322,21 @@ pub fn saveFile(p: *Pardes, id: usize) void {
}
f.disk_newer = null;
}
- p.emit(.{ .save_file = .{ .pane = @intCast(id) } });
+ p.emit(.{ .save_file = .{ .pane = .at(id) } });
}
pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void {
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
@@ -347,7 +347,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void {
// Save that fails changes nothing, the name included.
if (f.output != null and panes.Output.fileTraits(f.output).saves) {
p.emit(.{ .save_text = .{
- .pane = @intCast(id),
+ .pane = .at(id),
.serial = pane.serial,
.path = Pardes.SavePath.from(full),
.promote = true,
@@ -361,7 +361,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void {
fn askWrite(p: *Pardes, id: usize, serial: u32, path: []const u8) void {
p.emit(.{ .save_text = .{
- .pane = @intCast(id),
+ .pane = .at(id),
.serial = serial,
.path = Pardes.SavePath.from(path),
} });
@@ -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..0a10825d 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -1132,13 +1132,13 @@ 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") } });
+ p.emit(.{ .save_text = .{ .pane = .at(0), .serial = pane.serial, .path = .from("/n/peer/pending") } });
try std.testing.expectError(error.MountInUse, unmount(p, "peer"));
while (p.nextEffect()) |_| {}
try unmount(p, "peer");
@@ -1317,7 +1317,7 @@ test "bounded reads release terminal snapshots after success and size refusal" {
const empty = try readLimit(p, path, 0);
defer gpa.free(empty);
try std.testing.expectEqual(@as(usize, 0), empty.len);
- p.update(.{ .output = .{ .pane = 0, .bytes = "limited terminal output" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "limited terminal output" } });
const expected = "limited terminal output\n"; // a line ends with its newline
const bytes = try readLimit(p, path, expected.len);
defer gpa.free(bytes);
diff --git a/core/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..92e78b0e 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;
@@ -543,7 +543,7 @@ test "Esc back into a tty leaves its view at the prompt" {
// rides the view down and leaves that pin far up in the scrollback.
for (0..60) |i| {
var buf: [32]u8 = undefined;
- p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
+ p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } });
}
p.sync();
const live = pardes.Term.grid(sp.terminal).offset;
diff --git a/core/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..f7084079 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
@@ -1923,7 +1923,7 @@ test "Look hover waits without mutating the pane and input cancels it" {
// Background traffic in another pane does not change the text or geometry
// under this pointer and must not strand a stationary hover unarmed.
- p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(other_id), .bytes = "busy\r\n" } });
try std.testing.expect(p.look_hover_preview != null);
const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1;
@@ -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);
}
@@ -2504,9 +2504,9 @@ test "LookNext in a command pane walks its own file:line places, whoever walked
while (p.nextEffect()) |_| {}
const dst = exec.execute(p, 0, "make") orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
- p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } });
- p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } });
- p.update(.{ .eof = .{ .pane = @intCast(dst) } });
+ p.update(.{ .output = .{ .pane = .at(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } });
+ p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } });
+ p.update(.{ .eof = .{ .pane = .at(dst) } });
const cmd = p.panes[dst].?;
// A walk last made elsewhere, and another pane with places in it.
try std.testing.expect(p.executeBuiltinLine(0, "New"));
@@ -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..376b093d 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -113,7 +113,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
p.emit(.{ .lsp = .{
.id = p.lsp_ask.seq,
.kind = kind,
- .pane = @intCast(id),
+ .pane = .at(id),
.offset = @intCast(at),
.arg = .from(sent),
} });
@@ -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}));
@@ -445,7 +445,7 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place,
try std.testing.expectEqual(lsp.Kind.explain, e.lsp.kind);
try std.testing.expectEqualStrings("hover ", e.lsp.arg.slice());
try std.testing.expectEqual(hover_at, e.lsp.offset);
- try std.testing.expectEqual(@as(u8, 0), e.lsp.pane);
+ try std.testing.expectEqual(0, e.lsp.pane.index());
seen = true;
};
try std.testing.expect(seen);
diff --git a/core/mouse.zig b/core/mouse.zig
index 5707cb57..3d7c5af9 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) {
@@ -1580,17 +1580,17 @@ test "a wheel over a program that owns it is the program's, in the form it asked
.{ .modes = "\x1b[?1007l", .button = .wheel_up, .sent = "" },
};
for (cases) |case| {
- p.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
p.update(.{ .mouse = .{ .button = case.button, .kind = .press, .col = col, .row = row, .ctrl = case.ctrl, .alt = case.alt, .shift = case.shift } });
try std.testing.expectEqualStrings(case.sent, pardes.test_api.ptyBytes(p, 0, &out));
}
// A shell on the main screen: the wheel scrolls its scrollback, and
// the shell hears nothing.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1l\x1b[?1049l" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1l\x1b[?1049l" } });
for (0..40) |i| {
var line: [16]u8 = undefined;
- p.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
}
_ = try p.render(frame.allocator());
_ = pardes.test_api.ptyBytes(p, 0, &out);
@@ -1600,7 +1600,7 @@ test "a wheel over a program that owns it is the program's, in the form it asked
try std.testing.expect(pane.scroll() != was);
// A program tracking the mouse on the main screen: Shift and the
// wheel scroll the scrollback, the program hears nothing.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1000h\x1b[?1006h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1000h\x1b[?1006h" } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
const tracked = pane.scroll();
p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = col, .row = row, .shift = true } });
@@ -1671,7 +1671,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
}
}.f;
// htop's modes: clicks in SGR, a release its own `m`.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
try std.testing.expect(p.view().drag == .none);
@@ -1713,7 +1713,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
// codex's any-event tracking: a drag once per cell, carried past the
// grid's edge and clamped there, and bare moves.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003h" } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[<35;9;4M", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 }));
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 }));
@@ -1737,7 +1737,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
// Legacy X10 bytes: a release is button 3. (Turning 1003 off turns
// tracking off, as xterm's one tracking mode goes.)
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[M &$", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
try std.testing.expectEqualStrings("\x1b[M#&$", try send(p, &out, col, row, .{ .button = .left, .kind = .release }));
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index a4f16597..302b916a 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -228,7 +228,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep
}
if (p.panes[id] == null) return Reply.fail(req.tag, E.NOENT);
defer if (scratch) |s| if (v.active != s) if (p.panes[s]) |sp| if (sp.file) |f| {
- if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(s, "exec", err);
+ if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(.at(s), "exec", err);
};
p.fs.ran_at = p.panes[id].?.serial;
p.fs.no_pane_slot = false;
@@ -724,7 +724,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM
/// The editor's step: the text of /pager opens closed unread goes in.
pub fn fillClosedPagers(p: *Pardes) void {
for (p.fs.pages.items) |*page| {
- fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(id, "pager", err);
+ fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(.at(id), "pager", err);
page.bytes.deinit(p.gpa);
}
p.fs.pages.clearRetainingCapacity();
@@ -1252,7 +1252,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 {
if (listed) |content| panes.Output.openUnsaved(p, id, content);
var notice: pardes.Kind.Buf(64) = .{};
p.fs.unlogged = true;
- p.setMessage(id, notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word}));
+ p.setMessage(.at(id), notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word}));
p.fs.unlogged = false;
return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch &p.fs.ename; // cut to ename's 320
}
@@ -1282,7 +1282,7 @@ pub fn getFile(p: *Pardes, pane: *Pane, path: []const u8) GetError!void {
f.disk_newer_warned = false;
f.disk_gone = false;
f.on_disk = fs.localPath(path) != null;
- if (f.on_disk) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ if (f.on_disk) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
}
/// What Get and Edit's `e` fail with, as their callers say it (the 9P
@@ -1500,7 +1500,7 @@ test "a body write to a terminal is typed input, not a paste, even to a program
const term = for (p.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break id;
} else return error.SkipZigTest;
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b[?2004h" } });
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b[?2004h" } });
while (p.nextEffect()) |_| {}
const w = wr(p, Node.of(p.panes[term].?.serial, .body), "ls\n");
try testing.expectEqual(Status.ok, w.reply.status);
@@ -1513,7 +1513,7 @@ test "Save path of a file pane logs a save record naming that path" {
const serial = serialOf(p);
const saved = wr(p, Node.of(serial, .ctl), "Save /tmp/pardes-save-copy.txt\n");
try testing.expectEqual(Status.ok, saved.reply.status);
- p.perform(.{ .save_text = .{ .pane = 0, .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } });
+ p.perform(.{ .save_text = .{ .pane = .at(0), .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } });
var want: [64]u8 = undefined;
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "save {d} /tmp/pardes-save-copy.txt\n", .{serial})));
}
@@ -1590,7 +1590,7 @@ test "exec Save writes the named file through the host" {
const saved = wr(p, Node.of(serial, .exec), "Save\n");
try testing.expectEqual(Status.ok, saved.reply.status);
try testing.expect(saved.saved);
- p.perform(.{ .save_file = .{ .pane = 0 } });
+ p.perform(.{ .save_file = .{ .pane = .at(0) } });
try testing.expect(!pane_files.dirtyOf(pane));
try testing.expectEqualStrings(pane.file.?.content, p.fallback.get("/tmp/renamed.txt").?);
}
@@ -1638,7 +1638,7 @@ test "a builtin's Verbose announcement is logged only when it succeeds, its fail
var save_buf: [64]u8 = undefined;
const said_save = try std.fmt.bufPrint(&save_buf, "msg {d} Save\n", .{serial});
_ = wr(p, Node.of(serial, .exec), "Save\n");
- p.saveFailed(@intCast(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied);
+ p.saveFailed(.at(p.paneBySerial(serial).?), "/test.txt", error.AccessDenied);
try testing.expect(!th.logHas(p, said_save));
// One that does what it says keeps its announcement.
_ = wr(p, Node.of(serial, .exec), "Undo\n");
@@ -1902,7 +1902,7 @@ test "Term in a directory that is not there fails and makes no pane; a shell tha
_ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n");
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Term\n").reply.status);
const term = p.view().active;
- p.shellFailed(@intCast(term), error.FileNotFound);
+ p.shellFailed(.at(term), error.FileNotFound);
const run_node = Node.of(p.panes[term].?.serial, .pty_run);
const h = call(p, .{ .tag = 1, .op = .open, .node = run_node, .omode = 2 }).reply.handle;
_ = call(p, .{ .tag = 2, .op = .write, .node = run_node, .handle = h, .data = "true\n" });
@@ -1982,17 +1982,17 @@ test "a terminal told the directory it already goes by logs no rename" {
p.update(.tick); // announced
const term = p.view().active;
// The host says where its shell started: where it was already named.
- p.setCwd(term, "/tmp");
+ p.setCwd(.at(term), "/tmp");
var rec: [32]u8 = undefined;
try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial})));
// This process's directory, asked before the shell has said anything
// (so before its chdir): not taken.
const session = p.sessionDir();
- p.setCwd(term, session);
+ p.setCwd(.at(term), session);
try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial})));
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "$ " } });
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = "$ " } });
// Somewhere else is a rename.
- p.setCwd(term, "/usr");
+ p.setCwd(.at(term), "/usr");
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial})));
}
@@ -2000,14 +2000,14 @@ test "a terminal with text typed at its prompt is never typed into: a look at it
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const term = p.paneBySerial(serialOf(p)).?;
- p.setCwd(term, "/tmp");
- p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } });
+ p.setCwd(.at(term), "/tmp");
+ p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } });
while (p.nextEffect()) |_| {}
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.look), "/tmp\n").reply.status);
var typed_into = false;
- while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) {
+ while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) {
typed_into = true;
};
try testing.expect(!typed_into);
@@ -2016,7 +2016,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it
try testing.expectEqual(count + 1, after);
// An exec at it runs in a pane of its own, not typed after TYPED.
_ = wr(p, Node.of(serialOf(p), .exec), "echo hi\n");
- while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) {
+ while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) {
typed_into = true;
};
try testing.expect(!typed_into);
@@ -2042,7 +2042,7 @@ test "a command line from a missing directory fails ENOENT and makes no pane; a
_ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n");
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "echo hi\n").reply.status);
const cmd = p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, Node.of(serial, .exec), 0, 64).bytes, "\n"), 10)).?;
- p.shellFailed(@intCast(cmd), error.FileNotFound);
+ p.shellFailed(.at(cmd), error.FileNotFound);
const pane = p.panes[cmd].?;
try testing.expect(pane.command_done);
try testing.expectEqual(@as(?u8, 127), pane.command_status);
@@ -2057,13 +2057,13 @@ test "pty/ctl exec in a directory that is gone fails ENOENT; a shell that cannot
p.host = .{ .vtable = &th.starting };
defer p.host = .{};
const serial = serialOf(p);
- p.setCwd(p.paneBySerial(serial).?, "/tmp/pardes-no-such-dir-zz");
+ p.setCwd(.at(p.paneBySerial(serial).?), "/tmp/pardes-no-such-dir-zz");
const refused = wr(p, Node.of(serial, .pty_ctl), "exec\n");
try testing.expectEqual(E.NOENT, refused.errno());
try testing.expectStringStartsWith(refused.reply.ename, "exec: /tmp/pardes-no-such-dir-zz: no such directory");
// The host's own failure is the waiting write's (late_failure).
p.fs.late_failure_len = 0;
- p.shellFailed(@intCast(p.paneBySerial(serial).?), error.AccessDenied);
+ p.shellFailed(.at(p.paneBySerial(serial).?), error.AccessDenied);
try testing.expectEqualStrings("shell: permission denied", p.fs.late_failure[0..p.fs.late_failure_len]);
}
@@ -2095,14 +2095,14 @@ test "a script whose interpreter is not there: Term refuses it up front, only an
// one goes.
const id = p.paneBySerial(serial).?;
p.panes[id].?.shell = try p.gpa.dupe(u8, try std.fmt.bufPrint(&line, "{s}/bad", .{dir}));
- p.setCwd(id, dir);
+ p.setCwd(.at(id), dir);
const exec_refused = wr(p, Node.of(serial, .pty_ctl), "exec\n");
try testing.expectEqual(E.NOENT, exec_refused.errno());
try testing.expectEqualStrings("exec: interpreter /no/such/interp not found", exec_refused.reply.ename);
// One the host found could not start (the script changed after): said
// with the interpreter's name, and the running shell is not gone.
p.fs.late_failure_len = 0;
- p.restartFailed(@intCast(id), error.InterpreterNotFound);
+ p.restartFailed(.at(id), error.InterpreterNotFound);
try testing.expectEqualStrings("shell: interpreter /no/such/interp not found", p.fs.late_failure[0..p.fs.late_failure_len]);
try testing.expect(!p.panes[id].?.shell_failed);
}
@@ -2163,7 +2163,7 @@ test "a buffer whose file was deleted on disk is dirty, and Del asks first" {
defer p.deinit();
const serial = serialOf(p);
try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n"));
- pardes.panes.File.deleted(p, @intCast(p.paneBySerial(serial).?));
+ pardes.panes.File.deleted(p, .at(p.paneBySerial(serial).?));
try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n"));
try testing.expectEqual(Status.err, wr(p, Node.of(serial, .ctl), "Del\n").reply.status);
try testing.expect(p.paneBySerial(serial) != null);
@@ -2176,7 +2176,7 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.fs.write_waits = true;
- p.saveFailed(@intCast(p.view().active), "/nowhere/zz.txt", error.FileNotFound);
+ p.saveFailed(.at(p.view().active), "/nowhere/zz.txt", error.FileNotFound);
p.fs.write_waits = false;
try testing.expect(!th.logHas(p, "msg "));
try testing.expect(p.fs.late_failure_len > 0);
@@ -2260,8 +2260,8 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as
};
try testing.expectEqual(@as(usize, 2), n);
p.view().active = shells[0];
- p.update(.{ .output = .{ .pane = @intCast(shells[0]), .bytes = "\x1b[?1004h" } });
- p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } });
+ p.update(.{ .output = .{ .pane = .at(shells[0]), .bytes = "\x1b[?1004h" } });
+ p.update(.{ .output = .{ .pane = .at(shells[1]), .bytes = "\x1b[?1004h" } });
while (p.nextEffect()) |_| {}
var digits: [16]u8 = undefined;
const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
@@ -2304,7 +2304,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const term = p.paneBySerial(serialOf(p)).?;
- p.setCwd(term, "/tmp/two\nlines\x07\x7f\xc2\x85\xff");
+ p.setCwd(.at(term), "/tmp/two\nlines\x07\x7f\xc2\x85\xff");
const index = rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes;
// Each byte as itself, so the name decodes to what it is.
try testing.expect(std.mem.indexOf(u8, index, "/tmp/two\\nlines\\x07\\x7f\\xc2\\x85\\xff ") != null);
@@ -2344,7 +2344,7 @@ test "a new file saved shows in /recent, open, while it is" {
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
// A host that writes files, as the real ones do.
const Writing = struct {
- fn write(_: ?*anyopaque, _: u8, path: []const u8, bytes: []const u8) void {
+ fn write(_: ?*anyopaque, _: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
std.Io.Dir.cwd().writeFile(testing.io, .{ .sub_path = path, .data = bytes }) catch {};
}
};
@@ -2357,7 +2357,7 @@ test "a new file saved shows in /recent, open, while it is" {
_ = wr(p, Node.of(made, .name), try std.fmt.bufPrint(&name, "{s}\n", .{path}));
_ = wr(p, Node.of(made, .body), "fresh\n");
try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Save\n").reply.status);
- p.perform(.{ .save_file = .{ .pane = @intCast(p.paneBySerial(made).?) } });
+ p.perform(.{ .save_file = .{ .pane = .at(p.paneBySerial(made).?) } });
var want: [4300]u8 = undefined;
try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null);
}
@@ -2561,8 +2561,8 @@ test "get names the path it could not read, logs the edits it threw away, and a
var want: [512]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "get: {s}: no such file", .{path}), missing.reply.ename);
// Deleted on disk: said once.
- pardes.panes.File.deleted(p, 0);
- pardes.panes.File.deleted(p, 0);
+ pardes.panes.File.deleted(p, .at(0));
+ pardes.panes.File.deleted(p, .at(0));
var rec: [32]u8 = undefined;
const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
@@ -2575,7 +2575,7 @@ test "a word written to a raw terminal's look is listed as in normal mode" {
defer p.deinit();
const serial = serialOf(p);
const id = p.paneBySerial(serial).?;
- p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one MARK two\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(id), .bytes = "one MARK two\r\n" } });
p.panes[id].?.body.mode = .tty;
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), "MARK\n").reply.status);
const said = std.mem.trimEnd(u8, rd(p, Node.of(serial, .look), 0, 64).bytes, "\n");
@@ -2588,7 +2588,7 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select
defer p.deinit();
const serial = serialOf(p);
const id = p.paneBySerial(serial).?;
- p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one\r\ntwo MARK three\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(id), .bytes = "one\r\ntwo MARK three\r\n" } });
const pane = p.panes[id].?;
const root = @backingInt(tree.TopFile.look);
var line: [64]u8 = undefined;
@@ -2712,10 +2712,10 @@ test "a Save whose directory is missing because one above refuses says permissio
defer p.deinit();
// The refusing directory is Linux's /proc/1/root.
if (comptime @import("builtin").os.tag == .linux) {
- p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound);
+ p.saveFailed(.at(0), "/proc/1/root/x/f.txt", error.FileNotFound);
try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied"));
}
- p.saveFailed(0, "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound);
+ p.saveFailed(.at(0), "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound);
try testing.expect(th.logHas(p, "no such directory"));
}
diff --git a/core/ninep/events.zig b/core/ninep/events.zig
index 1e740345..93a1187a 100644
--- a/core/ninep/events.zig
+++ b/core/ninep/events.zig
@@ -1180,7 +1180,7 @@ test "the log records whether or not anyone reads, and an open that follows wait
);
// What the editor says is in the same stream, one line even when the
// message had several.
- p.setMessage(id, "save: two\nlines");
+ p.setMessage(.at(id), "save: two\nlines");
try testing.expectEqualStrings(
try std.fmt.bufPrint(&expected, "msg {d} save: two lines\n", .{serial}),
rdf.next(p, log, fh, frozen).bytes,
@@ -1198,7 +1198,7 @@ test "the log records whether or not anyone reads, and an open that follows wait
// pieces rather than failing. A repeat the follower waits on, having
// read the first, is its own line.
const said_by = p.panes[0].?.serial;
- p.setMessage(0, "same failure");
+ p.setMessage(.at(0), "same failure");
var pieced: [64]u8 = undefined;
var got: usize = 0;
while (got == 0 or pieced[got - 1] != '\n') {
@@ -1207,14 +1207,14 @@ test "the log records whether or not anyone reads, and an open that follows wait
got += piece.len;
}
try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure\n", .{said_by}), pieced[0..got]);
- p.setMessage(0, "same failure");
+ p.setMessage(.at(0), "same failure");
try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "msg {d} same failure (x2)\n", .{said_by}), rdf.next(p, log, fh, frozen).bytes);
// A follower the ring outran hears how much it missed, then carries on.
var filler: [200]u8 = @splat('x');
for (0..p.fs.log.cap / filler.len + 8) |i| {
_ = std.fmt.bufPrint(&filler, "{d:0>6}", .{i}) catch unreachable; // a repeat would collapse
- p.setMessage(0, &filler);
+ p.setMessage(.at(0), &filler);
}
const lost = rdf.next(p, log, fh, frozen).bytes;
try testing.expect(std.mem.startsWith(u8, lost, "lost "));
@@ -1226,7 +1226,7 @@ test "the log records whether or not anyone reads, and an open that follows wait
// everything else pushed out ahead of it.
p.fs.log.cap = 128;
var huge: [300]u8 = @splat('y');
- p.setMessage(0, &huge);
+ p.setMessage(.at(0), &huge);
const cut = call(p, .{ .tag = 11, .op = .open, .node = log });
const kept = call(p, .{ .tag = 12, .op = .read, .node = log, .handle = cut.reply.handle, .size = 512 }).bytes;
try testing.expectEqual(@as(usize, 124), kept.len);
@@ -1328,7 +1328,7 @@ test "a pane named before it is announced has its new under that name, and no re
const shell = try p.newShell(free, "");
try testing.expectEqualStrings(p.sessionDir(), pane_files.nameOf(p, shell));
announce(p);
- p.setCwd(free, p.sessionDir());
+ p.setCwd(.at(free), p.sessionDir());
const after = try freezeLog(p);
defer p.gpa.free(after.bytes);
try testing.expect(std.mem.indexOf(u8, after.bytes, try std.fmt.bufPrint(&want, "rename {d} ", .{shell.serial})) == null);
@@ -1427,12 +1427,12 @@ test "follow new skips what the log held and waits for what comes after" {
defer p.deinit();
p.update(.tick); // the pane's `new` is logged first
while (p.nextEffect()) |_| {}
- p.setMessage(0, "before the open");
+ p.setMessage(.at(0), "before the open");
const log = @backingInt(tree.TopFile.log);
const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = log, .handle = h, .data = "follow new\n" }).reply.status);
try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = log, .handle = h, .size = 4096 }).reply.status);
- p.setMessage(0, "after it");
+ p.setMessage(.at(0), "after it");
try testing.expect(std.mem.endsWith(u8, call(p, .{ .tag = 4, .op = .read, .node = log, .handle = h, .size = 4096 }).bytes, " after it\n"));
_ = call(p, .{ .tag = 5, .op = .release, .node = log, .handle = h });
}
@@ -1482,10 +1482,10 @@ test "two failures that agree only in what their records cut are two records, no
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const long = std.mem.asBytes(&@as([80][4]u8, @splat("why ".*)));
- p.setMessage(0, long ++ "first");
- p.setMessage(0, long ++ "second");
+ p.setMessage(.at(0), long ++ "first");
+ p.setMessage(.at(0), long ++ "second");
try testing.expect(!th.logHas(p, "(x2)"));
- p.setMessage(0, long ++ "second");
+ p.setMessage(.at(0), long ++ "second");
try testing.expect(th.logHas(p, "(x2)"));
}
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index 96a50703..8be26602 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -693,7 +693,7 @@ pub fn applyTagTruncation(p: *Pardes, pane: *Pane) void {
pf.tag_trunc_pending = false;
// An edit like a keyboard one: `u` in the tag brings it back.
pane.tag.remember(p.gpa, if (pane.tag.own) |own| .{ .text = own } else null) catch |err|
- return p.reportError(p.paneBySerial(pane.serial) orelse return, "tag", err);
+ return p.reportError(.at(p.paneBySerial(pane.serial) orelse return), "tag", err);
const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked
if (pane.tag.own) |own| p.gpa.free(own);
pane.tag.own = empty;
@@ -941,7 +941,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) !
f.context.revision = null;
pane.geometry_key = 0;
look.invalidateLookHover(p, id);
- p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = false } });
events.noteLog(p, .rename, pane);
// A name given: whether a file there is on disk is the disk's to say.
f.on_disk = f.output == null and pardes.Pardes.recentKeeps(p.tape, f.path);
@@ -1065,7 +1065,7 @@ test "a terminal's body stats as long as it reads" {
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
try testing.expect(pane.isTerminal());
- p.update(.{ .output = .{ .pane = 0, .bytes = "$ ls\r\nalpha beta\r\n$ " } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "$ ls\r\nalpha beta\r\n$ " } });
const body = Node.of(pane.serial, .body);
const whole = rd(p, body, 0, 1 << 16);
try testing.expect(whole.bytes.len > 0);
@@ -1198,7 +1198,7 @@ test "a long path's failed Save keeps its reason" {
const id = p.paneBySerial(serial).?;
try nameBuffer(p, id, long, false);
p.fs.late_failure_len = 0;
- p.saveFailed(@intCast(id), long, error.AccessDenied);
+ p.saveFailed(.at(id), long, error.AccessDenied);
const late = p.fs.late_failure[0..p.fs.late_failure_len];
try testing.expect(std.mem.startsWith(u8, late, "Save /tmp/nonexistent-pardes-root/"));
try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory"));
diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig
index 0fd75aa2..6f3a8af0 100644
--- a/core/ninep/pty.zig
+++ b/core/ninep/pty.zig
@@ -96,14 +96,14 @@ fn verb(p: *Pardes, id: usize, line: []const u8, apply: bool) ?[]const u8 {
// is refused, never quietly raised.
if (rows < pty_rows_min) return e_winsize_rows;
if (!apply) return null;
- p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } });
+ p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } });
pane.fs.winsize = .{ cols, rows };
},
.sig => {
const which = signalNamed(words.next() orelse return e_bad_pty_ctl) orelse return e_bad_pty_ctl;
if (words.next() != null) return e_bad_pty_ctl;
if (!apply) return null;
- p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = which } });
+ p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = which } });
},
.exec => {
if (words.next() != null) return e_bad_pty_ctl;
@@ -656,7 +656,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" {
const ctl = Node.of(pane.serial, .pty_ctl);
var path: [1025]u8 = @splat('d');
path[0] = '/';
- p.setCwd(0, &path);
+ p.setCwd(.at(0), &path);
for ([_][]const u8{ "exec\n", "winsize 100 30\nexec\n", "sig TERM\nexec\n" }) |command| {
const result = wr(p, ctl, command);
try testing.expectEqual(E.INVAL, result.errno());
@@ -664,7 +664,7 @@ test "owned cwd pty exec rejects long paths before applying its batch" {
try testing.expect(result.signal == null and result.winsize == null);
}
try testing.expectEqualStrings(&path, pane.cwdSlice());
- p.setCwd(0, path[0..pardes.effect_path_cap]);
+ p.setCwd(.at(0), path[0..pardes.effect_path_cap]);
const accepted = wr(p, ctl, "exec\n");
try testing.expectEqual(Status.ok, accepted.reply.status);
try testing.expect(accepted.spawned);
@@ -709,7 +709,7 @@ test "pty/data writes at the shell and reads the raw stream" {
try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status);
- p.update(.{ .output = .{ .pane = 0, .bytes = "unwatched" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "unwatched" } });
while (p.nextEffect()) |_| {}
try testing.expectEqual(@as(usize, 0), p.panes[0].?.fs.pty_out.buf.items.len);
try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status);
@@ -724,20 +724,20 @@ test "pty/data writes at the shell and reads the raw stream" {
try testing.expectEqual(@as(u16, 0), p.fs.listeners);
try testing.expect(p.panes[0].?.fs.readers == 0);
- p.update(.{ .output = .{ .pane = 0, .bytes = "hello" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello" } });
while (p.nextEffect()) |_| {}
try testing.expectEqualStrings("hello", rd(p, data, 0, 64).bytes);
try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status);
- p.update(.{ .output = .{ .pane = 0, .bytes = "abcdef" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "abcdef" } });
while (p.nextEffect()) |_| {}
try testing.expectEqualStrings("ab", rd(p, data, 0, 2).bytes);
try testing.expectEqualStrings("cd", rd(p, data, 0, 2).bytes);
- p.update(.{ .output = .{ .pane = 0, .bytes = "ghi" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "ghi" } });
while (p.nextEffect()) |_| {}
try testing.expectEqualStrings("efghi", rd(p, data, 0, 64).bytes);
- p.update(.{ .output = .{ .pane = 0, .bytes = "orphan" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "orphan" } });
while (p.nextEffect()) |_| {}
_ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = reader.reply.handle });
try testing.expect(!p.panes[0].?.fs.pty_reader);
@@ -750,7 +750,7 @@ test "pty/data writes at the shell and reads the raw stream" {
try testing.expectEqual(Status.err, second.reply.status);
try testing.expectEqualStrings(tree.e_in_use, second.reply.ename);
try testing.expect(p.panes[0].?.fs.pty_reader);
- p.update(.{ .output = .{ .pane = 0, .bytes = "still" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "still" } });
while (p.nextEffect()) |_| {}
try testing.expectEqualStrings("still", rd(p, data, 0, 64).bytes);
}
@@ -765,7 +765,7 @@ test "a run waiting for a new terminal's first prompt is the only line typed the
const node = Node.of(serialOf(p), .pty_run);
const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle;
_ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" });
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } });
var sent: [32]u8 = undefined;
var len: usize = 0;
while (p.nextEffect()) |e| if (e == .write) {
@@ -783,7 +783,7 @@ test "run answers how its command ended once the shell is back at a prompt" {
const node = Node.of(serialOf(p), .pty_run);
const out = struct {
fn put(pp: *Pardes, bytes: []const u8) void {
- pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } });
+ pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } });
while (pp.nextEffect()) |_| {}
}
};
@@ -799,9 +799,9 @@ test "run answers how its command ended once the shell is back at a prompt" {
try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status);
try testing.expect(std.mem.endsWith(u8, rd(p, status, 0, 64).bytes, " 1\n"));
// A respawn before that prompt keeps it waiting for the new shell's.
- p.acknowledgeShell(0, "/bin/sh", true);
+ p.acknowledgeShell(.at(0), "/bin/sh", true);
try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status);
- p.update(.{ .output = .{ .pane = 0, .bytes = prompt } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } });
var sent_late: [16]u8 = undefined;
var sent_len: usize = 0;
while (p.nextEffect()) |e| if (e == .write) {
@@ -909,7 +909,7 @@ test "a shell that exits under a run answers its status, and the log says exit b
const serial = serialOf(p);
const node = Node.of(serial, .pty_run);
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
- p.update(.{ .output = .{ .pane = 0, .bytes = prompt } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } });
while (p.nextEffect()) |_| {}
const log = @backingInt(tree.TopFile.log);
const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
@@ -918,9 +918,9 @@ test "a shell that exits under a run answers its status, and the log says exit b
const r = call(p, .{ .tag = 4, .op = .open, .node = node });
_ = call(p, .{ .tag = 5, .op = .write, .node = node, .handle = r.reply.handle, .data = "echo bye; exit 3\n" });
- p.update(.{ .output = .{ .pane = 0, .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } });
- p.update(.{ .exited = .{ .pane = 0, .status = 3 } });
- p.update(.{ .eof = .{ .pane = 0 } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } });
+ p.update(.{ .exited = .{ .pane = .at(0), .status = 3 } });
+ p.update(.{ .eof = .{ .pane = .at(0) } });
while (p.nextEffect()) |_| {}
try testing.expect(p.paneBySerial(serial) == null);
try testing.expectEqualStrings("exit 3\nbye\n", call(p, .{ .tag = 6, .op = .read, .node = node, .handle = r.reply.handle, .size = 64 }).bytes);
@@ -969,7 +969,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound
const pane = p.panes[0].?;
const sh = struct {
fn put(pp: *Pardes, bytes: []const u8) void {
- pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } });
+ pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } });
while (pp.nextEffect()) |_| {}
}
fn send(pp: *Pardes, n: u64) u32 {
@@ -1099,7 +1099,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l
const p = try withTerm(gpa);
defer p.deinit();
const serial = serialOf(p);
- p.update(.{ .output = .{ .pane = 0, .bytes = "some history\r\nmore" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "some history\r\nmore" } });
while (p.nextEffect()) |_| {}
const opened = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .body) });
const body_len = call(p, .{ .tag = 2, .op = .read, .node = Node.of(serial, .body), .handle = opened.reply.handle, .size = 1 << 16 }).bytes.len;
@@ -1114,7 +1114,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l
const f = call(p, .{ .tag = 4, .op = .open, .node = log }).reply.handle;
const frozen = call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .size = 1 << 16 }).bytes.len;
_ = call(p, .{ .tag = 6, .op = .write, .node = log, .handle = f, .data = "follow" });
- p.setCwd(0, "/somewhere/else");
+ p.setCwd(.at(0), "/somewhere/else");
var want: [64]u8 = undefined;
try testing.expectEqualStrings(
try std.fmt.bufPrint(&want, "rename {d} /somewhere/else\n", .{serial}),
diff --git a/core/ninep/screen.zig b/core/ninep/screen.zig
index cd3c73b6..1e2791b1 100644
--- a/core/ninep/screen.zig
+++ b/core/ninep/screen.zig
@@ -124,7 +124,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" {
const p = try withTerm(gpa);
defer p.deinit();
const node = Node.of(serialOf(p), .body);
- p.update(.{ .output = .{ .pane = 0, .bytes = "old caf\xc3\xa9\r\nold tail" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "old caf\xc3\xa9\r\nold tail" } });
while (p.nextEffect()) |_| {}
const original = try pardes.Term.scrollback(p.panes[0].?.terminal, gpa);
defer gpa.free(original);
@@ -132,7 +132,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" {
try testing.expectEqual(Status.ok, opened.reply.status);
const first = call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 3 });
try testing.expectEqualStrings(original[0..3], first.bytes);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } });
while (p.nextEffect()) |_| {}
var offset: usize = 3;
while (offset < original.len) {
@@ -154,7 +154,7 @@ test "an empty terminal body snapshot stays empty while output continues" {
const opened = call(p, .{ .tag = 1, .op = .open, .node = node });
try testing.expectEqualStrings("", call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes);
try testing.expect(p.fs.opens[opened.reply.handle - 1].what.snapshot != null);
- p.update(.{ .output = .{ .pane = 0, .bytes = "new output" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "new output" } });
while (p.nextEffect()) |_| {}
try testing.expectEqualStrings("", call(p, .{ .tag = 3, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes);
_ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = opened.reply.handle });
@@ -182,7 +182,7 @@ test "terminal body snapshots are lazy bounded and released after the pane close
const scratch = try th.newPane(p);
const scratch_id = p.paneBySerial(scratch).?;
try testing.expect(p.panes[scratch_id].?.file != null);
- p.update(.{ .output = .{ .pane = 0, .bytes = "latest output" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "latest output" } });
while (p.nextEffect()) |_| {}
var failing = std.testing.FailingAllocator.init(gpa, .{ .fail_index = 0 });
p.gpa = failing.allocator();
@@ -298,7 +298,7 @@ test "a terminal's body is its logical lines: a row the terminal wrapped is join
const pane = p.panes[0].?;
const long = &@as([50]u8, @splat('w')) ++ &@as([150]u8, @splat('x')); // wider than the pane: it wraps
try testing.expect(long.len > pane.cols);
- p.update(.{ .output = .{ .pane = 0, .bytes = long ++ "\r\nnext" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = long ++ "\r\nnext" } });
while (p.nextEffect()) |_| {}
const node = Node.of(pane.serial, .body);
const body = th.rd(p, node, 0, 4096).bytes;
diff --git a/core/ninep/testing.zig b/core/ninep/testing.zig
index 23a9199f..cf75d80d 100644
--- a/core/ninep/testing.zig
+++ b/core/ninep/testing.zig
@@ -153,15 +153,15 @@ pub fn nameAt(list: []const Dirent, want: []const u8) ?Dirent {
/// none.
pub const starting: pardes.Host.VTable = .{ .spawn = startNothing };
-fn startNothing(_: ?*anyopaque, _: u8, _: []const u8) void {}
+fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {}
pub const FakeTty = struct {
taken: bool,
pub const vtable: pardes.Host.VTable = .{ .tty_taken = answer };
- fn answer(ctx: ?*anyopaque, pane: u8) bool {
- _ = pane;
+ fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ _ = id;
const f: *FakeTty = @ptrCast(@alignCast(ctx.?));
return f.taken;
}
diff --git a/core/normal.zig b/core/normal.zig
index ef7618b8..ae6c2d18 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -356,7 +356,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);
@@ -598,7 +598,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;
@@ -621,7 +621,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;
@@ -636,7 +636,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 cdc28dba..b928917a 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -38,6 +38,21 @@ pub const Pane = struct {
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
};
+ /// A pane's slot in `Pardes.panes`, as it crosses the core's edge: an
+ /// entry's argument or answer, an event's, an effect's, a host call's.
+ /// A type of its own, so a view's slot (`View.Id`) is not taken for
+ /// it; the core's own loops and tables keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `i`, a slot the core holds.
+ pub fn at(i: usize) Id {
+ return @fromBackingInt(@intCast(i));
+ }
+ /// The slot, to index the core's tables with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
@@ -701,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
@@ -713,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();
}
@@ -1063,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
@@ -1177,8 +1192,8 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void {
if (pane.file) |*file| panes.File.leaveTwins(p, file);
const watched = (if (pane.file) |f| f.output == null else false) or (if (pane.addon) |k| k.path.len > 0 else false);
for (p.panes, 0..) |slot, id| if (slot == pane) {
- if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
- if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = @intCast(id) } });
+ if (watched) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } });
+ if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = .at(id) } });
// Its pty's end and its emulator are the authority's: a replica's
// speculation that closes a terminal waits for it.
if (pane.terminal != null) tape.poison("close a terminal");
@@ -1279,7 +1294,7 @@ pub fn emitSpawn(p: *Pardes, id: usize, serial: u32, cwd: []const u8) void {
if (p.spawn_dirs[id]) |old| p.gpa.free(old);
p.spawn_dirs[id] = null;
if (cwd.len > effect_path_cap) p.spawn_dirs[id] = p.gpa.dupe(u8, cwd) catch null;
- p.emit(.{ .spawn = .{ .pane = @intCast(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } });
+ p.emit(.{ .spawn = .{ .pane = .at(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } });
}
/// A command pane: a terminal whose child is `$SHELL -c line` rather
@@ -1335,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);
}
@@ -1514,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) {
@@ -1569,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();
@@ -1594,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);
@@ -1663,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].? };
@@ -1691,14 +1706,14 @@ 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].?;
p.sync();
while (p.nextEffect()) |_| {}
allocator.fail_index = allocator.alloc_index;
- p.update(.{ .eof = .{ .pane = 0 } });
+ p.update(.{ .eof = .{ .pane = .at(0) } });
try std.testing.expectEqual(parent, p.panes[0].?);
try std.testing.expectEqual(parent, child.cwd.inherited);
try std.testing.expectEqual(Text.Mode.normal, parent.body.mode);
@@ -1785,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"));
@@ -1799,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 e2775da8..c68848f2 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;
@@ -2278,13 +2278,13 @@ pub const Peers = struct {
if (ps.next_id == 0) ps.next_id = 1;
// The session's digest as dumped, for the joiner to check its load by.
const digest = tape.digestOf(core);
- peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
+ peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
if (ps.threads and (peer.writer == null or peer.reader == null)) {
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.
@@ -2591,7 +2591,7 @@ fn joinOn(gpa: Allocator, fd: c_int, session: []const u8, why: []u8, have: ?*Hav
.welcome => |w| {
r.j.pid = w.pid;
r.j.client = w.client;
- r.j.view = w.view;
+ r.j.view = w.view.index();
r.j.gmtoff = w.gmtoff;
r.j.digest = w.digest;
r.j.semantics = w.semantics;
@@ -3299,7 +3299,7 @@ const TestHost = struct {
/// A host with ptys whose pump polls for a frame, as a client's does.
const PtyHost = struct {
- fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {}
+ fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {}
fn poll(_: ?*anyopaque) void {}
const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll };
fn host() pardes.Host {
@@ -3736,7 +3736,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
for (0..3) |round| {
// The shell prints: its unit rolls the replica back and applies the
// key again; then its delta lands, under the new copy.
- for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } });
+ for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } });
r.confirm((try a.pending()).?);
r.settle();
try std.testing.expect(r.copy.held);
@@ -3758,7 +3758,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
r.confirm(try a.local(.{ .focus = false }));
_ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?);
try key(r, 'x', &sent);
- for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } });
+ for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -3882,7 +3882,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
// History the replica holds as holes, of lines a narrow grid wraps in
// two, which a wider one unwraps.
var line: [96]u8 = undefined;
- for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } });
+ for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } });
r.confirm((try a.pending()).?);
// Out of terminal mode in the session's view, which sizes it; then a
// client's own view (a copy of it), wider: its first key sizes the
@@ -3923,7 +3923,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();
@@ -3961,7 +3961,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
a.core.view().active = shell;
r.confirm(try a.local(.{ .focus = true }));
var line: [64]u8 = undefined;
- for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } });
+ for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
try deliver(a, &screens, peer, r, .flush);
r.settle();
@@ -3984,7 +3984,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
// The shell prints while they wait: its unit, then its delta, which
// sets the view the authority's (at the bottom still): what was applied
// goes on top of it again.
- for (0..5) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } });
+ for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -4050,7 +4050,7 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca
a.core.view().active = shell;
r.confirm(try a.local(.{ .focus = true }));
var line: [96]u8 = undefined;
- for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } });
+ for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } });
r.confirm((try a.pending()).?);
try deliver(a, &screens, peer, r, .flush);
// Out of the shell's tty mode, in the session's view: keys over its text.
@@ -4068,8 +4068,8 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca
r.settle();
}
// The program redraws the screen: other rows where those keys read.
- a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[H\x1b[2J" } });
- for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } });
+ for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
try deliver(a, &screens, peer, r, .flush);
@@ -4181,7 +4181,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &zon } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &zon } });
const r = try joinedNow(a, 1, 0);
defer r.deinit();
try std.testing.expectEqual(digestOf(a), r.digest());
@@ -4256,9 +4256,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;
@@ -4577,7 +4577,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
@@ -4587,7 +4587,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.
@@ -4614,13 +4614,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);
@@ -4710,7 +4710,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli
} else return error.NoShell;
a.core.view().active = shell;
var line: [64]u8 = undefined;
- for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
+ for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
const out = try gpa.dupe(u8, (try a.pending()).?);
defer gpa.free(out);
for ([_]*Replica{ r1, r2 }) |r| r.confirm(out);
@@ -4740,7 +4740,7 @@ test "a replica with no code for a kind whose state is not plain shows its pane
// replica's core takes the kind's words, never its code.
var words: [64]pardes.Kind.LoadedWord = undefined;
const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } }));
r.confirm(try a.local(.{ .command = "Counter" }));
try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null);
try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client"));
@@ -4798,7 +4798,7 @@ test "a kind's place moved in a step of another view's: a replica's key that rea
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }));
// The replica's view opens the kind's pane, and an Esc goes back to
// the file (Last): view 0 has the file.
const own = try a.openView(1);
@@ -4852,7 +4852,7 @@ test "a client joined from a dump numbers a kind's next job as the session does"
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &jobber } });
_ = try a.local(.{ .command = "Jobber" });
for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } });
const id = a.core.view().active;
@@ -4871,7 +4871,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }));
// Its replica has no code for the kind: the open's outcome (its place,
// `1:0 0`) is the authority's to say.
const msg = try gpa.dupe(u8, try r.input(.{ .command = "Placed" }));
@@ -4890,7 +4890,7 @@ test "a client joined from a dump tells a kind each view's facts as the session
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } });
_ = try a.local(.{ .command = "Placed" });
// A message in its pane: a band over its body, in each view.
_ = try a.local(.{ .command = "Placed x" });
@@ -4944,7 +4944,8 @@ const Asker = struct {
const BusyHost = struct {
var core: ?*Pardes = null;
var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity };
- fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+ fn job(_: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never);
}
fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void {
@@ -4962,7 +4963,7 @@ test "a kind's job answered at once inside its host's call (no worker free) is t
defer r.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words);
- r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } }));
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &asker } }));
// The client has its code (as a library of its own found by its scan).
r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops;
r.confirm(try a.local(.{ .command = "Asker" }));
@@ -4988,7 +4989,7 @@ test "a closed terminal with a kitty image brought back on a client: its image d
} else return error.NoShell;
// A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA
// of its own (TerminalImages.converted).
- a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } });
r.confirm((try a.pending()).?);
// Closed and brought back: the client loads the session's dump of it,
// its image with it.
@@ -5041,7 +5042,7 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b
defer a.deinit();
var words: [64]pardes.Kind.LoadedWord = undefined;
const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } });
_ = try a.local(.{ .command = "Counter" });
// Joined from the dump: the kind's pane is a line here (no code), its
// slot the dump's.
@@ -5099,7 +5100,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;
@@ -5108,7 +5109,7 @@ const SeenHost = struct {
of(ctx).linked += 1;
}
fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {}
- fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {}
+ fn watchFile(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: bool, _: pardes.WatchMode) void {}
const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile };
fn host(h: *SeenHost) pardes.Host {
return .{ .ctx = h, .vtable = &vtable };
@@ -5263,7 +5264,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re
const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd)));
var words: [64]pardes.Kind.LoadedWord = undefined;
const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } });
// The kind's pane, its +Search (a place a row, as a kind's `/` leaves
// it), and a scratch whose words name files in the session's directory
// (as a command's output would).
@@ -5570,14 +5571,14 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell'
if (slot) |pane| if (pane.isTerminal()) break id;
} else null;
if (shell) |id| {
- a.output(.{ .output = .{ .pane = @intCast(id), .bytes = "\x1b[?1004h$ " } });
+ a.output(.{ .output = .{ .pane = .at(id), .bytes = "\x1b[?1004h$ " } });
_ = (try a.pending()).?;
}
_ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/mise.toml", .{dir}) });
const file = a.core.view().active;
var words: [64]pardes.Kind.LoadedWord = undefined;
const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words);
- _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } });
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } });
_ = try a.local(.{ .command = "Still" });
const kind = a.core.view().active;
try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null);
@@ -5677,7 +5678,7 @@ test "a far client's click into a shell whose program asked for focus events is
const Told = struct {
var bytes: [64]u8 = undefined;
var len: usize = 0;
- fn write(_: ?*anyopaque, _: u8, b: []const u8) void {
+ fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void {
@memcpy(bytes[len..][0..b.len], b);
len += b.len;
}
@@ -5689,7 +5690,7 @@ test "a far client's click into a shell whose program asked for focus events is
const shell: u8 = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
} else return error.NoShell;
- a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[?1004h$ " } });
+ a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } });
_ = (try a.pending()).?;
_ = try a.local(.{ .command = "New" });
var screens: Screens = .init(gpa);
diff --git a/core/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/root.zig b/core/root.zig
index 2e8fe1dc..69ec3ded 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -221,7 +221,7 @@ pub const test_api = if (@import("builtin").is_test) struct {
var n: usize = 0;
while (p.nextEffect()) |effect| switch (effect) {
.write => |w| {
- if (pane != null and w.pane != pane.?) continue;
+ if (pane != null and w.pane.index() != pane.?) continue;
const b = w.bytes.slice();
if (n + b.len > buf.len) break;
@memcpy(buf[n..][0..b.len], b);
diff --git a/core/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 9d627a17..9985288d 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);
@@ -859,10 +859,10 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" {
defer out.deinit(gpa);
for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i});
try out.appendSlice(gpa, "LAST$ ");
- p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } });
+ p.update(.{ .output = .{ .pane = .at(id), .bytes = out.items } });
// Sized for the tall view, it fits there whole: nothing is passed over.
try testing.expectEqual(@as(u16, 0), term.pan);
- p.toView(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,5 +923,21 @@ 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" {
+ // An enum coerces into nothing but itself (an enum literal into it, it
+ // into a union of it): two distinct enum types never stand for each
+ // other, so `p.toView(pane_id)` or `p.setMessage(view_id, ..)` does not
+ // compile. What is left to show is that they are two, and a byte each.
+ comptime {
+ std.debug.assert(Pane.Id != View.Id);
+ for (.{ Pane.Id, View.Id }) |T| {
+ const e = @typeInfo(T).@"enum";
+ std.debug.assert(e.tag_type == u8 and e.mode == .nonexhaustive and @sizeOf(T) == 1);
+ }
+ }
+ for (0..MAX_PANES) |i| try testing.expectEqual(i, Pane.Id.at(i).index());
+ for (0..max) |k| try testing.expectEqual(k, View.Id.at(k).index());
}