summaryrefslogtreecommitdiff
path: root/dev/tui
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 /dev/tui
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 'dev/tui')
-rw-r--r--dev/tui/tui.zig86
1 files changed, 50 insertions, 36 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 70ea3295..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;
@@ -1500,7 +1502,7 @@ const Shell = struct {
if (t.stub >= 0) daemon.tellStub(t.stub, "d{s}", .{daemon.name()});
}
if (rec.fresh) return;
- for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
+ for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(.at(k));
}
fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
@@ -1673,7 +1675,7 @@ const Shell = struct {
// The terminal's input goes into its view.
switch (event) {
.key_press, .mouse, .paste, .paste_start, .paste_end, .winsize, .focus_in, .focus_out, .quit => {
- if (s.local() and s.client == null) core.toView(s.own);
+ if (s.local() and s.client == null) core.toView(.at(s.own));
},
else => {},
}
@@ -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);
@@ -1807,7 +1809,7 @@ const Shell = struct {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- core.setStatus(core.view().active, message.stamp(&mbuf, "lsp", text));
+ core.setStatus(.at(core.view().active), message.stamp(&mbuf, "lsp", text));
s.lsp_gpa.free(text);
},
.pipe_done => |response_value| {
@@ -1851,7 +1853,7 @@ const Shell = struct {
if (!sc.on or sc.vx.state.in_band_resize) return;
const ws = sc.tty.getWinsize() catch return;
if (sc.size) |was| if (std.meta.eql(was, ws)) return;
- if (s.client == null) s.core.toView(s.own);
+ if (s.client == null) s.core.toView(.at(s.own));
s.resized(sc, ws);
}
@@ -1885,7 +1887,7 @@ const Shell = struct {
};
for (&s.ptys, 0..) |*slot, id| if (slot.*) |pt| {
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(id, cwd);
+ if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(.at(id), cwd);
};
const sc = s.term() orelse return;
@@ -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(pane, err);
- return s.core.shellFailed(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(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,28 +2060,30 @@ 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 = .{} };
var exe_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- s.core.acknowledgeShell(pane, host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
+ s.core.acknowledgeShell(.at(pane), host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(pane, wd);
+ if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1));
+ if (s.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);
}
@@ -2199,7 +2212,7 @@ const Shell = struct {
const s = of(ctx);
if (!s.threads_ok) {
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable);
+ return s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable);
}
selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe);
}
@@ -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;