diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 18:35:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 20:24:14 -0300 |
| commit | bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (patch) | |
| tree | ed415f31749669a36d5df304af4101f56e9fdd23 /dev/tui/tui.zig | |
| parent | 78d94c4a62ec3f4039a475b637ff6a60649fde52 (diff) | |
| download | pardes-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/tui/tui.zig')
| -rw-r--r-- | dev/tui/tui.zig | 72 |
1 files changed, 43 insertions, 29 deletions
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; |
