diff options
Diffstat (limited to 'dev/tui/tui.zig')
| -rw-r--r-- | dev/tui/tui.zig | 47 |
1 files changed, 10 insertions, 37 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 1b00d1b9..ecc52df0 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -97,16 +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 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`). +/// 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). @@ -122,8 +120,6 @@ const Msg = union(enum) { paste_start, paste_end, 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). @@ -953,6 +949,7 @@ const Own = struct { .test_clock = host_io.testClock(), .peers = &l.peers, .ptys = &l.ptys, + .session = l, }; const sh = &o.sh; sh.screen = o.screen; @@ -983,7 +980,6 @@ const Own = struct { host_io.setExitWake(null, null); while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), - .adopted => |a| _ = libc.close(a.fd), else => {}, }; o.screen.art.deinit(gpa); @@ -1019,10 +1015,6 @@ 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; @@ -1054,24 +1046,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 { @@ -1103,6 +1077,9 @@ const Shell = struct { /// The session's ptys (runtime/session.zig's); a client's, an empty /// table over an empty queue. ptys: *host_io.Ptys, + /// The session's loop (its `watch`, the daemon's notes); a client's + /// and a test's, none. + session: ?*Own.Session = null, /// What `takeQueue` takes off the ptys' queue, and whether the loop /// was woken for it since it last did (one wake, not one a read ahead /// of the terminal's keys in the loop's queue). @@ -1563,7 +1540,7 @@ const Shell = struct { // without it, to be attached again. Gone before the first // frame, the reader that takes the daemon's `ok` (kept // waits on it) is not started yet: started here. - daemon.watch(s.loop, deliverNote); + if (s.session) |l| l.watch(); if (daemon.kept()) { if (!s.detached()) s.leaveTerminal(); return true; @@ -1571,11 +1548,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; }, @@ -1873,7 +1845,8 @@ const Shell = struct { // 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), + .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), + .fs_ready => {}, else => s.ptys.queue.land(s.core, m), } } |
