diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:57:44 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:27:20 -0300 |
| commit | 0de5fd5523faf4028b5c5e334367d28b4079aec3 (patch) | |
| tree | 5e059853da6a4a898291a429892cc66dd7ca31d9 /src/gui | |
| parent | e50c1b3fc928bf860bc6e91b0a2fea469f7e41e7 (diff) | |
| download | pardes-0de5fd5523faf4028b5c5e334367d28b4079aec3.tar.gz pardes-0de5fd5523faf4028b5c5e334367d28b4079aec3.zip | |
host_io: the shells a dead session left are one Adoptions table (Adopt's ask, adoptShell, a spawn's take, and the Adoption a terminal pane takes), where the tty and the window each kept the same three fields and the same adopt, adoptShell and spawn lookup
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index ecd9026f..8415d64e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4115,9 +4115,7 @@ const Shell = struct { grid: bool = false, /// Shells a dead session left (Adopt), each waiting for the spawn of /// the terminal pane made for it. - adoptions: [pardes.MAX_PANES]Adoption = undefined, - adoptions_len: usize = 0, - adopted: usize = 0, + adoptions: host_io.Adoptions = .{}, io: std.Io, gpa: std.mem.Allocator, fs: ?*ninep_io.Listener = null, @@ -4429,9 +4427,7 @@ const Shell = struct { fn adopt(ctx: ?*anyopaque, pane: u8) void { const s = shellOf(ctx); - if (!daemon.kept()) return s.core.reportFailure(pane, "Adopt: no pardes daemon is keeping shells for this session"); - s.adopted = 0; - daemon.adopt(); + s.adoptions.ask(s.core, pane); } fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void { @@ -4510,7 +4506,7 @@ const Shell = struct { for (rec.ptys[0..rec.nptys]) |k| { const pane = if (rec.fresh) null else s.core.panes[k.pane]; if (pane == null or !pane.?.isTerminal()) { - s.adoptShell(k.pid, k.fd); + s.adoptions.adoptShell(s.core, k.pid, k.fd); continue; } s.ptys[k.pane] = .{ .fd = k.fd, .pid = k.pid, .serial = pane.?.serial, .cmd = .{ .watched = pane.?.command != null and host_io.watchExit(k.pid), .fd = k.fd } }; @@ -4532,30 +4528,6 @@ const Shell = struct { s.follow(); } - /// One shell of a dead session (`pid` 0: the last of them was told): - /// a terminal pane made for it, as the Term word makes one, whose spawn - /// takes this pty (spawnPane). - fn adoptShell(s: *Shell, pid: libc.pid_t, fd: c_int) void { - const core = s.core; - if (pid == 0) { - var buf: [96]u8 = undefined; - return core.setMessage(core.active, if (s.adopted == 0) "Adopt: no shell of a session that died is waiting" else std.fmt.bufPrint(&buf, "Adopt: {d} shell{s} taken in; what they showed is gone", .{ s.adopted, if (s.adopted == 1) "" else "s" }) catch "Adopt: shells taken in"); - } - if (s.adoptions_len < s.adoptions.len) { - s.adoptions[s.adoptions_len] = .{ .pid = pid, .fd = fd, .pane = null }; - s.adoptions_len += 1; - if (core.adoptShell()) |id| { - s.adoptions[s.adoptions_len - 1].pane = id; - s.adopted += 1; - return; - } - s.adoptions_len -= 1; - } - _ = libc.close(fd); - var buf: [96]u8 = undefined; - core.setMessage(core.active, std.fmt.bufPrint(&buf, "Adopt: no room for shell {d}; it ends with this session", .{pid}) catch "Adopt: no room for a shell"); - } - const vtable: pardes.Host.VTable = .{ .wait_input = waitInput, .now = guiNow, @@ -4698,7 +4670,7 @@ const Shell = struct { s.saw_event = true; }, .adopted => |a| { - s.adoptShell(a.pid, a.fd); + s.adoptions.adoptShell(s.core, a.pid, a.fd); s.saw_event = true; }, }; @@ -5258,11 +5230,7 @@ fn gridPostPresent(ctx: ?*anyopaque) void { fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { const s = shellOf(ctx); s.reap(); - for (s.adoptions[0..s.adoptions_len], 0..) |a, i| if (a.pane == pane) { - std.mem.copyForwards(Adoption, s.adoptions[i .. s.adoptions_len - 1], s.adoptions[i + 1 .. s.adoptions_len]); - s.adoptions_len -= 1; - return takeShell(s, pane, a); - }; + if (s.adoptions.take(pane)) |a| return takeShell(s, pane, a); // The new shell starts before a running one goes: one that cannot // start leaves the running one be (pty/ctl's exec). const running = s.ptys[pane] != null; @@ -5289,11 +5257,9 @@ fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { }; } -const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?u8 }; - /// An adopted shell, running already, as pane `pane`'s: told the size twice /// (one it never had, then the pane's), which makes it redraw. -fn takeShell(s: *Shell, pane: u8, a: Adoption) void { +fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void { s.closePty(pane); s.gens[pane] +%= 1; s.ptys[pane] = .{ .fd = a.fd, .pid = a.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{} }; |
