summaryrefslogtreecommitdiff
path: root/core
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 /core
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 'core')
-rw-r--r--core/Core.zig12
-rw-r--r--core/Effect.zig11
-rw-r--r--core/ninep/harness.zig2
-rw-r--r--core/replica.zig4
-rw-r--r--core/root.zig1
5 files changed, 23 insertions, 7 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 91f647d4..8616aa35 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -2013,6 +2013,16 @@ pub fn sync(p: *Pardes) void {
tagline.revealHeader(p);
}
+/// Pane `id`'s pty as its host is to size it: its grid (or `cells`, a
+/// size 9P's pty/ctl gave), in pixels at the cell of the view that sizes
+/// it: a program sizes its kitty graphics by them.
+pub fn ptySize(p: *const Pardes, id: Pane.Id, cells: ?[2]u16) pardes.PtySize {
+ const pane = p.panes[id.index()] orelse return .{ .cols = 1, .rows = 1 };
+ const c = cells orelse .{ pane.cols, pane.rows };
+ const cell = (p.views[pane.sized_by] orelse p.views[p.live].?).cell_pixels;
+ return .{ .cols = @max(c[0], 1), .rows = @max(c[1], 1), .w_px = std.math.cast(u16, @as(u32, c[0]) * cell.w) orelse 0, .h_px = std.math.cast(u16, @as(u32, c[1]) * cell.h) orelse 0 };
+}
+
/// The view typing goes into is the one its terminal is sized for
/// (`sizes`).
fn typedInto(p: *Pardes) void {
@@ -2888,7 +2898,7 @@ test "a spawn is for the pane it was made for, not whatever took the slot since"
var command: [32]u8 = undefined;
var core: *Pardes = undefined;
const vtable: Host.VTable = .{ .spawn = spawn };
- fn spawn(_: ?*anyopaque, id: pardes.Pane.Id, _: []const u8) void {
+ fn spawn(_: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: pardes.PtySize) void {
const pane = id.index();
spawns += 1;
const line = core.panes[pane].?.command.?;
diff --git a/core/Effect.zig b/core/Effect.zig
index cabfe8ea..abfe4711 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -22,6 +22,10 @@ const Host = pardes.Host;
/// to the shell itself when the shell is in the foreground.
pub const PtySignal = enum(u8) { int, term, hup, quit, kill };
+/// A pty's size as the core gives it to its host: in cells, and in pixels
+/// at the cell of the view that sizes its pane (Core.ptySize).
+pub const PtySize = struct { cols: u16, rows: u16, w_px: u16 = 0, h_px: u16 = 0 };
+
/// IO the core wants done. Payloads are inline (fixed buffers): effects are
/// queued values with no lifetime ties back into the core.
pub const WatchMode = enum { reconcile, baseline_disk };
@@ -118,14 +122,15 @@ fn performInner(p: *Pardes, e: Effect) void {
defer panes.File.syncTwins(p);
switch (e) {
// The host reads the pane (its command, its shell) as it forks,
- // so the slot must still hold the pane the spawn was for.
- .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else p.tape.host(p, .spawn, .{ s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice() }) orelse {
+ // so the slot must still hold the pane the spawn was for. It forks
+ // at the pane's grid: laid out by the step that asked (`sync`).
+ .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else p.tape.host(p, .spawn, .{ s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice(), p.ptySize(s.pane, null) }) orelse {
p.fallback.spawned[s.pane.index()] = true;
},
// A pane with no child is silent: nothing invents output on its
// screen, and the bytes are dropped rather than transcribed.
.write => |w| _ = p.tape.host(p, .pty_write, .{ w.pane, w.bytes.slice() }),
- .resize_pty => |r| _ = p.tape.host(p, .pty_resize, .{ r.pane, r.cols, r.rows }),
+ .resize_pty => |r| _ = p.tape.host(p, .pty_resize, .{ r.pane, p.ptySize(r.pane, .{ r.cols, r.rows }) }),
// A signal for a pane that closed, its slot retaken in the same
// step, would reach another pane's child.
.signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else p.tape.host(p, .pty_signal, .{ s.pane, s.sig }) orelse {},
diff --git a/core/ninep/harness.zig b/core/ninep/harness.zig
index cf75d80d..1449ae54 100644
--- a/core/ninep/harness.zig
+++ b/core/ninep/harness.zig
@@ -153,7 +153,7 @@ pub fn nameAt(list: []const Dirent, want: []const u8) ?Dirent {
/// none.
pub const starting: pardes.Host.VTable = .{ .spawn = startNothing };
-fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {}
+fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: pardes.PtySize) void {}
pub const FakeTty = struct {
taken: bool,
diff --git a/core/replica.zig b/core/replica.zig
index ae1ae6c3..3aac5e82 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -3298,7 +3298,7 @@ const TestHost = struct {
/// A host with ptys whose pump polls for a frame, as a client's does.
const PtyHost = struct {
- fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {}
+ fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: pardes.PtySize) void {}
fn poll(_: ?*anyopaque) void {}
const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll };
fn host() pardes.Host {
@@ -4238,7 +4238,7 @@ fn firstOnPair(by_dump: bool) !void {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
const Spawns = struct {
- fn spawn(ctx: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {
+ fn spawn(ctx: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: pardes.PtySize) void {
const n: *u32 = @ptrCast(@alignCast(ctx.?));
n.* += 1;
}
diff --git a/core/root.zig b/core/root.zig
index fb606909..99fb4845 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -66,6 +66,7 @@ pub const CellPixels = @import("Event.zig").CellPixels;
pub const Event = @import("Event.zig").Event;
/// What goes out (Effect.zig).
pub const PtySignal = @import("Effect.zig").PtySignal;
+pub const PtySize = @import("Effect.zig").PtySize;
pub const WatchMode = @import("Effect.zig").WatchMode;
pub const effect_path_cap = @import("Effect.zig").effect_path_cap;
pub const effect_write_cap = @import("Effect.zig").effect_write_cap;