diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 12 | ||||
| -rw-r--r-- | core/Effect.zig | 11 | ||||
| -rw-r--r-- | core/ninep/harness.zig | 2 | ||||
| -rw-r--r-- | core/replica.zig | 4 | ||||
| -rw-r--r-- | core/root.zig | 1 |
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; |
