From d1d5d3cfb18841604bba2057eeb3598f729b4475 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 02:56:53 -0300 Subject: client #1, the views indexed: a view's share of the session is Pardes.View (the ~42 fields views.fields named: size, cell metrics, columns, rects, focus, jumps, pointer, gestures, prefixes, frontend), one of Pardes.views[4] (null when closed), the live one views[live] through Pardes.view() (index field `view` renamed `live`); going into another view is the index plus the panes' shares, which stay swapped (park and unpark now move only Pane.pv); views.zig loses fields, Part over Pardes, Parked, kept, emptied and the session half of every copy, and a pane closing leaves every view's layout at once (views.gone, at the two places a slot is freed) instead of the serials each parked view kept; drawOne and within put the drawn view's own share back whole; the views are in the digest now (tape's per-field parts name views[k].field), so a fresh view's col_x/col_w default to zeros, not undefined; the dump keeps every open view in the core and the panes' shares of the others under `shares`; an image from before (live view as the core's own fields, the rest under `views`) loads them into views[] once; the ~2,400 references rewritten mechanically from the compiler's errors (p.active is p.view().active, `const v = p.view()` hoisted in 823 places), Kind.zig (4 lines) and addon_test.zig (3) among them, macos.zig by pattern (not compiled here); tape's watched host writes read the live view's frontend and active; perf.zig's accessor lines change its harness hash, the debug baselines re-keyed to it (their numbers the base's); no golden changes; gates: core-test 956/956 both, unit-test 1487/1488 tui and 1530/1531 gui, behaviour-test 248/248 both, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed tui, replicas ok Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Core.zig | 498 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 259 insertions(+), 239 deletions(-) (limited to 'src/Core.zig') diff --git a/src/Core.zig b/src/Core.zig index bbacc536..7fe4f2e4 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -85,10 +85,97 @@ const tape = pardes.tape; const test_api = pardes.test_api; const themes = pardes.themes; const turn = &pardes.turn; -const views = pardes.views; +const Views = pardes.views; const Pardes = @This(); +/// One client's view of the session (views.zig): its screen and layout, +/// its focus, its pointer and gestures, its jumps, its key prefixes. +pub const View = struct { + pub const replica = .{ .len = .{ .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } } }; + + screen_w: u16 = 0, + screen_h: u16 = 0, + cell_pixels: CellPixels = .{}, + row_metrics: RowMetrics = .{}, + ncol: usize = 0, + cols: [MAX_COLS]Column = @splat(.{}), + /// Each column's tag and the workspace's: Texts like a pane's tag, with + /// no prefix, showing a default until someone edits them. Not the + /// Column's: a view opened takes the live one's columns (Views.open) but + /// tags of its own. + col_tags: [MAX_COLS]Text = @splat(.{ .what = .column }), + rects: [MAX_PANES]Rect = @splat(.{}), + col_x: [MAX_COLS]u16 = @splat(0), + col_w: [MAX_COLS]u16 = @splat(0), + active: usize = 0, + /// The places jumped from (Jump.zig). + jumps: Jump = .{}, + /// acme's activecol (dat.c:37), by column serial, 0 for none: the + /// column last typed in (acme.c:487), clicked in with the select button + /// (acme.c:659), dropped into by a grip (acme.c:640), or given a new + /// pane (util.c:467). Where the acme placement puts new panes + /// (exec.placeNew). A Look click moves the keyboard but not this. + active_column: u32 = 0, + /// The live view's frontend (Event.frontend): a window, what it draws and + /// the words it takes (builtins.zig `here`); it starts as + /// `Options.windowed` says. + frontend: Frontend = .{ .windowed = false }, + drag: mouse.Drag = .none, + /// A press a terminal's program took (mouse.programMouse): its drags + /// and release are the program's too, wherever the pointer goes. + mouse_grab: ?mouse.Grab = null, + /// Whether the host window has the keyboard (Event.focus), and the pane + /// whose program was last told it has it (reportFocus). + window_focused: bool = true, + focus_told: ?struct { id: usize, serial: u32 } = null, + hover_col: u16 = 0, + hover_row: u16 = 0, + pointer_raw_col: u16 = 0, + pointer_raw_row: u16 = 0, + pointer_body_hit: ?Mouse.BodyHit = null, + pointer_tag_hit: ?TagHit = null, + raw_hover_intent: bool = false, + /// A pixel shell's window, which hears the pointer leave it: only then + /// does /status say whether the pointer is over it (a terminal's mouse + /// reports never say it left, so a tty would claim it for ever). + pointer_inside: bool = false, + /// The last plain B1 click, for acme's double-click (text.c:881, + /// textselect: a second click at the same point within 500 ms). + last_click: ?struct { id: usize, on_tag: bool, row: i32, col: i32, ms: i64 } = null, + /// The button an Alt- or Super-click of button 1 stands for, from its + /// press through its release (mouse.emulateButton). + click_as: ?Mouse.Button = null, + /// A B1 chord's edits share the undo point it took (mouse.zig). + chord_hold: bool = false, + wheel_guard: u8 = 0, + /// A key that waits for the next: the leader (SPC) or the window prefix + /// (Ctrl-w), one at a time. + prefix: enum { none, leader, window } = .none, + /// The register the running normal command names (`"`); 0 for the + /// default one. + register: u21 = 0, + /// Window mode's outlined pane (layout.windowKey); null outside it. + window_pick: ?usize = null, + leader_keys: [4]u8 = undefined, + leader_n: u8 = 0, + /// The keyboard is on a header: a column's tag, or the workspace's. + header: ?Header = null, + /// A mouse sweep is extending the focused header's selection. + header_drag: bool = false, + /// A middle or right sweep held over a column's or the workspace's tag. + header_sweep: ?mouse.HeaderSweep = null, + header_scroll: usize = 0, + /// The focused header's first line on screen, which follows its caret + /// when it has more lines than rows. + header_top: usize = 0, + /// middle+left chord argument: a kept left selection captured by a left + /// press during an active middle select-drag; consumed on middle release + chord_arg: ?[]u8 = null, + clip_pending: ?edit.ClipRequest = null, +}; + + gpa: std.mem.Allocator, image_gpa: std.mem.Allocator, /// Its kinds of pane (Kind.zig): the compiled-in ones, then what addons @@ -97,10 +184,6 @@ kinds: pardes.Kind.Registry = .{}, pdf_gpa: std.mem.Allocator, tree_sitter_gpa: std.mem.Allocator, opts: Options, -screen_w: u16, -screen_h: u16, -cell_pixels: CellPixels = .{}, -row_metrics: RowMetrics = .{}, resize_count: usize = 0, panes: [MAX_PANES]?*Pane = @splat(null), @@ -108,23 +191,12 @@ reserved_slots: [MAX_PANES]bool = @splat(false), /// Deferred teardown of dropped panes (see RetiredPanes). retired_panes: RetiredPanes = .{}, // layout: columns own x by weight; panes own y by vweight within a column. -ncol: usize = 0, -cols: [MAX_COLS]Column = @splat(.{}), -/// Each column's tag and the workspace's: Texts like a pane's tag, with -/// no prefix, showing a default until someone edits them. Not the -/// Column's: a view opened takes the live one's columns (views.open) but -/// tags of its own. -col_tags: [MAX_COLS]Text = @splat(.{ .what = .column }), next_column_serial: u32 = 1, /// A pane or column on its way to another window (Handover.zig). handover: Handover = .{}, global_tag: Text = .{ .what = .workspace }, // derived each sync -rects: [MAX_PANES]Rect = @splat(.{}), -col_x: [MAX_COLS]u16 = undefined, -col_w: [MAX_COLS]u16 = undefined, -active: usize = 0, /// The files opened lately, closed ones too (recent.zig): `Recent`, /// /recent, and the jumplist's way back to a closed pane. recent: recent_files.List = .{}, @@ -144,8 +216,6 @@ twin_groups: std.ArrayList(pardes.panes.File.TwinGroup) = .empty, /// what changed. mousein_buttons: u8 = 0, next_twin: u32 = 1, -/// The places jumped from (Jump.zig). -jumps: Jump = .{}, look_src: [MAX_PANES]u32 = undefined, n_look_src: usize = 0, look_walk_owner: ?u32 = null, @@ -170,12 +240,6 @@ session_dir: [limits.host_path_cap]u8 = undefined, /// slot: the effect then carries none, and perform gives the host this. spawn_dirs: [MAX_PANES]?[]u8 = @splat(null), session_dir_len: ?u16 = null, -/// acme's activecol (dat.c:37), by column serial, 0 for none: the -/// column last typed in (acme.c:487), clicked in with the select button -/// (acme.c:659), dropped into by a grip (acme.c:640), or given a new -/// pane (util.c:467). Where the acme placement puts new panes -/// (exec.placeNew). A Look click moves the keyboard but not this. -active_column: u32 = 0, settings: config.Runtime = .{ .font = .{ .tagline_percent = config.gui_tagline_font_percent } }, locations_config: locations.Config = .{}, locations_cache: locations.Cache = .{}, @@ -193,42 +257,11 @@ theme_file_pane: u8 = 0, chrome: colors.ChromeTheme = colors.initial_chrome, /// Every drawn frame's timings (FrameStats: the Debug box, PARDES_FRAMES). frames: FrameStats = .{}, -/// The live view's frontend (Event.frontend): a window, what it draws and -/// the words it takes (builtins.zig `here`); it starts as -/// `Options.windowed` says. -frontend: Frontend = .{ .windowed = false }, quit: bool = false, /// A detached session with no frontend attached: nothing renders, so /// no input ever dismisses a message (Messages.expireUnattended). unattended: bool = false, haptic: HapticSlot = if (platform == .macos) .none else {}, -drag: mouse.Drag = .none, -/// A press a terminal's program took (mouse.programMouse): its drags -/// and release are the program's too, wherever the pointer goes. -mouse_grab: ?mouse.Grab = null, -/// Whether the host window has the keyboard (Event.focus), and the pane -/// whose program was last told it has it (reportFocus). -window_focused: bool = true, -focus_told: ?struct { id: usize, serial: u32 } = null, -hover_col: u16 = 0, -hover_row: u16 = 0, -pointer_raw_col: u16 = 0, -pointer_raw_row: u16 = 0, -pointer_body_hit: ?Mouse.BodyHit = null, -pointer_tag_hit: ?TagHit = null, -raw_hover_intent: bool = false, -/// A pixel shell's window, which hears the pointer leave it: only then -/// does /status say whether the pointer is over it (a terminal's mouse -/// reports never say it left, so a tty would claim it for ever). -pointer_inside: bool = false, -/// The last plain B1 click, for acme's double-click (text.c:881, -/// textselect: a second click at the same point within 500 ms). -last_click: ?struct { id: usize, on_tag: bool, row: i32, col: i32, ms: i64 } = null, -/// The button an Alt- or Super-click of button 1 stands for, from its -/// press through its release (mouse.emulateButton). -click_as: ?Mouse.Button = null, -/// A B1 chord's edits share the undo point it took (mouse.zig). -chord_hold: bool = false, /// The look just run found nothing (look.zig missed). look_missed: bool = false, /// The look being run opens a .diff or .patch as text, not its +Diff: @@ -240,7 +273,6 @@ look_hover_wait: ?look.LookHoverWait = null, look_hover_refused: ?look.LookHoverWait = null, look_hover_preview: ?look.LookHoverPreview = null, pdf_hover_preview: if (pdf_enabled) ?look.PdfWordPreview else void = if (pdf_enabled) null else {}, -wheel_guard: u8 = 0, /// While a key is replayed across the ranges (normal.replaySels): which /// range this pass is, in document order, how many there are, and /// whether this is the first pass; outside a replay, the one range and @@ -249,29 +281,6 @@ multi_first: bool = true, multi_stop: bool = false, multi_index: usize = 0, multi_count: usize = 1, -/// The register the running normal command names (`"`); 0 for the -/// default one. -register: u21 = 0, -/// A key that waits for the next: the leader (SPC) or the window prefix -/// (Ctrl-w), one at a time. -prefix: enum { none, leader, window } = .none, -/// Window mode's outlined pane (layout.windowKey); null outside it. -window_pick: ?usize = null, -leader_keys: [4]u8 = undefined, -leader_n: u8 = 0, -/// The keyboard is on a header: a column's tag, or the workspace's. -header: ?Header = null, -/// A mouse sweep is extending the focused header's selection. -header_drag: bool = false, -/// A middle or right sweep held over a column's or the workspace's tag. -header_sweep: ?mouse.HeaderSweep = null, -header_scroll: usize = 0, -/// The focused header's first line on screen, which follows its caret -/// when it has more lines than rows. -header_top: usize = 0, -/// middle+left chord argument: a kept left selection captured by a left -/// press during an active middle select-drag; consumed on middle release -chord_arg: ?[]u8 = null, /// how many `execute` calls are on the stack — see max_exec_depth exec_depth: u8 = 0, /// An exec waiting on the REPL question (`Pane.Prompt.repl_choice`): @@ -333,7 +342,6 @@ registers: Registers = .{}, macro: Macro = .{}, /// an edited text nothing kept (a tag's shown text): see edit.retireEditText retired_edit: ?[]u8 = null, -clip_pending: ?edit.ClipRequest = null, /// the last serialized dump (gpa-owned), read by the write_dump effect dump_out: ?[]u8 = null, /// Where the last Dump goes as a file of its own (`Dump export`; gpa- @@ -356,14 +364,16 @@ surface: Surface = .{}, /// presentation, its own, in no digest and no rollback copy. Null on a /// session's own core. echo: ?*pardes.echo.Echo = null, -/// The view the fields above are of: whose layout, focus, pointer and -/// panes' cursors and scroll (views.zig). `views_open` says which views -/// there are, one a window or terminal; each not live is in `parked`. -view: u8 = 0, +/// The live view, `views[live]` (`view()`): whose input the session +/// takes now, and whose share of the panes is in their own fields +/// (views.zig). `views_open` says which views there are, one a window +/// or terminal each. +live: u8 = 0, views_open: u8 = 1, -/// The open views kept for their clients' rejoin (views.away). +/// The open views kept for their clients' rejoin (Views.away). views_away: u8 = 0, -parked: [views.max]?*views.Parked = @splat(null), +/// Each open view (`views_open`); a closed one is null. +views: [Views.max]?View = @splat(null), /// The views no frontend here draws: a replica client's, which its own /// process draws (src/replica.zig). A pump skips them. undrawn: u8 = 0, @@ -396,9 +406,8 @@ pub const replica = .{ // Drained by every pump before its digest; a replica's queues // are its own. "effects", "effects_head", "effects_len", "in_q", "in_head", "in_len", - // The views not live: written whenever one goes out, so the - // live one's slot is stale (views.zig). - "parked", "undrawn", + // The views no frontend here draws (views.zig). + "undrawn", // How this process was started, and the last dump it made for // its host to write: a session loaded elsewhere has its own. "opts", "dump_out", "dump_export", @@ -409,7 +418,7 @@ pub const replica = .{ // session's closed panes, and the files of a host with no file // system of its own. .authority = .{ "host", "fs", "store", "recent", "db", "fallback" }, - .len = .{ .{ "look_src", "n_look_src" }, .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" }, .{ "session_dir", "session_dir_len" } }, + .len = .{ .{ "look_src", "n_look_src" }, .{ "session_dir", "session_dir_len" } }, }; /// The message row's entry points, called from everywhere as @@ -467,13 +476,15 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { .pdf_gpa = opts.pdf_allocator orelse gpa, .tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa, .opts = opts, - .frontend = .{ .windowed = opts.windowed }, .tty_toggle = opts.tty_toggle, - .col_tags = @splat(.{ .what = .column, .gpa = gpa }), + .views = .{ View{ + .frontend = .{ .windowed = opts.windowed }, + .col_tags = @splat(.{ .what = .column, .gpa = gpa }), + .screen_w = opts.cols, + .screen_h = opts.rows, + }, null, null, null }, .global_tag = .{ .what = .workspace, .gpa = gpa }, .fs = .{}, - .screen_w = opts.cols, - .screen_h = opts.rows, .scratch = .init(gpa), .frame_arena = .init(opts.frame_allocator orelse gpa), .fallback = .{ .gpa = gpa }, @@ -579,12 +590,12 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { _ = try p.newShell(1, ""); _ = try p.newShell(2, ""); for (p.panes[0..3]) |slot| slot.?.greet = true; - p.ncol = 2; - p.cols[0].n = 2; - p.cols[0].panes[0] = 0; - p.cols[0].panes[1] = 1; - p.cols[1].n = 1; - p.cols[1].panes[0] = 2; + p.view().ncol = 2; + p.view().cols[0].n = 2; + p.view().cols[0].panes[0] = 0; + p.view().cols[0].panes[1] = 1; + p.view().cols[1].n = 1; + p.view().cols[1].panes[0] = 2; }, .shell => { _ = try p.newShell(0, ""); @@ -616,9 +627,10 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { /// The layout every single-pane boot starts from. fn oneColumn(p: *Pardes) void { - p.ncol = 1; - p.cols[0].n = 1; - p.cols[0].panes[0] = 0; + const v = p.view(); + v.ncol = 1; + v.cols[0].n = 1; + v.cols[0].panes[0] = 0; } /// The recent list's own allocator: it is kept best effort (a file not @@ -750,8 +762,7 @@ pub fn deinit(p: *Pardes) void { slot.* = null; }; const gpa = p.gpa; - views.deinit(p); - for (&p.col_tags) |*t| t.deinit(gpa); + Views.deinit(p); p.global_tag.deinit(gpa); p.registers.deinit(gpa); p.macro.deinit(gpa); @@ -761,7 +772,6 @@ pub fn deinit(p: *Pardes) void { p.fallback.deinit(); if (p.last_dump) |d| gpa.free(d); if (p.custom_theme) |theme_value| gpa.free(theme_value.name); - if (p.chord_arg) |a| gpa.free(a); for (p.spawn_dirs) |d| if (d) |dir| gpa.free(dir); p.pipe.deinit(gpa); p.stream.deinit(gpa); @@ -824,18 +834,19 @@ pub fn takeRestore(p: *Pardes) ?[]const u8 { /// and `CSI O` when it gives it up, to another pane, a tag or header, /// or another window. fn reportFocus(p: *Pardes) void { - const want: @FieldType(Pardes, "focus_told") = blk: { - if (!p.window_focused or p.header != null) break :blk null; - const pane = p.panes[p.active] orelse break :blk null; + const v = p.view(); + const want: @FieldType(View, "focus_told") = blk: { + if (!v.window_focused or v.header != null) break :blk null; + const pane = p.panes[v.active] orelse break :blk null; if (pane.focus != .body) break :blk null; - break :blk .{ .id = p.active, .serial = pane.serial }; + break :blk .{ .id = v.active, .serial = pane.serial }; }; - if (std.meta.eql(want, p.focus_told)) return; - if (p.focus_told) |old| if (p.panes[old.id]) |pane| { + if (std.meta.eql(want, v.focus_told)) return; + if (v.focus_told) |old| if (p.panes[old.id]) |pane| { if (pane.serial == old.serial and pardes.panes.terminal.reportsFocus(pane)) p.emitWrite(old.id, "\x1b[O"); }; if (want) |new| if (pardes.panes.terminal.reportsFocus(p.panes[new.id].?)) p.emitWrite(new.id, "\x1b[I"); - p.focus_told = want; + v.focus_told = want; } pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void { @@ -922,7 +933,7 @@ pub fn adoptShell(p: *Pardes) ?u8 { for (p.panes) |slot| if (slot) |pn| { newest = @max(newest, pn.serial); }; - _ = p.executeBuiltinLine(p.active, "Term"); + _ = p.executeBuiltinLine(p.view().active, "Term"); for (p.panes, 0..) |slot, id| if (slot) |pn| if (pn.serial > newest and pn.isTerminal()) { pn.greet = false; return @intCast(id); @@ -1043,18 +1054,23 @@ fn applyWatchedFileChanged(p: *Pardes, id: u8, bytes: []const u8) bool { false; } +/// The live view. +pub inline fn view(p: anytype) if (@typeInfo(@TypeOf(p)).pointer.attrs.@"const") *const View else *View { + return &p.views[p.live].?; +} + /// A view of its own for a new client (a second window, a terminal /// `pardes --attach`ed), as the live one is laid out; null at -/// views.max. Not live until `toView`. +/// Views.max. Not live until `toView`. pub fn openView(p: *Pardes) ?u8 { const taped = tape.enter(p, .open_view); defer tape.leave(p, taped); // Every view taken: one kept for a client that has not come back - // for it (views.away) goes first. ponytail: no timer lets one go; + // for it (Views.away) goes first. ponytail: no timer lets one go; // until its place is wanted it costs a parked slot, and a terminal // it sized last keeps that size until another view types into it. - if (@popCount(p.views_open) == views.max and p.views_away != 0) { - views.close(p, @ctz(p.views_away)); + if (@popCount(p.views_open) == Views.max and p.views_away != 0) { + Views.close(p, @ctz(p.views_away)); p.sync(); } // What was queued since the last pump (a leaving client's view @@ -1063,7 +1079,7 @@ pub fn openView(p: *Pardes) ?u8 { // loaded from a dump has no queue (Replica.initDump). p.settle(); p.needs_frame = true; - return views.open(p); + return Views.open(p); } /// The client of view `k` gone: its view goes, the others stay. The @@ -1071,7 +1087,7 @@ pub fn openView(p: *Pardes) ?u8 { pub fn closeView(p: *Pardes, k: u8) void { const taped = tape.enter(p, .{ .close_view = k }); defer tape.leave(p, taped); - views.close(p, k); + Views.close(p, k); p.sync(); // What its sync queued (a terminal it sized, sized again) done here, // in its own unit on every side: the session's next pump is another @@ -1081,22 +1097,22 @@ pub fn closeView(p: *Pardes, k: u8) void { } /// The last client of a session no one else watches gone: its view -/// goes, and the session's own is laid out as it was (views.closeKeeping), +/// goes, and the session's own is laid out as it was (Views.closeKeeping), /// which the client's rejoin copies. Settled as `closeView` is. pub fn leaveView(p: *Pardes, k: u8) void { const taped = tape.enter(p, .{ .leave_view = k }); defer tape.leave(p, taped); - views.closeKeeping(p, k); + Views.closeKeeping(p, k); p.sync(); p.settle(); } /// The client of view `k` gone, to join again for it (an Upgrade's -/// rejoin, a divergence's): its view kept as it is (views.away). +/// rejoin, a divergence's): its view kept as it is (Views.away). pub fn awayView(p: *Pardes, k: u8) void { const taped = tape.enter(p, .{ .away_view = k }); defer tape.leave(p, taped); - views.away(p, k); + Views.away(p, k); } /// A client back for view `k`, kept for it (`awayView`): its own again, @@ -1105,7 +1121,7 @@ pub fn awayView(p: *Pardes, k: u8) void { pub fn rejoinView(p: *Pardes, k: u8) bool { const taped = tape.enter(p, .{ .rejoin_view = k }); defer tape.leave(p, taped); - if (!views.isAway(p, k)) return false; + if (!Views.isAway(p, k)) return false; p.views_away &= ~(@as(u8, 1) << @intCast(k)); p.settle(); p.needs_frame = true; @@ -1114,10 +1130,10 @@ pub fn rejoinView(p: *Pardes, k: u8) bool { /// Into view `k`, before the input its client sent. pub fn toView(p: *Pardes, k: u8) void { - if (k == p.view) return; + if (k == p.live) return; const taped = tape.enter(p, .{ .to_view = k }); defer tape.leave(p, taped); - views.to(p, k); + Views.to(p, k); } /// Something changed the core without going through `update` -- a watched @@ -1324,6 +1340,7 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { /// log, and the 9P write that asked for it fails with it, as a failed /// Save's does. pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void { + const v = p.view(); const taped = tape.enter(p, .{ .dump_failed = .{ .path = path, .err = err } }); defer tape.leave(p, taped); var what: [limits.host_path_cap + 8]u8 = undefined; @@ -1333,16 +1350,16 @@ pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void { const parent = parentTrouble(path, err); var said: [limits.host_path_cap + 48]u8 = undefined; if (parent.denied and parent.kind == null) - p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: permission denied", .{operation}) catch "Dump: permission denied") + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: permission denied", .{operation}) catch "Dump: permission denied") else if (parent.kind != null and parent.kind != .directory) - p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent.dir }) catch "Dump: not a directory") + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent.dir }) catch "Dump: not a directory") else if (parent.missing) - p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch "Dump: no such directory") + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch "Dump: no such directory") else - p.reportError(p.active, operation, err); + p.reportError(v.active, operation, err); // In the words the message row has, so the write's err is the one // record of it (its msg goes: 9p_io, dropMessage). - p.noteLateFailure(p.active); + p.noteLateFailure(v.active); } pub fn fsPayload(p: *const Pardes, r: ctlfs.Reply) []const u8 { @@ -1401,13 +1418,13 @@ pub fn pump(p: *Pardes, host: Host) !void { // drawing what nobody looked at. if (v.watched) |f| if (!f(h.ctx)) return; // The other views first, each into its own window or terminal. - if (views.several(p)) try views.drawOthers(p, h); + if (Views.several(p)) try Views.drawOthers(p, h); // A replica client's view live (its input the last): its own // process draws it. - if (p.undrawn & (@as(u8, 1) << @intCast(p.view)) == 0) { + if (p.undrawn & (@as(u8, 1) << @intCast(p.live)) == 0) { _ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept }); p.frames.mark_update = FrameStats.nowNs(); - p.frames.view = if (p.panes[p.active]) |pane| pane.scroll() else 0; + p.frames.view = if (p.panes[p.view().active]) |pane| pane.scroll() else 0; const surface = try p.render(p.frame_arena.allocator()); p.frames.mark_render = FrameStats.nowNs(); if (v.present) |f| f(h.ctx, surface); @@ -1471,7 +1488,7 @@ pub fn serveFs(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { // addr write then its close costs no frame between them. const drawn = if (ctlfs.Node.target(req.node)) |t| !(t == .pane and (t.pane.file == .addr or t.pane.file == .limit or t.pane.file == .mark)) else true; if (drawn) p.needs_frame = true; - p.raw_hover_intent = false; + p.view().raw_hover_intent = false; look.cancelLookHover(p); p.fs.serving = true; p.fs.lsp_answer_at = null; @@ -1498,6 +1515,7 @@ pub fn serveFs(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { } pub fn update(p: *Pardes, ev: Event) void { + const v = p.view(); const taped = tape.enter(p, .{ .update = ev }); defer tape.leave(p, taped); defer pardes.panes.File.syncTwins(p); @@ -1522,7 +1540,7 @@ pub fn update(p: *Pardes, ev: Event) void { else => false, }; if (!hover_stays) { - p.raw_hover_intent = false; + v.raw_hover_intent = false; look.cancelLookHover(p); } switch (ev) { @@ -1530,7 +1548,7 @@ pub fn update(p: *Pardes, ev: Event) void { for (p.panes) |slot| { if (slot) |pane| Messages.dismissMessage(p, pane); } - p.clip_pending = null; + v.clip_pending = null; }, .tick => { Stream.step(p); @@ -1547,17 +1565,17 @@ pub fn update(p: *Pardes, ev: Event) void { }; switch (ev) { .resize => |sz| { - if (sz.row_metrics) |metrics| p.row_metrics = metrics; + if (sz.row_metrics) |metrics| v.row_metrics = metrics; if (comptime pdf_enabled) { var before: [MAX_PANES]?pardes.panes.Pdf.Viewport = @splat(null); for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; if (pane.pdf != null) before[id] = pardes.panes.Pdf.paneViewport(p, pane); } - p.screen_w = sz.cols; - p.screen_h = sz.rows; - p.cell_pixels.w = @max(1, sz.cell_pixels.w); - p.cell_pixels.h = @max(1, sz.cell_pixels.h); + v.screen_w = sz.cols; + v.screen_h = sz.rows; + v.cell_pixels.w = @max(1, sz.cell_pixels.w); + v.cell_pixels.h = @max(1, sz.cell_pixels.h); layout.compute(p); for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; @@ -1570,8 +1588,8 @@ pub fn update(p: *Pardes, ev: Event) void { } } } else { - p.screen_w = sz.cols; - p.screen_h = sz.rows; + v.screen_w = sz.cols; + v.screen_h = sz.rows; } p.resize_count += 1; }, @@ -1611,7 +1629,7 @@ pub fn update(p: *Pardes, ev: Event) void { if (comptime pdf_enabled) { if (scroll.pane < MAX_PANES) { if (p.panes[scroll.pane]) |pane| { - if (pane.hasPdf() and p.frontend.native_images) + if (pane.hasPdf() and v.frontend.native_images) _ = pardes.panes.Pdf.scrollPane(p, pane, @floatCast(scroll.delta_pixels), scroll.glide); } } @@ -1621,21 +1639,21 @@ pub fn update(p: *Pardes, ev: Event) void { p.typedInto(); edit.applyPaste(p, bytes); }, - .command => |line| _ = p.executeBuiltinLine(p.active, line), + .command => |line| _ = p.executeBuiltinLine(v.active, line), .focus => |focused| { - p.window_focused = focused; - if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(p.active, newer_build_words); + v.window_focused = focused; + if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(v.active, newer_build_words); }, .handed => |h| p.handover.finish(p, h.seq, h.to, h.failure), .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*), .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes), .frontend => |f| { - p.frontend = f; + v.frontend = f; }, .pointer_leave => { - p.pointer_inside = false; - p.pointer_body_hit = null; - p.pointer_tag_hit = null; + v.pointer_inside = false; + v.pointer_body_hit = null; + v.pointer_tag_hit = null; }, .tick => { mouse.edgeScroll(p); @@ -1712,12 +1730,13 @@ pub fn noteLateFailure(p: *Pardes, id: usize) void { /// The frontend drew a frame: a pointer resting on it follows what is /// under it now, a drag's moving end and a look-hover's word. pub fn presented(p: *Pardes) void { + const v = p.view(); const taped = tape.enter(p, .presented); defer tape.leave(p, taped); - if (p.pointer_inside and p.drag != .none) { - p.hover_col = p.pointer_raw_col; - p.hover_row = p.pointer_raw_row; - mouse.dragUpdate(p, p.pointer_raw_col, p.pointer_raw_row, p.pointer_body_hit); + if (v.pointer_inside and v.drag != .none) { + v.hover_col = v.pointer_raw_col; + v.hover_row = v.pointer_raw_row; + mouse.dragUpdate(p, v.pointer_raw_col, v.pointer_raw_row, v.pointer_body_hit); } look.refreshLookHoverFromRaw(p); } @@ -1733,12 +1752,13 @@ pub fn windowOpacityDone(p: *Pardes, applied: u8, failure: ?[]const u8) void { // the same command will arm a new request. p.settings.window_opacity = applied; var buf: [256]u8 = undefined; - p.setMessage(p.active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch "WindowOpacity: compositor rejected the request"); + p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch "WindowOpacity: compositor rejected the request"); } /// Recompute geometry, push grid-size changes to each emulator and pty, /// fire deferred greetings. pub fn sync(p: *Pardes) void { + const v = p.view(); while (p.unplaced.findFirstSet()) |id| { p.unplaced.unset(id); // Refused, it was never there. Its serial is not handed out @@ -1754,16 +1774,16 @@ pub fn sync(p: *Pardes) void { tagline.exitHeader(p); } pardes.panes.reapPanes(p); - if (views.several(p)) views.show(p); + if (Views.several(p)) Views.show(p); layout.compute(p); Jump.trackJump(p); for (&p.panes, 0..) |*slot, id| { const pane = slot.* orelse continue; // The keyboard is on one pane, or on a header: a tag it has left // hands it back to its body, and a name drafted there is dropped. - if (id != p.active or p.header != null) { + if (id != v.active or v.header != null) { pane.focus = .body; - if (pane.prompt == .name and pane.prompt_view == p.view) pane.closePrompt(); + if (pane.prompt == .name and pane.prompt_view == p.live) pane.closePrompt(); } // A sweep over the tag is the tag's while it has the keyboard. const swept = pane.sel[sel_slot]; @@ -1778,11 +1798,11 @@ pub fn sync(p: *Pardes) void { p.emitWrite(id, state.reply[0..state.reply_len]); state.reply_len = 0; } - const r = p.rects[id]; + const r = v.rects[id]; // The session's part of the pane's view geometry (File.geometry), // and its context declarations. if (pane.file) |*f| pardes.panes.File.refreshContext(p, pane, f); - pane.view = .{ .wrap = p.settings.wrap, .body_h = p.row_metrics.body_h, .tagline_h = p.row_metrics.tagline_h, .rect_h = r.h }; + pane.view = .{ .wrap = p.settings.wrap, .body_h = v.row_metrics.body_h, .tagline_h = v.row_metrics.tagline_h, .rect_h = r.h }; // The tag takes a row per line, leaving the body one row if it // had any; a folded pane shows its first line only. Its prefix // is made once, on the stack: this runs on every event, and not @@ -1881,7 +1901,7 @@ pub fn sync(p: *Pardes) void { /// The view typing goes into is the one its terminal is sized for /// (`sizes`). fn typedInto(p: *Pardes) void { - if (p.panes[p.active]) |pane| pane.sized_by = p.view; + if (p.panes[p.view().active]) |pane| pane.sized_by = p.live; } /// Whether the live view sizes terminal `pane`: a terminal shown at two @@ -1891,9 +1911,9 @@ fn typedInto(p: *Pardes) void { // ponytail: a panned view's pointer reports to a terminal's program and // its kitty images are placed as the unpanned rows are. fn sizes(p: *Pardes, pane: *Pane) bool { - if (pane.sized_by == p.view) return true; - if (views.isOpen(p, pane.sized_by)) return false; - pane.sized_by = p.view; + if (pane.sized_by == p.live) return true; + if (Views.isOpen(p, pane.sized_by)) return false; + pane.sized_by = p.live; return true; } @@ -2091,7 +2111,7 @@ pub const Header = union(enum) { workspace, column: usize }; /// The column whose tag has the keyboard, null for none or the workspace's. pub fn headerColumn(p: *const Pardes) ?usize { - const h = p.header orelse return null; + const h = p.view().header orelse return null; return if (h == .column) h.column else null; } @@ -2289,8 +2309,8 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { // The Term word names the shell the host ran, and opens another of it. const pane = p.panes[0].?; try std.testing.expectEqualStrings(" Term+sh" ++ tagline.terminal_pane_tail[" Term".len..], tagline.curTail(pane)); - const tag_x = p.rects[0].x + TAG_TEXT_INSET; - const tag_y = p.rects[0].y; + const tag_x = p.view().rects[0].x + TAG_TEXT_INSET; + const tag_y = p.view().rects[0].y; const rendered = try tagline.tagText(p, p.scratch.allocator(), pane); const new_x = tag_x + @as(u16, @intCast(std.mem.indexOf(u8, rendered, "Term").?)) + 1; @@ -2309,8 +2329,8 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { panes_after += 1; }; try std.testing.expectEqual(panes_before + 1, panes_after); - try std.testing.expect(p.panes[p.active].?.isTerminal()); - try std.testing.expectEqualStrings("sh", p.panes[p.active].?.shell.?); + try std.testing.expect(p.panes[p.view().active].?.isTerminal()); + try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); // Argument-taking builtins use the same gesture path: a tag sweep is the // complete command line, and Theme consumes its tail without a PTY write. @@ -2403,7 +2423,7 @@ test "TreeContext rows in the tag style keep the message rows" { // An overlay takes nothing: the message is a chip OVER the body's first // row, so the viewport keeps every row it had. try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h); - const r = p.rects[0]; + const r = p.view().rects[0]; const band = for (p.surface.tagLayers()) |*layer| { if (layer.rows != 0 and layer.kind == .notice) break layer; } else return error.NoNoticeBand; @@ -2415,11 +2435,11 @@ test "TreeContext rows in the tag style keep the message rows" { try std.testing.expect(band.viewport.w < r.w - config.GUTTER); try std.testing.expectEqualStrings("!", band.cells[layout.tagCapacity(p, band.viewport.w) - 2].grapheme()); pane.msg_len = 0; - p.prefix = .leader; + p.view().prefix = .leader; p.sync(); _ = try p.render(p.scratch.allocator()); try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h); - p.prefix = .none; + p.view().prefix = .none; } test "TreeContext command and custom tag survive a workspace round trip" { @@ -2509,15 +2529,15 @@ test "compact tag commands stay beside their own prefix across layout changes" { // A longer sibling never introduces invisible padding into this tag. const below_id = p.freeSlot().?; const below = try p.newShell(below_id, ""); - const f = layout.findPane(p, p.active).?; + const f = layout.findPane(p, p.view().active).?; layout.insert(p, f.col, f.idx + 1, below_id); - layout.splitBelow(p, p.active, below); + layout.splitBelow(p, p.view().active, below); p.setCwd(below_id, "/a/deep/dir/whose/name/eats/the/right/pad/the/end/of/its/own/tagline"); p.sync(); while (p.nextEffect()) |_| {} const above = p.panes[0].?; - try std.testing.expectEqual(p.rects[0].x, p.rects[below_id].x); + try std.testing.expectEqual(p.view().rects[0].x, p.view().rects[below_id].x); const above_tag = try tagline.tagText(p, gpa, above); defer gpa.free(above_tag); const below_tag = try tagline.tagText(p, p.scratch.allocator(), below); @@ -2540,7 +2560,7 @@ test "compact tag commands stay beside their own prefix across layout changes" { p.update(.{ .resize = .{ .cols = 100, .rows = 2 } }); while (p.nextEffect()) |_| {} - try std.testing.expectEqual(@as(u16, 0), p.rects[below_id].h); + try std.testing.expectEqual(@as(u16, 0), p.view().rects[below_id].h); try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); } @@ -2552,7 +2572,7 @@ test "Term spawns a raw shell in the caller's directory" { p.setCwd(0, "/tmp/newtty-dir"); try std.testing.expect(p.executeBuiltinLine(0, "Term")); - const free = p.active; + const free = p.view().active; try std.testing.expect(free != 0); const nt = p.panes[free] orelse return error.NoNewPane; try std.testing.expect(nt.isTerminal()); @@ -2575,11 +2595,11 @@ test "a terminal respawned into a closed pane's slot hangs the old shell up firs const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); try std.testing.expect(p.executeBuiltinLine(0, "Term")); - const slot = p.active; + const slot = p.view().active; while (p.nextEffect()) |_| {} try p.removePane(slot, null); try std.testing.expect(p.executeBuiltinLine(0, "Term")); - try std.testing.expectEqual(slot, p.active); + try std.testing.expectEqual(slot, p.view().active); var closed = false; var spawned = false; while (p.nextEffect()) |effect| switch (effect) { @@ -2632,7 +2652,7 @@ test "an empty column shows its theme's empty_col under its tag: acme's white, e var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); const s = try p.render(arena.allocator()); - const cell = s.at(p.col_x[1] + 3, p.screen_h - 2); + const cell = s.at(p.view().col_x[1] + 3, p.view().screen_h - 2); const want = p.chromeTheme().empty_col; try std.testing.expectEqual(want, cell.style.bg.rgb); if (std.mem.eql(u8, name, "acme")) try std.testing.expectEqual([3]u8{ 0xff, 0xff, 0xff }, want) else try std.testing.expectEqual(p.chromeTheme().border, want); @@ -2682,7 +2702,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty // somewhere ELSE -- and still without moving focus, which is execute's // contract and the whole difference between it and a look try std.testing.expect(dst != 0); - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(usize, 0), p.view().active); try std.testing.expectEqualStrings("echo taken-fallback", p.panes[dst].?.command.?); var spawned = false; while (p.nextEffect()) |effect| switch (effect) { @@ -2998,9 +3018,9 @@ test "a Term started by a shell's path keeps the path in its Term+ word" { defer p.deinit(); while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Term /bin/sh")); - try std.testing.expect(p.active != 0); - p.acknowledgeShell(p.active, "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.active].?), " Term+/bin/sh ")); + try std.testing.expect(p.view().active != 0); + p.acknowledgeShell(p.view().active, "/bin/sh", false); + try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+/bin/sh ")); } test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell" { @@ -3008,11 +3028,11 @@ test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell defer p.deinit(); while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Tty+sh")); - try std.testing.expectEqualStrings("sh", p.panes[p.active].?.shell.?); - const first = p.active; - p.active = 0; + try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); + const first = p.view().active; + p.view().active = 0; try std.testing.expect(p.executeBuiltinLine(0, "Tty")); - try std.testing.expect(p.active != 0 and p.active != first); + try std.testing.expect(p.view().active != 0 and p.view().active != first); } test "Term+fish, one word a tag can hold, opens a terminal on that shell" { @@ -3021,23 +3041,23 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" { while (p.nextEffect()) |_| {} // sh, the one shell every host has. try std.testing.expect(p.executeBuiltinLine(0, "Term+sh")); - try std.testing.expect(p.active != 0); - try std.testing.expectEqualStrings("sh", p.panes[p.active].?.shell.?); - p.acknowledgeShell(p.active, "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.active].?), " Term+sh ")); - p.active = 0; + try std.testing.expect(p.view().active != 0); + try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); + p.acknowledgeShell(p.view().active, "/bin/sh", false); + try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+sh ")); + p.view().active = 0; // A shell that is not there is said, not quietly replaced, and the // pane that asked gets no shell of its own. - const before = p.active; + const before = p.view().active; const caller = p.panes[0].?; try std.testing.expect(p.executeBuiltinLine(0, "Term /nonexistent")); - try std.testing.expect(p.active == before and caller.shell == null); + try std.testing.expect(p.view().active == before and caller.shell == null); try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "shell \"/nonexistent\" not found") != null); try std.testing.expect(p.executeBuiltinLine(0, "Term fsh-not-a-shell")); try std.testing.expect(caller.shell == null); // A directory passes access(X_OK); it is no shell either. try std.testing.expect(p.executeBuiltinLine(0, "Term /etc")); - try std.testing.expect(p.active == before); + try std.testing.expect(p.view().active == before); try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "Term: not a shell: /etc is a directory") != null); // Only a word that says so splits at `+`: `Dump+x.zon` is no Dump. try std.testing.expect(!p.executeBuiltinLine(0, "Dump+x.zon")); @@ -3293,7 +3313,7 @@ test "Font keeps requested and acknowledged faces as separate plain state" { var line: [512]u8 = undefined; const cmd = try std.fmt.bufPrint(&line, "Font {s}", .{installed[0].name}); - try std.testing.expect(p.executeBuiltinLine(p.active, cmd)); + try std.testing.expect(p.executeBuiltinLine(p.view().active, cmd)); try std.testing.expect(p.settings.font.pending); try std.testing.expectEqualStrings(installed[0].name, p.settings.font.requested_name.get()); try std.testing.expectEqualStrings(installed[0].path, p.settings.font.requested_path.get()); @@ -3320,12 +3340,12 @@ test "Font keeps requested and acknowledged faces as separate plain state" { try std.testing.expectEqual(config.Runtime.FontSizeUnit.pixels, p.settings.font.effective_size_unit); try std.testing.expect(!p.acknowledgeFont("Duplicate Ack", 1400, .pixels)); - try std.testing.expect(p.executeBuiltinLine(p.active, cmd)); + try std.testing.expect(p.executeBuiltinLine(p.view().active, cmd)); _ = p.takeFontRequest() orelse return error.MissingRepeatedFontRequest; try std.testing.expect(p.acknowledgeFont(installed[0].name, 1375, .pixels)); // A name nothing answers to changes neither request nor effective state. - try std.testing.expect(p.executeBuiltinLine(p.active, "Font zzz-no-such-face")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Font zzz-no-such-face")); try std.testing.expectEqualStrings(installed[0].name, p.settings.font.requested_name.get()); try std.testing.expectEqualStrings(installed[0].name, p.settings.font.effective_name.get()); } @@ -3339,17 +3359,17 @@ test "Font size suffix reaches native request and invalid input leaves it intact const installed = fonts.list(arena.allocator(), null); if (installed.len == 0) return; var line: [512]u8 = undefined; - try std.testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&line, "Font {s}:18.5", .{installed[0].name}))); + try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&line, "Font {s}:18.5", .{installed[0].name}))); try std.testing.expectEqual(@as(u16, 1850), p.settings.font.requested_size_hundredths); try std.testing.expectEqualStrings(installed[0].path, p.takeFontRequest().?); try std.testing.expect(p.acknowledgeFont(installed[0].name, 1850, .pixels)); - try std.testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&line, "Font {s}:nan", .{installed[0].name}))); + try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&line, "Font {s}:nan", .{installed[0].name}))); try std.testing.expectEqual(@as(u16, 1850), p.settings.font.requested_size_hundredths); try std.testing.expect(p.takeFontRequest() == null); - try std.testing.expect(p.executeBuiltinLine(p.active, "Font zzz-no-such-face:20")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Font zzz-no-such-face:20")); try std.testing.expectEqual(@as(u16, 1850), p.settings.font.requested_size_hundredths); try std.testing.expect(p.takeFontRequest() == null); - try std.testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&line, "Font {s}", .{installed[0].name}))); + try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&line, "Font {s}", .{installed[0].name}))); try std.testing.expectEqual(@as(u16, 0), p.settings.font.requested_size_hundredths); try std.testing.expectEqual(@as(u16, 1850), p.settings.font.effective_size_hundredths); } @@ -3421,7 +3441,7 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const surface = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const text_x = rect.x + config.GUTTER + config.PREFIX_W; const body_y = rect.y + BOX_H; try std.testing.expectEqualStrings("x", surface.at(text_x + 8, body_y).grapheme()); @@ -3461,7 +3481,7 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const surface = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const text_x = rect.x + config.GUTTER + config.PREFIX_W; const body_y = rect.y + BOX_H; // The keyword's ink shows the glyph boundaries. @@ -3519,7 +3539,7 @@ test "editable workspace and column tags are typed into and persist" { defer p.deinit(); _ = try p.setTestFile("untouched\n"); p.presented(); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.rects[0].y); + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); // a sweep over a header is its selection, the caret where it ended p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } }); @@ -3546,8 +3566,8 @@ test "editable workspace and column tags are typed into and persist" { defer restored.deinit(); try std.testing.expectEqualStrings(p.global_tag.own.?, restored.global_tag.own.?); try std.testing.expectEqualStrings(tagline.columnTag(p, 0), tagline.columnTag(restored, 0)); - p.gpa.free(p.col_tags[0].own.?); - p.col_tags[0].own = try p.gpa.dupe(u8, ""); + p.gpa.free(p.view().col_tags[0].own.?); + p.view().col_tags[0].own = try p.gpa.dupe(u8, ""); try dump.dumpState(p); const empty = try dump.restore(p, p.dump_out.?, "test"); defer empty.deinit(); @@ -3562,14 +3582,14 @@ test "column tag first-cell execution keeps New local to the clicked column" { layout.newScratchIn(p, 0, layout.activeColumn(p).?); p.sync(); for (0..2) |column| { - p.active = p.cols[1 - column].panes[0]; + p.view().active = p.view().cols[1 - column].panes[0]; p.presented(); - const before = p.cols; - p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); - try std.testing.expectEqual(before[column].n + 1, p.cols[column].n); - try std.testing.expectEqual(before[1 - column].n, p.cols[1 - column].n); - try std.testing.expectEqual(column, layout.findPane(p, p.active).?.col); + const before = p.view().cols; + p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = p.view().col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); + p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = p.view().col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); + try std.testing.expectEqual(before[column].n + 1, p.view().cols[column].n); + try std.testing.expectEqual(before[1 - column].n, p.view().cols[1 - column].n); + try std.testing.expectEqual(column, layout.findPane(p, p.view().active).?.col); } try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); } @@ -3578,20 +3598,20 @@ test "a screen too short for the column row releases a column tag's focus withou const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("unchanged body\n"); - p.col_tags[0].own = try p.gpa.dupe(u8, "New Help"); + p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Help"); p.presented(); - const shown = p.rects[0]; + const shown = p.view().rects[0]; try std.testing.expectEqual(TOPBAR_H + COLBAR_H, shown.y); p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); - try std.testing.expect(p.header != null and p.headerColumn() != null); + try std.testing.expect(p.view().header != null and p.headerColumn() != null); p.update(.{ .resize = .{ .cols = 60, .rows = 2 } }); try std.testing.expectEqual(@as(u16, 0), layout.columnBarHeight(p)); - try std.testing.expectEqual(TOPBAR_H, p.rects[0].y); - try std.testing.expect(p.header == null and p.headerColumn() == null); + try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); + try std.testing.expect(p.view().header == null and p.headerColumn() == null); p.update(.{ .resize = .{ .cols = 60, .rows = 12 } }); - try std.testing.expectEqual(shown, p.rects[0]); + try std.testing.expectEqual(shown, p.view().rects[0]); try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0)); try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } @@ -3650,10 +3670,10 @@ test "argv naming nothing boots an errors pane rather than failing the launch" { // One pane, filling the window, and it is an OUTPUT pane rather than the // shell a bare `pardes` boots: the answer is the whole screen. - try std.testing.expectEqual(@as(u8, 1), p.ncol); - try std.testing.expectEqual(@as(usize, 1), p.cols[0].n); - try std.testing.expectEqual(@as(usize, 0), p.cols[0].panes[0]); - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(u8, 1), p.view().ncol); + try std.testing.expectEqual(@as(usize, 1), p.view().cols[0].n); + try std.testing.expectEqual(@as(usize, 0), p.view().cols[0].panes[0]); + try std.testing.expectEqual(@as(usize, 0), p.view().active); for (p.panes[1..]) |slot| try std.testing.expect(slot == null); const pane = p.panes[0].?; try std.testing.expect(!pane.isTerminal()); @@ -3678,7 +3698,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const visible = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; - const rect = p.rects[0]; + const rect = p.view().rects[0]; const body_y = rect.y + BOX_H; try std.testing.expectEqual(rect.x + config.GUTTER + 3, visible.x); try std.testing.expectEqual(body_y, visible.y); @@ -3723,7 +3743,7 @@ test "raw terminal cursor follows its active row only while that row is visible" var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const live = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; - const rect = p.rects[0]; + const rect = p.view().rects[0]; const body_y = rect.y + BOX_H; try std.testing.expectEqual(rect.x + config.GUTTER + 3, live.x); try std.testing.expectEqual(body_y + 2, live.y); @@ -3746,23 +3766,23 @@ test "the bare tty startup opens a text pane under the shell, unfocused" { try std.testing.expectEqual(Boot.tty, p.boot); // One column, shell on top in raw mode, an empty text pane under it. - try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqual(@as(usize, 2), p.cols[0].n); - const shell = p.panes[p.cols[0].panes[0]].?; - const scratch = p.panes[p.cols[0].panes[1]].?; + try std.testing.expectEqual(@as(usize, 1), p.view().ncol); + try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n); + const shell = p.panes[p.view().cols[0].panes[0]].?; + const scratch = p.panes[p.view().cols[0].panes[1]].?; try std.testing.expect(shell.isTerminal()); try std.testing.expectEqual(Text.Mode.tty, shell.body.mode); try std.testing.expect(!scratch.isTerminal()); try std.testing.expectEqualStrings("", scratch.file.?.content); // ...and the shell keeps the keyboard. - try std.testing.expectEqual(p.cols[0].panes[0], p.active); + try std.testing.expectEqual(p.view().cols[0].panes[0], p.view().active); // Unnamed, it is the bare shell every test asks for. const plain = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer plain.deinit(); try std.testing.expectEqual(Boot.tty_shell, plain.boot); - try std.testing.expectEqual(@as(usize, 1), plain.cols[0].n); + try std.testing.expectEqual(@as(usize, 1), plain.view().cols[0].n); } test "tty output follows only from the bottom" { @@ -3770,7 +3790,7 @@ test "tty output follows only from the bottom" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; + const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .key = .{ .cp = 'b', .ctrl = true } }); try std.testing.expectEqual(Text.Mode.tty, sp.body.mode); @@ -3915,7 +3935,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc - const shell = p.active; + const shell = p.view().active; const sp = p.panes[shell].?; try std.testing.expect(sp.isTerminal()); @@ -3980,7 +4000,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); - const shell = p.active; + const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ .pane = @intCast(shell), -- cgit v1.3