summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 18:35:16 -0300
committerGabriel Schneider <[email protected]>2026-11-19 20:24:14 -0300
commitbf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (patch)
treeed415f31749669a36d5df304af4101f56e9fdd23 /dev
parent78d94c4a62ec3f4039a475b637ff6a60649fde52 (diff)
downloadpardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.tar.gz
pardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.zip
core, dev: what carries a slot across the core's edge carries its type (P21, pardes-ids change 3): `Pane.Id` in Event's six variants that carry a pane (output, eof, exited, file_changed, addon, job), in the fourteen effects that do (spawn, write, resize_pty, signal_pty, close_pty, start, save_file, save_text, lsp, watch, dump_themes, detach, addon, job), in the fourteen Host functions that take one (dev/Host.zig: adopt, upgrade, spawn, pty_write, pty_resize, pty_signal, close_pty, tty_taken, fg_name, kill_job, write_file, watch_file, dump_themes, job; tape.zig's Wrap follows with no edit), in the device messages that carry one into the core (the inbox's output and eof and the five reader functions that make them, dev/Lsp.zig's Request, host_io's Adoption and Adoptions.take, which hold what adoptShell answered); `View.Id` in abi/wire.zig's welcome.view (its bytes on the wire unchanged: one byte, hand-encoded, `.at(takeByte())`/`writeByte(view.index())`); every producer converts at its own line (`.pane = .at(id)`, a script that refuses any path outside the workspace, `fields.py`), every consumer where it indexes or compares (`o.pane.index()`), every Host implementer at its own first line (`fn spawn(ctx, id: pardes.Pane.Id, ..) { const pane = id.index(); ..}`: the terminal's 14, the window's 14, the Mac's 10, and the tests' hosts), and an id that went integer and back is passed through whole (`s.core.readerFailed(e.pane, err)`); the compiler caught no pane's slot passed as a view's or the reverse, only integers meeting the type; kept integers on purpose: KindJob.pane (core/Kind.zig, another agent's, reads it four times; converted at KindJob's and Effect's lines), the Watch table (file_watch: its last slot is the theme's, no pane), the hello's view and the replica's Peer/Joined/Replica views (core/replica.zig, another agent's), the C ABI's `pardes_watch_changed(uint8_t pane)` (abi/pardes.h unchanged; runtime/macos.zig converts at its Host functions); in files another agent is in, each conversion on the line that was there: core/Kind.zig 2 lines, core/Addon.zig 4, core/replica.zig 31 (the welcome's view, 3 test hosts, test literals), test/replicas.zig 12 (4 host functions with their first lines, 1 signature, the welcome's view, 5 literals); the tape's shape moves (Event is update's input), so the semantics word moves, c47ecf638b3f4b9f -> 38b5ae573b965550; test/perf.zig follows on 6 lines its Event and effect literals forced, so its harness id moves, be7cc504010471bc -> 1ed95030eb768eae (unit-test's perf check was BaselineHarnessMismatch already); 607 lines added, 562 deleted in 48 files. Gate (load 4 to 8): tui core-test 841/984 (143 skipped), shell-test 1020/1023, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds of 70 steps, 0 failures, process-test lspcomplete and lspcompletemoved (the base's; hscroll failed once and passed on the runner's retry), gui unit-test 1618/1622 (BaselineHarnessMismatch, the base's); replicas --clients 5 (TMPDIR /tmp/claude-1000/ids): diverged 0, unequal 0 at rtt 30, 80, 207, deltas checked/wrong 1811/0, 1838/0, 1660/0, quiet checks 567/0, 650/0, 655/0, stops not on may_wait 0 (corpus through a client fails at step 21 as on the base with that TMPDIR); daemon.py plain, --far, --games, --window-clients, --upgrade both ways against pardes-tree's base prefix pass (the semantics words differ: the upgrade carries the session by its dump); test/cross_replay.py (tui records, gui replays): 27 digests agree in each of three replicas; rollback-bench runs; the macOS library for Linux and aarch64-macos and the FreeBSD cross-build build; frames (gpu/ids-3 against tree1) 77/77 byte-identical in Debug, unit-test 1618/1622 there, perfab corpus2x -0.021% (session noise 0.036%, threshold 0.4%), pictures identical in all 10 runs, perfops 97 counts within 0.1% (largest image-frame on longline +0.0231%), key-down on medium 10,040,108 -> 10,039,990 an operation (-0.0012%), render on medium 11,455,765 -> 11,455,683 (-0.0007%), terminal on all +0.0030%
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev')
-rw-r--r--dev/Host.zig28
-rw-r--r--dev/Inbox.zig28
-rw-r--r--dev/KindJob.zig2
-rw-r--r--dev/Lsp.zig26
-rw-r--r--dev/file_watch.zig6
-rw-r--r--dev/gui/gui.zig126
-rw-r--r--dev/host_io.zig52
-rw-r--r--dev/tui/tui.zig72
8 files changed, 184 insertions, 156 deletions
diff --git a/dev/Host.zig b/dev/Host.zig
index 1834e52e..24df3895 100644
--- a/dev/Host.zig
+++ b/dev/Host.zig
@@ -24,30 +24,30 @@ pub const VTable = struct {
/// for the daemon to attach again (daemon.zig).
detach: ?*const fn (ctx: ?*anyopaque) void = null,
/// Adopt: the shells a dead session left, asked of the daemon.
- adopt: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ adopt: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
/// Upgrade: this process exec'd as the pardes installed since, at
/// the step's end (upgrade.zig); `pane` hears why if it cannot be.
- upgrade: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ upgrade: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
/// Whether a newer pardes is installed at the path this process
/// started from, to be said once (upgrade.zig): asked at a focus-in.
newer_build: ?*const fn (ctx: ?*anyopaque) bool = null,
- spawn: ?*const fn (ctx: ?*anyopaque, pane: u8, cwd: []const u8) void = null,
- pty_write: ?*const fn (ctx: ?*anyopaque, pane: u8, bytes: []const u8) void = null,
- pty_resize: ?*const fn (ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void = null,
- pty_signal: ?*const fn (ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void = null,
- close_pty: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
- tty_taken: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null,
+ spawn: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cwd: []const u8) void = null,
+ pty_write: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, bytes: []const u8) void = null,
+ pty_resize: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cols: u16, rows: u16) void = null,
+ pty_signal: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, sig: pardes.PtySignal) void = null,
+ close_pty: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
+ tty_taken: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null,
/// The name of the program holding the tty, when it is not the
/// shell (host_io.foregroundName), in `buf`.
- fg_name: ?*const fn (ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 = null,
+ fg_name: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, buf: []u8) ?[]const u8 = null,
/// Answered at once, not queued as an effect: Kill asks while the
/// job it saw running is still the one in the tty (host_io.killJob).
- kill_job: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null,
- write_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void = null,
+ kill_job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null,
+ write_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, bytes: []const u8) void = null,
write_dump: ?*const fn (ctx: ?*anyopaque, bytes: []const u8) void = null,
- watch_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: pardes.WatchMode) void = null,
+ watch_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, on: bool, mode: pardes.WatchMode) void = null,
watch_theme: ?*const fn (ctx: ?*anyopaque, generation: u32, on: bool) void = null,
- dump_themes: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ dump_themes: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
set_clipboard: ?*const fn (ctx: ?*anyopaque, text: []const u8) void = null,
read_clipboard: ?*const fn (ctx: ?*anyopaque) void = null,
open_link: ?*const fn (ctx: ?*anyopaque, url: []const u8) void = null,
@@ -65,5 +65,5 @@ pub const VTable = struct {
/// Run job `token` of the pane in slot `pane` (whose serial is
/// `serial`) on a worker (`KindJob`), answering with the `job` event;
/// absent, it runs on the loop.
- job: ?*const fn (ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void = null,
+ job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void = null,
};
diff --git a/dev/Inbox.zig b/dev/Inbox.zig
index d8b14221..ed3a9835 100644
--- a/dev/Inbox.zig
+++ b/dev/Inbox.zig
@@ -8,8 +8,8 @@ const Lsp = host_io.Lsp;
const Inbox = @This();
pub const Msg = union(enum) {
- output: struct { pane: u8, gen: u32, bytes: []u8 },
- eof: struct { pane: u8, gen: u32, failure: ?anyerror = null },
+ output: struct { pane: pardes.Pane.Id, gen: u32, bytes: []u8 },
+ eof: struct { pane: pardes.Pane.Id, gen: u32, failure: ?anyerror = null },
lsp: struct { id: u32, rows: ?[]u8 },
lsp_status: []u8,
pipe: selection_pipe.Response,
@@ -96,18 +96,18 @@ pub fn wake(q: *Inbox) void {
if (q.wake_fn) |f| f(q.wake_ctx);
}
-pub fn acceptReader(q: *Inbox, pane: u8, gen: u32) void {
+pub fn acceptReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void {
q.lock();
defer q.unlock();
- std.debug.assert(q.readers[pane] == null);
- q.readers[pane] = gen;
+ std.debug.assert(q.readers[pane.index()] == null);
+ q.readers[pane.index()] = gen;
}
-pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void {
+pub fn cancelReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void {
q.lock();
defer q.unlock();
- if (q.readers[pane] != gen) return;
- q.readers[pane] = null;
+ if (q.readers[pane.index()] != gen) return;
+ q.readers[pane.index()] = null;
var i: usize = 0;
while (i < q.len) {
const msg = q.items[(q.head + i) % q.items.len];
@@ -121,14 +121,14 @@ pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void {
q.space.broadcast(q.io);
}
-pub fn pushOutput(q: *Inbox, pane: u8, gen: u32, bytes: []u8) bool {
+pub fn pushOutput(q: *Inbox, pane: pardes.Pane.Id, gen: u32, bytes: []u8) bool {
q.lock();
- while (!q.closed and q.readers[pane] == gen and q.len >= output_capacity) {
+ while (!q.closed and q.readers[pane.index()] == gen and q.len >= output_capacity) {
q.waiting += 1;
q.space.waitUncancelable(q.io, &q.mutex);
q.waiting -= 1;
}
- if (q.closed or q.readers[pane] != gen) {
+ if (q.closed or q.readers[pane.index()] != gen) {
q.unlock();
q.gpa.free(bytes);
return false;
@@ -186,7 +186,7 @@ pub fn push(q: *Inbox, m: Msg) void {
},
else => {
if (m == .eof) {
- if (q.readers[m.eof.pane] != m.eof.gen) {
+ if (q.readers[m.eof.pane.index()] != m.eof.gen) {
q.unlock();
return;
}
@@ -270,13 +270,13 @@ pub fn deinit(q: *Inbox) void {
/// A pane's reader: its pty's output pushed as it comes, then its end
/// of file; canceled (closePty), it pushes nothing more.
-pub fn startReader(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) !std.Io.Future(void) {
+pub fn startReader(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) !std.Io.Future(void) {
q.acceptReader(pane, gen);
errdefer q.cancelReader(pane, gen);
return q.io.concurrent(readPty, .{ q, pty, pane, gen });
}
-fn readPty(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) void {
+fn readPty(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) void {
var buf: [0x10000]u8 = undefined;
var failure: ?anyerror = null;
while (true) {
diff --git a/dev/KindJob.zig b/dev/KindJob.zig
index c24ad88d..e9cea5b4 100644
--- a/dev/KindJob.zig
+++ b/dev/KindJob.zig
@@ -48,7 +48,7 @@ pub fn run(j: *KindJob) void {
/// Its answer to the core, and it gone.
pub fn land(j: *KindJob, p: *pardes.Pardes) void {
if (j.draw != null) return pardes.Kind.landDraw(p, j);
- p.update(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } });
+ p.update(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } });
j.drop();
}
diff --git a/dev/Lsp.zig b/dev/Lsp.zig
index d7f11bfe..4b8bfa03 100644
--- a/dev/Lsp.zig
+++ b/dev/Lsp.zig
@@ -5,7 +5,7 @@ const filesystem = @import("core").filesystem;
pub const Request = struct {
id: u32,
kind: pardes.lsp.Kind,
- pane: u8,
+ pane: pardes.Pane.Id,
offset: u32,
arg: []const u8,
};
@@ -45,8 +45,8 @@ pub const Job = struct {
// Copy before starting a worker; the editor may replace any source slice afterward.
pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request) !*Job {
- if (req.pane >= core.panes.len) return error.NoPane;
- const pane = core.panes[req.pane] orelse return error.NoPane;
+ if (req.pane.index() >= core.panes.len) return error.NoPane;
+ const pane = core.panes[req.pane.index()] orelse return error.NoPane;
const file = pane.file;
const job = try gpa.create(Job);
errdefer gpa.destroy(job);
@@ -87,7 +87,7 @@ pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request
var copied: usize = 0;
for (core.panes, 0..) |slot, i| {
const other = slot orelse continue;
- if (i == req.pane) continue;
+ if (i == req.pane.index()) continue;
const f = other.file orelse continue;
if (f.output != null) continue;
if (copied + f.content.len > pardes.memory.limits.lsp_snapshot_bytes) continue;
@@ -118,12 +118,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T
}
const job = snapshot(gpa, core, req) catch |err| {
core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return core.reportError(.at(req.pane), "lsp", err);
+ return core.reportError(req.pane, "lsp", err);
};
const future = io.concurrent(work, .{ io, gpa, job, ctx, deliver }) catch |err| {
job.free(gpa);
core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return core.reportError(.at(req.pane), "lsp", err);
+ return core.reportError(req.pane, "lsp", err);
};
task.* = .{ .id = req.id, .future = future };
}
@@ -173,7 +173,7 @@ test "a snapshot owns every byte the backend will read" {
const job = try snapshot(gpa, core, .{
.id = 7,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = &needle,
});
@@ -202,7 +202,7 @@ test "LSP snapshot frees every partially copied field on allocation failure" {
const job = try snapshot(gpa, p, .{
.id = 7,
.kind = .hover,
- .pane = @intCast(p.view().active),
+ .pane = .at(p.view().active),
.offset = 6,
.arg = "query",
});
@@ -226,7 +226,7 @@ test "LSP snapshots translate explicit OS paths once and retain virtual names" {
const replacement = try gpa.dupe(u8, case.path);
gpa.free(pane.file.?.path);
pane.file.?.path = replacement;
- const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = .at(core.view().active), .offset = 0, .arg = "" });
defer job.free(gpa);
try std.testing.expectEqualStrings(case.native, job.path);
try std.testing.expectEqualStrings(std.Io.Dir.path.dirname(case.native).?, job.root);
@@ -247,7 +247,7 @@ test "a pane that is gone yields no job rather than a null deref" {
try std.testing.expectError(error.NoPane, snapshot(gpa, core, .{
.id = 1,
.kind = .definition,
- .pane = empty,
+ .pane = .at(empty),
.offset = 0,
.arg = "",
}));
@@ -272,7 +272,7 @@ test "work consumes the job and hands its rows to the sink" {
const job = try snapshot(gpa, core, .{
.id = 42,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
});
@@ -320,7 +320,7 @@ test "LSP edit query failure leaves text and undo untouched before a successful
const job = try snapshot(failing.allocator(), core, .{
.id = core.lsp_ask.wait.?.id,
.kind = kind,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 6,
.arg = "renamed",
});
@@ -389,7 +389,7 @@ test "LSP work delivers failure when transferring result ownership cannot alloca
} };
const core = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer core.deinit();
- const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" });
var sink: Sink = .{};
work(std.testing.io, gpa, job, &sink, Sink.take);
if (sink.rows) |rows| gpa.free(rows);
diff --git a/dev/file_watch.zig b/dev/file_watch.zig
index a02ad272..84f37c81 100644
--- a/dev/file_watch.zig
+++ b/dev/file_watch.zig
@@ -706,7 +706,7 @@ test "a restored file is watched again: one clean takes what its file became sin
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
var armed = false;
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
_ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode);
armed = true;
},
@@ -774,7 +774,7 @@ test "ordinary file watches still reconcile changes between open and watch" {
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
var armed = false;
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
try std.testing.expectEqual(.reconcile, watch.mode);
try std.testing.expect(!applyEffect(core, io, fd, &watches, id, watch.on, watch.mode));
armed = true;
@@ -949,7 +949,7 @@ test "a watched file deleted wakes the watch at once, and its pane says so" {
var watches: Table = @splat(null);
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
_ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode);
},
else => {},
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 3d050bbf..c147c2e2 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -1130,7 +1130,7 @@ const Own = struct {
pub fn start(o: *Own, l: *Session) !void {
for (&o.ptys, 0..) |*slot, id| if (slot.*) |*pt| {
- pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), o.gens[id]);
+ pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), o.gens[id]);
};
if (o.inotify_fd >= 0) {
o.watch_stop = try stopPipe();
@@ -2485,7 +2485,8 @@ const Shell = struct {
took_input: bool = false,
held: ?c.SDL_Event = null,
- fn closePaneShell(ctx: ?*anyopaque, pane: u8) void {
+ fn closePaneShell(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
shellOf(ctx).closePty(pane);
}
@@ -2493,7 +2494,7 @@ const Shell = struct {
const pt = if (s.ptys[pane]) |*pt| pt else return;
// Out of the queue first, which lets go a reader waiting for room
// in it; then its read is canceled (or, at its end, it is joined).
- s.queue.cancelReader(pane, s.gens[pane]);
+ s.queue.cancelReader(.at(pane), s.gens[pane]);
if (pt.reader) |*reader| {
reader.cancel(s.queue.io); // the Io it was started on (startReader)
pt.reader = null;
@@ -2603,12 +2604,14 @@ const Shell = struct {
return shellOf(ctx).gui != null;
}
- fn adopt(ctx: ?*anyopaque, pane: u8) void {
+ fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
s.adoptions.ask(s.core, pane);
}
- fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void {
+ fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place");
s.upgrade_asked = pane;
@@ -2656,7 +2659,7 @@ const Shell = struct {
const failed = upgrade.dumpInto(core, &rec, &at_buf, &why) orelse upgrade.execAs(s.gpa, path, &rec, &at_buf, s.fs, &why);
// As it was: its ptys read on.
for (s.ptys, 0..) |*slot, id| if (slot.*) |*pt| if (pt.fd >= 0 and pt.reader == null) {
- pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), s.gens[id]) catch null;
+ pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), s.gens[id]) catch null;
};
core.reportFailure(pane, failed);
}
@@ -2751,18 +2754,18 @@ const Shell = struct {
var check_files = false;
for (msgs.slice()) |m| switch (m) {
.output => |o| {
- if (s.gens[o.pane] == o.gen)
+ if (s.gens[o.pane.index()] == o.gen)
s.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } });
s.gpa.free(o.bytes);
},
.eof => |e| {
- if (s.gens[e.pane] == e.gen) eof: {
+ if (s.gens[e.pane.index()] == e.gen) eof: {
if (e.failure) |err| {
- s.closePty(e.pane);
- s.core.readerFailed(.at(e.pane), err);
+ s.closePty(e.pane.index());
+ s.core.readerFailed(e.pane, err);
break :eof;
}
- const pt = if (s.ptys[e.pane]) |*pt| pt else {
+ const pt = if (s.ptys[e.pane.index()]) |*pt| pt else {
s.core.update(.{ .eof = .{ .pane = e.pane } });
break :eof;
};
@@ -2770,15 +2773,15 @@ const Shell = struct {
// closing it would hang up one that runs on without it.
// Its exit, if it came first, is told now its output is in.
if (pt.cmd.watched) {
- host_io.commandEof(s.core, s.ptys, e.pane, s, closeWatched);
+ host_io.commandEof(s.core, s.ptys, e.pane.index(), s, closeWatched);
break :eof;
}
// Unwatched, a command's exit is read here, as its end,
// and a shell's, for a run waiting on it and the log.
- const unwatched = if (s.core.panes[e.pane]) |pane| pane.command != null else false;
+ const unwatched = if (s.core.panes[e.pane.index()]) |pane| pane.command != null else false;
const status = host_io.exitStatus(pt.pid, 100);
if (status != null) pt.pid = 0; // reaped: no shell to retire
- s.closePty(e.pane);
+ s.closePty(e.pane.index());
if (unwatched or status != null) s.core.update(.{ .exited = .{ .pane = e.pane, .status = status } });
s.core.update(.{ .eof = .{ .pane = e.pane } });
}
@@ -3327,32 +3330,33 @@ fn guiNow(ctx: ?*anyopaque) u64 {
return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS();
}
-fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
+fn spawnPane(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
- if (s.adoptions.take(pane)) |a| return takeShell(s, pane, a);
+ if (s.adoptions.take(id)) |a| return takeShell(s, pane, a);
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
- if (running) return s.core.restartFailed(.at(pane), err);
- return s.core.shellFailed(.at(pane), err);
+ if (running) return s.core.restartFailed(id, err);
+ return s.core.shellFailed(id, err);
};
s.closePty(pane);
if (s.ptys[pane] != null) {
_ = libc.close(child.file.handle);
host_io.retireShell(child.pid);
- return s.core.reportError(.at(pane), "shell", error.WorkersBusy);
+ return s.core.reportError(id, "shell", error.WorkersBusy);
}
s.gens[pane] +%= 1;
const command = s.core.panes[pane].?.command != null;
const pt: Pty = .{ .fd = child.file.handle, .pid = child.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } };
s.ptys[pane] = pt;
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
+ if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(id, wd);
if (!s.threads_ok) return;
- s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| {
+ s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, id, s.gens[pane]) catch |err| {
s.closePty(pane);
- return s.core.reportError(.at(pane), "terminal reader", err);
+ return s.core.reportError(id, "terminal reader", err);
};
}
@@ -3368,9 +3372,9 @@ fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void {
if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1));
+ if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1));
if (!s.threads_ok) return;
- s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| {
+ s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, .at(pane), s.gens[pane]) catch |err| {
s.closePty(pane);
return s.core.reportError(.at(pane), "terminal reader", err);
};
@@ -3397,12 +3401,14 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
}
}
-fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void {
+fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.fd, bytes);
}
-fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
+fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.ptys[pane]) |pt| {
const ws = host_io.ptyWinsize(s.core, cols, rows);
@@ -3410,31 +3416,36 @@ fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
}
}
-fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void {
+fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void {
+ const pane = id.index();
const s = shellOf(ctx);
// A command whose exit is recorded is reaped: its group may be another's.
if (s.ptys[pane]) |pt| if (!pt.cmd.exited) host_io.signalTty(pt.pid, pt.fd, sig, pt.cmd.watched);
}
-fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool {
+fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.ttyTaken(pt.pid, pt.fd);
}
-fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 {
+fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return null;
return host_io.foregroundName(pt.pid, pt.fd, buf);
}
-fn killJob(ctx: ?*anyopaque, pane: u8) bool {
+fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.killJob(pt.pid, pt.fd);
}
-fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void {
+fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
host_io.writeFile(s.core, s.watches, pane, path, bytes);
}
@@ -3443,7 +3454,8 @@ fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void {
host_io.writeDump(shellOf(ctx).core, bytes);
}
-fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, s.watches, pane, on, mode))
s.queue.push(.files_changed);
@@ -3461,7 +3473,8 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void {
)) s.queue.push(.files_changed);
}
-fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
+fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
host_io.dumpThemes(s.core, s.io, s.gpa, pane);
}
@@ -3501,7 +3514,7 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void {
const s = shellOf(ctx);
if (s.threads_ok) return s.queue.startLsp(s.core, req);
s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable);
+ s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
}
fn pipe(ctx: ?*anyopaque, id: u32) void {
@@ -3517,7 +3530,8 @@ fn kindDraw(ctx: ?*anyopaque, j: *host_io.KindJob) bool {
return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s.queue, Queue.pushJob);
}
-fn kindJob(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+fn kindJob(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.threads_ok) return host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s.queue, Queue.pushJob);
host_io.KindJob.runHere(s.core, pane, serial, token);
@@ -6280,7 +6294,7 @@ test "GUI PTY reader delivers a real shell tail before EOF and joins on close" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try std.testing.expect(host_io.writeFd(child.file.handle, "printf '\\120\\101\\122\\104\\105\\123\\055\\124\\101\\111\\114'; exit\n"));
var bytes: std.ArrayList(u8) = .empty;
defer bytes.deinit(gpa);
@@ -6317,8 +6331,8 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
try dump.dumpState(core);
var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(1, 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 1, .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } });
+ queue.acceptReader(.at(1), 1);
+ for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(1), .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } });
var ptys: [pardes.MAX_PANES]?Pty = @splat(null);
var gens: [pardes.MAX_PANES]u32 = @splat(1);
var shell: Shell = undefined;
@@ -6331,7 +6345,7 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try std.testing.expect(host_io.writeFd(child.file.handle, "printf 'after-full'; exit\n"));
try host_io.PtyTests.waitBlocked(&queue);
const old_serial = core.panes[0].?.serial;
@@ -6345,10 +6359,10 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
try std.testing.expectEqual(@as(usize, 0), queue.waiting);
try std.testing.expect(queue.readers[0] == null);
try std.testing.expectEqual(@as(c_int, -1), libc.fcntl(child.file.handle, libc.F.GETFD));
- queue.cancelReader(1, 1);
- queue.acceptReader(0, gens[0]);
- queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- try std.testing.expect(queue.pushOutput(0, gens[0], try gpa.dupe(u8, "fresh")));
+ queue.cancelReader(.at(1), 1);
+ queue.acceptReader(.at(0), gens[0]);
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
+ try std.testing.expect(queue.pushOutput(.at(0), gens[0], try gpa.dupe(u8, "fresh")));
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(@as(usize, 1), batch.len);
@@ -6373,7 +6387,7 @@ test "GUI PTY deletion joins an idle reader and its shell is reaped by exit" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try core.removePane(0, null);
shell.reconcilePtys();
try std.testing.expect(queue.readers[0] == null);
@@ -6414,9 +6428,9 @@ test "GUI completion failure survives backlog and leaves the document unchanged"
const id = core.lsp_ask.wait.?.id;
var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = id };
defer queue.deinit();
- queue.acceptReader(0, 1);
+ queue.acceptReader(.at(0), 1);
for (0..output_capacity) |_| queue.push(.{ .output = .{
- .pane = 0,
+ .pane = .at(0),
.gen = 1,
.bytes = try gpa.dupe(u8, "output"),
} });
@@ -6459,7 +6473,7 @@ test "GUI worker setup failures finish matching LSP and pipe requests" {
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
};
@@ -6560,7 +6574,7 @@ test "the window's function and editing keys reach a terminal as its cursor keys
.{ .modes = "", .sym = c.SDLK_UP, .sent = "\x1b[1;1:1A" },
};
for (cases) |case| {
- core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } });
while (core.nextEffect()) |_| {}
keyDown(&in, case.sym, case.mod);
written.clearRetainingCapacity();
@@ -6678,7 +6692,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac
fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6692,7 +6706,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac
putClipboard(gpa, "ls\x1b[201~; rm -rf ~\nx");
readClipboard(&shell);
try std.testing.expectEqualStrings("ls [201~; rm -rf ~\rx", try take(core, &sent));
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } });
_ = try take(core, &sent);
readClipboard(&shell);
try std.testing.expectEqualStrings("\x1b[200~ls [201~; rm -rf ~\nx\x1b[201~", try take(core, &sent));
@@ -6774,7 +6788,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift
fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6784,7 +6798,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift
const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
const next: MouseCell = .{ .col = mc.col + 1, .row = mc.row };
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
_ = try take(core, &sent);
in.post(.{ .mouse = pointerMouse(.none, .motion, mc, .{}) });
try std.testing.expectEqualStrings("\x1b[<35;6;4M", try take(core, &sent));
@@ -6824,7 +6838,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
fn take(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6834,7 +6848,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
// What codex 0.159's chat sets on start.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
// A notch up, then a fast turn of three down: each its report, none
@@ -6860,14 +6874,14 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
try std.testing.expectEqualStrings("", try Sent.take(core, &sent));
resetScroll(&g);
// Its sign-in screen: mouse off, alternate scroll on, so arrow keys.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
wheelAt(&g, &in, .{ .y = -1, .integer_y = -1 }, mc);
try std.testing.expectEqualStrings("\x1b[B", try Sent.take(core, &sent));
// Back on the main screen a shell's wheel is ours: a notch to glide,
// nothing to the pty.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc);
diff --git a/dev/host_io.zig b/dev/host_io.zig
index 2ee7c47e..f86c3250 100644
--- a/dev/host_io.zig
+++ b/dev/host_io.zig
@@ -69,7 +69,7 @@ pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u
/// A shell of a dead session the daemon handed this one (Adopt), and the
/// terminal pane made for it once there is one.
-pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?u8 };
+pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?pardes.Pane.Id };
/// The shells of dead sessions handed this one (Adopt), each waiting for
/// the spawn of the terminal pane made for it (`take`).
@@ -99,7 +99,7 @@ pub const Adoptions = struct {
a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null };
a.len += 1;
if (core.adoptShell()) |id| {
- a.list[a.len - 1].pane = id.index();
+ a.list[a.len - 1].pane = id;
a.taken += 1;
return;
}
@@ -112,7 +112,7 @@ pub const Adoptions = struct {
}
/// The adopted shell pane `pane`'s spawn takes, off the list.
- pub fn take(a: *Adoptions, pane: u8) ?Adoption {
+ pub fn take(a: *Adoptions, pane: pardes.Pane.Id) ?Adoption {
for (a.list[0..a.len], 0..) |it, i| if (it.pane == pane) {
std.mem.copyForwards(Adoption, a.list[i .. a.len - 1], a.list[i + 1 .. a.len]);
a.len -= 1;
@@ -1105,7 +1105,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo
if (!pt.cmd.watched or !pt.cmd.due()) continue;
pt.cmd.told = true;
const eof = pt.cmd.eof;
- core.update(.{ .exited = .{ .pane = @intCast(id), .status = pt.cmd.status } });
+ core.update(.{ .exited = .{ .pane = .at(id), .status = pt.cmd.status } });
if (eof) close(ctx, id);
}
}
@@ -1115,7 +1115,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo
pub fn commandEof(core: *pardes.Pardes, ptys: anytype, id: usize, ctx: anytype, comptime close: anytype) void {
const pt = slotPty(&ptys[id]) orelse return;
pt.cmd.eof = true;
- core.update(.{ .eof = .{ .pane = @intCast(id) } });
+ core.update(.{ .eof = .{ .pane = .at(id) } });
if (pt.cmd.told) return close(ctx, id);
takeExits(core, ptys, ctx, close);
}
@@ -1549,7 +1549,7 @@ pub const PtyTests = struct {
}
fn tail(queue: *Inbox, bytes: []u8) void {
- if (queue.pushOutput(0, 1, bytes)) queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
+ if (queue.pushOutput(.at(0), 1, bytes)) queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
}
};
@@ -2155,9 +2155,9 @@ test "completion survives a full output queue" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 7 };
defer queue.deinit();
- queue.acceptReader(0, 1);
+ queue.acceptReader(.at(0), 1);
for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{
- .pane = 0,
+ .pane = .at(0),
.gen = 1,
.bytes = try gpa.dupe(u8, "output"),
} });
@@ -2193,15 +2193,15 @@ test "PTY backpressure retains byte order and tail before EOF" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ queue.acceptReader(.at(0), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
const tail = try gpa.dupe(u8, "tail");
var thread: ?std.Thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
gpa.free(tail);
return err;
};
defer {
- queue.cancelReader(0, 1);
+ queue.cancelReader(.at(0), 1);
if (thread) |owned| owned.join();
}
try PtyTests.waitBlocked(&queue);
@@ -2227,24 +2227,24 @@ test "PTY backpressure cancellation and close release owned producers" {
for ([_]bool{ false, true }) |close| {
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ queue.acceptReader(.at(0), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
const tail = try gpa.dupe(u8, "cancelled");
const thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
gpa.free(tail);
return err;
};
defer {
- queue.cancelReader(0, 1);
+ queue.cancelReader(.at(0), 1);
thread.join();
}
try PtyTests.waitBlocked(&queue);
- if (close) queue.close() else queue.cancelReader(0, 1);
+ if (close) queue.close() else queue.cancelReader(.at(0), 1);
if (!close) {
- queue.acceptReader(0, 2);
- queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- try std.testing.expect(queue.pushOutput(0, 2, try gpa.dupe(u8, "replacement")));
- queue.push(.{ .eof = .{ .pane = 0, .gen = 2 } });
+ queue.acceptReader(.at(0), 2);
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
+ try std.testing.expect(queue.pushOutput(.at(0), 2, try gpa.dupe(u8, "replacement")));
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 2 } });
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(@as(usize, 2), batch.len);
@@ -2258,14 +2258,14 @@ test "PTY EOF reserve cannot evict terminal output" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- for (0..pardes.MAX_PANES) |pane| queue.acceptReader(@intCast(pane), 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
- for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = @intCast(pane), .gen = 1 } });
+ for (0..pardes.MAX_PANES) |pane| queue.acceptReader(.at(pane), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = .at(pane), .gen = 1 } });
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(Inbox.capacity, batch.len);
for (batch.items[0..Inbox.output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes);
- for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane);
+ for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index());
}
test "completions retain their arrival order across LSP and pipes" {
@@ -2288,8 +2288,8 @@ test "completion reset frees queued payloads and rejects late LSP workers" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 9 };
defer queue.deinit();
- queue.acceptReader(0, 1);
- queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "retained") } });
+ queue.acceptReader(.at(0), 1);
+ queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "retained") } });
queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "current") } });
queue.push(.{ .lsp = .{ .id = 8, .rows = try gpa.dupe(u8, "late old request") } });
try std.testing.expectEqualStrings("current", queue.completions[0].lsp.rows.?);
@@ -2343,7 +2343,7 @@ test "LSP query answers, and a newer one cancels it" {
defer queue.deinit();
for (0..2) |_| {
core.lspRequest(core.view().active, .status, "");
- queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" });
}
const last = core.lsp_ask.wait.?.id;
queue.lsp_task.?.future.await(io);
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 48b5d3d1..1f6b9a49 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -1099,7 +1099,7 @@ const Own = struct {
}
sh.pipe_tasks.cancelAll(io);
for (&sh.gens) |*generation| generation.* +%= 1;
- for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, @intCast(pane));
+ for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, .at(pane));
// One view, the terminal's (host_io.restoreCore).
const live = o.screen;
stopInput(io, &live.thread);
@@ -1386,7 +1386,8 @@ const Shell = struct {
if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why});
}
- fn adopt(ctx: ?*anyopaque, pane: u8) void {
+ fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
s.adoptions.ask(s.core, pane);
}
@@ -1397,7 +1398,8 @@ const Shell = struct {
return of(ctx).client == null and upgrade.newer();
}
- fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void {
+ fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place");
s.upgrade_asked = pane;
@@ -1748,7 +1750,7 @@ const Shell = struct {
s.output_seen = true;
if (pr.id == core.view().active) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
if (s.gens[pr.id] == pr.gen)
- core.update(.{ .output = .{ .pane = @intCast(pr.id), .bytes = pr.bytes } });
+ core.update(.{ .output = .{ .pane = .at(pr.id), .bytes = pr.bytes } });
s.gpa.free(pr.bytes);
// An exit waiting behind this output may be told now.
s.takeExits();
@@ -1771,9 +1773,9 @@ const Shell = struct {
const status = host_io.exitStatus(pt.pid, 100);
if (status == null) host_io.retireShell(pt.pid);
s.ptys[e.id] = null;
- if (command or status != null) core.update(.{ .exited = .{ .pane = @intCast(e.id), .status = status } });
+ if (command or status != null) core.update(.{ .exited = .{ .pane = .at(e.id), .status = status } });
}
- core.update(.{ .eof = .{ .pane = @intCast(e.id) } });
+ core.update(.{ .eof = .{ .pane = .at(e.id) } });
},
.key_press => |key| if (s.in_paste) {
const bytes = vaxis_input.pasteBytes(key);
@@ -2028,17 +2030,18 @@ const Shell = struct {
tracy.frameMark();
}
- fn spawn(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
+ fn spawn(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
- if (s.adoptions.take(pane)) |a| return s.takeShell(pane, a);
+ if (s.adoptions.take(id)) |a| return s.takeShell(pane, a);
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
- if (running) return s.core.restartFailed(.at(pane), err);
- return s.core.shellFailed(.at(pane), err);
+ if (running) return s.core.restartFailed(id, err);
+ return s.core.shellFailed(id, err);
};
- closePty(ctx, pane); // a shell still in the slot goes, reaped
+ closePty(ctx, id); // a shell still in the slot goes, reaped
s.gens[pane] +%= 1;
const command = if (s.core.panes[pane]) |pn| pn.command != null else false;
s.ptys[pane] = .{ .file = child.file, .pid = child.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } };
@@ -2046,7 +2049,7 @@ const Shell = struct {
// Only a shell given no directory is asked where it is: one given a
// directory is named by it already (newShell), and asked now, before
// its chdir, it would answer this process's, a rename to undo.
- if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
+ if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(id, wd);
if (s.threads_ok) {
if (s.ptys[pane]) |*pt| {
pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader;
@@ -2057,7 +2060,7 @@ const Shell = struct {
/// An adopted shell, running already, as pane `pane`'s: told the size
/// twice (a size it never had, then the pane's), which makes it redraw.
fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void {
- closePty(s, pane);
+ closePty(s, .at(pane));
s.gens[pane] +%= 1;
const file: std.Io.File = .{ .handle = a.fd, .flags = .{ .nonblocking = false } };
s.ptys[pane] = .{ .file = file, .pid = a.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{} };
@@ -2067,18 +2070,20 @@ const Shell = struct {
if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1));
+ if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1));
if (s.threads_ok) if (s.ptys[pane]) |*pt| {
pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader;
};
}
- fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void {
+ fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.file.handle, bytes);
}
- fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
+ fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void {
+ const pane = id.index();
const s = of(ctx);
if (s.ptys[pane]) |pt| {
const ws = host_io.ptyWinsize(s.core, cols, rows);
@@ -2086,7 +2091,8 @@ const Shell = struct {
}
}
- fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void {
+ fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void {
+ const pane = id.index();
const s = of(ctx);
// A command whose exit is recorded is reaped: its group may be
// another's by now.
@@ -2096,7 +2102,8 @@ const Shell = struct {
/// The pane is gone: hang its pty up, which the kernel passes on to the
/// shell as SIGHUP, and retire the shell. Output still in flight
/// carries the old generation and is dropped.
- fn closePty(ctx: ?*anyopaque, pane: u8) void {
+ fn closePty(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
var pt = s.ptys[pane] orelse return;
s.ptys[pane] = null;
@@ -2107,13 +2114,15 @@ const Shell = struct {
host_io.retireShell(pt.pid);
}
- fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool {
+ fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.ttyTaken(pt.pid, pt.file.handle);
}
- fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 {
+ fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return null;
return host_io.foregroundName(pt.pid, pt.file.handle, buf);
@@ -2130,13 +2139,15 @@ const Shell = struct {
s.ptys[id] = null;
}
- fn killJob(ctx: ?*anyopaque, pane: u8) bool {
+ fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.killJob(pt.pid, pt.file.handle);
}
- fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void {
+ fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
host_io.writeFile(s.core, &s.watches, pane, path, bytes);
}
@@ -2145,7 +2156,8 @@ const Shell = struct {
host_io.writeDump(of(ctx).core, bytes);
}
- fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ const pane = id.index();
const s = of(ctx);
if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, &s.watches, pane, on, mode))
s.loop.postEvent(.files_changed) catch {};
@@ -2157,7 +2169,8 @@ const Shell = struct {
s.loop.postEvent(.files_changed) catch {};
}
- fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
+ fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
host_io.dumpThemes(s.core, s.io, s.gpa, pane);
}
@@ -2185,7 +2198,7 @@ const Shell = struct {
const s = of(ctx);
if (!s.threads_ok) {
s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable);
+ return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
}
host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows);
}
@@ -2220,7 +2233,8 @@ const Shell = struct {
}.deliver);
}
- fn job(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+ fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
const s = of(ctx);
if (!s.threads_ok) return host_io.KindJob.runHere(s.core, pane, serial, token);
host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s, struct {
@@ -2960,7 +2974,7 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell
for (0..64 * 64) |i| px[i * 3 ..][0..3].* = .{ 13, 77, 231 };
const enc = try a.alloc(u8, std.base64.standard.Encoder.calcSize(px.len));
_ = std.base64.standard.Encoder.encode(enc, px);
- core.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } });
while (core.nextEffect()) |_| {}
const s = try core.render(a);
try std.testing.expectEqual(@as(usize, 4), s.placements.items.len);
@@ -3056,7 +3070,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" {
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
};
@@ -3156,7 +3170,7 @@ test "the terminal's keys reach a program as its cursor keys' mode and keyboard
.{ .modes = "\x1b[?1l\x1b[>7u", .in = "\x1b[99;5u\x1b[97;3u\x1b[A", .sent = "\x1b[99;5u\x1b[97;3u\x1b[1;1:1A" },
};
for (cases) |case| {
- core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } });
while (core.nextEffect()) |_| {}
var parser: vaxis.Parser = .{};
var bytes = case.in;