diff options
Diffstat (limited to 'dev/host_io.zig')
| -rw-r--r-- | dev/host_io.zig | 42 |
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); |
