summaryrefslogtreecommitdiff
path: root/core/Core.zig
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/Core.zig
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/Core.zig')
-rw-r--r--core/Core.zig281
1 files changed, 149 insertions, 132 deletions
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();