diff options
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 99 |
1 files changed, 23 insertions, 76 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 543be3aa..1b00d1b9 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -97,8 +97,9 @@ 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 the +/// daemon and a replica's reader hand over. A pane's output and a worker's +/// answer 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 @@ -120,11 +121,6 @@ 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, @@ -369,8 +365,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 +754,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 +777,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; @@ -985,18 +981,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 => {}, }; @@ -1040,7 +1026,6 @@ const Own = struct { 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); @@ -1124,8 +1109,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, @@ -1648,27 +1631,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; } @@ -1877,7 +1839,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. @@ -1905,8 +1868,13 @@ 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; + }, + .fs_ready, .adopted => m.deinit(s.gpa, s.lsp_gpa), + else => s.ptys.queue.land(s.core, m), } } } @@ -1961,50 +1929,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); } }; @@ -2737,7 +2684,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); } } |
