diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 12:36:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 13:09:56 -0300 |
| commit | 9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3 (patch) | |
| tree | 1fd44d101a680ed4ff601c8760d2f6bd4139edc0 /dev/tui/tui.zig | |
| parent | 1374e668fe568ad4f7f70c06156c1ecdbb8840b9 (diff) | |
| parent | c8ac386d8f2404417b6d09af1635e1104bcc66ae (diff) | |
| download | pardes-9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3.tar.gz pardes-9c50dd0b64ecaa8cbcfd4f76868dc83e5b9636e3.zip | |
integration: the addons' workers and the daemon's notes once, on the five faults a busy machine showed: pardes-services-3 (jobs, draws, pipes and a search through the session's one queue, their workers the queue's; the daemon's notes the loop's own: eight frontend calls; an Adopt's shells kept room in a full queue; a command's exit told after its reads are applied; the tty harness's end of a case) and pardes-merge36 (pardes-faults-5); two conflicts, both where the daemon's reader starts: the faults made daemon.watch() argument-free with daemon.notesTo, the services gave the loop its own note: daemon.notesTo(&l, note) and daemon.watch(); the terminal frontend's quit arm starts no reader (kept does), and Shell.session, whose one reader that line was, is deleted; tui core-test 861/1016 (155 skipped), shell-test 1058/1061, term-test 17/17, both soaks diverged 0, unequal 0, unlisted 0, the window builds; the coordinator's gate in the ledger (reorg/merge37)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/tui/tui.zig')
| -rw-r--r-- | dev/tui/tui.zig | 140 |
1 files changed, 27 insertions, 113 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index e699745a..e5e28f6e 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -97,15 +97,14 @@ fn kittyShmProbe(w: *std.Io.Writer, feed: *Feed) void { w.flush() catch {}; } -/// What the loop's queue carries: a terminal's input, a pane's output, a -/// worker's answer, a wake. +/// What the loop's queue carries: a terminal's input, a wake, what a +/// replica client's reader hands over. A pane's output, a worker's answer +/// and the daemon's notes are the session's queue's (Inbox, `takeQueue`). const Msg = union(enum) { nop, /// The terminal's input ended: its end of file, a hangup. A session /// a daemon keeps carries on detached; any other ends. quit, - /// A shell a dead session left, its pty's master (daemon.Note.adopted). - adopted: struct { pid: posix.pid_t, fd: posix.fd_t }, /// A timed wait ran out: the core's next wake has come. wake, /// A SIGWINCH: a terminal changed size (Shell.winched). @@ -120,14 +119,7 @@ const Msg = union(enum) { paste: []const u8, paste_start, paste_end, - pipe_done: selection_pipe.Response, - /// A streaming search's rows (pardes.Stream). - search_rows: pardes.Stream.Batch, - /// A kind's job done on a worker (host_io.KindJob). - kind_job: *host_io.KindJob, fs_ready, - /// A replica's connection, handed over by the daemon (Peers). - replica: daemon.Joining, /// A replica's reader posted: the step boundary takes it in. replica_mail, /// A replica client's: what the session streamed (replica.Link). @@ -369,8 +361,6 @@ const TestReader = struct { } }; -const PipeTasks = selection_pipe.Tasks; - /// A watched child exited: wake the loop, which takes it (`takeExits`). fn wakeForExit(ctx: ?*anyopaque) void { const loop: *Loop = @ptrCast(@alignCast(ctx.?)); @@ -760,7 +750,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var c = try Client.init(&tty, &start); defer c.link.deinit(gpa); // A client has no clients of its own, and spawns nothing: its pty - // table an empty one over an empty queue. + // table an empty one over a queue that carries its draws alone. var no_peers: replica.Peers = .{}; var no_inbox: host_io.Inbox = .{ .io = io, .gpa = gpa, .lsp_allocator = start.allocs.lsp }; defer no_inbox.deinit(); @@ -783,6 +773,8 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, .ptys = &no_ptys, }; tty = .{ .sh = &sh, .screen = &screen, .loop = &loop, .joins = &start }; + no_inbox.wake_fn = Shell.wakeForQueue; + no_inbox.wake_ctx = &sh; pardes.Kind.drawer = .{ .ctx = &sh, .go = Shell.draw }; defer pardes.Kind.drawer = null; @@ -1001,19 +993,8 @@ const Own = struct { stopInput(io, &o.screen.thread); pardes.Kind.drawer = null; host_io.setExitWake(null, null); - sh.pipe_tasks.cancelAll(io); - sh.job_tasks.cancelAll(io); - // Its worker may be waiting on the loop's queue for room. - sh.core.stream.cancelTask(); while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), - .pipe_done => |response_value| { - var response = response_value; - response.deinit(gpa); - }, - .search_rows => |b| b.deinit(gpa), - .kind_job => |j| j.drop(), - .adopted => |a| _ = libc.close(a.fd), else => {}, }; o.screen.art.deinit(gpa); @@ -1049,14 +1030,9 @@ const Own = struct { if (o.sh.upgrade_asked) |pane| o.sh.upgradeNow(pane); } - pub fn note(o: *Own, n: daemon.Note) void { - deliverNote(o.loop, n); - } - pub fn restoring(o: *Own, nc: *pardes.Pardes) void { const sh = &o.sh; const io = sh.io; - sh.pipe_tasks.cancelAll(io); // One view, the terminal's (host_io.restoreCore). const live = o.screen; stopInput(io, &live.thread); @@ -1085,24 +1061,6 @@ fn clearNativeImages( kitty_handles.clearRetainingCapacity(); } -/// The daemon's thread: what it says, onto the loop's queue. -fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { - const loop: *Loop = @ptrCast(@alignCast(ctx)); - switch (note) { - // A full queue wakes it anyway. - .relinked => _ = loop.tryPostEvent(.nop) catch false, - .adopted => |a| { - for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| loop.postEvent(.{ .adopted = .{ .pid = pid, .fd = fd } }) catch { - _ = libc.close(fd); - }; - loop.postEvent(.{ .adopted = .{ .pid = 0, .fd = -1 } }) catch {}; - }, - .replica => |j| loop.postEvent(.{ .replica = j }) catch { - _ = libc.close(j.fd); - }, - } -} - /// A replica reader's post: the session's wait ends, and its step /// boundary takes the post in. fn wakeForReplica(ctx: ?*anyopaque) void { @@ -1140,8 +1098,6 @@ const Shell = struct { batch: host_io.Inbox.Batch = .{}, batch_at: usize = 0, queue_woken: std.atomic.Value(bool) = .init(false), - pipe_tasks: PipeTasks = .{}, - job_tasks: PipeTasks = .{}, threads_ok: bool = false, check_files: bool = false, in_paste: bool = false, @@ -1511,11 +1467,9 @@ const Shell = struct { // is held for the next wait: `split`). s.takeQueue(); // An exit's wake (a .nop) or output an exit waited behind: told - // here, inside the step, so the frame after it shows it; not while - // reads taken off the queue wait their steps (`takeQueue`): one of - // them may be the command's own last output, which its exit would - // be drawn above (CommandWatch.due cannot see it). - if (s.batch_at == s.batch.len) s.takeExits(); + // here, inside the step, so the frame after it shows it (a read + // still to be applied holds it back: Ptys.unapplied). + s.takeExits(); s.reloadWatched(); } @@ -1593,11 +1547,6 @@ const Shell = struct { core.quit = true; return true; }, - .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), - .replica => |j| { - s.peers.handed(j.fd, j.view); - s.input_seen = true; - }, .replica_mail => if (s.peers.urgent.swap(false, .acq_rel)) { s.input_seen = true; }, @@ -1653,27 +1602,6 @@ const Shell = struct { s.paste_buf.clearRetainingCapacity(); }, .fs_ready => {}, - .pipe_done => |response_value| { - var response = response_value; - core.update(.{ .pipe_resp = .{ - .id = response.id, - .success = response.success, - .outputs = response.outputs, - .failure = response.failure, - } }); - response.deinit(s.gpa); - s.pipe_tasks.finish(s.io, response_value.id); - }, - .search_rows => |b| { - core.update(.{ .search = b }); - b.deinit(s.gpa); - }, - .kind_job => |j| { - s.job_tasks.finish(s.io, j.id); - j.land(core); - // A client's draw done: its frame is its own to draw again. - if (s.client) |cl| cl.link.dirty = true; - }, } return false; } @@ -1882,7 +1810,8 @@ const Shell = struct { } /// What the session's queue holds: its ptys' output (`waitInput` - /// paces it; the focused pane's is its echo) and their ends of file. + /// paces it; the focused pane's is its echo), their ends of file and + /// the workers' answers. /// A read a step, as the terminal's own queue gave them: the frame /// after one shows it before what came after it (a command's last line /// before its exit scrolls it away), the rest kept for the next wait. @@ -1910,8 +1839,14 @@ const Shell = struct { }, .eof => |e| s.ptys.eof(s.core, e), .files_changed => s.check_files = true, - .lsp, .lsp_status => s.ptys.queue.landLsp(s.core, m), - else => m.deinit(s.gpa, s.lsp_gpa), + .kind_job => { + s.ptys.queue.land(s.core, m); + // A client's draw done: its frame is its own to draw again. + if (s.client) |cl| cl.link.dirty = true; + }, + .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), + .fs_ready => {}, + else => s.ptys.queue.land(s.core, m), } } } @@ -1966,50 +1901,29 @@ const Shell = struct { s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); 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); + const q = s.ptys.queue; + selection_pipe.start(s.io, s.gpa, s.core, &q.pipe_tasks, id, q, host_io.Inbox.pushPipe); } fn search(ctx: ?*anyopaque, gen: u32) void { const s = of(ctx); - if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s, deliverSearch); + if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s.ptys.queue, host_io.Inbox.pushSearch); pardes.Stream.runHere(s.core, gen, true); } /// A draw (api.draw) on a worker, as a job is. fn draw(ctx: ?*anyopaque, j: *host_io.KindJob) bool { const s = of(ctx); - return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s, struct { - fn deliver(c: ?*anyopaque, k: *host_io.KindJob) void { - of(c).loop.postEvent(.{ .kind_job = k }) catch k.drop(); - } - }.deliver); + const q = s.ptys.queue; + return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &q.job_tasks, j, q, host_io.Inbox.pushJob); } 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 { - fn deliver(c: ?*anyopaque, j: *host_io.KindJob) void { - of(c).loop.postEvent(.{ .kind_job = j }) catch j.drop(); - } - }.deliver); - } - - /// The loop's queue waits for room (a wait the worker's cancel ends). - fn deliverSearch(ctx: ?*anyopaque, batch: pardes.Stream.Batch) bool { - const s = of(ctx); - s.loop.postEvent(.{ .search_rows = batch }) catch { - batch.deinit(s.gpa); - return false; - }; - return true; - } - - fn deliverPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void { - const s = of(ctx); - var owned = response; - s.loop.postEvent(.{ .pipe_done = owned }) catch owned.deinit(s.gpa); + const q = s.ptys.queue; + host_io.KindJob.start(s.io, s.core, &q.job_tasks, pane, serial, token, q, host_io.Inbox.pushJob); } }; @@ -2758,7 +2672,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { try std.testing.expect(core.pipe.wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); try std.testing.expect(queue.lsp_task == null); - try std.testing.expectEqual(@as(usize, 0), shell.pipe_tasks.len); + try std.testing.expectEqual(@as(usize, 0), queue.pipe_tasks.len); } } |
