summaryrefslogtreecommitdiff
path: root/dev/Ptys.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 14:14:39 -0300
committerGabriel Schneider <[email protected]>2026-11-22 15:36:59 -0300
commitb0e96978b619e1111ee2fb30e3c4a48f9fac38b3 (patch)
treeda0c3c266b52c84ab6d96f1652f17b80effab342 /dev/Ptys.zig
parent85e793ae92683808d14433cb7c99ccdab4c967dc (diff)
downloadpardes-b0e96978b619e1111ee2fb30e3c4a48f9fac38b3.tar.gz
pardes-b0e96978b619e1111ee2fb30e3c4a48f9fac38b3.zip
pty: a shell forks at its pane's grid, and the core hands its host every pty's size, pixels too (pardes-term-join-9, item 2 (B), points (a) and (c)): the spawn host call took no size and both hosts forked at the session's live screen (dev/Ptys.zig `spawn`, runtime/macos.zig `spawnShell`: `core.view().screen_h/w`), so a shell started again into a pane already sized (pty/ctl's exec, a finished command pane run again by exec.zig `runCommand`, a Restore's `revivePane`) ran at the screen's size and nothing resized it, the grid unchanged and `sync` emitting nothing (`stty size` said 50 160 in a 44x158 pane); and a pty's pixels were the live view's (host_io.zig `ptyWinsize` read `core.view().cell_pixels`) whichever view sized it; now `Effect.PtySize` (cells and pixels) is what the core gives its host for `spawn` and `pty_resize`, made by `Core.ptySize` from the pane's grid (or 9P's numbers) at the cell of the view that sizes it, a spawn performed after its step's `sync` reading the laid-out grid, and the hosts fork and size from it alone (`Ptys.take` sizes an adopted shell from it too: 1x1 then the size, once, its forced redraw kept, an ioctl to the size a pty has already sending no SIGWINCH); test (test/process/terminals.zig, a new case): a Term pane's shell, the same shell started again by pty/ctl's exec and a finished command pane run again each say the grid their pty/ctl reads back (fails on the base: 50 160 against 44 158); not covered: a new command pane made over 9P is placed a step after its fork, so its first size can still be the screen's
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/Ptys.zig')
-rw-r--r--dev/Ptys.zig27
1 files changed, 13 insertions, 14 deletions
diff --git a/dev/Ptys.zig b/dev/Ptys.zig
index 583e3c38..5b8705ef 100644
--- a/dev/Ptys.zig
+++ b/dev/Ptys.zig
@@ -45,16 +45,15 @@ pub fn Calls(comptime Ctx: type) type {
fn of(ctx: ?*anyopaque) *Ctx {
return @ptrCast(@alignCast(ctx.?));
}
- pub fn spawn(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ pub fn spawn(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8, size: pardes.PtySize) void {
const s = of(ctx);
- s.ptys.spawn(s.core, id, cwd);
+ s.ptys.spawn(s.core, id, cwd, size);
}
pub fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
of(ctx).ptys.write(id, bytes);
}
- pub fn resize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void {
- const s = of(ctx);
- s.ptys.resize(s.core, id, cols, rows);
+ pub fn resize(ctx: ?*anyopaque, id: pardes.Pane.Id, size: pardes.PtySize) void {
+ of(ctx).ptys.resize(id, size);
}
pub fn signal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void {
of(ctx).ptys.signal(id, sig);
@@ -82,14 +81,14 @@ pub fn Calls(comptime Ctx: type) type {
}
/// Pane `id`'s shell, in `cwd` (empty: where its pane's directory says),
-/// or the adopted one waiting for it.
-pub fn spawn(p: *Ptys, core: *pardes.Pardes, id: pardes.Pane.Id, cwd: []const u8) void {
+/// at `size`, or the adopted one waiting for it.
+pub fn spawn(p: *Ptys, core: *pardes.Pardes, id: pardes.Pane.Id, cwd: []const u8, size: pardes.PtySize) void {
const pane = id.index();
- if (p.adoptions.take(id)) |a| return p.take(core, pane, a);
+ if (p.adoptions.take(id)) |a| return p.take(core, pane, a, size);
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = p.slots[pane] != null;
- const child = host_io.forkShell(core, pane, p.prompt_rcs, core.shellBin(), cwd, core.view().screen_h, core.view().screen_w) catch |err| {
+ const child = host_io.forkShell(core, pane, p.prompt_rcs, core.shellBin(), cwd, size) catch |err| {
if (running) return core.restartFailed(id, err);
return core.shellFailed(id, err);
};
@@ -107,7 +106,7 @@ pub fn spawn(p: *Ptys, core: *pardes.Pardes, id: pardes.Pane.Id, cwd: []const u8
/// An adopted shell, running already, as pane `pane`'s: told the size
/// twice (a size it never had, then the pane's), which makes it redraw.
-fn take(p: *Ptys, core: *pardes.Pardes, pane: u8, a: host_io.Adoption) void {
+fn take(p: *Ptys, core: *pardes.Pardes, pane: u8, a: host_io.Adoption, size: pardes.PtySize) void {
p.close(.at(pane));
p.gens[pane] +%= 1;
p.slots[pane] = .{ .fd = a.fd, .pid = a.pid };
@@ -117,7 +116,7 @@ fn take(p: *Ptys, core: *pardes.Pardes, pane: u8, a: host_io.Adoption) void {
if (host_io.shellCwd(a.pid, &lbuf)) |wd| core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (core.panes[pane]) |pn| p.resize(core, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1));
+ p.resize(.at(pane), size);
p.read(core, pane);
}
@@ -144,9 +143,9 @@ pub fn write(p: *Ptys, id: pardes.Pane.Id, bytes: []const u8) void {
if (p.slots[id.index()]) |pt| _ = host_io.writeFd(pt.fd, bytes);
}
-pub fn resize(p: *Ptys, core: *const pardes.Pardes, id: pardes.Pane.Id, cols: u16, rows: u16) void {
+pub fn resize(p: *Ptys, id: pardes.Pane.Id, size: pardes.PtySize) void {
const pt = p.slots[id.index()] orelse return;
- const ws = host_io.ptyWinsize(core, cols, rows);
+ const ws = host_io.ptyWinsize(size);
_ = posix.system.ioctl(pt.fd, TIOCSWINSZ, @intFromPtr(&ws));
}
@@ -290,7 +289,7 @@ fn testing(queue: *Inbox) Ptys {
}
fn testShell(p: *Ptys, pane: u8) !libc.pid_t {
- const child = try host_io.forkShell(null, pane, p.prompt_rcs, "/bin/sh", "", 24, 80);
+ const child = try host_io.forkShell(null, pane, p.prompt_rcs, "/bin/sh", "", .{ .cols = 80, .rows = 24 });
p.slots[pane] = .{ .fd = child.file.handle, .pid = child.pid };
p.slots[pane].?.reader = try p.queue.startReader(.{ .handle = child.file.handle, .flags = .{ .nonblocking = false } }, .at(pane), p.gens[pane]);
return child.pid;