diff options
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index dce71fd5..bf051e9a 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -710,7 +710,7 @@ const Tty = struct { while (t.loop.tryEvent() catch null) |ev| switch (ev) { .said => |msg| switch (msg) { .unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b), - .checked => {}, + .checked, .ended, .left => {}, }, .paste => |b| t.sh.gpa.free(@constCast(b)), else => {}, @@ -797,6 +797,22 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, screen.leave(); Said.no(io, "'{s}' let this client go (a Detach in it, or the session's end)", .{session}); }, + .left => { + screen.leave(); + var said: [600]u8 = undefined; + std.Io.File.stderr().writeStreamingAll(io, std.fmt.bufPrint(&said, "pardes: detached from '{s}', which is still running; come back with `pardes attach {s}`\n", .{ session, session }) catch "pardes: detached\n") catch {}; + std.process.exit(0); + }, + .ended => |code| { + screen.leave(); + // A pair's client is its session's parent: its status once it + // is gone, as a terminal's job ends with its program. + if (opts.pair != null) { + var status: c_int = 0; + while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} + } + std.process.exit(code); + }, .failed => { screen.leave(); Said.no(io, "{s}", .{start.said()}); @@ -1256,10 +1272,10 @@ const Shell = struct { /// and the shell has its terminal again), the session left running. fn detach(ctx: ?*anyopaque) void { const s = of(ctx); - // A replica client's: its link ends. + if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon lists this session (it is its terminal's job)"); + // A replica client's: its last word, and its link ends. if (s.peers.detach(s.core.live)) return; if (s.detached()) return s.core.reportFailure(s.core.view().active, "Detach: detached already (no terminal of its own)"); - if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon lists this session (it is its terminal's job)"); s.leaveTerminal(); } @@ -1600,10 +1616,10 @@ const Shell = struct { }; if (echo) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); c.take(said); - if (said == .refused) return true; + if (said == .refused or said == .ended or said == .left) return true; } else switch (said) { .unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b), - .checked => {}, + .checked, .ended, .left => {}, }, .link_gone => if (s.client) |c| { c.link.quit = true; |
