summaryrefslogtreecommitdiff
path: root/dev/host_io.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/host_io.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/host_io.zig')
-rw-r--r--dev/host_io.zig42
1 files changed, 18 insertions, 24 deletions
diff --git a/dev/host_io.zig b/dev/host_io.zig
index 419c4570..f189c8ea 100644
--- a/dev/host_io.zig
+++ b/dev/host_io.zig
@@ -420,13 +420,8 @@ pub const exec_command_max = pardes.exec.command_max;
/// A pane's pty size, in cells and in pixels: a program sizes its kitty
/// graphics by the pixels (yazi's previews; pardes nested in a pane).
-pub fn ptyWinsize(core: ?*const pardes.Pardes, cols: u16, rows: u16) posix.winsize {
- var ws: posix.winsize = .{ .row = rows, .col = cols, .xpixel = 0, .ypixel = 0 };
- if (core) |c| {
- ws.xpixel = std.math.cast(u16, @as(u32, cols) * c.view().cell_pixels.w) orelse 0;
- ws.ypixel = std.math.cast(u16, @as(u32, rows) * c.view().cell_pixels.h) orelse 0;
- }
- return ws;
+pub fn ptyWinsize(size: pardes.PtySize) posix.winsize {
+ return .{ .row = size.rows, .col = size.cols, .xpixel = size.w_px, .ypixel = size.h_px };
}
pub fn forkShell(
@@ -435,8 +430,7 @@ pub fn forkShell(
prompt_rcs: *const Shell.PromptFiles,
bin: []const u8,
cwd: []const u8,
- rows: u16,
- cols: u16,
+ size: pardes.PtySize,
) !Child {
const native_cwd = filesystem.localPath(cwd) orelse cwd;
if (std.mem.indexOfScalar(u8, native_cwd, 0) != null) return error.InvalidPath;
@@ -494,7 +488,7 @@ pub fn forkShell(
else
.terminal;
const envp = ChildEnv.build(&env_slots, paging);
- const ws = ptyWinsize(core, cols, rows);
+ const ws = ptyWinsize(size);
// The child says here why it could not become the shell (its chdir or
// its exec failed, as for a script whose interpreter is not there): the
// pipe closes on exec, so the parent reads nothing when the shell runs,
@@ -1672,9 +1666,9 @@ test "the child environment replaces the launcher's terminal identity exactly on
test "shell spawn rejects invalid directories before creating a child" {
const rcs: Shell.PromptFiles = .{};
- try std.testing.expectError(error.InvalidPath, forkShell(null, 0, &rcs, "/bin/sh", "/tmp\x00/ignored", 24, 80));
+ try std.testing.expectError(error.InvalidPath, forkShell(null, 0, &rcs, "/bin/sh", "/tmp\x00/ignored", .{ .cols = 80, .rows = 24 }));
const too_long = @as([4096]u8, @splat('x'));
- try std.testing.expectError(error.NameTooLong, forkShell(null, 0, &rcs, "/bin/sh", &too_long, 24, 80));
+ try std.testing.expectError(error.NameTooLong, forkShell(null, 0, &rcs, "/bin/sh", &too_long, .{ .cols = 80, .rows = 24 }));
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
@@ -1683,12 +1677,12 @@ test "shell spawn rejects invalid directories before creating a child" {
const directory = directory_buf[0..try tmp.dir.realPath(std.testing.io, &directory_buf)];
var path_buf: [4096]u8 = undefined;
const file = try std.fmt.bufPrint(&path_buf, "{s}/file", .{directory});
- try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", file, 24, 80));
+ try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", file, .{ .cols = 80, .rows = 24 }));
const explicit_file = try std.fmt.bufPrint(&path_buf, "/n/os{s}/file", .{directory});
- try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", explicit_file, 24, 80));
+ try std.testing.expectError(error.NotDir, forkShell(null, 0, &rcs, "/bin/sh", explicit_file, .{ .cols = 80, .rows = 24 }));
const missing = try std.fmt.bufPrint(&path_buf, "{s}/missing/" ++ (std.mem.asBytes(&@as([50][6]u8, @splat("child/".*)))), .{directory});
try std.testing.expect(missing.len > 256);
- try std.testing.expectError(error.FileNotFound, forkShell(null, 0, &rcs, "/bin/sh", missing, 24, 80));
+ try std.testing.expectError(error.FileNotFound, forkShell(null, 0, &rcs, "/bin/sh", missing, .{ .cols = 80, .rows = 24 }));
}
test "a forked shell is told which terminal it is talking to" {
@@ -1711,7 +1705,7 @@ test "a forked shell is told which terminal it is talking to" {
_ = Shell.setenv("TERM", "dumb", 1);
const rcs: Shell.PromptFiles = .{};
- const child = try forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", "", .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1739,7 +1733,7 @@ test "shell spawn uses an explicit OS directory longer than 256 bytes" {
var explicit_buf: [4096]u8 = undefined;
const explicit = try std.fmt.bufPrint(&explicit_buf, "/n/os{s}", .{directory});
const rcs: Shell.PromptFiles = .{};
- const child = try forkShell(null, 0, &rcs, "/bin/sh", explicit, 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", explicit, .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1768,7 +1762,7 @@ test "a terminal is where its shell is: under a wrapper the foreground shell, ne
// A wrapper exec'd over the shell (timeout standing in for 9ns) runs
// another, two directories down, in the foreground.
{
- const child = try forkShell(null, 0, &rcs, "/bin/sh", start, 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", start, .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1787,7 +1781,7 @@ test "a terminal is where its shell is: under a wrapper the foreground shell, ne
// A job of the shell's own, gone into a/b, leaves the pane where the
// shell is.
{
- const child = try forkShell(null, 0, &rcs, "/bin/sh", start, 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", start, .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1812,7 +1806,7 @@ test "shell cwd rejects truncation and preserves an owned child path longer than
const directory = path_buf[0..try tmp.dir.realPathFile(io, nested, &path_buf)];
try std.testing.expect(directory.len > 1024);
const rcs: Shell.PromptFiles = .{};
- const child = try forkShell(null, 0, &rcs, "/bin/sh", directory, 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", directory, .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1839,7 +1833,7 @@ test "a shell whose directory was removed is not named `... (deleted)`" {
var path_buf: [4096]u8 = undefined;
const directory = path_buf[0..try tmp.dir.realPathFile(io, "gone", &path_buf)];
const rcs: Shell.PromptFiles = .{};
- const child = try forkShell(null, 0, &rcs, "/bin/sh", directory, 24, 80);
+ const child = try forkShell(null, 0, &rcs, "/bin/sh", directory, .{ .cols = 80, .rows = 24 });
defer {
_ = libc.kill(child.pid, libc.SIG.KILL);
_ = libc.waitpid(child.pid, null, 0);
@@ -1949,7 +1943,7 @@ test "a command pane's child is its shell running the one line, and its exit sta
_ = try panes.newCommand(core, id, "", "printf 'said '; exit 7");
while (core.nextEffect()) |_| {}
const rcs: Shell.PromptFiles = .{};
- const child = try forkShell(core, id, &rcs, "/bin/sh", "", 24, 80);
+ const child = try forkShell(core, id, &rcs, "/bin/sh", "", .{ .cols = 80, .rows = 24 });
defer _ = libc.close(child.file.handle);
var got: [256]u8 = undefined;
var n: usize = 0;
@@ -1980,7 +1974,7 @@ test "a command's exit is its process's, told by its watcher, whether or not its
const id = core.freeSlot().?;
_ = try panes.newCommand(core, id, "", c.line);
while (core.nextEffect()) |_| {}
- const child = try forkShell(core, id, &rcs, "/bin/sh", "", 24, 80);
+ const child = try forkShell(core, id, &rcs, "/bin/sh", "", .{ .cols = 80, .rows = 24 });
defer _ = libc.close(child.file.handle);
try std.testing.expect(watchExit(child.pid));
var got: ?libc.pid_t = null;
@@ -2021,7 +2015,7 @@ test "a command's background job outlives it and its pty, and Kill stops its who
const id = core.freeSlot().?;
_ = try panes.newCommand(core, id, dir, c.line);
while (core.nextEffect()) |_| {}
- const child = try forkShell(core, id, &rcs, "/bin/sh", dir, 24, 80);
+ const child = try forkShell(core, id, &rcs, "/bin/sh", dir, .{ .cols = 80, .rows = 24 });
if (c.kill) {
sleepMs(150);
signalTty(child.pid, child.file.handle, .term, true);