diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 01:46:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 04:00:32 -0300 |
| commit | 969369d4b84fa1847dc3dee0e737dcd58e56c5e7 (patch) | |
| tree | e866b74b33701005eb2009ce573aef8dd4ab420f /dev/tui | |
| parent | 11f55f018a5eb0699d58627a4f2ea39c2b7f5e89 (diff) | |
| download | pardes-969369d4b84fa1847dc3dee0e737dcd58e56c5e7.tar.gz pardes-969369d4b84fa1847dc3dee0e737dcd58e56c5e7.zip | |
attach: `pardes attach [NAME]` is a client always, from a terminal a terminal's and from `pardes-gui` a window's, whatever the session was born with (the ruling of 2026-11-17: a session's own frontend is only the one it was born with), and the in-place attach deleted with what only it used (305 lines deleted, 94 added): the daemon's `attach` request and its `find` that chose (runtime/daemon.zig), `daemon.attach` and its `Answer`, `Note.attach`, the stub's second use (`stubWait`'s `child` and its `r`/`x` words, `tellStubExit`), `attachTo`'s two hand-offs and `crossAttach` (runtime/main.zig: a named attach goes straight to the replica socket, where the daemon refuses a name nobody has; a bare one takes the one detached session, else the one session, from the daemon's `list`, else names them: `bareAttach`, with a test), the terminal handed to a session (`attachTerminal`, `refuse`, the `.attach` message and its three arms: dev/tui/tui.zig), the window opened again in place (`openTheWindow`, `Shell.detached`, the queue's `.window` and its arms: dev/gui/gui.zig, dev/Inbox.zig, runtime/macos.zig), and `setState(false)`, which nothing says now (`setDetached`); test/daemon.py's attach cases expect a client (a Detach in its own terminal once, then each attach a client in `--ps`, the session detached still, its Detach exit 1 "let this client go"; the window cycles as window clients, offscreen); tui shell-test 1046/1049 (3 skipped, as the base), core-test 855/1005 (the base's less the deleted `find` test), daemon.py plain passing (gated with the next change)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 5c1945e6..42f73559 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -104,9 +104,6 @@ const Msg = union(enum) { /// The terminal's input ended: its end of file, a hangup. A session /// a daemon keeps carries on detached; any other ends. quit, - /// A terminal for this detached session, and its stub's pipe - /// (daemon.Note.attach). - attach: struct { tty: posix.fd_t, stub: posix.fd_t }, /// 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. @@ -573,7 +570,7 @@ fn surfaceHasKittyKey(surface: *const pardes.Surface, key: u64) bool { /// Where a session's terminal comes from: /dev/tty, as a plain `pardes` /// opens it; one open already (a session forked off its stub, -/// daemon.forkSession); or none, detached until one is attached (`--detach`). +/// daemon.forkSession); or none, detached from the start (`--detach`). /// The terminal a session starts on: /dev/tty, one its stub opened (an /// upgraded session's is raw already, `termios` the cooked one), or none. pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, detached }; @@ -811,9 +808,9 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, /// A terminal a session draws on, while it has one: entered (raw, the /// alternate screen, mouse and paste reports) and left (all of it put back, -/// the terminal closed) at the session's start and end, and at a detach and -/// a reattach in between (daemon.zig), its stub `daemon.stub`. One a -/// process: a second terminal on a session is a replica client of it. +/// the terminal closed) at the session's start and end, or at a detach +/// (daemon.zig), its stub `daemon.stub`. One a process, the one the session +/// was born with: an attach is a replica client of it. const Screen = struct { io: std.Io, gpa: std.mem.Allocator, @@ -1019,10 +1016,6 @@ const Own = struct { }, .search_rows => |b| b.deinit(gpa), .kind_job => |j| j.drop(), - .attach => |a| { - _ = libc.close(a.tty); - if (a.stub >= 0) _ = libc.close(a.stub); - }, .adopted => |a| _ = libc.close(a.fd), else => {}, }; @@ -1108,12 +1101,6 @@ fn clearNativeImages( fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { const loop: *Loop = @ptrCast(@alignCast(ctx)); switch (note) { - .attach => |a| if (a.tty < 0) { - if (a.stub >= 0) daemon.tellStub(a.stub, "r{s}", .{"a terminal session takes a terminal"}); - } else loop.postEvent(.{ .attach = .{ .tty = a.tty, .stub = a.stub } }) catch { - _ = libc.close(a.tty); - _ = libc.close(a.stub); - }, .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); @@ -1324,42 +1311,7 @@ const Shell = struct { if (null_fd > 2) _ = libc.close(null_fd); } daemon.tellStubDetached(); - daemon.setState(true); - } - - /// `pardes --attach`'s terminal, for a detached session: its own again, - /// entered as the first one was, sized, asked what it can do, and drawn - /// whole. One attached already takes no other (the daemon makes a second - /// a replica client). - fn attachTerminal(s: *Shell, fd: posix.fd_t, stub: posix.fd_t, cooked: ?posix.termios) void { - const screen = s.screen orelse { - _ = libc.close(fd); - return refuse(stub, "that session has no terminal of its own to attach to"); - }; - if (screen.on) { - _ = libc.close(fd); - return refuse(stub, "that session has a terminal: join it as a client, `pardes --attach=<socket>:<name>`"); - } - const tty = Screen.ttyOn(s.io, screen.buf, fd, cooked) catch { - _ = libc.close(fd); - daemon.setState(true); - return refuse(stub, "that terminal would not go raw"); - }; - screen.enter(tty) catch { - daemon.setState(true); - return refuse(stub, "that terminal would not take the screen"); - }; - daemon.stub = stub; - s.setAttended(true); - startInput(s.loop, screen) catch {}; - screen.vx.queryTerminalSend(screen.tty.writer()) catch {}; - s.core.needs_frame = true; - daemon.setState(false); - } - - /// A terminal refused: its stub told why (a test's has none). - fn refuse(stub: posix.fd_t, why: []const u8) void { - if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why}); + daemon.setDetached(); } const PtyCalls = host_io.Ptys.Calls(Shell); @@ -1662,7 +1614,6 @@ const Shell = struct { core.quit = true; return true; }, - .attach => |a| s.attachTerminal(a.tty, a.stub, null), .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), .replica => |j| { s.peers.handed(j.fd, j.view); |
