summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Addon.zig2
-rw-r--r--src/Core.zig498
-rw-r--r--src/Dir.zig16
-rw-r--r--src/Effect.zig4
-rw-r--r--src/File.zig4
-rw-r--r--src/Handover.zig133
-rw-r--r--src/Jump.zig148
-rw-r--r--src/Kind.zig7
-rw-r--r--src/Messages.zig88
-rw-r--r--src/Output.zig27
-rw-r--r--src/Pipe.zig8
-rw-r--r--src/Places.zig7
-rw-r--r--src/Query.zig143
-rw-r--r--src/Store.zig34
-rw-r--r--src/Stream.zig4
-rw-r--r--src/Tables.zig2
-rw-r--r--src/TerminalImages.zig4
-rw-r--r--src/addon_test.zig10
-rw-r--r--src/builtins.zig82
-rw-r--r--src/colors.zig4
-rw-r--r--src/config.zig8
-rw-r--r--src/draw.zig192
-rw-r--r--src/dump.zig93
-rw-r--r--src/echo.zig10
-rw-r--r--src/edit.zig44
-rw-r--r--src/edit_cmd.zig34
-rw-r--r--src/exec.zig71
-rw-r--r--src/fs.zig2
-rw-r--r--src/gui/gui.zig132
-rw-r--r--src/host_io.zig32
-rw-r--r--src/hunks.zig4
-rw-r--r--src/keys.zig196
-rw-r--r--src/layout.zig779
-rw-r--r--src/look.zig170
-rw-r--r--src/lsp/Ask.zig29
-rw-r--r--src/macos.zig38
-rw-r--r--src/mini.zig8
-rw-r--r--src/mouse.zig486
-rw-r--r--src/ninep/cols.zig81
-rw-r--r--src/ninep/ctl.zig93
-rw-r--r--src/ninep/events.zig10
-rw-r--r--src/ninep/pane.zig2
-rw-r--r--src/ninep/screen.zig8
-rw-r--r--src/ninep/tree.zig34
-rw-r--r--src/normal.zig56
-rw-r--r--src/panes.zig65
-rw-r--r--src/pardes.zig15
-rw-r--r--src/pdf_view.zig53
-rw-r--r--src/replica.zig22
-rw-r--r--src/rollback.zig6
-rw-r--r--src/screen_state.zig2
-rw-r--r--src/selection_pipe.zig4
-rw-r--r--src/tagline.zig66
-rw-r--r--src/tape.zig36
-rw-r--r--src/terminal.zig42
-rw-r--r--src/tui/tui.zig48
-rw-r--r--src/upgrade.zig6
-rw-r--r--src/views.zig555
-rw-r--r--test/column_drag.zig177
-rw-r--r--test/fs_namespace.zig16
-rw-r--r--test/hxdiff.zig4
-rw-r--r--test/kitty.zig8
-rw-r--r--test/mode.zig2
-rw-r--r--test/output.zig84
-rw-r--r--test/panes.zig214
-rw-r--r--test/pdf.zig178
-rw-r--r--test/perf-baseline-gui-debug.json2
-rw-r--r--test/perf-baseline-tui-debug.json2
-rw-r--r--test/perf.zig12
-rw-r--r--test/replicas.zig2
-rw-r--r--test/session.zig4
71 files changed, 2751 insertions, 2711 deletions
diff --git a/src/Addon.zig b/src/Addon.zig
index 61b8327d..4a387afa 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -504,7 +504,7 @@ pub fn openPanes(p: *const Pardes, name: []const u8) usize {
/// The `addon` event: what a library brought taken in (or listed
/// refused), or a reload's swap; the panes that waited for it open.
pub fn landed(p: *Pardes, op: Op, pane: u8, l: Loaded) void {
- const id = if (pane < p.panes.len and p.panes[pane] != null) pane else p.active;
+ const id = if (pane < p.panes.len and p.panes[pane] != null) pane else p.view().active;
var said: [320]u8 = undefined;
const base = std.fs.path.basename(l.path);
if (op == .reload) {
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 (`"<reg>`); 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 (`"<reg>`); 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),
diff --git a/src/Dir.zig b/src/Dir.zig
index ae96d816..d8d4d9b0 100644
--- a/src/Dir.zig
+++ b/src/Dir.zig
@@ -209,7 +209,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void {
exec.placeNew(p, from, from, free, .doc);
// Refused a place: that is the look's one failure.
if (p.fs.failures != failures) return;
- fit(p, pane, @max(1, p.rects[free].w -| config.GUTTER));
+ fit(p, pane, @max(1, p.view().rects[free].w -| config.GUTTER));
}
/// A pane on directory `name` (ending in `/`) with its entries `names`,
@@ -244,7 +244,7 @@ pub fn show(p: *Pardes, from: usize, id: usize) void {
refresh(p, id) catch |err| return p.reportError(from, what, err);
// Closed while the turn was out: nothing to give the keyboard to.
const now = p.panes[id] orelse return;
- if (now.serial == serial) p.active = id;
+ if (now.serial == serial) p.view().active = id;
}
// ---- tests ----
@@ -360,7 +360,7 @@ test "a look at a directory opens a pane named for it with a /, its entries in c
var name_buf: [4200]u8 = undefined;
const name = try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir});
const id = named(p, name).id orelse return error.NoDirectoryPane;
- try testing.expectEqual(id, p.active);
+ try testing.expectEqual(id, p.view().active);
const pane = p.panes[id].?;
try testing.expectEqualStrings(".dot sub/ top.txt\n", pane.file.?.content);
try testing.expectEqualStrings(@import("tagline.zig").dir_pane_tail, @import("tagline.zig").curTail(pane));
@@ -402,7 +402,7 @@ test "a look at an entry is a look from the directory, .. goes up to the open pa
p.sync();
const again = named(p, try std.fmt.bufPrint(&name_buf, "{s}/", .{s.dir}));
try testing.expectEqual(@as(usize, 1), again.count);
- try testing.expectEqual(top, p.active);
+ try testing.expectEqual(top, p.view().active);
try testing.expect(std.mem.indexOf(u8, p.panes[top].?.file.?.content, "new.txt") != null);
// Get, in its tag or its text: read again.
try tmp.dir.writeFile(testing.io, .{ .sub_path = "sub/later.txt", .data = "" });
@@ -421,7 +421,7 @@ test "an exec in a directory pane runs in its directory, and its +Errors goes th
pardes.look.lookAt(p, 0, s.dir);
p.sync();
const sub_name = try std.fmt.bufPrint(&name_buf, "{s}/sub/", .{s.dir});
- pardes.look.lookAt(p, p.active, sub_name);
+ pardes.look.lookAt(p, p.view().active, sub_name);
p.sync();
const sub = named(p, sub_name).id.?;
try testing.expectEqualStrings(sub_name[0 .. sub_name.len - 1], p.execDir(sub));
@@ -442,7 +442,7 @@ test "over 9P a directory pane is a text pane whose name ends in /, its body the
var line_buf: [4200]u8 = undefined;
_ = th.wr(p, @backingInt(tree.TopFile.look), try std.fmt.bufPrint(&line_buf, "{s}\n", .{s.dir}));
p.sync();
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
const index = th.rd(p, @backingInt(tree.TopFile.index), 0, 8192).bytes;
try testing.expect(std.mem.indexOf(u8, index, try std.fmt.bufPrint(&line_buf, "{d} text 0 {s}/ ", .{ pane.serial, s.dir })) != null);
try testing.expectEqualStrings(".dot sub/ top.txt\n", th.rd(p, tree.Node.of(pane.serial, .body), 0, 4096).bytes);
@@ -465,13 +465,13 @@ test "a directory pane lays its entries out again when its width changes, unless
const p = s.p;
pardes.look.lookAt(p, 0, s.dir);
p.sync();
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
// 9 cells a column: two of them want 18 cells and the line numbers.
fit(p, pane, 24);
try testing.expectEqualStrings(".dot top.txt\nsub/\n", pane.file.?.content);
fit(p, pane, 80);
try testing.expectEqualStrings(".dot sub/ top.txt\n", pane.file.?.content);
- try testing.expect(p.executeBuiltinLine(p.active, "Edit 1d"));
+ try testing.expect(p.executeBuiltinLine(p.view().active, "Edit 1d"));
const edited = try testing.allocator.dupe(u8, pane.file.?.content);
defer testing.allocator.free(edited);
fit(p, pane, 24);
diff --git a/src/Effect.zig b/src/Effect.zig
index 5fc5f970..31187751 100644
--- a/src/Effect.zig
+++ b/src/Effect.zig
@@ -336,7 +336,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file
const source: usize = 2;
p.setCwd(source, "/tmp/pardes-save-dir");
try std.testing.expect(p.executeBuiltinLine(source, "New"));
- const id = p.active;
+ const id = p.view().active;
const np = p.panes[id].?;
p.sync(); // the frame boundary that gives the new pane its geometry
while (p.nextEffect()) |_| {}
@@ -631,7 +631,7 @@ test "a save path that names no file is refused before anything is rewritten" {
const source: usize = 2;
p.setCwd(source, "/tmp/pardes-refuse");
try std.testing.expect(p.executeBuiltinLine(source, "New"));
- const id = p.active;
+ const id = p.view().active;
const scratch = p.panes[id].?;
p.sync();
while (p.nextEffect()) |_| {}
diff --git a/src/File.zig b/src/File.zig
index 038f4920..f2723851 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -797,7 +797,7 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
std.debug.assert(p.panes[id] == null and !p.reserved_slots[id]);
const path_copy = try p.gpa.dupe(u8, path);
errdefer p.gpa.free(path_copy);
- const pane = try terminal.createDoc(p.gpa, p.screen_w, p.screen_h);
+ const pane = try terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
errdefer p.gpa.destroy(pane);
const history = try History.create(p.gpa);
errdefer p.gpa.destroy(history);
@@ -1071,7 +1071,7 @@ const ParkedPlaces = struct {
const tf = if (pane.file) |*file| file else continue;
if (tf != f and (f.twin == 0 or tf.twin != f.twin)) continue;
for (0..pardes.views.max) |k| {
- if (k == p.view or !pardes.views.isOpen(p, @intCast(k)) or pp.n == max) continue;
+ if (k == p.live or !pardes.views.isOpen(p, @intCast(k)) or pp.n == max) continue;
const v = &pane.pv[k];
const at = lineStart(p.gpa, tf, @intCast(@max(0, v.body.cur_row))) + @as(usize, @intCast(@max(0, v.body.cur_col)));
pp.at[pp.n] = .{
diff --git a/src/Handover.zig b/src/Handover.zig
index 2d47bb4e..fdd263e9 100644
--- a/src/Handover.zig
+++ b/src/Handover.zig
@@ -88,20 +88,21 @@ pub fn deinit(h: *Handover, gpa: std.mem.Allocator) void {
/// and the host asked to carry it. Only text panes travel: a terminal's
/// shell is this process's child and would die with the pane here.
pub fn begin(h: *Handover, p: *Pardes, carried: Kind, at: usize) void {
+ const v = p.view();
var ids: [MAX_PANES]usize = undefined;
var n: usize = 0;
switch (carried) {
.pane => {
const f = layout.findPane(p, at) orelse return;
const end = if (layout.ownerOf(p, at) == null) layout.groupEnd(p, f.col, f.idx) else f.idx + 1;
- for (p.cols[f.col].panes[f.idx..end]) |id| {
+ for (v.cols[f.col].panes[f.idx..end]) |id| {
ids[n] = id;
n += 1;
}
},
.column => {
- if (at >= p.ncol or p.cols[at].n == 0) return;
- for (p.cols[at].panes[0..p.cols[at].n]) |id| {
+ if (at >= v.ncol or v.cols[at].n == 0) return;
+ for (v.cols[at].panes[0..p.view().cols[at].n]) |id| {
ids[n] = id;
n += 1;
}
@@ -137,6 +138,7 @@ pub fn begin(h: *Handover, p: *Pardes, carried: Kind, at: usize) void {
/// not. Taken, its panes close here, unless one was edited since it was
/// dumped: that one stays, so neither window loses the edit.
pub fn finish(h: *Handover, p: *Pardes, seq: u32, to: []const u8, failure: ?[]const u8) void {
+ const v = p.view();
if (!h.flying or seq != h.seq) return;
h.flying = false;
// Its answer is the carrier's last word: what is left of it is freeing.
@@ -150,7 +152,7 @@ pub fn finish(h: *Handover, p: *Pardes, seq: u32, to: []const u8, failure: ?[]co
h.deinit(p.gpa);
var buf: [320]u8 = undefined;
if (failure) |why| {
- const at = p.paneBySerial(h.serials[0]) orelse p.active;
+ const at = p.paneBySerial(h.serials[0]) orelse v.active;
return p.reportFailure(at, std.fmt.bufPrint(&buf, "handover: {s}; the pane stays here", .{why}) catch "handover failed; the pane stays here");
}
var kept: usize = 0;
@@ -172,10 +174,10 @@ pub fn finish(h: *Handover, p: *Pardes, seq: u32, to: []const u8, failure: ?[]co
};
}
if (h.carried == .column) if (layout.columnBySerial(p, h.column_serial)) |c| {
- if (p.cols[c].n == 0 and p.ncol > 1) layout.dropColumn(p, c);
+ if (v.cols[c].n == 0 and v.ncol > 1) layout.dropColumn(p, c);
};
layout.compute(p);
- p.setMessage(p.active, if (kept == 0)
+ p.setMessage(v.active, if (kept == 0)
std.fmt.bufPrint(&buf, "moved to {s}", .{to}) catch "moved"
else
std.fmt.bufPrint(&buf, "copied to {s}; edited on the way, kept here too", .{to}) catch "copied");
@@ -197,7 +199,7 @@ fn dumpCarried(p: *Pardes, kind: Kind, at: usize, ids: []const usize, seq: u32)
}
const value: Carried = .{
.kind = kind,
- .tag = if (kind == .column) p.col_tags[at].own else null,
+ .tag = if (kind == .column) p.view().col_tags[at].own else null,
.panes = bytes,
.weights = weights,
.owners = owners,
@@ -257,9 +259,9 @@ pub fn adopt(p: *Pardes, bytes: []const u8) !usize {
if (st.panes.len == 0 or st.weights.len != st.panes.len or st.owners.len != st.panes.len) return error.NotCarried;
// Where the pointer is, else the middle of the pane with the keyboard.
layout.compute(p);
- const here = p.rects[p.active];
- const x = if (p.pointer_inside) p.hover_col else here.x + here.w / 2;
- const y = if (p.pointer_inside) p.hover_row else here.y + here.h / 2;
+ const here = p.view().rects[p.view().active];
+ const x = if (p.view().pointer_inside) p.view().hover_col else here.x + here.w / 2;
+ const y = if (p.view().pointer_inside) p.view().hover_row else here.y + here.h / 2;
var slots: [MAX_PANES]usize = undefined;
var n: usize = 0;
errdefer for (slots[0..n]) |slot| p.removePane(slot, null) catch {};
@@ -278,40 +280,40 @@ pub fn adopt(p: *Pardes, bytes: []const u8) !usize {
}
const tc = layout.targetColumn(p, x);
var heights: [MAX_PANES]u16 = @splat(0);
- if (carried == .column or p.ncol == 0) {
- const c = if (p.ncol == 0) layout.insertColumn(p, 0, false) else layout.insertColumn(p, tc, x < p.col_x[tc] + p.col_w[tc] / 2);
+ if (carried == .column or p.view().ncol == 0) {
+ const c = if (p.view().ncol == 0) layout.insertColumn(p, 0, false) else layout.insertColumn(p, tc, x < p.view().col_x[tc] + p.view().col_w[tc] / 2);
const col = c orelse return error.NoRoom;
if (carried == .column) if (st.tag) |tag| {
- p.col_tags[col].own = try p.gpa.dupe(u8, tag);
+ p.view().col_tags[col].own = try p.gpa.dupe(u8, tag);
};
for (slots[0..n], 0..) |slot, k| {
layout.insert(p, col, k, slot);
p.panes[slot].?.vweight = st.weights[k];
}
- p.active = slots[0];
+ p.view().active = slots[0];
p.setActiveColumn(col);
p.sync();
return slots[0];
}
- for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |id| {
- heights[id] = p.rects[id].h;
+ for (0..p.view().ncol) |c| for (p.view().cols[c].panes[0..p.view().cols[c].n]) |id| {
+ heights[id] = p.view().rects[id].h;
};
// The group under the pointer (a pane with what is attached to it): the
// new panes go under all of it, out of its owner's rows.
- var after: usize = p.cols[tc].n;
+ var after: usize = p.view().cols[tc].n;
var root: ?usize = null;
var k: usize = 0;
- while (k < p.cols[tc].n) {
+ while (k < p.view().cols[tc].n) {
const end = layout.groupEnd(p, tc, k);
- const first = p.cols[tc].panes[k];
- const last = p.cols[tc].panes[end - 1];
+ const first = p.view().cols[tc].panes[k];
+ const last = p.view().cols[tc].panes[end - 1];
root = first;
after = end;
- if (y < p.rects[last].y + p.rects[last].h) break;
+ if (y < p.view().rects[last].y + p.view().rects[last].h) break;
k = end;
}
if (root) |owner| {
- const r = p.rects[owner];
+ const r = p.view().rects[owner];
// Down to the pointer's row; let go over one of its attachments,
// half of it.
const keeps = @max(layout.minRows(p, owner), if (y >= r.y and y < r.y + r.h) (y - r.y) + 1 else r.h / 2);
@@ -332,7 +334,7 @@ pub fn adopt(p: *Pardes, bytes: []const u8) !usize {
}
for (slots[0..n], 0..) |slot, j| layout.insert(p, tc, after + j, slot);
layout.setColumnWeights(p, tc, &heights);
- p.active = slots[0];
+ p.view().active = slots[0];
p.setActiveColumn(tc);
p.sync();
return slots[0];
@@ -504,31 +506,32 @@ fn twoPanes(gpa: std.mem.Allocator) !*Pardes {
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 });
errdefer p.deinit();
_ = try p.setTestFile("alpha\nbeta\n");
- try std.testing.expect(p.executeBuiltinLine(p.active, "New"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
p.sync();
return p;
}
fn releaseOutside(p: *Pardes, id: usize) void {
- const r = p.rects[id];
+ const v = p.view();
+ const r = v.rects[id];
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x, .row = p.tagTop(p.panes[id].?, r) } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = p.screen_w - 1, .row = r.y + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = p.screen_w - 1, .row = r.y + 1, .outside = true } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = v.screen_w - 1, .row = r.y + 1 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = v.screen_w - 1, .row = r.y + 1, .outside = true } });
}
test "a grip let go past the window's edge dumps its pane alone, and closes it only once another window has it" {
const p = try twoPanes(std.testing.allocator);
defer p.deinit();
const f = layout.findPane(p, 0).?;
- try std.testing.expect(p.cols[f.col].n == 2);
- const other = p.cols[f.col].panes[1 - f.idx];
- const before = p.rects[other];
+ try std.testing.expect(p.view().cols[f.col].n == 2);
+ const other = p.view().cols[f.col].panes[1 - f.idx];
+ const before = p.view().rects[other];
releaseOutside(p, 0);
// Dumped and asked for; nothing moved yet.
try std.testing.expect(p.handover.flying);
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
try std.testing.expect(p.panes[0] != null);
- try std.testing.expectEqual(before, p.rects[other]);
+ try std.testing.expectEqual(before, p.view().rects[other]);
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const carried = try readCarried(arena.allocator(), p.handover.bytes.?);
@@ -552,7 +555,7 @@ test "a grip let go past the window's edge dumps its pane alone, and closes it o
// (Store.zig): Panes does not offer it back here.
try std.testing.expect(p.store.closedBySerial(serial) == null);
p.sync();
- try std.testing.expectEqual(@as(usize, 1), p.cols[layout.findPane(p, other).?.col].n);
+ try std.testing.expectEqual(@as(usize, 1), p.view().cols[layout.findPane(p, other).?.col].n);
}
test "a pane edited while it is on its way to another window stays here too" {
@@ -569,7 +572,7 @@ test "a terminal's grip let go past the edge stays: its shell is this window's"
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30, .shells = 3 });
defer p.deinit();
p.update(.{ .resize = .{ .cols = 100, .rows = 30 } });
- const id = p.cols[1].panes[0];
+ const id = p.view().cols[1].panes[0];
try std.testing.expect(p.panes[id].?.isTerminal());
releaseOutside(p, id);
try std.testing.expect(!p.handover.flying);
@@ -585,66 +588,66 @@ test "a pane let go over another window goes under the pane the pointer is over,
const to = try twoPanes(gpa);
defer to.deinit();
to.sync();
- const before = to.rects;
+ const before = to.view().rects;
const c = layout.findPane(to, 0).?.col;
- const upper = to.cols[c].panes[0];
- const lower = to.cols[c].panes[1];
+ const upper = to.view().cols[c].panes[0];
+ const lower = to.view().cols[c].panes[1];
// The pointer over the upper pane, six rows into it.
- to.pointer_inside = true;
- to.hover_col = to.rects[upper].x + 5;
- to.hover_row = to.rects[upper].y + 6;
+ to.view().pointer_inside = true;
+ to.view().hover_col = to.view().rects[upper].x + 5;
+ to.view().hover_row = to.view().rects[upper].y + 6;
const id = try adopt(to, from.handover.bytes.?);
to.sync();
const pane = to.panes[id].?;
try std.testing.expectEqualStrings("unsaved alpha\nbeta\n", pane.file.?.content);
try std.testing.expect(tagline.dirty(pane));
- try std.testing.expectEqual(upper, to.cols[c].panes[0]);
- try std.testing.expectEqual(id, to.cols[c].panes[1]);
- try std.testing.expectEqual(lower, to.cols[c].panes[2]);
+ try std.testing.expectEqual(upper, to.view().cols[c].panes[0]);
+ try std.testing.expectEqual(id, to.view().cols[c].panes[1]);
+ try std.testing.expectEqual(lower, to.view().cols[c].panes[2]);
// The pane under the pointer keeps its top and gives its rows below
// the pointer; the new one is just there; every other pane is where it was.
- try std.testing.expectEqual(before[upper].y, to.rects[upper].y);
- try std.testing.expectEqual(@as(u16, 7), to.rects[upper].h);
- try std.testing.expectEqual(before[upper].y + 7, to.rects[id].y);
- try std.testing.expectEqual(before[upper].h - 7, to.rects[id].h);
+ try std.testing.expectEqual(before[upper].y, to.view().rects[upper].y);
+ try std.testing.expectEqual(@as(u16, 7), to.view().rects[upper].h);
+ try std.testing.expectEqual(before[upper].y + 7, to.view().rects[id].y);
+ try std.testing.expectEqual(before[upper].h - 7, to.view().rects[id].h);
for (to.panes, 0..) |slot, k| if (slot != null and k != upper and k != id)
- try std.testing.expectEqual(before[k], to.rects[k]);
- try std.testing.expectEqual(id, to.active);
+ try std.testing.expectEqual(before[k], to.view().rects[k]);
+ try std.testing.expectEqual(id, to.view().active);
}
test "a column let go over another window goes beside the column the pointer is over, out of its width alone" {
const gpa = std.testing.allocator;
const from = try twoPanes(gpa);
defer from.deinit();
- const r = from.rects[0];
+ const r = from.view().rects[0];
const c = layout.findPane(from, 0).?.col;
- from.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = from.col_x[c], .row = from.topBarHeight() } });
- from.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = from.screen_w - 1, .row = r.y } });
- from.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = from.screen_w - 1, .row = r.y, .outside = true } });
+ from.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = from.view().col_x[c], .row = from.topBarHeight() } });
+ from.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = from.view().screen_w - 1, .row = r.y } });
+ from.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = from.view().screen_w - 1, .row = r.y, .outside = true } });
try std.testing.expect(from.handover.flying);
try std.testing.expectEqual(Kind.column, from.handover.carried);
const to = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 30 });
defer to.deinit();
_ = try to.setTestFile("x\n");
- try std.testing.expect(to.executeBuiltinLine(to.active, "Newcol"));
+ try std.testing.expect(to.executeBuiltinLine(to.view().active, "Newcol"));
to.sync();
- const ncol = to.ncol;
- const widths = to.col_w;
- const xs = to.col_x;
+ const ncol = to.view().ncol;
+ const widths = to.view().col_w;
+ const xs = to.view().col_x;
// Over the right half of the last column: the new one goes after it.
- to.pointer_inside = true;
- to.hover_col = to.col_x[ncol - 1] + to.col_w[ncol - 1] - 2;
- to.hover_row = 10;
+ to.view().pointer_inside = true;
+ to.view().hover_col = to.view().col_x[ncol - 1] + to.view().col_w[ncol - 1] - 2;
+ to.view().hover_row = 10;
const id = try adopt(to, from.handover.bytes.?);
to.sync();
- try std.testing.expectEqual(ncol + 1, to.ncol);
+ try std.testing.expectEqual(ncol + 1, to.view().ncol);
try std.testing.expectEqual(ncol, layout.findPane(to, id).?.col);
- try std.testing.expectEqual(@as(usize, 2), to.cols[ncol].n);
+ try std.testing.expectEqual(@as(usize, 2), to.view().cols[ncol].n);
for (0..ncol - 1) |k| {
- try std.testing.expectEqual(widths[k], to.col_w[k]);
- try std.testing.expectEqual(xs[k], to.col_x[k]);
+ try std.testing.expectEqual(widths[k], to.view().col_w[k]);
+ try std.testing.expectEqual(xs[k], to.view().col_x[k]);
}
// The finish here: both panes and their column gone from the window.
from.update(.{ .handed = .{ .seq = from.handover.seq, .to = "pardes/2" } });
- try std.testing.expect(from.ncol == 1 or from.cols[c].n == 0 or layout.findPane(from, 0) == null);
+ try std.testing.expect(from.view().ncol == 1 or from.view().cols[c].n == 0 or layout.findPane(from, 0) == null);
}
diff --git a/src/Jump.zig b/src/Jump.zig
index 2220f3c8..0d82d104 100644
--- a/src/Jump.zig
+++ b/src/Jump.zig
@@ -81,7 +81,7 @@ const JumpsTest = struct {
for (order, 0..) |letter, i| {
const which = std.mem.indexOfScalar(u8, letters, letter).?;
const pane = p.panes[t.ids[which]].?;
- p.jumps.list[i] = .{
+ p.view().jumps.list[i] = .{
.pane = @intCast(t.ids[which]),
.serial = pane.serial,
.line = 10 + 40 * seen[which],
@@ -90,9 +90,9 @@ const JumpsTest = struct {
};
seen[which] += 1;
}
- p.jumps.n = order.len;
- p.jumps.cur = order.len - 1;
- look.focusPaneLine(p, p.jumps.list[p.jumps.cur].pane, .{ .line = p.jumps.list[p.jumps.cur].line, .col = 1 }, .center);
+ p.view().jumps.n = order.len;
+ p.view().jumps.cur = order.len - 1;
+ look.focusPaneLine(p, p.view().jumps.list[p.view().jumps.cur].pane, .{ .line = p.view().jumps.list[p.view().jumps.cur].line, .col = 1 }, .center);
p.sync();
return t;
}
@@ -114,14 +114,14 @@ const JumpsTest = struct {
fn walk(t: JumpsTest, way: Way, delta: i32, buf: []u8) ![]const u8 {
var out: std.Io.Writer = .fixed(buf);
for (0..2 * MAX_JUMPS) |_| {
- const before = t.p.jumps.cur;
+ const before = t.p.view().jumps.cur;
t.step(way, delta);
- if (t.p.jumps.cur == before) break;
- const pane = t.p.panes[t.p.active].?;
- const which = std.mem.indexOfScalar(usize, &t.ids, t.p.active).?;
+ if (t.p.view().jumps.cur == before) break;
+ const pane = t.p.panes[t.p.view().active].?;
+ const which = std.mem.indexOfScalar(usize, &t.ids, t.p.view().active).?;
try out.print("{s}{c}{d}", .{ if (out.end > 0) " " else "", letters[which], pane.body.cur_row + 1 });
} else return error.NoEnd;
- const pane = t.p.panes[t.p.active].?;
+ const pane = t.p.panes[t.p.view().active].?;
const said = pane.msg[0..pane.msg_len];
try std.testing.expect(std.mem.indexOf(u8, said, if (delta < 0) "nothing further back" else "nothing further on") != null);
return out.buffered();
@@ -145,15 +145,16 @@ fn samePlace(p: *const Pardes, a: Loc, b: Loc) bool {
return @abs(ya - yb) <= @as(f64, @floatFromInt(view.pixel_h));
};
if (a.line == 0 or b.line == 0) return true;
- const body = @max(1, p.rects[b.pane].h -| BOX_H);
+ const body = @max(1, p.view().rects[b.pane].h -| BOX_H);
return @max(a.line, b.line) - @min(a.line, b.line) <= body;
}
pub fn trackJump(p: *Pardes) void {
+ const v = p.view();
var w: usize = 0;
var cur: usize = 0;
- for (p.jumps.list[0..p.jumps.n], 0..) |j, i| {
- if (i == p.jumps.cur) cur = w; // survives -> lands at w; dies -> the next one does
+ for (v.jumps.list[0..p.view().jumps.n], 0..) |j, i| {
+ if (i == v.jumps.cur) cur = w; // survives -> lands at w; dies -> the next one does
var kept = j;
const live = if (j.serial == 0) false else if (p.panes[j.pane]) |pane| pane.serial == j.serial else false;
// A file's pane closed: its entry stays, closed, and a jump to it
@@ -174,51 +175,51 @@ pub fn trackJump(p: *Pardes) void {
}
// Two in a row the same (a closed one reopened beside its own,
// or the entry between them gone): one entry, one step.
- if (w > 0 and std.meta.eql(p.jumps.list[w - 1], kept)) {
- if (i == p.jumps.cur) cur = w - 1;
+ if (w > 0 and std.meta.eql(v.jumps.list[w - 1], kept)) {
+ if (i == v.jumps.cur) cur = w - 1;
continue;
}
- p.jumps.list[w] = kept;
+ v.jumps.list[w] = kept;
w += 1;
}
- p.jumps.n = w;
- p.jumps.cur = @min(cur, w -| 1);
+ v.jumps.n = w;
+ v.jumps.cur = @min(cur, w -| 1);
- const pane = p.panes[p.active] orelse return;
+ const pane = p.panes[v.active] orelse return;
// A query being typed moves the owner's selection to show, never a
// jump; its pane is no place to come back to either.
if (pane.query) |q| if (!q.frozen) return;
- const force = p.jumps.force;
- p.jumps.force = false;
+ const force = v.jumps.force;
+ v.jumps.force = false;
const pdf_place = panes.Pdf.place(pane);
const now: Loc = .{
- .pane = @intCast(p.active),
+ .pane = @intCast(v.active),
.serial = pane.serial,
.line = if (pdf_place) |at| @intCast(at.page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0,
.col = if (pdf_place) |at| at.at else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0,
.path_hash = if (jumpPath(pane)) |path| std.hash.Wyhash.hash(0, path) else 0,
.pdf = pdf_place != null,
};
- if (!force and p.jumps.n > 0 and samePlace(p, p.jumps.list[p.jumps.cur], now)) {
- p.jumps.list[p.jumps.cur] = now; // same visit; the entry IS where you are
+ if (!force and v.jumps.n > 0 and samePlace(p, v.jumps.list[v.jumps.cur], now)) {
+ v.jumps.list[v.jumps.cur] = now; // same visit; the entry IS where you are
return;
}
// a new jump made from the middle of the list drops everything ahead of
// it, the way vim's does: the future you did not take is not history.
- if (p.jumps.n > 0) p.jumps.n = p.jumps.cur + 1;
- if (!force and p.jumps.n >= 2 and samePlace(p, p.jumps.list[p.jumps.n - 2], now)) {
- p.jumps.list[p.jumps.n - 2] = p.jumps.list[p.jumps.n - 1];
- p.jumps.list[p.jumps.n - 1] = now;
- p.jumps.cur = p.jumps.n - 1;
+ if (v.jumps.n > 0) v.jumps.n = v.jumps.cur + 1;
+ if (!force and v.jumps.n >= 2 and samePlace(p, v.jumps.list[v.jumps.n - 2], now)) {
+ v.jumps.list[v.jumps.n - 2] = v.jumps.list[v.jumps.n - 1];
+ v.jumps.list[v.jumps.n - 1] = now;
+ v.jumps.cur = v.jumps.n - 1;
return;
}
- if (p.jumps.n == MAX_JUMPS) {
- std.mem.copyForwards(Loc, p.jumps.list[0 .. MAX_JUMPS - 1], p.jumps.list[1..]);
- p.jumps.n -= 1;
+ if (v.jumps.n == MAX_JUMPS) {
+ std.mem.copyForwards(Loc, v.jumps.list[0 .. MAX_JUMPS - 1], v.jumps.list[1..]);
+ v.jumps.n -= 1;
}
- p.jumps.list[p.jumps.n] = now;
- p.jumps.cur = p.jumps.n;
- p.jumps.n += 1;
+ v.jumps.list[v.jumps.n] = now;
+ v.jumps.cur = v.jumps.n;
+ v.jumps.n += 1;
}
/// One step through the jumplist, older for a negative `delta`, newer
@@ -233,22 +234,23 @@ pub fn trackJump(p: *Pardes) void {
/// of Backs inside one file step for step, and Forwards end, as they
/// always have, at the newest entry.
pub fn jumpBy(p: *Pardes, delta: i32) void {
+ const v = p.view();
const older = delta < 0;
// At an end of the list: said, not a step that silently does nothing.
- if (p.jumps.n == 0 or (older and p.jumps.cur == 0) or (!older and p.jumps.cur + 1 >= p.jumps.n))
- return p.setMessage(p.active, if (older) "Back: nothing further back" else "Forward: nothing further on");
- var next = if (older) p.jumps.cur - 1 else p.jumps.cur + 1;
+ if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n))
+ return p.setMessage(v.active, if (older) "Back: nothing further back" else "Forward: nothing further on");
+ var next = if (older) v.jumps.cur - 1 else v.jumps.cur + 1;
// A terminal or a scratch has no file to keep to: the step is global.
- if (p.panes[p.active]) |here| if (Pardes.recentPlace(here)) |place| if (place.path.len > 0) {
+ if (p.panes[v.active]) |here| if (Pardes.recentPlace(here)) |place| if (place.path.len > 0) {
const hash = if (jumpPath(here)) |path| std.hash.Wyhash.hash(0, path) else 0;
// The nearest of this pane's own wins over a nearer one of this
// file in another pane: the step does not move the keyboard.
var pick: ?usize = null;
- var i = p.jumps.cur;
- while (if (older) i > 0 else i + 1 < p.jumps.n) {
+ var i = v.jumps.cur;
+ while (if (older) i > 0 else i + 1 < v.jumps.n) {
i = if (older) i - 1 else i + 1;
- const k = p.jumps.list[i];
- if (k.pane == p.active and k.serial == here.serial) {
+ const k = v.jumps.list[i];
+ if (k.pane == v.active and k.serial == here.serial) {
pick = i;
break;
}
@@ -256,7 +258,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
}
next = pick orelse next;
};
- const j = p.jumps.list[next];
+ const j = v.jumps.list[next];
if (j.pane >= MAX_PANES) return;
// A closed file's entry: opened again at its dot, placed as a look
// places it, and the entry is that pane from here on.
@@ -267,45 +269,45 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
// stuck on one that cannot open.
if (found == null or !Pardes.recentKeeps(found.?.path)) {
var said: [recent_path_cap + 32]u8 = undefined;
- if (found) |e| p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
+ if (found) |e| p.setMessage(v.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
const hash = j.path_hash;
var w: usize = 0;
- var cur = p.jumps.cur;
- for (p.jumps.list[0..p.jumps.n], 0..) |k, i| {
+ var cur = v.jumps.cur;
+ for (v.jumps.list[0..p.view().jumps.n], 0..) |k, i| {
if (k.serial == 0 and k.path_hash == hash) {
- if (i < p.jumps.cur) cur -= 1;
+ if (i < v.jumps.cur) cur -= 1;
continue;
}
- p.jumps.list[w] = k;
+ v.jumps.list[w] = k;
w += 1;
}
- p.jumps.n = w;
- p.jumps.cur = @min(cur, w -| 1);
+ v.jumps.n = w;
+ v.jumps.cur = @min(cur, w -| 1);
// The same step again, over the list without them: each
// round takes one file's entries away, so it ends.
return jumpBy(p, delta);
}
const e = found.?;
- const from = p.active;
+ const from = v.active;
look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) });
- const opened = p.panes[p.active] orelse return;
+ const opened = p.panes[v.active] orelse return;
const opened_path = jumpPath(opened) orelse return;
if (!std.mem.eql(u8, opened_path, e.path)) return; // it did not open
if (j.pdf) panes.Pdf.landAt(p, opened, .{ .page = j.line -| 1, .at = j.col });
// Every entry of that file is the reopened pane from here on, so
// a step onto another of them moves in it rather than reopening.
- for (p.jumps.list[0..p.jumps.n]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) {
- k.pane = @intCast(p.active);
+ for (v.jumps.list[0..p.view().jumps.n]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) {
+ k.pane = @intCast(v.active);
k.serial = opened.serial;
};
- p.jumps.cur = next;
+ v.jumps.cur = next;
return;
}
const pane = p.panes[j.pane] orelse return;
if (pane.serial != j.serial) return;
- if (p.panes[p.active]) |source| look.clearNavigationSelection(p, source);
- if (p.active != j.pane) look.clearNavigationSelection(p, pane);
- p.jumps.cur = next;
+ if (p.panes[v.active]) |source| look.clearNavigationSelection(p, source);
+ if (v.active != j.pane) look.clearNavigationSelection(p, pane);
+ v.jumps.cur = next;
if (pane.pdfPath() != null) {
look.focusPaneLine(p, j.pane, .{ .line = 0, .col = 0 }, .keep);
panes.Pdf.landAt(p, pane, .{ .page = j.line -| 1, .at = if (j.pdf) j.col else 0 });
@@ -320,36 +322,36 @@ test "the jump list never holds two entries in a row the same, when the one betw
const pane = try p.setTestFile(std.mem.asBytes(&@as([200][2]u8, @splat("a\n".*))));
const at: Loc = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
// A, a pane long closed with no file to keep it, A again, then far on.
- p.jumps.list[0] = at;
- p.jumps.list[1] = .{ .pane = 5, .serial = 999, .line = 1, .col = 1 };
- p.jumps.list[2] = at;
- p.jumps.list[3] = .{ .pane = 0, .serial = pane.serial, .line = 150, .col = 1 };
- p.jumps.n = 4;
- p.jumps.cur = 3;
+ p.view().jumps.list[0] = at;
+ p.view().jumps.list[1] = .{ .pane = 5, .serial = 999, .line = 1, .col = 1 };
+ p.view().jumps.list[2] = at;
+ p.view().jumps.list[3] = .{ .pane = 0, .serial = pane.serial, .line = 150, .col = 1 };
+ p.view().jumps.n = 4;
+ p.view().jumps.cur = 3;
pane.body.cur_row = 80; // where you are now: far from both
trackJump(p);
- for (1..p.jumps.n) |i| try std.testing.expect(!std.meta.eql(p.jumps.list[i - 1], p.jumps.list[i]));
- try std.testing.expectEqual(@as(usize, 3), p.jumps.n);
- try std.testing.expectEqual(@as(u32, 1), p.jumps.list[0].line);
- try std.testing.expectEqual(@as(u32, 150), p.jumps.list[1].line);
+ for (1..p.view().jumps.n) |i| try std.testing.expect(!std.meta.eql(p.view().jumps.list[i - 1], p.view().jumps.list[i]));
+ try std.testing.expectEqual(@as(usize, 3), p.view().jumps.n);
+ try std.testing.expectEqual(@as(u32, 1), p.view().jumps.list[0].line);
+ try std.testing.expectEqual(@as(u32, 150), p.view().jumps.list[1].line);
}
test "jump history skips an entry whose pane slot or serial is gone, leaving the selection" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n");
- p.jumps.n = 2;
- p.jumps.cur = 1;
- p.jumps.list[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
+ p.view().jumps.n = 2;
+ p.view().jumps.cur = 1;
+ p.view().jumps.list[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
const selected = pane.body.primaryRange(pane.file.?.content, 0);
for ([_]Loc{
.{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 },
.{ .pane = 0, .serial = pane.serial + 1, .line = 1, .col = 1 },
}) |missing| {
- p.jumps.list[0] = missing;
+ p.view().jumps.list[0] = missing;
jumpBy(p, -1);
- try std.testing.expectEqual(@as(usize, 1), p.jumps.cur);
+ try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur);
try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0));
}
}
diff --git a/src/Kind.zig b/src/Kind.zig
index e5332831..241acf4b 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -366,7 +366,7 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator,
const cells = arena.alloc(c.pa_cell, @as(usize, cols) * rows) catch return null;
@memset(std.mem.sliceAsBytes(cells), 0);
var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len });
- const px = if (comptime pardes.pdf_enabled) p.cell_pixels else struct { w: u16 = 8, h: u16 = 16 }{};
+ const px = if (comptime pardes.pdf_enabled) p.view().cell_pixels else struct { w: u16 = 8, h: u16 = 16 }{};
const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)) });
var cl: Call = .{ .p = null, .id = 0, .slot = slot, .quiet = true };
const prev = cl.begin("paint");
@@ -430,7 +430,7 @@ fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
var w: std.Io.Writer = .fixed(buf);
w.writeAll(if (own.len > 0) own else slot.nameOf()) catch {};
if (placed) w.print(" petscii:{s} palette:{t} ascii:{s}", .{
- if (slot.art.glyph or !p.frontend.native_images) "on" else "off",
+ if (slot.art.glyph or !p.view().frontend.native_images) "on" else "off",
slot.art.palette,
if (slot.art.ascii) "on" else "off",
}) catch {};
@@ -524,8 +524,7 @@ pub fn step(p: *Pardes) void {
/// Whether pane `id` has the keyboard in some view (its window focused).
fn focusedAnywhere(p: *const Pardes, id: usize) bool {
- if (p.active == id and p.window_focused) return true;
- for (p.parked, 0..) |v, k| if (v) |pv| if (k != p.view and views.isOpen(p, @intCast(k)) and pv.view.active == id and pv.view.window_focused) return true;
+ for (&p.views) |*v| if (v.*) |*vw| if (vw.active == id and vw.window_focused) return true;
return false;
}
diff --git a/src/Messages.zig b/src/Messages.zig
index 66beb6bc..ad91cf8d 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -52,7 +52,7 @@ fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 {
buf.* = @splat(' ');
@memcpy(buf[0..3], "SPC");
var end: usize = 3;
- for (p.leader_keys[0..p.leader_n]) |ch| {
+ for (p.view().leader_keys[0..p.view().leader_n]) |ch| {
if (end + 2 > buf.len) break;
buf[end + 1] = ch;
end += 2;
@@ -522,7 +522,7 @@ fn collectBands(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
// new one lands under them; when rows run out the oldest go first.
for (pane.msg_older[0..pane.msg_older_len], 0..) |line, i| pane.notices.pushAt(.older, @intCast(i), line.slot);
if (pane.msg_len > 0) pane.notices.pushAt(.message, 0, pane.msg_slot);
- if (id == p.active and p.prefix == .leader) pane.notices.push(.leader);
+ if (id == p.view().active and p.view().prefix == .leader) pane.notices.push(.leader);
// Del's question shows once its delay is up: answered before that, it
// was never there.
const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns;
@@ -576,7 +576,7 @@ test "the message log keeps what the row forgets, and collapses repeats" {
// The same text from a DIFFERENT pane is a different event: one pane's
// failure must not be recorded as another's.
p.newScratchBelow(0);
- const other = p.active;
+ const other = p.view().active;
setMessage(p, other, "save: AccessDenied");
try std.testing.expectEqual(@as(usize, 3), p.messages.len);
try std.testing.expectEqual(p.panes[other].?.serial, p.messages.at(2).?.serial);
@@ -643,9 +643,9 @@ test "Msg writes the transient row by hand, bare or with text, and input ends it
test "with no frontend attached a message goes once it has lingered, on the clock" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- const pane = p.panes[p.active].?;
- p.setMessage(p.active, "said");
- p.setMessage(p.active, "said again");
+ const pane = p.panes[p.view().active].?;
+ p.setMessage(p.view().active, "said");
+ p.setMessage(p.view().active, "said again");
// Attached: it waits for input, however long.
pane.msg_said_ms -= 60_000;
p.update(.tick);
@@ -661,7 +661,7 @@ test "with no frontend attached a message goes once it has lingered, on the cloc
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
// A fresh one stays until its linger is up.
- p.setMessage(p.active, "fresh");
+ p.setMessage(p.view().active, "fresh");
p.update(.tick);
try std.testing.expect(pane.msg_len > 0);
}
@@ -670,15 +670,15 @@ test "a message lingers past the input that dismisses it, and goes" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const pane = p.panes[p.active].?;
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
+ const pane = p.panes[p.view().active].?;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
// Shown at once, until input; the same line again stays shown.
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expect(!p.animationActive());
for (0..100) |_| p.update(.tick);
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
// Input (a key that announces nothing): 160 ms of lingering (ten frames), unaffected by more input...
p.update(.{ .key = .{ .cp = 'h' } });
@@ -697,12 +697,12 @@ test "a message lingers past the input that dismisses it, and goes" {
try std.testing.expect(!p.animationActive());
// Shown again while lingering: fresh, so it stays; a status update to a
// line on screen swaps its text in place.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
p.update(.{ .key = .{ .cp = 'h' } });
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- setStatus(p, p.active, "progress 50%");
+ setStatus(p, p.view().active, "progress 50%");
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expectEqualStrings("progress 50%", pane.msg[0..pane.msg_len]);
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
@@ -712,20 +712,20 @@ test "messages stack, oldest on top, each on its own timing" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const pane = p.panes[p.active].?;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160"));
+ const pane = p.panes[p.view().active].?;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose off"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160"));
// `Verbose off` announced itself before it took effect.
pane.msg_len = 0;
pane.msg_life = .{};
- setMessage(p, p.active, "first");
+ setMessage(p, p.view().active, "first");
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
// A second message stacks under the first instead of replacing it.
- setMessage(p, p.active, "second");
+ setMessage(p, p.view().active, "second");
try std.testing.expectEqual(@as(u8, 1), pane.msg_older_len);
try std.testing.expectEqualStrings("first", pane.msg_older[0].slice());
try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]);
- collectNotices(p, pane, p.rects[p.active], p.active);
+ collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
try std.testing.expectEqual(Pane.Notices.Kind.older, pane.notices.kinds[0]);
try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[1]);
// One key dismisses both, each on its own clock: a line already
@@ -734,7 +734,7 @@ test "messages stack, oldest on top, each on its own timing" {
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase);
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
p.update(.tick);
- setMessage(p, p.active, "third");
+ setMessage(p, p.view().active, "third");
try std.testing.expectEqual(@as(u8, 2), pane.msg_older_len);
p.update(.{ .key = .{ .cp = 'h' } });
const linger = messageFrames(p.settings.message_linger_ms);
@@ -747,24 +747,24 @@ test "messages stack, oldest on top, each on its own timing" {
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
try std.testing.expect(!p.animationActive());
// A status ticking in place does not pile up.
- setStatus(p, p.active, "lsp 10%");
- setStatus(p, p.active, "lsp 20%");
+ setStatus(p, p.view().active, "lsp 10%");
+ setStatus(p, p.view().active, "lsp 20%");
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
// Lines keep their rows: when the top one leaves, the one under it does
// not move up, and the next message fills the gap instead.
- setMessage(p, p.active, "top");
- setMessage(p, p.active, "under");
+ setMessage(p, p.view().active, "top");
+ setMessage(p, p.view().active, "under");
try std.testing.expectEqual(@as(u8, 0), pane.msg_older[0].slot);
try std.testing.expectEqual(@as(u8, 1), pane.msg_slot);
pane.removeOlderMessage(0);
- collectNotices(p, pane, p.rects[p.active], p.active);
+ collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]);
try std.testing.expectEqual(@as(u8, 2), pane.notices.span());
- setMessage(p, p.active, "fills");
+ setMessage(p, p.view().active, "fills");
try std.testing.expectEqual(@as(u8, 0), pane.msg_slot);
try std.testing.expectEqual(@as(u8, 1), pane.msg_older[0].slot);
// The stack keeps the newest few.
- for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, p.active, text);
+ for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, p.view().active, text);
try std.testing.expectEqual(@as(u8, Pane.message_stack), pane.msg_older_len);
try std.testing.expectEqualStrings("b", pane.msg_older[0].slice());
try std.testing.expectEqualStrings("e", pane.msg[0..pane.msg_len]);
@@ -773,23 +773,23 @@ test "messages stack, oldest on top, each on its own timing" {
test "a builtin announces itself on the message row, and Verbose silences it" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
p.sync();
try std.testing.expect(p.settings.verbose);
// Wrap, not Collapse: a builtin that folds its own pane away leaves no row
// for its announcement, which is correct and not what this is testing.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap"));
try std.testing.expectEqualStrings("Wrap", pane.msg[0..pane.msg_len]);
// A value it does not take is said, in place of the announcement.
const wrapped = p.settings.wrap;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap maybe"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap maybe"));
try std.testing.expectEqualStrings("Wrap: takes on, off", pane.msg[0..pane.msg_len]);
try std.testing.expectEqual(wrapped, p.settings.wrap);
// The notice list is what the paint pass reads, so the announcement has to
// reach it, not just the buffer.
- collectNotices(p, pane, p.rects[p.active], p.active);
+ collectNotices(p, pane, p.view().rects[p.view().active], p.view().active);
try std.testing.expect(pane.notices.len > 0);
try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[0]);
@@ -798,7 +798,7 @@ test "a builtin announces itself on the message row, and Verbose silences it" {
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const r = p.rects[p.active];
+ const r = p.view().rects[p.view().active];
const band = for (p.surface.tagLayers()) |*layer| {
if (layer.rows != 0 and layer.kind == .notice) break layer;
} else return error.NoNoticeBand;
@@ -812,32 +812,32 @@ test "a builtin announces itself on the message row, and Verbose silences it" {
try std.testing.expect(line[0].grapheme()[0] == ' ');
// Msg owns the row itself, so it does not announce over its own text.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
try std.testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]);
pane.msg_len = 0;
p.settings.verbose = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap"));
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
}
test "notices stack over the body's top rows without moving them" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
const pane = p.panes[id].?;
p.sync();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- const r = p.rects[id];
+ const r = p.view().rects[id];
const top = p.bodyTop(pane, r);
// A message and a leader prefix at once: two chips, in the order
// collectNotices chose, each one row tall and each one row further down.
try std.testing.expect(p.executeBuiltinLine(id, "Msg first"));
- p.prefix = .leader;
- p.leader_n = 0;
+ p.view().prefix = .leader;
+ p.view().leader_n = 0;
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u8, 2), pane.notices.len);
@@ -861,7 +861,7 @@ test "notices stack over the body's top rows without moving them" {
try std.testing.expect(pane.notices.left[0] < pane.notices.left[1]);
// Gone with the notices: no stale chip left behind.
- p.prefix = .none;
+ p.view().prefix = .none;
pane.msg_len = 0;
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
@@ -876,9 +876,9 @@ test "an idle core wants no wake and a lingering message sleeps to its linger's
const frame = pardes.frame_ns;
p.advance(1_000_000);
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
// Shown, a message asks for no wake.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello"));
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
// A key starts the 800 ms linger: the core sleeps to its end, not a
@@ -898,8 +898,8 @@ test "an idle core wants no wake and a lingering message sleeps to its linger's
// A long linger ends when it says, jumped in one step, not stretched by
// the cap on catching up with moving frames.
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 5000"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 5000"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again"));
p.update(.{ .key = .{ .cp = 'x' } });
const long_due = p.clock.stepped_ns + messageFrames(5000) * frame;
try std.testing.expectEqual(@as(?u64, long_due), p.nextWake());
diff --git a/src/Output.zig b/src/Output.zig
index ecd0666b..006ab7bd 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -488,7 +488,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []
try setArg(output, arg);
p.gpa.free(content);
p.fs.refilled = rp.serial;
- p.active = id;
+ p.view().active = id;
if (traits(from).steps) {
pane.search_pane = i;
pane.search_row = anchor;
@@ -552,7 +552,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
rf.highlight_start = 0;
rf.syntax_dirty = true;
}
- p.active = id;
+ p.view().active = id;
if (traits(from).steps) {
pane.search_pane = i;
pane.search_row = anchor;
@@ -564,7 +564,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
const np = try open(p, free, dir, from, arg, result_content);
np.file.?.location_rows = result_rows;
exec.placeNew(p, id, id, free, .doc);
- p.active = id;
+ p.view().active = id;
if (traits(from).steps) {
pane.search_pane = free;
pane.search_row = anchor;
@@ -606,7 +606,7 @@ pub fn showDiffText(p: *Pardes, id: usize, source: []const u8) void {
}
if (newest) |i| {
if (p.panes[i].?.collapsed) layout.toggleCollapse(p, i);
- p.active = i;
+ p.view().active = i;
return;
}
p.look_text = true;
@@ -626,7 +626,7 @@ pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 {
pub fn openJumps(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();
- for (p.jumps.list[0..p.jumps.n]) |j| {
+ for (p.view().jumps.list[0..p.view().jumps.n]) |j| {
// A closed file's entry: marked, and a look at it opens it again.
if (j.serial == 0) {
const e = p.recentByHash(j.path_hash) orelse continue;
@@ -720,7 +720,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void {
const free = p.freeSlot() orelse return p.gpa.free(content);
_ = open(p, free, dir, .unsaved, "", content) catch return;
exec.placeNew(p, id, id, free, .doc);
- p.active = id;
+ p.view().active = id;
}
/// `pardes -`'s pane: a new `<dir>/+Pager` for each paged text, as each
@@ -749,12 +749,12 @@ pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize {
pane.file.?.path = path;
pane.file.?.pager = true;
pane.tty_filter = true;
- const keyboard = p.active;
+ const keyboard = p.view().active;
exec.placeNew(p, from, null, free, .fs);
if (p.unplaced.isSet(free)) return error.NoPaneRoom;
// Shown, not asked for: the keyboard stays where it was, as a command
// pane's does.
- if (p.panes[keyboard] != null) p.active = keyboard;
+ if (p.panes[keyboard] != null) p.view().active = keyboard;
return free;
}
@@ -857,7 +857,7 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void {
const free = p.freeSlot() orelse return error.NoPaneSlots;
_ = try open(p, free, dir, from, "", content);
exec.placeNew(p, id, id, free, .doc);
- p.active = id;
+ p.view().active = id;
pane.search_pane = free;
pane.search_row = null;
look.armLookWalk(p, free);
@@ -1002,7 +1002,7 @@ pub fn openConfig(p: *Pardes, id: usize) !void {
.theme_file = pardes.colors.loadedThemeFile(p),
.compiled_default_shell = config.defaultShell(),
.hover_delay_frames = config.look_preview_delay_frames,
- .native_images = p.frontend.native_images,
+ .native_images = p.view().frontend.native_images,
.capabilities = builtins.viewCapabilities(p),
.state = &p.settings,
});
@@ -1043,6 +1043,7 @@ pub fn openErrors(p: *Pardes, id: usize, content: []u8) !void {
}
pub fn resetBody(p: *Pardes, pane: *Pane) void {
+ const v = p.view();
pane.file.?.scroll = 0;
pane.body.cur_row = 0;
pane.body.cur_col = 0;
@@ -1064,7 +1065,7 @@ pub fn resetBody(p: *Pardes, pane: *Pane) void {
if (p.look_hover_preview) |preview| if (preview.serial == pane.serial) {
p.look_hover_preview = null;
};
- if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none;
+ if (v.drag == .select and p.panes[v.drag.select.id] == pane) v.drag = .none;
}
fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) !void {
@@ -1078,7 +1079,7 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8)
try setArg(ho, arg);
File.setContent(p, hf, content);
resetBody(p, hp);
- p.active = i;
+ p.view().active = i;
return;
}
// Where the word ran: the pane's directory, or from a column's or the
@@ -1087,5 +1088,5 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8)
const free = p.freeSlot() orelse return error.NoPaneSlots;
_ = try open(p, free, dir, from, arg, content);
exec.placeNew(p, id, id, free, if (from == .errors) .errors else .doc);
- p.active = free;
+ p.view().active = free;
}
diff --git a/src/Pipe.zig b/src/Pipe.zig
index b7310e5c..e7895c0d 100644
--- a/src/Pipe.zig
+++ b/src/Pipe.zig
@@ -179,14 +179,14 @@ fn pipeFailed(p: *Pardes, wait: *const PendingPipe, failure: ?selection_pipe.Fai
w.print("selection {d} of {d}: ", .{ fail.index + 1, wait.inputs.len }) catch return;
writeFailure(w, failure) catch return;
const content = out.toOwnedSlice() catch return;
- const was = p.active;
+ const was = p.view().active;
panes.Output.openErrors(p, wait.pane, content) catch |err| {
p.gpa.free(content);
// Nowhere to put the report is itself worth one line.
p.reportError(wait.pane, "pipe", err);
return;
};
- if (p.panes[was] != null) p.active = was;
+ if (p.panes[was] != null) p.view().active = was;
}
/// How a filter failed, a line, and the command's stderr after it: what
@@ -263,7 +263,7 @@ pub fn pipeResponse(
const t: *Text = switch (wait.what) {
.body => &pane.body,
.tag => &pane.tag,
- .column => if (wait.column < p.ncol) &p.col_tags[wait.column] else return,
+ .column => if (wait.column < p.view().ncol) &p.view().col_tags[wait.column] else return,
.workspace => &p.global_tag,
.input => return,
};
@@ -572,7 +572,7 @@ test "a failed filter opens an errors buffer carrying the command's own words" {
try std.testing.expectEqualSlices(u8, "abc\n", pane.file.?.content);
try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.journal.done);
// ...and the cursor did not go anywhere, so `|` again edits the same file.
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
var found: ?[]const u8 = null;
for (p.panes) |slot| {
diff --git a/src/Places.zig b/src/Places.zig
index 0ed64ae7..ddbbc271 100644
--- a/src/Places.zig
+++ b/src/Places.zig
@@ -604,9 +604,10 @@ pub fn step(set: *Places, p: *Pardes, pane: *Pane, forward: bool, count: u32, ad
/// query's always; a search's while it is what the register says (an `s`,
/// a `/` elsewhere or `"a` since makes them helix's register search again).
pub fn answersN(set: *const Places, p: *Pardes, pane: *Pane) bool {
+ const v = p.view();
if (!set.shows(pane) and !set.started) return false;
- if (set.provenance != .search) return p.register == 0;
- const name = if (p.register != 0) p.register else p.registers.last_search;
+ if (set.provenance != .search) return v.register == 0;
+ const name = if (v.register != 0) v.register else p.registers.last_search;
const pat = p.registers.value(name, 0) orelse return false;
if (!set.literal) return std.mem.eql(u8, pat, set.pattern);
var spelled: std.ArrayList(u8) = .empty;
@@ -883,7 +884,7 @@ test "a session's places loaded from its dump find what an edit makes as the ses
defer b.deinit();
try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b));
for ([_]*Pardes{ a, b }) |p| {
- const pn = p.panes[p.active].?;
+ const pn = p.panes[p.view().active].?;
const new = try gpa.dupe(u8, "alpha beta\ngamma alpha alpha\n");
File.setContentSpan(p, &pn.file.?, new, null);
pn.places.fill(p, pn, 0, frame_steps);
diff --git a/src/Query.zig b/src/Query.zig
index 749a5245..0f08ce80 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -265,7 +265,7 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo
produce(p, id, false, false);
// What a 9P exec reads back: the pane it filled (ninep/ctl.zig).
p.fs.refilled = p.panes[id].?.serial;
- if (focus) toLineOne(p, id) else p.active = from;
+ if (focus) toLineOne(p, id) else p.view().active = from;
}
/// The body rows a query pane is born with under its line 1 (and its
@@ -303,7 +303,7 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize
var preview_rows: u16 = tag + born_rows;
if (with_preview) {
layout.compute(p);
- const spare = p.rects[owner_id].h -| layout.minRows(p, owner_id);
+ const spare = p.view().rects[owner_id].h -| layout.minRows(p, owner_id);
if (spare < want + preview_rows) {
const both = want + preview_rows;
want = @max(tag + 2, @as(u16, @intCast(@as(u32, spare) * want / both)));
@@ -323,7 +323,7 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize
pub fn toLineOne(p: *Pardes, id: usize) void {
const rp = p.panes[id] orelse return;
tagline.exitHeader(p);
- p.active = id;
+ p.view().active = id;
if (layout.findPane(p, id)) |at| p.setActiveColumn(at.col);
rp.focus = .body;
const t = &rp.body;
@@ -441,7 +441,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void {
if (a.pat.len == 0) {
if (set.from == rp.serial) set.clear(p.gpa);
set.restore(owner);
- } else set.search(p, owner, .typed, rp.serial, a.pat, false, set.origin(owner), p.active == id);
+ } else set.search(p, owner, .typed, rp.serial, a.pat, false, set.origin(owner), p.view().active == id);
}
// The owner edited: its places shifted at once; the rows follow
// once its text has stood a frame.
@@ -518,7 +518,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void {
// Typed, not answered: asked of the language server at the
// owner's cursor; its answer fills these rows (fillList).
// An answer opening the pane is no typing.
- if (p.active != id) return;
+ if (p.view().active != id) return;
if (owner_id) |oid| p.lspRequest(oid, switch (a.source) {
.refs => .references,
.defs => .definition,
@@ -1302,11 +1302,11 @@ pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) v
// on the current row in normal mode (j, k, n, N step, Enter lands, Esc
// goes back), line 1 left as text for whoever wants to edit it.
if (source == .diagnostics) {
- p.active = owner_id;
+ p.view().active = owner_id;
return;
}
tagline.exitHeader(p);
- p.active = qid;
+ p.view().active = qid;
if (layout.findPane(p, qid)) |at| p.setActiveColumn(at.col);
rp.focus = .body;
const t = &rp.body;
@@ -1523,9 +1523,9 @@ pub fn step(p: *Pardes, id: usize, delta: i32) void {
if (q.source == .text) if (p.paneBySerial(q.owner)) |oid| {
const owner = p.panes[oid].?;
if (owner.places.from == rp.serial) {
- const keyboard = p.active;
+ const keyboard = p.view().active;
owner.places.step(p, owner, delta > 0, 1, false);
- p.active = keyboard;
+ p.view().active = keyboard;
showPlacesCurrent(p, id);
return;
}
@@ -1584,8 +1584,8 @@ fn showTarget(p: *Pardes, id: usize) void {
if (c + 1 >= f.location_rows.len) return;
const it = q.items.items[c];
const meta = f.location_rows[c + 1];
- const keyboard = p.active;
- defer p.active = keyboard;
+ const keyboard = p.view().active;
+ defer p.view().active = keyboard;
if (it.serial != 0) {
const tid = p.paneBySerial(it.serial) orelse return;
const tp = p.panes[tid].?;
@@ -1676,7 +1676,7 @@ fn makePreview(p: *Pardes, qid: usize, rows: u16, giver: usize) ?usize {
/// file open in a pane would be shown there instead), the place centred
/// and selected. Made when the pane has none and its owner has the rows.
fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void {
- const id = previewOf(p, qid) orelse makePreview(p, qid, p.rects[qid].h / 2, qid) orelse return;
+ const id = previewOf(p, qid) orelse makePreview(p, qid, p.view().rects[qid].h / 2, qid) orelse return;
const pane = p.panes[id].?;
const f = &pane.file.?;
if (!std.mem.eql(u8, f.path, path)) {
@@ -1778,6 +1778,7 @@ fn promote(p: *Pardes, qid: usize, id: usize) void {
/// in its pane (the +Preview promoted to the file's pane when it shows
/// it), a `/` into the register, and the rows frozen into ordinary text.
pub fn land(p: *Pardes, id: usize, row: ?usize) void {
+ const v = p.view();
const rp = p.panes[id] orelse return;
const q = rp.query orelse return;
if (row) |r| if (r < q.items.items.len and q.items.items[r].kind == .hit) setCurrent(p, id, r, true);
@@ -1803,8 +1804,8 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void {
p.registers.last_search = '/';
set.provenance = .search;
}
- p.jumps.force = true;
- p.active = oid;
+ v.jumps.force = true;
+ v.active = oid;
return;
}
const f = &rp.file.?;
@@ -1813,15 +1814,15 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void {
// is none: there is nowhere to land, as with no current one.
const current = if (q.current) |i| (if (i < q.items.items.len and i + 1 < f.location_rows.len) i else null) else null;
const c = current orelse {
- if (owner_id) |oid| p.active = oid;
+ if (owner_id) |oid| v.active = oid;
return;
};
const it = q.items.items[c];
const meta = f.location_rows[c + 1];
- p.jumps.force = true;
+ v.jumps.force = true;
if (it.serial != 0) {
if (p.paneBySerial(it.serial)) |tid| {
- p.active = tid;
+ v.active = tid;
if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col);
}
return;
@@ -1833,7 +1834,7 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void {
},
.panes => {
if (p.paneBySerial(it.ref)) |tid| {
- p.active = tid;
+ v.active = tid;
if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col);
return;
}
@@ -1847,7 +1848,7 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void {
// The preview shows it: promoted where it stands.
if (previewOf(p, id)) |pid| if (std.mem.eql(u8, p.panes[pid].?.file.?.path, meta.path)) {
promote(p, id, pid);
- p.active = pid;
+ v.active = pid;
if (q.source == .grep) {
const a = parse(q.asked) orelse return;
const pp = p.panes[pid].?;
@@ -1923,14 +1924,14 @@ pub fn cancel(p: *Pardes, id: usize) void {
const owner = p.panes[oid].?;
owner.places.search(p, owner, .search, rp.serial, a.pat, false, null, false);
};
- if (owner_id) |oid| p.active = oid;
+ if (owner_id) |oid| p.view().active = oid;
return;
}
// Attached, its rows go back to its owner; else to its own column's.
const attached = layout.ownerOf(p, id) != null;
if (owner_id) |oid| {
p.removePane(id, if (attached) oid else null) catch {};
- p.active = oid;
+ p.view().active = oid;
if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col);
} else p.removePane(id, null) catch {};
}
@@ -2163,10 +2164,10 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
defer p.deinit();
const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n");
p.newScratchBelow(0);
- const below = p.cols[0].panes[1];
- p.active = 0;
+ const below = p.view().cols[0].panes[1];
+ p.view().active = 0;
layout.compute(p);
- const before = p.rects;
+ const before = p.view().rects;
// cursor on line 3 (row 2)
pane.body.cur_row = 2;
pane.body.cur_col = 0;
@@ -2174,9 +2175,9 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
const qid = queryPane(p).?;
const qp = p.panes[qid].?;
try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, qid));
- try std.testing.expectEqual(qid, p.active);
- try std.testing.expectEqualDeep(before[below], p.rects[below]);
- const born = p.rects[qid];
+ try std.testing.expectEqual(qid, p.view().active);
+ try std.testing.expectEqualDeep(before[below], p.view().rects[below]);
+ const born = p.view().rects[qid];
try std.testing.expectEqualStrings("/", lineOne(qp.file.?.content));
// keystroke 1
typeKeys(p, "a");
@@ -2184,7 +2185,7 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
try std.testing.expectEqual(Source.text, q.source);
try std.testing.expect(pane.places.started and pane.places.from == qp.serial);
try std.testing.expect(q.total > 0);
- try std.testing.expectEqualDeep(born, p.rects[qid]);
+ try std.testing.expectEqualDeep(born, p.view().rects[qid]);
// keystroke 2 .. `alph`: four places on four lines (rows), the
// current the first at or after the cursor (line 3's alphabet)
typeKeys(p, "lph");
@@ -2193,9 +2194,9 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
try std.testing.expectEqual(@as(?usize, 1), pane.places.current);
const sel = pane.body.primaryRange(pane.file.?.content, 0);
try std.testing.expectEqual(@as(usize, 15), @min(sel.anchor, sel.head));
- try std.testing.expectEqualDeep(born, p.rects[qid]);
- try std.testing.expectEqualDeep(before[below], p.rects[below]);
- try std.testing.expectEqual(qid, p.active);
+ try std.testing.expectEqualDeep(born, p.view().rects[qid]);
+ try std.testing.expectEqualDeep(before[below], p.view().rects[below]);
+ try std.testing.expectEqual(qid, p.view().active);
// Ctrl-n steps, the owner follows
p.update(.{ .key = .{ .cp = 'n', .ctrl = true } });
try std.testing.expectEqual(@as(usize, 3), q.k);
@@ -2209,16 +2210,16 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
try std.testing.expectEqual(@as(usize, 0), q.total);
try std.testing.expect(p.panes[qid] != null);
try std.testing.expectEqualStrings("/alphzz", lineOne(qp.file.?.content));
- try std.testing.expectEqualDeep(born, p.rects[qid]);
+ try std.testing.expectEqualDeep(born, p.view().rects[qid]);
const tag = try tagline.pathPrefix(p, p.scratch.allocator(), qp);
try std.testing.expectEqualStrings("+Search 0", tag);
// Esc: the pane gone, its rows back to the owner, the owner as it was
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(p.panes[qid] == null);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
layout.compute(p);
- try std.testing.expectEqualDeep(before[0], p.rects[0]);
- try std.testing.expectEqualDeep(before[below], p.rects[below]);
+ try std.testing.expectEqualDeep(before[0], p.view().rects[0]);
+ try std.testing.expectEqualDeep(before[below], p.view().rects[below]);
try std.testing.expect(!pane.places.started);
try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
}
@@ -2252,7 +2253,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
const q = qp.query.?;
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(q.frozen);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqualStrings("alpha", p.registers.value('/', 0).?);
try std.testing.expectEqual(Places.Provenance.search, pane.places.provenance);
const frozen = try std.testing.allocator.dupe(u8, qp.file.?.content);
@@ -2277,7 +2278,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
// a later `/` reuses the pane: line 1 fresh, the rows the new query's
typeKeys(p, "/");
try std.testing.expectEqual(qid, queryPane(p).?);
- try std.testing.expectEqual(qid, p.active);
+ try std.testing.expectEqual(qid, p.view().active);
try std.testing.expect(!q.frozen);
typeKeys(p, "beta");
try std.testing.expectEqual(@as(usize, 1), q.total);
@@ -2328,11 +2329,11 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing
defer p.deinit();
_ = try testFileIn(p, &tmp, "x.txt", "x\n");
p.newScratchBelow(0);
- const other = p.cols[0].panes[1];
+ const other = p.view().cols[0].panes[1];
try std.testing.expect(layout.splitColumn(p, other, other, false));
- p.active = 0;
+ p.view().active = 0;
layout.compute(p);
- const before = p.rects;
+ const before = p.view().rects;
leader(p, "ff");
const qid = queryPane(p).?;
const q = p.panes[qid].?.query.?;
@@ -2341,32 +2342,32 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing
// the group: owner, query pane, +Preview, out of the owner's rows alone
const pv = previewOf(p, qid).?;
try std.testing.expectEqual(@as(usize, 0), layout.groupRoot(p, pv));
- try std.testing.expectEqualDeep(before[other], p.rects[other]);
- try std.testing.expectEqual(before[0].h, p.rects[0].h + p.rects[qid].h + p.rects[pv].h);
+ try std.testing.expectEqualDeep(before[other], p.view().rects[other]);
+ try std.testing.expectEqual(before[0].h, p.view().rects[0].h + p.view().rects[qid].h + p.view().rects[pv].h);
settle(p);
// an empty query lists every name
try std.testing.expectEqual(@as(usize, 4), q.total);
- const born = p.rects;
+ const born = p.view().rects;
typeKeys(p, "lay");
settle(p);
try std.testing.expectEqual(@as(usize, 1), q.total);
- try std.testing.expectEqualDeep(born[qid], p.rects[qid]);
- try std.testing.expectEqualDeep(born[pv], p.rects[pv]);
+ try std.testing.expectEqualDeep(born[qid], p.view().rects[qid]);
+ try std.testing.expectEqualDeep(born[pv], p.view().rects[pv]);
// the current one in the preview, never by the pointer
try std.testing.expect(std.mem.endsWith(u8, p.panes[pv].?.file.?.path, "src/layout.zig"));
- try std.testing.expectEqual(qid, p.active);
+ try std.testing.expectEqual(qid, p.view().active);
const serial = p.panes[pv].?.serial;
- const rect = p.rects[pv];
+ const rect = p.view().rects[pv];
p.update(.{ .key = .{ .cp = Key.enter } });
// promoted where it stands: same slot, serial, rect; a file pane now
- try std.testing.expectEqual(pv, p.active);
+ try std.testing.expectEqual(pv, p.view().active);
try std.testing.expectEqual(serial, p.panes[pv].?.serial);
try std.testing.expect(p.panes[pv].?.file.?.output == null);
try std.testing.expect(p.panes[pv].?.attached_to == null);
layout.compute(p);
- try std.testing.expectEqualDeep(rect, p.rects[pv]);
+ try std.testing.expectEqualDeep(rect, p.view().rects[pv]);
try std.testing.expect(q.frozen);
- try std.testing.expectEqualDeep(before[other], p.rects[other]);
+ try std.testing.expectEqualDeep(before[other], p.view().rects[other]);
}
test "Grep: lines of the files under the owner's directory, under their file; All: every pane's, under @pN in serial order, a line once" {
@@ -2394,10 +2395,10 @@ test "Grep: lines of the files under the owner's directory, under their file; Al
// All: a second pane, both searched, grouped by serial
p.newScratchBelow(0);
- const s = p.active;
+ const s = p.view().active;
const sf = &p.panes[s].?.file.?;
File.setContent(p, sf, try p.gpa.dupe(u8, "needle needle twice\n"));
- p.active = 0;
+ p.view().active = 0;
leader(p, "/");
const aid = queryPane(p).?;
const aq = p.panes[aid].?.query.?;
@@ -2424,15 +2425,15 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
// `*` on `const`: line 1 `/\bconst\b`, the keyboard still in the text
typeKeys(p, "e*");
const qid = queryPane(p).?;
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expect(std.mem.startsWith(u8, lineOne(p.panes[qid].?.file.?.content), "/"));
try std.testing.expect(pane.places.started);
typeKeys(p, "n");
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
// SPC b b: the open panes by name; Enter goes to the marked one
p.newScratchBelow(0);
- const other = p.active;
- p.active = 0;
+ const other = p.view().active;
+ p.view().active = 0;
leader(p, "bb");
const bid = queryPane(p).?;
try std.testing.expectEqual(bid, qid);
@@ -2440,7 +2441,7 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
try std.testing.expect(p.panes[bid].?.query.?.total >= 1);
// SPC s s: the declarations, fuzzy; Enter lands on the line
p.update(.{ .key = .{ .cp = Key.escape } });
- p.active = 0;
+ p.view().active = 0;
leader(p, "ss");
const sid = queryPane(p).?;
try std.testing.expectEqual(Source.symbols, p.panes[sid].?.query.?.source);
@@ -2448,7 +2449,7 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
typeKeys(p, "bet");
try std.testing.expectEqual(@as(usize, 1), p.panes[sid].?.query.?.total);
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
_ = other;
}
@@ -2475,7 +2476,7 @@ test "a language server's list: one answer lands with no pane, several open the
p.lspRequest(0, .references, "");
p.update(.{ .lsp_resp = .{ .id = p.lsp_ask.wait.?.id, .rows = "/test.txt:3:1-5 alpha two\n" } });
try std.testing.expectEqual(@as(usize, 1), npanes(p));
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
try std.testing.expectEqual(@as(usize, 1), pane.places.hits.items.len);
try std.testing.expectEqual(Places.Hit{ .start = 15, .end = 20 }, pane.places.hits.items[0]);
@@ -2493,7 +2494,7 @@ test "a language server's list: one answer lands with no pane, several open the
const qid = queryPane(p).?;
const qp = p.panes[qid].?;
const q = qp.query.?;
- try std.testing.expectEqual(qid, p.active);
+ try std.testing.expectEqual(qid, p.view().active);
try std.testing.expect(qp.body.mode == .normal);
try std.testing.expect(std.mem.startsWith(u8, qp.file.?.content, "Refs"));
try std.testing.expectEqual(@as(i32, @intCast(q.current.? + 1)), qp.body.cur_row);
@@ -2506,7 +2507,7 @@ test "a language server's list: one answer lands with no pane, several open the
// Esc: back to the text, as it was, the list gone.
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(p.panes[qid] == null);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
}
@@ -2523,7 +2524,7 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the
const owner_scroll = pane.file.?.scroll;
try std.testing.expectEqual(@as(?usize, 0), q.current);
const place = pane.places.current;
- const r = p.rects[qid];
+ const r = p.view().rects[qid];
const row_y = r.y + qp.tag_rows;
const y = row_y + 3;
const x = r.x + config.GUTTER + File.gutterWidth(qp) + 6;
@@ -2551,7 +2552,7 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the
try std.testing.expectEqual(@as(?usize, 0), q.current);
try std.testing.expectEqual(owner_sel, pane.body.primaryRange(pane.file.?.content, 0));
// the keyboard: n steps from the current row, not the caret's, the caret with it
- p.active = qid;
+ p.view().active = qid;
if (qp.body.mode == .insert) p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(p.panes[qid] != null);
typeKeys(p, "n");
@@ -2564,9 +2565,9 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the
// B1 elsewhere, then Enter: the current row lands, not the caret's
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = row_y + 1 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = row_y + 1 } });
- p.active = qid;
+ p.view().active = qid;
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
}
@@ -2575,7 +2576,7 @@ test "Enter on a frozen query pane's rows after its text was edited: no row to l
defer p.deinit();
_ = try p.setTestFile("alpha\n");
p.newScratchBelow(0);
- p.active = 0;
+ p.view().active = 0;
// SPC b b and Enter: the current row lands, the rows frozen.
leader(p, "bb");
const qid = queryPane(p).?;
@@ -2583,12 +2584,12 @@ test "Enter on a frozen query pane's rows after its text was edited: no row to l
const qp = p.panes[qid].?;
try std.testing.expect(qp.query.?.frozen and qp.query.?.current != null);
// Its text edited: the rows' places go with the text they were of.
- p.active = qid;
+ p.view().active = qid;
typeKeys(p, "ggjxd");
try std.testing.expectEqual(@as(usize, 0), qp.file.?.location_rows.len);
try std.testing.expect(qp.body.cur_row > 0);
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
}
test "a query row's place is its text: the match tinted after it, B3 on it opens the place, the rows saved and read again still Look" {
@@ -2625,19 +2626,19 @@ test "a query row's place is its text: the match tinted after it, B3 on it opens
// B3 on the address: the place, in the pane that shows it
a.body.cur_row = 0;
p.presented();
- const r = p.rects[qid];
+ const r = p.view().rects[qid];
const y = r.y + qp.tag_rows + @as(u16, @intCast(row4)) - @as(u16, @intCast(qp.scroll()));
const x = r.x + config.GUTTER + File.gutterWidth(qp) + 3;
p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 3), a.body.cur_row);
// the rows as a plain text in that directory (what Save writes): a
// Look at a row's address word still goes there
const saved = try std.testing.allocator.dupe(u8, f.content);
defer std.testing.allocator.free(saved);
p.newScratchBelow(0);
- const sid = p.active;
+ const sid = p.view().active;
const sp = p.panes[sid].?;
File.setContent(p, &sp.file.?, try p.gpa.dupe(u8, saved));
try std.testing.expect(sp.query == null and sp.file.?.location_rows.len == 0);
@@ -2646,7 +2647,7 @@ test "a query row's place is its text: the match tinted after it, B3 on it opens
const word = look.expandedWord(line, 3).?;
a.body.cur_row = 0;
look.lookAt(p, sid, line[word.lo..word.hi]);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 1), a.body.cur_row);
}
diff --git a/src/Store.zig b/src/Store.zig
index 970fe85e..64a8a7be 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -120,7 +120,7 @@ pub fn keep(s: *Store, p: *Pardes, id: usize) ?Kept {
.column = if (at) |f| layout.columnSerial(p, f.col) else 0,
.owner = if (owner) |o| p.panes[o].?.serial else 0,
.idx = if (at) |f| f.idx else 0,
- .rows = p.rects[id].h,
+ .rows = p.view().rects[id].h,
.name = name,
.dump = owned,
};
@@ -222,7 +222,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool {
freeClosed(p.recentGpa(), s.closed.orderedRemove(i));
break;
};
- p.active = free;
+ p.view().active = free;
if (layout.findPane(p, free)) |f| p.setActiveColumn(f.col);
p.sync();
return true;
@@ -268,8 +268,8 @@ test "store: this session keeps its newest 64 closed panes" {
var serial: u32 = 0;
var text: [16]u8 = undefined;
for (0..max_closed + 6) |i| {
- p.newScratchBelow(p.active);
- const id = p.active;
+ p.newScratchBelow(p.view().active);
+ const id = p.view().active;
@import("File.zig").setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, std.fmt.bufPrint(&text, "scratch {d}\n", .{i}) catch unreachable));
serial = p.panes[id].?.serial;
// Made outside a step: announced as a step's end would.
@@ -278,8 +278,8 @@ test "store: this session keeps its newest 64 closed panes" {
}
try testing.expectEqual(@as(usize, max_closed), p.store.closed.items.len);
try testing.expectEqual(serial, p.store.closed.items[max_closed - 1].serial);
- try testing.expect(p.store.reopen(p, serial, p.active));
- try testing.expectEqualStrings("scratch 69\n", p.panes[p.active].?.file.?.content);
+ try testing.expect(p.store.reopen(p, serial, p.view().active));
+ try testing.expectEqualStrings("scratch 69\n", p.panes[p.view().active].?.file.?.content);
}
test "store: a closed pane comes back where it was, its rows from the pane that took them, nothing else moving; Panes lists it, marked" {
@@ -291,36 +291,36 @@ test "store: a closed pane comes back where it was, its rows from the pane that
defer p.deinit();
_ = try p.setTestFile("alpha\nbeta\n");
p.newScratchBelow(0);
- const sid = p.active;
+ const sid = p.view().active;
@import("File.zig").setContent(p, &p.panes[sid].?.file.?, try p.gpa.dupe(u8, "kept text\n"));
p.newScratchBelow(0);
- try testing.expect(layout.splitColumn(p, p.active, p.active, false));
- const far = p.active;
- p.active = 0;
+ try testing.expect(layout.splitColumn(p, p.view().active, p.view().active, false));
+ const far = p.view().active;
+ p.view().active = 0;
// Made outside a step: announced as a step's end would.
pardes.ctlfs.events.announce(p);
layout.compute(p);
- const before = p.rects;
+ const before = p.view().rects;
const serial = p.panes[sid].?.serial;
try p.removePane(sid, null);
layout.compute(p);
- try testing.expectEqualDeep(before[far], p.rects[far]);
+ try testing.expectEqualDeep(before[far], p.view().rects[far]);
try testing.expect(p.store.reopen(p, serial, 0));
- const back = p.active;
+ const back = p.view().active;
layout.compute(p);
try testing.expectEqualStrings("kept text\n", p.panes[back].?.file.?.content);
try testing.expect(p.panes[back].?.serial != serial);
// Its rect as it was, the one above as it was, the other column's
// untouched: its rows came from the pane that took them alone.
- try testing.expectEqualDeep(before[sid], p.rects[back]);
- try testing.expectEqualDeep(before[0], p.rects[0]);
- try testing.expectEqualDeep(before[far], p.rects[far]);
+ try testing.expectEqualDeep(before[sid], p.view().rects[back]);
+ try testing.expectEqualDeep(before[0], p.view().rects[0]);
+ try testing.expectEqualDeep(before[far], p.view().rects[far]);
try testing.expect(p.store.closedBySerial(serial) == null);
// Closed again: Panes lists it after the open ones, `(closed)`.
const again = p.panes[back].?.serial;
pardes.ctlfs.events.announce(p);
try p.removePane(back, null);
- p.active = 0;
+ p.view().active = 0;
p.update(.{ .key = .{ .cp = ' ', .text = " " } });
for ("bb") |ch| p.update(.{ .key = .{ .cp = ch, .text = &.{ch} } });
const qid = for (p.panes, 0..) |slot, i| {
diff --git a/src/Stream.zig b/src/Stream.zig
index 90ab2a1d..6a7dc324 100644
--- a/src/Stream.zig
+++ b/src/Stream.zig
@@ -597,7 +597,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an
s.cancelTask();
const job = makeJob(gpa, s) catch |err| {
s.state = .failed;
- return p.reportError(p.active, "search", err);
+ return p.reportError(p.view().active, "search", err);
};
const future = io.concurrent(work, .{ io, job, ctx, sink }) catch {
// No worker to be had: it runs here, on the loop.
@@ -640,7 +640,7 @@ pub fn runHere(p: *Pardes, gen: u32) void {
if (gen != s.gen or s.state != .searching) return;
const job = makeJob(p.gpa, s) catch |err| {
s.state = .failed;
- return p.reportError(p.active, "search", err);
+ return p.reportError(p.view().active, "search", err);
};
defer job.deinit();
job.waits = false;
diff --git a/src/Tables.zig b/src/Tables.zig
index b0b1930e..c29e6954 100644
--- a/src/Tables.zig
+++ b/src/Tables.zig
@@ -883,7 +883,7 @@ test "tables: a markdown table is drawn aligned, its bytes in order, the caret a
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
const pane = try testPane(p, sample, frame.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const text_x = r.x + config.GUTTER + File.gutterWidth(pane);
const body_y = p.bodyTop(pane, r);
// The k-th pipe of every row on one screen column.
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig
index 9c44ec40..0aee6b52 100644
--- a/src/TerminalImages.zig
+++ b/src/TerminalImages.zig
@@ -148,8 +148,8 @@ pub fn draw(
const pages = &screen.pages;
const top = pages.getTopLeft(.viewport);
const bottom = pages.getBottomRight(.viewport) orelse return;
- const cw: u32 = @max(1, p.cell_pixels.w);
- const ch: u32 = @max(1, p.cell_pixels.h);
+ const cw: u32 = @max(1, p.view().cell_pixels.w);
+ const ch: u32 = @max(1, p.view().cell_pixels.h);
const ctx: Ctx = .{ .ti = ti, .p = p, .pane = pane_id, .serial = serial, .tx = tx, .body_y = body_y, .cols = cols, .rows_of = rows_of, .cw = cw, .ch = ch };
// Handed on lowest z first (the storage's order is a hash map's), the
// order a shell draws them in; equal z keeps the order they came in.
diff --git a/src/addon_test.zig b/src/addon_test.zig
index 3cbb5a64..9acd319b 100644
--- a/src/addon_test.zig
+++ b/src/addon_test.zig
@@ -118,7 +118,7 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
while (rows.next()) |row| try out.print("={s}\n", .{row});
continue;
} else if (!is(verb, "open")) {
- p.active = at;
+ p.view().active = at;
if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb});
}
drain(p);
@@ -129,8 +129,8 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
fn open(p: *Pardes, k: u8, path: ?[]const u8) !usize {
const free = p.freeSlot() orelse return error.NoPaneSlots;
_ = if (path) |at| try Kind.openFile(p, free, k, at) else try Kind.open(p, free, k, null, null);
- pardes.exec.placeNew(p, p.active, null, free, .doc);
- p.active = free;
+ pardes.exec.placeNew(p, p.view().active, null, free, .doc);
+ p.view().active = free;
drain(p);
return free;
}
@@ -152,8 +152,8 @@ fn reloaded(p: *Pardes, gpa: std.mem.Allocator, at: usize, out: *std.Io.Writer)
const pane = try p.newDocPane(free);
pane.addon = fresh;
pardes.dump.reviveSlot(p, free, fresh);
- pardes.exec.placeNew(p, p.active, null, free, .doc);
- p.active = free;
+ pardes.exec.placeNew(p, p.view().active, null, free, .doc);
+ p.view().active = free;
drain(p);
return free;
}
diff --git a/src/builtins.zig b/src/builtins.zig
index a22872df..643fe5bb 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -41,13 +41,13 @@ pub const capabilities: config.Runtime.Capabilities = if (desktop) window_capabi
/// (`Pardes.frontend`, which its client says, Event.frontend).
pub fn viewCapabilities(p: *const Pardes) config.Runtime.Capabilities {
if (comptime !desktop) return frontend;
- return if (p.frontend.windowed) window_capabilities else terminal_capabilities;
+ return if (p.view().frontend.windowed) window_capabilities else terminal_capabilities;
}
/// The live view's frontend, by name (the Settings report's platform).
pub fn viewPlatform(p: *const Pardes) []const u8 {
if (comptime !desktop) return @tagName(pardes.platform);
- return if (p.frontend.windowed) "gui" else "tui";
+ return if (p.view().frontend.windowed) "gui" else "tui";
}
/// Where a builtin acts: at the pane it runs from, or on the editor as a
@@ -179,7 +179,7 @@ pub const registry = struct {
/// cannot show) in a window's view alone. The rest of a build's words are
/// every view's.
pub fn here(p: *const Pardes, b: Builtin()) bool {
- return hereFor(b, viewCapabilities(p), !desktop or p.frontend.windowed);
+ return hereFor(b, viewCapabilities(p), !desktop or p.view().frontend.windowed);
}
/// `here` for a frontend of these capabilities, windowed or not.
@@ -298,11 +298,11 @@ test "Exit asks once about unsaved text, and quits when asked again" {
const pane = try p.setTestFile("saved\n");
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n"));
// Told once, and nothing edited since: the second Exit quits.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
@@ -313,15 +313,15 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
const first = try p.setTestFile("saved\n");
first.file.?.saved_revision = first.file.?.revision -% 1;
first.file.?.saved_hash = 0; // edited: what it had is not what it has
- p.newScratchBelow(p.active);
- const second = p.panes[p.active].?;
+ p.newScratchBelow(p.view().active);
+ const second = p.panes[p.view().active].?;
panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('x'))));
try std.testing.expect(second.file.?.revision != second.file.?.saved_revision);
// A ctl write, or a click through exec (ctl.captured).
if (clicked) p.fs.capturing = true else p.fs.no_prompt = true;
defer p.fs.capturing = false;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
// Two: counted, never a list cut short; `unsaved` records name them.
try std.testing.expectEqualStrings("2 unsaved panes: Modified (Exit again to discard)", p.fs.failure[0..p.fs.failure_len]);
@@ -340,7 +340,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
// Edited since: only that one is named again (acme's rule).
p.fs.failure_len = 0;
panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('y'))));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
const again = p.fs.failure[0..p.fs.failure_len];
try std.testing.expect(std.mem.indexOf(u8, again, first.file.?.path) == null);
@@ -353,7 +353,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), first.file.?.path) == null);
try std.testing.expect(std.mem.startsWith(u8, again, second.file.?.path));
p.fs.failure_len = 0;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
}
@@ -385,10 +385,10 @@ test "Restore asks about unsaved text as Exit does, and restores when asked agai
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
var line_buf: [4200]u8 = undefined;
const line = try testDump(&line_buf);
- try std.testing.expect(p.executeBuiltinLine(p.active, line));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, line));
try std.testing.expect(p.restore_req == null);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nRestore again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, line));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, line));
try std.testing.expectEqualStrings(line["Restore ".len..], p.restore_req.?);
}
@@ -400,7 +400,7 @@ test "a Restore of a dump that cannot be read says so, before the unsaved-text w
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
p.fs.no_prompt = true;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Restore /nope/missing.zon"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Restore /nope/missing.zon"));
try std.testing.expect(p.restore_req == null);
try std.testing.expectEqualStrings("Restore: /nope/missing.zon: no such file", p.fs.failure[0..p.fs.failure_len]);
// No warning spent: the Exit after it still asks.
@@ -414,13 +414,13 @@ test "a Restore's warning is not an Exit's: each word is warned on its own" {
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
var line_buf: [4200]u8 = undefined;
- try std.testing.expect(p.executeBuiltinLine(p.active, try testDump(&line_buf)));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try testDump(&line_buf)));
try std.testing.expect(p.restore_req == null);
// The Restore warned; an Exit after it has not been, and asks.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
@@ -428,7 +428,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const term = p.active;
+ const term = p.view().active;
try std.testing.expect(p.panes[term].?.isTerminal());
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
p.update(.{ .output = .{ .pane = @intCast(term), .bytes = prompt } });
@@ -445,7 +445,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
}
fn count(pp: *Pardes, line: []const u8) usize {
asked = 0;
- _ = pp.executeBuiltinLine(pp.active, line);
+ _ = pp.executeBuiltinLine(pp.view().active, line);
return asked;
}
};
@@ -1282,7 +1282,7 @@ pub const Del = struct {
{
c.pane.prompt = .del_side;
c.pane.question_due_ns = exec.clockNow(c.p) + config.del_question_delay_ns;
- c.p.active = c.id;
+ c.p.view().active = c.id;
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch "");
// The question says Del already.
@@ -1515,8 +1515,8 @@ pub const Joincol = struct {
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
// The keyboard's column joins the one to its right; the last has none.
- const col = layout.keyboardColumn(c.p, c.p.active) orelse return;
- if (col + 1 >= c.p.ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right");
+ const col = layout.keyboardColumn(c.p, c.p.view().active) orelse return;
+ if (col + 1 >= c.p.view().ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right");
// As Newcol is refused: a column that could not give each pane its
// tag and 2 rows would leave a layout `size` refuses as it is.
if (!layout.joinFits(c.p, col)) return c.p.reportFailure(c.id, "Joincol: no space: the joined column cannot give each pane its tag and 2 rows");
@@ -1565,7 +1565,7 @@ pub const Config = struct {
panes.newScratchFor(c.p, c.id, .scratch);
if (c.p.panes[free] == null) return;
@import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, "Config", err);
- c.p.active = free;
+ c.p.view().active = free;
}
};
@@ -1723,7 +1723,7 @@ pub const Panes = struct {
/// Move the keyboard to the pane, or column tag, to the left.
pub const Left = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
if (c.p.headerColumn()) |column| if (column > 0) tagline.enterHeader(c.p, column - 1);
return;
}
@@ -1734,16 +1734,16 @@ pub const Left = struct {
/// Move the keyboard to the pane below, off a tag onto the pane under it.
pub const Down = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
const column = layout.findPane(c.p, c.id);
if (c.p.headerColumn() == null and layout.columnBarHeight(c.p) > 0)
return tagline.enterHeader(c.p, if (column) |at| at.col else 0);
// Onto the top pane of the column the header stands over.
const col = c.p.headerColumn() orelse if (column) |at| at.col else return;
// An empty column's tag has nothing below it.
- if (col < c.p.ncol and c.p.cols[col].n == 0) return;
+ if (col < c.p.view().ncol and c.p.view().cols[col].n == 0) return;
tagline.exitHeader(c.p);
- if (col < c.p.ncol) c.p.active = c.p.cols[col].panes[0];
+ if (col < c.p.view().ncol) c.p.view().active = c.p.view().cols[col].panes[0];
return;
}
_ = layout.focusDir(c.p, c.id, .down);
@@ -1753,7 +1753,7 @@ pub const Down = struct {
/// Move the keyboard to the pane above, and from a column's top pane to its tag.
pub const Up = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
if (c.p.headerColumn() != null and c.p.topBarHeight() > 0) tagline.enterHeader(c.p, null);
return;
}
@@ -1767,8 +1767,8 @@ pub const Up = struct {
/// Move the keyboard to the pane, or column tag, to the right.
pub const Right = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
- if (c.p.headerColumn()) |column| if (column + 1 < c.p.ncol) tagline.enterHeader(c.p, column + 1);
+ if (c.p.view().header != null) {
+ if (c.p.headerColumn()) |column| if (column + 1 < c.p.view().ncol) tagline.enterHeader(c.p, column + 1);
return;
}
_ = layout.focusDir(c.p, c.id, .right);
@@ -1780,7 +1780,7 @@ pub const Right = struct {
pub const Window = struct {
pub fn run(c: Ctx) void {
tagline.exitHeader(c.p);
- c.p.window_pick = if (c.p.panes[c.id] != null) c.id else c.p.active;
+ c.p.view().window_pick = if (c.p.panes[c.id] != null) c.id else c.p.view().active;
}
};
@@ -1821,10 +1821,10 @@ pub const LookPrev = struct {
/// Go back to the last place jumped from in another pane.
pub const Last = struct {
pub fn run(c: Ctx) void {
- var i = c.p.jumps.n;
+ var i = c.p.view().jumps.n;
while (i > 0) {
i -= 1;
- const j = c.p.jumps.list[i];
+ const j = c.p.view().jumps.list[i];
if (j.serial == 0) continue; // a closed file's: Back reopens it, Last goes to a pane
// Restore the cursor without recentering the pane's retained view.
if (j.pane != c.id) return look.focusPaneLine(c.p, j.pane, .{ .line = j.line, .col = j.col }, .keep);
@@ -2006,25 +2006,25 @@ test "Exit and Restore name a modified +New scratch as well as files" {
const file = try p.setTestFile("saved\n");
file.file.?.saved_revision = file.file.?.revision -% 1; // modified
file.file.?.saved_hash = 0; // edited: what it had is not what it has
- p.newScratchBelow(p.active);
- const scratch = &p.panes[p.active].?.file.?;
+ p.newScratchBelow(p.view().active);
+ const scratch = &p.panes[p.view().active].?.file.?;
scratch.content = try p.gpa.realloc(scratch.content, 120);
@memset(scratch.content, 'n'); // past acme's 100 bytes, where it whines
scratch.revision +%= 1; // typed into, never saved
scratch.saved_hash = 0; // edited: what it had is not what it has
p.fs.no_prompt = true;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
// Each pane's message row names it; the write's refusal counts them.
try std.testing.expectEqualStrings("2 unsaved panes: Modified (Exit again to discard)", p.fs.failure[0..p.fs.failure_len]);
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "test.txt: Modified") != null);
- const scratch_pane = p.panes[p.active].?;
+ const scratch_pane = p.panes[p.view().active].?;
var named: [64]u8 = undefined;
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), try std.fmt.bufPrint(&named, "{s} (pane {d})", .{ config.scratch_buffer, scratch_pane.serial })) != null);
// Delcol, Restore and Exit name it the same way.
p.fs.failure_len = 0;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Delcol"));
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "Delcol again to discard") == null);
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), named[0 .. config.scratch_buffer.len + 7]) != null);
}
@@ -2036,22 +2036,22 @@ test "Del and Delcol refuse a pane with unsaved text once, as acme's do, and clo
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
const serial = pane.serial;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Delcol"));
try std.testing.expect(p.paneBySerial(serial) != null);
// A refused Delcol changes nothing: no +Unsaved (its records say it).
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "Delcol") == null);
// Each word is warned on its own: Del asks too, then closes.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Del"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Del"));
try std.testing.expect(p.paneBySerial(serial) != null);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nDel again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Del"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Del"));
try std.testing.expect(p.paneBySerial(serial) == null);
}
test "a pane renamed but never edited has no text to lose: Del closes it at once" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- p.newScratchBelow(p.active);
+ p.newScratchBelow(p.view().active);
const pane = try p.setTestFile("loaded\n");
pane.file.?.saved_revision = pane.file.?.revision -% 1; // dirty by the rename alone
const serial = pane.serial;
diff --git a/src/colors.zig b/src/colors.zig
index b028888f..de20cf9b 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -998,8 +998,8 @@ test "line numbers stay quiet without a current-line tag background" {
custom.lineno_active = .{ 95, 95, 95 };
p.custom_theme = custom;
p.sync();
- const x = p.rects[0].x + config.GUTTER;
- const y = p.rects[0].y + BOX_H;
+ const x = p.view().rects[0].x + config.GUTTER;
+ const y = p.view().rects[0].y + BOX_H;
const surface = try p.render(p.scratch.allocator());
try std.testing.expectEqual(Color{ .rgb = .{ 95, 95, 95 } }, surface.at(x, y).style.fg);
try std.testing.expectEqual(Color{ .rgb = .{ 70, 70, 70 } }, surface.at(x, y + 1).style.fg);
diff --git a/src/config.zig b/src/config.zig
index 2f72d332..ae9b774a 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -192,17 +192,17 @@ test "Space-k is unbound while Exit, Kill and other k chords remain available" {
pane.body.cur_row = 1;
while (p.nextEffect()) |_| {}
p.update(.{ .key = .{ .cp = ' ' } });
- try std.testing.expect(p.prefix == .leader);
+ try std.testing.expect(p.view().prefix == .leader);
p.update(.{ .key = .{ .cp = 'k' } });
- try std.testing.expect(p.prefix != .leader and !p.quit);
+ try std.testing.expect(p.view().prefix != .leader and !p.quit);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
while (p.nextEffect()) |effect| try std.testing.expect(effect != .quit);
p.update(.{ .key = .{ .cp = 'k' } });
try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
// Kill stops commands and never quits; Exit quits.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Kill"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Kill"));
try std.testing.expect(!p.quit);
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
diff --git a/src/draw.zig b/src/draw.zig
index 4c476914..c97e2a6c 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -42,16 +42,17 @@ const NOTICE_LAYER_BASE = pardes.NOTICE_LAYER_BASE;
/// and notice chips; each column's grip and tag; the workspace tag. The
/// painters below and every shell read these rectangles.
pub fn place(p: *Pardes, s: *Surface) void {
+ const v = p.view();
s.nregions = 0;
s.nrail_ticks = 0;
s.addRegion(.{ .kind = .page, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = s.rows } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
- Messages.collectNotices(p, pane, p.rects[id], id);
- const r = p.rects[id];
+ Messages.collectNotices(p, pane, v.rects[id], id);
+ const r = v.rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const owner: u8 = @intCast(id);
- const active = id == p.active;
+ const active = id == v.active;
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
s.addRegion(.{ .kind = .grip, .owner = owner, .serial = pane.serial, .active = active, .dirty = tagline.dirty(pane), .rect = .{ .x = r.x, .y = tag_y, .w = config.GUTTER, .h = pane.tag_rows } });
@@ -106,28 +107,28 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
}
const column_rows = layout.columnBarHeight(p);
- if (column_rows > 0) for (0..p.ncol) |c| {
- if (p.col_w[c] == 0) continue;
- const active = if (layout.findPane(p, p.active)) |found| found.col == c else false;
- const inset = @min(TAG_TEXT_INSET, p.col_w[c]);
- s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, p.col_w[c]), .h = column_rows } });
- s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c] + inset, .y = p.topBarHeight(), .w = p.col_w[c] - inset, .h = column_rows } });
+ if (column_rows > 0) for (0..p.view().ncol) |c| {
+ if (v.col_w[c] == 0) continue;
+ const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
+ const inset = @min(TAG_TEXT_INSET, v.col_w[c]);
+ s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, v.col_w[c]), .h = column_rows } });
+ s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active, .rect = .{ .x = v.col_x[c] + inset, .y = p.topBarHeight(), .w = v.col_w[c] - inset, .h = column_rows } });
};
- const active_col = if (layout.findPane(p, p.active)) |found| found.col else null;
- for (0..p.ncol) |c| {
- if (p.col_w[c] == 0) continue;
- s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active_col == c, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = p.col_w[c], .h = s.rows -| p.topBarHeight() } });
+ const active_col = if (layout.findPane(p, v.active)) |found| found.col else null;
+ for (0..p.view().ncol) |c| {
+ if (v.col_w[c] == 0) continue;
+ s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| p.topBarHeight() } });
}
if (p.settings.workspace_tag)
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
// A column carried to the window's right edge shows where it lands as a
// rail in the last cell: the layers under it stop a cell short.
- if (p.drag == .column_move) rail: {
- const d = p.drag.column_move;
+ if (v.drag == .column_move) rail: {
+ const d = v.drag.column_move;
const source = layout.columnBySerial(p, d.serial) orelse break :rail;
const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
.stay => break :rail,
- .reorder => |target| if (target < source) p.col_x[target] else p.col_x[target] + p.col_w[target],
+ .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
.edge => |x| x,
};
if (edge != s.cols) break :rail;
@@ -164,20 +165,21 @@ fn inkOn(bg: [3]u8) [3]u8 {
}
pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
+ const v = p.view();
const taped = pardes.tape.enter(p, .render);
defer pardes.tape.leave(p, taped);
panes.terminal.drawing = true;
defer panes.terminal.drawing = false;
panes.File.refreshHighlights(p);
const s = &p.surface;
- const ncells = @as(usize, p.screen_w) * p.screen_h;
+ const ncells = @as(usize, v.screen_w) * v.screen_h;
if (s.cells.len != ncells) {
const cells = try p.gpa.alloc(Cell, ncells);
p.gpa.free(s.cells);
s.cells = cells;
}
- s.cols = p.screen_w;
- s.rows = p.screen_h;
+ s.cols = v.screen_w;
+ s.rows = v.screen_h;
s.cursor = null;
s.pointer_shape = .arrow;
if (comptime pdf_enabled) if (p.pdf_hover_preview) |preview| {
@@ -193,7 +195,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// the pointer per-text (the macOS I-beam) read this as "target" and
// afford it the arrow instead.
if (p.look_hover_preview != null) s.pointer_shape = .target;
- if (p.drag == .move or p.drag == .column_move) s.pointer_shape = .box;
+ if (v.drag == .move or v.drag == .column_move) s.pointer_shape = .box;
for (&s.body_layers) |*layer| layer.rows = 0;
for (&s.tag_layers) |*layer| layer.rows = 0;
s.placements.clearRetainingCapacity();
@@ -221,12 +223,12 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// Separators have their own role; a scrollbar need not frame the page.
const whole = s.regions[0].rect;
s.fill(whole.x, whole.y, whole.w, whole.h, .{ .bg = .{ .rgb = chrome.border } });
- for (0..p.ncol) |c| if (p.cols[c].n == 0) s.fill(p.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), p.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
+ for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
s.body_layers[id].rows = 0;
- try renderPane(p, s, arena, pane, p.rects[id], id, id == p.active);
+ try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active);
}
// Each notice once, as a tag layer, and the grid's chip a copy of it.
for (s.regionList()) |region| {
@@ -235,7 +237,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
try paintHeaders(p, s);
- switch (p.drag) {
+ switch (v.drag) {
.border_v => |d| {
if (d.cur_x < s.cols) {
var row: u16 = p.topBarHeight();
@@ -243,19 +245,19 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = p.topBarHeight(), .w = 1, .h = s.rows -| p.topBarHeight() } });
}
if (d.corner) |k| if (d.cur_y < s.rows) {
- const first = if (k.col == d.left_col) p.col_x[k.col] else d.cur_x +| 1;
- const end = if (k.col == d.left_col) d.cur_x else p.col_x[k.col] +| p.col_w[k.col] -| 1;
+ const first = if (k.col == d.left_col) v.col_x[k.col] else d.cur_x +| 1;
+ const end = if (k.col == d.left_col) d.cur_x else v.col_x[k.col] +| v.col_w[k.col] -| 1;
var col = first;
while (col <= end and col < s.cols) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
if (col > first) s.addRegion(.{ .kind = .guide, .rect = .{ .x = first, .y = d.cur_y, .w = col - first, .h = 1 } });
};
},
// A column that went away mid-drag has nothing to guide.
- .border_h => |d| if (d.cur_y < s.rows and d.col < p.ncol and p.col_x[d.col] < s.cols) {
- const end = @min(s.cols, p.col_x[d.col] + p.col_w[d.col]);
- var col = p.col_x[d.col];
+ .border_h => |d| if (d.cur_y < s.rows and d.col < v.ncol and v.col_x[d.col] < s.cols) {
+ const end = @min(s.cols, v.col_x[d.col] + v.col_w[d.col]);
+ var col = v.col_x[d.col];
while (col < end) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = p.col_x[d.col], .y = d.cur_y, .w = end - p.col_x[d.col], .h = 1 } });
+ s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[d.col], .y = d.cur_y, .w = end - v.col_x[d.col], .h = 1 } });
},
.column_move => |d| rail: {
const source = layout.columnBySerial(p, d.serial) orelse break :rail;
@@ -263,7 +265,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// Where the column's left edge would land, reordered or not.
const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
.stay => break :rail,
- .reorder => |target| if (target < source) p.col_x[target] else p.col_x[target] + p.col_w[target],
+ .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
.edge => |x| x,
};
// The layers under an outside rail stop a cell short of it:
@@ -292,13 +294,13 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
},
.move => |d| if (d.cur_x < s.cols) {
- if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and p.col_x[placement.preview_col] + p.col_w[placement.preview_col] <= s.cols) {
- var col: u16 = p.col_x[placement.preview_col];
- while (col < p.col_x[placement.preview_col] + p.col_w[placement.preview_col]) : (col += 1) {
+ if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and v.col_x[placement.preview_col] + v.col_w[placement.preview_col] <= s.cols) {
+ var col: u16 = v.col_x[placement.preview_col];
+ while (col < v.col_x[placement.preview_col] + v.col_w[placement.preview_col]) : (col += 1) {
s.set(col, placement.row, "╌", .{ .fg = .{ .rgb = chrome.lineno } });
}
s.set(d.cur_x, placement.row, "▌", .{ .fg = .{ .rgb = chrome.lineno } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = p.col_x[placement.preview_col], .y = placement.row, .w = p.col_w[placement.preview_col], .h = 1 } });
+ s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[placement.preview_col], .y = placement.row, .w = v.col_w[placement.preview_col], .h = 1 } });
s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = placement.row, .w = 1, .h = 1 } });
};
},
@@ -307,7 +309,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
}
// debug overlay: a small stats box drawn last, top-right ("Debug")
- if (p.settings.debug) if (p.panes[p.active]) |at| {
+ if (p.settings.debug) if (p.panes[v.active]) |at| {
var nlive: usize = 0;
for (p.panes) |slot| {
if (slot != null) nlive += 1;
@@ -336,7 +338,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
const text = std.fmt.bufPrint(
&ov_buf,
"pardes resizes={d}\ntheme {s}\nfont {s}\nterms {d} cols {d}\nactive #{d} {d}x{d}\nscroll {d}/{d}\n{s}",
- .{ p.resize_count, p.theme().name, font_name[0..@min(font_name.len, 64)], nlive, p.ncol, p.active, at.cols, at.rows, sb_off, sb_total, timings },
+ .{ p.resize_count, p.theme().name, font_name[0..@min(font_name.len, 64)], nlive, v.ncol, v.active, at.cols, at.rows, sb_off, sb_total, timings },
) catch "";
// wide enough for the longest theme name compiled in, which is the
// only row here whose width is not ours to choose
@@ -419,7 +421,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
.font_role = .tagline,
});
// In window mode the box holds the pane's letter instead of its mode.
- const label: ?u8 = if (p.window_pick != null) layout.windowLabel(p, id) else null;
+ const label: ?u8 = if (p.view().window_pick != null) layout.windowLabel(p, id) else null;
s.set(r.x, tag_y, if (label) |*letter| @as(*const [1]u8, letter) else switch (pane.body.mode) {
.normal => config.tag_normal,
.insert => config.tag_insert,
@@ -467,11 +469,12 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
/// The workspace and column tags: each line a tag layer, and the grid's
/// rows copies of those; the column grips, which are the grid's alone.
fn paintHeaders(p: *Pardes, s: *Surface) !void {
+ const v = p.view();
const chrome = p.chromeTheme();
// global tagbar: full width, top rows — unless a native shell has
// taken its commands over, in which case the rows are not ours to draw
if (s.region(.workspace_tag, Region.none)) |region| {
- const top = if (p.header != null and p.headerColumn() == null) p.header_top else 0;
+ const top = if (v.header != null and p.headerColumn() == null) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + MAX_COLS];
var viewport = region.rect;
const inset = @min(TAG_TEXT_INSET, viewport.w);
@@ -482,28 +485,28 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
joinHeaderRows(s, layer, chrome.tag_fg);
}
const column_rows = layout.columnBarHeight(p);
- if (column_rows > 0) for (0..p.ncol) |c| {
+ if (column_rows > 0) for (0..p.view().ncol) |c| {
const region = s.region(.column_tag, c) orelse continue;
- const active = if (layout.findPane(p, p.active)) |found| found.col == c else false;
+ const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
const bg = if (active) chrome.tag_active_bg else chrome.tag_bg;
const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
- if (p.col_x[c] < s.cols) {
+ if (v.col_x[c] < s.cols) {
// A grip is muted until it is grabbed; then it lights, as a
// pane's box does for the active pane, so the drag shows what it
// holds.
- const grip = @min(config.GUTTER, p.col_w[c]);
- const inset = @min(TAG_TEXT_INSET, p.col_w[c]);
- const grabbed = p.drag == .column_move and layout.columnBySerial(p, p.drag.column_move.serial) == c;
+ const grip = @min(config.GUTTER, v.col_w[c]);
+ const inset = @min(TAG_TEXT_INSET, v.col_w[c]);
+ const grabbed = v.drag == .column_move and layout.columnBySerial(p, v.drag.column_move.serial) == c;
const grip_bg = if (grabbed) chrome.column_box else chrome.column_box_dim;
const ink = inkOn(grip_bg);
- s.fill(p.col_x[c], region.rect.y, grip, @min(1, column_rows), .{ .bg = .{ .rgb = grip_bg }, .fg = .{ .rgb = ink }, .font_role = .tagline });
- s.fill(p.col_x[c], region.rect.y + 1, grip, column_rows -| 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
- s.fill(p.col_x[c] + grip, region.rect.y, inset - grip, column_rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
+ s.fill(v.col_x[c], region.rect.y, grip, @min(1, column_rows), .{ .bg = .{ .rgb = grip_bg }, .fg = .{ .rgb = ink }, .font_role = .tagline });
+ s.fill(v.col_x[c], region.rect.y + 1, grip, column_rows -| 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
+ s.fill(v.col_x[c] + grip, region.rect.y, inset - grip, column_rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
}
- const top = if (p.header != null and p.headerColumn() == c) p.header_top else 0;
+ const top = if (v.header != null and p.headerColumn() == c) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + c];
try renderHeaderLayer(p, layer, .column, @intCast(c), region.rect, tagline.columnTag(p, c), top, bg, fg);
- if (p.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
+ if (v.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
// Laid out at its full width; only shown short of the rail.
layer.viewport.w -|= region.clip;
};
@@ -575,6 +578,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct {
/// of `text` and on, laid out at the tagline's pitch -- as wide as its
/// widest line and never narrower than its viewport.
fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, viewport: Rect, text: []const u8, top: usize, bg: [3]u8, fg: [3]u8) !void {
+ const v = p.view();
if (viewport.w == 0 or viewport.h == 0) {
// No layer, and nothing of an earlier frame's left in it.
layer.rows = 0;
@@ -589,7 +593,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
layer.kind = kind;
layer.id = id;
- layer.serial = if (kind == .column) p.cols[id].serial else 0;
+ layer.serial = if (kind == .column) v.cols[id].serial else 0;
layer.viewport = viewport;
layer.cols = columns;
layer.rows = viewport.h;
@@ -599,12 +603,12 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
// A notice band carries a PANE id, not a column index, so it must not
// answer to the column being edited -- that would scroll and select
// its text with the column tag's offsets and give it a second caret.
- const editing: ?*Text = if (p.header != null and switch (kind) {
+ const editing: ?*Text = if (v.header != null and switch (kind) {
.workspace => p.headerColumn() == null,
.column => p.headerColumn() == id,
.pane, .notice, .body => false,
}) tagline.focusedHeader(p) else null;
- const scroll = if (editing != null) p.header_scroll else 0;
+ const scroll = if (editing != null) v.header_scroll else 0;
for (0..viewport.h) |index| {
const line: u16 = @intCast(index);
const shown = modal.lineSlice(text, index + top);
@@ -617,13 +621,13 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
// (joined from this); not on a column a carried column's pointer is
// aiming at a place over; nor under a held middle or right sweep,
// which paints what it sweeps instead.
- const hovered = p.pointer_inside and !(kind == .column and p.drag == .column_move) and p.header_sweep == null;
+ const hovered = v.pointer_inside and !(kind == .column and v.drag == .column_move) and v.header_sweep == null;
if (hovered) {
- const tag_hit = p.pointer_tag_hit;
+ const tag_hit = v.pointer_tag_hit;
const col: ?usize = if (tag_hit) |pointer|
(if (pointer.kind == kind and pointer.id == id and pointer.line == line) pointer.col else null)
- else if (p.hover_row == viewport.y + line and p.hover_col >= viewport.x and p.hover_col - viewport.x < viewport.w)
- p.hover_col - viewport.x
+ else if (v.hover_row == viewport.y + line and v.hover_col >= viewport.x and v.hover_col - viewport.x < viewport.w)
+ v.hover_col - viewport.x
else
null;
if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(shown, hover + scroll))) |bounds| {
@@ -636,7 +640,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
};
}
if (editing) |t| {
- if (tagline.headerSelection(t, try edit.flatSurface(p, t), line + p.header_top)) |span| {
+ if (tagline.headerSelection(t, try edit.flatSurface(p, t), line + v.header_top)) |span| {
var col = panes.File.rawDisplayCol(shown, span.lo) -| scroll;
const end = panes.File.rawDisplayCol(shown, span.hi) -| scroll;
while (col < end and col < columns) : (col += 1) {
@@ -645,12 +649,12 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
}
}
const caret = panes.File.rawDisplayCol(shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll;
- const asking = if (p.panes[p.active]) |active| active.prompt != .none else false;
- if (!asking and t.cur_row == line + p.header_top and caret < columns) layer.cursor = .{ .x = @intCast(caret), .y = line, .bar = t.mode == .insert };
+ const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
+ if (!asking and t.cur_row == line + v.header_top and caret < columns) layer.cursor = .{ .x = @intCast(caret), .y = line, .bar = t.mode == .insert };
}
// A middle or right sweep held over this header, tinted by its
// button as a pane tag's is.
- if (p.header_sweep) |sweep| if (sweep.column(p)) |column| {
+ if (v.header_sweep) |sweep| if (sweep.column(p)) |column| {
const mine = switch (kind) {
.workspace => column == null,
.column => column == id,
@@ -675,6 +679,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
/// A pane's tag rows, painted once into their layer, a row to a line, and
/// copied into the grid; the grid's caret where the layer has it.
fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
+ const v = p.view();
const capacity = layout.tagCapacity(p, r.w -| TAG_TEXT_INSET);
// Too narrow for a layer: only the grid's gap cell.
if (r.w <= TAG_TEXT_INSET) return paintPaneTag(p, s, arena, pane, r, id, active);
@@ -696,7 +701,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active);
// Window mode (layout.windowKey): the outlined pane's tag in the
// selection's colours.
- if (p.window_pick == id) {
+ if (v.window_pick == id) {
for (0..rows) |row| temporary.tint(0, @intCast(row), temporary.cols, p.theme().sel_bg, p.theme().sel_fg);
}
const tag_fg: Color = .{ .rgb = if (active) chrome.tag_active_fg else chrome.tag_fg };
@@ -711,8 +716,8 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
- layer.bg = if (p.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
- layer.cursor = if (p.header != null) null else if (temporary.cursor) |cursor|
+ layer.bg = if (v.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
+ layer.cursor = if (v.header != null) null else if (temporary.cursor) |cursor|
.{ .x = cursor.x - TAG_TEXT_INSET, .y = cursor.y, .bar = cursor.bar }
else
null;
@@ -731,12 +736,13 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
/// A notice chip, painted once as a tag layer at the tagline's pitch, and the
/// grid's chip a copy of its right end, where its text is.
fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) !void {
+ const v = p.view();
const chrome = p.chromeTheme();
const id: usize = region.owner;
const pane = p.panes[id].?;
const i: usize = region.notice;
const kind = pane.notices.kinds[i];
- const r = p.rects[id];
+ const r = v.rects[id];
const chip = region.rect.w;
var leader_buf: [16]u8 = undefined;
const text = Messages.noticeText(p, pane, i, &leader_buf);
@@ -749,7 +755,7 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
if (text.len == 0) return;
const printed = Messages.printRight(s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
- if (kind != .prompt or id != p.active or pane.prompt == .del_side or pane.prompt == .repl_choice) return;
+ if (kind != .prompt or id != v.active or pane.prompt == .del_side or pane.prompt == .repl_choice) return;
const prompt_col = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
if (prompt_col < printed.dropped) return;
s.cursor = .{ .x = @intCast(printed.left + (prompt_col - printed.dropped)), .y = region.rect.y, .bar = pane.input.mode == .insert };
@@ -776,7 +782,7 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
const layer = &s.tag_layers[NOTICE_LAYER_BASE + id * Pane.Notices.max + i];
try renderHeaderLayer(p, layer, .notice, @intCast(id), region.rect, line, 0, bg, fg);
// The caret rides the band, where the prompt's glyphs are.
- if (kind == .prompt and id == p.active and pane.prompt != .del_side and pane.prompt != .repl_choice) caret: {
+ if (kind == .prompt and id == v.active and pane.prompt != .del_side and pane.prompt != .repl_choice) caret: {
const typed = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
const dropped = shown - panes.File.displayWidth(kept);
if (typed < dropped) break :caret;
@@ -934,10 +940,10 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
defer arena.deinit();
for (pardes.themes[0..colors.native_count], 0..) |theme, index| {
colors.setThemeIndex(p, index);
- p.active = 1;
+ p.view().active = 1;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const grip = s.at(r.x, p.tagTop(p.panes[0].?, r)).style.bg.rgb;
const ratio = colors.contrast(grip, p.chromeTheme().tag_bg);
// ponytail: dark and helix have always had a faint grip (1.2:1); flagged, not changed here.
@@ -959,12 +965,12 @@ test "a grip's four states, focused or not and clean or dirty, are each its own
colors.setThemeIndex(p, index);
var states: [4]State = undefined;
for (&states, 0..) |*state, i| {
- p.active = if (i & 1 == 0) 0 else 1;
+ p.view().active = if (i & 1 == 0) 0 else 1;
const saved = pane.file.?.saved_revision;
pane.file.?.revision = if (i & 2 != 0) saved + 1 else saved;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const y = p.tagTop(pane, r);
state.* = .{ .first = s.at(r.x, y).*, .second = s.at(r.x + 1, y).*, .dirty = s.region(.grip, 0).?.dirty };
try std.testing.expectEqual(i & 2 != 0, state.dirty);
@@ -988,7 +994,7 @@ test "every theme draws a file's name, a +Errors and a Term word in a tint, neve
defer p.deinit();
_ = try p.setTestFile("text\n");
try std.testing.expect(p.executeBuiltinLine(0, "Term+sh"));
- const terminal = p.active;
+ const terminal = p.view().active;
p.acknowledgeShell(terminal, "/bin/sh", false);
try @import("Output.zig").openErrors(p, 0, try gpa.dupe(u8, "oops\n"));
while (p.nextEffect()) |_| {}
@@ -1004,11 +1010,11 @@ test "every theme draws a file's name, a +Errors and a Term word in a tint, neve
colors.setThemeIndex(p, index);
// Each pane focused in turn: every word on both grounds.
for (probes) |focused| {
- p.active = focused.id;
+ p.view().active = focused.id;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
for (probes) |probe| {
- const r = p.rects[probe.id];
+ const r = p.view().rects[probe.id];
const y = p.tagTop(p.panes[probe.id].?, r);
// The row's text, and the column each byte of it is drawn at.
var row: [512]u8 = undefined;
@@ -1045,7 +1051,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil
p.sync();
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const top = p.tagTop(pane, r);
try std.testing.expect(pane.tag_rows >= 3);
const chrome = p.chromeTheme();
@@ -1073,11 +1079,11 @@ test "place puts every part where the painters and layers put it, in every layou
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
for (0..16) |step| {
- if (step & 4 != 0) try std.testing.expect(p.executeBuiltinLine(p.active, "Msg a placed notice"));
+ if (step & 4 != 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg a placed notice"));
if (step == 8) try std.testing.expect(p.executeBuiltinLine(1, "Collapse"));
if (step == 12) try std.testing.expect(p.executeBuiltinLine(1, "Collapse"));
if (step == 10) {
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
pane.tag.own = try std.testing.allocator.dupe(u8, "Second\nthird");
}
p.sync();
@@ -1086,7 +1092,7 @@ test "place puts every part where the painters and layers put it, in every layou
try std.testing.expectEqual(Region.Kind.page, s.regions[0].kind);
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const grip = s.region(.grip, id).?;
try std.testing.expectEqual(Rect{ .x = r.x, .y = p.tagTop(pane, r), .w = config.GUTTER, .h = pane.tag_rows }, grip.rect);
@@ -1125,13 +1131,13 @@ test "place puts every part where the painters and layers put it, in every layou
}
try std.testing.expectEqual(@as(usize, pane.notices.len), notices);
}
- for (0..p.ncol) |c| {
+ for (0..p.view().ncol) |c| {
const region = s.region(.column_tag, c);
if (layout.columnBarHeight(p) == 0) {
try std.testing.expect(region == null);
continue;
}
- try std.testing.expectEqual(Rect{ .x = p.col_x[c] + TAG_TEXT_INSET, .y = p.topBarHeight(), .w = p.col_w[c] - TAG_TEXT_INSET, .h = layout.columnBarHeight(p) }, region.?.rect);
+ try std.testing.expectEqual(Rect{ .x = p.view().col_x[c] + TAG_TEXT_INSET, .y = p.topBarHeight(), .w = p.view().col_w[c] - TAG_TEXT_INSET, .h = layout.columnBarHeight(p) }, region.?.rect);
}
}
}
@@ -1142,7 +1148,7 @@ test "the word under the pointer on a notice is lit in its layer and in the grid
_ = try p.setTestFile("text\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg Look here"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg Look here"));
p.sync();
var s = try p.render(arena.allocator());
const notice = for (s.regionList()) |region| {
@@ -1152,9 +1158,9 @@ test "the word under the pointer on a notice is lit in its layer and in the grid
// "here", the chip's last word, before its blank edge.
const here = notice.rect.x + notice.rect.w - 5;
try std.testing.expectEqualStrings("h", row[here].grapheme());
- p.pointer_inside = true;
- p.hover_col = here + 1;
- p.hover_row = notice.rect.y;
+ p.view().pointer_inside = true;
+ p.view().hover_col = here + 1;
+ p.view().hover_row = notice.rect.y;
_ = arena.reset(.retain_capacity);
s = try p.render(arena.allocator());
const lit = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols];
@@ -1182,7 +1188,7 @@ test "a notice wider than its band, as a shader's compile error is, draws its en
const long = std.mem.asBytes(&@as([3][126]u8, @splat("Shader /home/someone/shaders/test_shadertoy_invalid.glsl: error: Linking fragment stage: No function definition (body) found: ".*)));
for ([_][]const u8{ "Msg " ++ long, "" }) |line| {
// The Msg builtin, and the path a failed compile takes (Post.zig).
- if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.active, line)) else p.setMessage(p.active, long);
+ if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, line)) else p.setMessage(p.view().active, long);
p.sync();
for (0..30) |_| p.update(.tick);
_ = arena.reset(.retain_capacity);
@@ -1230,12 +1236,12 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
1, 2 => {
text.clearRetainingCapacity();
for (0..random.uintAtMost(usize, 60)) |_| try text.appendSlice(std.testing.allocator, words[random.uintLessThan(usize, words.len)]);
- if (random.boolean()) p.setMessage(p.active, text.items) else {
+ if (random.boolean()) p.setMessage(p.view().active, text.items) else {
const line = try std.fmt.allocPrint(arena.allocator(), "Msg {s}", .{text.items});
- _ = p.executeBuiltinLine(p.active, line);
+ _ = p.executeBuiltinLine(p.view().active, line);
}
},
- 3 => _ = p.executeBuiltinLine(p.active, commands[random.uintLessThan(usize, commands.len)]),
+ 3 => _ = p.executeBuiltinLine(p.view().active, commands[random.uintLessThan(usize, commands.len)]),
// Typing, escaping and entering, into a prompt when one is up.
4 => p.update(.{ .key = .{ .cp = switch (random.uintLessThan(u8, 9)) {
0 => pardes.Key.escape,
@@ -1248,7 +1254,7 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
else => 'a' + random.uintLessThan(u21, 26),
} } }),
// A tag of several rows.
- 5 => if (p.panes[p.active]) |pane| {
+ 5 => if (p.panes[p.view().active]) |pane| {
text.clearRetainingCapacity();
for (0..random.uintAtMost(usize, 5)) |_| try text.appendSlice(std.testing.allocator, if (random.boolean()) " Look\nmore \u{754c}" else "\n" ++ &@as([150]u8, @splat('x')));
if (pane.tag.own) |own| std.testing.allocator.free(own);
@@ -1256,8 +1262,8 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
},
// Hover, and clicks: into a tag, a header, a body, a grip.
6 => {
- const col = random.uintAtMost(u16, p.screen_w);
- const row = random.uintAtMost(u16, p.screen_h);
+ const col = random.uintAtMost(u16, p.view().screen_w);
+ const row = random.uintAtMost(u16, p.view().screen_h);
if (random.boolean()) p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = col, .row = row } }) else {
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } });
@@ -1278,13 +1284,13 @@ test "a wide glyph cut by a tag's or a notice's edge is joined into the grid as
_ = try p.setTestFile("wide\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
// Both alignments, so one of them puts a wide glyph across each edge.
for ([_][]const u8{ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))), "x" ++ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))) }) |wide| {
if (pane.tag.own) |own| std.testing.allocator.free(own);
pane.tag.own = try std.testing.allocator.dupe(u8, wide);
var message: [200]u8 = undefined;
- try std.testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&message, "Msg {s}", .{wide})));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&message, "Msg {s}", .{wide})));
p.sync();
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
@@ -1332,7 +1338,7 @@ test "a body with context rows is painted once, and the grid's rows are what a p
@memset(cells, .{});
var plain: Surface = .{ .cols = s.cols, .rows = s.rows, .cells = cells };
pane.view.layered = false;
- try body_layer.renderBody(p, &plain, arena.allocator(), pane, p.rects[0], 0, true, null);
+ try body_layer.renderBody(p, &plain, arena.allocator(), pane, p.view().rects[0], 0, true, null);
pane.view.layered = true;
for (0..body.rect.h) |row| {
const y = body.rect.y + row;
diff --git a/src/dump.zig b/src/dump.zig
index 3c31c805..38fdbb7d 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -101,10 +101,10 @@ pub var terminal_gpa: ?std.mem.Allocator = null;
/// its panes' files were on disk when it was made (one gone by its load is
/// said deleted: its text is nowhere else now), its theme's name (the
/// setting is a place in this build's ring of themes, another build's
-/// ring is another), and the views not live (views.zig: the core holds
-/// the live one's).
-const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Dumped });
-const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Dumped });
+/// ring is another), and the panes' shares of the views not live
+/// (views.zig: the panes hold the live one's).
+const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares });
+const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares });
const OnDisk = [MAX_PANES]bool;
fn onDisk(pane: *const pardes.panes.Pane) bool {
@@ -187,21 +187,21 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
for (others) |o| gpa.free(o.panes);
gpa.free(others);
}
- const kept: []const views.Dumped = others;
+ const kept: []const views.Shares = others;
try db.runContext(struct {
w: *walk.Put,
p: *Pardes,
mounts: *const []const filesystem.Mount,
on_disk: *const OnDisk,
theme: *const []const u8,
- others: *const []const views.Dumped,
+ others: *const []const views.Shares,
pub fn run(ctx: @This(), cursor: *walk.Mem.Cursor(.read_write)) !void {
const root = try walk.Mem.HashMap(.read_write).init(cursor.*);
try ctx.w.member(root, "core", Pardes, ctx.p);
try ctx.w.member(root, "mounts", []const filesystem.Mount, ctx.mounts);
try ctx.w.member(root, "on_disk", OnDisk, ctx.on_disk);
try ctx.w.member(root, "theme", []const u8, ctx.theme);
- try ctx.w.member(root, "views", []const views.Dumped, ctx.others);
+ try ctx.w.member(root, "shares", []const views.Shares, ctx.others);
}
}{ .w = &w, .p = p, .mounts = &mounts, .on_disk = &on_disk, .theme = &theme, .others = &kept });
return pardes.Db.image(gpa, name, buf.written(), w.blobs.items, panes);
@@ -240,8 +240,8 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8
for (others) |o| p.gpa.free(o.panes);
p.gpa.free(others);
}
- const kept: []const views.Dumped = others;
- try d.put([]const views.Dumped, &kept);
+ const kept: []const views.Shares = others;
+ try d.put([]const views.Shares, &kept);
return d.finish();
}
@@ -342,12 +342,12 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
// The views not live, last: what it moves into the core is never
// rolled back from under it, nothing after it failing.
const at = l.shared.items.len;
- const others = l.get([]const views.Dumped) catch |err| switch (err) {
+ const others = l.get([]const views.Shares) catch |err| switch (err) {
// A dump made before views were in it.
error.EndOfDump => &.{},
else => return err,
};
- try views.undumped(p, others);
+ views.undumped(p, others);
for (others) |o| gpa.free(o.panes);
gpa.free(others);
l.shared.shrinkRetainingCapacity(at);
@@ -374,6 +374,15 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
}
l.allocs = .{ .image = p.image_gpa, .pdf = p.pdf_gpa, .terminal = terminal_gpa };
try l.into(Pardes, core_at, p);
+ if (try walk.Get.member(core_at, "views") == null) {
+ // From before `Pardes.views`: the live view's share is the core's
+ // own fields, by the same names, and its index `view`.
+ var old: struct { view: u8 = 0 } = .{};
+ try l.into(@TypeOf(old), core_at, &old);
+ p.live = if (old.view < views.max) old.view else 0;
+ if (p.live != 0) std.mem.swap(?Pardes.View, &p.views[0], &p.views[p.live]);
+ try l.into(Pardes.View, core_at, p.view());
+ }
const read = l.made.items.len;
const mounts: []const filesystem.Mount = if (try walk.Get.member(root, "mounts")) |c| try l.get([]const filesystem.Mount, c) else &.{};
defer {
@@ -410,10 +419,21 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
// The views not live, last: what it moves into the core is never
// rolled back from under it, nothing after it failing.
const at = l.made.items.len;
- const others: []const views.Dumped = if (try walk.Get.member(root, "views")) |c| try l.get([]const views.Dumped, c) else &.{};
- try views.undumped(p, others);
- for (others) |o| gpa.free(o.panes);
- gpa.free(others);
+ if (try walk.Get.member(root, "shares")) |c| {
+ const others = try l.get([]const views.Shares, c);
+ views.undumped(p, others);
+ for (others) |o| gpa.free(o.panes);
+ gpa.free(others);
+ } else {
+ // A dump from before `Pardes.views`: the live view's share was
+ // the core's own fields, each other view's in `views`.
+ const others: []const views.OldDumped = if (try walk.Get.member(root, "views")) |c| try l.get([]const views.OldDumped, c) else &.{};
+ defer {
+ for (others) |o| gpa.free(o.panes);
+ gpa.free(others);
+ }
+ try views.undumpedOld(p, others, gpa);
+ }
l.made.shrinkRetainingCapacity(at);
return p;
}
@@ -431,15 +451,16 @@ fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void {
/// The panes a column lists that are not there (another build's dump left
/// them out) taken out of it, and the keyboard on one that is.
fn dropMissing(p: *Pardes) void {
- for (0..p.ncol) |c| {
+ const v = p.view();
+ for (0..p.view().ncol) |c| {
var n: usize = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) {
- p.cols[c].panes[n] = id;
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) {
+ v.cols[c].panes[n] = id;
n += 1;
};
- p.cols[c].n = n;
+ v.cols[c].n = n;
}
- if (p.active >= MAX_PANES or p.panes[p.active] == null) p.active = for (p.panes, 0..) |slot, i| {
+ if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |slot, i| {
if (slot != null) break i;
} else 0;
}
@@ -450,8 +471,8 @@ pub fn restore(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes {
const taped = pardes.tape.enter(p, .{ .restore = .{ .bytes = bytes, .from = from } });
defer pardes.tape.leave(p, taped);
var opts = p.opts;
- opts.cols = p.screen_w;
- opts.rows = p.screen_h;
+ opts.cols = p.view().screen_w;
+ opts.rows = p.view().screen_h;
const replacement = try loadAndRevive(p.gpa, opts, bytes, p, null);
replacement.pointRestoreAt(from);
// The tape follows the replacement from here (it is the session).
@@ -508,7 +529,7 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ
if (notes.items.len > 0) {
const first = notes.items[0 .. std.mem.indexOfScalar(u8, notes.items, '\n') orelse notes.items.len];
var buf: [320]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read");
+ p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read");
}
return p;
}
@@ -529,9 +550,9 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void {
p.lsp_ask.seq = @max(p.lsp_ask.seq, old.lsp_ask.seq);
p.pipe.seq = @max(p.pipe.seq, old.pipe.seq);
// The host's facts, as this host told them.
- p.cell_pixels = old.cell_pixels;
- p.row_metrics = old.row_metrics;
- p.frontend.native_images = old.frontend.native_images;
+ p.view().cell_pixels = old.view().cell_pixels;
+ p.view().row_metrics = old.view().row_metrics;
+ p.view().frontend.native_images = old.view().frontend.native_images;
// Its panes close here, each noted where it was, as at its end.
for (old.panes) |slot| if (slot) |pane| old.noteClosed(pane);
p.recent = old.recent.clone(p.recentGpa());
@@ -659,7 +680,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane {
pane.command_from = 0;
pane.places.from = 0;
pane.collapsed = false;
- pane.prompt_view = p.view;
+ pane.prompt_view = p.live;
if (pane.file) |*f| if (f.content.len == 0 and (f.saved_len orelse 0) > 0) {
// A clean file kept slim: its text is its file's.
if (filesystem.read(p, f.path)) |text| {
@@ -676,8 +697,8 @@ test "a dump keeps the session's settings, and a restore applies them" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true });
defer p.deinit();
- try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap off"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose off"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap off"));
try dumpState(p);
const restored = try initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
defer restored.deinit();
@@ -689,10 +710,10 @@ test "a session with every column it may hold dumps and restores them all" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 });
defer p.deinit();
- while (p.ncol < MAX_COLS) {
+ while (p.view().ncol < MAX_COLS) {
layout.compute(p);
var widest: usize = 0;
- for (0..p.ncol) |c| if (p.col_w[c] > p.col_w[widest]) {
+ for (0..p.view().ncol) |c| if (p.view().col_w[c] > p.view().col_w[widest]) {
widest = c;
};
_ = layout.insertColumn(p, widest, false) orelse return error.NoColumn;
@@ -700,7 +721,7 @@ test "a session with every column it may hold dumps and restores them all" {
try dumpState(p);
const restored = try initFromDump(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 }, p.dump_out.?);
defer restored.deinit();
- try std.testing.expectEqual(@as(usize, MAX_COLS), restored.ncol);
+ try std.testing.expectEqual(@as(usize, MAX_COLS), restored.view().ncol);
}
test "a restored session's column and workspace tags take more than one selection, and its 9P files have a time" {
@@ -711,7 +732,7 @@ test "a restored session's column and workspace tags take more than one selectio
try dumpState(p);
const restored = try initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
defer restored.deinit();
- try std.testing.expect(restored.col_tags[0].reserveSels());
+ try std.testing.expect(restored.view().col_tags[0].reserveSels());
try std.testing.expect(restored.global_tag.reserveSels());
try std.testing.expect(restored.fs.started != 0);
const stat = th.call(restored, .{ .tag = 1, .op = .getattr, .node = @backingInt(pardes.ctlfs.TopFile.index) });
@@ -798,7 +819,7 @@ test "an upgraded session's dump keeps its views and its running terminal as the
defer p.deinit();
while (p.nextEffect()) |_| {}
term.feedOutput(p, p.panes[0].?, "one\r\n\x1b[?1049h$ vim");
- try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose on"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose on"));
_ = p.openView().?;
const bytes = try dumpBytes(p);
defer gpa.free(bytes);
@@ -825,7 +846,7 @@ test "a session's image, read by name as every load reads it, is the same sessio
defer p.deinit();
const pane = try p.setTestFile("one\ntwo\n");
_ = ctlfs.pane.spliceBody(p, pane, 0, 0, "unsaved ").?;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Zerox"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Zerox"));
const bytes = try dumpBytes(p);
defer gpa.free(bytes);
var notes: std.ArrayList(u8) = .empty;
@@ -845,7 +866,7 @@ test "a session's byte dump read by name, field by field as another build reads
defer p.deinit();
const pane = try p.setTestFile("one\ntwo\n");
_ = ctlfs.pane.spliceBody(p, pane, 0, 0, "unsaved ").?;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Zerox"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Zerox"));
const bytes = try byteDump(p);
defer gpa.free(bytes);
const q = try Pardes.create(gpa, p.opts);
diff --git a/src/echo.zig b/src/echo.zig
index 8c196816..3d2ee060 100644
--- a/src/echo.zig
+++ b/src/echo.zig
@@ -445,7 +445,7 @@ pub const Echo = struct {
/// characters predicted and the cursor after them.
pub fn paint(e: *const Echo, p: *const Pardes, s: *Surface, pane: *const Pane, id: usize, tx: u16, tw: u16, body_y: u16, body_h: u16, active: bool) void {
if (e.n == 0 and e.cursor == null) return;
- if (id != e.pane or pane.serial != e.serial or p.view != e.view or pane.body.mode != .tty) return;
+ if (id != e.pane or pane.serial != e.serial or p.live != e.view or pane.body.mode != .tty) return;
if (!e.visible(p)) return;
const state = pane.terminal orelse return;
const sb = state.vt.screens.active.pages.scrollbar();
@@ -538,10 +538,10 @@ fn atPrompt(pane: *const Pane) bool {
/// The terminal view `view`'s keys go to, in tty mode: none when they go
/// elsewhere (a prompt, a header, window mode, another pane).
fn keyboardPane(c: *const Pardes, view: u8) ?usize {
- const live = c.view == view;
- const part = if (live) null else &(c.parked[view] orelse return null).view;
- const id = if (part) |v| v.active else c.active;
- if (if (part) |v| v.window_pick != null or v.header != null else c.window_pick != null or c.header != null) return null;
+ const live = c.live == view;
+ const v = &(c.views[view] orelse return null);
+ const id = v.active;
+ if (v.window_pick != null or v.header != null) return null;
const pane = c.panes[id] orelse return null;
if (!pane.isTerminal() or pane.terminal == null or pane.prompt != .none) return null;
const mode = if (live) pane.body.mode else pane.pv[view].body.mode;
diff --git a/src/edit.zig b/src/edit.zig
index 5adb94e3..c6c59604 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -35,7 +35,7 @@ const Registers = pardes.Registers;
/// registers computed from the editor (`#`, `.`, `%`) cannot be written.
/// `+` and `*` are the system clipboard: the value is sent there too.
pub fn setYank(p: *Pardes, text: []const u8) void {
- var name: u21 = if (p.register != 0) p.register else Registers.default;
+ var name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
switch (name) {
'_', '#', '.', '%' => return,
'*' => name = '+',
@@ -75,7 +75,7 @@ fn selText(p: *Pardes, t: *Text) []const u8 {
pub const Paste = enum { after, before, replace };
pub fn pasteRegister(p: *Pardes, t: *Text, how: Paste, count: usize) void {
- const name: u21 = if (p.register != 0) p.register else Registers.default;
+ const name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
if (name == '+' or name == '*') {
if (!normal.multiOnce(p)) return;
const pane = t.pane() orelse return;
@@ -98,7 +98,7 @@ pub const ClipRequest = struct {
pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void {
const pane = p.panes[id] orelse return;
- p.clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
+ p.view().clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
p.emit(.read_clipboard);
}
@@ -111,27 +111,28 @@ pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) voi
}
pub fn applyPaste(p: *Pardes, whole: []const u8) void {
+ const v = p.view();
// Every shell's paste comes through here, bounded: what is past the
// limit is left out, at a character's start, and said.
const limit = @import("memory.zig").limits.max_paste_bytes;
const bytes = if (whole.len > limit) whole[0..modal.graphemeStart(whole, limit)] else whole;
if (whole.len > limit) {
var said: [96]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
+ p.setMessage(v.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
}
// A prompt answering for a header takes the paste, as it takes keys.
- const asking = if (p.panes[p.active]) |active| active.prompt != .none else false;
+ const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking) if (tagline.focusedHeader(p)) |t| {
- p.clip_pending = null;
+ v.clip_pending = null;
return pasteInto(p, t, bytes);
};
- const req = p.clip_pending;
- p.clip_pending = null;
+ const req = v.clip_pending;
+ v.clip_pending = null;
if (bytes.len == 0) return;
- const id = if (req) |r| r.pane else p.active;
+ const id = if (req) |r| r.pane else v.active;
const pane = p.panes[id] orelse return;
if (req) |r| if (pane.serial != r.serial) return;
- p.active = id;
+ v.active = id;
if (pane.prompt != .none and pane.prompt != .del_side and pane.prompt != .repl_choice) {
// an answer is one line: a newline in it would only be submitting it
const line = p.scratch.allocator().alloc(u8, bytes.len) catch return;
@@ -172,10 +173,11 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void {
}
pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void {
+ const v = p.view();
// helix's `"+y`: the clipboard register, and only it
- const named = p.register;
- p.register = '+';
- defer p.register = named;
+ const named = v.register;
+ v.register = '+';
+ defer v.register = named;
if (comptime pdf_enabled) if (pane.pdf) |pv| {
if (pv.selection_text.len > 0) setYank(p, pv.selection_text);
return;
@@ -350,7 +352,7 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool {
/// the active modal selection as text, if any
pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 {
- if (comptime pdf_enabled) if (p.frontend.native_images) if (pane.pdf) |pv|
+ if (comptime pdf_enabled) if (p.view().frontend.native_images) if (pane.pdf) |pv|
if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text;
if (!pane.body.vsel.active) return null;
return vselText(p, &pane.body);
@@ -1027,7 +1029,7 @@ fn insertEdit(p: *Pardes, t: *Text, key: Key) void {
const f = (t.pane() orelse break :dot).file orelse break :dot;
if (f.output != null or !lsp.speaks(f.path)) break :dot;
const seq = p.lsp_ask.seq;
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
if (p.lsp_ask.seq != seq) return;
}
// helix smart_tab: after text, Tab leaves the syntax node the
@@ -1845,7 +1847,7 @@ pub fn pushUndo(p: *Pardes, t: *Text) void {
if (!p.multi_first) return;
switch (t.what) {
// A B1 chord took its one undo point when it began (mouse.zig).
- .body => if (p.chord_hold) return,
+ .body => if (p.view().chord_hold) return,
.tag, .column, .workspace => return t.remember(p.gpa, if (t.own) |own| .{ .text = own } else null),
// a prompt's answer is typed once and gone; it keeps no history
.input => return,
@@ -1880,7 +1882,7 @@ const PointerTextSelection = struct {
pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) ?PointerTextSelection {
const pane = p.panes[id] orelse return null;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (col < r.x + config.GUTTER or col >= r.x + r.w or row < r.y or row >= r.y + r.h) return null;
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
@@ -2063,11 +2065,11 @@ test "only the SPC clipboard commands cross to the system clipboard" {
const before = pane.file.?.content.len;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'p' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
try std.testing.expect(drainedEffect(p, .read_clipboard));
try std.testing.expectEqual(before, pane.file.?.content.len); // nothing yet
p.update(.{ .paste = "PASTED" });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "PASTED") != null);
// ...and it did NOT land in the register on its way past, nor echo back
// out to the clipboard it came from.
@@ -2084,9 +2086,9 @@ test "only the SPC clipboard commands cross to the system clipboard" {
// than firing late into whatever pane is focused by then.
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'P' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
p.update(.{ .key = .{ .cp = 'l' } });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
}
/// acme's double-click (plan9port acme text.c:1407, textdoubleclick): from
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig
index 99cac6ce..207dd7cc 100644
--- a/src/edit_cmd.zig
+++ b/src/edit_cmd.zig
@@ -96,11 +96,11 @@ const World = struct {
return said(sam.File, why, "B: {s} is a directory", .{path});
// A look opens it, or finds it open, where a look would; the
// keyboard stays where the Edit ran.
- const was = p.active;
+ const was = p.view().active;
p.look_text = true;
look.lookAt(p, w.from, path);
p.look_text = false;
- if (p.panes[was] != null) p.active = was;
+ if (p.panes[was] != null) p.view().active = was;
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
const f = ninep_pane.fileOf(pane) orelse continue;
@@ -310,7 +310,7 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
const pd = p.pipe.edit_run orelse return;
p.pipe.edit_run = null;
defer pd.deinit(p.gpa);
- const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.active) else p.active;
+ const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.view().active) else p.view().active;
// Whatever fails from here fails the 9P write that ran it too.
const failures = p.fs.failures;
defer answerHold(p, at, p.fs.failures != failures);
@@ -329,9 +329,9 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
Pipe.writeFailure(w, failure) catch break :report;
const why = std.mem.sliceTo(out.written()[why_at..], '\n');
const said = std.fmt.bufPrint(&line, "Edit: {c} {s}: {s}", .{ job.c, job.command[0..@min(job.command.len, 120)], why }) catch "Edit: a command failed";
- const was = p.active;
+ const was = p.view().active;
_ = ninep_pane.appendErrors(p, at, out.written());
- if (p.panes[was] != null) p.active = was;
+ if (p.panes[was] != null) p.view().active = was;
return p.reportFailure(at, said);
}
p.reportFailure(at, "Edit: a command failed");
@@ -341,7 +341,7 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
/// of it, if a pane it changes is not the one it read any more.
fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
const res = pd.res;
- const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.active) else p.active;
+ const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.view().active) else p.view().active;
var text: [320]u8 = undefined;
for (res.files, 0..) |f, i| {
if (f.ops.items.len == 0 and !f.close and !f.renamed and !f.moved and f.get == null) continue;
@@ -429,9 +429,9 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
out.appendSlice(p.gpa, res.printed[from..]) catch return;
// Printed, the keyboard stays where it was: a +Errors made for it
// does not take it, so the next Edit lands where this one did.
- const was = p.active;
+ const was = p.view().active;
if (out.items.len > 0) _ = ninep_pane.appendErrors(p, at, out.items);
- if (p.panes[was] != null) p.active = was;
+ if (p.panes[was] != null) p.view().active = was;
}
if (refused.written().len > 0) {
var said: [320]u8 = undefined;
@@ -572,7 +572,7 @@ test "Edit's < | and > with a real shell: a command per address, > printed to +E
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl, "Edit , > wc -l\n").reply.status);
try runReal(p);
// The +Errors it opened did not take the keyboard.
- try testing.expectEqual(@as(usize, 0), p.active);
+ try testing.expectEqual(@as(usize, 0), p.view().active);
try testing.expectEqualStrings("ONE TWO\nnew", p.panes[0].?.file.?.content);
try testing.expectEqualStrings("1", std.mem.trim(u8, errorsText(p).?, " \n"));
}
@@ -621,9 +621,9 @@ test "X over open files, w, e, r, f, B and D on panes and the disk" {
defer p.deinit();
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/a.c", .{dir}));
- const a = p.active;
+ const a = p.view().active;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/b.h", .{dir}));
- p.active = 0;
+ p.view().active = 0;
const ctl = tree.Node.of(th.serialOf(p), .ctl);
// X: every open file whose line matches, each from its own dot.
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl, "Edit X/\\.[ch]$/ ,s/foo/FOO/g\n").reply.status);
@@ -637,7 +637,7 @@ test "X over open files, w, e, r, f, B and D on panes and the disk" {
// B opens a file, which a `"re"` address then edits, from pane 0.
var cmd: [4400]u8 = undefined;
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl, try std.fmt.bufPrint(&cmd, "Edit B {s}/c.c\n", .{dir})).reply.status);
- try testing.expectEqual(@as(usize, 0), p.active);
+ try testing.expectEqual(@as(usize, 0), p.view().active);
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl, "Edit \"c\\.c$\" 1 s/bar/BAR/\n").reply.status);
const c = for (p.panes, 0..) |slot, i| {
if (slot) |q| if (q.file) |f| if (std.mem.endsWith(u8, f.path, "/c.c")) break i;
@@ -694,10 +694,10 @@ test "an Edit's w to a file changed on disk is refused once, as Save is, and the
defer p.deinit();
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/a.txt", .{dir}));
- const a = p.active;
+ const a = p.view().active;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/b.txt", .{dir}));
- const b = p.active;
- p.active = 0;
+ const b = p.view().active;
+ p.view().active = 0;
for ([_]usize{ a, b }) |i| try testing.expectEqual(tree.Status.ok, th.wr(p, tree.Node.of(p.panes[i].?.serial, .ctl), "Edit $a/more/\n").reply.status);
// a.txt changed on disk since it was read (the watch says so).
p.panes[a].?.file.?.disk_newer = 1;
@@ -729,8 +729,8 @@ test "an Edit with no command runs beside one whose commands run, unless it touc
defer p.deinit();
var path: [4200]u8 = undefined;
look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/other.txt", .{dir}));
- const other = p.active;
- p.active = 0;
+ const other = p.view().active;
+ p.view().active = 0;
const ctl = tree.Node.of(th.serialOf(p), .ctl);
const other_ctl = tree.Node.of(p.panes[other].?.serial, .ctl);
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl, "Edit , | sort\n").reply.status);
diff --git a/src/exec.zig b/src/exec.zig
index 327d4683..c927cb49 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -44,6 +44,7 @@ pub fn takesCommandLine(p: *const Pardes, id: usize) bool {
}
pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool {
+ const v = p.view();
if (pane.body.nsel == 0) return false;
const text = edit.flatSurface(p, &pane.body) catch return false;
var ranges: [panes.Text.max_selections]modal.Selection = undefined;
@@ -63,7 +64,7 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool {
// All or nothing, like the pipe: half a chord is not a chord.
if (made != got.n) return false;
- const id = p.active;
+ const id = v.active;
const serial = pane.serial;
pane.body.vsel.active = false;
pane.body.select = false;
@@ -73,12 +74,12 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool {
for (texts[0..made], 0..) |txt, i| {
// Every selection is the body's, each one sent as the first is.
runBuiltinFrom(p, cmd, id, "", txt, true);
- if (i == got.pri) primary_active = p.active;
+ if (i == got.pri) primary_active = v.active;
const still = p.panes[id] orelse break;
if (still.serial != serial) break;
}
if (primary_active) |a| if (p.panes[a] != null) {
- p.active = a;
+ v.active = a;
};
return true;
}
@@ -259,17 +260,17 @@ fn fileWordCells(pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pa
fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane {
const i = switch (k) {
0 => first,
- 1 => p.active,
+ 1 => p.view().active,
else => k - 2,
};
- if (k > 0 and (i == first or (k > 1 and i == p.active))) return null;
+ if (k > 0 and (i == first or (k > 1 and i == p.view().active))) return null;
return p.panes[i];
}
pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 {
for (0..p.panes.len + 2) |k| {
const t = heldPane(p, first, k) orelse continue;
- if (comptime pdf_enabled) if (p.frontend.native_images) if (t.pdf) |pv| {
+ if (comptime pdf_enabled) if (p.view().frontend.native_images) if (t.pdf) |pv| {
if (pv.selection != null and pv.selection_text.len > 0)
return pv.selection_text;
};
@@ -535,7 +536,7 @@ fn routeToRepl(p: *Pardes, from: usize, text: []const u8) Routed {
w.writeAll(" (Esc: none)") catch {};
src.question_len = @intCast(w.buffered().len);
src.prompt = .repl_choice;
- p.active = from;
+ p.view().active = from;
var rec: [96]u8 = undefined;
var rw = std.Io.Writer.fixed(&rec);
rw.print("{d} repl", .{src.serial}) catch {};
@@ -960,7 +961,7 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void {
// the other has (Font, GripWidth in a terminal) is no failure here.
if (setting) |s| if (!s.enabled(builtins.viewCapabilities(p))) continue;
const failures = p.fs.failures;
- const known = executeBuiltinLine(p, p.active, line);
+ const known = executeBuiltinLine(p, p.view().active, line);
if (known and p.fs.failures == failures) continue;
// Never silent: a word it has not, or one that failed, is a notice
// on the message row and an err in the log, with its line.
@@ -970,7 +971,7 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void {
else if (p.fs.said_len > 0) p.fs.said[0..p.fs.said_len] else "failed";
var said: [400]u8 = undefined;
const line_said = std.fmt.bufPrint(&said, "init file line {d}: {s}", .{ number, why }) catch "init file: a line failed";
- if (!known) p.reportFailure(p.active, line_said);
+ if (!known) p.reportFailure(p.view().active, line_said);
pardes.ctlfs.events.notePath(p, "err -", line_said);
}
}
@@ -1012,6 +1013,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
}
pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]const u8) void {
+ const v = p.view();
const previous_tagline_percent = p.settings.font.tagline_percent;
switch (setting.action) {
.theme => {
@@ -1025,7 +1027,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
const room = 128 -| ("Theme: no theme \"\"; like it: ; Themes lists all".len + shown.len);
var near: [128]u8 = undefined;
var text: [256]u8 = undefined;
- return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch "Theme: no such theme");
+ return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch "Theme: no such theme");
},
.font => {
if (comptime !font_picker) return;
@@ -1044,22 +1046,22 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
p.settings.shell.pending = true;
if (!p.announce) return;
var said: [320]u8 = undefined;
- return p.setMessage(p.active, std.fmt.bufPrint(&said, "Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()}) catch "Shell: the default again");
+ return p.setMessage(v.active, std.fmt.bufPrint(&said, "Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()}) catch "Shell: the default again");
}
var why: [320]u8 = undefined;
if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| {
var text: [340]u8 = undefined;
- return p.reportFailure(p.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch "Shell: no such shell");
+ return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch "Shell: no such shell");
}
- if (!p.settings.apply(setting, want)) p.reportFailure(p.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
+ if (!p.settings.apply(setting, want)) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
},
// Bare, each says its value, as acme's Tab says the width.
inline .tab, .callstack_depth => |_, tag| if (arg == null) {
var said: [40]u8 = undefined;
- return p.setMessage(p.active, std.fmt.bufPrint(&said, "{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }) catch setting.word);
+ return p.setMessage(v.active, std.fmt.bufPrint(&said, "{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }) catch setting.word);
} else if (!p.settings.apply(setting, arg)) {
var said: [96]u8 = undefined;
- p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }) catch setting.word);
+ p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }) catch setting.word);
} else if (tag == .tab) {
config.tab_now = p.settings.tab;
},
@@ -1067,7 +1069,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
else => if (!p.settings.apply(setting, arg)) {
var text: [160]u8 = undefined;
const why = if (config.Runtime.takes(setting.action)) |values| std.fmt.bufPrint(&text, "{s}: takes {s}", .{ setting.word, values }) else std.fmt.bufPrint(&text, "{s}: does not take that value", .{setting.word});
- p.reportFailure(p.active, why catch "does not take that value");
+ p.reportFailure(v.active, why catch "does not take that value");
},
}
if (setting.action == .tab) {
@@ -1092,12 +1094,13 @@ pub const NewPane = enum { scratch, fs, shell, doc, command, errors };
/// from: null when a column tag, the workspace tag or 9P asked (acme's
/// t->w == nil).
pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPane) void {
+ const v = p.view();
// No column left (the last one Delcol'd): a pane made from the workspace
// tag opens one to go in.
_ = layout.firstColumn(p);
const asked = if (p.exec_column != null) null else origin;
layout.compute(p);
- const before = p.rects;
+ const before = v.rects;
const before_min = layout.minima(p);
switch (kind) {
// New: the bottom half of the last pane in its own column
@@ -1105,8 +1108,8 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
.scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id),
// +Errors, a command's output: the last column (util.c:94-98); a
// command run from a column's tag, that column.
- .command => layout.acmePlace(p, p.exec_column orelse p.ncol - 1, null, id),
- .errors => layout.acmePlace(p, p.ncol - 1, null, id),
+ .command => layout.acmePlace(p, p.exec_column orelse v.ncol - 1, null, id),
+ .errors => layout.acmePlace(p, v.ncol - 1, null, id),
// makenewwindow(nil) for 9P's new (acme.c:877), else (t).
.fs => layout.acmePlace(p, acmeColumn(p, from), null, id),
.shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id),
@@ -1117,12 +1120,12 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
// (Pardes.unplaced) once whatever made it is done with it.
if (!layout.placedRoomy(p, id, &before)) if (layout.findPane(p, id)) |f| {
layout.removePane(p, id);
- for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.rects[k] = before[k];
+ for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k];
layout.snapColWeights(p, f.col);
if (!layout.splitTallest(p, f.col, id) or !layout.placedRoomy(p, id, &before)) {
if (layout.findPane(p, id) != null) {
layout.removePane(p, id);
- for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.rects[k] = before[k];
+ for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k];
layout.snapColWeights(p, f.col);
}
// No pane to halve, but the column has the rows for the new
@@ -1136,20 +1139,20 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
// the text some other way (appendErrors), and pane/new is
// refused.
if (layout.takeRoom(p, f.col, id)) {} else if (kind == .errors or kind == .fs) {
- var c = p.ncol;
+ var c = v.ncol;
while (c > 0) {
c -= 1;
if (c == f.col) continue;
- for (p.cols[c].panes[0..p.cols[c].n]) |k| p.rects[k] = before[k];
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |k| v.rects[k] = before[k];
layout.snapColWeights(p, c);
- if (p.cols[c].n == 0) {
+ if (v.cols[c].n == 0) {
layout.insert(p, c, 0, id);
break;
}
if (layout.splitTallest(p, c, id) and layout.placedRoomy(p, id, &before)) break;
if (layout.findPane(p, id) != null) layout.removePane(p, id);
} else {
- layout.insert(p, f.col, p.cols[f.col].n, id);
+ layout.insert(p, f.col, v.cols[f.col].n, id);
p.unplaced.set(id);
// Refused holding no weight: its column's rows come
// back as they were.
@@ -1159,7 +1162,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
return;
}
} else {
- layout.insert(p, f.col, p.cols[f.col].n, id);
+ layout.insert(p, f.col, v.cols[f.col].n, id);
// Refused, it closes at the step's end holding no weight, so
// its column's rows come back as they were, none rounded off.
p.panes[id].?.vweight = 0;
@@ -1179,7 +1182,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
layout.restoreMinimaFrom(p, &settled, &before_min);
if (kind == .command) return;
tagline.exitHeader(p);
- p.active = id;
+ v.active = id;
if (layout.findPane(p, id)) |f| p.setActiveColumn(f.col);
}
@@ -1189,12 +1192,12 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan
fn acmeColumn(p: *Pardes, from: usize) usize {
if (p.exec_column) |c| return c;
if (layout.activeColumn(p)) |c| return c;
- if (layout.findPane(p, p.active)) |f| return f.col;
+ if (layout.findPane(p, p.view().active)) |f| return f.col;
return columnOf(p, from);
}
fn columnOf(p: *Pardes, id: usize) usize {
- return if (layout.findPane(p, id)) |f| f.col else p.ncol - 1;
+ return if (layout.findPane(p, id)) |f| f.col else p.view().ncol - 1;
}
test "the acme chords act once per selection, not once on the primary" {
@@ -1212,11 +1215,11 @@ test "the acme chords act once per selection, not once on the primary" {
pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true);
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
- const before = p.ncol;
+ const before = p.view().ncol;
p.update(.{ .key = .{ .cp = Key.tab } }); // config.exec_key: Exec
// BOTH ran. Before this the chord read the primary range and dropped the
// other cursor, so one keystroke over two cursors made one column.
- try std.testing.expectEqual(before + 2, p.ncol);
+ try std.testing.expectEqual(before + 2, p.view().ncol);
// ...and the chord consumed the selection exactly as it does with one.
try std.testing.expectEqual(@as(u16, 0), p.panes[0].?.body.nsel);
}
@@ -1226,11 +1229,11 @@ test "a switch clicked with a selection held flips unless the selection says on
defer p.deinit();
while (p.nextEffect()) |_| {}
const before = p.settings.verbose;
- _ = execute(p, p.active, withArg(p, "Verbose", "some selected text"));
+ _ = execute(p, p.view().active, withArg(p, "Verbose", "some selected text"));
try std.testing.expectEqual(!before, p.settings.verbose);
- _ = execute(p, p.active, withArg(p, "Verbose", "on"));
+ _ = execute(p, p.view().active, withArg(p, "Verbose", "on"));
try std.testing.expect(p.settings.verbose);
- _ = execute(p, p.active, withArg(p, "Verbose", " off\n"));
+ _ = execute(p, p.view().active, withArg(p, "Verbose", " off\n"));
try std.testing.expect(!p.settings.verbose);
// A word that takes any argument still gets the selection.
try std.testing.expectEqualStrings("Msg some text", withArg(p, "Msg", "some text"));
diff --git a/src/fs.zig b/src/fs.zig
index d79b8cb3..835b191a 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -663,7 +663,7 @@ test "virtual body writes can read their input from the same pane" {
try std.testing.expectEqualStrings("same pane contents\n", pane.file.?.content);
// The truncation and the write are one undo step.
try std.testing.expectEqual(@as(usize, 1), pane.file.?.history.journal.done);
- const events = &p.panes[p.active].?.fs.events;
+ const events = &p.panes[p.view().active].?.fs.events;
try std.testing.expect(std.mem.startsWith(u8, events.peek().?, "ED"));
events.pop();
try std.testing.expect(std.mem.startsWith(u8, events.peek().?, "EI"));
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index eb8636be..85245b54 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -473,20 +473,20 @@ test "the shader instance ABI: the flags after the colours, the clip after them"
}
fn updateCoreResize(core: *pardes.Pardes, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) bool {
- core.update(resizeOf(core, cols, rows, cell_w, cell_h, tag_w, tag_h) orelse return false);
+ core.update(resizeOf(core.view(), cols, rows, cell_w, cell_h, tag_w, tag_h) orelse return false);
return true;
}
/// The resize a window of `cols` by `rows` cells of these sizes is to the
/// live view, or null when it is that already.
-fn resizeOf(core: anytype, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) ?pardes.Event {
+fn resizeOf(v: *const pardes.Pardes.View, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) ?pardes.Event {
const metrics: pardes.RowMetrics = .{ .body_w = @intCast(cell_w), .body_h = @intCast(cell_h), .tagline_w = @intCast(tag_w), .tagline_h = @intCast(tag_h) };
- const same_metrics = std.meta.eql(metrics, core.row_metrics);
+ const same_metrics = std.meta.eql(metrics, v.row_metrics);
if (comptime pardes.pdf_enabled) {
const cell_px_w: u16 = @intCast(@min(@max(1, cell_w), std.math.maxInt(u16)));
const cell_px_h: u16 = @intCast(@min(@max(1, cell_h), std.math.maxInt(u16)));
- if (cols == core.screen_w and rows == core.screen_h and
- cell_px_w == core.cell_pixels.w and cell_px_h == core.cell_pixels.h and same_metrics) return null;
+ if (cols == v.screen_w and rows == v.screen_h and
+ cell_px_w == v.cell_pixels.w and cell_px_h == v.cell_pixels.h and same_metrics) return null;
return .{ .resize = .{
.cols = cols,
.rows = rows,
@@ -494,7 +494,7 @@ fn resizeOf(core: anytype, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w
.row_metrics = metrics,
} };
}
- if (cols == core.screen_w and rows == core.screen_h and same_metrics) return null;
+ if (cols == v.screen_w and rows == v.screen_h and same_metrics) return null;
return .{ .resize = .{ .cols = cols, .rows = rows, .row_metrics = metrics } };
}
@@ -824,7 +824,7 @@ test "GUI completion failure survives backlog and leaves the document unchanged"
defer core.deinit();
const pane = try core.setTestFile("abc");
pane.body.cur_col = 1;
- core.lspRequest(core.active, .completion, "");
+ core.lspRequest(core.view().active, .completion, "");
const id = core.lsp_ask.wait.?.id;
var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = id };
defer queue.deinit();
@@ -898,11 +898,11 @@ test "GUI worker setup failures finish matching LSP and pipe requests" {
};
defer queue.deinit();
var tasks: PipeTasks = .{};
- core.lspRequest(core.active, .status, "");
+ core.lspRequest(core.view().active, .status, "");
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 0,
.arg = "",
};
@@ -1766,9 +1766,9 @@ fn localSession(
defer core.deinit();
g.hit_core = core;
defer g.hit_core = null;
- core.frontend.windowed = true;
- core.frontend.native_images = true;
- core.frontend.native_image_patches = true;
+ core.view().frontend.windowed = true;
+ core.view().frontend.native_images = true;
+ core.view().frontend.native_image_patches = true;
observeGuiFont(g, core);
syncTaglineFont(g, core);
@@ -1904,11 +1904,11 @@ fn localSession(
shell.stopPtys();
clearNativeImages(g);
g.prepared_images.clearRetainingCapacity();
- nc.frontend.native_images = true;
- nc.frontend.native_image_patches = true;
+ nc.view().frontend.native_images = true;
+ nc.view().frontend.native_image_patches = true;
nc.host = host;
if (fs) |f| f.reset(nc);
- nc.frontend.windowed = true;
+ nc.view().frontend.windowed = true;
core.deinit();
core = nc;
frame_probe = &nc.frames; // the old core's ring went with it
@@ -2055,7 +2055,7 @@ const OwnView = struct {
const g = v.g;
if (fitTaglineFont(g, core.settings.font.tagline_percent)) v.s.remote.?.link.dirty = true;
const geom = windowCells(g);
- if (resizeOf(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| v.in.post(ev);
+ if (resizeOf(core.view(), geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| v.in.post(ev);
if (v.pointer) refreshPresentedPointer(g, v.in);
runDemo(g, v.in, core);
if (v.s.test_mode) {
@@ -2565,7 +2565,7 @@ const Input = struct {
if (in.remote) |r| return r.post(ev);
// The window's input is its own view's, a replica client's input
// the session's last or not.
- if (in.shell) |s| if (s.core.view != s.gview) {
+ if (in.shell) |s| if (s.core.live != s.gview) {
_ = s.windowView();
};
in.core.update(ev);
@@ -2578,7 +2578,7 @@ const Input = struct {
return;
}
if (in.shell) |s| {
- if (s.windowsOpen() > 1) return s.closeView(s.core.view);
+ if (s.windowsOpen() > 1) return s.closeView(s.core.live);
// The last window, with replica clients: they keep the session,
// as a Detach would, the daemon holding it.
if (s.peers.count() > 0 and daemon.kept()) return s.closeTheWindow();
@@ -2883,7 +2883,7 @@ fn gridCellAtDimensions(
// On the rule over this row, which is where two panes meet if they do.
point.rule_above = row > 0 and @max(y, 0) - @as(f32, @floatFromInt(row)) * @max(body_h, 1) < dp(rule_grab_px);
if (onGrid(core, x / @max(body_w, 1), y / @max(body_h, 1))) for (core.surface.tagLayers()) |*layer| {
- if (layer.tagHit(x, y, body_w, body_h, tagline_w, @floatFromInt(core.row_metrics.tagline_h))) |hit| {
+ if (layer.tagHit(x, y, body_w, body_h, tagline_w, @floatFromInt(core.view().row_metrics.tagline_h))) |hit| {
point.tag_hit = hit;
break;
}
@@ -2894,7 +2894,7 @@ fn gridCellAtDimensions(
/// Whether a point, in cells, is on the grid.
fn onGrid(core: *const pardes.Pardes, x: f32, y: f32) bool {
return std.math.isFinite(x) and std.math.isFinite(y) and x >= 0 and y >= 0 and
- x < @as(f32, @floatFromInt(core.screen_w)) and y < @as(f32, @floatFromInt(core.screen_h));
+ x < @as(f32, @floatFromInt(core.view().screen_w)) and y < @as(f32, @floatFromInt(core.view().screen_h));
}
fn gridCellAtPixels(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell {
@@ -2913,12 +2913,12 @@ test "tagline pointer mapping retains physical grips and carries logical text co
defer core.deinit();
core.update(.{ .resize = .{ .cols = 60, .rows = 12 } });
core.update(.{ .command = "Newcol" });
- core.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 12 };
+ core.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 12 };
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
_ = try core.render(arena.allocator());
- const r = core.rects[core.active];
+ const r = core.view().rects[core.view().active];
const body_w: f32 = 10;
const body_h: f32 = 20;
const tag_w: f32 = 8;
@@ -2934,7 +2934,7 @@ test "tagline pointer mapping retains physical grips and carries logical text co
try std.testing.expect(grip.tag_hit == null);
try std.testing.expectEqual(r.x + config.GUTTER - 1, grip.col);
- const body_y = tag_y + core.panes[core.active].?.tag_rows; // a long tag wraps
+ const body_y = tag_y + core.panes[core.view().active].?.tag_rows; // a long tag wraps
const body = gridCellAtDimensions(core, x, (@as(f32, @floatFromInt(body_y)) + 0.5) * body_h, body_w, body_h, tag_w);
try std.testing.expectEqual(pixelCell(x, 10), body.col);
try std.testing.expectEqual(body_y, body.row);
@@ -2968,7 +2968,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
const core = in.core;
const hit: ?usize = for (core.panes, 0..) |slot, i| {
if (slot == null) continue;
- const r = core.rects[i];
+ const r = core.view().rects[i];
if (mc.col >= r.x and mc.col < r.x + r.w and mc.row >= r.y and mc.row < r.y + r.h) break i;
} else null;
if (g.scroll_pane) |old| if (hit == null or hit.? != old) {
@@ -2976,7 +2976,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
};
if (hit) |id| {
const pdf_target = if (comptime pardes.pdf_enabled)
- core.frontend.native_images and core.panes[id].?.pdfPage() != null
+ core.view().frontend.native_images and core.panes[id].?.pdfPage() != null
else
false;
const pane = core.panes[id].?;
@@ -3259,11 +3259,11 @@ const Shell = struct {
fn detachWindow(ctx: ?*anyopaque) void {
const s = shellOf(ctx);
// A replica client's: its link ends.
- if (s.peers.detach(s.core.view)) return;
- if (s.gui == null) return s.core.reportFailure(s.core.active, "Detach: no window is open");
+ if (s.peers.detach(s.core.live)) return;
+ if (s.gui == null) return s.core.reportFailure(s.core.view().active, "Detach: no window is open");
// One of several: its window goes, and the session stays in the rest.
- if (s.windowsOpen() > 1) return s.closeView(s.core.view);
- if (!daemon.kept()) return s.core.reportFailure(s.core.active, "Detach: no pardes daemon keeps this session; closing its window ends it");
+ if (s.windowsOpen() > 1) return s.closeView(s.core.live);
+ if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon keeps this session; closing its window ends it");
s.closeTheWindow();
}
@@ -3276,7 +3276,7 @@ const Shell = struct {
/// The Gui holds the window of the core's live view.
fn follow(s: *Shell) void {
const g = s.gui orelse return;
- const k = s.core.view;
+ const k = s.core.live;
if (s.gview == k) return;
// A replica client's view has no window here: the Gui keeps the one
// it holds (`windowView` puts that view back when it acts).
@@ -3338,7 +3338,7 @@ const Shell = struct {
/// (its size, its scroll): a replica client's input may have been the
/// last. True when it was not, and is now.
fn windowView(s: *Shell) bool {
- if (s.core.view == s.gview or !pardes.views.isOpen(s.core, s.gview)) return false;
+ if (s.core.live == s.gview or !pardes.views.isOpen(s.core, s.gview)) return false;
s.core.toView(s.gview);
return true;
}
@@ -3355,7 +3355,7 @@ const Shell = struct {
s.core.closeView(k);
// Into another window's view, if a client's was the one left live.
for (0..pardes.views.max) |i| if (s.windowed & (@as(u8, 1) << @intCast(i)) != 0 and pardes.views.isOpen(s.core, @intCast(i))) {
- if (s.core.view != i) s.core.toView(@intCast(i));
+ if (s.core.live != i) s.core.toView(@intCast(i));
break;
};
s.follow();
@@ -3507,7 +3507,7 @@ const Shell = struct {
/// live view's, the others open as `--attach` opens one; a replica
/// client's, kept for its rejoin (views.away), none.
fn resumeWindows(s: *Shell) void {
- const live = s.core.view;
+ const live = s.core.live;
s.gview = live;
for (0..pardes.views.max) |i| {
const k: u8 = @intCast(i);
@@ -3608,7 +3608,7 @@ const Shell = struct {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- s.core.setStatus(s.core.active, message.stamp(&mbuf, "lsp", text));
+ s.core.setStatus(s.core.view().active, message.stamp(&mbuf, "lsp", text));
s.lsp_allocator.free(text);
},
.pipe => |response_value| {
@@ -3855,12 +3855,11 @@ fn pollFrame(ctx: ?*anyopaque) void {
};
// A replica client's view live: the window's own view back before what
// the window does to it (its size, its scroll, its font).
- if (core.view != s.gview) {
+ if (core.live != s.gview) {
const geom = windowCells(g);
- const own = if (core.parked[s.gview]) |slot| &slot.view else null;
const due = g.scroll_pane != null or g.scroll_notch != 0 or g.glide.moving() or
core.settings.font.tagline_percent != g.tagline_percent or core.settings.font.pending or
- (own != null and resizeOf(own.?, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height) != null);
+ (if (core.views[s.gview]) |*own| resizeOf(own, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height) != null else false);
if (due) _ = s.windowView();
}
syncWindowOpacity(g, core);
@@ -3939,6 +3938,7 @@ fn demoDue(g: *const Gui) ?c_int {
/// focused pane's body; its clock starts at the first loop. Its end
/// ends the session (PARDES_FRAMES has the timings then).
fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void {
+ const v = core.view();
const steps = g.demo;
var next = g.demo_next orelse return;
const now = monoNs();
@@ -3949,7 +3949,7 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void {
}
defer g.demo_next = next;
while (next < steps.len and g.demo_start_ns + @as(u64, steps[next].at_ms) * std.time.ns_per_ms <= now) : (next += 1) {
- const r = core.rects[core.active];
+ const r = v.rects[v.active];
if (steps[next].act != .phase) g.input_seen = true;
switch (steps[next].act) {
.wheel => |notches| {
@@ -3967,7 +3967,7 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void {
.phase => {},
.click => |click| {
core.frames.input(now);
- const pane = core.panes[core.active] orelse continue;
+ const pane = core.panes[v.active] orelse continue;
const top = core.bodyTop(pane, r);
const row: u16 = top + @as(u16, @intFromFloat(click.at * @as(f32, @floatFromInt(r.h -| pane.tag_rows -| 1))));
const col: u16 = if (click.rail) r.x else r.x + config.GUTTER + 4;
@@ -3987,10 +3987,10 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void {
for (core.panes) |slot| if (slot) |pane| {
newest = @max(newest, pane.serial);
};
- _ = pardes.exec.executeFrom(core, core.active, line, false);
+ _ = pardes.exec.executeFrom(core, v.active, line, false);
// What it opened is what the next steps scroll.
for (core.panes, 0..) |slot, id| if (slot) |pane| if (pane.serial > newest) {
- core.active = id;
+ v.active = id;
core.needs_frame = true;
};
},
@@ -4135,7 +4135,7 @@ fn postPresent(ctx: ?*anyopaque) void {
if (!s.presented) return;
// A client's view live: the window's frame counts when its own view is
// live and drawn.
- if (s.core.view != s.gview) return;
+ if (s.core.live != s.gview) return;
var in: Input = .{ .core = s.core };
refreshPresentedPointer(g, &in);
s.core.presented();
@@ -4156,7 +4156,7 @@ fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
- const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.screen_h, s.core.screen_w) catch |err| {
+ const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
if (running) return s.core.restartFailed(pane, err);
return s.core.shellFailed(pane, err);
};
@@ -4363,7 +4363,7 @@ fn pipe(ctx: ?*anyopaque, id: u32) void {
const s = shellOf(ctx);
if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, s.pipe_tasks, id, s.queue, Queue.pushPipe);
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- s.core.reportError(s.core.active, "pipe", error.WorkersUnavailable);
+ s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable);
}
fn kindJob(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
@@ -4545,7 +4545,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift
}.f;
_ = try take(core, &sent);
const pane = core.panes[0].?;
- const r = core.rects[0];
+ const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
const next: MouseCell = .{ .col = mc.col + 1, .row = mc.row };
core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
@@ -4594,7 +4594,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
};
_ = try Sent.take(core, &sent);
const pane = core.panes[0].?;
- const r = core.rects[0];
+ const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
// What codex 0.159's chat sets on start.
core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
@@ -4650,7 +4650,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
resetScroll(g);
break :wheel;
};
- const r = core.rects[id];
+ const r = core.view().rects[id];
if (r.h <= pane.tag_rows or r.w <= config.GUTTER) {
resetScroll(g);
break :wheel;
@@ -4706,11 +4706,11 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
var s = try core.render(arena.allocator());
var g = testGui(10, 20, 6, 12);
defer g.glide.deinit(gpa);
- const r = core.rects[core.active];
- g.scroll_pane = core.active;
+ const r = core.view().rects[core.view().active];
+ g.scroll_pane = core.view().active;
g.scroll_col = r.x + 10;
g.scroll_row = r.y + r.h - 2;
- const body_y = core.bodyTop(core.panes[core.active].?, r);
+ const body_y = core.bodyTop(core.panes[core.view().active].?, r);
const row_before = try gpa.dupe(pardes.Cell, s.cells[@as(usize, body_y + 1) * s.cols + r.x + config.GUTTER ..][0 .. r.w - config.GUTTER]);
defer gpa.free(row_before);
// The window has drawn the view once (Glide.frame finds a view that moved).
@@ -4718,9 +4718,9 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
glideFrame(&g, gpa, s);
// One notch down: the core is a line on at once.
g.scroll_notch = 1;
- const scrolled = core.panes[core.active].?.scroll();
+ const scrolled = core.panes[core.view().active].?.scroll();
stepGlide(&g, core, gpa);
- try std.testing.expectEqual(scrolled + 1, core.panes[core.active].?.scroll());
+ try std.testing.expectEqual(scrolled + 1, core.panes[core.view().active].?.scroll());
_ = arena.reset(.retain_capacity);
s = try core.render(arena.allocator());
glideFrame(&g, gpa, s);
@@ -4768,8 +4768,8 @@ test "a wheel's caret rides with its line, the text's own glide, never a spring
var s = try core.render(arena.allocator());
var g = testGui(10, 20, 6, 12);
defer g.glide.deinit(gpa);
- const r = core.rects[core.active];
- g.scroll_pane = core.active;
+ const r = core.view().rects[core.view().active];
+ g.scroll_pane = core.view().active;
g.scroll_col = r.x + 10;
g.scroll_row = r.y + r.h - 2;
stepGlide(&g, core, gpa);
@@ -4828,7 +4828,7 @@ const GlideRun = struct {
glideFrame(g, gpa, s);
seeCaret(g, s, fixedCellLayout(g), @floatFromInt(@as(u32, s.rows) * g.cell_h), now);
seq.offsets[frame] = g.glide.follow.offset;
- seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll);
+ seq.lines[frame] = @intCast(core.panes[core.view().active].?.file.?.scroll);
seq.carets[frame] = caretRow(g, s, now) orelse -1;
seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1;
}
@@ -4873,7 +4873,7 @@ test "every scroll glides on one law: a half page, a page, the far jumps, a run
_ = try core.render(arena.allocator());
var g = testGui(10, 20, 6, 12);
defer g.glide.deinit(gpa);
- const body_h: f32 = @floatFromInt(core.rects[core.active].h - core.panes[core.active].?.tag_rows);
+ const body_h: f32 = @floatFromInt(core.view().rects[core.view().active].h - core.panes[core.view().active].?.tag_rows);
const ctrl = struct {
fn key(cp: u21) pardes.Key {
return .{ .cp = cp, .ctrl = true };
@@ -4996,7 +4996,7 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
if (g.scroll_lag == 0 and g.scroll_notch == 0 and !g.glide.moving()) resetScroll(g);
return;
}
- const r = core.rects[id];
+ const r = core.view().rects[id];
if (r.h <= pane.tag_rows) {
resetScroll(g);
return;
@@ -5494,7 +5494,7 @@ fn renderFrame(
g.cursor_quad_alpha = if (quad_mode) caret_alpha * blink_alpha else 0;
// The probe's view of this frame's motion (FrameStats.Frame).
// A focused PDF's strip is the core's (pdf_view.draw).
- const pdf_focus = if (core.panes[core.active]) |pane| pane.hasPdf() else false;
+ const pdf_focus = if (core.panes[core.view().active]) |pane| pane.hasPdf() else false;
if (!pdf_focus) core.frames.scroll = g.glide.follow.offset;
core.frames.caret = caretRow(g, surface, now) orelse 0;
const cursors_shown = !quad_mode;
@@ -5812,7 +5812,7 @@ test "the layer cover is the per-cell layer scan, over a core's layouts and rand
var notices = false;
for (0..32) |step| {
if (step & 3 == 0) try std.testing.expect(core.executeBuiltinLine(2, "Collapse"));
- core.prefix = if (step & 4 != 0) .leader else .none;
+ core.view().prefix = if (step & 4 != 0) .leader else .none;
if (step & 8 != 0) {
try std.testing.expect(core.executeBuiltinLine(0, "Msg a message chip over the body"));
try std.testing.expect(core.executeBuiltinLine(3, "Msg another"));
@@ -5830,7 +5830,7 @@ test "the layer cover is the per-cell layer scan, over a core's layouts and rand
const cell = cover[@as(usize, region.rect.y) * s.cols + region.rect.x + offset];
try std.testing.expect(cell.grip);
try std.testing.expectEqual(offset, cell.grip_offset);
- try std.testing.expectEqual(region.owner == core.active, cell.focus);
+ try std.testing.expectEqual(region.owner == core.view().active, cell.focus);
}
}
for (s.tagLayers()) |layer| notices = notices or (layer.rows != 0 and layer.kind == .notice);
@@ -6151,7 +6151,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits
pane.tag.own = try gpa.dupe(u8, "second\nthird");
core.newScratchBelow(0);
for ([_]struct { w: u32, h: u32, tag: u32 }{ .{ .w = 10, .h = 20, .tag = 12 }, .{ .w = 17, .h = 35, .tag = 30 }, .{ .w = 9, .h = 19, .tag = 15 }, .{ .w = 12, .h = 24, .tag = 24 } }) |m| for ([_]usize{ 0, 1 }) |focus| for ([_]bool{ false, true }) |dirty| {
- core.active = focus;
+ core.view().active = focus;
pane.file.?.revision = pane.file.?.saved_revision + @intFromBool(dirty);
core.sync();
const s = try core.render(core.scratch.allocator());
@@ -7915,7 +7915,7 @@ test "the scrollbar thumb moves by the pixel and follows a glide" {
const at11 = try thumb.top(&g, core);
// A line of a thousand moves it a fraction of a row, not 0 or 20 px.
try std.testing.expect(at11 > at10 and at11 - at10 < 1);
- g.glide.pane = core.active;
+ g.glide.pane = core.view().active;
g.glide.follow.offset = -1;
try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3);
// A wrapped line: the picture moved two rows for the one line, and the
@@ -7965,8 +7965,8 @@ test "an empty column is ruled on both sides, as between two filled ones" {
// Newcol from the left pane: an empty column between the two filled ones.
pardes.layout.newColumn(core, 0);
core.sync();
- try std.testing.expectEqual(@as(usize, 3), core.ncol);
- try std.testing.expectEqual(@as(usize, 0), core.cols[1].n);
+ try std.testing.expectEqual(@as(usize, 3), core.view().ncol);
+ try std.testing.expectEqual(@as(usize, 0), core.view().cols[1].n);
const s = try core.render(core.scratch.allocator());
var g = testGui(10, 20, 6, 12);
defer g.decor.deinit(gpa);
@@ -7977,7 +7977,7 @@ test "an empty column is ruled on both sides, as between two filled ones" {
// Its left edge and its right edge (the next column's left): each a
// rule `rule_px` wide in the border colour, down to the window's foot.
for ([_]usize{ 1, 2 }) |column| {
- const px: f32 = @floatFromInt(@as(u32, core.col_x[column]) * 10);
+ const px: f32 = @floatFromInt(@as(u32, core.view().col_x[column]) * 10);
const rule = for (g.decor.items) |item| {
if (@abs(item.x0 - (px / 800 * 2 - 1)) < 1e-4 and @abs(item.x1 - ((px + @as(f32, @floatFromInt(s.chrome.rule_px))) / 800 * 2 - 1)) < 1e-4 and
std.mem.eql(f32, &.{ item.br, item.bg, item.bb }, &border)) break item;
@@ -8070,7 +8070,7 @@ test "decor is read from the regions" {
try buildDecor(&g, gpa, s, &groups, layout, 800, 480, true);
// A spine one pixel wide at each column's left edge, down from under the
// workspace tag; a rail two pixels wide at each pane's.
- for (core.col_x[0..core.ncol]) |x| {
+ for (core.view().col_x[0..core.view().ncol]) |x| {
const left = ndc.x(@as(f32, @floatFromInt(x)) * 10);
// Two pixels (rule_px), and none at the window's own edge.
const spine = for (g.decor.items) |item| {
diff --git a/src/host_io.zig b/src/host_io.zig
index 1808d266..19cc920f 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -197,12 +197,12 @@ pub fn stopWorkers() void {
pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes {
peers.dropAll(core);
const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| {
- core.reportError(core.active, "Restore", err);
+ core.reportError(core.view().active, "Restore", err);
return null;
};
defer gpa.free(bytes);
const nc = pardes.dump.restore(core, bytes, path) catch |err| {
- core.reportError(core.active, "Restore", err);
+ core.reportError(core.view().active, "Restore", err);
return null;
};
file_watch.unwatchAll(inotify_fd, watches);
@@ -236,7 +236,7 @@ pub const Adoptions = struct {
pub fn adoptShell(a: *Adoptions, core: *pardes.Pardes, pid: libc.pid_t, fd: c_int) void {
if (pid == 0) {
var buf: [96]u8 = undefined;
- return core.setMessage(core.active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else std.fmt.bufPrint(&buf, "Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }) catch "Adopt: shells taken in");
+ return core.setMessage(core.view().active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else std.fmt.bufPrint(&buf, "Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }) catch "Adopt: shells taken in");
}
if (a.len < a.list.len) {
a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null };
@@ -251,7 +251,7 @@ pub const Adoptions = struct {
// No room for it: its master goes, and the shell with this session.
_ = libc.close(fd);
var buf: [96]u8 = undefined;
- core.setMessage(core.active, std.fmt.bufPrint(&buf, "Adopt: no room for shell {d}; it ends with this session", .{pid}) catch "Adopt: no room for a shell");
+ core.setMessage(core.view().active, std.fmt.bufPrint(&buf, "Adopt: no room for shell {d}; it ends with this session", .{pid}) catch "Adopt: no room for a shell");
}
/// The adopted shell pane `pane`'s spawn takes, off the list.
@@ -868,7 +868,7 @@ pub const Lsp = struct {
const job = try snapshot(gpa, core, .{
.id = 7,
.kind = .status,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 0,
.arg = &needle,
});
@@ -883,7 +883,7 @@ pub const Lsp = struct {
try std.testing.expectEqualStrings("", job.path);
try std.testing.expectEqual(@as(usize, 0), job.source.len);
try std.testing.expectEqual(@as(u8, 0), job.source[0]);
- const pane = core.panes[core.active].?;
+ const pane = core.panes[core.view().active].?;
try std.testing.expectEqualStrings(pane.cwdSlice(), job.root);
if (job.root.len > 0) try std.testing.expect(job.root.ptr != pane.cwdSlice().ptr);
}
@@ -897,7 +897,7 @@ pub const Lsp = struct {
const job = try snapshot(gpa, p, .{
.id = 7,
.kind = .hover,
- .pane = @intCast(p.active),
+ .pane = @intCast(p.view().active),
.offset = 6,
.arg = "query",
});
@@ -921,7 +921,7 @@ pub const Lsp = struct {
const replacement = try gpa.dupe(u8, case.path);
gpa.free(pane.file.?.path);
pane.file.?.path = replacement;
- const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
defer job.free(gpa);
try std.testing.expectEqualStrings(case.native, job.path);
try std.testing.expectEqualStrings(std.fs.path.dirname(case.native).?, job.root);
@@ -967,7 +967,7 @@ pub const Lsp = struct {
const job = try snapshot(gpa, core, .{
.id = 42,
.kind = .status,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 0,
.arg = "",
});
@@ -1011,11 +1011,11 @@ pub const Lsp = struct {
var sink: Sink = .{ .core = core, .gpa = failing.allocator() };
for ([_]bool{ true, false }) |fail| {
failing.fail_index = std.math.maxInt(usize);
- core.lspRequest(core.active, kind, "renamed");
+ core.lspRequest(core.view().active, kind, "renamed");
const job = try snapshot(failing.allocator(), core, .{
.id = core.lsp_ask.wait.?.id,
.kind = kind,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 6,
.arg = "renamed",
});
@@ -1084,7 +1084,7 @@ pub const Lsp = struct {
} };
const core = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer core.deinit();
- const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = @intCast(core.active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
var sink: Sink = .{};
work(std.testing.io, gpa, job, &sink, Sink.take);
if (sink.rows) |rows| gpa.free(rows);
@@ -2152,8 +2152,8 @@ pub const exec_command_max = pardes.exec.command_max;
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 (comptime pardes.pdf_enabled) if (core) |c| {
- ws.xpixel = std.math.cast(u16, @as(u32, cols) * c.cell_pixels.w) orelse 0;
- ws.ypixel = std.math.cast(u16, @as(u32, rows) * c.cell_pixels.h) orelse 0;
+ 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;
}
@@ -3853,8 +3853,8 @@ test "LSP query answers, and a newer one cancels it" {
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
for (0..2) |_| {
- core.lspRequest(core.active, .status, "");
- queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.active), .offset = 0, .arg = "" });
+ core.lspRequest(core.view().active, .status, "");
+ queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
}
const last = core.lsp_ask.wait.?.id;
queue.lsp_task.?.future.await(io);
diff --git a/src/hunks.zig b/src/hunks.zig
index b30f09a6..00d4cc97 100644
--- a/src/hunks.zig
+++ b/src/hunks.zig
@@ -740,13 +740,13 @@ test "a .patch looked at opens its +Diff, and Diff goes to the text and back" {
pardes.look.lookAt(p, 0, patch);
try testing.expectEqual(@as(usize, 1), Count.of(p, hunks_path));
try testing.expectEqual(@as(usize, 0), Count.of(p, patch));
- const hid = p.active;
+ const hid = p.view().active;
try testing.expectEqualStrings(hunks_path, p.panes[hid].?.file.?.path);
try testing.expectEqualStrings("x.txt:1\n-a\n+b\n", p.panes[hid].?.file.?.content);
// Diff on it: the patch as text.
try testing.expect(p.executeBuiltinLine(hid, "Diff"));
try testing.expectEqual(@as(usize, 1), Count.of(p, patch));
- const raw = p.active;
+ const raw = p.view().active;
try testing.expectEqualStrings(patch, p.panes[raw].?.file.?.path);
// Diff on the text: the +Diff again, refilled, not another.
try testing.expect(p.executeBuiltinLine(raw, "Diff"));
diff --git a/src/keys.zig b/src/keys.zig
index d9925838..06566714 100644
--- a/src/keys.zig
+++ b/src/keys.zig
@@ -35,7 +35,7 @@ pub fn cycleMode(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
if (pane.file == null and !pane.isTerminal()) return;
const previous = pane.body.mode;
- p.active = id;
+ p.view().active = id;
tagline.exitHeader(p);
pane.focus = .body;
pane.closePrompt();
@@ -56,7 +56,7 @@ pub fn cycleMode(p: *Pardes, id: usize) void {
pub fn toggleTty(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
if (!pane.isTerminal()) return;
- p.active = id;
+ p.view().active = id;
tagline.exitHeader(p);
pane.focus = .body;
pane.closePrompt();
@@ -107,6 +107,7 @@ pub fn questionChoices(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 {
/// `answer` on the pane's ctl, and the log says which, as `answer
/// <serial> <choice|->`; false when the pane asks nothing.
pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool {
+ const v = p.view();
const asked = p.panes[id] orelse return false;
var offered: [64]u8 = undefined;
if (questionChoices(p, id, &offered)) |choices| {
@@ -143,7 +144,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool {
if (choice == 'k') exec.runBuiltin(p, .Del, id, "", "k");
if (choice == 'j') exec.runBuiltin(p, .Del, id, "", "j");
// Asked from window mode (`d`): the outline goes with the rows.
- if (p.window_pick == id and p.panes[id] == null) p.window_pick = if (p.header != null) null else p.active;
+ if (v.window_pick == id and p.panes[id] == null) v.window_pick = if (v.header != null) null else v.active;
},
else => return false,
}
@@ -152,7 +153,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool {
pub fn handleKey(p: *Pardes, key: Key) void {
// A double-click is two clicks with nothing between them.
- p.last_click = null;
+ p.view().last_click = null;
if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key);
// A question waiting on a pane takes the next key, whatever mode the
// pane or a header edit is in: that key is its answer.
@@ -166,8 +167,8 @@ pub fn handleKey(p: *Pardes, key: Key) void {
}
return;
}
- if (p.window_pick != null) return layout.windowKey(p, key);
- const pane = p.panes[p.active] orelse return;
+ if (p.view().window_pick != null) return layout.windowKey(p, key);
+ const pane = p.panes[p.view().active] orelse return;
layout.noteTyped(p);
// In a raw terminal the two Escs swap: Esc backs out, and Shift-Esc is
// the program's, sent as a plain Esc.
@@ -175,17 +176,17 @@ pub fn handleKey(p: *Pardes, key: Key) void {
pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none and
tagline.focusedHeader(p) == null;
if (raw_esc and key.shift) {
- p.prefix = .none;
+ p.view().prefix = .none;
panes.terminal.followOutput(pane);
var plain = key;
plain.shift = false;
- return panes.terminal.forwardKey(p, p.active, plain);
+ return panes.terminal.forwardKey(p, p.view().active, plain);
}
// Shift-Esc backs out of whatever the pane is in -- a prompt, insert
// mode, a pending count, a raw program -- to the previous pane, as
// Esc does from normal mode. Nothing under it sees the key.
if (raw_esc or hit(key, config.back_out)) {
- p.prefix = .none;
+ p.view().prefix = .none;
if (pane.prompt != .none) {
pane.closePrompt();
pane.focus = .body;
@@ -196,7 +197,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
t.select = false;
}
tagline.exitHeader(p);
- return exec.runBuiltin(p, .Last, p.active, "", null);
+ return exec.runBuiltin(p, .Last, p.view().active, "", null);
}
// Alt-Down and Alt-Up in a pane's tag expand and collapse it, in
// either mode: acme's Tagdown and Tagup (plan9port text.c:776).
@@ -207,9 +208,9 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// An open prompt takes the keys even when it answers for a header.
const header = if (pane.prompt != .none) null else tagline.focusedHeader(p);
if (header == null and pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none) {
- p.prefix = .none;
+ p.view().prefix = .none;
if (key.ctrl and !key.alt and key.cp == p.tty_toggle)
- return toggleTty(p, p.active);
+ return toggleTty(p, p.view().active);
panes.terminal.followOutput(pane); // typing snaps back to live output
// Paste stays the window's, the one exception to forwarding a raw
// tty's keys: Ctrl-V types the register at the program and
@@ -218,27 +219,27 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// account instead — a coding agent goes there hunting for an image.
// A host that folds Shift into the letter says the same thing.
if (key.ctrl and !key.alt and (key.cp == 'v' or key.cp == 'V')) {
- if (key.shift or key.cp == 'V') return edit.clipRequest(p, p.active, .after);
+ if (key.shift or key.cp == 'V') return edit.clipRequest(p, p.view().active, .after);
// With something in the register this is a paste. With nothing
// in it the chord is the program's -- vim's visual block,
// readline's quoted-insert -- and swallowing it would make
// Ctrl-V a black hole in every full-screen application.
- if (p.registers.text(p.gpa, Registers.default)) |text| return edit.typeToTty(p, p.active, pane, text);
+ if (p.registers.text(p.gpa, Registers.default)) |text| return edit.typeToTty(p, p.view().active, pane, text);
}
- return panes.terminal.forwardKey(p, p.active, key);
+ return panes.terminal.forwardKey(p, p.view().active, key);
}
// A kind's pane that takes keys takes them all, as a raw terminal
// does, but Esc, which leaves (and Shift-Esc, above).
if (header == null and pane.focus == .body and pane.prompt == .none) if (pane.addon) |slot| if (pardes.Kind.takesKeys(p, slot)) {
- p.prefix = .none;
- if (key.cp == Key.escape and !key.ctrl and !key.alt) return exec.runBuiltin(p, .Last, p.active, "", null);
- if (pardes.Kind.key(p, p.active, key)) return;
+ p.view().prefix = .none;
+ if (key.cp == Key.escape and !key.ctrl and !key.alt) return exec.runBuiltin(p, .Last, p.view().active, "", null);
+ if (pardes.Kind.key(p, p.view().active, key)) return;
};
- if (p.prefix == .leader) return leaderKey(p, key);
- if (p.prefix == .window) {
- p.prefix = .none;
+ if (p.view().prefix == .leader) return leaderKey(p, key);
+ if (p.view().prefix == .window) {
+ p.view().prefix = .none;
for (config.window_keys) |wk| {
- if (hit(key, &.{ wk.letter, wk.arrow })) return exec.runBuiltin(p, wk.cmd, p.active, "", null);
+ if (hit(key, &.{ wk.letter, wk.arrow })) return exec.runBuiltin(p, wk.cmd, p.view().active, "", null);
}
return;
}
@@ -248,37 +249,37 @@ pub fn handleKey(p: *Pardes, key: Key) void {
const t = header orelse if (pane.focus == .tag) &pane.tag else &pane.body;
if (hit(key, config.window_prefix) and t.mode != .insert and (header != null or pane.prompt == .none)) {
if (header != null) {
- p.prefix = .window;
+ p.view().prefix = .window;
return;
}
- return exec.runBuiltin(p, .Window, p.active, "", null);
+ return exec.runBuiltin(p, .Window, p.view().active, "", null);
}
// global window ops (any mode): Alt-n new terminal below, Alt-c move
// the active terminal into a fresh column
if (hit(key, config.new_shell_below)) {
- const free = p.freeSlot() orelse return p.reportError(p.active, "Term", error.NoPaneSlots);
+ const free = p.freeSlot() orelse return p.reportError(p.view().active, "Term", error.NoPaneSlots);
const nt = p.newShell(free, "") catch return;
nt.greet = true;
// From a tag, as a 9P new is: acme's t->w == nil.
- exec.placeNew(p, p.active, if (p.header != null) null else p.active, free, .shell);
+ exec.placeNew(p, p.view().active, if (p.view().header != null) null else p.view().active, free, .shell);
return;
}
for (config.jump_keys) |jk| {
if (!hit(key, &.{jk.chord})) continue;
tagline.exitHeader(p);
- return exec.runBuiltin(p, jk.cmd, p.active, "", null);
+ return exec.runBuiltin(p, jk.cmd, p.view().active, "", null);
}
if (hit(key, config.pane_to_new_column)) {
tagline.exitHeader(p);
- const f = layout.findPane(p, p.active).?;
- if (p.ncol < MAX_COLS and p.cols[f.col].n > 1) {
- _ = layout.splitColumn(p, p.active, p.active, false);
+ const f = layout.findPane(p, p.view().active).?;
+ if (p.view().ncol < MAX_COLS and p.view().cols[f.col].n > 1) {
+ _ = layout.splitColumn(p, p.view().active, p.view().active, false);
}
return;
}
const tty_toggle = key.ctrl and key.cp == p.tty_toggle;
if (pane.isTerminal() and tty_toggle) {
- return toggleTty(p, p.active);
+ return toggleTty(p, p.view().active);
}
if (header == null and pane.prompt == .name) {
// Enter or the execute key commits the draft and the keyboard
@@ -297,7 +298,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
}
if (hit(key, config.escape) or pending) {
pane.input.mode = .normal;
- p.setMessage(p.active, "name drafted: Enter renames the buffer, Esc drops the draft");
+ p.setMessage(p.view().active, "name drafted: Enter renames the buffer, Esc drops the draft");
return;
}
edit.handleInsert(p, &pane.input, key);
@@ -308,10 +309,10 @@ pub fn handleKey(p: *Pardes, key: Key) void {
const submit = hit(key, config.search_submit);
const target = panes.promptTarget(p, pane);
switch (pane.prompt) {
- .pipe => if (submit) Pipe.submitPipe(p, p.active),
- .save => if (submit) exec.submitSave(p, p.active),
+ .pipe => if (submit) Pipe.submitPipe(p, p.view().active),
+ .save => if (submit) exec.submitSave(p, p.view().active),
.search => if (submit)
- look.submitSearch(p, p.active)
+ look.submitSearch(p, p.view().active)
else if (normal.selRegexArmed(pane)) |_| if (target) |answered|
normal.applySelRegex(p, pane, answered, "", .select),
.none, .del_side, .repl_choice, .name => unreachable,
@@ -330,7 +331,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
if (t == &pane.body and pane.jump.items.len > 0) return normal.jumpKey(p, pane, t, key);
// A query pane's line 1 answers Enter, Esc and the stepping keys
// itself (Query.zig).
- if (t == &pane.body and header == null and pane.query != null and panes.Query.key(p, p.active, key)) return;
+ if (t == &pane.body and header == null and pane.query != null and panes.Query.key(p, p.view().active, key)) return;
if (t.mode == .normal and p.macro.replaying == 0 and (hit(key, config.look_key) or hit(key, config.exec_key))) {
// A header's words are the workspace's and column's commands, so
// Enter runs them there, as the execute key does.
@@ -362,12 +363,12 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// A pane's tag word: an event reader hears it as a click on
// it, at its place in the tag (flatSurface is the tag's text).
if (header == null and t.what == .tag and
- mouse.reportRange(p, p.active, cmd, txt, true, .{ .q0 = @intCast(span[0]), .q1 = @intCast(span[1]) }, null)) return;
- exec.runBuiltin(p, cmd, p.active, "", txt);
+ mouse.reportRange(p, p.view().active, cmd, txt, true, .{ .q0 = @intCast(span[0]), .q1 = @intCast(span[1]) }, null)) return;
+ exec.runBuiltin(p, cmd, p.view().active, "", txt);
return;
}
edit.pinPaneCursor(p, &pane.body);
- const explicit = (p.frontend.native_images and pane.hasPdfSelection()) or
+ const explicit = (p.view().frontend.native_images and pane.hasPdfSelection()) or
(pane.body.vsel.active and pane.body.vsel.explicit);
if (explicit) {
if (exec.chordEachSel(p, pane, cmd)) return;
@@ -375,7 +376,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
pane.body.vsel.active = false;
pane.body.select = false;
// The execute key on a body: text a bound REPL may take.
- exec.runBuiltinFrom(p, cmd, p.active, "", txt, true);
+ exec.runBuiltinFrom(p, cmd, p.view().active, "", txt, true);
return;
}
}
@@ -383,7 +384,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// (exec.operandAt), a diff line's address and all, and an
// event reader told as a click tells it.
const operand = exec.operandAt(p, pane, look.cursorWordSel(p, pane), false, cmd == config.look_cmd);
- mouse.dispatchPointerBuiltin(p, p.active, cmd, operand.text, .{ .on_tag = false, .operand = operand });
+ mouse.dispatchPointerBuiltin(p, p.view().active, cmd, operand.text, .{ .on_tag = false, .operand = operand });
return;
}
if (t.mode == .normal and t.what == .body and pane.hasPdf()) return normal.handlePdfNormal(p, pane, key);
@@ -406,7 +407,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
edit.exitInsert(p, t)
else
edit.handleInsert(p, t, key),
- .tty => panes.terminal.forwardKey(p, p.active, key),
+ .tty => panes.terminal.forwardKey(p, p.view().active, key),
}
// `.`'s log: the keys of the normal command that entered insert
// mode, then everything typed until it is left
@@ -440,42 +441,43 @@ pub fn leaderTaken(keys: []const u8) bool {
}
fn leaderKey(p: *Pardes, key: Key) void {
- p.prefix = .none; // only "still a prefix" below re-arms it
+ const v = p.view();
+ v.prefix = .none; // only "still a prefix" below re-arms it
if (key.ctrl or key.alt or key.cp < 0x20 or key.cp > 0x7e) return;
const c: u8 = @intCast(key.cp);
if (c == config.leader_help) {
- panes.Output.openHelp(p, p.active, p.leader_keys[0..p.leader_n]) catch |err|
- p.reportError(p.active, "help", err);
+ panes.Output.openHelp(p, v.active, v.leader_keys[0..p.view().leader_n]) catch |err|
+ p.reportError(v.active, "help", err);
return;
}
- if (p.leader_n >= p.leader_keys.len) return;
- p.leader_keys[p.leader_n] = c;
- p.leader_n += 1;
- const pfx = p.leader_keys[0..p.leader_n];
+ if (v.leader_n >= v.leader_keys.len) return;
+ v.leader_keys[v.leader_n] = c;
+ v.leader_n += 1;
+ const pfx = v.leader_keys[0..p.view().leader_n];
// A path that runs a builtin with its argument (the query pane's
// sources with no word of their own).
- for (config.leader_args) |la| if (std.mem.eql(u8, la.path, pfx)) return exec.runBuiltin(p, la.cmd, p.active, "", la.arg);
+ for (config.leader_args) |la| if (std.mem.eql(u8, la.path, pfx)) return exec.runBuiltin(p, la.cmd, v.active, "", la.arg);
for (config.leader_args) |la| if (std.mem.startsWith(u8, la.path, pfx)) {
- p.prefix = .leader;
+ v.prefix = .leader;
};
// a path-less builtin is a row here too (it is the same index Help
// reads), and SPC cannot reach one — so both scans skip it; and a
// window's own word is no path in a terminal's view
for (builtin_rows) |row| {
if (!builtins.registry.here(p, row.cmd)) continue;
- if (std.mem.eql(u8, row.path orelse continue, pfx)) return exec.runBuiltin(p, row.cmd, p.active, "", null);
+ if (std.mem.eql(u8, row.path orelse continue, pfx)) return exec.runBuiltin(p, row.cmd, v.active, "", null);
}
for (builtin_rows) |row| {
if (!builtins.registry.here(p, row.cmd)) continue;
if (std.mem.startsWith(u8, row.path orelse continue, pfx)) {
- p.prefix = .leader;
+ v.prefix = .leader;
return;
}
}
// An addon's word, after the core's (a path the core has is no addon's).
switch (p.kinds.leader(pfx)) {
- .word => |w| exec.runWord(p, p.active, w, w.name.slice(), ""),
- .prefix => p.prefix = .leader,
+ .word => |w| exec.runWord(p, v.active, w, w.name.slice(), ""),
+ .prefix => v.prefix = .leader,
.none => {},
}
}
@@ -486,16 +488,16 @@ test "Esc back into a tty leaves its view at the prompt" {
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());
// A click pins the modal cursor — one of the several ordinary ways to get a
// pin, and the pin is what a shell's rows then scroll out from under.
- const r = p.rects[shell];
+ const r = p.view().rects[shell];
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H } });
- try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqual(shell, p.view().active);
p.update(.{ .key = .{ .cp = 'b', .ctrl = true } });
try std.testing.expectEqual(Text.Mode.tty, sp.body.mode);
@@ -511,10 +513,10 @@ test "Esc back into a tty leaves its view at the prompt" {
try std.testing.expect(live > 0);
p.update(.{ .key = .{ .cp = Key.escape } }); // shell-prompt heuristic: out to the doc
- try std.testing.expect(p.active != shell);
+ try std.testing.expect(p.view().active != shell);
p.update(.{ .key = .{ .cp = Key.escape } }); // ...and back in
p.sync();
- try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqual(shell, p.view().active);
try std.testing.expectEqual(live, sp.terminal.?.vt.screens.active.pages.scrollbar().offset);
}
@@ -524,16 +526,16 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
defer p.deinit();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- const top = p.active;
+ const top = p.view().active;
p.newScratchBelow(top);
- const mid = p.active;
+ const mid = p.view().active;
p.newScratchBelow(mid);
- const low = p.active;
+ const low = p.view().active;
p.sync();
- var h = [_]u16{ p.rects[top].h, p.rects[mid].h, p.rects[low].h };
+ var h = [_]u16{ p.view().rects[top].h, p.view().rects[mid].h, p.view().rects[low].h };
// SPC d on the middle pane asks on its notice band, and closes nothing yet.
- p.active = mid;
+ p.view().active = mid;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'd' } });
try std.testing.expect(p.panes[mid] != null);
@@ -545,19 +547,19 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
// j: the pane below takes every row, the one above keeps its own.
p.update(.{ .key = .{ .cp = 'j' } });
try std.testing.expect(p.panes[mid] == null);
- try std.testing.expectEqual(h[0], p.rects[top].h);
- try std.testing.expectEqual(h[1] + h[2], p.rects[low].h);
- try std.testing.expectEqual(low, p.active); // focus follows the rows
+ try std.testing.expectEqual(h[0], p.view().rects[top].h);
+ try std.testing.expectEqual(h[1] + h[2], p.view().rects[low].h);
+ try std.testing.expectEqual(low, p.view().active); // focus follows the rows
// Esc takes the question back and the pane stays; so does any other key,
// and so does a click. A New goes to the column's foot, under low, which
// is between two again.
p.newScratchBelow(low);
- const foot = p.active;
+ const foot = p.view().active;
const again = low;
- p.active = again;
+ p.view().active = again;
p.sync();
- h = .{ p.rects[top].h, p.rects[again].h, p.rects[foot].h };
+ h = .{ p.view().rects[top].h, p.view().rects[again].h, p.view().rects[foot].h };
try std.testing.expect(p.executeBuiltinLine(again, "Msg keep"));
for ([_]Key{ .{ .cp = Key.escape }, .{ .cp = 'x' } }) |answer| {
p.update(.{ .key = .{ .cp = ' ' } });
@@ -569,12 +571,12 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
}
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'd' } });
- const r = p.rects[again];
+ const r = p.view().rects[again];
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x + 5, .row = r.y + 3 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x + 5, .row = r.y + 3 } });
try std.testing.expect(p.panes[again] != null);
try std.testing.expectEqual(Pane.Prompt.none, p.panes[again].?.prompt);
- try std.testing.expectEqual(h[1], p.rects[again].h);
+ try std.testing.expectEqual(h[1], p.view().rects[again].h);
// A word that is not a side closes nothing.
try std.testing.expect(p.executeBuiltinLine(again, "Del x"));
@@ -584,18 +586,18 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
try std.testing.expect(p.executeBuiltinLine(again, "DelAbove"));
p.sync();
try std.testing.expect(p.panes[again] == null);
- try std.testing.expectEqual(h[0] + h[1], p.rects[top].h);
- try std.testing.expectEqual(top, p.active);
- try std.testing.expectEqual(h[2], p.rects[foot].h);
+ try std.testing.expectEqual(h[0] + h[1], p.view().rects[top].h);
+ try std.testing.expectEqual(top, p.view().active);
+ try std.testing.expectEqual(h[2], p.view().rects[foot].h);
// A script answers the question on the pane's ctl, as the log's `ask`
// names it: `answer -` takes it back, a side closes the pane toward it.
p.newScratchBelow(foot);
- const tail = p.active;
+ const tail = p.view().active;
{
const th = @import("ninep/testing.zig");
const asked = foot;
- p.active = asked;
+ p.view().active = asked;
p.sync();
const serial = p.panes[asked].?.serial;
const ctl = ctlfs.Node.of(serial, .ctl);
@@ -619,17 +621,17 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
// Bare Del from anything but a key closes at once and gives the rows up,
// as it always has.
p.newScratchBelow(tail);
- const last = p.active;
+ const last = p.view().active;
const third = tail;
p.sync();
- h = .{ p.rects[top].h, p.rects[third].h, p.rects[last].h };
+ h = .{ p.view().rects[top].h, p.view().rects[third].h, p.view().rects[last].h };
try std.testing.expect(p.executeBuiltinLine(third, "Del"));
p.sync();
try std.testing.expect(p.panes[third] == null);
- try std.testing.expectEqual(h[0] + h[1], p.rects[top].h);
+ try std.testing.expectEqual(h[0] + h[1], p.view().rects[top].h);
// With nothing open below, there is nothing to ask: SPC d closes at once.
- p.active = last;
+ p.view().active = last;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'd' } });
try std.testing.expect(p.panes[last] == null);
@@ -639,7 +641,7 @@ test "raw tty Esc backs out and Shift-Esc is the program's Esc" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
defer p.deinit();
_ = exec.spawnTty(p, 0);
- const shell = p.active;
+ const shell = p.view().active;
const pane = p.panes[shell].?;
var buf: [256]u8 = undefined;
_ = test_api.ptyBytes(p, null, &buf);
@@ -647,15 +649,15 @@ test "raw tty Esc backs out and Shift-Esc is the program's Esc" {
p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
_ = test_api.ptyBytes(p, null, &buf);
p.update(.{ .key = .{ .cp = Key.escape } }); // past typed text too
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqualStrings("", test_api.ptyBytes(p, null, &buf));
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
p.update(.{ .key = .{ .cp = Key.escape } }); // back into the shell
- try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqual(shell, p.view().active);
_ = test_api.ptyBytes(p, null, &buf);
p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
- try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqual(shell, p.view().active);
try std.testing.expectEqualStrings("\x1b", test_api.ptyBytes(p, null, &buf));
}
@@ -664,12 +666,12 @@ test "the Del question shows only once its delay is up: a quick SPC d j never se
defer p.deinit();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- const top = p.active;
+ const top = p.view().active;
p.newScratchBelow(top);
- const mid = p.active;
+ const mid = p.view().active;
p.newScratchBelow(mid);
p.sync();
- p.active = mid;
+ p.view().active = mid;
p.clock.now_ns = 5 * std.time.ns_per_s;
p.clock.stepped_ns = p.clock.now_ns;
const asked_at = p.clock.now_ns;
@@ -711,12 +713,12 @@ test "raw tty Ctrl-B switches to editor mode without sending child input" {
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
defer p.deinit();
_ = exec.spawnTty(p, 0);
- const shell = p.active;
+ const shell = p.view().active;
p.sync();
var buf: [256]u8 = undefined;
_ = test_api.ptyBytes(p, null, &buf);
p.update(.{ .key = .{ .cp = 'b', .ctrl = true } });
- try std.testing.expectEqual(shell, p.active);
+ try std.testing.expectEqual(shell, p.view().active);
try std.testing.expectEqual(Text.Mode.normal, p.panes[shell].?.body.mode);
try std.testing.expectEqualStrings("", test_api.ptyBytes(p, null, &buf));
}
@@ -739,24 +741,24 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" {
else => &expected,
};
try std.testing.expectEqualStrings(encoded, test_api.ptyBytes(p, null, &buf));
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(Text.Mode.tty, p.panes[0].?.body.mode);
- try std.testing.expect(p.prefix != .window and p.clip_pending == null);
+ try std.testing.expect(p.view().prefix != .window and p.view().clip_pending == null);
}
// ...and the two paste chords are the exception: Ctrl-V types the register
// at the program, Ctrl-Shift-V asks the desktop first and types nothing yet.
p.update(.{ .key = .{ .cp = 'v', .ctrl = true } });
try std.testing.expectEqualStrings("register text", test_api.ptyBytes(p, null, &buf));
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
p.update(.{ .key = .{ .cp = 'v', .ctrl = true, .shift = true } });
try std.testing.expectEqualStrings("", test_api.ptyBytes(p, null, &buf));
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
const unopened = p.freeSlot(); // whatever the boot layout already used
for ([_]u8{ 'n', 'c' }) |letter| {
p.update(.{ .key = .{ .cp = letter, .alt = true } });
const expected = [_]u8{ 0x1b, letter };
try std.testing.expectEqualStrings(&expected, test_api.ptyBytes(p, null, &buf));
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(unopened, p.freeSlot());
}
p.update(.{ .key = .{ .cp = Key.up } });
@@ -779,7 +781,7 @@ test "s in a header selects in the header's own text" {
// the prompt takes the keys while the header keeps the keyboard
p.update(.{ .key = .{ .cp = 'c', .text = "col" } });
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(p.header != null and pane.prompt == .none);
+ try std.testing.expect(p.view().header != null and pane.prompt == .none);
var ranges: [Text.max_selections]modal.Selection = undefined;
const text = try edit.flatSurface(p, &p.global_tag);
const got = p.global_tag.ranges(text, 0, &ranges);
diff --git a/src/layout.zig b/src/layout.zig
index 1515b525..a0d7cbd5 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -35,7 +35,7 @@ pub const Dir = enum { left, right, up, down };
/// Move the keyboard to the nearest pane in `dir`; false when there is none.
pub fn focusDir(p: *Pardes, from: usize, dir: Dir) bool {
const b = nearest(p, from, dir) orelse return false;
- p.active = b;
+ p.view().active = b;
// a count typed before the hop was meant for the pane you left
p.panes[b].?.body.normal.clear();
return true;
@@ -43,12 +43,12 @@ pub fn focusDir(p: *Pardes, from: usize, dir: Dir) bool {
/// The pane next to `from` in `dir`, by the screen.
pub fn nearest(p: *const Pardes, from: usize, dir: Dir) ?usize {
- const a = p.rects[from];
+ const a = p.view().rects[from];
var best: ?usize = null;
var best_d: i32 = 0;
for (p.panes, 0..) |slot, i| {
if (slot == null or i == from) continue;
- const r = p.rects[i];
+ const r = p.view().rects[i];
const vov = a.y < r.y + r.h and r.y < a.y + a.h;
const hov = a.x < r.x + r.w and r.x < a.x + a.w;
const ok = switch (dir) {
@@ -81,7 +81,7 @@ pub const window_labels = "asfgqwertyuiopzxvbnm";
/// The letter window mode shows on pane `id`.
pub fn windowLabel(p: *const Pardes, id: usize) ?u8 {
var n: usize = 0;
- for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |pane| {
+ for (0..p.view().ncol) |c| for (p.view().cols[c].panes[0..p.view().cols[c].n]) |pane| {
if (n == window_labels.len) return null;
if (pane == id) return window_labels[n];
n += 1;
@@ -98,9 +98,10 @@ pub fn windowLabel(p: *const Pardes, id: usize) ?u8 {
/// question, when Del asks one; keys.answerQuestion). Any other key
/// changes nothing.
pub fn windowKey(p: *Pardes, key: pardes.Key) void {
- const at = p.window_pick orelse return;
+ const v = p.view();
+ const at = v.window_pick orelse return;
if (p.panes[at] == null) {
- p.window_pick = null;
+ v.window_pick = null;
return;
}
if (key.ctrl or key.alt) return;
@@ -112,10 +113,10 @@ pub fn windowKey(p: *Pardes, key: pardes.Key) void {
else => .right,
};
if (nearest(p, at, dir)) |next| {
- p.window_pick = next;
+ v.window_pick = next;
} else if (dir == .up) {
- p.window_pick = null;
- p.active = at;
+ v.window_pick = null;
+ v.active = at;
pardes.exec.runBuiltin(p, .Up, at, "", null);
}
return;
@@ -124,33 +125,34 @@ pub fn windowKey(p: *Pardes, key: pardes.Key) void {
if (pardes.hit(key, config.window_delete)) {
// Del's focus follows the rows from the pane it closes, so the
// outlined pane is the active one while it runs.
- p.active = at;
+ v.active = at;
pardes.exec.runBuiltin(p, .Del, at, "", null);
- if (p.panes[at] == null) p.window_pick = if (p.header != null) null else p.active;
+ if (p.panes[at] == null) v.window_pick = if (v.header != null) null else v.active;
return;
}
const chosen = if (key.cp == pardes.Key.enter or key.cp == pardes.Key.escape or key.cp == ':') at else for (0..p.panes.len) |id| {
if (p.panes[id] != null and key.cp < 128 and windowLabel(p, id) == @as(u8, @intCast(key.cp))) break id;
} else return;
- p.window_pick = null;
- p.active = chosen;
+ v.window_pick = null;
+ v.active = chosen;
p.panes[chosen].?.body.normal.clear();
if (key.cp == ':') tagline.enterTag(p, p.panes[chosen].?);
}
/// Column `c`'s serial, handed out the first time it is asked for.
pub fn columnSerial(p: *Pardes, c: usize) u32 {
- if (p.cols[c].serial == 0) {
- p.cols[c].serial = p.next_column_serial;
+ const v = p.view();
+ if (v.cols[c].serial == 0) {
+ v.cols[c].serial = p.next_column_serial;
p.next_column_serial +%= 1;
if (p.next_column_serial == 0) p.next_column_serial = 1;
}
- return p.cols[c].serial;
+ return v.cols[c].serial;
}
pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize {
if (serial == 0) return null;
- for (0..p.ncol) |column| if (p.cols[column].serial == serial) return column;
+ for (0..p.view().ncol) |column| if (p.view().cols[column].serial == serial) return column;
return null;
}
@@ -162,17 +164,18 @@ pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize {
pub const ColumnDrop = union(enum) { stay, reorder: usize, edge: u16 };
pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop {
- if (source >= p.ncol) return .stay;
+ const v = p.view();
+ if (source >= v.ncol) return .stay;
var insertion: usize = 0;
- for (0..p.ncol) |column| {
+ for (0..p.view().ncol) |column| {
if (column == source) continue;
- if (x >= p.col_x[column] + p.col_w[column] / 2) insertion += 1;
+ if (x >= v.col_x[column] + v.col_w[column] / 2) insertion += 1;
}
if (insertion != source) return .{ .reorder = insertion };
- if (source == 0 or (x >= p.col_x[source] and x < p.col_x[source] + config.GUTTER)) return .stay;
- if (p.col_w[source - 1] + p.col_w[source] < 2 * config.MINW) return .stay;
- const lo = p.col_x[source - 1] + config.MINW;
- const hi = (p.col_x[source] + p.col_w[source]) -| config.MINW;
+ if (source == 0 or (x >= v.col_x[source] and x < v.col_x[source] + config.GUTTER)) return .stay;
+ if (v.col_w[source - 1] + v.col_w[source] < 2 * config.MINW) return .stay;
+ const lo = v.col_x[source - 1] + config.MINW;
+ const hi = (v.col_x[source] + v.col_w[source]) -| config.MINW;
return .{ .edge = std.math.clamp(x -| grab, lo, @max(lo, hi)) };
}
@@ -180,48 +183,51 @@ pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop
/// `left_width` cells, neither below MINW. A border drag and a column grip
/// dropped inside its own place both end here.
pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void {
- if (left + 1 >= p.ncol) return;
- const combined: u64 = p.col_w[left] + p.col_w[left + 1];
+ const v = p.view();
+ if (left + 1 >= v.ncol) return;
+ const combined: u64 = v.col_w[left] + v.col_w[left + 1];
// Too narrow for both to keep MINW: any split would squeeze one away.
if (combined < 2 * @as(u64, config.MINW)) return;
const width = std.math.clamp(left_width, config.MINW, @max(@as(u64, config.MINW), combined -| config.MINW));
- const pair = p.cols[left].weight + p.cols[left + 1].weight;
+ const pair = v.cols[left].weight + v.cols[left + 1].weight;
if (pair <= 1 or combined == 0) return;
const numerator = @as(u128, pair) * width + combined / 2;
const share = std.math.clamp(@as(u64, @intCast(numerator / combined)), 1, pair - 1);
- p.cols[left].weight = share;
- p.cols[left + 1].weight = pair - share;
+ v.cols[left].weight = share;
+ v.cols[left + 1].weight = pair - share;
}
pub fn reorderColumn(p: *Pardes, from: usize, to: usize) void {
- if (from >= p.ncol or to >= p.ncol or from == to) return;
- const moved = p.cols[from];
- const tag = p.col_tags[from];
+ const v = p.view();
+ if (from >= v.ncol or to >= v.ncol or from == to) return;
+ const moved = v.cols[from];
+ const tag = v.col_tags[from];
var at = from;
while (at != to) {
const next = if (at < to) at + 1 else at - 1;
- p.cols[at] = p.cols[next];
- p.col_tags[at] = p.col_tags[next];
+ v.cols[at] = v.cols[next];
+ v.col_tags[at] = v.col_tags[next];
at = next;
}
- p.cols[to] = moved;
- p.col_tags[to] = tag;
- if (p.header) |*h| if (h.* == .column) {
+ v.cols[to] = moved;
+ v.col_tags[to] = tag;
+ if (v.header) |*h| if (h.* == .column) {
const column = h.column;
if (column == from) h.column = to else if (from < to and column > from and column <= to) {
h.column = column - 1;
} else if (from > to and column >= to and column < from) h.column = column + 1;
};
- p.pointer_tag_hit = null;
+ v.pointer_tag_hit = null;
p.look_hover_wait = null;
p.look_hover_preview = null;
compute(p);
}
pub fn targetColumn(p: *Pardes, cur_x: u16) usize {
- var tc: usize = if (p.ncol > 0) p.ncol - 1 else 0;
- for (0..p.ncol) |c| {
- if (cur_x >= p.col_x[c] and cur_x < p.col_x[c] + p.col_w[c]) {
+ const v = p.view();
+ var tc: usize = if (v.ncol > 0) v.ncol - 1 else 0;
+ for (0..p.view().ncol) |c| {
+ if (cur_x >= v.col_x[c] and cur_x < v.col_x[c] + v.col_w[c]) {
tc = c;
break;
}
@@ -247,15 +253,16 @@ fn splitRowFor(y: u16, h: u16, cur_y: u16, least: ?u16) ?u16 {
/// within its group resizes it and anywhere else detaches it (movePane).
/// Another group is one place: a pane dropped on it lands under all of it.
pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlacement {
+ const v = p.view();
const src = findPane(p, id) orelse return null;
const span_end = if (ownerOf(p, id) == null) groupEnd(p, src.col, src.idx) else src.idx + 1;
const own_root = groupRoot(p, id);
const tc = targetColumn(p, cur_x);
- if (tc == src.col and p.cols[src.col].n == span_end - src.idx) return null;
+ if (tc == src.col and v.cols[src.col].n == span_end - src.idx) return null;
var span_h: u16 = 0;
- for (p.cols[src.col].panes[src.idx..span_end]) |k| span_h +|= p.rects[k].h;
+ for (v.cols[src.col].panes[src.idx..span_end]) |k| span_h +|= v.rects[k].h;
if (tc == src.col) {
- const top = p.rects[id].y;
+ const top = v.rects[id].y;
// Dropped on itself it stays, unless dragged down from its top with
// a pane above: its top moves down there, the pane above taking the
// rows, as acme's window dragged by its button does. With no rule
@@ -264,29 +271,29 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme
}
// Every pane's rows as laid out; only the placed panes' are read.
var heights: [MAX_PANES]u16 = undefined;
- for (&heights, p.rects) |*h, r| h.* = r.h;
- if (p.cols[src.col].n > span_end - src.idx) {
- const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[span_end];
+ for (&heights, v.rects) |*h, r| h.* = r.h;
+ if (v.cols[src.col].n > span_end - src.idx) {
+ const sib = if (src.idx > 0) v.cols[src.col].panes[src.idx - 1] else v.cols[src.col].panes[span_end];
heights[sib] +|= span_h;
}
var y: u16 = p.topBarHeight() + columnBarHeight(p);
- if (p.cols[tc].n == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 };
+ if (v.cols[tc].n == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 };
var last: ?MovePlacement = null;
var k: usize = 0;
- while (k < p.cols[tc].n) {
+ while (k < v.cols[tc].n) {
if (tc == src.col and k >= src.idx and k < span_end) {
k += 1;
continue;
}
// Its own group's panes are places of their own: that is how an
// attachment's grip resizes it against its owner.
- const unit_end = if (groupRoot(p, p.cols[tc].panes[k]) == own_root) k + 1 else groupEnd(p, tc, k);
+ const unit_end = if (groupRoot(p, v.cols[tc].panes[k]) == own_root) k + 1 else groupEnd(p, tc, k);
var h: u16 = 0;
for (k..unit_end) |j| {
if (tc == src.col and j >= src.idx and j < span_end) continue;
- h +|= heights[p.cols[tc].panes[j]];
+ h +|= heights[v.cols[tc].panes[j]];
}
- const above = p.cols[tc].panes[unit_end - 1];
+ const above = v.cols[tc].panes[unit_end - 1];
k = unit_end;
const row = splitRowFor(y, h, cur_y, if (tc == src.col) BOX_H else null) orelse {
y +|= h;
@@ -309,6 +316,7 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme
/// Move pane `id`, and the group it owns, where movePlacement says. An
/// attachment moved anywhere but within its own group is detached there.
pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void {
+ const v = p.view();
const placement = movePlacement(p, id, cur_x, cur_y) orelse return;
const src = findPane(p, id) orelse return;
const owner = ownerOf(p, id);
@@ -316,15 +324,15 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void {
const span_end = if (owner == null) groupEnd(p, src.col, src.idx) else src.idx + 1;
const count = span_end - src.idx;
var moved: [MAX_PANES]usize = undefined;
- @memcpy(moved[0..count], p.cols[src.col].panes[src.idx..span_end]);
- const source_multi = p.cols[src.col].n > count;
+ @memcpy(moved[0..count], v.cols[src.col].panes[src.idx..span_end]);
+ const source_multi = v.cols[src.col].n > count;
var heights: [MAX_PANES]u16 = undefined;
- for (&heights, p.rects) |*h, r| h.* = r.h;
+ for (&heights, v.rects) |*h, r| h.* = r.h;
var span_h: u16 = 0;
for (moved[0..count]) |m| span_h +|= heights[m];
for (moved[0..count]) |m| removePane(p, m);
if (source_multi) {
- const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[src.idx];
+ const sib = if (src.idx > 0) v.cols[src.col].panes[src.idx - 1] else v.cols[src.col].panes[src.idx];
heights[sib] +|= span_h;
}
const above = placement.above_id orelse {
@@ -364,9 +372,9 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void {
}
pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16) void {
- if (col >= p.ncol) return;
- for (0..p.cols[col].n) |k| {
- const pid = p.cols[col].panes[k];
+ if (col >= p.view().ncol) return;
+ for (0..p.view().cols[col].n) |k| {
+ const pid = p.view().cols[col].panes[k];
if (p.panes[pid]) |pane| if (!pane.collapsed) {
pane.vweight = @floatFromInt(@max(1, heights[pid]));
};
@@ -376,12 +384,13 @@ pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16)
/// Give a newly opened report enough rows to read, borrowing only space
/// above the other panes' usable minima. Keep their tags and bodies visible.
pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void {
+ const v = p.view();
const at = findPane(p, id) orelse return;
compute(p);
var heights: [MAX_PANES]u16 = @splat(0);
- for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| heights[other] = p.rects[other].h;
+ for (v.cols[at.col].panes[0..p.view().cols[at.col].n]) |other| heights[other] = v.rects[other].h;
var missing = wanted -| heights[id];
- for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| {
+ for (v.cols[at.col].panes[0..p.view().cols[at.col].n]) |other| {
if (other == id or p.panes[other].?.collapsed) continue;
const body_rows: u16 = if (other == context) 6 else 3;
const minimum = @max(minRows(p, other), p.panes[other].?.tag_rows + body_rows);
@@ -396,17 +405,18 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void {
}
pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void {
- if (k + 1 >= p.cols[cc].n) return;
- const a = p.panes[p.cols[cc].panes[k]] orelse return;
- const b = p.panes[p.cols[cc].panes[k + 1]] orelse return;
- const ra = p.rects[p.cols[cc].panes[k]];
- const rb = p.rects[p.cols[cc].panes[k + 1]];
+ const v = p.view();
+ if (k + 1 >= v.cols[cc].n) return;
+ const a = p.panes[v.cols[cc].panes[k]] orelse return;
+ const b = p.panes[v.cols[cc].panes[k + 1]] orelse return;
+ const ra = v.rects[v.cols[cc].panes[k]];
+ const rb = v.rects[v.cols[cc].panes[k + 1]];
const combined: f32 = @floatFromInt(ra.h + rb.h);
var nt: f32 = @floatFromInt((cur_y + 1) -| ra.y);
// A terminal keeps its tag and two body rows (floorRows); a text pane
// gives up all but its tag, as acme's do.
- const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k])));
- const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k + 1]))));
+ const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, v.cols[cc].panes[k])));
+ const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, v.cols[cc].panes[k + 1]))));
nt = std.math.clamp(nt, @min(lo, @max(@as(f32, BOX_H), hi)), @max(@as(f32, BOX_H), hi));
if (combined <= 0) return;
// Dragging a folded tag open is an explicit resize, so switch this pair
@@ -425,30 +435,32 @@ pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void {
}
pub fn findPane(p: *const Pardes, id: usize) ?struct { col: usize, idx: usize } {
- for (0..p.ncol) |c| {
- for (0..p.cols[c].n) |k| {
- if (p.cols[c].panes[k] == id) return .{ .col = c, .idx = k };
+ for (0..p.view().ncol) |c| {
+ for (0..p.view().cols[c].n) |k| {
+ if (p.view().cols[c].panes[k] == id) return .{ .col = c, .idx = k };
}
}
return null;
}
pub fn insert(p: *Pardes, c: usize, idx: usize, id: usize) void {
- var k = p.cols[c].n;
- while (k > idx) : (k -= 1) p.cols[c].panes[k] = p.cols[c].panes[k - 1];
- p.cols[c].panes[idx] = id;
- p.cols[c].n += 1;
+ const v = p.view();
+ var k = v.cols[c].n;
+ while (k > idx) : (k -= 1) v.cols[c].panes[k] = v.cols[c].panes[k - 1];
+ v.cols[c].panes[idx] = id;
+ v.cols[c].n += 1;
}
/// Take a pane out of its column. The column stays, empty if this was its
/// last pane, as acme's colclose leaves it (cols.c:186): only Delcol and
/// Joincol take a column away.
pub fn removePane(p: *Pardes, id: usize) void {
+ const v = p.view();
const f = findPane(p, id) orelse return;
const c = f.col;
var k = f.idx;
- while (k + 1 < p.cols[c].n) : (k += 1) p.cols[c].panes[k] = p.cols[c].panes[k + 1];
- p.cols[c].n -= 1;
+ while (k + 1 < v.cols[c].n) : (k += 1) v.cols[c].panes[k] = v.cols[c].panes[k + 1];
+ v.cols[c].n -= 1;
}
/// Close column `c` once its panes are gone, its width to the one left of
@@ -461,19 +473,20 @@ pub fn dropColumn(p: *Pardes, c: usize) void {
/// dropColumn with no `delcol`, for a column never announced.
pub fn dropColumnUnannounced(p: *Pardes, c: usize) void {
- std.debug.assert(p.cols[c].n == 0);
+ const v = p.view();
+ std.debug.assert(v.cols[c].n == 0);
tagline.exitHeader(p);
- const heir: ?usize = if (p.ncol <= 1) null else if (c > 0) c - 1 else c + 1;
- if (heir) |h| p.cols[h].weight +|= p.cols[c].weight;
- p.col_tags[c].deinit(p.gpa);
+ const heir: ?usize = if (v.ncol <= 1) null else if (c > 0) c - 1 else c + 1;
+ if (heir) |h| v.cols[h].weight +|= v.cols[c].weight;
+ v.col_tags[c].deinit(p.gpa);
var j = c;
- while (j + 1 < p.ncol) : (j += 1) {
- p.cols[j] = p.cols[j + 1];
- p.col_tags[j] = p.col_tags[j + 1];
+ while (j + 1 < v.ncol) : (j += 1) {
+ v.cols[j] = v.cols[j + 1];
+ v.col_tags[j] = v.col_tags[j + 1];
}
- p.ncol -= 1;
- p.col_tags[p.ncol] = .{ .what = .column, .gpa = p.gpa };
- p.cols[p.ncol].serial = 0;
+ v.ncol -= 1;
+ v.col_tags[v.ncol] = .{ .what = .column, .gpa = p.gpa };
+ v.cols[v.ncol].serial = 0;
}
/// `newcol <serial>` or `delcol <serial>` in the log: the column's serial,
@@ -485,7 +498,7 @@ pub fn noteColumn(p: *Pardes, what: []const u8, serial: u32) void {
/// Fold column `c` into the one on its right, its panes below theirs.
pub fn joinCol(p: *Pardes, c: usize) void {
- if (c + 1 >= p.ncol) return;
+ if (c + 1 >= p.view().ncol) return;
const dst = c + 1;
joinPanes(p, c, dst);
dropColumn(p, c);
@@ -495,24 +508,26 @@ pub fn joinCol(p: *Pardes, c: usize) void {
/// its tag and 2 rows (minimaFit), tried in place and undone: nothing is
/// dropped or logged for a join that does not fit.
pub fn joinFits(p: *Pardes, c: usize) bool {
- if (c + 1 >= p.ncol) return true;
+ const v = p.view();
+ if (c + 1 >= v.ncol) return true;
const dst = c + 1;
- const kept = .{ p.cols[c], p.cols[dst] };
+ const kept = .{ v.cols[c], v.cols[dst] };
joinPanes(p, c, dst);
const fits = minimaFit(p);
- p.cols[c] = kept[0];
- p.cols[dst] = kept[1];
+ v.cols[c] = kept[0];
+ v.cols[dst] = kept[1];
compute(p);
return fits;
}
fn joinPanes(p: *Pardes, c: usize, dst: usize) void {
- for (0..p.cols[c].n) |k| p.cols[dst].panes[p.cols[dst].n + k] = p.cols[c].panes[k];
- p.cols[dst].n += p.cols[c].n;
- p.cols[c].n = 0;
+ const v = p.view();
+ for (0..p.view().cols[c].n) |k| v.cols[dst].panes[v.cols[dst].n + k] = v.cols[c].panes[k];
+ v.cols[dst].n += v.cols[c].n;
+ v.cols[c].n = 0;
// The width goes right, where the panes went.
- p.cols[dst].weight +|= p.cols[c].weight;
- p.cols[c].weight = 0;
+ v.cols[dst].weight +|= v.cols[c].weight;
+ v.cols[c].weight = 0;
}
/// Put new pane `id` in column `c` as acme's makenewwindow does
@@ -524,7 +539,7 @@ fn joinPanes(p: *Pardes, c: usize, dst: usize) void {
/// that is in the column and not much smaller.
pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void {
compute(p);
- const n = p.cols[c].n;
+ const n = p.view().cols[c].n;
if (n == 0) {
insert(p, c, 0, id);
p.panes[id].?.vweight = 1;
@@ -532,7 +547,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void {
}
var big: ?usize = null;
var empty: ?usize = null;
- for (p.cols[c].panes[0..n]) |k| {
+ for (p.view().cols[c].panes[0..n]) |k| {
const pane = p.panes[k] orelse continue;
// An attachment is its owner's: never halved for another pane.
if (pane.collapsed or ownerOf(p, k) != null) continue;
@@ -548,7 +563,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void {
const y: u16 = y: {
const o = origin orelse {
var last = v0;
- for (p.cols[c].panes[0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) {
+ for (p.view().cols[c].panes[0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) {
last = k;
};
break :y bodyFrom(p, last) + bodyRows(p, last) / 2;
@@ -560,8 +575,8 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void {
// Asked from a results pane, it is its owner that is split.
const root = groupRoot(p, o);
const mine = if (findPane(p, root)) |f| f.col == c and !p.panes[root].?.collapsed else false;
- const v = if (mine and @as(u32, p.rects[root].h) * 3 > @as(u32, p.rects[v0].h) * 2) root else v0;
- break :y p.rects[v].y + p.rects[v].h / 2;
+ const v = if (mine and @as(u32, p.view().rects[root].h) * 3 > @as(u32, p.view().rects[v0].h) * 2) root else v0;
+ break :y p.view().rects[v].y + p.view().rects[v].h / 2;
};
splitAt(p, c, id, y);
}
@@ -581,12 +596,13 @@ pub fn minRows(p: *Pardes, id: usize) u16 {
/// the weights happen to share the rows, so a size that fits keeps fitting
/// when it grows. One pane alone in its column always fits.
pub fn minimaFit(p: *Pardes) bool {
+ const v = p.view();
compute(p);
- const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p));
- for (0..p.ncol) |c| {
- if (p.cols[c].n < 2) continue;
+ const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p));
+ for (0..p.view().ncol) |c| {
+ if (v.cols[c].n < 2) continue;
var need: u32 = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |k| {
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |k| {
const pane = p.panes[k] orelse continue;
need += if (pane.collapsed) BOX_H else minRows(p, k);
}
@@ -598,11 +614,12 @@ pub fn minimaFit(p: *Pardes) bool {
/// Whether every unfolded pane of column `c` has its `minRows` (a pane
/// alone in its column always does).
pub fn columnAtMinimums(p: *Pardes, c: usize) bool {
+ const v = p.view();
compute(p);
- if (p.cols[c].n < 2) return true;
- for (p.cols[c].panes[0..p.cols[c].n]) |k| {
+ if (v.cols[c].n < 2) return true;
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |k| {
const pane = p.panes[k] orelse continue;
- if (!pane.collapsed and p.rects[k].h < minRows(p, k)) return false;
+ if (!pane.collapsed and v.rects[k].h < minRows(p, k)) return false;
}
return true;
}
@@ -611,16 +628,17 @@ pub fn columnAtMinimums(p: *Pardes, c: usize) bool {
/// `minRows`, as evenly as that allows; false, changing nothing, when the
/// column has not the rows for all of them (or holds a folded pane).
pub fn shareColumn(p: *Pardes, c: usize) bool {
+ const v = p.view();
compute(p);
- const n = p.cols[c].n;
+ const n = v.cols[c].n;
if (n == 0) return false;
- const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p));
+ const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p));
var mins: [MAX_PANES]u16 = undefined;
var need: u32 = 0;
- for (p.cols[c].panes[0..n], 0..) |k, i| {
+ for (v.cols[c].panes[0..n], 0..) |k, i| {
const pane = p.panes[k] orelse return false;
if (pane.collapsed) return false;
- p.rects[k].w = p.col_w[c];
+ v.rects[k].w = v.col_w[c];
mins[i] = minRows(p, k);
need += mins[i];
}
@@ -636,7 +654,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool {
};
hs[low] += 1;
}
- for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]);
+ for (v.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]);
compute(p);
return true;
}
@@ -646,7 +664,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool {
pub fn minima(p: *Pardes) [MAX_PANES]u16 {
compute(p);
var mins: [MAX_PANES]u16 = @splat(0);
- for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |k| {
+ for (0..p.view().ncol) |c| for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| {
mins[k] = minRows(p, k);
};
return mins;
@@ -659,22 +677,23 @@ pub fn minima(p: *Pardes) [MAX_PANES]u16 {
/// minimum before the step (its tag may wrap onto more rows since): one
/// that had that minimum is lifted to its minimum now.
pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void {
+ const v = p.view();
compute(p);
- for (0..p.ncol) |c| {
- const n = p.cols[c].n;
+ for (0..p.view().ncol) |c| {
+ const n = v.cols[c].n;
if (n < 2) continue;
var hs: [MAX_PANES]u16 = undefined;
var mins: [MAX_PANES]u16 = undefined;
var short = false;
- for (p.cols[c].panes[0..n], 0..) |k, i| {
+ for (v.cols[c].panes[0..n], 0..) |k, i| {
const pane = p.panes[k] orelse return;
if (pane.collapsed) break;
- hs[i] = p.rects[k].h;
+ hs[i] = v.rects[k].h;
mins[i] = minRows(p, k);
if (hs[i] < mins[i] and before[k].h >= if (before_min) |bm| bm[k] else mins[i]) short = true;
} else {
if (!short) continue;
- for (p.cols[c].panes[0..n], 0..) |k, i| {
+ for (v.cols[c].panes[0..n], 0..) |k, i| {
if (hs[i] >= mins[i] or before[k].h < if (before_min) |bm| bm[k] else mins[i]) continue;
while (hs[i] < mins[i]) {
var giver: ?usize = null;
@@ -688,7 +707,7 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min:
hs[i] += 1;
}
}
- for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i]));
+ for (v.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i]));
}
}
compute(p);
@@ -702,13 +721,14 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min:
/// where that is not enough. False, `c` dropped unannounced, where nothing
/// holds every minimum, as a size too small is refused.
pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool {
+ const v = p.view();
restoreMinimaFrom(p, before, before_min);
- for (0..p.ncol) |k| {
+ for (0..p.view().ncol) |k| {
compute(p);
- if (p.cols[k].n < 2) continue;
- const squeezed = for (p.cols[k].panes[0..p.cols[k].n]) |id| {
+ if (v.cols[k].n < 2) continue;
+ const squeezed = for (v.cols[k].panes[0..p.view().cols[k].n]) |id| {
const pane = p.panes[id] orelse continue;
- if (!pane.collapsed and p.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true;
+ if (!pane.collapsed and v.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true;
} else false;
if (squeezed and !shareColumn(p, k)) {
dropColumnUnannounced(p, c);
@@ -723,17 +743,18 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m
/// dragged short keeps its rows and the others give only what they must.
/// False, changing nothing, when the column has not the rows.
pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool {
+ const v = p.view();
compute(p);
- const n = p.cols[c].n;
- p.rects[id].w = p.col_w[c];
+ const n = v.cols[c].n;
+ v.rects[id].w = v.col_w[c];
var need = minRows(p, id);
var hs: [MAX_PANES]u16 = undefined;
var mins: [MAX_PANES]u16 = undefined;
var spare: u32 = 0;
- for (p.cols[c].panes[0..n], 0..) |k, i| {
+ for (v.cols[c].panes[0..n], 0..) |k, i| {
const pane = p.panes[k] orelse return false;
if (pane.collapsed) return false;
- hs[i] = p.rects[k].h;
+ hs[i] = v.rects[k].h;
mins[i] = minRows(p, k);
spare += hs[i] -| mins[i];
}
@@ -745,7 +766,7 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool {
};
hs[giver] -= 1;
}
- for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i]));
+ for (v.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i]));
insert(p, c, n, id);
p.panes[id].?.vweight = @floatFromInt(minRows(p, id));
compute(p);
@@ -757,14 +778,15 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool {
/// the rects as they were). A pane alone in its column always has room: the
/// window can be no taller.
pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool {
+ const v = p.view();
compute(p);
const f = findPane(p, id) orelse return true;
- if (p.cols[f.col].n == 1) return true;
- for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| {
+ if (v.cols[f.col].n == 1) return true;
+ for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| {
const pane = p.panes[k] orelse continue;
if (pane.collapsed) continue;
- if (k != id and p.rects[k].h >= before[k].h) continue;
- if (p.rects[k].h < minRows(p, k)) return false;
+ if (k != id and v.rects[k].h >= before[k].h) continue;
+ if (v.rects[k].h < minRows(p, k)) return false;
}
return true;
}
@@ -775,17 +797,17 @@ pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool {
pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool {
compute(p);
var tall: ?usize = null;
- for (p.cols[c].panes[0..p.cols[c].n]) |k| {
+ for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| {
if (k == id or p.panes[k].?.collapsed or ownerOf(p, k) != null) continue;
- if (tall == null or p.rects[k].h > p.rects[tall.?].h) tall = k;
+ if (tall == null or p.view().rects[k].h > p.view().rects[tall.?].h) tall = k;
}
const v = tall orelse return false;
- const h = p.rects[v].h;
+ const h = p.view().rects[v].h;
// Its tag wraps at the column's width: measured there, not at none.
- p.rects[id].w = p.col_w[c];
+ p.view().rects[id].w = p.view().col_w[c];
if (h < minRows(p, v) + minRows(p, id)) return false;
snapColWeights(p, c);
- insert(p, c, p.cols[c].n, id);
+ insert(p, c, p.view().cols[c].n, id);
const given = std.math.clamp(h / 2, minRows(p, id), h - minRows(p, v));
p.panes[v].?.vweight = @floatFromInt(h - given);
p.panes[id].?.vweight = @floatFromInt(given);
@@ -798,11 +820,11 @@ pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool {
/// `y` in a group: the new pane goes under all of it, its rows from the
/// group's owner, so nothing lands between a pane and its results.
fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void {
- const n = p.cols[c].n;
+ const n = p.view().cols[c].n;
var k: usize = 0;
- while (k + 1 < n and y >= p.rects[p.cols[c].panes[k]].y + p.rects[p.cols[c].panes[k]].h) k += 1;
- const v = groupRoot(p, p.cols[c].panes[k]);
- const r = p.rects[v];
+ while (k + 1 < n and y >= p.view().rects[p.view().cols[c].panes[k]].y + p.view().rects[p.view().cols[c].panes[k]].h) k += 1;
+ const v = groupRoot(p, p.view().cols[c].panes[k]);
+ const r = p.view().rects[v];
snapColWeights(p, c);
insert(p, c, groupEnd(p, c, k), id);
const pane = p.panes[id].?;
@@ -821,11 +843,11 @@ fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void {
/// A pane's top plus its tag's rows, as heights go: a split this far down
/// leaves the pane its tag and that much of its body.
fn bodyFrom(p: *const Pardes, id: usize) u16 {
- return p.rects[id].y + p.panes[id].?.tag_rows;
+ return p.view().rects[id].y + p.panes[id].?.tag_rows;
}
fn bodyRows(p: *const Pardes, id: usize) u16 {
- return p.rects[id].h -| p.panes[id].?.tag_rows;
+ return p.view().rects[id].h -| p.panes[id].?.tag_rows;
}
/// The rows at the bottom of a pane's body that show nothing: acme's
@@ -846,15 +868,16 @@ fn blankRows(p: *const Pardes, id: usize) u16 {
/// Whether column `col` has the width and the weight to halve for a new
/// column beside it.
pub fn canSplitCol(p: *Pardes, col: usize) bool {
- if (p.ncol >= MAX_COLS or col >= p.ncol) return false;
+ const v = p.view();
+ if (v.ncol >= MAX_COLS or col >= v.ncol) return false;
// Refresh derived widths: public layout surgery may be chained between
// syncs, and a cached width must never admit a now-too-narrow split.
compute(p);
- if (p.col_w[col] < config.MINW * 2) return false;
+ if (v.col_w[col] < config.MINW * 2) return false;
- const weight = p.cols[col].weight;
+ const weight = v.cols[col].weight;
if (weight >= 2 and weight % 2 == 0) return true;
- for (0..p.ncol) |column| if (p.cols[column].weight > std.math.maxInt(u64) / 2)
+ for (0..p.view().ncol) |column| if (v.cols[column].weight > std.math.maxInt(u64) / 2)
return false;
return weight > 0;
}
@@ -864,10 +887,11 @@ pub fn canSplitCol(p: *Pardes, col: usize) bool {
/// A window with no column left (Delcol took the last, as acme lets it):
/// its first one, empty; null when it has columns.
pub fn firstColumn(p: *Pardes) ?usize {
- if (p.ncol != 0) return null;
- p.cols[0] = .{ .weight = 2 };
- p.col_tags[0] = .{ .what = .column, .gpa = p.gpa };
- p.ncol = 1;
+ const v = p.view();
+ if (v.ncol != 0) return null;
+ v.cols[0] = .{ .weight = 2 };
+ v.col_tags[0] = .{ .what = .column, .gpa = p.gpa };
+ v.ncol = 1;
noteColumn(p, "newcol", columnSerial(p, 0));
return 0;
}
@@ -881,24 +905,25 @@ pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize {
/// insertColumn with no serial given and no `newcol`: a column that may
/// yet be taken back (Newcol's trial), which then leaves no trace.
pub fn insertColumnUnannounced(p: *Pardes, col: usize, before: bool) ?usize {
+ const v = p.view();
if (!canSplitCol(p, col)) return null;
- var old_weight = p.cols[col].weight;
+ var old_weight = v.cols[col].weight;
if (old_weight < 2 or old_weight % 2 != 0) {
old_weight *= 2;
- for (0..p.ncol) |column| p.cols[column].weight *= 2;
+ for (0..p.view().ncol) |column| v.cols[column].weight *= 2;
}
const source_weight = old_weight / 2;
- p.cols[col].weight = source_weight;
+ v.cols[col].weight = source_weight;
const c = col + @intFromBool(!before);
tagline.exitHeader(p);
- var j = p.ncol;
+ var j = v.ncol;
while (j > c) : (j -= 1) {
- p.cols[j] = p.cols[j - 1];
- p.col_tags[j] = p.col_tags[j - 1];
+ v.cols[j] = v.cols[j - 1];
+ v.col_tags[j] = v.col_tags[j - 1];
}
- p.cols[c] = .{ .weight = old_weight - source_weight };
- p.col_tags[c] = .{ .what = .column, .gpa = p.gpa };
- p.ncol += 1;
+ v.cols[c] = .{ .weight = old_weight - source_weight };
+ v.col_tags[c] = .{ .what = .column, .gpa = p.gpa };
+ v.ncol += 1;
return c;
}
@@ -910,7 +935,7 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool {
const source = findPane(p, source_id) orelse return false;
if (!canSplitCol(p, source.col)) return false;
if (id == source_id) {
- if (p.cols[source.col].n <= 1) return false;
+ if (p.view().cols[source.col].n <= 1) return false;
_ = absorbVWeight(p, id, null);
removePane(p, id);
} else if (findPane(p, id) != null) return false;
@@ -920,10 +945,10 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool {
}
pub fn snapColWeights(p: *Pardes, c: usize) void {
- for (0..p.cols[c].n) |k| {
- const pid = p.cols[c].panes[k];
+ for (0..p.view().cols[c].n) |k| {
+ const pid = p.view().cols[c].panes[k];
if (p.panes[pid]) |pp| if (!pp.collapsed) {
- pp.vweight = @floatFromInt(@max(1, p.rects[pid].h));
+ pp.vweight = @floatFromInt(@max(1, p.view().rects[pid].h));
};
}
}
@@ -934,27 +959,28 @@ pub fn snapColWeights(p: *Pardes, c: usize) void {
/// Give a closing pane's rows to `to`, or to the nearest document above it
/// (the pane below for the top one); the pane that got them is returned.
pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) ?usize {
+ const v = p.view();
const f = findPane(p, id) orelse return null;
- if (p.cols[f.col].n <= 1) return null;
+ if (v.cols[f.col].n <= 1) return null;
// A refused pane held no weight: the rows the others' rounding lent it
// go back to them as they were, nobody's weight snapped.
if (p.panes[id]) |pane| if (!pane.collapsed and pane.vweight == 0) return null;
snapColWeights(p, f.col);
- var sib = to orelse if (f.idx > 0) p.cols[f.col].panes[f.idx - 1] else p.cols[f.col].panes[f.idx + 1];
+ var sib = to orelse if (f.idx > 0) v.cols[f.col].panes[f.idx - 1] else v.cols[f.col].panes[f.idx + 1];
var k = f.idx;
while (to == null and k > 0) : (k -= 1) {
- sib = p.cols[f.col].panes[k - 1];
+ sib = v.cols[f.col].panes[k - 1];
// nor to a pane attached to another: rows go to owners
if (p.panes[sib]) |pp| if (if (pp.file) |ff| panes.Output.fileTraits(ff.output).doc else true) if (ownerOf(p, sib) == null) break;
}
const s = p.panes[sib] orelse return null;
- s.vweight += @as(f32, @floatFromInt(@max(1, p.rects[id].h)));
+ s.vweight += @as(f32, @floatFromInt(@max(1, v.rects[id].h)));
return sib;
}
pub fn splitBelow(p: *Pardes, src_id: usize, nw: *Pane) void {
const src = p.panes[src_id] orelse return;
- const src_h = p.rects[src_id].h;
+ const src_h = p.view().rects[src_id].h;
// Its tag may wrap to more than one row: the rows under it are its body.
const tag_h = @max(BOX_H, src.tag_rows);
const body: u16 = if (src_h > tag_h) src_h - tag_h else 1;
@@ -1020,9 +1046,10 @@ fn descends(p: *const Pardes, id: usize, root: usize) bool {
/// One past the last pane of the group that pane `idx` of column `c` is
/// in: `idx + 1` for a pane with nothing attached.
pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize {
- const root = groupRoot(p, p.cols[c].panes[idx]);
+ const v = p.view();
+ const root = groupRoot(p, v.cols[c].panes[idx]);
var k = idx + 1;
- while (k < p.cols[c].n and descends(p, p.cols[c].panes[k], root) and p.cols[c].panes[k] != root) k += 1;
+ while (k < v.cols[c].n and descends(p, v.cols[c].panes[k], root) and v.cols[c].panes[k] != root) k += 1;
return k;
}
@@ -1033,10 +1060,10 @@ pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize {
/// it stands. Nothing moves. Top to bottom, so a nested attachment is
/// judged after the one it hangs from.
pub fn keepGroups(p: *Pardes) void {
- for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n], 0..) |id, k| {
+ for (0..p.view().ncol) |c| for (p.view().cols[c].panes[0..p.view().cols[c].n], 0..) |id, k| {
const pane = p.panes[id] orelse continue;
if (pane.attached_to == null) continue;
- const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.cols[c].panes[k - 1], owner) else false;
+ const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.view().cols[c].panes[k - 1], owner) else false;
if (kept) continue;
pane.attached_to = null;
};
@@ -1053,6 +1080,7 @@ pub fn keepGroups(p: *Pardes) void {
/// itself or a pane of its group (a +Preview added under a query pane later
/// takes the text's rows, so the query pane, typed into, keeps its own).
pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize) bool {
+ const v = p.view();
const o = p.panes[owner] orelse return false;
const g = p.panes[giver] orelse return false;
const nw = p.panes[id] orelse return false;
@@ -1062,8 +1090,8 @@ pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize)
const f = findPane(p, owner) orelse return false;
if (giver != owner and groupRoot(p, owner) != groupRoot(p, giver)) return false;
// Its tag wraps at the column's width: measured there.
- p.rects[id].w = p.col_w[f.col];
- const oh = p.rects[giver].h;
+ v.rects[id].w = v.col_w[f.col];
+ const oh = v.rects[giver].h;
const least = minRows(p, id);
if (oh < least + BOX_H) return false;
const giver_keeps = if (oh >= least + minRows(p, giver)) minRows(p, giver) else BOX_H;
@@ -1083,14 +1111,15 @@ pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize)
/// so no other pane moves. False when the gainer is folded or too short
/// to give a pane its minimum and keep its own.
pub fn giveBack(p: *Pardes, id: usize, gainer: usize, below: bool, rows: u16) bool {
+ const v = p.view();
const g = p.panes[gainer] orelse return false;
const nw = p.panes[id] orelse return false;
if (g.collapsed) return false;
compute(p);
const f = findPane(p, gainer) orelse return false;
// Its tag wraps at the column's width: measured there.
- p.rects[id].w = p.col_w[f.col];
- const gh = p.rects[gainer].h;
+ v.rects[id].w = v.col_w[f.col];
+ const gh = v.rects[gainer].h;
const least = minRows(p, id);
const keeps = minRows(p, gainer);
if (gh < least + keeps) return false;
@@ -1109,16 +1138,17 @@ pub fn giveBack(p: *Pardes, id: usize, gainer: usize, below: bool, rows: u16) bo
/// ponytail: unfolding opens every attachment, one folded alone before
/// included; remembering which were is a bit a pane.
fn collapseGroup(p: *Pardes, c: usize, start: usize, end: usize) void {
- const root = p.panes[p.cols[c].panes[start]].?;
+ const v = p.view();
+ const root = p.panes[v.cols[c].panes[start]].?;
const folding = !root.collapsed;
snapColWeights(p, c);
const neighbor = expandedNeighbor(p, c, start, .above) orelse expandedNeighbor(p, c, end - 1, .below);
- var spare: u16 = if (neighbor) |other| p.rects[other].h -| BOX_H else 0;
- for (p.cols[c].panes[start..end]) |k| {
+ var spare: u16 = if (neighbor) |other| v.rects[other].h -| BOX_H else 0;
+ for (v.cols[c].panes[start..end]) |k| {
const pane = p.panes[k] orelse continue;
if (folding) {
if (pane.collapsed) continue;
- const h = p.rects[k].h;
+ const h = v.rects[k].h;
pane.vweight = @floatFromInt(@max(1, h));
pane.collapsed = true;
if (neighbor) |other| p.panes[other].?.vweight += @floatFromInt(h -| BOX_H);
@@ -1151,7 +1181,7 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void {
if (end > at.idx + 1) return collapseGroup(p, at.col, at.idx, end);
}
const was_collapsed = pane.collapsed;
- const old_height = p.rects[id].h;
+ const old_height = p.view().rects[id].h;
const remembered_height = pane.vweight;
// Convert only visible panes to row weights. The toggle then changes one
// pair, rather than letting the column redistribute the released space.
@@ -1160,7 +1190,7 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void {
if (was_collapsed) {
if (neighbor) |other| {
const wanted: u16 = @intFromFloat(@min(@as(f32, @floatFromInt(std.math.maxInt(u16))), @max(1, @round(remembered_height))));
- const give = @min(wanted -| old_height, p.rects[other].h -| BOX_H);
+ const give = @min(wanted -| old_height, p.view().rects[other].h -| BOX_H);
p.panes[other].?.vweight -= @floatFromInt(give);
pane.vweight = @floatFromInt(@max(1, old_height + give));
}
@@ -1182,20 +1212,21 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void {
/// would spread over the whole column instead.
pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum { above, below }) ?usize {
var k = index;
- while (if (side == .above) k > 0 else k + 1 < p.cols[col].n) {
+ while (if (side == .above) k > 0 else k + 1 < p.view().cols[col].n) {
k = if (side == .above) k - 1 else k + 1;
- const id = p.cols[col].panes[k];
+ const id = p.view().cols[col].panes[k];
if (p.panes[id]) |pane| if (!pane.collapsed) return id;
}
return null;
}
fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usize) void {
+ const v = p.view();
var y: u16 = p.topBarHeight() + columnBarHeight(p);
- const available = p.screen_h -| y;
+ const available = v.screen_h -| y;
var expanded_left: usize = 0;
var weight: f32 = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| {
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| {
if (!pane.collapsed) {
expanded_left += 1;
weight += pane.vweight;
@@ -1204,9 +1235,9 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz
const expanded_height = available -| @as(u16, @intCast(folded));
var budget = expanded_height;
var folded_left = folded;
- for (p.cols[c].panes[0..p.cols[c].n]) |id| {
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |id| {
const pane = p.panes[id] orelse continue;
- const room = p.screen_h -| y;
+ const room = v.screen_h -| y;
const height: u16 = if (pane.collapsed) blk: {
folded_left -= 1;
break :blk @min(room, BOX_H);
@@ -1218,32 +1249,33 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz
budget -|= h;
break :blk h;
};
- p.rects[id] = .{ .x = x, .y = y, .w = width, .h = height };
+ v.rects[id] = .{ .x = x, .y = y, .w = width, .h = height };
y +|= height;
}
}
pub fn compute(p: *Pardes) void {
- p.rects = @splat(.{});
- if (p.ncol == 0) return;
+ const v = p.view();
+ v.rects = @splat(.{});
+ if (v.ncol == 0) return;
keepGroups(p);
- for (0..p.ncol) |column| _ = columnSerial(p, column);
+ for (0..p.view().ncol) |column| _ = columnSerial(p, column);
var wsum: u128 = 0;
- for (0..p.ncol) |c| wsum += p.cols[c].weight;
+ for (0..p.view().ncol) |c| wsum += v.cols[c].weight;
if (wsum == 0) wsum = 1;
// Round cumulative boundaries so widths still sum to the available screen.
var prefix: u128 = 0;
- for (0..p.ncol) |c| {
- const x = columnBoundary(p.screen_w, prefix, wsum);
- prefix += p.cols[c].weight;
- const end: u16 = if (c == p.ncol - 1) p.screen_w else columnBoundary(p.screen_w, prefix, wsum);
+ for (0..p.view().ncol) |c| {
+ const x = columnBoundary(v.screen_w, prefix, wsum);
+ prefix += v.cols[c].weight;
+ const end: u16 = if (c == v.ncol - 1) v.screen_w else columnBoundary(v.screen_w, prefix, wsum);
const cw = end -| x;
- p.col_x[c] = x;
- p.col_w[c] = cw;
+ v.col_x[c] = x;
+ v.col_w[c] = cw;
var folded: usize = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| {
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| {
if (pane.collapsed) folded += 1;
};
if (folded > 0) {
@@ -1252,34 +1284,34 @@ pub fn compute(p: *Pardes) void {
}
var vsum: f32 = 0;
- for (0..p.cols[c].n) |k| {
- if (p.panes[p.cols[c].panes[k]]) |pane| vsum += pane.vweight;
+ for (0..p.view().cols[c].n) |k| {
+ if (p.panes[v.cols[c].panes[k]]) |pane| vsum += pane.vweight;
}
if (vsum <= 0) vsum = 1;
var y: u16 = p.topBarHeight() + columnBarHeight(p);
const top = y;
- const avail_h = p.screen_h -| y;
+ const avail_h = v.screen_h -| y;
var hs: [MAX_PANES]u16 = undefined;
- const n = p.cols[c].n;
+ const n = v.cols[c].n;
for (0..n) |k| {
- const id = p.cols[c].panes[k];
+ const id = v.cols[c].panes[k];
const pane = p.panes[id] orelse {
hs[k] = 0;
continue;
};
const lastk = k + 1 == n;
const fh = @as(f32, @floatFromInt(avail_h)) * pane.vweight / vsum;
- const room = p.screen_h -| y;
+ const room = v.screen_h -| y;
hs[k] = if (lastk) room else @min(room, @max(1, @as(u16, @intFromFloat(@round(fh)))));
y +|= hs[k];
}
keepTerminalFloors(p, c, hs[0..n]);
y = top;
for (0..n) |k| {
- const id = p.cols[c].panes[k];
+ const id = v.cols[c].panes[k];
if (p.panes[id] == null) continue;
- p.rects[id] = .{ .x = x, .y = y, .w = cw, .h = hs[k] };
+ v.rects[id] = .{ .x = x, .y = y, .w = cw, .h = hs[k] };
y +|= hs[k];
}
}
@@ -1299,13 +1331,13 @@ fn floorRows(p: *Pardes, id: usize) u16 {
// ponytail: a row per step, O(panes x rows); a column holds few of both.
fn keepTerminalFloors(p: *Pardes, c: usize, hs: []u16) void {
for (hs, 0..) |*h, k| {
- const floor = floorRows(p, p.cols[c].panes[k]);
+ const floor = floorRows(p, p.view().cols[c].panes[k]);
while (h.* < floor) {
var giver: ?usize = null;
var spare: u16 = 0;
for (hs, 0..) |other, j| {
if (j == k) continue;
- const extra = other -| floorRows(p, p.cols[c].panes[j]);
+ const extra = other -| floorRows(p, p.view().cols[c].panes[j]);
if (extra > spare) {
spare = extra;
giver = j;
@@ -1328,18 +1360,18 @@ test "collapse transfers height upward and restores the original layout" {
p.panes[0].?.vweight = 3;
p.panes[1].?.vweight = 2;
compute(p);
- const original = p.rects;
+ const original = p.view().rects;
toggleCollapse(p, 1);
- try std.testing.expectEqual(@as(u16, 1), p.rects[1].h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h);
try std.testing.expectEqual(@as(f32, @floatFromInt(original[1].h)), p.panes[1].?.vweight);
- try std.testing.expectEqual(p.screen_h, p.rects[2].y + p.rects[2].h);
- try std.testing.expect(p.rects[0].h > original[0].h);
- try std.testing.expectEqualDeep(original[2], p.rects[2]);
+ try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h);
+ try std.testing.expect(p.view().rects[0].h > original[0].h);
+ try std.testing.expectEqualDeep(original[2], p.view().rects[2]);
toggleCollapse(p, 1);
- try std.testing.expectEqualDeep(original, p.rects);
+ try std.testing.expectEqualDeep(original, p.view().rects);
toggleCollapse(p, 2);
- try std.testing.expectEqual(@as(u16, 1), p.rects[2].h);
- try std.testing.expectEqual(p.screen_h, p.rects[2].y + p.rects[2].h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[2].h);
+ try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h);
}
test "collapse changes only one neighbor at the top middle and bottom" {
@@ -1352,16 +1384,16 @@ test "collapse changes only one neighbor at the top middle and bottom" {
}
for ([_]f32{ 11, 7, 5, 3 }, 0..) |weight, id| p.panes[id].?.vweight = weight;
compute(p);
- const original = p.rects;
+ const original = p.view().rects;
const recipient = if (target > 0) target - 1 else 1;
for (0..5) |_| {
toggleCollapse(p, target);
- try std.testing.expectEqual(@as(u16, BOX_H), p.rects[target].h);
- try std.testing.expectEqual(original[recipient].h + original[target].h - BOX_H, p.rects[recipient].h);
+ try std.testing.expectEqual(@as(u16, BOX_H), p.view().rects[target].h);
+ try std.testing.expectEqual(original[recipient].h + original[target].h - BOX_H, p.view().rects[recipient].h);
for (0..4) |id| if (id != target and id != recipient)
- try std.testing.expectEqualDeep(original[id], p.rects[id]);
+ try std.testing.expectEqualDeep(original[id], p.view().rects[id]);
toggleCollapse(p, target);
- try std.testing.expectEqualDeep(original, p.rects);
+ try std.testing.expectEqualDeep(original, p.view().rects);
}
}
}
@@ -1376,21 +1408,21 @@ test "collapse skips folded neighbors and expansion reclaims only its neighbor"
compute(p);
toggleCollapse(p, 1);
toggleCollapse(p, 2);
- const original = p.rects;
+ const original = p.view().rects;
toggleCollapse(p, 3);
- try std.testing.expectEqual(original[0].h + original[3].h - BOX_H, p.rects[0].h);
- try std.testing.expectEqualDeep(original[4], p.rects[4]);
- for (1..4) |id| try std.testing.expectEqual(@as(u16, BOX_H), p.rects[id].h);
+ try std.testing.expectEqual(original[0].h + original[3].h - BOX_H, p.view().rects[0].h);
+ try std.testing.expectEqualDeep(original[4], p.view().rects[4]);
+ for (1..4) |id| try std.testing.expectEqual(@as(u16, BOX_H), p.view().rects[id].h);
toggleCollapse(p, 3);
- try std.testing.expectEqualDeep(original, p.rects);
+ try std.testing.expectEqualDeep(original, p.view().rects);
// With no expanded pane above, give the space to the first one below.
toggleCollapse(p, 0);
- const with_folded_above = p.rects;
+ const with_folded_above = p.view().rects;
toggleCollapse(p, 3);
- try std.testing.expectEqual(with_folded_above[4].h + with_folded_above[3].h - BOX_H, p.rects[4].h);
- for (0..3) |id| try std.testing.expectEqualDeep(with_folded_above[id], p.rects[id]);
+ try std.testing.expectEqual(with_folded_above[4].h + with_folded_above[3].h - BOX_H, p.view().rects[4].h);
+ for (0..3) |id| try std.testing.expectEqualDeep(with_folded_above[id], p.view().rects[id]);
toggleCollapse(p, 3);
- try std.testing.expectEqualDeep(with_folded_above, p.rects);
+ try std.testing.expectEqualDeep(with_folded_above, p.view().rects);
}
test "collapse local transfers remain bounded through repeated tiny window resizes" {
@@ -1401,19 +1433,19 @@ test "collapse local transfers remain bounded through repeated tiny window resiz
insert(p, 0, id, id);
}
for (0..180) |step| {
- p.screen_h = @intCast((step * 17) % 81);
+ p.view().screen_h = @intCast((step * 17) % 81);
compute(p);
toggleCollapse(p, step % 5);
var used: u16 = 0;
for (0..5) |id| {
const pane = p.panes[id].?;
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
try std.testing.expect(std.math.isFinite(pane.vweight) and pane.vweight > 0);
- try std.testing.expect(rect.h <= p.screen_h -| rect.y);
+ try std.testing.expect(rect.h <= p.view().screen_h -| rect.y);
if (pane.collapsed) try std.testing.expect(rect.h <= BOX_H);
used += rect.h;
}
- try std.testing.expect(used <= p.screen_h);
+ try std.testing.expect(used <= p.view().screen_h);
}
}
@@ -1423,7 +1455,7 @@ test "collapse expansion is limited to space available in one neighbor" {
// Text panes: a terminal would keep its tag and two rows (floorRows).
for (1..4) |id| {
p.newScratchBelow(0);
- try std.testing.expectEqual(id, p.cols[0].panes[id]);
+ try std.testing.expectEqual(id, p.view().cols[0].panes[id]);
}
compute(p);
toggleCollapse(p, 2);
@@ -1432,28 +1464,28 @@ test "collapse expansion is limited to space available in one neighbor" {
p.panes[0].?.vweight += p.panes[1].?.vweight - 2;
p.panes[1].?.vweight = 2;
compute(p);
- const before = p.rects;
+ const before = p.view().rects;
toggleCollapse(p, 2);
- try std.testing.expectEqual(@as(u16, 2), p.rects[2].h);
- try std.testing.expectEqual(@as(u16, BOX_H), p.rects[1].h);
- try std.testing.expectEqualDeep(before[0], p.rects[0]);
- try std.testing.expectEqualDeep(before[3], p.rects[3]);
+ try std.testing.expectEqual(@as(u16, 2), p.view().rects[2].h);
+ try std.testing.expectEqual(@as(u16, BOX_H), p.view().rects[1].h);
+ try std.testing.expectEqualDeep(before[0], p.view().rects[0]);
+ try std.testing.expectEqualDeep(before[3], p.view().rects[3]);
}
test "collapse single and all panes leave unused column space" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 32 });
defer p.deinit();
toggleCollapse(p, 0);
- try std.testing.expectEqual(@as(u16, 1), p.rects[0].h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[0].h);
_ = try p.newShell(1, "");
insert(p, 0, 1, 1);
toggleCollapse(p, 1);
- try std.testing.expectEqual(@as(u16, 1), p.rects[0].h);
- try std.testing.expectEqual(@as(u16, 1), p.rects[1].h);
- try std.testing.expectEqual(p.rects[0].y + 1, p.rects[1].y);
- try std.testing.expect(p.rects[1].y + 1 < p.screen_h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[0].h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h);
+ try std.testing.expectEqual(p.view().rects[0].y + 1, p.view().rects[1].y);
+ try std.testing.expect(p.view().rects[1].y + 1 < p.view().screen_h);
toggleCollapse(p, 0);
- try std.testing.expectEqual(p.screen_h - 1, p.rects[1].y);
+ try std.testing.expectEqual(p.view().screen_h - 1, p.view().rects[1].y);
}
test "collapse survives tiny resizes" {
@@ -1465,20 +1497,20 @@ test "collapse survives tiny resizes" {
insert(p, 0, 2, 2);
p.panes[1].?.collapsed = true;
for (0..50) |height| {
- p.screen_h = @intCast(height);
+ p.view().screen_h = @intCast(height);
compute(p);
var used: u16 = 0;
- for (p.cols[0].panes[0..p.cols[0].n]) |id| {
- const rect = p.rects[id];
- try std.testing.expect(rect.h <= p.screen_h -| rect.y);
+ for (p.view().cols[0].panes[0..p.view().cols[0].n]) |id| {
+ const rect = p.view().rects[id];
+ try std.testing.expect(rect.h <= p.view().screen_h -| rect.y);
used += rect.h;
}
- try std.testing.expect(used <= p.screen_h);
- if (height >= 5) try std.testing.expectEqual(@as(u16, 1), p.rects[1].h);
+ try std.testing.expect(used <= p.view().screen_h);
+ if (height >= 5) try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h);
}
- p.screen_h = 32;
+ p.view().screen_h = 32;
compute(p);
- try std.testing.expectEqual(@as(u16, 1), p.rects[1].h);
+ try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h);
}
test "collapse can be expanded by dragging its boundary" {
@@ -1487,15 +1519,15 @@ test "collapse can be expanded by dragging its boundary" {
_ = try p.newShell(1, "");
insert(p, 0, 1, 1);
toggleCollapse(p, 0);
- applyRowSplit(p, 0, 0, p.rects[0].y + 5);
+ applyRowSplit(p, 0, 0, p.view().rects[0].y + 5);
compute(p);
try std.testing.expect(!p.panes[0].?.collapsed);
- try std.testing.expectEqual(@as(u16, 6), p.rects[0].h);
+ try std.testing.expectEqual(@as(u16, 6), p.view().rects[0].h);
toggleCollapse(p, 1);
- applyRowSplit(p, 0, 0, p.rects[1].y - 6);
+ applyRowSplit(p, 0, 0, p.view().rects[1].y - 6);
compute(p);
try std.testing.expect(!p.panes[1].?.collapsed);
- try std.testing.expectEqual(@as(u16, 6), p.rects[1].h);
+ try std.testing.expectEqual(@as(u16, 6), p.view().rects[1].h);
}
test "collapse dump restores folded state and retained expansion weight" {
@@ -1503,47 +1535,47 @@ test "collapse dump restores folded state and retained expansion weight" {
defer p.deinit();
p.panes[0].?.vweight = 7;
compute(p);
- const original_height = p.rects[0].h;
+ const original_height = p.view().rects[0].h;
toggleCollapse(p, 0);
try dump.dumpState(p);
const restored = try dump.initFromDump(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 32 }, p.dump_out.?);
defer restored.deinit();
try std.testing.expect(restored.panes[0].?.collapsed);
try std.testing.expectEqual(@as(f32, @floatFromInt(original_height)), restored.panes[0].?.vweight);
- try std.testing.expectEqual(@as(u16, 1), restored.rects[0].h);
+ try std.testing.expectEqual(@as(u16, 1), restored.view().rects[0].h);
toggleCollapse(restored, 0);
- try std.testing.expectEqual(restored.screen_h - restored.rects[0].y, restored.rects[0].h);
+ try std.testing.expectEqual(restored.view().screen_h - restored.view().rects[0].y, restored.view().rects[0].h);
}
test "column reorder moves only crossed state and preserves weights" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 173, .rows = 20 });
defer p.deinit();
- p.ncol = 4;
+ p.view().ncol = 4;
for (0..4) |c| {
- p.cols[c].n = 0;
- p.cols[c].weight = c * 13 + 7;
- p.cols[c].serial = @intCast(c + 10);
- p.cols[c].panes[0] = c;
- p.col_tags[c].cur_col = @intCast(c + 20);
+ p.view().cols[c].n = 0;
+ p.view().cols[c].weight = c * 13 + 7;
+ p.view().cols[c].serial = @intCast(c + 10);
+ p.view().cols[c].panes[0] = c;
+ p.view().col_tags[c].cur_col = @intCast(c + 20);
}
compute(p);
const original_weights = weightsOf(p);
- const outer_x = p.col_x[0];
- const outer_w = p.col_w[0];
- p.header = .{ .column = 1 };
- p.header_scroll = 9;
+ const outer_x = p.view().col_x[0];
+ const outer_w = p.view().col_w[0];
+ p.view().header = .{ .column = 1 };
+ p.view().header_scroll = 9;
reorderColumn(p, 1, 3);
- try std.testing.expectEqual(original_weights[1], p.cols[3].weight);
- try std.testing.expectEqual(original_weights[2], p.cols[1].weight);
- try std.testing.expectEqual(@as(u32, 11), p.cols[3].serial);
+ try std.testing.expectEqual(original_weights[1], p.view().cols[3].weight);
+ try std.testing.expectEqual(original_weights[2], p.view().cols[1].weight);
+ try std.testing.expectEqual(@as(u32, 11), p.view().cols[3].serial);
try std.testing.expectEqual(@as(?usize, 3), p.headerColumn());
try std.testing.expectEqual(@as(i32, 21), tagline.focusedHeader(p).?.cur_col);
- try std.testing.expectEqual(@as(usize, 9), p.header_scroll);
- try std.testing.expectEqual(outer_x, p.col_x[0]);
- try std.testing.expectEqual(outer_w, p.col_w[0]);
+ try std.testing.expectEqual(@as(usize, 9), p.view().header_scroll);
+ try std.testing.expectEqual(outer_x, p.view().col_x[0]);
+ try std.testing.expectEqual(outer_w, p.view().col_w[0]);
reorderColumn(p, 3, 1);
try std.testing.expectEqualSlices(u64, original_weights[0..4], weightsOf(p)[0..4]);
- try std.testing.expectEqual(@as(i32, 21), p.col_tags[1].cur_col);
+ try std.testing.expectEqual(@as(i32, 21), p.view().col_tags[1].cur_col);
}
/// A test's attachment: an empty +Search in a new slot, in no column.
@@ -1560,31 +1592,31 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves,
_ = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma\nalpha two\ndelta\nepsilon\nzeta\n");
p.newScratchBelow(0);
p.newScratchBelow(0);
- const other_col = p.cols[0].panes[2];
+ const other_col = p.view().cols[0].panes[2];
try std.testing.expect(splitColumn(p, other_col, other_col, false));
- const below = p.cols[0].panes[1];
- p.active = 0;
+ const below = p.view().cols[0].panes[1];
+ p.view().active = 0;
compute(p);
- const before = p.rects;
+ const before = p.view().rects;
const unrelated = [_]usize{ below, other_col };
// Under its owner, the rows asked for, the owner's and nobody else's.
const s = try testAttachment(p);
try std.testing.expect(attachFrom(p, 0, s, 9, 0));
try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s));
- try std.testing.expectEqual(s, p.cols[0].panes[1]);
- for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]);
- try std.testing.expectEqual(before[0].h, p.rects[0].h + p.rects[s].h);
- try std.testing.expectEqual(before[0].y, p.rects[0].y);
- try std.testing.expectEqual(@as(u16, 9), p.rects[s].h);
+ try std.testing.expectEqual(s, p.view().cols[0].panes[1]);
+ for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.view().rects[k]);
+ try std.testing.expectEqual(before[0].h, p.view().rects[0].h + p.view().rects[s].h);
+ try std.testing.expectEqual(before[0].y, p.view().rects[0].y);
+ try std.testing.expectEqual(@as(u16, 9), p.view().rects[s].h);
// A second level (a preview under a query pane): out of the first's rows.
const pv = try testAttachment(p);
try std.testing.expect(attachFrom(p, s, pv, 4, s));
- try std.testing.expectEqual(pv, p.cols[0].panes[2]);
+ try std.testing.expectEqual(pv, p.view().cols[0].panes[2]);
try std.testing.expectEqual(@as(usize, 0), groupRoot(p, pv));
try std.testing.expectEqual(@as(usize, 3), groupEnd(p, 0, 0));
- for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]);
- try std.testing.expectEqual(@as(u16, 5), p.rects[s].h);
+ for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.view().rects[k]);
+ try std.testing.expectEqual(@as(u16, 5), p.view().rects[s].h);
// Its text changing never resizes it: nothing here fits it to content.
const sf = &p.panes[s].?.file.?;
var many: [2 + 4 * 30]u8 = @splat('\n');
@@ -1592,55 +1624,55 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves,
many[0] = 'q';
panes.File.setContent(p, sf, try p.gpa.dupe(u8, &many));
compute(p);
- try std.testing.expectEqual(@as(u16, 5), p.rects[s].h);
+ try std.testing.expectEqual(@as(u16, 5), p.view().rects[s].h);
// An unrelated New, from the owner or from its attachment, never lands
// inside the group.
exec.runBuiltin(p, .New, 0, "", null);
exec.runBuiltin(p, .New, s, "", null);
var at = findPane(p, 0).?;
- try std.testing.expectEqual(s, p.cols[at.col].panes[at.idx + 1]);
- try std.testing.expectEqual(pv, p.cols[at.col].panes[at.idx + 2]);
+ try std.testing.expectEqual(s, p.view().cols[at.col].panes[at.idx + 1]);
+ try std.testing.expectEqual(pv, p.view().cols[at.col].panes[at.idx + 2]);
// The seam between owner and attachment is the user's: the pair alone.
compute(p);
- const pre_drag = p.rects;
- applyRowSplit(p, at.col, at.idx, p.rects[s].y - 3);
+ const pre_drag = p.view().rects;
+ applyRowSplit(p, at.col, at.idx, p.view().rects[s].y - 3);
compute(p);
- try std.testing.expectEqual(pre_drag[0].h + pre_drag[s].h, p.rects[0].h + p.rects[s].h);
- for (p.cols[at.col].panes[0..p.cols[at.col].n]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.rects[k]);
+ try std.testing.expectEqual(pre_drag[0].h + pre_drag[s].h, p.view().rects[0].h + p.view().rects[s].h);
+ for (p.view().cols[at.col].panes[0..p.view().cols[at.col].n]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.view().rects[k]);
// Collapse folds the group and unfolds it.
compute(p);
- const open = p.rects;
+ const open = p.view().rects;
exec.runBuiltin(p, .Collapse, 0, "", null);
try std.testing.expect(p.panes[0].?.collapsed and p.panes[s].?.collapsed and p.panes[pv].?.collapsed);
exec.runBuiltin(p, .Collapse, 0, "", null);
try std.testing.expect(!p.panes[0].?.collapsed and !p.panes[s].?.collapsed);
- try std.testing.expectEqual(open[0].h + open[s].h + open[pv].h, p.rects[0].h + p.rects[s].h + p.rects[pv].h);
+ try std.testing.expectEqual(open[0].h + open[s].h + open[pv].h, p.view().rects[0].h + p.view().rects[s].h + p.view().rects[pv].h);
// The owner's grip dragged to the other column takes its group along.
- movePane(p, 0, p.col_x[1] + 4, p.rects[other_col].y + p.rects[other_col].h / 2);
+ movePane(p, 0, p.view().col_x[1] + 4, p.view().rects[other_col].y + p.view().rects[other_col].h / 2);
at = findPane(p, 0).?;
try std.testing.expectEqual(@as(usize, 1), at.col);
- try std.testing.expectEqual(s, p.cols[1].panes[at.idx + 1]);
- try std.testing.expectEqual(pv, p.cols[1].panes[at.idx + 2]);
+ try std.testing.expectEqual(s, p.view().cols[1].panes[at.idx + 1]);
+ try std.testing.expectEqual(pv, p.view().cols[1].panes[at.idx + 2]);
try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s));
// Del of the preview gives its rows to its owner, the query pane.
compute(p);
- var pair = p.rects;
+ var pair = p.view().rects;
exec.runBuiltin(p, .Del, pv, "", null);
try std.testing.expect(p.panes[pv] == null);
compute(p);
- try std.testing.expectEqual(pair[s].h + pair[pv].h, p.rects[s].h);
+ try std.testing.expectEqual(pair[s].h + pair[pv].h, p.view().rects[s].h);
// Del of the attachment gives its rows back to the owner, nobody else.
- pair = p.rects;
+ pair = p.view().rects;
exec.runBuiltin(p, .Del, s, "", null);
try std.testing.expect(p.panes[s] == null);
compute(p);
- try std.testing.expectEqual(pair[0].h + pair[s].h, p.rects[0].h);
- for (p.cols[1].panes[0..p.cols[1].n]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.rects[k]);
+ try std.testing.expectEqual(pair[0].h + pair[s].h, p.view().rects[0].h);
+ for (p.view().cols[1].panes[0..p.view().cols[1].n]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.view().rects[k]);
// Del of the owner closes what is attached to it.
const again = try testAttachment(p);
@@ -1688,7 +1720,7 @@ pub fn topBarHeight(p: *const Pardes) u16 {
/// gives a column tag one font height); a newline in one is a space
/// (tagline.flattenHeaders).
pub fn columnBarHeight(p: *const Pardes) u16 {
- if (p.screen_h < 3) return 0;
+ if (p.view().screen_h < 3) return 0;
return COLBAR_H;
}
@@ -1701,14 +1733,14 @@ pub fn newColumn(p: *Pardes, from_id: usize) void {
// A trial: laying it out gives it a serial (layout.compute), which a
// refusal takes back. Every other column has its own already, so
// the counter as it is now is the trial's to return to.
- for (0..p.ncol) |k| _ = columnSerial(p, k);
+ for (0..p.view().ncol) |k| _ = columnSerial(p, k);
const unspent = p.next_column_serial;
const before_min = minima(p);
- const before = p.rects;
+ const before = p.view().rects;
// Said, not silently nothing: "no space" is 9ns's word for ENOSPC.
const c = insertColumnUnannounced(p, col, false) orelse {
var said: [96]u8 = undefined;
- return p.reportFailure(from_id, if (p.ncol >= MAX_COLS)
+ return p.reportFailure(from_id, if (p.view().ncol >= MAX_COLS)
std.fmt.bufPrint(&said, "Newcol: no space for a column: {d} max", .{MAX_COLS}) catch "Newcol: no space for a column"
else
"Newcol: no space for a column: this one is too narrow to split");
@@ -1724,18 +1756,18 @@ pub fn newColumn(p: *Pardes, from_id: usize) void {
}
pub fn setActiveColumn(p: *Pardes, c: usize) void {
- if (c < p.ncol) p.active_column = columnSerial(p, c);
+ if (c < p.view().ncol) p.view().active_column = columnSerial(p, c);
}
/// The active column, while it is still there.
pub fn activeColumn(p: *const Pardes) ?usize {
- return columnBySerial(p, p.active_column);
+ return columnBySerial(p, p.view().active_column);
}
pub fn noteTyped(p: *Pardes) void {
- if (p.header != null) {
+ if (p.view().header != null) {
if (p.headerColumn()) |c| p.setActiveColumn(c);
- } else if (findPane(p, p.active)) |f| p.setActiveColumn(f.col);
+ } else if (findPane(p, p.view().active)) |f| p.setActiveColumn(f.col);
}
/// New, run from column `c`'s tag.
@@ -1755,14 +1787,15 @@ pub fn keyboardColumn(p: *Pardes, id: usize) ?usize {
/// Delcol: close column `col` and every pane in it.
pub fn removeColumn(p: *Pardes, col: usize) !void {
- if (col >= p.ncol) return;
- const had_focus = keyboardColumn(p, p.active) == col;
- const beside = if (had_focus) besideColumn(p, col, if (p.header != null) null else p.rects[p.active]) else null;
+ const v = p.view();
+ if (col >= v.ncol) return;
+ const had_focus = keyboardColumn(p, v.active) == col;
+ const beside = if (had_focus) besideColumn(p, col, if (v.header != null) null else v.rects[v.active]) else null;
var ids: [MAX_PANES]usize = undefined;
var parents: [MAX_PANES]*Pane = undefined;
- const count = p.cols[col].n;
+ const count = v.cols[col].n;
for (0..count) |i| {
- ids[i] = p.cols[col].panes[i];
+ ids[i] = v.cols[col].panes[i];
parents[i] = p.panes[ids[i]].?;
}
try panes.detachCwds(p, parents[0..count]);
@@ -1772,25 +1805,27 @@ pub fn removeColumn(p: *Pardes, col: usize) !void {
panes.retirePane(p, pane);
removePane(p, closed);
p.panes[closed] = null;
+ pardes.views.gone(p, closed);
}
dropColumn(p, col);
// The last column gone, the window stays, empty but for the
// workspace tag, as acme's does; Newcol starts again from there.
- if (p.panes[p.active] == null) p.active = beside orelse panes.anyPane(p) orelse return tagline.enterHeader(p, null);
+ if (p.panes[v.active] == null) v.active = beside orelse panes.anyPane(p) orelse return tagline.enterHeader(p, null);
}
/// The pane that takes over the keyboard from column `col`: in the
/// column layout.dropColumn gives the width to, the one level with the
/// middle of `r` (of the screen without one). Asked while rects hold.
pub fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize {
- if (p.ncol < 2) return null;
+ const v = p.view();
+ if (v.ncol < 2) return null;
const next = if (col > 0) col - 1 else col + 1;
- const mid = if (r) |at| at.y + at.h / 2 else p.screen_h / 2;
+ const mid = if (r) |at| at.y + at.h / 2 else v.screen_h / 2;
var pick: ?usize = null;
- for (p.cols[next].panes[0..p.cols[next].n]) |k| {
+ for (v.cols[next].panes[0..p.view().cols[next].n]) |k| {
if (p.panes[k] == null) continue;
pick = k;
- if (p.rects[k].y +| p.rects[k].h > mid) break;
+ if (v.rects[k].y +| v.rects[k].h > mid) break;
}
return pick;
}
@@ -1800,7 +1835,7 @@ pub fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize {
pub fn wantedTagRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return BOX_H;
if (pane.collapsed or !pane.tag_expanded) return BOX_H;
- if (p.rects[id].w == 0) return pane.tag_rows; // never laid out
+ if (p.view().rects[id].w == 0) return pane.tag_rows; // never laid out
var wrap_room: [32 * 1024]u8 = undefined;
var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
const wa = wrap_fba.allocator();
@@ -1823,7 +1858,7 @@ pub fn tagTop(_: *const Pardes, _: *const Pane, r: Rect) u16 {
pub fn tagCapacity(p: *const Pardes, physical_width: u16) u16 {
const layer: Layer = .{ .kind = .pane, .viewport = .{ .x = 0, .y = 0, .w = physical_width, .h = 1 } };
- return layer.capacity(p.row_metrics);
+ return layer.capacity(p.view().row_metrics);
}
// ---- render: build the canonical surface (draw.zig) ----
@@ -1836,7 +1871,7 @@ pub fn reprojectTagHit(p: *const Pardes, tag_hit: TagHit) ?TagHit {
const pane = p.panes[tag_hit.id] orelse return null;
if (pane.serial != tag_hit.serial) return null;
}
- if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.cols[tag_hit.id].serial != tag_hit.serial)) return null;
+ if (tag_hit.kind == .column and (tag_hit.id >= p.view().ncol or p.view().cols[tag_hit.id].serial != tag_hit.serial)) return null;
return Layer.tagAgain(tag_hit);
}
@@ -1850,23 +1885,23 @@ test "a new column takes width only from the column that created it" {
try std.testing.expect(splitColumn(p, 0, 2, true));
p.sync();
- const left_before = p.rects[2];
- const right_before = p.rects[1];
+ const left_before = p.view().rects[2];
+ const right_before = p.view().rects[1];
_ = try p.newShell(3, "");
try std.testing.expect(splitColumn(p, 0, 3, false));
p.sync();
- try std.testing.expectEqual(left_before.x, p.rects[2].x);
- try std.testing.expectEqual(left_before.w, p.rects[2].w);
- try std.testing.expectEqual(right_before.x, p.rects[1].x);
- try std.testing.expectEqual(right_before.w, p.rects[1].w);
- try std.testing.expectEqual(@as(u16, 16), p.rects[0].w);
- try std.testing.expectEqual(@as(u16, 15), p.rects[3].w);
+ try std.testing.expectEqual(left_before.x, p.view().rects[2].x);
+ try std.testing.expectEqual(left_before.w, p.view().rects[2].w);
+ try std.testing.expectEqual(right_before.x, p.view().rects[1].x);
+ try std.testing.expectEqual(right_before.w, p.view().rects[1].w);
+ try std.testing.expectEqual(@as(u16, 16), p.view().rects[0].w);
+ try std.testing.expectEqual(@as(u16, 15), p.view().rects[3].w);
const narrow = try Pardes.init(std.testing.allocator, .{ .cols = config.MINW * 2 - 1, .rows = 10 });
defer narrow.deinit();
try std.testing.expect(!splitColumn(narrow, 0, 1, false));
- try std.testing.expectEqual(@as(usize, 1), narrow.ncol);
+ try std.testing.expectEqual(@as(usize, 1), narrow.view().ncol);
const sequential = try Pardes.init(std.testing.allocator, .{ .cols = config.MINW * 2, .rows = 10 });
defer sequential.deinit();
@@ -1874,16 +1909,16 @@ test "a new column takes width only from the column that created it" {
try std.testing.expect(splitColumn(sequential, 0, 1, false));
_ = try sequential.newShell(2, "");
try std.testing.expect(!splitColumn(sequential, 0, 2, false));
- try std.testing.expectEqual(@as(usize, 2), sequential.ncol);
+ try std.testing.expectEqual(@as(usize, 2), sequential.view().ncol);
const coarse = try Pardes.init(std.testing.allocator, .{ .cols = 22, .rows = 10 });
defer coarse.deinit();
- coarse.cols[0].weight = 3;
+ coarse.view().cols[0].weight = 3;
_ = try coarse.newShell(1, "");
try std.testing.expect(splitColumn(coarse, 0, 1, false));
coarse.sync();
- try std.testing.expectEqual(@as(u16, 11), coarse.col_w[0]);
- try std.testing.expectEqual(@as(u16, 11), coarse.col_w[1]);
+ try std.testing.expectEqual(@as(u16, 11), coarse.view().col_w[0]);
+ try std.testing.expectEqual(@as(u16, 11), coarse.view().col_w[1]);
const extreme = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20 });
defer extreme.deinit();
@@ -1891,14 +1926,14 @@ test "a new column takes width only from the column that created it" {
try std.testing.expect(splitColumn(extreme, 0, 1, false));
_ = try extreme.newShell(2, "");
insert(extreme, 0, 1, 2);
- extreme.cols[0].weight = std.math.maxInt(u64) / 2 + 2; // odd and cannot double
- extreme.cols[1].weight = 1;
+ extreme.view().cols[0].weight = std.math.maxInt(u64) / 2 + 2; // odd and cannot double
+ extreme.view().cols[1].weight = 1;
compute(extreme);
- const cols_before = extreme.cols;
+ const cols_before = extreme.view().cols;
const source_vweight = extreme.panes[0].?.vweight;
const sibling_vweight = extreme.panes[2].?.vweight;
try std.testing.expect(!splitColumn(extreme, 0, 0, false));
- try std.testing.expectEqual(cols_before, extreme.cols);
+ try std.testing.expectEqual(cols_before, extreme.view().cols);
try std.testing.expectEqual(source_vweight, extreme.panes[0].?.vweight);
try std.testing.expectEqual(sibling_vweight, extreme.panes[2].?.vweight);
}
@@ -1912,8 +1947,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" {
try std.testing.expect(splitColumn(p, id - 1, id, false));
}
const restored_cap = std.math.maxInt(u64) / 6;
- for (0..4) |column| p.cols[column].weight = restored_cap;
- p.cols[3].weight -= 1;
+ for (0..4) |column| p.view().cols[column].weight = restored_cap;
+ p.view().cols[3].weight -= 1;
for ([_]usize{ 3, 2, 1 }) |id| {
const pane = p.panes[id].?;
try panes.deinitPane(p, pane);
@@ -1923,8 +1958,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" {
}
while (p.nextEffect()) |_| {}
- try std.testing.expect(p.cols[0].weight > std.math.maxInt(u64) / 2);
- try std.testing.expect(p.cols[0].weight % 2 == 1);
+ try std.testing.expect(p.view().cols[0].weight > std.math.maxInt(u64) / 2);
+ try std.testing.expect(p.view().cols[0].weight % 2 == 1);
try std.testing.expect(!canSplitCol(p, findPane(p, 0).?.col));
const panes_before = p.panes;
const serial_before = p.next_serial;
@@ -1942,7 +1977,7 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" {
try std.testing.expect(splitColumn(p, 0, 1, false));
p.sync();
- const handle = p.col_x[0] + p.col_w[0] - 1;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
const untouched = weightsOf(p);
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } });
@@ -1952,19 +1987,19 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" {
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 417, .row = TOPBAR_H + 1 } });
p.sync();
- try std.testing.expectEqual(@as(u16, 418), p.rects[0].w);
+ try std.testing.expectEqual(@as(u16, 418), p.view().rects[0].w);
_ = try p.newShell(2, "");
try std.testing.expect(splitColumn(p, 1, 2, false));
p.sync();
- const left_before = p.rects[0];
- const middle_before = p.rects[1];
+ const left_before = p.view().rects[0];
+ const middle_before = p.view().rects[1];
_ = try p.newShell(3, "");
try std.testing.expect(splitColumn(p, 2, 3, false));
p.sync();
- try std.testing.expectEqual(left_before, p.rects[0]);
- try std.testing.expectEqual(middle_before, p.rects[1]);
+ try std.testing.expectEqual(left_before, p.view().rects[0]);
+ try std.testing.expectEqual(middle_before, p.view().rects[1]);
}
test "dragging a column's only pane to another leaves that column in place, empty" {
@@ -1972,37 +2007,37 @@ test "dragging a column's only pane to another leaves that column in place, empt
defer p.deinit();
newColumn(p, 0);
newScratchIn(p, 0, activeColumn(p).?);
- const moved = p.active;
+ const moved = p.view().active;
p.sync();
const weights = weightsOf(p);
- const tag_serial = p.cols[1].serial;
- movePane(p, moved, p.col_x[0] + 4, p.rects[0].y + p.rects[0].h / 2);
+ const tag_serial = p.view().cols[1].serial;
+ movePane(p, moved, p.view().col_x[0] + 4, p.view().rects[0].y + p.view().rects[0].h / 2);
p.sync();
// acme's coldragwin: colclose then coladd (cols.c:516-517); the column
// left behind keeps its place, width and tag.
- try std.testing.expectEqual(@as(usize, 2), p.ncol);
- try std.testing.expectEqual(@as(usize, 0), p.cols[1].n);
- try std.testing.expectEqual(tag_serial, p.cols[1].serial);
+ try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
+ try std.testing.expectEqual(@as(usize, 0), p.view().cols[1].n);
+ try std.testing.expectEqual(tag_serial, p.view().cols[1].serial);
try std.testing.expectEqualDeep(weights, weightsOf(p));
- try std.testing.expectEqual(@as(usize, 2), p.cols[0].n);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n);
// ...and a pane dragged into the empty column takes it whole.
- movePane(p, moved, p.col_x[1] + 4, p.screen_h / 2);
+ movePane(p, moved, p.view().col_x[1] + 4, p.view().screen_h / 2);
p.sync();
- try std.testing.expectEqualSlices(usize, &.{moved}, p.cols[1].panes[0..p.cols[1].n]);
- try std.testing.expectEqual(@as(usize, 1), p.cols[0].n);
+ try std.testing.expectEqualSlices(usize, &.{moved}, p.view().cols[1].panes[0..p.view().cols[1].n]);
+ try std.testing.expectEqual(@as(usize, 1), p.view().cols[0].n);
}
test "tiny screens keep pane space before adding a column tag" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 8, .rows = 2, .tty_only = true });
defer p.deinit();
try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
- try std.testing.expectEqual(TOPBAR_H, p.rects[0].y);
+ try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
_ = try p.render(p.scratch.allocator());
}
/// Each column's weight, as a test compares them.
fn weightsOf(p: *const Pardes) [MAX_COLS]u64 {
var out: [MAX_COLS]u64 = undefined;
- for (&out, p.cols) |*w, c| w.* = c.weight;
+ for (&out, p.view().cols) |*w, c| w.* = c.weight;
return out;
}
diff --git a/src/look.zig b/src/look.zig
index 7af69c55..b2fb5ae9 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -445,7 +445,7 @@ pub fn armLookWalk(p: *Pardes, id: usize) void {
pub fn invalidateLookHover(p: *Pardes, id: usize) void {
if (lookHoverPane(p) != id) return;
- p.raw_hover_intent = false;
+ p.view().raw_hover_intent = false;
cancelLookHover(p);
}
@@ -556,9 +556,9 @@ fn lookFirstHit(p: *Pardes, id: usize) void {
const rid = pane.search_pane orelse return;
const rp = p.panes[rid] orelse return;
if ((rp.file orelse return).content.len == 0) return;
- p.active = rid;
+ p.view().active = rid;
lookWalk(p, 1);
- if (p.active != rid) return; // walked out of the list; leave it there
+ if (p.view().active != rid) return; // walked out of the list; leave it there
const txt = edit.currentSelText(p, rp) orelse return;
// spent, exactly as the look chord spends it (handleKey)
rp.body.vsel.active = false;
@@ -656,7 +656,7 @@ pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool {
while (step >= 0 and step < nrows) : (step += direction) {
if (!panes.Output.isResultRow(rf, @intCast(step))) continue;
_ = jumpResult(p, id, @intCast(step));
- p.active = id;
+ p.view().active = id;
break;
}
return true;
@@ -733,10 +733,11 @@ fn lookStand(pane: *Pane) LookFrom {
}
fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize {
+ const v = p.view();
var n: usize = 0;
// A command pane walked from (`make`'s errors): its own places first.
if (commandPaneActive(p)) {
- out[0] = p.active;
+ out[0] = v.active;
n = 1;
}
var i = p.n_look_src;
@@ -765,8 +766,8 @@ fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize {
}
}
if (n == 0) {
- if (p.panes[p.active] == null) return out[0..0];
- out[0] = p.active;
+ if (p.panes[v.active] == null) return out[0..0];
+ out[0] = v.active;
n = 1;
}
return out[0..n];
@@ -846,8 +847,8 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz
/// A command pane has the keyboard: `n` there walks its own output.
fn commandPaneActive(p: *Pardes) bool {
- const pane = p.panes[p.active] orelse return false;
- return pane.command != null and pane.file == null and p.header == null;
+ const pane = p.panes[p.view().active] orelse return false;
+ return pane.command != null and pane.file == null and p.view().header == null;
}
pub fn lookWalk(p: *Pardes, delta: i32) void {
@@ -855,8 +856,8 @@ pub fn lookWalk(p: *Pardes, delta: i32) void {
const order = lookWalkPanes(p, &buf);
if (order.len == 0) return;
// From a command pane the walk starts there, whoever walked last.
- const owner = if (commandPaneActive(p)) p.active else if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null;
- const active_at = std.mem.indexOfScalar(usize, order, p.active) orelse 0;
+ const owner = if (commandPaneActive(p)) p.view().active else if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null;
+ const active_at = std.mem.indexOfScalar(usize, order, p.view().active) orelse 0;
const at = if (owner) |wanted|
std.mem.indexOfScalar(usize, order, wanted) orelse active_at
else
@@ -884,7 +885,7 @@ fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void {
pane.body.cur_pinned = true;
pane.look_at = spot;
p.look_walk_owner = pane.serial;
- p.active = id;
+ p.view().active = id;
pane.ensureCursorVisible();
}
@@ -931,15 +932,16 @@ fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_h
}
pub fn refreshLookHoverFromRaw(p: *Pardes) void {
- if (!p.pointer_inside or !p.raw_hover_intent) return;
- const mapped: struct { col: u16, row: u16 } = .{ .col = p.pointer_raw_col, .row = p.pointer_raw_row };
- p.hover_col = mapped.col;
- p.hover_row = mapped.row;
- const body_hit: ?Mouse.BodyHit = if (p.pointer_body_hit) |mapped_hit|
+ const v = p.view();
+ if (!v.pointer_inside or !v.raw_hover_intent) return;
+ const mapped: struct { col: u16, row: u16 } = .{ .col = v.pointer_raw_col, .row = v.pointer_raw_row };
+ v.hover_col = mapped.col;
+ v.hover_row = mapped.row;
+ const body_hit: ?Mouse.BodyHit = if (v.pointer_body_hit) |mapped_hit|
mouse.bodyHitForPane(p, mouse.paneAt(p, mapped.col, mapped.row) orelse return cancelLookHover(p), mapped_hit, false) orelse return cancelLookHover(p)
else
null;
- noteLookHover(p, mapped.col, mapped.row, body_hit, p.pointer_tag_hit);
+ noteLookHover(p, mapped.col, mapped.row, body_hit, v.pointer_tag_hit);
}
pub fn advanceLookHover(p: *Pardes) void {
@@ -991,7 +993,7 @@ pub fn advanceLookHover(p: *Pardes) void {
pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, keep }) void {
if (id >= MAX_PANES) return;
const pane = p.panes[id] orelse return;
- p.active = id;
+ p.view().active = id;
if (pane.collapsed) layout.toggleCollapse(p, id);
pane.body.normal.clear();
if (pane.hasPdf()) {
@@ -1056,6 +1058,7 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool {
/// Navigation starts a new selection at the destination.
pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void {
+ const v = p.view();
pane.body.vsel = .{};
pane.body.nsel = 0;
pane.body.select = false;
@@ -1068,12 +1071,13 @@ pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void {
state.clearDrag();
state.clearSelection(p.pdf_gpa);
};
- if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none;
+ if (v.drag == .select and p.panes[v.drag.select.id] == pane) v.drag = .none;
}
/// Resolve without changing focus or falling back to search. PDF links use
/// the same location rules as an ordinary Look before offering a choice.
fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) Target {
+ const v = p.view();
const trimmed = std.mem.trim(u8, txt, " \t\r\n");
const pl = parsePathLine(trimmed);
if (pl.path.len > 0) if (openPaneTarget(p, pl.path, pl.at)) |target| return target;
@@ -1081,8 +1085,8 @@ fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8)
var seen: [MAX_PANES][]const u8 = undefined;
var nseen: usize = 0;
var n: usize = 0;
- cand: while (n <= p.jumps.n) : (n += 1) {
- const k: usize = if (n == 0) id else p.jumps.list[p.jumps.n - n].pane;
+ cand: while (n <= v.jumps.n) : (n += 1) {
+ const k: usize = if (n == 0) id else v.jumps.list[v.jumps.n - n].pane;
if (n > 0 and k == id) continue; // tried first, skip the rerun
const op = p.panes[k] orelse continue;
const dir = Pardes.paneDir(op);
@@ -1180,7 +1184,7 @@ pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) v
.internal => |dest| {
p.noteHaptic(.look);
noteLookSource(p, id);
- p.active = id;
+ p.view().active = id;
panes.Pdf.revealOutlineDestination(p, pane, dest);
},
.external => lookAt(p, id, target),
@@ -1303,11 +1307,11 @@ fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
/// nothing, leaves no pane it opened, and is a miss; a bare line number
/// selects the line, its newline included, as acme's does.
fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, opened: ?usize) void {
- const shown = p.panes[p.active] orelse return;
+ const shown = p.panes[p.view().active] orelse return;
const f = if (shown.file) |*file| file else return;
if (at.line > panes.File.nlines(p.gpa, f)) {
if (opened) |free| p.removePane(free, null) catch {};
- if (p.panes[before] != null) p.active = before;
+ if (p.panes[before] != null) p.view().active = before;
return missedLine(p, id, path, at.line);
}
if (at.line > 0 and at.col == 0 and at.end_line == 0) {
@@ -1332,7 +1336,7 @@ fn lookWord(p: *Pardes, id: usize, pane: *Pane, word: []const u8) void {
});
clearNavigationSelection(p, pane);
ninep_pane.setDot(pane, .{ .q0 = @intCast(at), .q1 = @intCast(at + word.len) });
- p.active = id;
+ p.view().active = id;
}
/// `file:addr` or `:addr`, acme's look.c:450-543: a colon followed by an
@@ -1445,6 +1449,7 @@ test "a commit hash is 7 to 40 lowercase hex digits with a letter and a digit" {
/// and selects what `expr` addresses there from its dot. An address that
/// does not evaluate moves nothing and says why (acme: no jump).
fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
+ const v = p.view();
const ninep_pane = @import("ninep/pane.zig");
const Addr = @import("ninep/addr.zig").Addr;
var target = id;
@@ -1464,11 +1469,11 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
// is looked for, as `zzq:2` is, and a miss quotes it as written.
if (!by_serial and resolveLookTarget(p, id, path, &realbuf) == .none)
return lookUnresolved(p, id, p.panes[id] orelse return, path.ptr[0 .. path.len + 1 + expr.len], path.ptr[0 .. path.len + 1 + expr.len]);
- const before = p.active;
+ const before = v.active;
const failures = p.fs.failures;
const was_missed = p.look_missed;
lookAt(p, id, path);
- target = p.active;
+ target = v.active;
// Look said why it opened nothing (its placement refused, say):
// that one failure is the look's, no miss of the address after it.
if (p.fs.failures != failures or (p.look_missed and !was_missed)) return;
@@ -1501,7 +1506,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
const place = std.fmt.bufPrint(&placed, "{s}:{d}", .{ name, line }) catch name;
if (!opened_here) return missedLine(p, target, place, line);
p.removePane(target, null) catch {};
- if (p.panes[id] != null) p.active = id;
+ if (p.panes[id] != null) v.active = id;
return missedLine(p, id, place, line);
} else |_| {}
if (opened_here) return closeAndMiss(p, id, target, name, a.err);
@@ -1514,7 +1519,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
}
clearNavigationSelection(p, pane);
ninep_pane.setDot(pane, r);
- p.active = target;
+ v.active = target;
}
/// A PDF's address is its page: `:N` turns to page N, one past its last a
@@ -1536,14 +1541,14 @@ fn lookPdfPage(p: *Pardes, id: usize, target: usize, pv: *panes.Pdf.State, expr:
const pane = p.panes[target].?;
clearNavigationSelection(p, pane);
if (pv.focusLocation(p.pdf_gpa, page, hit)) panes.Pdf.resetPageChrome(pane);
- p.active = target;
+ p.view().active = target;
}
fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void {
var kept: [miss_path_cap + "…".len]u8 = undefined;
@memcpy(kept[0..name.len], name);
p.removePane(opened, null) catch {};
- if (p.panes[id] != null) p.active = id;
+ if (p.panes[id] != null) p.view().active = id;
missed(p, id, "{s}: {s}", .{ kept[0..name.len], why });
}
@@ -1593,7 +1598,7 @@ fn spotAt(text: []const u8, q: u32) struct { line: usize, col: usize } {
/// still fit.
pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
lookAt(p, from, path);
- const id = p.active;
+ const id = p.view().active;
const pane = p.panes[id] orelse return;
// A PDF's place is its page, the last if it has fewer now.
if (comptime pdf_enabled) if (pane.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) {
@@ -1709,6 +1714,7 @@ fn diffLineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]c
}
pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
+ const v = p.view();
const pane = p.panes[id] orelse return;
// `~/x`, `~/x:12`, `~/x:/re/`: home, before anything reads the text.
// Anything else as written: a look of ` return x` is of those blanks
@@ -1733,7 +1739,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
var diff_buf: [4096 + 32]u8 = undefined;
const looked: []const u8 = diffLineAddress(p, pane, operand_raw, &diff_buf) orelse looked: {
if (config.commandWord(command)) |cmd| {
- if (exec.execute(p, id, cmd)) |dst| p.active = dst;
+ if (exec.execute(p, id, cmd)) |dst| v.active = dst;
return;
}
break :looked operand;
@@ -1801,7 +1807,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
};
// A directory's pane, looked at again: read again.
if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id);
- const before = p.active;
+ const before = v.active;
clearNavigationSelection(p, target);
focusPaneLine(p, t.id, t.at, .center);
settleLine(p, id, trimmed, t.at, before, null);
@@ -1843,7 +1849,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
if (target.at.line > panes.File.nlines(p.gpa, f))
return missedLine(p, id, target.path, target.at.line);
// focus an existing pane on this path (rescrolled), else open
- const before = p.active;
+ const before = v.active;
var opened: ?usize = null;
if (!focusPaneByPath(p, target.path, target.at)) {
// A .diff or .patch looked at bare: its hunks stacked in a
@@ -1854,7 +1860,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
if (filesystem.read(p, target.path)) |bytes| {
defer p.gpa.free(bytes);
if (panes.Output.openDiff(p, id, target.path, bytes)) |hid| {
- p.active = hid;
+ v.active = hid;
return;
} else |_| {}
} else |_| {};
@@ -1868,7 +1874,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// miss of its line too.
if (p.fs.failures != failures) return;
layout.compute(p);
- nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2;
+ nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2;
if (target.at.end_line != 0) {
const centered = nt.file.?.scroll;
selectSpan(p, nt, target.at);
@@ -1918,15 +1924,15 @@ test "Look hover waits without mutating the pane and input cancels it" {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[p.active];
+ const rect = p.view().rects[p.view().active];
const word_x = rect.x + config.GUTTER + config.PREFIX_W + 7;
const body_y = rect.y + BOX_H;
const motion = Event{ .mouse = .{ .button = .none, .kind = .motion, .col = word_x, .row = body_y } };
const selections_before = pane.sel;
- const active_before = p.active;
+ const active_before = p.view().active;
const cursor_before = .{ pane.body.cur_row, pane.body.cur_col };
- const jumps_before = .{ p.jumps.n, p.jumps.cur, p.n_look_src };
+ const jumps_before = .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src };
const effects_before = p.effects_len;
p.update(motion);
@@ -1951,9 +1957,9 @@ test "Look hover waits without mutating the pane and input cancels it" {
// Resolving and displaying the operand is observational only.
try std.testing.expect(std.meta.eql(selections_before, pane.sel));
- try std.testing.expectEqual(active_before, p.active);
+ try std.testing.expectEqual(active_before, p.view().active);
try std.testing.expectEqual(cursor_before, .{ pane.body.cur_row, pane.body.cur_col });
- try std.testing.expectEqual(jumps_before, .{ p.jumps.n, p.jumps.cur, p.n_look_src });
+ try std.testing.expectEqual(jumps_before, .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src });
try std.testing.expectEqual(effects_before, p.effects_len);
_ = frame.reset(.retain_capacity);
@@ -1966,7 +1972,7 @@ test "Look hover waits without mutating the pane and input cancels it" {
p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } });
try std.testing.expect(p.look_hover_preview != null);
- const seam_x = p.col_x[0] + p.col_w[0] - 1;
+ const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1;
p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = seam_x, .row = body_y } });
p.update(.pointer_leave);
try std.testing.expect(p.look_hover_wait == null);
@@ -1987,7 +1993,7 @@ test "Look hover waits without mutating the pane and input cancels it" {
p.look_hover_preview = .{
.col = rect.x + TAG_TEXT_INSET,
.row = tag_y,
- .pane = p.active,
+ .pane = p.view().active,
.serial = pane.serial,
.sel = .{ .state = .done, .c0 = 0, .c1 = 0, .r0 = 0, .r1 = 0 },
};
@@ -2042,13 +2048,13 @@ test "Look copies its operand before releasing pointer selection storage" {
.rows = try p.gpa.alloc(Pane.PointerRow, 0),
.raw_text = operand,
};
- p.drag = .{ .select = .{ .id = 0, .button = config.select_button } };
+ p.view().drag = .{ .select = .{ .id = 0, .button = config.select_button } };
lookAt(p, 0, operand);
try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
try std.testing.expect(pane.pointer_selections[0] == null);
try std.testing.expectEqual(.none, pane.sel[0].state);
- try std.testing.expectEqual(.none, p.drag);
+ try std.testing.expectEqual(.none, p.view().drag);
}
test "@p names a pane by its serial, as /index does" {
@@ -2068,7 +2074,7 @@ test "Look ignores missing and out of bounds pane addresses" {
for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| {
pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true);
lookAt(p, 0, operand);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
try std.testing.expect(pane.body.vsel.active); // a miss changes nothing, the selection included
}
@@ -2079,7 +2085,7 @@ test "a pointer resting where a look-hover found nothing does not wake the core
defer p.deinit();
_ = try p.setTestFile(std.mem.asBytes(&@as([30][6]u8, @splat(" \n".*))));
p.sync();
- const r = p.rects[p.active];
+ const r = p.view().rects[p.view().active];
// Resting on blanks in the body: a wait, then nothing to open.
p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 20, .row = r.y + 5 } });
var frames: usize = 0;
@@ -2123,7 +2129,7 @@ const DiffFixture = struct {
/// A right click's look at `row` of the diff pane (slot 0): the look
/// of the address that line names.
fn click(p: *Pardes, diff_pane: *Pane, row: usize) void {
- p.active = 0;
+ p.view().active = 0;
const lines = diffLines(p, diff_pane).?;
var buf: [4096]u8 = undefined;
p.look_missed = false;
@@ -2132,7 +2138,7 @@ const DiffFixture = struct {
};
fn expectAt(p: *Pardes, suffix: []const u8, line: usize) !void {
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
const f = pane.file orelse return error.NoFileOpened;
if (!std.mem.endsWith(u8, f.path, suffix)) {
std.debug.print("opened {s}, not {s}\n", .{ f.path, suffix });
@@ -2181,26 +2187,26 @@ test "Look on each kind of diff line opens the new file at the line it names" {
DiffFixture.click(p, pane, 9);
try expectAt(p, "/src/a.zig", 13);
DiffFixture.click(p, pane, 3); // +++ b/path: the file, a/ b/ dropped
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/src/a.zig"));
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig"));
DiffFixture.click(p, pane, 2); // --- a/path
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/src/a.zig"));
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig"));
try std.testing.expect(!p.look_missed);
// No click: a 9P look writes a whole line, found from the cursor on.
- p.active = 0;
+ p.view().active = 0;
pane.body.cur_row = 0;
lookAt(p, 0, "+line 12");
try expectAt(p, "/src/a.zig", 12);
// A word on a hunk line is a word, looked for in the diff as ever.
- p.active = 0;
+ p.view().active = 0;
pane.body.cur_row = 9;
lookAt(p, 0, "line");
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
// A line that is no part of a hunk is looked at as ever.
- p.active = 0;
+ p.view().active = 0;
pane.body.cur_row = 1;
lookAt(p, 0, "1111111");
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
}
test "Look on plain diff -u output: names as written, timestamps cut, next to the diff" {
@@ -2271,12 +2277,12 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover
defer frame.deinit();
for (points) |at| {
// Back to the diff, scrolled to its top again.
- p.active = 0;
+ p.view().active = 0;
pane.file.?.scroll = 0;
p.sync();
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col;
const y = p.bodyTop(pane, rect) + at.row;
// The hover's span is the click's operand.
@@ -2298,11 +2304,11 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = x, .row = y } });
if (at.line == 0) {
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
continue;
}
try std.testing.expect(!p.look_missed);
- if (p.active == 0) {
+ if (p.view().active == 0) {
std.debug.print("a look at row {d} col {d} stayed in the diff\n", .{ at.row, at.col });
return error.LookStayed;
}
@@ -2345,14 +2351,14 @@ test "a click, a 9P whole-line look and an empty event write-back take one expan
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
for (points) |at| {
- p.active = 0;
+ p.view().active = 0;
pane.file.?.scroll = 0;
pane.body.cur_row = 0;
p.sync();
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
// The mouse's.
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col;
const y = p.bodyTop(pane, rect) + at.row;
const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed;
@@ -2417,7 +2423,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
other.body.cur_row = 0;
other.body.cur_col = 0;
};
- p.active = 0;
+ p.view().active = 0;
pane.body.mode = .normal;
pane.body.vsel.active = false;
pane.body.cur_row = case.row;
@@ -2427,7 +2433,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
p.sync();
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x0 = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
const y = p.bodyTop(pane, rect) + case.row;
switch (entry) {
@@ -2454,7 +2460,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
lookAt(p, 0, p.scratch.allocator().dupe(u8, text) catch unreachable);
},
}
- const landed = p.panes[p.active].?;
+ const landed = p.panes[p.view().active].?;
const f = landed.file orelse return error.NothingOpened;
if (column < 0) column = landed.body.cur_col;
if (!std.mem.endsWith(u8, f.path, "/src/x.zig") or landed.body.cur_row != case.line or landed.body.cur_col != column) {
@@ -2516,8 +2522,8 @@ test "a tag word looked at by a click and by Enter is one record to an event rea
const shown_at = std.mem.lastIndexOf(u8, shown, "Del").?;
const shown_row: u16 = @intCast(std.mem.count(u8, shown[0..shown_at], "\n"));
const line_start = if (std.mem.lastIndexOfScalar(u8, shown[0..shown_at], '\n')) |nl| nl + 1 else 0;
- const x = p.rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1;
- const y = p.rects[0].y + shown_row;
+ const x = p.view().rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1;
+ const y = p.view().rects[0].y + shown_row;
p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } });
var clicked_buf: [128]u8 = undefined;
@@ -2555,11 +2561,11 @@ test "Incl's directories find a name found nowhere else, <name> too; bare Incl l
var line: [4200]u8 = undefined;
try std.testing.expect(p.executeBuiltinLine(0, try std.fmt.bufPrint(&line, "Incl {s}/inc", .{root})));
for ([_][]const u8{ "pardes_incl_probe.h", "<pardes_incl_probe.h>" }) |word| {
- p.active = 0;
+ p.view().active = 0;
p.look_missed = false;
lookAt(p, 0, word);
try std.testing.expect(!p.look_missed);
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/inc/pardes_incl_probe.h"));
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/inc/pardes_incl_probe.h"));
}
// Bare, it lists them.
try std.testing.expect(p.executeBuiltinLine(0, "Incl"));
@@ -2597,20 +2603,20 @@ test "LookNext in a command pane walks its own file:line places, whoever walked
const cmd = p.panes[dst].?;
// A walk last made elsewhere, and another pane with places in it.
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const scratch = p.panes[p.active].?;
+ const scratch = p.panes[p.view().active].?;
_ = pardes.ctlfs.pane.spliceBody(p, scratch, 0, 0, "x.c:1:1 elsewhere\n") orelse return error.NoScratch;
p.look_walk_owner = scratch.serial;
- p.active = dst;
+ p.view().active = dst;
cmd.focus = .body;
cmd.body.mode = .normal;
for ([_]u21{ 'g', 'g' }) |cp| p.update(.{ .key = .{ .cp = cp } });
- exec.runBuiltin(p, .LookNext, p.active, "", null);
- try std.testing.expectEqual(dst, p.active);
+ exec.runBuiltin(p, .LookNext, p.view().active, "", null);
+ try std.testing.expectEqual(dst, p.view().active);
const first = cmd.look_at orelse return error.NoSpot;
const lines = try edit.paneCursorLines(p, &cmd.body);
try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(first.row)][@intCast(first.col0)..], "x.c:3:1"));
- exec.runBuiltin(p, .LookNext, p.active, "", null);
- try std.testing.expectEqual(dst, p.active);
+ exec.runBuiltin(p, .LookNext, p.view().active, "", null);
+ try std.testing.expectEqual(dst, p.view().active);
const second = cmd.look_at orelse return error.NoSpot;
try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(second.row)][@intCast(second.col0)..], "y.c:2:1"));
}
@@ -2625,7 +2631,7 @@ test "Look outside a diff pane expands and looks as ever" {
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + 0;
const pointed = edit.pointerTextSelection(p, 0, x, p.bodyTop(pane, rect) + 2, null, null).?;
const operand = exec.operandAt(p, pane, pointed.sel, true, true);
@@ -2655,7 +2661,7 @@ test "Look on a diff under each git prefix opens the repository's file, and a re
try expectAt(p, c.file, 2);
DiffFixture.click(p, pane, 1); // `---`
try std.testing.expect(!p.look_missed);
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, c.file));
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, c.file));
}
}
@@ -2687,8 +2693,8 @@ test "Look on a diff line is the look of the address it names, selected by hand:
// The checkout's file, opened by a look from the diff pane.
lookAt(p, 0, cargo);
p.update(.tick);
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "Cargo.toml"));
- p.active = 0;
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "Cargo.toml"));
+ p.view().active = 0;
p.update(.tick);
p.look_missed = false;
if (way == 0) {
@@ -2696,7 +2702,7 @@ test "Look on a diff line is the look of the address it names, selected by hand:
} else {
lookAt(p, 0, "entry/src/entry.rs:2"); // the same, selected by hand
}
- const shown = p.panes[p.active].?;
+ const shown = p.panes[p.view().active].?;
var n: usize = 0;
for (p.panes) |slot| n += @intFromBool(slot != null);
seen[way] = .{
diff --git a/src/lsp/Ask.zig b/src/lsp/Ask.zig
index f071cf7b..8ed0aecc 100644
--- a/src/lsp/Ask.zig
+++ b/src/lsp/Ask.zig
@@ -264,6 +264,7 @@ fn lspWord(kind: lsp.Kind) []const u8 {
}
pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
+ const v = p.view();
defer pardes.turn.bump(&pardes.turn.lsp_answers);
const w = p.lsp_ask.wait orelse return;
if (w.id != id) return; // superseded by a newer press, or the pane died
@@ -332,7 +333,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
// The one place is the text's places, as a list's would be: tinted,
// and n and N step it.
const spot = look.parsePathLine(place);
- if (!p.look_missed and spot.at.line > 0) if (p.panes[p.active]) |there| if (there.file) |*tf| if (spot.at.line <= panes.File.nlines(p.gpa, tf)) {
+ if (!p.look_missed and spot.at.line > 0) if (p.panes[v.active]) |there| if (there.file) |*tf| if (spot.at.line <= panes.File.nlines(p.gpa, tf)) {
const ls = panes.File.lineStart(p.gpa, tf, spot.at.line - 1);
const line = tf.content[ls .. std.mem.indexOfScalarPos(u8, tf.content, ls, '\n') orelse tf.content.len];
const col = @min(spot.at.col -| 1, line.len);
@@ -349,7 +350,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
};
if (listing and !p.look_missed) {
var where: [300]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&where, "{s}: the one, {s}", .{ lspWord(w.kind), place[0..@min(place.len, 240)] }) catch lspWord(w.kind));
+ p.setMessage(v.active, std.fmt.bufPrint(&where, "{s}: the one, {s}", .{ lspWord(w.kind), place[0..@min(place.len, 240)] }) catch lspWord(w.kind));
}
return;
}
@@ -387,7 +388,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
if (result_pane.serial != p.fs.lsp_result) continue;
if (p.next_serial != serial_before) {
const report_rows = std.mem.count(u8, result_pane.file.?.content, "\n");
- const wanted: u16 = @intCast(@min(p.screen_h, report_rows + result_pane.tag_rows));
+ const wanted: u16 = @intCast(@min(v.screen_h, report_rows + result_pane.tag_rows));
layout.givePaneRows(p, result_id, wanted, w.pane);
}
look.focusPaneLine(p, result_id, .{ .line = 1, .col = 1 }, .keep);
@@ -488,7 +489,7 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r
p.update(.{ .key = .{ .cp = 'c' } });
try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .callstack));
- const r = p.rects[0];
+ const r = p.view().rects[0];
const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane);
const use_y = p.bodyTop(pane, r) + 1;
// Copied out of the scratch arena, which each p.update resets.
@@ -530,7 +531,7 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy
p.lspRequest(0, .callstack, "");
const first = p.lsp_ask.wait orelse return error.NoRequest;
lspResponse(p, first.id, "╰──┬ /test.txt:1:4-7 work\n@callstack-match ╰─ /test.txt:1:4-7 fn work() {}\n");
- const report = p.panes[p.active].?;
+ const report = p.panes[p.view().active].?;
try std.testing.expect(report != source);
try std.testing.expect(std.mem.endsWith(u8, report.file.?.path, "/+Callstack"));
try std.testing.expectEqual(@as(i32, 0), source.body.cur_row);
@@ -541,22 +542,22 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy
defer frame.deinit();
const surface = try p.render(frame.allocator());
p.presented();
- const r = p.rects[p.active];
+ const r = p.view().rects[p.view().active];
const row = r.y + report.tag_rows;
const col = r.x + config.GUTTER + panes.File.gutterWidth(report) + 7;
try std.testing.expectEqual(.off, surface.at(col, row).style.ul);
p.update(.{ .mouse = .{ .button = .right, .kind = .press, .row = row, .col = col } });
p.update(.{ .mouse = .{ .button = .right, .kind = .release, .row = row, .col = col } });
try std.testing.expect(!source.collapsed);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expect(!report.body.vsel.active);
try std.testing.expectEqual(@as(usize, 0), report.body.nsel);
const serial = report.serial;
p.lspRequest(0, .callstack, "");
const second = p.lsp_ask.wait orelse return error.NoRequest;
lspResponse(p, second.id, "No callers reported\n");
- try std.testing.expectEqual(serial, p.panes[p.active].?.serial);
- try std.testing.expectEqualStrings("No callers reported\n", p.panes[p.active].?.file.?.content);
+ try std.testing.expectEqual(serial, p.panes[p.view().active].?.serial);
+ try std.testing.expectEqualStrings("No callers reported\n", p.panes[p.view().active].?.file.?.content);
}
test "Callers with one answer jumps to it and says where, in a msg" {
@@ -564,7 +565,7 @@ test "Callers with one answer jumps to it and says where, in a msg" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("fn a() {}\nfn b() { a(); }\n");
- p.lspRequest(p.active, .incoming_calls, "");
+ p.lspRequest(p.view().active, .incoming_calls, "");
const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "/test.txt:2:10 b\n" } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
@@ -576,7 +577,7 @@ test "a Rename the language server finds nothing for says so, and changes nothin
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("const value=1;\n");
- p.lspRequest(p.active, .rename, "renamed");
+ p.lspRequest(p.view().active, .rename, "renamed");
const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "" } });
try std.testing.expectEqualStrings("Rename: nothing here to rename", pane.msg[0..pane.msg_len]);
@@ -591,9 +592,9 @@ test "LSP failure clears only its matching wait without completion indentation"
pane.body.mode = .insert;
pane.body.cur_col = 1;
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
const old_id = p.lsp_ask.wait.?.id;
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
const current_id = p.lsp_ask.wait.?.id;
p.update(.{ .lsp_resp = .{ .id = old_id, .rows = null } });
try std.testing.expectEqual(current_id, p.lsp_ask.wait.?.id);
@@ -602,7 +603,7 @@ test "LSP failure clears only its matching wait without completion indentation"
try std.testing.expectEqualStrings("x", pane.file.?.content);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
p.update(.{ .lsp_resp = .{ .id = p.lsp_ask.wait.?.id, .rows = "" } });
try std.testing.expect(p.lsp_ask.wait == null);
try std.testing.expectEqualStrings("x ", pane.file.?.content);
diff --git a/src/macos.zig b/src/macos.zig
index a152edfc..3ba5f52a 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -356,11 +356,11 @@ test "mac worker setup failures finish matching LSP and pipe requests" {
};
defer st.config_arena.deinit();
defer st.inbox.close();
- core.lspRequest(core.active, .status, "");
+ core.lspRequest(core.view().active, .status, "");
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 0,
.arg = "",
};
@@ -530,7 +530,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void {
std.mem.eql(u8, std.mem.span(v), "1")
else
@import("pardes_config").workspace_tag;
- core.frontend.native_images = true;
+ core.view().frontend.native_images = true;
var prompt_rcs = host_io.Shell.prepare();
errdefer prompt_rcs.deinit();
@@ -1083,7 +1083,7 @@ fn drainInbox(st: *State) bool {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- st.core.setStatus(st.core.active, message.stamp(&mbuf, "lsp", text));
+ st.core.setStatus(st.core.view().active, message.stamp(&mbuf, "lsp", text));
},
.pipe => |value| {
st.core.update(.{ .pipe_resp = .{
@@ -1140,12 +1140,12 @@ fn restoreCore(st: *State) bool {
if (st.core.quit) return false;
const path = st.core.takeRestore() orelse return false;
const bytes = dump.restoreBytes(st.core, st.gpa, path) catch |err| {
- st.core.reportError(st.core.active, "Restore", err);
+ st.core.reportError(st.core.view().active, "Restore", err);
return false;
};
defer st.gpa.free(bytes);
const replacement = dump.restore(st.core, bytes, path) catch |err| {
- st.core.reportError(st.core.active, "Restore", err);
+ st.core.reportError(st.core.view().active, "Restore", err);
return false;
};
if (st.inbox.lsp_task) |*task| {
@@ -1438,7 +1438,7 @@ export fn pardes_mouse_pixel(button_arg: c_int, kind_arg: c_int, col: u16, row:
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return);
- const source = st.core.presentation.pointerFractional(st.core.screen_w, st.core.screen_h, x / @max(1, bw), y / @max(1, bh));
+ const source = st.core.presentation.pointerFractional(st.core.view().screen_w, st.core.view().screen_h, x / @max(1, bw), y / @max(1, bh));
var hit: ?pardes.Mouse.BodyHit = null;
for (&st.core.surface.body_layers) |*layer| {
const point = source orelse break;
@@ -1762,8 +1762,8 @@ fn collectImages(st: *State, surface: *const pardes.Surface) void {
for (placements) |place| {
if (place.raster.w == 0 or place.raster.h == 0) continue;
const dst = place.at orelse pardes.RectPx{
- .w = @as(u32, place.dst.w) * st.core.cell_pixels.w,
- .h = @as(u32, place.dst.h) * st.core.cell_pixels.h,
+ .w = @as(u32, place.dst.w) * st.core.view().cell_pixels.w,
+ .h = @as(u32, place.dst.h) * st.core.view().cell_pixels.h,
};
if (dst.w == 0 or dst.h == 0 or place.src.w == 0 or place.src.h == 0) continue;
var scroll: f64 = 0;
@@ -1984,7 +1984,7 @@ export fn pardes_row_metrics(body_w: u16, body_h: u16, tagline_w: u16, tagline_h
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return);
- st.core.update(.{ .resize = .{ .cols = st.core.screen_w, .rows = st.core.screen_h, .cell_pixels = st.core.cell_pixels, .row_metrics = .{ .body_w = @max(1, body_w), .body_h = @max(1, body_h), .tagline_w = @max(1, tagline_w), .tagline_h = @max(1, tagline_h) } } });
+ st.core.update(.{ .resize = .{ .cols = st.core.view().screen_w, .rows = st.core.view().screen_h, .cell_pixels = st.core.view().cell_pixels, .row_metrics = .{ .body_w = @max(1, body_w), .body_h = @max(1, body_h), .tagline_w = @max(1, tagline_w), .tagline_h = @max(1, tagline_h) } } });
}
export fn pardes_pointer_shape() u32 {
@@ -2085,14 +2085,14 @@ export fn pardes_active_dirty() bool {
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return false);
- const pane = st.core.panes[st.core.active] orelse return false;
+ const pane = st.core.panes[st.core.view().active] orelse return false;
const f = if (pane.file) |*x| x else return false;
if (f.output != null) return false;
return f.revision != f.saved_revision;
}
fn activeFilePath(st: *State) ?[]const u8 {
- const pane = st.core.panes[st.core.active] orelse return null;
+ const pane = st.core.panes[st.core.view().active] orelse return null;
if (pane.file) |*f| return if (f.output == null) f.path else null;
if (comptime pardes.pdf_enabled) if (pane.pdfPath()) |path| return path;
if (pane.addon) |k| return k.path;
@@ -2145,7 +2145,7 @@ fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = st.ptys[pane] != null;
- const child = host_io.forkShell(core, pane, &st.prompt_rcs, core.shellBin(), cwd, core.screen_h, core.screen_w) catch |err| {
+ const child = host_io.forkShell(core, pane, &st.prompt_rcs, core.shellBin(), cwd, core.view().screen_h, core.view().screen_w) catch |err| {
if (running) return core.restartFailed(pane, err);
return core.shellFailed(pane, err);
};
@@ -2815,14 +2815,14 @@ test "mac row metrics ABI preserves PDF cell dimensions and the unrendered grid"
state.?.config_arena.deinit();
state = null;
}
- if (comptime pardes.pdf_enabled) core.cell_pixels = .{ .w = 22, .h = 39 };
- const pixels = core.cell_pixels;
+ if (comptime pardes.pdf_enabled) core.view().cell_pixels = .{ .w = 22, .h = 39 };
+ const pixels = core.view().cell_pixels;
try std.testing.expectEqual(@as(u16, 0), core.surface.cols);
pardes_row_metrics(22, 39, 17, 30);
- try std.testing.expectEqualDeep(pixels, core.cell_pixels);
- try std.testing.expectEqual(@as(u16, 80), core.screen_w);
- try std.testing.expectEqual(@as(u16, 24), core.screen_h);
- try std.testing.expectEqualDeep(pardes.RowMetrics{ .body_w = 22, .body_h = 39, .tagline_w = 17, .tagline_h = 30 }, core.row_metrics);
+ try std.testing.expectEqualDeep(pixels, core.view().cell_pixels);
+ try std.testing.expectEqual(@as(u16, 80), core.view().screen_w);
+ try std.testing.expectEqual(@as(u16, 24), core.view().screen_h);
+ try std.testing.expectEqualDeep(pardes.RowMetrics{ .body_w = 22, .body_h = 39, .tagline_w = 17, .tagline_h = 30 }, core.view().row_metrics);
}
test "mac tag layer ABI preserves logical capacity and physical grip" {
diff --git a/src/mini.zig b/src/mini.zig
index 9f7d865d..91870674 100644
--- a/src/mini.zig
+++ b/src/mini.zig
@@ -167,7 +167,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void {
file.syntax_dirty = false;
Output.resetBody(p, pane);
}
- p.active = i;
+ p.view().active = i;
return;
}
const free = p.freeSlot() orelse return error.NoPaneSlots;
@@ -187,7 +187,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void {
};
pane.body.cur_pinned = true;
exec.placeNew(p, id, id, free, .doc);
- p.active = free;
+ p.view().active = free;
}
test "Mini maps every braille dot and partial line group" {
@@ -287,13 +287,13 @@ test "Mini publishes only complete snapshots and content replacement drops metad
const source = try p.setTestFile("untouched\n");
const free = p.freeSlot();
open(p, 0, path) catch |err| {
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(free, p.freeSlot());
try std.testing.expectEqual(source, p.panes[0].?);
try std.testing.expectEqualStrings("untouched\n", source.file.?.content);
return err;
};
- const file = &p.panes[p.active].?.file.?;
+ const file = &p.panes[p.view().active].?.file.?;
try std.testing.expectEqualStrings("⠉\n", file.content);
try std.testing.expectEqualStrings(path, file.mini.?.source);
const replacement = try gpa.dupe(u8, "plain\n");
diff --git a/src/mouse.zig b/src/mouse.zig
index f57bb533..7eab8322 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -98,29 +98,31 @@ pub const HeaderSweep = struct {
/// in that text. `clamp` holds a held sweep to the header's rows and text,
/// as a pane tag's sweep stays on its tag.
fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } {
- const t = if (column) |c| &p.col_tags[c] else &p.global_tag;
- const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
- const focused = p.header != null and p.headerColumn() == column;
+ const v = p.view();
+ const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
+ const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
+ const focused = v.header != null and p.headerColumn() == column;
const text = edit.flatSurface(p, t) catch return null;
const base = if (column != null) p.topBarHeight() else 0;
const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight();
const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base;
- const top: usize = if (focused) p.header_top else 0;
+ const top: usize = if (focused) v.header_top else 0;
const lines = modal.lineCount(text);
const line: u16 = if (clamp) @intCast(@min(row + top, lines -| 1)) else @intCast(row + top);
if (line > 0 and line >= lines) return null;
const bar = modal.lineSlice(text, line);
- const scroll = if (focused) p.header_scroll else 0;
+ const scroll = if (focused) v.header_scroll else 0;
const kind: Layer.Kind = if (column != null) .column else .workspace;
- const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, kind, column orelse 0, p.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll));
+ const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, kind, column orelse 0, v.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll));
return .{ .t = t, .text = text, .line = line, .at = modal.lineStartOffset(text, line) + at };
}
/// A header sweep's button came up: a click runs the word under it, or the
/// header's selection when it is on that; a sweep runs what it swept.
fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void {
+ const v = p.view();
const column = sweep.column(p) catch return;
- const t = if (column) |c| &p.col_tags[c] else &p.global_tag;
+ const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
const text = edit.flatSurface(p, t) catch return;
const swept = sweep.span(text.len);
const selected = if (swept.lo < swept.hi) text[swept.lo..swept.hi] else click: {
@@ -128,7 +130,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void {
const start = modal.lineStartOffset(text, line);
const bar = modal.lineSlice(text, line);
const at = swept.lo - start;
- const focused = p.header != null and p.headerColumn() == column;
+ const focused = v.header != null and p.headerColumn() == column;
const on = if (focused) tagline.headerSelection(t, text, line) else null;
const under = if (tagline.wordBoundsAtCol(bar, at)) |b| bar[b.lo..b.hi] else "";
break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else under) else under;
@@ -143,9 +145,9 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void {
if (word.len == 0) return;
if (sweep.button == config.exec_button) {
const named = std.meta.stringToEnum(Builtin, word);
- const held = if (named) |b| (if (builtins.registry.takesArg(b)) exec.heldSelection(p, p.active) else null) else exec.heldSelection(p, p.active);
- _ = exec.execute(p, p.active, exec.withArg(p, word, held));
- } else exec.runBuiltin(p, config.look_cmd, p.active, "", word);
+ const held = if (named) |b| (if (builtins.registry.takesArg(b)) exec.heldSelection(p, v.active) else null) else exec.heldSelection(p, v.active);
+ _ = exec.execute(p, v.active, exec.withArg(p, word, held));
+ } else exec.runBuiltin(p, config.look_cmd, v.active, "", word);
}
fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 {
@@ -161,14 +163,14 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 {
}
fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 {
- const r = p.rects[p.cols[c].panes[k]];
+ const r = p.view().rects[p.view().cols[c].panes[k]];
return r.y + r.h -| 1;
}
fn cornerFixture(gpa: std.mem.Allocator) !*Pardes {
const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 });
p.update(.{ .resize = .{ .cols = 100, .rows = 30 } });
- p.active = p.cols[1].panes[0];
+ p.view().active = p.view().cols[1].panes[0];
p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell below it, same column
p.sync();
return p;
@@ -178,9 +180,9 @@ test "a pane's last row of text is no resize handle; the rule over the next pane
const p = try cornerFixture(std.testing.allocator);
defer p.deinit();
const seam = seamRowOf(p, 1, 0);
- const inside = p.col_x[1] + p.col_w[1] / 2;
+ const inside = p.view().col_x[1] + p.view().col_w[1] / 2;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = inside, .row = seam } });
- try std.testing.expect(p.drag != .border_h);
+ try std.testing.expect(p.view().drag != .border_h);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = inside, .row = seam } });
try std.testing.expect(nudgeRightSeam(p, 2) == seam + 2);
}
@@ -188,32 +190,32 @@ test "a pane's last row of text is no resize handle; the rule over the next pane
test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" {
const p = try cornerFixture(std.testing.allocator);
defer p.deinit();
- const upper = p.cols[1].panes[0];
- const lower = p.cols[1].panes[1];
- const grip_x = p.rects[lower].x;
+ const upper = p.view().cols[1].panes[0];
+ const lower = p.view().cols[1].panes[1];
+ const grip_x = p.view().rects[lower].x;
// Up, past the pane above's first row: a text pane keeps its tag, a
// terminal its tag and two rows (layout.floorRows).
- const top = p.rects[upper].y;
+ const top = p.view().rects[upper].y;
const above = p.panes[upper].?;
const floor: u16 = if (above.isTerminal()) above.tag_rows + layout.min_body_rows else 1;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.rects[lower].y } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.view().rects[lower].y } });
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = grip_x, .row = top } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = grip_x, .row = top } });
p.sync();
- try std.testing.expectEqual(floor, p.rects[upper].h);
- try std.testing.expectEqual(lower, p.cols[1].panes[1]);
+ try std.testing.expectEqual(floor, p.view().rects[upper].h);
+ try std.testing.expectEqual(lower, p.view().cols[1].panes[1]);
// Down, inside itself: its top follows, the pane above taking the rows.
- const to = p.rects[lower].y + 6;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.rects[lower].y } });
+ const to = p.view().rects[lower].y + 6;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.view().rects[lower].y } });
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = grip_x, .row = to } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = grip_x, .row = to } });
p.sync();
- try std.testing.expectEqual(to, p.rects[lower].y);
+ try std.testing.expectEqual(to, p.view().rects[lower].y);
}
fn nudgeRightSeam(p: *Pardes, delta: i32) u16 {
const from = seamRowOf(p, 1, 0);
- const inside = p.col_x[1] + p.col_w[1] / 2;
+ const inside = p.view().col_x[1] + p.view().col_w[1] / 2;
const to: u16 = @intCast(@as(i32, from) + delta);
// On the rule a pixel frontend draws over the lower pane's first row.
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = inside, .row = from + 1, .rule_above = true } });
@@ -229,23 +231,24 @@ pub const ChromeTarget = struct { col: u16, row: u16 };
/// on the cell, a pane's grip, a column's handle or a seam; then a cell
/// away, any of a pane's tag, a handle or a seam.
pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget {
+ const v = p.view();
if (row < p.topBarHeight() + layout.columnBarHeight(p)) return .{ .col = col, .row = row };
for ([_]u16{ 0, 1 }) |slack| {
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const rect = p.rects[id];
+ const rect = v.rects[id];
const tag = p.tagTop(pane, rect);
const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w;
if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge)
return .{ .col = col, .row = row };
}
- for (0..p.ncol -| 1) |column| {
- const handle = p.col_x[column] + p.col_w[column] -| 1;
+ for (0..p.view().ncol -| 1) |column| {
+ const handle = v.col_x[column] + v.col_w[column] -| 1;
if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row };
}
- for (0..p.ncol) |column| {
- if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue;
- for (0..p.cols[column].n -| 1) |index| {
+ for (0..p.view().ncol) |column| {
+ if (col < v.col_x[column] or col >= v.col_x[column] + v.col_w[column]) continue;
+ for (0..p.view().cols[column].n -| 1) |index| {
const seam = seamRowOf(p, column, index);
if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam };
}
@@ -259,11 +262,11 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on
defer p.deinit();
// Column 0's two panes share its rows evenly; column 1's lower one is
// tall, its middle a body row.
- const handle = p.col_x[0] + p.col_w[0] - 1;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
const seam = seamRowOf(p, 0, 0);
- const mid = p.col_x[0] + p.col_w[0] / 2;
- const top = p.rects[p.cols[0].panes[0]].y;
- const low = p.rects[p.cols[1].panes[1]];
+ const mid = p.view().col_x[0] + p.view().col_w[0] / 2;
+ const top = p.view().rects[p.view().cols[0].panes[0]].y;
+ const low = p.view().rects[p.view().cols[1].panes[1]];
const body = low.y + low.h / 2;
try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?);
try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?);
@@ -277,7 +280,7 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on
pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize {
for (p.panes, 0..) |slot, id| {
if (slot == null) continue;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (col >= r.x and col < r.x + r.w and row >= r.y and row < r.y + r.h) return id;
}
return null;
@@ -293,7 +296,7 @@ pub fn bodyHitForPane(p: *const Pardes, id: usize, supplied: Mouse.BodyHit, clam
if (clamp) {
// Onto the body the sweep is in: the place of its last hit there
// (the drag's `body`), the hit's own while it is over it.
- if (supplied.serial != pane.serial) mapped_hit.place = (if (p.drag == .select) p.drag.select.body else null) orelse return null;
+ if (supplied.serial != pane.serial) mapped_hit.place = (if (p.view().drag == .select) p.view().drag.select.body else null) orelse return null;
mapped_hit.serial = pane.serial;
if (mapped_hit.place.rows == 0) return null;
const v = mapped_hit.place.viewport;
@@ -329,7 +332,7 @@ fn programWheel(p: *Pardes, id: usize, m: Mouse, col: u16, row: u16) bool {
if (m.shift) return false;
const pane = p.panes[id] orelse return false;
if (!pane.isTerminal() or !panes.terminal.ownsWheel(pane)) return false;
- const r = p.rects[id];
+ const r = p.view().rects[id];
const body_y = p.bodyTop(pane, r);
const gcol = std.math.clamp(col -| (r.x + config.GUTTER), 0, pane.cols -| 1);
const grow = std.math.clamp(row -| body_y, 0, pane.rows -| 1);
@@ -359,7 +362,7 @@ pub const Grab = struct {
/// the grid).
fn programCell(p: *const Pardes, id: usize, col: u16, row: u16) ?struct { col: i32, row: i32 } {
const pane = p.panes[id] orelse return null;
- const r = p.rects[id];
+ const r = p.view().rects[id];
const x0 = r.x + config.GUTTER;
const y0 = p.bodyTop(pane, r);
const h = @min(r.h -| pane.tag_rows, pane.rows);
@@ -384,22 +387,24 @@ fn tracksMouse(pane: *const Pane) bool {
/// The pointer over the body of a pane whose kind takes the mouse: the
/// kind's, a press focusing the pane first.
fn kindMouse(p: *Pardes, m: Mouse) bool {
- if (p.drag != .none or p.header_drag or p.header_sweep != null) return false;
+ const v = p.view();
+ if (v.drag != .none or v.header_drag or v.header_sweep != null) return false;
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
const k = pane.addon orelse continue;
if (!pardes.Kind.takesMouse(p, k) or pane.collapsed) continue;
- const r = p.rects[id];
+ const r = v.rects[id];
const top = p.bodyTop(pane, r) + pane.notices.span();
const x0 = r.x + config.GUTTER;
if (m.col < x0 or m.col >= r.x + r.w or m.row < top or m.row >= r.y + r.h) continue;
- if (m.kind == .press) p.active = id;
+ if (m.kind == .press) v.active = id;
return pardes.Kind.mouse(p, id, m, m.col - x0, m.row - top);
}
return false;
}
fn programMouse(p: *Pardes, m: Mouse) bool {
+ const v = p.view();
const button: ?panes.terminal.MouseButton = switch (m.button) {
.left => .left,
.middle => .middle,
@@ -408,22 +413,22 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
else => return false,
};
const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
- const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, p.screen_w -| 1), .row = @min(m.row, p.screen_h -| 1) };
+ const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, v.screen_w -| 1), .row = @min(m.row, v.screen_h -| 1) };
var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
- if (p.mouse_grab) |*grab| {
+ if (v.mouse_grab) |*grab| {
if (grab.unshift) mods.shift = false;
const pane = p.panes[grab.id] orelse {
- p.mouse_grab = null;
+ v.mouse_grab = null;
return false;
};
if (pane.serial != grab.serial or !pane.isTerminal()) {
- p.mouse_grab = null;
+ v.mouse_grab = null;
return false;
}
// Off the grid the cell runs on past its edge, and the encoder
// clamps it there.
- const r = p.rects[grab.id];
+ const r = v.rects[grab.id];
const col: i32 = @as(i32, at.col) - @as(i32, r.x + config.GUTTER);
const row: i32 = @as(i32, at.row) - @as(i32, p.bodyTop(pane, r));
const action: panes.terminal.MouseAction = switch (m.kind) {
@@ -435,10 +440,10 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
if (m.kind == .release) grab.held &= ~bit;
const bytes = panes.terminal.mouseBytes(pane, &buf, action, button, mods, col, row, grab.held != 0);
if (bytes.len > 0) p.emitWrite(grab.id, bytes);
- if (grab.held == 0) p.mouse_grab = null;
+ if (grab.held == 0) v.mouse_grab = null;
return true;
}
- if (p.drag != .none or p.header_drag or p.header_sweep != null) return false;
+ if (v.drag != .none or v.header_drag or v.header_sweep != null) return false;
const shifted_to_program = m.button == .middle or m.button == .right;
if (m.shift != shifted_to_program) return false;
if (shifted_to_program) mods.shift = false;
@@ -449,14 +454,14 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
const cell = programCell(p, id, mapped.col, mapped.row) orelse return false;
switch (m.kind) {
.press => {
- if (id != p.active) if (p.panes[p.active]) |previous| {
+ if (id != v.active) if (p.panes[v.active]) |previous| {
previous.focus = .body;
previous.closePrompt();
};
- p.active = id;
+ v.active = id;
pane.focus = .body;
pane.closePrompt();
- p.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program };
+ v.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program };
const bytes = panes.terminal.mouseBytes(pane, &buf, .press, button, mods, cell.col, cell.row, true);
if (bytes.len > 0) p.emitWrite(id, bytes);
return true;
@@ -480,20 +485,22 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
/// meanwhile. Ctrl-click keeps its own meaning (a definition). Run after
/// programMouse: a program that takes the click gets it as it was.
fn emulateButton(p: *Pardes, m: *Mouse) void {
+ const v = p.view();
if (m.button != .left) return;
- if (m.kind == .press) p.click_as = if (m.ctrl) null else if (m.super) .right else if (m.alt) .middle else null;
- const as = p.click_as orelse return;
+ if (m.kind == .press) v.click_as = if (m.ctrl) null else if (m.super) .right else if (m.alt) .middle else null;
+ const as = v.click_as orelse return;
m.button = as;
m.alt = false;
m.super = false;
- if (m.kind == .release) p.click_as = null;
+ if (m.kind == .release) v.click_as = null;
}
pub fn handleMouse(p: *Pardes, event: Mouse) void {
+ const v = p.view();
var m = event;
// A click goes somewhere else: the question it leaves unanswered is
// taken back, and the pane stays. A wheel only looks around.
- if (m.kind == .press) p.window_pick = null;
+ if (m.kind == .press) v.window_pick = null;
if (m.kind == .press and switch (m.button) {
.left, .middle, .right => true,
else => false,
@@ -508,37 +515,37 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// A grip let go past the window's edge, as a browser's tab dragged out
// of its window: the pane or column goes to another window. Inside, the
// grip's drag is the layout move below, as it always was.
- if (m.kind == .release and m.outside and m.button == config.select_button) switch (p.drag) {
+ if (m.kind == .release and m.outside and m.button == config.select_button) switch (v.drag) {
.move => |d| {
- p.drag = .none;
+ v.drag = .none;
return p.handover.begin(p, .pane, d.id);
},
.column_move => |d| {
- p.drag = .none;
+ v.drag = .none;
const column = layout.columnBySerial(p, d.serial) orelse return;
return p.handover.begin(p, .column, column);
},
else => {},
};
- const raw_col = @min(m.col, p.screen_w -| 1);
- const raw_row = @min(m.row, p.screen_h -| 1);
- p.pointer_raw_col = raw_col;
- p.pointer_raw_row = raw_row;
- const previous_hit = p.pointer_body_hit;
- p.pointer_body_hit = m.body_hit;
- const previous_tag_hit = p.pointer_tag_hit;
- p.pointer_tag_hit = if (m.tag_hit) |point| layout.reprojectTagHit(p, point) else null;
- if (m.tag_hit != null and p.pointer_tag_hit == null and m.kind == .press) return;
- if (m.tag_hit == null and (m.kind == .drag or m.kind == .release) and (p.drag == .select or p.header_drag or p.header_sweep != null)) {
+ const raw_col = @min(m.col, v.screen_w -| 1);
+ const raw_row = @min(m.row, v.screen_h -| 1);
+ v.pointer_raw_col = raw_col;
+ v.pointer_raw_row = raw_row;
+ const previous_hit = v.pointer_body_hit;
+ v.pointer_body_hit = m.body_hit;
+ const previous_tag_hit = v.pointer_tag_hit;
+ v.pointer_tag_hit = if (m.tag_hit) |point| layout.reprojectTagHit(p, point) else null;
+ if (m.tag_hit != null and v.pointer_tag_hit == null and m.kind == .press) return;
+ if (m.tag_hit == null and (m.kind == .drag or m.kind == .release) and (v.drag == .select or v.header_drag or v.header_sweep != null)) {
if (previous_tag_hit) |previous| {
var continued = previous;
continued.pixel_x = (@as(f32, @floatFromInt(raw_col)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_w));
continued.pixel_y = (@as(f32, @floatFromInt(raw_row)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_h));
- p.pointer_tag_hit = continued;
+ v.pointer_tag_hit = continued;
}
}
- if ((m.kind == .drag or m.kind == .release) and (p.drag == .select or p.header_drag or p.header_sweep != null)) {
- if (previous_tag_hit) |previous| if (p.pointer_tag_hit) |*current| {
+ if ((m.kind == .drag or m.kind == .release) and (v.drag == .select or v.header_drag or v.header_sweep != null)) {
+ if (previous_tag_hit) |previous| if (v.pointer_tag_hit) |*current| {
current.kind = previous.kind;
current.id = previous.id;
current.serial = previous.serial;
@@ -548,43 +555,43 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
// A drag can leave the compact text viewport. Preserve its metrics so
// the endpoint still clamps to that body's last visible logical row.
- if (m.body_hit == null and (m.kind == .drag or m.kind == .release) and p.drag == .select) {
+ if (m.body_hit == null and (m.kind == .drag or m.kind == .release) and v.drag == .select) {
if (previous_hit) |previous| {
var continued = previous;
continued.pixel_x = (@as(f32, @floatFromInt(raw_col)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_w));
continued.pixel_y = (@as(f32, @floatFromInt(raw_row)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_h));
- p.pointer_body_hit = continued;
+ v.pointer_body_hit = continued;
}
}
- p.pointer_inside = true;
+ v.pointer_inside = true;
if (kindMouse(p, m)) return;
if (programMouse(p, m)) return;
emulateButton(p, &m);
if (m.button == .none and m.kind == .motion) {
- p.raw_hover_intent = true;
+ v.raw_hover_intent = true;
look.refreshLookHoverFromRaw(p);
return;
}
- p.raw_hover_intent = false;
+ v.raw_hover_intent = false;
const mapped: struct { col: u16, row: u16 } = .{ .col = raw_col, .row = raw_row };
const mcol = mapped.col;
const mrow = mapped.row;
- p.hover_col = mcol;
- p.hover_row = mrow;
+ v.hover_col = mcol;
+ v.hover_row = mrow;
const hovered = paneAt(p, mcol, mrow);
// any press that is NOT the execute+select chord abandons a pending
// chord argument
if (m.kind == .press and
- !(m.button == config.select_button and p.drag == .select and p.drag.select.button == config.exec_button))
+ !(m.button == config.select_button and v.drag == .select and v.drag.select.button == config.exec_button))
{
- if (p.chord_arg) |a| {
+ if (v.chord_arg) |a| {
p.gpa.free(a);
- p.chord_arg = null;
+ v.chord_arg = null;
}
}
- if (p.header_sweep) |*sweep| {
+ if (v.header_sweep) |*sweep| {
if (m.kind == .press and switch (m.button) {
.left, .middle, .right => true,
else => false,
@@ -593,36 +600,36 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// sweep. The select button is inert: a header's command already
// takes the held selection as its argument, which is what a 2-1
// chord would give it.
- if (m.button != config.select_button) p.header_sweep = null;
+ if (m.button != config.select_button) v.header_sweep = null;
return;
}
if (m.button == sweep.button and (m.kind == .drag or m.kind == .release)) {
const column = sweep.column(p) catch {
- p.header_sweep = null;
+ v.header_sweep = null;
return;
};
if (headerPoint(p, column, mcol, mrow, true)) |point| sweep.cur = point.at;
if (m.kind == .release) {
const done = sweep.*;
- p.header_sweep = null;
+ v.header_sweep = null;
headerSweepRun(p, done);
}
return;
}
}
if (mrow >= p.topBarHeight() and mrow < p.topBarHeight() + layout.columnBarHeight(p) and m.kind == .press) {
- for (0..p.ncol) |column| {
- if (mcol < p.col_x[column] or mcol >= p.col_x[column] + @min(config.GUTTER, p.col_w[column])) continue;
+ for (0..p.view().ncol) |column| {
+ if (mcol < v.col_x[column] or mcol >= v.col_x[column] + @min(config.GUTTER, v.col_w[column])) continue;
if (m.button == config.select_button) {
- p.header_drag = false;
- p.drag = .{ .column_move = .{ .serial = p.cols[column].serial, .cur_x = mcol, .grab = mcol - p.col_x[column] } };
+ v.header_drag = false;
+ v.drag = .{ .column_move = .{ .serial = v.cols[column].serial, .cur_x = mcol, .grab = mcol - v.col_x[column] } };
}
return;
}
}
- if (p.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) {
+ if (v.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) {
if (tagline.focusedHeader(p) == null) {
- p.header_drag = false;
+ v.header_drag = false;
return;
}
// Held to the focused header's rows and text; the anchor stays
@@ -632,13 +639,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
t.cur_row = point.line;
t.cur_col = @intCast(point.at - modal.lineStartOffset(point.text, point.line));
t.vsel.active = t.vsel.row != t.cur_row or t.vsel.col != t.cur_col;
- if (m.kind == .release) p.header_drag = false;
+ if (m.kind == .release) v.header_drag = false;
return;
}
if (mrow < p.topBarHeight() + layout.columnBarHeight(p) and m.kind == .press and
(m.button == config.select_button or m.button == config.exec_button or m.button == config.look_button))
{
- if (m.button == config.select_button) if (p.panes[p.active]) |pane| {
+ if (m.button == config.select_button) if (p.panes[v.active]) |pane| {
pane.focus = .body;
pane.closePrompt();
};
@@ -646,11 +653,11 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
var x: u16 = TAG_TEXT_INSET;
if (mcol < x) return;
if (mrow >= p.topBarHeight()) {
- for (0..p.ncol) |c| if (mcol >= p.col_x[c] and mcol < p.col_x[c] + p.col_w[c]) {
+ for (0..p.view().ncol) |c| if (mcol >= v.col_x[c] and mcol < v.col_x[c] + v.col_w[c]) {
column = c;
- x = p.col_x[c] + TAG_TEXT_INSET;
- if (layout.findPane(p, p.active)) |active_col| {
- if (active_col.col != c and p.cols[c].n > 0) p.active = p.cols[c].panes[0];
+ x = v.col_x[c] + TAG_TEXT_INSET;
+ if (layout.findPane(p, v.active)) |active_col| {
+ if (active_col.col != c and v.cols[c].n > 0) v.active = v.cols[c].panes[0];
}
break;
};
@@ -661,17 +668,17 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
const t = point.t;
const at = point.at - modal.lineStartOffset(point.text, point.line);
// A clicked header starts in normal mode, as a clicked tag does.
- if (!(p.header != null and p.headerColumn() == column)) tagline.enterHeader(p, column);
+ if (!(v.header != null and p.headerColumn() == column)) tagline.enterHeader(p, column);
t.mode = .normal;
t.cur_row = point.line;
t.cur_col = @intCast(at);
t.vsel = .{ .active = false, .row = point.line, .col = @intCast(at) };
- p.header_drag = true;
+ v.header_drag = true;
} else {
// Held, as a pane tag's sweep is: it runs when the button
// comes up (headerSweepRun).
- p.header_sweep = .{
- .serial = if (column) |c| p.cols[c].serial else null,
+ v.header_sweep = .{
+ .serial = if (column) |c| v.cols[c].serial else null,
.button = m.button,
.anchor = point.at,
.cur = point.at,
@@ -689,7 +696,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
if (m.kind != .press) return;
// re-arms the drift guard below; vertical always scrolls, so
// the answer is never in doubt here
- _ = config.wheelTick(&p.wheel_guard, true);
+ _ = config.wheelTick(&v.wheel_guard, true);
const id = hovered orelse return;
const pane = p.panes[id].?;
if (pane.hasPdf())
@@ -699,7 +706,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
},
.wheel_left, .wheel_right => {
if (m.kind != .press) return;
- if (!config.wheelTick(&p.wheel_guard, false)) return;
+ if (!config.wheelTick(&v.wheel_guard, false)) return;
const id = hovered orelse return;
const pane = p.panes[id].?;
if (programWheel(p, id, m, mcol, mrow)) {
@@ -721,67 +728,67 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
},
config.select_button => switch (m.kind) {
.press => {
- if (p.drag == .select and p.drag.select.button == config.exec_button) {
- if (exec.heldSelection(p, p.drag.select.id)) |tx| {
- if (p.chord_arg) |old| p.gpa.free(old);
- p.chord_arg = p.gpa.dupe(u8, tx) catch null;
+ if (v.drag == .select and v.drag.select.button == config.exec_button) {
+ if (exec.heldSelection(p, v.drag.select.id)) |tx| {
+ if (v.chord_arg) |old| p.gpa.free(old);
+ v.chord_arg = p.gpa.dupe(u8, tx) catch null;
}
return;
}
// acme 3-1: a select tap during a LOOK drag cancels the
// look; the rest of the gesture is inert
- if (p.drag == .select and p.drag.select.button == config.look_button) {
- if (p.panes[p.drag.select.id]) |t| {
+ if (v.drag == .select and v.drag.select.button == config.look_button) {
+ if (p.panes[v.drag.select.id]) |t| {
t.sel[@backingInt(config.look_button)].state = .none;
if (comptime pdf_enabled)
- panes.Pdf.pointerCancel(t, p.drag.select.pdf);
+ panes.Pdf.pointerCancel(t, v.drag.select.pdf);
}
- p.drag = .none;
+ v.drag = .none;
return;
}
if (hovered) |mid| {
- const mr = p.rects[mid];
+ const mr = v.rects[mid];
const mpane = p.panes[mid].?;
const mtag = p.tagTop(mpane, mr);
if (mcol < mr.x + config.GUTTER and mrow >= mtag and mrow < mtag + mpane.tag_rows) {
- p.drag = .{ .move = .{ .id = mid, .cur_x = mcol, .cur_y = mrow } };
+ v.drag = .{ .move = .{ .id = mid, .cur_x = mcol, .cur_y = mrow } };
return;
}
}
- for (0..p.ncol -| 1) |c| {
- if (mcol == p.col_x[c] + p.col_w[c] -| 1) {
+ for (0..p.view().ncol -| 1) |c| {
+ if (mcol == v.col_x[c] + v.col_w[c] -| 1) {
const corner: @FieldType(@FieldType(Drag, "border_v"), "corner") = if (seamIdxAt(p, c, mrow)) |k|
.{ .col = c, .idx = k }
else if (seamIdxAt(p, c + 1, mrow)) |k|
.{ .col = c + 1, .idx = k }
else
null;
- p.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } };
+ v.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } };
return;
}
}
// Two panes are resized on the rule between them, never on a
// row of text; with no rule, by the grip, as acme moves a
// window by its button.
- if (m.rule_above and mrow > 0) for (0..p.ncol) |cc| {
- if (mcol < p.col_x[cc] or mcol >= p.col_x[cc] + p.col_w[cc]) continue;
+ if (m.rule_above and mrow > 0) for (0..p.view().ncol) |cc| {
+ if (mcol < v.col_x[cc] or mcol >= v.col_x[cc] + v.col_w[cc]) continue;
const seam = mrow - 1;
if (seamIdxAt(p, cc, seam)) |k| {
- p.drag = .{ .border_h = .{ .col = cc, .top_idx = k, .cur_y = seam } };
+ v.drag = .{ .border_h = .{ .col = cc, .top_idx = k, .cur_y = seam } };
return;
}
};
const id = hovered orelse return;
- const r = p.rects[id];
+ const r = v.rects[id];
const pane = p.panes[id] orelse return;
- if (id != p.active) if (p.panes[p.active]) |previous| {
+ if (id != v.active) if (p.panes[v.active]) |previous| {
previous.focus = .body;
previous.closePrompt();
};
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
if (mcol < r.x + config.GUTTER) {
- p.active = id;
+ v.active = id;
// A tick of the pane's places: that place, selected and in view.
// The rail is chrome, and only the tick's cell does this.
const rail_h = r.h -| pane.tag_rows;
@@ -794,10 +801,10 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
} else {
const on_tag = mrow >= tag_y and mrow < tag_y + pane.tag_rows;
if (on_tag and mcol < r.x + TAG_TEXT_INSET) return;
- p.active = id;
+ v.active = id;
layout.noteTyped(p); // acme's button 1 sets activecol (acme.c:659)
pane.closePrompt();
- const pointed = edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit) orelse return;
+ const pointed = edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, v.pointer_tag_hit) orelse return;
pane.clearPointerSelection(sel_slot);
pane.sel[sel_slot] = pointed.sel;
// A clicked tag starts in normal mode, its cursor where it
@@ -815,7 +822,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.tag.cur_row = @intCast(at.row);
pane.tag.cur_col = @intCast(at.col);
}
- p.drag = .{ .select = .{
+ v.drag = .{ .select = .{
.id = id,
.button = config.select_button,
.ctrl = m.ctrl,
@@ -831,9 +838,9 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
} };
}
},
- .drag => dragUpdate(p, mcol, mrow, p.pointer_body_hit),
+ .drag => dragUpdate(p, mcol, mrow, v.pointer_body_hit),
.release => {
- if ((p.pointer_body_hit != null or p.pointer_tag_hit != null or p.drag == .column_move) and p.drag.button() == m.button) dragUpdate(p, mcol, mrow, p.pointer_body_hit);
+ if ((v.pointer_body_hit != null or v.pointer_tag_hit != null or v.drag == .column_move) and v.drag.button() == m.button) dragUpdate(p, mcol, mrow, v.pointer_body_hit);
dragRelease(p, config.select_button);
},
.motion => {},
@@ -842,23 +849,23 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
.press => {
// acme 1-2 / 1-3: the execute (Cut) or look (Paste) button
// tapped while the select button holds a selection drag
- if (p.drag == .select and p.drag.select.button == config.select_button) {
+ if (v.drag == .select and v.drag.select.button == config.select_button) {
chordCutPaste(p, m.button == config.exec_button);
return;
}
// acme 2-3 / 3-2: tapping the OTHER of execute/look during
// an execute or look drag cancels it (textselect23's mask)
- if (p.drag == .select) {
- if (p.panes[p.drag.select.id]) |t| {
- t.sel[@backingInt(p.drag.select.button)].state = .none;
+ if (v.drag == .select) {
+ if (p.panes[v.drag.select.id]) |t| {
+ t.sel[@backingInt(v.drag.select.button)].state = .none;
if (comptime pdf_enabled)
- panes.Pdf.pointerCancel(t, p.drag.select.pdf);
+ panes.Pdf.pointerCancel(t, v.drag.select.pdf);
}
- p.drag = .none;
+ v.drag = .none;
return;
}
const id = hovered orelse return;
- const r = p.rects[id];
+ const r = v.rects[id];
const pane = p.panes[id] orelse return;
// the tag row and the body's first, exactly as the select
// arm above derives them
@@ -867,13 +874,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
const on_tag = mrow >= tag_y and mrow < tag_y + pane.tag_rows;
if (mcol < r.x + config.GUTTER and !on_tag) {
const local = @as(i32, mrow) - @as(i32, body_y);
- if (m.button == config.look_button) p.active = id;
+ if (m.button == config.look_button) v.active = id;
pane.scrollBy(if (m.button == config.look_button) local else -local);
- } else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit)) |pointed| {
- if (m.button == config.look_button) p.active = id;
+ } else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, v.pointer_tag_hit)) |pointed| {
+ if (m.button == config.look_button) v.active = id;
pane.clearPointerSelection(@backingInt(m.button));
pane.sel[@backingInt(m.button)] = pointed.sel;
- p.drag = .{
+ v.drag = .{
.select = .{
.id = id,
.button = m.button,
@@ -892,9 +899,9 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
};
}
},
- .drag => dragUpdate(p, mcol, mrow, p.pointer_body_hit),
+ .drag => dragUpdate(p, mcol, mrow, v.pointer_body_hit),
.release => {
- if ((p.pointer_body_hit != null or p.pointer_tag_hit != null or p.drag == .column_move) and p.drag.button() == m.button) dragUpdate(p, mcol, mrow, p.pointer_body_hit);
+ if ((v.pointer_body_hit != null or v.pointer_tag_hit != null or v.drag == .column_move) and v.drag.button() == m.button) dragUpdate(p, mcol, mrow, v.pointer_body_hit);
dragRelease(p, m.button);
},
.motion => {},
@@ -905,22 +912,23 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
/// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen
/// row `mrow`. Out-of-range columns simply have no seam.
fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize {
- if (c >= p.ncol) return null;
- for (0..p.cols[c].n -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k;
+ if (c >= p.view().ncol) return null;
+ for (0..p.view().cols[c].n -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k;
return null;
}
pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) void {
- switch (p.drag) {
+ const v = p.view();
+ switch (v.drag) {
.border_v => |*d| {
const c = d.left_col;
- d.cur_x = if (c + 1 < p.ncol)
- clampBorderCol(p.col_x[c], p.col_w[c], p.col_w[c + 1], mcol)
+ d.cur_x = if (c + 1 < v.ncol)
+ clampBorderCol(v.col_x[c], v.col_w[c], v.col_w[c + 1], mcol)
else
mcol;
- if (d.corner) |k| if (k.idx + 1 < p.cols[k.col].n) {
- const a = p.rects[p.cols[k.col].panes[k.idx]];
- const b = p.rects[p.cols[k.col].panes[k.idx + 1]];
+ if (d.corner) |k| if (k.idx + 1 < v.cols[k.col].n) {
+ const a = v.rects[v.cols[k.col].panes[k.idx]];
+ const b = v.rects[v.cols[k.col].panes[k.idx + 1]];
d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow);
} else {
d.cur_y = mrow;
@@ -929,9 +937,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
.border_h => |*d| {
const cc = d.col;
const k = d.top_idx;
- if (k + 1 < p.cols[cc].n) {
- const a = p.rects[p.cols[cc].panes[k]];
- const b = p.rects[p.cols[cc].panes[k + 1]];
+ if (k + 1 < v.cols[cc].n) {
+ const a = v.rects[v.cols[cc].panes[k]];
+ const b = v.rects[v.cols[cc].panes[k + 1]];
// Held by the rule over the lower pane: the seam is the row above.
d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow -| 1);
} else d.cur_y = mrow;
@@ -943,7 +951,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
},
.select => |*s| {
if (p.panes[s.id]) |pane| {
- const r = p.rects[s.id];
+ const r = v.rects[s.id];
const b = @backingInt(s.button);
const tag_rows: i32 = pane.tag_rows;
panes.File.geometry(pane);
@@ -958,7 +966,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
// nearest the pointer.
const tag_y = p.tagTop(pane, r);
const tag_line: u16 = @intCast(std.math.clamp(@as(i32, mrow) - @as(i32, tag_y), 0, tag_rows - 1));
- if (pane.sel[b].r0 < tag_rows) if (Layer.columnAt(p, .pane, s.id, p.pointer_tag_hit, true, tag_line)) |value| {
+ if (pane.sel[b].r0 < tag_rows) if (Layer.columnAt(p, .pane, s.id, v.pointer_tag_hit, true, tag_line)) |value| {
pane.sel[b].c1 = @as(i32, value) + pane.tag_scroll;
pane.sel[b].r1 = tag_line;
return;
@@ -978,7 +986,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
else if (mrow >= body_y + body_h or
// The pointer cannot leave the screen: at a bottom pane,
// its last row is the edge.
- (body_y + body_h >= p.screen_h and mrow + 1 >= body_y + body_h))
+ (body_y + body_h >= v.screen_h and mrow + 1 >= body_y + body_h))
1
else
0;
@@ -1105,8 +1113,8 @@ pub fn dispatchPointerBuiltin(
text: ?[]const u8,
gesture: ?struct { on_tag: bool, operand: exec.PointerOperand },
) void {
- const arg = p.chord_arg;
- p.chord_arg = null;
+ const arg = p.view().chord_arg;
+ p.view().chord_arg = null;
defer if (arg) |a| p.gpa.free(a);
// A click that takes no text does nothing, and tells an event reader
// nothing, as acme's look3 and execute return on an empty expansion.
@@ -1158,14 +1166,15 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void {
/// second selects what edit.doubleClickRange says, from the caret the click
/// left. A plain click still puts the caret on its cell.
fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, col: i32) void {
+ const v = p.view();
// The host's clock, which every host keeps and a test's virtual one
// replaces.
const now: i64 = @intCast(p.clock.now_ns / std.time.ns_per_ms);
- const prev = p.last_click;
- p.last_click = .{ .id = id, .on_tag = on_tag, .row = row, .col = col, .ms = now };
+ const prev = v.last_click;
+ v.last_click = .{ .id = id, .on_tag = on_tag, .row = row, .col = col, .ms = now };
const c = prev orelse return;
if (c.id != id or c.on_tag != on_tag or c.row != row or c.col != col or now - c.ms > 500) return;
- p.last_click = null;
+ v.last_click = null;
const text = edit.flatSurface(p, t) catch return;
const q = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
const r = edit.doubleClickRange(text, q);
@@ -1182,8 +1191,8 @@ fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, co
/// scrolls a line toward it, the sweep's end stays under the pointer and
/// its start stays on its text (Drag.select.anchor).
pub fn edgeScroll(p: *Pardes) void {
- if (p.drag != .select) return;
- const s = &p.drag.select;
+ if (p.view().drag != .select) return;
+ const s = &p.view().drag.select;
if (s.edge == 0) return;
const pane = p.panes[s.id] orelse return;
const sl = &pane.sel[sel_slot];
@@ -1207,19 +1216,20 @@ fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor {
}
fn dragRelease(p: *Pardes, button: Mouse.Button) void {
+ const v = p.view();
// A different button's release belongs to a chord or another host
// stream; only the button which began this gesture may end it.
- if (p.drag.button() != button) return;
- defer p.drag = .none;
- defer p.chord_hold = false;
- switch (p.drag) {
+ if (v.drag.button() != button) return;
+ defer v.drag = .none;
+ defer v.chord_hold = false;
+ switch (v.drag) {
.border_v => |d| {
const c = d.left_col;
- const old_seam = p.col_x[c] + p.col_w[c] -| 1;
+ const old_seam = v.col_x[c] + v.col_w[c] -| 1;
// the handle is the left pane's LAST column (inclusive), so
// the new width includes it — a no-drag click changes nothing
- if (c + 1 < p.ncol and d.cur_x != old_seam)
- layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| p.col_x[c]);
+ if (c + 1 < v.ncol and d.cur_x != old_seam)
+ layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| v.col_x[c]);
if (d.corner) |k| {
if (d.cur_y != seamRowOf(p, k.col, k.idx))
layout.applyRowSplit(p, k.col, k.idx, d.cur_y);
@@ -1233,7 +1243,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
layout.reorderColumn(p, column, target);
p.setActiveColumn(target); // a grip drag sets activecol (acme.c:640)
},
- .edge => |x| layout.setColumnPairWidth(p, column - 1, x - p.col_x[column - 1]),
+ .edge => |x| layout.setColumnPairWidth(p, column - 1, x - v.col_x[column - 1]),
},
.move => |d| {
layout.movePane(p, d.id, d.cur_x, d.cur_y);
@@ -1315,7 +1325,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
pane.body.sticky_col = -1;
// A ctrl-click is a definition jump, not half a double-click.
if (!dragged and !s.ctrl) doubleClick(p, s.id, &pane.body, false, sl.r1, sl.c1);
- if (s.ctrl) p.last_click = null;
+ if (s.ctrl) v.last_click = null;
// A sweep that scrolled has its start off the screen: it
// is kept as the text's own selection, start to end.
if (dragged) if (s.anchor) |a| {
@@ -1390,7 +1400,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
}
fn chordCutPaste(p: *Pardes, cut: bool) void {
- const s = &p.drag.select;
+ const s = &p.view().drag.select;
const pane = p.panes[s.id] orelse return;
if (comptime pdf_enabled) if (pane.pdf) |pv| {
if (!s.chorded) {
@@ -1460,7 +1470,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) void {
// marks the file once per B1 hold (text.c:881 textselect, `state`
// and its one filemark): B1-B2 then B1-B3 is a copy.
edit.pushUndo(p, &pane.body);
- p.chord_hold = true;
+ p.view().chord_hold = true;
const sl = pane.sel[sel_slot];
pane.sel[sel_slot].state = .none;
const pfx: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0;
@@ -1521,7 +1531,7 @@ test "plain left click clears explicit modal selection" {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const click_x = rect.x + config.GUTTER + config.PREFIX_W + 3;
const body_y = rect.y + BOX_H;
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = click_x, .row = body_y } });
@@ -1536,14 +1546,14 @@ test "a selection drag and its release leave the selection done" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 10, .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("alpha beta\n");
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + config.PREFIX_W + 1;
const y = rect.y + BOX_H;
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x + 2, .row = y } });
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x + 2, .row = y } });
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
try std.testing.expectEqual(.done, pane.sel[sel_slot].state);
}
@@ -1586,19 +1596,19 @@ test "a corner drag's two axes clamp independently" {
test "a v-handle press at the RIGHT column's seam drags both boundaries" {
const p = try cornerFixture(std.testing.allocator);
defer p.deinit();
- try std.testing.expectEqual(@as(usize, 2), p.cols[1].n);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n);
- const handle = p.col_x[0] + p.col_w[0] - 1;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
const right_seam = nudgeRightSeam(p, 3);
try std.testing.expect(right_seam != seamRowOf(p, 0, 0));
- const w0 = p.cols[0].weight;
- const v_left = p.panes[p.cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.cols[1].panes[0]].?.vweight;
+ const w0 = p.view().cols[0].weight;
+ const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
+ const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expect(p.drag == .border_v);
- const corner = p.drag.border_v.corner orelse return error.NoCorner;
+ try std.testing.expect(p.view().drag == .border_v);
+ const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
try std.testing.expectEqual(@as(usize, 1), corner.col);
try std.testing.expectEqual(@as(usize, 0), corner.idx);
@@ -1608,9 +1618,9 @@ test "a v-handle press at the RIGHT column's seam drags both boundaries" {
// both halves committed: the column pair widened, and the RIGHT column's
// pane pair reweighted — while the left column's panes stayed put
- try std.testing.expect(p.cols[0].weight > w0);
- try std.testing.expect(p.panes[p.cols[1].panes[0]].?.vweight != v_right);
- try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight);
+ try std.testing.expect(p.view().cols[0].weight > w0);
+ try std.testing.expect(p.panes[p.view().cols[1].panes[0]].?.vweight != v_right);
+ try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
}
test "a tie row still moves the LEFT column's pane pair only" {
@@ -1623,19 +1633,19 @@ test "a tie row still moves the LEFT column's pane pair only" {
_ = nudgeRightSeam(p, @as(i32, left_seam) - @as(i32, seamRowOf(p, 1, 0)));
try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0));
- const handle = p.col_x[0] + p.col_w[0] - 1;
- const v_left = p.panes[p.cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.cols[1].panes[0]].?.vweight;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
+ const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
+ const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } });
- const corner = p.drag.border_v.corner orelse return error.NoCorner;
+ const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
try std.testing.expectEqual(@as(usize, 0), corner.col);
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } });
p.sync();
- try std.testing.expect(p.panes[p.cols[0].panes[0]].?.vweight != v_left);
- try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight);
+ try std.testing.expect(p.panes[p.view().cols[0].panes[0]].?.vweight != v_left);
+ try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
}
test "a v-handle press at nobody's seam is still a plain edge drag" {
@@ -1644,44 +1654,44 @@ test "a v-handle press at nobody's seam is still a plain edge drag" {
const right_seam = nudgeRightSeam(p, 3);
const left_seam = seamRowOf(p, 0, 0);
- const handle = p.col_x[0] + p.col_w[0] - 1;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
var row: u16 = TOPBAR_H + 1;
while (row == left_seam or row == right_seam) row += 1;
- const w0 = p.cols[0].weight;
- const v_left = p.panes[p.cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.cols[1].panes[0]].?.vweight;
+ const w0 = p.view().cols[0].weight;
+ const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
+ const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } });
- try std.testing.expect(p.drag == .border_v);
- try std.testing.expect(p.drag.border_v.corner == null);
+ try std.testing.expect(p.view().drag == .border_v);
+ try std.testing.expect(p.view().drag.border_v.corner == null);
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = row + 5 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } });
p.sync();
// exactly ONE boundary moved
- try std.testing.expect(p.cols[0].weight > w0);
- try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight);
- try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight);
+ try std.testing.expect(p.view().cols[0].weight > w0);
+ try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
+ try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
}
test "a RIGHT-column corner's two axes clamp independently" {
const p = try cornerFixture(std.testing.allocator);
defer p.deinit();
const right_seam = nudgeRightSeam(p, 3);
- const handle = p.col_x[0] + p.col_w[0] - 1;
+ const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expectEqual(@as(usize, 1), (p.drag.border_v.corner orelse return error.NoCorner).col);
+ try std.testing.expectEqual(@as(usize, 1), (p.view().drag.border_v.corner orelse return error.NoCorner).col);
// off the right edge at mid-height: x parks at its MINW wall, y is the mouse
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 999, .row = right_seam } });
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.drag.border_v.cur_x);
- try std.testing.expectEqual(right_seam, p.drag.border_v.cur_y);
+ try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.view().drag.border_v.cur_x);
+ try std.testing.expectEqual(right_seam, p.view().drag.border_v.cur_y);
// and the mirror: below the bottom at mid-width. y parks, x tracks again
p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } });
- try std.testing.expectEqual(handle, p.drag.border_v.cur_x);
- const a = p.rects[p.cols[1].panes[0]];
- const b = p.rects[p.cols[1].panes[1]];
- try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.drag.border_v.cur_y);
+ try std.testing.expectEqual(handle, p.view().drag.border_v.cur_x);
+ const a = p.view().rects[p.view().cols[1].panes[0]];
+ const b = p.view().rects[p.view().cols[1].panes[1]];
+ try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.view().drag.border_v.cur_y);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } });
}
@@ -1690,20 +1700,20 @@ test "mouse thumb buttons navigate once and clear selection gestures" {
defer p.deinit();
const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n");
pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
- p.jumps.n = 3;
- p.jumps.cur = 2;
- for (0..3) |i| p.jumps.list[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 };
- p.drag = .{ .select = .{ .id = 0, .button = config.select_button } };
+ p.view().jumps.n = 3;
+ p.view().jumps.cur = 2;
+ for (0..3) |i| p.view().jumps.list[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 };
+ p.view().drag = .{ .select = .{ .id = 0, .button = config.select_button } };
p.update(.{ .mouse = .{ .button = .back, .kind = .press, .col = 0, .row = 0 } });
- try std.testing.expectEqual(@as(usize, 1), p.jumps.cur);
+ try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur);
for ([_]Mouse.Kind{ .drag, .release, .motion }) |kind|
p.update(.{ .mouse = .{ .button = .back, .kind = kind, .col = 0, .row = 0 } });
- try std.testing.expectEqual(@as(usize, 1), p.jumps.cur);
+ try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur);
p.update(.{ .mouse = .{ .button = .forward, .kind = .press, .col = 0, .row = 0 } });
p.update(.{ .mouse = .{ .button = .forward, .kind = .release, .col = 0, .row = 0 } });
- try std.testing.expectEqual(@as(usize, 2), p.jumps.cur);
+ try std.testing.expectEqual(@as(usize, 2), p.view().jumps.cur);
try std.testing.expect(!pane.body.vsel.active);
- try std.testing.expectEqual(.none, p.drag);
+ try std.testing.expectEqual(.none, p.view().drag);
}
test "a chorded exec an event reader holds is told with its argument, and written back runs with it" {
@@ -1715,7 +1725,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte
const h = th.call(p, .{ .tag = 1, .op = .open, .node = event, .omode = 2 }).reply.handle;
// The argument: a selection held in the pane (its second line).
ctlfs.pane.setDot(p.panes[0].?, .{ .q0 = 9, .q1 = 17 });
- p.chord_arg = try p.gpa.dupe(u8, "arg-text");
+ p.view().chord_arg = try p.gpa.dupe(u8, "arg-text");
dispatchPointerBuiltin(p, 0, config.exec_cmd, "Msg", .{ .on_tag = false, .operand = .{ .row = 0, .col = 1, .text = "Msg" } });
var records: [3][]const u8 = undefined;
var got: [3][64]u8 = undefined;
@@ -1763,7 +1773,7 @@ test "a wheel over a program that owns it is the program's, in the form it asked
var out: [4096]u8 = undefined;
_ = pardes.test_api.ptyBytes(p, 0, &out);
const pane = p.panes[0].?;
- const r = p.rects[0];
+ const r = p.view().rects[0];
// Grid cell 6,4 (1-based), as a program counts.
const col = r.x + config.GUTTER + 5;
const row = p.bodyTop(pane, r) + 3;
@@ -1824,28 +1834,28 @@ test "Alt-click is B2 and Super-click B3, kept from the press through the releas
defer p.deinit();
const file = try p.setTestFile("Newcol here\n");
p.presented();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const col = r.x + config.GUTTER + panes.File.gutterWidth(file) + 1;
const row = p.bodyTop(file, r);
// A Super-press sweeps with B3's selection, not B1's.
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .super = true } });
- try std.testing.expect(p.drag == .select and file.sel[2].state != .none and file.sel[0].state == .none);
+ try std.testing.expect(p.view().drag == .select and file.sel[2].state != .none and file.sel[0].state == .none);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } });
- try std.testing.expect(p.drag == .none);
- try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as);
+ try std.testing.expect(p.view().drag == .none);
+ try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as);
// Ctrl with Alt is Ctrl's: a B1 click (a definition), never B2.
- const cols = p.ncol;
+ const cols = p.view().ncol;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .ctrl = true, .alt = true } });
- try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as);
+ try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row, .ctrl = true } });
- try std.testing.expectEqual(cols, p.ncol);
+ try std.testing.expectEqual(cols, p.view().ncol);
// Alt-click on Newcol runs it, as B2 does, though Alt is let go
// before the button.
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .alt = true } });
- try std.testing.expectEqual(@as(?Mouse.Button, .middle), p.click_as);
+ try std.testing.expectEqual(@as(?Mouse.Button, .middle), p.view().click_as);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } });
- try std.testing.expectEqual(cols + 1, p.ncol);
- try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as);
+ try std.testing.expectEqual(cols + 1, p.view().ncol);
+ try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as);
}
test "a program tracking the mouse gets its clicks, drags and moves over its grid as xterm reports them; Shift and chrome stay pardes's" {
@@ -1859,7 +1869,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
_ = pardes.test_api.ptyBytes(p, 0, &out);
const pane = p.panes[0].?;
try std.testing.expectEqual(.tty, pane.body.mode);
- const r = p.rects[0];
+ const r = p.view().rects[0];
const col = r.x + config.GUTTER + 5;
const row = p.bodyTop(pane, r) + 3;
const Ev = struct { button: Mouse.Button, kind: Mouse.Kind, dx: i32 = 0, dy: i32 = 0, shift: bool = false, alt: bool = false, ctrl: bool = false, super: bool = false };
@@ -1882,7 +1892,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } });
_ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
// 1000 has no drags; the release is reported where it lands.
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .drag, .dx = 1 }));
try std.testing.expectEqualStrings("\x1b[<0;7;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .dx = 1 }));
@@ -1892,12 +1902,12 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
try std.testing.expectEqualStrings("\x1b[<0;6;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release }));
try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press, .super = true }));
try std.testing.expectEqualStrings("\x1b[<0;6;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .super = true }));
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
// B2 and B3 are pardes's execute and look, as in any pane.
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .right, .kind = .press }));
- try std.testing.expect(p.drag == .select);
+ try std.testing.expect(p.view().drag == .select);
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .right, .kind = .release }));
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
// Shift-B3 is the program's, the Shift that chose it left out: meta
// and ctrl, 2 + 8 + 16.
try std.testing.expectEqualStrings("\x1b[<26;6;4M", try send(p, &out, col, row, .{ .button = .right, .kind = .press, .shift = true, .alt = true, .ctrl = true }));
@@ -1908,10 +1918,10 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .none, .kind = .motion }));
// Shift: pardes's own sweep, the program hears nothing of it.
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .press, .shift = true }));
- try std.testing.expect(p.drag == .select);
+ try std.testing.expect(p.view().drag == .select);
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .drag, .dx = 2 }));
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .dx = 2 }));
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
// Chrome is never the program's: the tag, and the gutter.
const tag_row = p.tagTop(pane, r);
try std.testing.expectEqualStrings("", try send(p, &out, col, tag_row, .{ .button = .right, .kind = .press }));
@@ -1931,7 +1941,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
// Up over the tag: row 1, the grid's first.
try std.testing.expectEqualStrings("\x1b[<32;7;1M", try send(p, &out, col + 1, tag_row, .{ .button = .left, .kind = .drag }));
try std.testing.expectEqualStrings("\x1b[<0;7;1m", try send(p, &out, col + 1, tag_row, .{ .button = .left, .kind = .release }));
- try std.testing.expect(p.mouse_grab == null);
+ try std.testing.expect(p.view().mouse_grab == null);
// Over the tag a bare move is pardes's.
try std.testing.expectEqualStrings("", try send(p, &out, col, tag_row, .{ .button = .none, .kind = .motion }));
// B2 held for pardes: its sweep's moves are not the program's; held
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index 20ee2e3e..74d1f668 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -20,8 +20,8 @@ const E = tree.E;
/// else the active pane's. Null when the workspace tag has it and no pane
/// is active.
pub fn activeColumn(p: *const Pardes) ?usize {
- if (p.headerColumn()) |c| return if (c < p.ncol) c else null;
- const at = layout.findPane(p, p.active) orelse return null;
+ if (p.headerColumn()) |c| return if (c < p.view().ncol) c else null;
+ const at = layout.findPane(p, p.view().active) orelse return null;
return at.col;
}
@@ -32,13 +32,14 @@ pub fn activeColumn(p: *const Pardes) ?usize {
/// then `active <serial>`: the active column, where pane/new and a look
/// place a pane next (acme's activecol), not always the keyboard's.
pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void {
+ const v = p.view();
const active = activeColumn(p);
- for (0..p.ncol) |c| {
+ for (0..p.view().ncol) |c| {
try w.print("{d} {d} {d} {d} {s} {s}", .{
- layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c],
- if (active == c) "current" else "notcurrent", if (p.cols[c].n == 0) "empty" else "full",
+ layout.columnSerial(p, c), c, v.col_x[c], v.col_w[c],
+ if (active == c) "current" else "notcurrent", if (v.cols[c].n == 0) "empty" else "full",
});
- for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
+ for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
try w.writeByte('\n');
}
if (layout.activeColumn(p) orelse active) |c| try w.print("active {d}\n", .{layout.columnSerial(p, c)}) else try w.writeAll("active -\n");
@@ -51,7 +52,7 @@ const Header = struct { text: *Text, col: ?usize };
fn header(p: *Pardes, serial: ?u32) ?Header {
const s = serial orelse return .{ .text = &p.global_tag, .col = null };
const c = layout.columnBySerial(p, s) orelse return null;
- return .{ .text = &p.col_tags[c], .col = c };
+ return .{ .text = &p.view().col_tags[c], .col = c };
}
pub fn headerText(p: *Pardes, serial: ?u32) ?[]const u8 {
@@ -174,7 +175,7 @@ pub fn writeCtl(p: *Pardes, req: Req, serial: u32) Reply {
defer p.exec_column = null;
p.exec_header = true;
defer p.exec_header = false;
- if (pardes.ctlfs.ctl.runBuiltin(p, req, p.active, line)) |refusal| return refusal;
+ if (pardes.ctlfs.ctl.runBuiltin(p, req, p.view().active, line)) |refusal| return refusal;
}
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
@@ -206,7 +207,7 @@ pub fn writeExec(p: *Pardes, req: Req, serial: ?u32) Reply {
defer p.exec_column = null;
p.exec_header = true;
defer p.exec_header = false;
- if (pardes.ctlfs.ctl.captured(p, req, p.active, true, line, true)) |refusal| return refusal;
+ if (pardes.ctlfs.ctl.captured(p, req, p.view().active, true, line, true)) |refusal| return refusal;
}
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
@@ -220,7 +221,7 @@ test "New written to a column's exec makes its scratch in the session's director
const serial = layout.columnSerial(p, 0);
const exec_node = tree.Node.ofCol(serial, .exec);
try testing.expectEqual(tree.Status.ok, th.wr(p, exec_node, "New\n").reply.status);
- try testing.expectEqualStrings("/project/src/+New", p.panes[p.active].?.file.?.path);
+ try testing.expectEqualStrings("/project/src/+New", p.panes[p.view().active].?.file.?.path);
}
test "Joincol is refused when the joined column cannot give each pane its tag and 2 rows" {
@@ -237,15 +238,15 @@ test "Joincol is refused when the joined column cannot give each pane its tag an
var digits: [16]u8 = undefined;
_ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{b}));
_ = try th.newPane(p);
- try testing.expectEqual(@as(usize, 2), p.ncol);
- try testing.expect(p.cols[0].n >= 2 and p.cols[1].n >= 2);
+ try testing.expectEqual(@as(usize, 2), p.view().ncol);
+ try testing.expect(p.view().cols[0].n >= 2 and p.view().cols[1].n >= 2);
// Focus in the left column: joined, four panes want 12 rows of 10.
- const left = p.panes[p.cols[0].panes[0]].?.serial;
+ const left = p.panes[p.view().cols[0].panes[0]].?.serial;
_ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
const r = th.wr(p, ctl, "Joincol\n");
try testing.expectEqual(tree.Status.err, r.reply.status);
try testing.expect(std.mem.indexOf(u8, r.reply.ename, "tag and 2 rows") != null);
- try testing.expectEqual(@as(usize, 2), p.ncol);
+ try testing.expectEqual(@as(usize, 2), p.view().ncol);
try testing.expect(pardes.layout.minimaFit(p));
}
@@ -253,7 +254,7 @@ test "pane/new takes rows from a pane in another column before refusing ENOSPC"
const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 16 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const first = p.panes[p.active].?.serial;
+ const first = p.panes[p.view().active].?.serial;
// A second column holding one tall pane.
try testing.expectEqual(tree.Status.ok, th.wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status);
const tall = try th.newPane(p);
@@ -311,12 +312,12 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe
const made = try th.newPane(p);
const pane = p.panes[p.paneBySerial(made).?].?;
const col = layout.findPane(p, p.paneBySerial(made).?).?.col;
- for (p.cols[col].panes[0..p.cols[col].n]) |k| {
+ for (p.view().cols[col].panes[0..p.view().cols[col].n]) |k| {
const each = p.panes[k].?;
if (each.tag.own) |old| p.gpa.free(old);
each.tag.own = try p.gpa.dupe(u8, std.mem.asBytes(&@as([60][5]u8, @splat("word ".*))));
}
- try testing.expect(p.cols[col].n >= 2);
+ try testing.expect(p.view().cols[col].n >= 2);
p.sync();
const ctl = @backingInt(tree.TopFile.ctl);
const focus = @backingInt(tree.TopFile.focus);
@@ -354,7 +355,7 @@ test "a tagexec word that makes, acts on and focuses no pane reads back nothing"
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
try testing.expectEqual(tree.Status.ok, th.wr(p, col_exec, "New\n").reply.status);
var want: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.active].?.serial}), th.rd(p, col_exec, 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.view().active].?.serial}), th.rd(p, col_exec, 0, 64).bytes);
}
test "New written to a column's ctl reads back the new pane alone, as its exec does" {
@@ -365,7 +366,7 @@ test "New written to a column's ctl reads back the new pane alone, as its exec d
const ctl_node = tree.Node.ofCol(layout.columnSerial(p, 0), .ctl);
try testing.expectEqual(tree.Status.ok, th.wr(p, ctl_node, "New\n").reply.status);
var want: [16]u8 = undefined;
- try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.active].?.serial}), th.rd(p, root_exec, 0, 64).bytes);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.view().active].?.serial}), th.rd(p, root_exec, 0, 64).bytes);
}
/// Whether `line` names a builtin that acts on a pane (every one of pane
@@ -412,7 +413,7 @@ test "Help and Find at /tagexec act in the session's directory, not the keyboard
const tagexec = @backingInt(tree.TopFile.tagexec);
for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| {
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status);
- const made = p.panes[p.active].?.file.?.path;
+ const made = p.panes[p.view().active].?.file.?.path;
try testing.expectEqualStrings(session, std.fs.path.dirname(made).?);
}
}
@@ -421,11 +422,11 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const term = p.panes[p.active].?;
- try testing.expect(pardes.exec.takesCommandLine(p, p.active));
+ const term = p.panes[p.view().active].?;
+ try testing.expect(pardes.exec.takesCommandLine(p, p.view().active));
const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec);
for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| {
- p.active = p.paneBySerial(term.serial).?;
+ p.view().active = p.paneBySerial(term.serial).?;
const before = p.next_serial;
const r = th.wr(p, node, "echo from-the-tag\n");
try testing.expectEqual(tree.Status.ok, r.reply.status);
@@ -449,8 +450,8 @@ test "New and Term run at /tagexec and a column's exec, with no pane at all too"
};
// Every pane gone: the workspace tag makes one all the same.
for ([_][]const u8{ "New\n", "Term\n" }) |line| {
- while (p.ncol > 0) {
- const first = p.panes[p.cols[0].panes[0]].?.serial;
+ while (p.view().ncol > 0) {
+ const first = p.panes[p.view().cols[0].panes[0]].?.serial;
_ = th.wr(p, tree.Node.of(first, .ctl), "delete\n");
if (panes.anyPane(p) == null) break;
}
@@ -495,7 +496,7 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in
pub fn remove(p: *Pardes, req: Req, serial: u32, file: tree.ColFile) Reply {
if (file != .dir) return Reply.fail(req.tag, E.PERM);
const col = layout.columnBySerial(p, serial) orelse return Reply.fail(req.tag, E.NOENT);
- if (p.cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl");
+ if (p.view().cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl");
layout.removeColumn(p, col) catch return Reply.fail(req.tag, E.IO);
return .{ .tag = req.tag };
}
@@ -509,7 +510,7 @@ const Node = tree.Node;
test "layout lists each column's place, panes and state, and the active one" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- layout.newColumn(p, p.active);
+ layout.newColumn(p, p.view().active);
p.sync();
const first_serial = layout.columnSerial(p, 0);
const new_serial = layout.columnSerial(p, 1);
@@ -517,7 +518,7 @@ test "layout lists each column's place, panes and state, and the active one" {
const layout_node = @backingInt(tree.TopFile.layout);
const text = th.rd(p, layout_node, 0, 4096).bytes;
var want: [256]u8 = undefined;
- const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.col_x[0], p.col_w[0], p.panes[0].?.serial });
+ const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.view().col_x[0], p.view().col_w[0], p.panes[0].?.serial });
try testing.expect(std.mem.startsWith(u8, text, first));
// Newcol gives the new, empty column's tag the keyboard.
try testing.expect(std.mem.indexOf(u8, text, "current empty\n") != null);
@@ -564,10 +565,10 @@ test "a focus write makes its pane's column the active one: layout says so and p
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const left = p.panes[0].?.serial;
- layout.newColumn(p, p.active);
- panes.newScratchFor(p, p.active, .fs); // fills the new, right column
+ layout.newColumn(p, p.view().active);
+ panes.newScratchFor(p, p.view().active, .fs); // fills the new, right column
p.sync();
- try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.col);
+ try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.view().active).?.col);
var digits: [16]u8 = undefined;
_ = th.wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left}));
var want: [32]u8 = undefined;
@@ -613,11 +614,11 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
const first = layout.columnSerial(p, 0);
- layout.newColumn(p, p.active);
+ layout.newColumn(p, p.view().active);
const empty = layout.columnSerial(p, 1);
// New on the empty column's ctl fills it, wherever the keyboard is.
try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(empty, .ctl), "New\n").reply.status);
- try testing.expectEqual(@as(usize, 1), p.cols[1].n);
+ try testing.expectEqual(@as(usize, 1), p.view().cols[1].n);
try testing.expectEqual(E.INVAL, th.wr(p, Node.ofCol(empty, .ctl), "Exit\n").errno());
var rec: [64]u8 = undefined;
try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err - col/{d}/ctl: unknown control message \"Exit\"", .{empty})));
@@ -630,14 +631,14 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on
try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(empty, .exec), "Delcol\n").reply.status);
try testing.expectEqual(@as(?usize, null), layout.columnBySerial(p, empty));
// An empty column goes on rmdir.
- layout.newColumn(p, p.active);
+ layout.newColumn(p, p.view().active);
const made = layout.columnSerial(p, 1);
try testing.expectEqual(tree.Status.ok, th.call(p, .{ .tag = 2, .op = .release, .node = Node.ofCol(made, .dir), .remove = true }).reply.status);
try testing.expectEqual(@as(?usize, null), layout.columnBySerial(p, made));
try testing.expectEqual(first, layout.columnSerial(p, 0));
// Joincol folds a column into the one on its right, which keeps its own
// serial and tag.
- layout.newColumn(p, p.active);
+ layout.newColumn(p, p.view().active);
const right = layout.columnSerial(p, 1);
_ = th.wr(p, Node.ofCol(right, .tag), " Mine");
try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(first, .ctl), "Joincol\n").reply.status);
@@ -654,7 +655,7 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back
const tagexec = @backingInt(tree.TopFile.tagexec);
try testing.expectEqual(tree.Status.ok, th.look_up(p, tree.root, "tagexec").reply.status);
try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status);
- try testing.expectEqual(@as(usize, 2), p.ncol);
+ try testing.expectEqual(@as(usize, 2), p.view().ncol);
// Its announcement is the message row's, never logged; a pane's word
// such as Msg is refused there.
try testing.expect(!th.logHas(p, "msg - Newcol\n"));
@@ -662,7 +663,7 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back
// A column's exec makes a pane there and reads it back.
const right = layout.columnSerial(p, 1);
try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(right, .exec), "New\n").reply.status);
- const made = p.panes[p.cols[1].panes[0]].?.serial;
+ const made = p.panes[p.view().cols[1].panes[0]].?.serial;
var want: [16]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, Node.ofCol(right, .exec), 0, 64).bytes);
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, tagexec, 0, 64).bytes);
@@ -690,8 +691,8 @@ test "a word run from the workspace's or a column's tag runs in the session's di
test "a command run from a column's tag gets its pane in that column, not the last" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- layout.newColumn(p, p.active);
- panes.newScratchFor(p, p.active, .fs); // fills the new, right column
+ layout.newColumn(p, p.view().active);
+ panes.newScratchFor(p, p.view().active, .fs); // fills the new, right column
p.sync();
const left = layout.columnSerial(p, 0);
try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(left, .exec), "true\n").reply.status);
@@ -716,7 +717,7 @@ test "a column's ctl refuses an unknown word and an argument as the other ctls d
const extra = th.wr(p, ctl_node, "New extra\n");
try testing.expectEqual(E.INVAL, extra.errno());
try testing.expect(std.mem.startsWith(u8, extra.reply.ename, "wrong #args"));
- try testing.expectEqual(@as(usize, 1), p.cols[0].n);
+ try testing.expectEqual(@as(usize, 1), p.view().cols[0].n);
// A pane's bare answer and a winsize of no size say what they take.
try testing.expectEqualStrings("answer takes a choice or -", th.wr(p, Node.of(p.panes[0].?.serial, .ctl), "answer\n").reply.ename);
}
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 78fe15c1..9b87d9aa 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -54,6 +54,7 @@ fn noteResult(p: *Pardes, serial: u32) void {
/// created; failing that, a look records the pane it focused and an exec
/// the pane it acted on (even one it closed).
pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) void {
+ const v = p.view();
const context = if (p.panes[id]) |pane| pane.serial else 0;
// A pane an event reader holds hears its clicks instead of acting on
// them (editors/acme/look.c:53 and exec.c:173 send them to winevent),
@@ -106,10 +107,10 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo
// A word in a column's or the workspace's tag ran at no pane: it
// answers one only if it focused one (Newcol answers nothing).
if (p.exec_header) {
- if (p.active != id) if (p.panes[p.active]) |pane| noteResult(p, pane.serial);
+ if (v.active != id) if (p.panes[v.active]) |pane| noteResult(p, pane.serial);
return;
}
- noteResult(p, if (exec) context else (p.panes[p.active] orelse return).serial);
+ noteResult(p, if (exec) context else (p.panes[v.active] orelse return).serial);
}
/// A write's messages, a line each, except that an `Edit` line takes the
@@ -190,9 +191,10 @@ pub fn completeEnd(p: *Pardes, data: []const u8) usize {
/// A null `serial` clicks at whichever pane is active as each line runs,
/// which is what the root's own look and exec mean; a serial stays put.
pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Reply {
+ const v = p.view();
// The root's lines run at the keyboard's pane: a refusal before any runs
// is that pane's too, in its err record.
- p.fs.ran_at = if (serial == null) (if (p.panes[p.active]) |pane| pane.serial else 0) else 0;
+ p.fs.ran_at = if (serial == null) (if (p.panes[v.active]) |pane| pane.serial else 0) else 0;
if (editNotAlone(p, req.data)) return tree.failText(req.tag, E.INVAL, e_after_edit);
for ([2]bool{ false, true }) |apply| {
if (apply) p.fs.results_len = 0;
@@ -204,7 +206,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep
for (text) |c| if ((c < ' ' and c != '\t' and c != '\n') or c == 0x7f) return tree.failText(req.tag, E.INVAL, e_control);
if (exec) if (tooLong(req, text)) |refusal| return refusal;
if (!apply) continue;
- var id = if (serial) |s| p.paneBySerial(s) orelse break else p.active;
+ var id = if (serial) |s| p.paneBySerial(s) orelse break else v.active;
// No pane at all: the root's look and exec act in the session's
// directory. An exec runs as the workspace tag's; a look from a
// scratch made as New makes one (and its column), dropped
@@ -220,12 +222,12 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep
const free = p.freeSlot() orelse return Reply.fail(req.tag, E.NOSPC);
panes.newScratchFor(p, id, .scratch);
if (p.panes[free] == null) return Reply.fail(req.tag, E.NOSPC);
- p.active = free;
+ v.active = free;
id = free;
scratch = free;
}
if (p.panes[id] == null) return Reply.fail(req.tag, E.NOENT);
- defer if (scratch) |s| if (p.active != s) if (p.panes[s]) |sp| if (sp.file) |f| {
+ defer if (scratch) |s| if (v.active != s) if (p.panes[s]) |sp| if (sp.file) |f| {
if (f.content.len == 0) p.removePane(s, null) catch {};
};
p.fs.ran_at = p.panes[id].?.serial;
@@ -389,7 +391,7 @@ pub fn statusText(p: *Pardes) []const u8 {
// Whether the pointer is over this window: what a grip let go past
// another window's edge asks of every window, to find the one it was
// let go over (Handover.zig), where no window may know another's place.
- if (p.frontend.windowed) w.writer.print("pointer {s}\n", .{if (p.pointer_inside) "in" else "out"}) catch {};
+ if (p.view().frontend.windowed) w.writer.print("pointer {s}\n", .{if (p.view().pointer_inside) "in" else "out"}) catch {};
return w.written();
}
@@ -431,7 +433,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 {
const font = p.settings.font.effective_name.get();
writeQuoted(&w, if (font.len == 0) "default" else font) catch return w.buffered();
// While a column's or the workspace's tag has the keyboard, no pane does.
- const current = p.panes[p.active] == pane and p.header == null;
+ const current = p.panes[p.view().active] == pane and p.view().header == null;
const f = pane_files.fileOf(pane);
const undo = if (f) |file| file.history.journal.done > 0 else false;
const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false;
@@ -684,7 +686,7 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
if (pardes.filesystem.deniedAbove(local))
return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch "pager: permission denied");
};
- const id = pardes.panes.Output.openPager(p, p.active, dir) catch |err|
+ const id = pardes.panes.Output.openPager(p, p.view().active, dir) catch |err|
return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) {
error.NoPaneRoom, error.NoPaneSlots => "pager: no space for a +Pager pane",
else => "pager: could not make a +Pager pane",
@@ -715,12 +717,12 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM
// +Diff in the +Pager's place, the +Pager closed. The keyboard stays
// where it was, as a page's.
if (f.pager_diff) {
- const keyboard = p.active;
+ const keyboard = p.view().active;
if (panes.Output.openDiff(p, id, f.path, f.content)) |hid| {
// ponytail: the text is gone with it; Diff on the +Diff says no such file.
p.removePane(id, hid) catch {};
} else |_| {}
- if (p.panes[keyboard] != null) p.active = keyboard;
+ if (p.panes[keyboard] != null) p.view().active = keyboard;
}
}
@@ -736,6 +738,7 @@ pub fn fillClosedPagers(p: *Pardes) void {
/// One session builtin a line, at whichever pane has the keyboard as each
/// runs, as the root's look and exec click there; all are checked first.
pub fn writeRoot(p: *Pardes, req: Req) Reply {
+ const v = p.view();
for ([2]bool{ false, true }) |apply| {
if (apply) p.fs.results_len = 0;
var it: Messages = .{ .p = p, .data = req.data };
@@ -749,8 +752,8 @@ pub fn writeRoot(p: *Pardes, req: Req) Reply {
// attached to (--detach, unattended) takes one written.
if (!p.unattended) return refuseQuoting(p, req, "size: a frontend is attached and owns the size", value, "");
if (apply) {
- const was: [2]u16 = .{ p.screen_w, p.screen_h };
- const before = p.rects;
+ const was: [2]u16 = .{ v.screen_w, v.screen_h };
+ const before = v.rects;
p.update(.{ .resize = .{ .cols = size[0], .rows = size[1] } });
p.sync();
// Every pane keeps its tag and two rows, as placement
@@ -785,10 +788,10 @@ pub fn writeRoot(p: *Pardes, req: Req) Reply {
continue;
}
// An empty window (no pane at all) still takes its session words.
- if (p.panes[p.active] == null and panes.anyPane(p) != null) return Reply.fail(req.tag, E.NOENT);
+ if (p.panes[v.active] == null and panes.anyPane(p) != null) return Reply.fail(req.tag, E.NOENT);
p.fs.session_write = true;
defer p.fs.session_write = false;
- if (runBuiltin(p, req, p.active, line)) |refusal| return refusal;
+ if (runBuiltin(p, req, v.active, line)) |refusal| return refusal;
}
}
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
@@ -923,8 +926,8 @@ pub fn commandsText(p: *Pardes) ![]const u8 {
/// rio keeps `current` apart from `unhide`.
pub fn readFocus(p: *Pardes, req: Req) Reply {
const out = p.fs.stage(p.gpa);
- if (p.header != null) return tree.stagedReply(p, req);
- const pane = p.panes[p.active] orelse return tree.stagedReply(p, req);
+ if (p.view().header != null) return tree.stagedReply(p, req);
+ const pane = p.panes[p.view().active] orelse return tree.stagedReply(p, req);
out.print(p.gpa, "{d}\n", .{pane.serial}) catch return Reply.fail(req.tag, E.NOMEM);
return tree.stagedReply(p, req);
}
@@ -937,7 +940,7 @@ pub fn writeFocus(p: *Pardes, req: Req) Reply {
// its column becomes the active one, as the user's click there would
// make it: pane/new and a look place there next.
tagline.exitHeader(p);
- p.active = id;
+ p.view().active = id;
if (pardes.layout.findPane(p, id)) |at| p.setActiveColumn(at.col);
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
@@ -1405,11 +1408,11 @@ test "status in a window says whether the pointer is over it" {
// there is a terminal's view.
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- p.frontend.windowed = true;
+ p.view().frontend.windowed = true;
var lines = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n');
for (0..3) |_| _ = lines.next();
try testing.expectEqualStrings("pointer out", lines.next().?);
- p.frontend.windowed = false;
+ p.view().frontend.windowed = false;
}
@@ -1591,9 +1594,9 @@ test "a builtin for one kind of pane is refused on another, and still acts on it
// Petscii chose; with them, what it chose.
for ([_]bool{ false, true }) |art| {
doc.addon.?.art.glyph = art;
- p.frontend.native_images = false;
+ p.view().frontend.native_images = false;
try testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(p, doc), " petscii:on ") != null);
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
try testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagPrefix(p, doc), if (art) " petscii:on " else " petscii:off ") != null);
}
}
@@ -1650,7 +1653,7 @@ test "a builtin's Verbose announcement is logged only when it succeeds, its fail
try testing.expect(!th.logHas(p, said_exit));
// Refused at the keyboard (no write to fail), edited since: the same.
f.revision +%= 1;
- _ = p.executeBuiltinLine(p.active, "Exit");
+ _ = p.executeBuiltinLine(p.view().active, "Exit");
try testing.expect(!th.logHas(p, said_exit));
try testing.expect(!p.quit);
// A Save the host could not do, told a step later: the Save goes too.
@@ -1919,7 +1922,7 @@ test "Term in a directory that is not there fails and makes no pane; a shell tha
// A terminal whose shell the host could not start.
_ = wr(p, Node.of(serial, .name), "/tmp/f.txt\n");
try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Term\n").reply.status);
- const term = p.active;
+ const term = p.view().active;
p.shellFailed(@intCast(term), error.FileNotFound);
const run_node = Node.of(p.panes[term].?.serial, .pty_run);
const h = call(p, .{ .tag = 1, .op = .open, .node = run_node, .omode = 2 }).reply.handle;
@@ -1997,7 +2000,7 @@ test "a terminal told the directory it already goes by logs no rename" {
_ = wr(p, Node.of(serialOf(p), .name), "/tmp/f.txt\n");
try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .ctl), "Term\n").reply.status);
p.update(.tick); // announced
- const term = p.active;
+ const term = p.view().active;
// The host says where its shell started: where it was already named.
p.setCwd(term, "/tmp");
var rec: [32]u8 = undefined;
@@ -2126,7 +2129,7 @@ test "a script whose interpreter is not there: Term refuses it up front, only an
test "a language server question that finds nothing, cannot be answered, or is asked of no file fails, and a write to an image's body is refused" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
// Asked of a pane that is no file's: at once.
_ = wr(p, root_exec, "Recent\n");
const listed = p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?;
@@ -2212,7 +2215,7 @@ test "a PDF's body reads its page's text layer, and takes no write" {
var line: [4200]u8 = undefined;
_ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/doc.pdf\n", .{dir}));
p.sync();
- const doc = p.panes[p.active].?;
+ const doc = p.panes[p.view().active].?;
try testing.expect(doc.hasPdf());
const body = Node.of(doc.serial, .body);
try testing.expect(std.mem.indexOf(u8, rd(p, body, 0, 4096).bytes, "target.txt") != null);
@@ -2226,7 +2229,7 @@ test "a PDF's body reads its page's text layer, and takes no write" {
test "workspace symbols, Symbols and Diagnostics share their directory's one +Search" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
const Output = pardes.panes.Output;
try Output.fillResults(p, id, "/tmp", .{ .query = .workspace_symbols }, "x", try p.gpa.dupe(u8, "a.txt:1:1 x\n"), null);
try Output.fillResults(p, id, "/tmp", .{ .query = .document_symbols }, "", try p.gpa.dupe(u8, "a.txt:2:1 fn f\n"), null);
@@ -2256,7 +2259,7 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.fs.write_waits = true;
- p.saveFailed(@intCast(p.active), "/nowhere/zz.txt", error.FileNotFound);
+ p.saveFailed(@intCast(p.view().active), "/nowhere/zz.txt", error.FileNotFound);
p.fs.write_waits = false;
try testing.expect(!th.logHas(p, "msg "));
try testing.expect(p.fs.late_failure_len > 0);
@@ -2337,14 +2340,14 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as
n += 1;
};
try testing.expectEqual(@as(usize, 2), n);
- p.active = shells[0];
+ p.view().active = shells[0];
p.update(.{ .output = .{ .pane = @intCast(shells[0]), .bytes = "\x1b[?1004h" } });
p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } });
while (p.nextEffect()) |_| {}
var digits: [16]u8 = undefined;
const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial}));
try testing.expectEqual(Status.ok, moved.reply.status);
- try testing.expectEqual(shells[1], p.active);
+ try testing.expectEqual(shells[1], p.view().active);
try testing.expectEqualStrings("\x1b[O\x1b[I", moved.pty_buf[0..moved.pty_len]);
}
@@ -2402,14 +2405,14 @@ test "a column takes panes until their documented minimums fill it, not until no
const new = @backingInt(tree.TopFile.new);
while (call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status == .ok) p.sync();
p.sync();
- const avail = p.screen_h - (p.topBarHeight() + layout.columnBarHeight(p));
- for (0..p.ncol) |c| {
+ const avail = p.view().screen_h - (p.topBarHeight() + layout.columnBarHeight(p));
+ for (0..p.view().ncol) |c| {
var need: u32 = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |k| need += layout.minRows(p, k);
+ for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| need += layout.minRows(p, k);
// Refused only when one more pane's tag and two rows would not fit.
- if (p.cols[c].n > 1) try testing.expect(avail - need < 3);
+ if (p.view().cols[c].n > 1) try testing.expect(avail - need < 3);
// Every pane keeps its minimum.
- for (p.cols[c].panes[0..p.cols[c].n]) |k| try testing.expect(p.rects[k].h >= layout.minRows(p, k));
+ for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| try testing.expect(p.view().rects[k].h >= layout.minRows(p, k));
}
}
@@ -2461,7 +2464,7 @@ test "size is monotonic: growing is never refused, and a size once taken is take
// until a column has no room (ENOSPC).
try testing.expectEqual(Status.ok, wr(p, root_ctl, "Newcol\n").reply.status);
for (0..3) |_| try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status);
- try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[p.active].?.serial, .ctl), "Term\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[p.view().active].?.serial, .ctl), "Term\n").reply.status);
p.sync();
while (call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status == .ok) p.sync();
p.sync();
@@ -2485,7 +2488,7 @@ test "size is monotonic: growing is never refused, and a size once taken is take
}
for ([_]u16{ 60, 61, 64, 70, 100 }) |grown| {
try testing.expectEqual(Status.ok, wr(p, root_ctl, try std.fmt.bufPrint(&line, "size 160 {d}\n", .{grown})).reply.status);
- try testing.expectEqual(grown, p.screen_h);
+ try testing.expectEqual(grown, p.view().screen_h);
}
// Out of range is EINVAL, in words 9ns reads as that.
const bad = wr(p, root_ctl, "size 5 2\n");
@@ -2587,11 +2590,11 @@ test "Newcol at the column cap fails the write and says the cap" {
defer p.deinit();
p.update(.{ .resize = .{ .cols = 4000, .rows = 30 } });
const root_ctl = @backingInt(tree.TopFile.ctl);
- while (p.ncol < pardes.MAX_COLS) {
+ while (p.view().ncol < pardes.MAX_COLS) {
// From the widest column's tag, so no column gets too narrow first.
p.sync();
var widest: usize = 0;
- for (0..p.ncol) |c| if (p.col_w[c] > p.col_w[widest]) {
+ for (0..p.view().ncol) |c| if (p.view().col_w[c] > p.view().col_w[widest]) {
widest = c;
};
pardes.tagline.enterHeader(p, widest);
@@ -2815,7 +2818,7 @@ test "Term+bash on a pane ctl is Term with its argument, as exec and the tag tak
test "a Rename that reaches other files previews them, says so, and is the pane a waiting write answers" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
p.fs.lsp_result = null;
p.lspRequest(id, .rename, "sum");
Ask.lspResponse(p, p.lsp_ask.wait.?.id, "lib.rs:2:8 sum\nmain.rs:4:13-15 sum\n");
@@ -2862,7 +2865,7 @@ test "Petscii, Palette and Ascii take the state their tag word names, set rather
test "a Rename the server answered for this file alone, with other open files saying the name, is previewed and says so" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- p.lspRequest(p.active, .rename, "sum");
+ p.lspRequest(p.view().active, .rename, "sum");
Ask.lspResponse(p, p.lsp_ask.wait.?.id, "util.zig:1:8 sum\nmain.zig: also says add, which the server did not rename\n");
try testing.expect(th.logHas(p, "Rename: previewed, not applied: the server renamed in this file only, and 1 other open file(s) say the name"));
}
@@ -2902,7 +2905,7 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its +
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
p.fs.lsp_result = null;
- p.lspRequest(p.active, .status, "");
+ p.lspRequest(p.view().active, .status, "");
Ask.lspResponse(p, p.lsp_ask.wait.?.id, "language servers:\n");
const shown = p.paneBySerial(p.fs.lsp_result.?).?;
try testing.expect(std.mem.endsWith(u8, p.panes[shown].?.file.?.path, "+Lsp"));
@@ -2976,10 +2979,10 @@ test "a setting the other frontend has is passed over in the init file, not fail
test "the init file saved in a pane applies its settings again, and runs none of its commands twice" {
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .startup_config = "Theme dusk\n", .startup_config_path = "/tmp/pardes-init-test/init" });
defer p.deinit();
- const cols = p.ncol;
+ const cols = p.view().ncol;
pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/elsewhere", "Theme acme\n");
try testing.expectEqualStrings("dusk", p.theme().name);
pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/init", "Theme acme\nNewcol\n");
try testing.expectEqualStrings("acme", p.theme().name);
- try testing.expectEqual(cols, p.ncol);
+ try testing.expectEqual(cols, p.view().ncol);
}
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index a4094e57..6fd0d345 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -835,7 +835,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply {
p.look_missed = false;
look.lookAt(p, live, text);
p.fs.results_len = 0;
- if (!p.look_missed) if (p.panes[p.active]) |found| {
+ if (!p.look_missed) if (p.panes[p.view().active]) |found| {
p.fs.results[0] = found.serial;
p.fs.results_len = 1;
};
@@ -1334,9 +1334,9 @@ test "an empty range written back is expanded as a click at that point would be"
try testing.expectEqual(Status.ok, wr(p, event, "ML1 1\n").reply.status);
try testing.expectEqual(pane_files.State.Range{ .q0 = 8, .q1 = 11 }, pane_files.dotOf(pane));
// An exec at 15 runs the word there, `Newcol`.
- const cols = p.ncol;
+ const cols = p.view().ncol;
try testing.expectEqual(Status.ok, wr(p, event, "MX15 15\n").reply.status);
- try testing.expectEqual(cols + 1, p.ncol);
+ try testing.expectEqual(cols + 1, p.view().ncol);
}
test "opens of the log share the open records, and a closed one frees its record" {
@@ -1366,13 +1366,13 @@ test "a click in the body reports the offsets of the word it takes, so the recor
_ = wr(p, Node.of(scratch, .body), text);
for ([_]u32{ serialOf(p), scratch }) |serial| {
const id = p.paneBySerial(serial).?;
- p.active = p.paneBySerial(if (serial == scratch) serialOf(p) else scratch).?;
+ p.view().active = p.paneBySerial(if (serial == scratch) serialOf(p) else scratch).?;
const event = Node.of(serial, .event);
const h = call(p, .{ .tag = 1, .op = .open, .node = event }).reply.handle;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const x0 = rect.x + config.GUTTER + config.PREFIX_W;
const y0 = rect.y + p.panes[id].?.tag_rows;
const tab: u16 = config.tab_now;
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 3b982803..92d28b99 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -1216,7 +1216,7 @@ test "owned cwd name promotion releases the former directory" {
const p = try th.withTerm(testing.allocator);
defer p.deinit();
p.newScratchBelow(0);
- const id = p.active;
+ const id = p.view().active;
const pane = p.panes[id].?;
try pane.setOwnedCwd("/old/directory");
const result = wr(p, Node.of(pane.serial, .name), "saved.txt\n");
diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig
index 8d8b6e33..33a8717b 100644
--- a/src/ninep/screen.zig
+++ b/src/ninep/screen.zig
@@ -220,9 +220,9 @@ test "screen snapshots preserve rendered cells and styles until their handle is
const parsed = try std.json.parseFromSlice(std.json.Value, gpa, original, .{});
defer parsed.deinit();
const data = parsed.value.object;
- try testing.expectEqual(@as(i64, p.screen_w), data.get("cols").?.integer);
- try testing.expectEqual(@as(i64, p.screen_h), data.get("rows").?.integer);
- try testing.expectEqual(@as(usize, p.screen_w) * p.screen_h, data.get("cells").?.array.items.len);
+ try testing.expectEqual(@as(i64, p.view().screen_w), data.get("cols").?.integer);
+ try testing.expectEqual(@as(i64, p.view().screen_h), data.get("rows").?.integer);
+ try testing.expectEqual(@as(usize, p.view().screen_w) * p.view().screen_h, data.get("cells").?.array.items.len);
try testing.expect(data.get("styles").?.array.items.len > 0);
_ = wr(p, Node.of(serialOf(p), .body), "changed\n");
const newer = call(p, .{ .tag = 2, .op = .open, .node = screen_node });
@@ -259,7 +259,7 @@ test "screen inspection leaves the next real frame as it would have been" {
1 => p.update(.{ .command = "New" }),
2 => {
p.update(.tick);
- try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[p.active].?.serial, .body), "changed cells\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(p.panes[p.view().active].?.serial, .body), "changed cells\n").reply.status);
},
3 => p.update(.{ .command = "Del" }),
else => unreachable,
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 4f155b4f..d15ddd53 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -690,8 +690,8 @@ fn topSize(p: *Pardes, f: TopFile) u64 {
.ctl => if (ctl.settingsText(p)) |text| text.len else |_| 0,
.commands => if (ctl.commandsText(p)) |text| text.len else |_| 0,
.focus => focus: {
- if (p.header != null) break :focus 0;
- const pn = p.panes[p.active] orelse break :focus 0;
+ if (p.view().header != null) break :focus 0;
+ const pn = p.panes[p.view().active] orelse break :focus 0;
var digits: [16]u8 = undefined;
// unreachable: a u32 serial and a newline fit 16
break :focus (std.fmt.bufPrint(&digits, "{d}\n", .{pn.serial}) catch unreachable).len;
@@ -784,7 +784,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
stageDirent(out, p.gpa, Node.of(serial, .dir), true, name);
}
},
- .col => for (0..p.ncol) |c| {
+ .col => for (0..p.view().ncol) |c| {
if (skip > 0) {
skip -= 1;
continue;
@@ -841,7 +841,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
// Refused, the open's err is the one record of it (the
// one rule): no msg besides.
p.fs.capturing = true;
- panes.newScratchFor(p, p.active, .fs);
+ panes.newScratchFor(p, p.view().active, .fs);
p.fs.capturing = false;
p.fs.failure_len = 0;
const made = p.panes[slot] orelse return Reply.fail(req.tag, E.NFILE);
@@ -1438,7 +1438,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
var frame: std.heap.ArenaAllocator = .init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
p.update(.{ .mouse = .{
.button = .none,
.kind = .motion,
@@ -1473,13 +1473,13 @@ test "filesystem inspection preserves pending and displayed Look hover" {
try testing.expectEqual(Status.ok, answer.reply.status);
try testing.expect(std.meta.eql(waiting, p.look_hover_wait));
try testing.expect(std.meta.eql(preview, p.look_hover_preview));
- try testing.expect(p.raw_hover_intent);
+ try testing.expect(p.view().raw_hover_intent);
}
}
try testing.expectEqual(Status.ok, wr(p, body, "changed").reply.status);
try testing.expect(p.look_hover_wait == null);
try testing.expect(p.look_hover_preview == null);
- try testing.expect(!p.raw_hover_intent);
+ try testing.expect(!p.view().raw_hover_intent);
}
test "log stats 0 however much it holds, a stream as acme's generated files are" {
@@ -1501,13 +1501,13 @@ test "filesystem pane creation and truncation cancel Look hover" {
const p = try withFile(testing.allocator, "word\n");
defer p.deinit();
p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = serialOf(p) };
- p.raw_hover_intent = true;
+ p.view().raw_hover_intent = true;
var req = request;
if (req.op == .setattr) req.node = Node.of(serialOf(p), .body);
try testing.expectEqual(Status.ok, call(p, req).reply.status);
try testing.expect(p.look_hover_wait == null);
try testing.expect(p.look_hover_preview == null);
- try testing.expect(!p.raw_hover_intent);
+ try testing.expect(!p.view().raw_hover_intent);
}
}
@@ -1839,9 +1839,9 @@ test "random placements, refused or not, leave no pane under its tag and two row
6 => _ = th.wr(p, Node.of(at, .exec), "Delcol\n"),
else => _ = th.wr(p, Node.of(at, .ctl), "delete\n"),
}
- for (0..p.ncol) |c| if (!layout.columnAtMinimums(p, c)) {
+ for (0..p.view().ncol) |c| if (!layout.columnAtMinimums(p, c)) {
std.debug.print("seed {d} rows {d} step {d} action {d}: column {d} under its minimums\n", .{ seed, rows, step, action, c });
- for (p.cols[c].panes[0..p.cols[c].n]) |id| std.debug.print(" pane {d} h {d} min {d}\n", .{ id, p.rects[id].h, layout.minRows(p, id) });
+ for (p.view().cols[c].panes[0..p.view().cols[c].n]) |id| std.debug.print(" pane {d} h {d} min {d}\n", .{ id, p.view().rects[id].h, layout.minRows(p, id) });
return error.TestUnexpectedResult;
};
}
@@ -1997,14 +1997,14 @@ test "look and exec read back what their own open's write touched; a fresh open
const mine = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
const theirs = call(p, .{ .tag = 2, .op = .open, .node = exec, .omode = 2 }).reply.handle;
_ = call(p, .{ .tag = 3, .op = .write, .node = exec, .handle = mine, .data = "Term\n" });
- const made = p.panes[p.active].?.serial;
+ const made = p.panes[p.view().active].?.serial;
try testing.expect(made != first);
_ = call(p, .{ .tag = 4, .op = .write, .node = exec, .handle = theirs, .data = "Msg hi\n" });
var want: [16]u8 = undefined;
// Read at the offset the write left, as a shell's `exec 3<>` does.
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), call(p, .{ .tag = 5, .op = .read, .node = exec, .handle = mine, .off = 4, .size = 64 }).bytes);
try testing.expectEqualStrings("", call(p, .{ .tag = 6, .op = .read, .node = exec, .handle = mine, .off = 4, .size = 64 }).bytes);
- const said = p.panes[p.active].?.serial;
+ const said = p.panes[p.view().active].?.serial;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{said}), call(p, .{ .tag = 7, .op = .read, .node = exec, .handle = theirs, .size = 64 }).bytes);
const fresh = call(p, .{ .tag = 8, .op = .open, .node = exec }).reply.handle;
try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{said}), call(p, .{ .tag = 9, .op = .read, .node = exec, .handle = fresh, .size = 64 }).bytes);
@@ -2061,9 +2061,9 @@ test "no placement leaves a pane shorter than its tag and two rows; a full colum
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
try testing.expectEqual(made, count); // the refused one is gone
- for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |k| {
- if (p.cols[c].n > 1 and !p.panes[k].?.collapsed)
- try testing.expect(p.rects[k].h >= p.panes[k].?.tag_rows + pardes.layout.min_body_rows);
+ for (0..p.view().ncol) |c| for (p.view().cols[c].panes[0..p.view().cols[c].n]) |k| {
+ if (p.view().cols[c].n > 1 and !p.panes[k].?.collapsed)
+ try testing.expect(p.view().rects[k].h >= p.panes[k].?.tag_rows + pardes.layout.min_body_rows);
};
}
@@ -2111,6 +2111,6 @@ test "a pane made from pane/new goes last in its column, even when the last pane
for (0..3) |_| {
const made = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }).reply.handle;
p.sync();
- try testing.expectEqual(made, p.panes[p.cols[0].panes[p.cols[0].n - 1]].?.serial);
+ try testing.expectEqual(made, p.panes[p.view().cols[0].panes[p.view().cols[0].n - 1]].?.serial);
}
}
diff --git a/src/normal.zig b/src/normal.zig
index 96c61fba..d5ce5f4a 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -149,10 +149,11 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m
/// Search only the primary range, as Helix does. Select mode adds a new
/// match and makes it primary; normal mode replaces only the primary.
fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32) void {
- const name = if (p.register != 0) p.register else p.registers.last_search;
+ const v = p.view();
+ const name = if (v.register != 0) v.register else p.registers.last_search;
const pat = p.registers.value(name, 0) orelse return;
var re = SearchRegex.compile(p.scratch.allocator(), pat) catch {
- p.setMessage(p.active, "invalid search pattern");
+ p.setMessage(v.active, "invalid search pattern");
return;
};
var hay = text;
@@ -175,7 +176,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32)
wrapped = true;
break :blk lastMatch(&re, hay, from, hay.len);
}) orelse {
- p.setMessage(p.active, "no more matches");
+ p.setMessage(v.active, "no more matches");
return;
};
if (found.end == 0) return;
@@ -190,7 +191,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32)
ranges[got.pri] = next;
t.setRanges(text, ranges[0..got.n], &.{}, got.pri, true);
}
- if (wrapped) p.setMessage(p.active, "wrapped around document");
+ if (wrapped) p.setMessage(v.active, "wrapped around document");
}
t.show();
}
@@ -220,7 +221,7 @@ pub fn searchSelection(p: *Pardes, t: *Text, text: []const u8, boundary: bool) v
appendSearchLiteral(&pattern, arena, text[from..to]) catch return;
if (boundary and to < text.len and modal.searchWordBefore(text, to) and !modal.searchWordAt(text, to)) pattern.appendSlice(arena, "\\b") catch return;
}
- const name = if (p.register != 0) p.register else '/';
+ const name = if (p.view().register != 0) p.view().register else '/';
p.registers.put(p.gpa, name, pattern.items, 0, 1, true);
p.registers.last_search = name;
}
@@ -485,7 +486,7 @@ const Replay = union(enum) {
};
pub fn replaySels(p: *Pardes, t: *Text, what: Replay) void {
- const id = p.active;
+ const id = p.view().active;
// a header belongs to no pane and cannot go away under the replay
const owner = t.pane();
const serial = if (owner) |pane| pane.serial else 0;
@@ -600,17 +601,18 @@ pub fn handleNormal(p: *Pardes, t: *Text, key: Key) void {
.action => |value| value,
};
t.normal.register = 0;
- p.register = named;
- defer p.register = 0;
+ p.view().register = named;
+ defer p.view().register = 0;
if (t.nsel == 0 or action.once())
return executeNormalAction(p, t, action);
replaySels(p, t, .{ .normal = action });
}
fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
+ const v = p.view();
// What reaches past the text -- a builtin, a search, a language query --
// acts for the pane the text belongs to; a header's is the active one.
- const pane = t.pane() orelse p.panes[p.active] orelse return;
+ const pane = t.pane() orelse p.panes[v.active] orelse return;
const raw_selection = t.what == .body and pane.rawPointerText(pane.sel[sel_slot]) != null;
const before = .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode };
defer if (raw_selection and !std.meta.eql(before, .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode })) {
@@ -629,7 +631,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// typed again by a macro, Esc is only helix's
if (p.macro.replaying > 0) return;
tagline.exitHeader(p); // out of a header too, as Shift-Esc
- return exec.runBuiltin(p, .Last, p.active, "", null);
+ return exec.runBuiltin(p, .Last, v.active, "", null);
},
// gg and G: a count names the line; bare G is no move (helix)
.goto_file_start, .goto_line => {
@@ -719,7 +721,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
(if (p.panes[qid].?.query) |q| q.source == .diagnostics else false)
else
false;
- if (!fed) return p.lspRequest(p.active, .diagnostics, "");
+ if (!fed) return p.lspRequest(v.active, .diagnostics, "");
if (a.role == .goto_diagnostic) return set.step(p, pane, a.forward, 1, false);
if (set.hits.items.len == 0) return;
set.goTo(pane, if (a.forward) set.hits.items.len - 1 else 0, false);
@@ -817,18 +819,18 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
.undo => return edit.undoStep(p, t, true),
.redo => return edit.undoStep(p, t, false),
// Language shortcuts run the same builtins as tags and leader commands.
- .goto_definition => return exec.runBuiltin(p, .Def, p.active, "", null),
- .goto_references => return exec.runBuiltin(p, .Refs, p.active, "", null),
- .goto_callstack => return exec.runBuiltin(p, .Callstack, p.active, "", null),
- .goto_declaration => return p.lspRequest(p.active, .declaration, ""),
- .goto_type_definition => return p.lspRequest(p.active, .type_definition, ""),
- .goto_implementation => return p.lspRequest(p.active, .implementation, ""),
- .format => return p.lspRequest(p.active, .format, ""),
+ .goto_definition => return exec.runBuiltin(p, .Def, v.active, "", null),
+ .goto_references => return exec.runBuiltin(p, .Refs, v.active, "", null),
+ .goto_callstack => return exec.runBuiltin(p, .Callstack, v.active, "", null),
+ .goto_declaration => return p.lspRequest(v.active, .declaration, ""),
+ .goto_type_definition => return p.lspRequest(v.active, .type_definition, ""),
+ .goto_implementation => return p.lspRequest(v.active, .implementation, ""),
+ .format => return p.lspRequest(v.active, .format, ""),
.increment => return edit.normalAdjustNumber(p, t, @intCast(a.count)),
.decrement => return edit.normalAdjustNumber(p, t, -@as(i64, @intCast(a.count))),
.leader => if (p.macro.replaying == 0) {
- p.prefix = .leader;
- p.leader_n = 0;
+ v.prefix = .leader;
+ v.leader_n = 0;
},
// `:` is the one key a tag and a body do not share: it moves the
// keyboard between them.
@@ -845,7 +847,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// `/` in a text is its query pane's line 1 (Query.zig); a
// terminal's still asks on the notice band.
.search => if (pane.file != null and t.what == .body)
- panes.Query.open(p, p.active, .text, "", true)
+ panes.Query.open(p, v.active, .text, "", true)
else
return panes.startPrompt(p, pane, &pane.body, .{ .search = config.search_marker }),
// In a file's text, n and N step its places while they answer for
@@ -859,9 +861,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// The pattern is line 1 of this text's query pane, made or
// reused, the keyboard staying here: n and N step its places.
if (t.what == .body and pane.file != null and !pane.hasPdf() and pane.query == null) {
- const name = if (p.register != 0) p.register else '/';
+ const name = if (v.register != 0) v.register else '/';
const pat = p.registers.value(name, 0) orelse return;
- panes.Query.open(p, p.active, .text, pat, false);
+ panes.Query.open(p, v.active, .text, pat, false);
pane.places.provenance = .search;
}
},
@@ -869,7 +871,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
.macro_record => {
const m = &p.macro;
if (m.recording == 0) {
- m.recording = if (p.register != 0) p.register else '@';
+ m.recording = if (v.register != 0) v.register else '@';
m.recorded.clearRetainingCapacity();
return;
}
@@ -882,10 +884,10 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
m.recording = 0;
},
.macro_replay => {
- const name: u21 = if (p.register != 0) p.register else '@';
+ const name: u21 = if (v.register != 0) v.register else '@';
const notation = p.registers.value(name, 0) orelse return;
const keys = Macro.decode(p.scratch.allocator(), notation) catch return;
- p.register = 0;
+ v.register = 0;
for (0..a.count) |_| keyboard.replayKeys(p, keys);
},
.repeat_insert => {
@@ -913,7 +915,7 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void {
if (pane.pdf == null) return;
if (pane.body.normal.prefix == null and isPrefix(key, 'f')) {
pane.body.normal.clear();
- return exec.runBuiltin(p, .PdfSections, p.active, "", null);
+ return exec.runBuiltin(p, .PdfSections, p.view().active, "", null);
}
switch (modal.Normal.parse(&pane.body.normal, normalInput(key))) {
.pending, .ignored, .unbound => {},
diff --git a/src/panes.zig b/src/panes.zig
index 9f1ce036..e4872468 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -842,7 +842,7 @@ pub fn installPane(p: *Pardes, id: usize, pane: *Pane) void {
std.debug.assert(p.panes[id] == null);
p.next_serial += 1;
pane.serial = p.next_serial;
- p.rects[id] = .{};
+ p.view().rects[id] = .{};
p.panes[id] = pane;
views.installed(p, pane);
// /log hears of it once the update that made it ends, when it has
@@ -853,7 +853,7 @@ pub fn installPane(p: *Pardes, id: usize, pane: *Pane) void {
pub fn newShell(p: *Pardes, id: usize, cwd: []const u8) !*Pane {
std.debug.assert(p.panes[id] == null);
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
- const pane = try panes.terminal.create(p.gpa, p.screen_w, p.screen_h);
+ const pane = try panes.terminal.create(p.gpa, p.view().screen_w, p.view().screen_h);
// Named by the directory it is started in from the first, so the
// shell saying it is there is no rename (`new N /` then `rename`);
// out of memory for it, the shell names it when it says.
@@ -884,7 +884,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
const owned = try p.gpa.dupe(u8, line);
errdefer p.gpa.free(owned);
- const pane = try panes.terminal.create(p.gpa, p.screen_w, p.screen_h);
+ const pane = try panes.terminal.create(p.gpa, p.view().screen_w, p.view().screen_h);
pane.command = owned;
pane.command_pty = true;
pane.body.mode = .tty;
@@ -898,7 +898,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
pub fn newDocPane(p: *Pardes, id: usize) !*Pane {
std.debug.assert(p.panes[id] == null);
- const pane = try panes.terminal.createDoc(p.gpa, p.screen_w, p.screen_h);
+ const pane = try panes.terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
p.installPane(id, pane);
return pane;
}
@@ -949,7 +949,7 @@ pub fn paneBySerial(p: *Pardes, serial: u32) ?usize {
/// The pane a session word runs with in an empty window.
pub fn standIn(p: *Pardes) ?*Pane {
- if (p.stand_in == null) p.stand_in = panes.terminal.createDoc(p.gpa, p.screen_w, p.screen_h) catch null;
+ if (p.stand_in == null) p.stand_in = panes.terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h) catch null;
return p.stand_in;
}
@@ -973,20 +973,21 @@ pub fn openTutorView(p: *Pardes, id: usize) !*Pane {
}
pub fn setTestFile(p: *Pardes, content: []const u8) !*Pane {
+ const v = p.view();
const copy = try p.gpa.dupe(u8, content);
errdefer p.gpa.free(copy);
const path = try p.gpa.dupe(u8, "/test.txt");
errdefer p.gpa.free(path);
const history = try panes.File.History.create(p.gpa);
errdefer p.gpa.destroy(history);
- const pane = try panes.terminal.createDoc(p.gpa, p.screen_w, p.screen_h);
+ const pane = try panes.terminal.createDoc(p.gpa, v.screen_w, v.screen_h);
errdefer p.gpa.destroy(pane);
try deinitPane(p, p.panes[0].?);
p.panes[0] = null;
pane.file = .{ .path = path, .content = copy, .history = history };
p.installPane(0, pane);
pane.body.cur_pinned = true;
- p.active = 0;
+ v.active = 0;
p.sync();
return pane;
}
@@ -1013,6 +1014,7 @@ pub fn paneDir(pane: *const Pane) []const u8 {
/// through here or removeColumn, so none picks focus for itself, and
/// none by recency.
pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void {
+ const v = p.view();
const pane = p.panes[id] orelse return;
// What is attached to it closes with it, first, each giving its rows
// back to it: then its rows, theirs among them, go where a pane's go.
@@ -1024,24 +1026,25 @@ pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void {
// An attachment's rows go back to its owner and nobody else.
const owner = layout.ownerOf(p, id);
const place = layout.findPane(p, id);
- const emptied = if (place) |f| (if (p.cols[f.col].n == 1) f.col else null) else null;
+ const emptied = if (place) |f| (if (v.cols[f.col].n == 1) f.col else null) else null;
// What it was and where, for Panes to bring back (Store.zig).
const kept = p.store.keep(p, id);
errdefer if (kept) |k| k.free(p.recentGpa());
// Before anything is torn down, so a failure here changes nothing.
try deinitPane(p, pane);
const gainer = layout.absorbVWeight(p, id, owner orelse to);
- const beside = if (emptied) |c| layout.besideColumn(p, c, p.rects[id]) else null;
+ const beside = if (emptied) |c| layout.besideColumn(p, c, v.rects[id]) else null;
layout.removePane(p, id);
p.panes[id] = null;
+ views.gone(p, id);
if (kept) |k| p.store.close(p, k, gainer);
- if (p.active != id) return;
+ if (v.active != id) return;
// No pane left: the session is over.
- p.active = gainer orelse beside orelse anyPane(p) orelse {
+ v.active = gainer orelse beside orelse anyPane(p) orelse {
p.quit = true;
return p.emit(.quit);
};
- if (emptied) |c| if (p.header == null) tagline.enterHeader(p, c);
+ if (emptied) |c| if (v.header == null) tagline.enterHeader(p, c);
}
/// The pane Last should fall back to when the jumplist has nothing: the
@@ -1051,8 +1054,8 @@ pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void {
/// the jumplist, and alternating with it is exactly what Last is for.
pub fn neighbourPane(p: *Pardes, from: usize) ?usize {
if (layout.findPane(p, from)) |at| {
- const n = p.cols[at.col].n;
- if (n > 1) return p.cols[at.col].panes[(at.idx + 1) % n];
+ const n = p.view().cols[at.col].n;
+ if (n > 1) return p.view().cols[at.col].panes[(at.idx + 1) % n];
}
for (p.panes, 0..) |slot, id| {
if (slot != null and id != from) return id;
@@ -1113,7 +1116,7 @@ pub fn startPrompt(p: *Pardes, pane: *Pane, t: *Text, request: union(enum) {
switch (t.what) {
.body => {
pane.focus = .body;
- if (p.panes[p.active] == pane) tagline.exitHeader(p);
+ if (p.panes[p.view().active] == pane) tagline.exitHeader(p);
},
.tag => pane.focus = .tag,
.column, .workspace, .input => {},
@@ -1200,18 +1203,18 @@ test "owned cwd close copies are transactional across inherited chains" {
p.gpa.free(parent.file.?.path);
parent.file.?.path = try p.gpa.dupe(u8, "/work/project/source.zig");
p.newScratchBelow(0);
- const first_id = p.active;
+ const first_id = p.view().active;
const first = p.panes[first_id].?;
p.newScratchBelow(0);
- const second = p.panes[p.active].?;
+ const second = p.panes[p.view().active].?;
p.newScratchBelow(first_id);
- const grandchild = p.panes[p.active].?;
+ const grandchild = p.panes[p.view().active].?;
p.sync();
while (p.nextEffect()) |_| {}
p.parkPendingWrite(0, "queued");
const pending = p.pending_write[0].?.bytes;
- const columns = p.cols;
- const active = p.active;
+ const columns = p.view().cols;
+ const active = p.view().active;
const live_bytes = allocator.allocated_bytes - allocator.freed_bytes;
allocator.fail_index = allocator.alloc_index + failed_copy;
try std.testing.expectError(error.OutOfMemory, p.removePane(0, null));
@@ -1219,8 +1222,8 @@ test "owned cwd close copies are transactional across inherited chains" {
try std.testing.expectEqual(parent, first.cwd.inherited);
try std.testing.expectEqual(parent, second.cwd.inherited);
try std.testing.expectEqual(first, grandchild.cwd.inherited);
- try std.testing.expectEqualDeep(columns, p.cols);
- try std.testing.expectEqual(active, p.active);
+ try std.testing.expectEqualDeep(columns, p.view().cols);
+ try std.testing.expectEqual(active, p.view().active);
try std.testing.expectEqual(@as(usize, 0), p.effects_len);
try std.testing.expectEqual(pending.ptr, p.pending_write[0].?.bytes.ptr);
try std.testing.expectEqual(live_bytes, allocator.allocated_bytes - allocator.freed_bytes);
@@ -1252,11 +1255,11 @@ test "owned cwd column close allocates every copy before removing any pane" {
second_child.cwd = .{ .inherited = p.panes[1].? };
while (p.nextEffect()) |_| {}
const before = p.panes;
- const columns = p.cols;
+ const columns = p.view().cols;
allocator.fail_index = allocator.alloc_index + 1;
try std.testing.expectError(error.OutOfMemory, layout.removeColumn(p, 0));
for (before, p.panes) |old, current| try std.testing.expectEqual(old, current);
- try std.testing.expectEqualDeep(columns, p.cols);
+ try std.testing.expectEqualDeep(columns, p.view().cols);
try std.testing.expectEqual(@as(usize, 0), p.effects_len);
try std.testing.expect(first_child.cwd == .inherited and second_child.cwd == .inherited);
allocator.fail_index = std.math.maxInt(usize);
@@ -1275,7 +1278,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" {
p.setCwd(0, "/exited");
const parent = p.panes[0].?;
p.newScratchBelow(0);
- const child = p.panes[p.active].?;
+ const child = p.panes[p.view().active].?;
p.sync();
while (p.nextEffect()) |_| {}
allocator.fail_index = allocator.alloc_index;
@@ -1301,7 +1304,7 @@ test "owned cwd restore either copies the directory or preserves the old core" {
const p = try Pardes.init(allocator.allocator(), .{ .tty_only = true, .file = "/nonexistent/pardes-owned-cwd" });
defer p.deinit();
p.newScratchBelow(0);
- const id = p.active;
+ const id = p.view().active;
try p.panes[id].?.setOwnedCwd("/retained/terminal/directory");
try dump.dumpState(p);
const original = p.panes[id].?;
@@ -1331,7 +1334,7 @@ test "owned cwd Save promotion releases the former directory" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
p.newScratchBelow(0);
- const id = p.active;
+ const id = p.view().active;
const pane = p.panes[id].?;
try pane.setOwnedCwd("/old/directory");
exec.saveTo(p, id, "saved.txt");
@@ -1371,7 +1374,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" {
try std.testing.expect(p.executeBuiltinLine(source, "New"));
// no shell IO: the scratch is created in-core, focused, below the caller
while (p.nextEffect()) |_| {}
- const id = p.active;
+ const id = p.view().active;
try std.testing.expect(id != source);
try std.testing.expectEqual(source_col, layout.findPane(p, id).?.col);
const np = p.panes[id].?;
@@ -1392,7 +1395,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" {
test "a prompt chip is a band with its caret, still on the grid, and only the chip swallows a click" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
const pane = p.panes[id].?;
p.sync();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
@@ -1404,7 +1407,7 @@ test "a prompt chip is a band with its caret, still on the grid, and only the ch
// detached wire will encode.
startPrompt(p, pane, &pane.body, .{ .search = "/" });
_ = try p.render(frame.allocator());
- const r = p.rects[id];
+ const r = p.view().rects[id];
const cursor = p.surface.cursor orelse return error.MissingPromptCursor;
const row = p.bodyTop(pane, r);
try std.testing.expectEqual(@as(u8, 1), pane.notices.len);
@@ -1476,7 +1479,7 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro
try std.testing.expectEqualStrings("t", band.cells[caret.x - 1].grapheme());
try std.testing.expectEqualStrings("w", band.cells[caret.x].grapheme());
const grid = p.surface.cursor orelse return error.MissingPromptCursor;
- try std.testing.expectEqual(p.bodyTop(pane, p.rects[0]), grid.y);
+ try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[0]), grid.y);
// Submitting searches for what was typed and gives the prompt its line back.
p.update(.{ .key = .{ .cp = Key.enter } });
diff --git a/src/pardes.zig b/src/pardes.zig
index 940e5c5d..35cccf26 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -158,14 +158,15 @@ pub const BOX_H: u16 = 1;
pub const TAG_TEXT_INSET: u16 = config.GUTTER;
pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
+ const v = p.view();
if (row < p.topBarHeight()) return 0;
if (row < p.topBarHeight() + layout.columnBarHeight(p)) {
- for (p.col_x[0..p.ncol], p.col_w[0..p.ncol]) |x, w|
+ for (v.col_x[0..p.view().ncol], v.col_w[0..p.view().ncol]) |x, w|
if (col >= x and col - x < w) return @floatFromInt(x);
}
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const r = p.rects[id];
+ const r = v.rects[id];
const tag_y = p.tagTop(pane, r);
if (row >= tag_y and row < tag_y + pane.tag_rows and col >= r.x and col < r.x + r.w) return @floatFromInt(r.x);
}
@@ -177,7 +178,7 @@ pub fn gridColAt(p: ?*const Pardes, x: f32, row: u16, body_w: f32, tagline_w: f3
const tag = @max(tagline_w, 1);
if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) return colFromSpan(x, tag);
if (p) |core| if (row < core.topBarHeight() + layout.columnBarHeight(core)) {
- for (core.col_x[0..core.ncol], core.col_w[0..core.ncol]) |origin, width| {
+ for (core.view().col_x[0..core.view().ncol], core.view().col_w[0..core.view().ncol]) |origin, width| {
if (width == 0) continue;
const left = @as(f32, @floatFromInt(origin)) * body;
const right = @as(f32, @floatFromInt(origin + width)) * body;
@@ -190,7 +191,7 @@ pub fn gridColAt(p: ?*const Pardes, x: f32, row: u16, body_w: f32, tagline_w: f3
};
if (p) |core| for (core.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const r = core.rects[id];
+ const r = core.view().rects[id];
const tag_y = core.tagTop(pane, r);
if (row < tag_y or row >= tag_y + pane.tag_rows or r.w == 0) continue;
const left = @as(f32, @floatFromInt(r.x)) * body;
@@ -218,8 +219,8 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
// Two panes side by side put two tags on ONE row, which is the case a
// per-row origin gets wrong and the reason this is asked per cell.
- const left = p.rects[0];
- const right = p.rects[1];
+ const left = p.view().rects[0];
+ const right = p.view().rects[1];
try std.testing.expect(right.x > left.x);
try std.testing.expectEqual(@as(f32, @floatFromInt(left.x)), taglineOriginCol(p, left.x + 3, left.y));
try std.testing.expectEqual(@as(f32, @floatFromInt(right.x)), taglineOriginCol(p, right.x + 3, right.y));
@@ -233,7 +234,7 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
const body_w: f32 = 10;
const tag_w: f32 = 8;
- for (p.col_x[0..p.ncol], p.col_w[0..p.ncol]) |origin, width| {
+ for (p.view().col_x[0..p.view().ncol], p.view().col_w[0..p.view().ncol]) |origin, width| {
if (width == 0) continue;
const col = origin;
try std.testing.expectEqual(@as(f32, @floatFromInt(origin)), taglineOriginCol(p, col, TOPBAR_H));
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 4da382fd..8edb4902 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -2326,11 +2326,12 @@ fn movePage(
/// A normal-mode command in a PDF pane: the page moves, or the session is
/// asked for what a page cannot do (Last, the leader, the tag, a search).
pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Action) void {
+ const v = core.view();
if (comptime !enabled) return;
const state = pane.pdf orelse return;
const gpa = core.pdf_gpa;
- const native = core.frontend.native_images;
- const cells: CellPixels = .{ .w = core.cell_pixels.w, .h = core.cell_pixels.h };
+ const native = v.frontend.native_images;
+ const cells: CellPixels = .{ .w = v.cell_pixels.w, .h = v.cell_pixels.h };
const viewport = paneViewport(core, pane);
const placed = if (native) paneGeometry(core, pane) else null;
const page_changed = switch (a.role) {
@@ -2338,7 +2339,7 @@ pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Act
// a pane (text-only, the page shows neither); typed again by a
// macro, Esc is only the page's.
.escape => {
- if ((!state.cancelChrome(gpa) or !native) and core.macro.replaying == 0) exec.runBuiltin(core, .Last, core.active, "", null);
+ if ((!state.cancelChrome(gpa) or !native) and core.macro.replaying == 0) exec.runBuiltin(core, .Last, v.active, "", null);
return;
},
.move_down, .goto_line_down => moveRows(state, gpa, native, viewport, cells, 1, a.count),
@@ -2359,8 +2360,8 @@ pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Act
.half_page_down, .page_down => movePage(state, gpa, native, viewport, cells, 1, a.role == .half_page_down, a.count),
.half_page_up, .page_up => movePage(state, gpa, native, viewport, cells, -1, a.role == .half_page_up, a.count),
.leader => {
- core.prefix = .leader;
- core.leader_n = 0;
+ v.prefix = .leader;
+ v.leader_n = 0;
return;
},
.command_line => return tagline.enterTag(core, pane),
@@ -2718,7 +2719,7 @@ fn rearmCleanSections(
pane.search_pane = remembered.pane;
pane.search_row = null;
look.armLookWalk(core, remembered.pane);
- core.active = id;
+ core.view().active = id;
return true;
}
@@ -2759,7 +2760,7 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void {
};
exec.placeNew(core, id, id, free, .doc);
layout.compute(core);
- core.active = id;
+ core.view().active = id;
pane.search_pane = free;
pane.search_row = null;
look.armLookWalk(core, free);
@@ -2824,7 +2825,7 @@ pub fn lookSection(
.external => |uri| if (uri.len <= 256) core.emit(.{ .open_link = .from(uri) }),
.none => unreachable,
}
- core.active = owner.id;
+ core.view().active = owner.id;
return true;
}
@@ -2928,14 +2929,15 @@ pub fn toggleTint(pane: *pardes.Pane) void {
}
pub fn paneViewport(core: *const pardes.Pardes, pane: *const pardes.Pane) ?Viewport {
+ const v = core.view();
if (comptime !enabled) return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = v.rects[panes.paneIdOf(core, pane) orelse return null];
const cols = rect.w -| config.GUTTER;
const rows = rect.h -| pane.tag_rows;
if (cols == 0 or rows == 0) return null;
return .{
- .pixel_w = @as(u32, cols) * @as(u32, core.cell_pixels.w),
- .pixel_h = @as(u32, rows) * @as(u32, core.cell_pixels.h),
+ .pixel_w = @as(u32, cols) * @as(u32, v.cell_pixels.w),
+ .pixel_h = @as(u32, rows) * @as(u32, v.cell_pixels.h),
};
}
@@ -2965,13 +2967,14 @@ pub fn paneGeometry(core: *const pardes.Pardes, pane: *const pardes.Pane) ?image
/// The page under grid row `row`, from the middle of its cell.
pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row: u16) ?usize {
+ const v = core.view();
if (comptime !enabled) return null;
const state = pane.pdf orelse return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = v.rects[panes.paneIdOf(core, pane) orelse return null];
const body_y = core.bodyTop(pane, rect);
if (!state.layout_valid or row < body_y or row >= body_y + (rect.h -| pane.tag_rows)) return null;
const document_y = state.document_scroll_y + @as(f64, @floatFromInt(
- @as(u32, row - body_y) * core.cell_pixels.h + core.cell_pixels.h / 2,
+ @as(u32, row - body_y) * v.cell_pixels.h + v.cell_pixels.h / 2,
));
const page = pageAtOffset(state, document_y);
const start: f64 = @floatFromInt(state.page_starts[page]);
@@ -2983,7 +2986,7 @@ pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row:
/// Some page of the pane is placed where it is drawn.
pub fn paneNativeReady(core: *const pardes.Pardes, pane: *const pardes.Pane) bool {
if (comptime !enabled) return false;
- if (!core.frontend.native_images) return false;
+ if (!core.view().frontend.native_images) return false;
const state = if (pane.pdf) |view| view else return false;
const view = paneViewport(core, pane) orelse return false;
for (state.rasters[0..state.rasters_len]) |*raster| {
@@ -2999,7 +3002,7 @@ pub fn nativePageAtGridRow(
row: u16,
) ?usize {
if (comptime !enabled) return null;
- if (!core.frontend.native_images) return null;
+ if (!core.view().frontend.native_images) return null;
const state = if (pane.pdf) |view| view else return null;
const page = pageAtGridRow(core, pane, row) orelse return null;
const view = paneViewport(core, pane) orelse return null;
@@ -3023,11 +3026,11 @@ pub fn panePointAtPage(
const raster = rasterForPageConst(state, page) orelse return null;
if (raster.rgba.len == 0) return null;
const placed = placedGeometry(state, raster, view, page) orelse return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = core.view().rects[panes.paneIdOf(core, pane) orelse return null];
const body_x = @as(i64, rect.x + config.GUTTER);
const body_y = @as(i64, core.bodyTop(pane, rect));
- const px = (@as(i64, col) - body_x) * core.cell_pixels.w + core.cell_pixels.w / 2;
- const py = (@as(i64, row) - body_y) * core.cell_pixels.h + core.cell_pixels.h / 2;
+ const px = (@as(i64, col) - body_x) * core.view().cell_pixels.w + core.view().cell_pixels.w / 2;
+ const py = (@as(i64, row) - body_y) * core.view().cell_pixels.h + core.view().cell_pixels.h / 2;
return pointAtGeometry(placed.geometry, placed.pixel_offset_y, raster.iw, raster.ih, raster.band_y, px, py, clamp_to_page);
}
@@ -3246,7 +3249,7 @@ pub fn highlightInput(
.hover_page = hover_page,
.hover_color = if (link_hover) core.theme().box else selection_color,
.selection_color = selection_color,
- .live = core.frontend.native_image_patches,
+ .live = core.view().frontend.native_image_patches,
};
}
@@ -3279,24 +3282,24 @@ fn stripAt(state: *State, view: Viewport) f64 {
pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void {
if (comptime !enabled) return;
- if (!core.frontend.native_images) {
+ if (!core.view().frontend.native_images) {
// The text layer: a page a notch.
const state = pane.pdf orelse return;
if (stepPage(state, core.pdf_gpa, direction)) resetPageChrome(pane);
return;
}
const rows: u32 = @intCast(@max(1, config.wheel_rows));
- const pixels = scaledStep(core.cell_pixels.h, rows);
+ const pixels = scaledStep(core.view().cell_pixels.h, rows);
_ = scrollPane(core, pane, @as(f64, @floatFromInt(pixels)) * direction, true);
}
pub fn horizontalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void {
if (comptime !enabled) return;
const state = pane.pdf orelse return;
- if (!core.frontend.native_images or state.fit != .height) return;
+ if (!core.view().frontend.native_images or state.fit != .height) return;
const placed = paneGeometry(core, pane) orelse return;
const cols: u32 = @intCast(@max(1, config.wheel_cols));
- _ = panPixels(state, placed, .horizontal, direction, scaledStep(core.cell_pixels.w, cols));
+ _ = panPixels(state, placed, .horizontal, direction, scaledStep(core.view().cell_pixels.w, cols));
}
pub fn draw(
@@ -3310,7 +3313,7 @@ pub fn draw(
rail: *pardes.Region,
) bool {
if (comptime !enabled) return false;
- if (!core.frontend.native_images or rect.h <= pane.tag_rows) return false;
+ if (!core.view().frontend.native_images or rect.h <= pane.tag_rows) return false;
const state = pane.pdf orelse return false;
const view = paneViewport(core, pane) orelse return false;
const key = TintKey{ .mode = state.tint, .colors = tintColors(core) };
@@ -3321,7 +3324,7 @@ pub fn draw(
const shown = stripAt(state, view);
state.document_scroll_y = shown;
defer state.document_scroll_y = state.drawn_y;
- if (pane_id == core.active) core.frames.scroll = @floatCast(shown);
+ if (pane_id == core.view().active) core.frames.scroll = @floatCast(shown);
defer {
core.frames.landed +|= state.landed;
state.landed = 0;
diff --git a/src/replica.zig b/src/replica.zig
index 6de125bd..40353d89 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -437,7 +437,7 @@ pub const Screens = struct {
pp.shadow.deinit(x.s.gpa);
pp.shadow.serial = pane.serial;
}
- const r = p.rects[id];
+ const r = p.view().rects[id];
const cols = r.w -| pardes.config.GUTTER;
const rows = (r.h -| pane.tag_rows) -| pane.notices.span();
if (cols == 0 or rows == 0) continue;
@@ -990,7 +990,7 @@ pub const Replica = struct {
// and applied again over each delta while it waits (`screen`), so
// what the authority's unit confirms read the emulator its step
// read (the deltas come before it).
- const keyboard = if (c.panes[c.active]) |pane| pane.terminal != null else false;
+ const keyboard = if (c.panes[c.view().active]) |pane| pane.terminal != null else false;
c.update(in.event);
c.step();
p.terminal = r.t.screen_state and (keyboard or r.t.touched);
@@ -3087,7 +3087,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
} else return error.NoShell;
// Typing goes to the text pane under the shell (the host's write of
// `active`, taped).
- a.core.active = for (a.core.panes, 0..) |slot, id| {
+ a.core.view().active = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.file != null) break id;
} else return error.NoTextPane;
r.confirm(try a.local(.{ .focus = true }));
@@ -3170,7 +3170,7 @@ test "a closed terminal brought back on a screen-state replica: its emulator on
const shell: u8 = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
} else return error.NoShell;
- a.core.active = shell;
+ a.core.view().active = shell;
r.confirm(try a.local(.{ .command = "Del" }));
try std.testing.expectEqual(@as(usize, 1), a.core.store.closed.items.len);
var line: [32]u8 = undefined;
@@ -3195,7 +3195,7 @@ test "a view that sized a terminal closing leaves nothing queued: the others' re
defer r1.deinit();
const r2 = try Replica.init(gpa, 2, first, true);
defer r2.deinit();
- a.core.active = for (a.core.panes, 0..) |slot, id| {
+ a.core.view().active = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break id;
} else return error.NoShell;
const opened = try a.openView(2);
@@ -3243,7 +3243,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
const shell: u8 = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
} else return error.NoShell;
- a.core.active = shell;
+ a.core.view().active = shell;
// History the replica holds as holes, of lines a narrow grid wraps in
// two, which a wider one unwraps.
var line: [96]u8 = undefined;
@@ -3345,7 +3345,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves
const shell: u8 = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
} else return error.NoShell;
- a.core.active = shell;
+ a.core.view().active = shell;
r.confirm(try a.local(.{ .focus = true }));
var line: [64]u8 = undefined;
for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } });
@@ -3801,7 +3801,7 @@ test "a replica joined after a pane closed: the session's jump to it, its Panes
_ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/build.zig.zon", .{dir}) });
_ = try a.local(.{ .command = "Del" });
try std.testing.expectEqual(@as(usize, 1), a.core.store.closed.items.len);
- try std.testing.expect(a.core.jumps.n > 1);
+ try std.testing.expect(a.core.view().jumps.n > 1);
// What another window of the user's wrote to the store, which the
// session read (src/variants_test.zig's case, the variant hunt's).
a.core.recent.opened(a.core.recentGpa(), try std.fmt.bufPrint(&line, "{s}/build.zig", .{dir}));
@@ -3928,7 +3928,7 @@ test "a client that diverged joins again for its view: kept for it meanwhile, it
old.confirm(opened.unit);
var buf: [256]u8 = undefined;
old.confirm(try a.take(try inputOf(&buf, 2, 1, .{ .command = "New" })));
- const made = a.core.active;
+ const made = a.core.view().active;
// Its bye says it joins again: its view is kept, as every replica keeps it.
var was = Stepping.begin(&a.t, null);
a.core.awayView(opened.view);
@@ -3948,7 +3948,7 @@ test "a client that diverged joins again for its view: kept for it meanwhile, it
defer gpa.free(u);
old.confirm(u);
back.confirm(u);
- try std.testing.expectEqual(made, a.core.active);
+ try std.testing.expectEqual(made, a.core.view().active);
try std.testing.expect(pardes.layout.findPane(a.core, made) != null);
try agrees(a, old);
try agrees(a, back);
@@ -4055,7 +4055,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli
const shell: u8 = for (a.core.panes, 0..) |slot, id| {
if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
} else return error.NoShell;
- a.core.active = shell;
+ a.core.view().active = shell;
var line: [64]u8 = undefined;
for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
const out = try gpa.dupe(u8, (try a.pending()).?);
diff --git a/src/rollback.zig b/src/rollback.zig
index 46e00721..ce4016d8 100644
--- a/src/rollback.zig
+++ b/src/rollback.zig
@@ -679,16 +679,16 @@ test "a view's slot, live or drawn outside a step (a replica's own, another live
// or view 1 read (as a replica client's frontend reads its own) while
// view 0 is live: 0 parked and put back.
const text = "the column tag of view 0, its own";
- p.col_tags[0].own = try gpa.dupe(u8, text);
+ p.view().col_tags[0].own = try gpa.dupe(u8, text);
if (drawn) try pardes.views.within(p, 1, {}, Read.read) else {
p.toView(1);
p.toView(0);
}
// The live view drops it, and its memory is another's: something the
// copy has no business saving.
- const was = p.col_tags[0].own.?;
+ const was = p.view().col_tags[0].own.?;
gpa.free(was);
- p.col_tags[0].own = null;
+ p.view().col_tags[0].own = null;
const other = try gpa.alloc(u8, text.len);
defer gpa.free(other);
if (other.ptr != was.ptr) { // the heap handed out another
diff --git a/src/screen_state.zig b/src/screen_state.zig
index 07d4153b..1416ef42 100644
--- a/src/screen_state.zig
+++ b/src/screen_state.zig
@@ -1280,7 +1280,7 @@ test "a replica's terminal pane draws as its authority's does" {
_ = fb.reset(.retain_capacity);
const sa = try a.render(fa.allocator());
const sb = try b.render(fb.allocator());
- const r = a.rects[0];
+ const r = a.view().rects[0];
// The body: below the pane's tag row.
for (r.y + 1..r.y + r.h) |y| for (r.x..r.x + r.w) |x| {
const ca = sa.at(@intCast(x), @intCast(y));
diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig
index 7832a75d..8d06077e 100644
--- a/src/selection_pipe.zig
+++ b/src/selection_pipe.zig
@@ -223,12 +223,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, tasks: *T
const view = core.pipe.pipeRequest(id) orelse return;
const job = Job.copy(gpa, view) catch |err| {
core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return core.reportError(core.active, "pipe", err);
+ return core.reportError(core.view().active, "pipe", err);
};
const future = io.concurrent(work, .{ io, gpa, job, ctx, sink }) catch |err| {
job.deinit(gpa);
core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return core.reportError(core.active, "pipe", err);
+ return core.reportError(core.view().active, "pipe", err);
};
std.debug.assert(tasks.add(.{ .id = id, .future = future }));
}
diff --git a/src/tagline.zig b/src/tagline.zig
index 5cfb9f50..469d97d1 100644
--- a/src/tagline.zig
+++ b/src/tagline.zig
@@ -65,37 +65,39 @@ pub fn topbar(p: *Pardes) []const u8 {
}
pub fn columnTag(p: *const Pardes, c: usize) []const u8 {
- return p.col_tags[c].own orelse column_tag_default;
+ return p.view().col_tags[c].own orelse column_tag_default;
}
/// The header with the keyboard, when one has it.
pub fn focusedHeader(p: *Pardes) ?*Text {
- if (p.header == null) return null;
- if (p.headerColumn()) |c| return if (c < p.ncol) &p.col_tags[c] else null;
+ const v = p.view();
+ if (v.header == null) return null;
+ if (p.headerColumn()) |c| return if (c < v.ncol) &v.col_tags[c] else null;
return &p.global_tag;
}
pub fn revealHeader(p: *Pardes) void {
+ const v = p.view();
const t = focusedHeader(p) orelse {
- p.header_scroll = 0;
- p.header_top = 0;
+ v.header_scroll = 0;
+ v.header_top = 0;
return;
};
const text = edit.flatSurface(p, t) catch return;
const cur: usize = @intCast(@max(0, t.cur_row));
const rows: usize = if (p.headerColumn() != null) layout.columnBarHeight(p) else p.topBarHeight();
- if (cur < p.header_top) p.header_top = cur;
- if (rows > 0 and cur >= p.header_top + rows) p.header_top = cur + 1 - rows;
+ if (cur < v.header_top) v.header_top = cur;
+ if (rows > 0 and cur >= v.header_top + rows) v.header_top = cur + 1 - rows;
const line = modal.lineSlice(text, cur);
- const width = layout.tagCapacity(p, if (p.headerColumn()) |c| p.col_w[c] -| TAG_TEXT_INSET else p.screen_w -| TAG_TEXT_INSET);
+ const width = layout.tagCapacity(p, if (p.headerColumn()) |c| v.col_w[c] -| TAG_TEXT_INSET else v.screen_w -| TAG_TEXT_INSET);
const col = panes.File.rawDisplayCol(line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len));
- if (col < p.header_scroll) p.header_scroll = col;
- if (col >= p.header_scroll + width) p.header_scroll = col -| (width -| 1);
- var raw = panes.File.rawAtDisplay(line, p.header_scroll);
- p.header_scroll = panes.File.rawDisplayCol(line, raw);
- if (width > 0 and col >= p.header_scroll + width) {
+ if (col < v.header_scroll) v.header_scroll = col;
+ if (col >= v.header_scroll + width) v.header_scroll = col -| (width -| 1);
+ var raw = panes.File.rawAtDisplay(line, v.header_scroll);
+ v.header_scroll = panes.File.rawDisplayCol(line, raw);
+ if (width > 0 and col >= v.header_scroll + width) {
raw = modal.nextGrapheme(line, raw);
- p.header_scroll = panes.File.rawDisplayCol(line, raw);
+ v.header_scroll = panes.File.rawDisplayCol(line, raw);
}
}
@@ -151,7 +153,7 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
// A terminal showing kitty graphics says how it draws them, as an image
// pane does, and so does one drawing them as glyph art by choice.
if (panes.terminal.petscii(pane)) |chosen| {
- const on = chosen or !p.frontend.native_images;
+ const on = chosen or !p.view().frontend.native_images;
if (chosen or panes.terminal.hasImages(pane))
return std.fmt.allocPrint(arena, "{s} petscii:{s}", .{ (try shownDir(arena, pane)), if (on) "on" else "off" });
}
@@ -309,7 +311,7 @@ pub fn wrapTag(arena: std.mem.Allocator, whole: []const u8, width: usize) !Shown
/// than what is left (libframe frutil.c _frcklinewrap), and the caret past
/// its end sits at the edge (frptofchar.c clamps it to r.max.x).
pub fn tagWidth(p: *const Pardes, id: usize) usize {
- return @max(1, @as(usize, layout.tagCapacity(p, p.rects[id].w -| TAG_TEXT_INSET)));
+ return @max(1, @as(usize, layout.tagCapacity(p, p.view().rects[id].w -| TAG_TEXT_INSET)));
}
pub fn shownTag(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Shown {
@@ -366,7 +368,7 @@ pub fn draftName(p: *Pardes, pane: *Pane, col: usize) void {
const name = p.gpa.dupe(u8, f.path) catch return;
pane.closePrompt();
pane.prompt = .name;
- pane.prompt_view = p.view;
+ pane.prompt_view = p.live;
pane.input = .{ .what = .input, .own = name, .mode = .insert, .cur_pinned = true, .cur_col = @intCast(@min(name.len, panes.File.rawAtDisplay(name, col))) };
}
@@ -398,18 +400,19 @@ pub fn commitTagName(p: *Pardes, pane: *Pane) bool {
}
pub fn exitHeader(p: *Pardes) void {
- p.header = null;
- p.header_drag = false;
- p.header_scroll = 0;
- p.header_top = 0;
+ const v = p.view();
+ v.header = null;
+ v.header_drag = false;
+ v.header_scroll = 0;
+ v.header_top = 0;
}
/// Give the keyboard to a column's tag, or the workspace's for null, in
/// normal mode, its cursor where that header last had it.
pub fn enterHeader(p: *Pardes, column: ?usize) void {
exitHeader(p);
- if (p.panes[p.active]) |pane| pane.focus = .body;
- p.header = if (column) |c| .{ .column = c } else .workspace;
+ if (p.panes[p.view().active]) |pane| pane.focus = .body;
+ p.view().header = if (column) |c| .{ .column = c } else .workspace;
if (column) |c| p.setActiveColumn(c);
const t = focusedHeader(p) orelse return exitHeader(p);
takeKeyboard(t, edit.flatSurface(p, t) catch "");
@@ -437,10 +440,11 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l
/// tabs: blank is no text, so no button of acme's is taken from any. A
/// column's tag and a pane's are not: their blank is where B1 types.
pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) bool {
- if (row >= p.topBarHeight() or col >= p.screen_w) return false;
+ const v = p.view();
+ if (row >= p.topBarHeight() or col >= v.screen_w) return false;
if (col < TAG_TEXT_INSET) return true;
const text = edit.flatSurface(p, &p.global_tag) catch return false;
- const scroll: usize = if (p.header != null and p.headerColumn() == null) p.header_scroll else 0;
+ const scroll: usize = if (v.header != null and p.headerColumn() == null) v.header_scroll else 0;
const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - TAG_TEXT_INSET)) + scroll;
return at >= panes.File.displayWidth(modal.lineSlice(text, 0)) + 2;
}
@@ -474,7 +478,7 @@ test "the workspace tag is blank left of its text and past its end, and nowhere
/// pasted or restored from a dump into one becomes a space, the caret and
/// the selection kept on the same characters.
pub fn flattenHeaders(p: *Pardes) void {
- for (p.col_tags[0..p.ncol]) |*t| flatten(t);
+ for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(t);
flatten(&p.global_tag);
}
@@ -494,15 +498,15 @@ fn flatten(t: *Text) void {
test "a column or workspace tag is one line: a newline in it is a space" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true });
defer p.deinit();
- p.col_tags[0].own = try p.gpa.dupe(u8, "New\nSnarf");
- p.col_tags[0].cur_row = 1;
- p.col_tags[0].cur_col = 2;
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "New\nSnarf");
+ p.view().col_tags[0].cur_row = 1;
+ p.view().col_tags[0].cur_col = 2;
p.global_tag.own = try p.gpa.dupe(u8, "Newcol\nExit");
p.sync();
try std.testing.expectEqualStrings("New Snarf", columnTag(p, 0));
try std.testing.expectEqualStrings("Newcol Exit", p.global_tag.own.?);
- try std.testing.expectEqual(@as(i32, 0), p.col_tags[0].cur_row);
- try std.testing.expectEqual(@as(i32, 6), p.col_tags[0].cur_col);
+ try std.testing.expectEqual(@as(i32, 0), p.view().col_tags[0].cur_row);
+ try std.testing.expectEqual(@as(i32, 6), p.view().col_tags[0].cur_col);
try std.testing.expectEqual(pardes.COLBAR_H, layout.columnBarHeight(p));
try std.testing.expectEqual(pardes.TOPBAR_H, p.topBarHeight());
}
diff --git a/src/tape.zig b/src/tape.zig
index 3752af54..d3e5558a 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -169,13 +169,22 @@ pub const shape = blk: {
var types: []const type = &.{ Input, []const u64, struct { u8, u64 } };
for (results) |R| types = types ++ .{R};
for (host_fns) |f| types = types ++ .{@typeInfo(@typeInfo(@typeInfo(@FieldType(VTable, f)).optional.child).pointer.child).@"fn".return_type.?};
- for (watched) |name| types = types ++ .{@FieldType(Pardes, name)};
+ for (watched) |name| types = types ++ .{Watched(name)};
break :blk walk.shape(types);
};
/// Fields a host writes straight into the core between its calls.
const watched = .{ "frontend", "present_skipped", "needs_frame", "quit", "active", "unattended" };
+/// Watched field `name` of `p`: the live view's, or the session's.
+fn watchedOf(p: *Pardes, comptime name: []const u8) *Watched(name) {
+ return if (comptime @hasField(Pardes.View, name)) &@field(p.view(), name) else &@field(p, name);
+}
+
+fn Watched(comptime name: []const u8) type {
+ return if (@hasField(Pardes.View, name)) @FieldType(Pardes.View, name) else @FieldType(Pardes, name);
+}
+
const Kind = enum(u8) { input, done, host, ret, set, digest };
/// A digest record's kind byte (replica.zig reads a unit's last).
pub const digest_kind: u8 = @backingInt(Kind.digest);
@@ -292,10 +301,10 @@ pub const Tape = struct {
fn noteWrites(t: *Tape) void {
const p = t.core orelse return;
inline for (watched, 0..) |name, i| {
- const now = walk.digest(@FieldType(Pardes, name), &@field(p, name));
+ const now = walk.digest(Watched(name), watchedOf(p, name));
if (now != t.seen[i]) {
t.seen[i] = now;
- const set: struct { u8, @FieldType(Pardes, name) } = .{ i, @field(p, name) };
+ const set: struct { u8, Watched(name) } = .{ i, watchedOf(p, name).* };
t.record(.set, @TypeOf(set), &set);
}
}
@@ -303,7 +312,7 @@ pub const Tape = struct {
fn seeFields(t: *Tape) void {
const p = t.core orelse return;
- inline for (watched, 0..) |name, i| t.seen[i] = walk.digest(@FieldType(Pardes, name), &@field(p, name));
+ inline for (watched, 0..) |name, i| t.seen[i] = walk.digest(Watched(name), watchedOf(p, name));
}
/// The host's functions go through the tape while it records, whoever
@@ -534,7 +543,7 @@ pub const Tape = struct {
}
const p = t.core orelse return;
inline for (watched, 0..) |name, i| if (i == which) {
- @field(p, name) = walk.decode(@FieldType(Pardes, name), r, t.arena.allocator()) catch return;
+ watchedOf(p, name).* = walk.decode(Watched(name), r, t.arena.allocator()) catch return;
};
}
@@ -645,13 +654,20 @@ const stream_fields = walk.fieldNames(pardes.Stream);
const pane_fields = walk.fieldNames(pardes.Pane);
const file_fields = walk.fieldNames(pardes.panes.File.State);
const places_fields = walk.fieldNames(pardes.panes.Places);
-const Parts = [pardes_fields.len + stream_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64;
+const view_fields = walk.fieldNames(Pardes.View);
+const Parts = [pardes_fields.len + stream_fields.len + pardes.views.max * view_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64;
/// The session's digest as one per field of the core's, its stream's, and
/// each pane's and its file's, so a divergence says where it is.
fn digestParts(p: *const Pardes, parts: *Parts) []const u64 {
var n = walk.fieldDigests(Pardes, p, parts[0..pardes_fields.len]).len;
n += walk.fieldDigests(pardes.Stream, &p.stream, parts[n..][0..stream_fields.len]).len;
+ for (&p.views) |*slot| if (slot.*) |*v| {
+ n += walk.fieldDigests(Pardes.View, v, parts[n..][0..view_fields.len]).len;
+ } else {
+ @memset(parts[n..][0..view_fields.len], 0);
+ n += view_fields.len;
+ };
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
parts[n] = id;
@@ -677,6 +693,14 @@ fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []cons
said.print(a, "{s}{s} ", .{ if (i < pardes_fields.len) "" else "stream.", name }) catch {};
count += 1;
}
+ for (0..pardes.views.max) |k| for (view_fields) |name| {
+ if (i >= n) break;
+ if (got[i] != want[i]) {
+ said.print(a, "views[{d}].{s} ", .{ k, name }) catch {};
+ count += 1;
+ }
+ i += 1;
+ };
while (i + 2 <= n and count < 16) {
const id = got[i];
const has_file = got[i + 1] != 0;
diff --git a/src/terminal.zig b/src/terminal.zig
index c9c60b5b..8204b0af 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -544,7 +544,7 @@ pub fn visibleCursor(pane: *const Pane) ?GridCursor {
/// many as keep its cursor's row in sight, as tmux pans a bigger window in
/// a smaller client. 0 in the view that sizes it, and in one tall enough.
pub fn panFor(p: *const Pardes, pane: *const Pane, r: pardes.Rect) u16 {
- if (pane.sized_by == p.view or pane.collapsed or !pane.isTerminal()) return 0;
+ if (pane.sized_by == p.live or pane.collapsed or !pane.isTerminal()) return 0;
const shown = r.h -| pane.tag_rows;
if (shown == 0 or shown >= pane.rows) return 0;
const state = pane.terminal orelse return 0;
@@ -2642,7 +2642,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
@@ -2783,7 +2783,7 @@ test "terminal Filter preserves exact palette-null light theme default roles" {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
const ordinary = try p.render(frame.allocator());
@@ -2842,7 +2842,7 @@ test "terminal Filter refuses a foreground that would collapse onto the page" {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
@@ -2934,7 +2934,7 @@ test "tty ansi colors follow the prompt hug into normal mode" {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
const red: pardes.Color = .{ .rgb = p.theme().palette.?[1] };
@@ -2971,7 +2971,7 @@ test "a prompt row hidden end to end paints nothing at all" {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
p.shell_rows.stale = true;
@@ -3060,8 +3060,8 @@ fn syncPixels(p: *const Pardes, pane: *Pane) void {
if (comptime !images_enabled) return;
const state = pane.terminal orelse return;
const vt = &state.vt;
- vt.width_px = @as(u32, vt.cols) * p.cell_pixels.w;
- vt.height_px = @as(u32, vt.rows) * p.cell_pixels.h;
+ vt.width_px = @as(u32, vt.cols) * p.view().cell_pixels.w;
+ vt.height_px = @as(u32, vt.rows) * p.view().cell_pixels.h;
}
/// When the pane's next kitty animation frame is due (ms on the core's
@@ -3153,7 +3153,7 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t
var out: std.ArrayList(u8) = .empty;
defer out.deinit(gpa);
_ = try ptyWritesByPane(p, &out);
- p.active = 0;
+ p.view().active = 0;
// Asking while its pane has the keyboard: told at once that it has.
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1004h" } });
try std.testing.expectEqualStrings("0:\x1b[I\n", try ptyWritesByPane(p, &out));
@@ -3161,12 +3161,12 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t
try std.testing.expectEqualStrings("", try ptyWritesByPane(p, &out));
// A click into the other pane moves the keyboard: out of one, into the
// other.
- const r = p.rects[1];
+ const r = p.view().rects[1];
const at_col = r.x + config.GUTTER + 2;
const at_row = p.bodyTop(p.panes[1].?, r) + 1;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = at_col, .row = at_row } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = at_col, .row = at_row } });
- try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().active);
try std.testing.expectEqualStrings("0:\x1b[O\n1:\x1b[I\n", try ptyWritesByPane(p, &out));
// The window: away and back.
p.update(.{ .focus = false });
@@ -3176,7 +3176,7 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t
p.update(.{ .focus = true });
try std.testing.expectEqualStrings("1:\x1b[I\n", try ptyWritesByPane(p, &out));
// A program that did not ask hears nothing: pane 2.
- p.active = 2;
+ p.view().active = 2;
p.update(.tick);
try std.testing.expectEqualStrings("1:\x1b[O\n", try ptyWritesByPane(p, &out));
}
@@ -3203,8 +3203,8 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 });
defer p.deinit();
- p.frontend.native_images = true;
- p.active = 0;
+ p.view().frontend.native_images = true;
+ p.view().active = 0;
p.update(.{ .resize = .{ .cols = 80, .rows = 24, .cell_pixels = .{ .w = 10, .h = 20 } } });
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -3215,7 +3215,7 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
const places = imagePlaces(s);
try std.testing.expectEqual(@as(usize, 1), places.len);
const place = places[0];
- const r = p.rects[0];
+ const r = p.view().rects[0];
const img = pane.terminal.?.vt.screens.active.kitty_images.imageById(7).?;
try std.testing.expectEqual(pardes.Placement.keyOf(pane.serial, 7, @truncate(img.generation)), place.key);
try std.testing.expectEqual(pardes.RectCell{ .x = r.x + config.GUTTER + 4, .y = p.bodyTop(pane, r) + 2, .w = 2, .h = 1 }, place.dst);
@@ -3257,7 +3257,7 @@ test "ED 3 takes away a kitty placement whose row it erased: it never comes back
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
p.update(.{ .resize = .{ .cols = 80, .rows = 24, .cell_pixels = .{ .w = 10, .h = 20 } } });
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -3324,7 +3324,7 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
p.update(.{ .resize = .{ .cols = 80, .rows = 24, .cell_pixels = .{ .w = 10, .h = 20 } } });
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -3338,7 +3338,7 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
const s = try p.render(frame.allocator());
const places = imagePlaces(s);
try std.testing.expectEqual(@as(usize, 1), places.len);
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r) + 1;
try std.testing.expectEqual(pardes.RectCell{ .x = tx + 2, .y = y, .w = 2, .h = 1 }, places[0].dst);
@@ -3358,13 +3358,13 @@ test "a terminal's image is a placement whatever the frontend draws, and the Pet
const pane = p.panes[0].?;
pane.body.mode = .tty;
p.update(.{ .output = .{ .pane = 0, .bytes = kittyTransmit("c=2,r=1") } });
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r);
// A frontend that draws no pixels (a tty under no kitty graphics) is
// handed the picture all the same, and the cells under it are its.
- p.frontend.native_images = false;
+ p.view().frontend.native_images = false;
var s = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
try std.testing.expect(!imagePlaces(s)[0].art.glyph);
@@ -3374,7 +3374,7 @@ test "a terminal's image is a placement whatever the frontend draws, and the Pet
try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null);
// The builtin flips the pane to glyph art and back.
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
try std.testing.expect(p.executeBuiltinLine(0, "Petscii"));
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 414fe776..860e96c8 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -1030,7 +1030,7 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell
defer art.deinit(gpa);
try std.testing.expectEqual(@as(*const pardes.Surface, s), try art.frame(gpa, a, s, true, 16));
const shown = try art.frame(gpa, a, s, false, 16);
- const r = core.rects[0];
+ const r = core.view().rects[0];
const x0 = r.x + pardes.config.GUTTER + 7;
const y0 = core.bodyTop(pane, r) + 1;
var painted: usize = 0;
@@ -1098,7 +1098,7 @@ test "host watch closes initial race and reloads rename-over PDF while idle" {
}
try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "reloaded") != null);
- core.frontend.native_images = true;
+ core.view().frontend.native_images = true;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const surface = try core.render(frame.allocator());
@@ -1124,14 +1124,14 @@ const PdfWheelTarget = struct { pane: usize, page: usize };
fn nativePdfWheelTarget(core: *const pardes.Pardes, mouse: vaxis.Mouse) ?PdfWheelTarget {
if (comptime !pardes.pdf_enabled) return null;
- if (!core.frontend.native_images or mouse.type != .press or
+ if (!core.view().frontend.native_images or mouse.type != .press or
(mouse.button != .wheel_up and mouse.button != .wheel_down) or
mouse.col < 0 or mouse.row < 0) return null;
const col: u16 = @intCast(mouse.col);
const row: u16 = @intCast(mouse.row);
for (core.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const rect = core.rects[id];
+ const rect = core.view().rects[id];
if (col < rect.x or col >= rect.x + rect.w or
row < rect.y or row >= rect.y + rect.h) continue;
const page = pane.pdfPage() orelse return null;
@@ -1769,7 +1769,7 @@ fn localSession(
sh.from = 0;
if (live.on) startInput(loop, live) catch {};
if (live.on) clearNativeImages(&live.kitty, &live.vx, &live.tty);
- nc.frontend.native_images = live.on and live.vx.caps.kitty_graphics;
+ nc.view().frontend.native_images = live.on and live.vx.caps.kitty_graphics;
nc.unattended = !live.on;
sh.peers.alone_unattended = !live.on;
if (fs) |f| f.reset(nc);
@@ -1977,7 +1977,7 @@ const Shell = struct {
/// The live view's terminal (null in tests).
fn term(s: *const Shell) ?*Screen {
- return s.terms[s.core.view];
+ return s.terms[s.core.live];
}
fn attached(s: *const Shell) bool {
@@ -2001,11 +2001,11 @@ const Shell = struct {
fn detach(ctx: ?*anyopaque) void {
const s = of(ctx);
// A replica client's: its link ends.
- if (s.peers.detach(s.core.view)) return;
- if (!s.attached()) return s.core.reportFailure(s.core.active, "Detach: no terminal is attached");
+ if (s.peers.detach(s.core.live)) return;
+ if (!s.attached()) return s.core.reportFailure(s.core.view().active, "Detach: no terminal is attached");
// One of several: its view goes, and the session stays on the rest.
- if (pardes.views.count(s.core) > 1) return s.dropView(s.core.view, .detach);
- if (!daemon.kept()) return s.core.reportFailure(s.core.active, "Detach: no pardes daemon keeps this session (it is its terminal's job)");
+ if (pardes.views.count(s.core) > 1) return s.dropView(s.core.live, .detach);
+ if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon keeps this session (it is its terminal's job)");
s.leaveTerminal();
}
@@ -2023,7 +2023,7 @@ const Shell = struct {
const screen = s.term() orelse return;
stopInput(s.io, &screen.thread);
screen.leave();
- s.core.frontend.native_images = false;
+ s.core.view().frontend.native_images = false;
s.setAttended(false);
// The stub's stdin, stdout and stderr were its terminal too.
const null_fd = libc.open("/dev/null", .{ .ACCMODE = .RDWR, .CLOEXEC = true }, @as(libc.mode_t, 0));
@@ -2194,9 +2194,9 @@ const Shell = struct {
if (rec.nttys == 0) {
// The live view alone (never one kept for a rejoin) is the
// session's own.
- for (0..pardes.views.max) |k| if (k != core.view and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
- s.terms[core.view] = primary;
- primary.feed.view = core.view;
+ for (0..pardes.views.max) |k| if (k != core.live and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
+ s.terms[core.live] = primary;
+ primary.feed.view = core.live;
return;
}
for (rec.ttys[0..rec.nttys]) |t| {
@@ -2229,7 +2229,7 @@ const Shell = struct {
s.terms[t.view] = sc;
}
for (0..pardes.views.max) |k| if (pardes.views.isOpen(core, @intCast(k)) and s.terms[k] == null and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
- if (s.terms[core.view] == null) s.terms[core.view] = primary;
+ if (s.terms[core.live] == null) s.terms[core.live] = primary;
}
fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
@@ -2427,7 +2427,7 @@ const Shell = struct {
}
// One of several: its view goes with it.
if (pardes.views.count(core) > 1) {
- s.dropView(core.view, .detach);
+ s.dropView(core.live, .detach);
return true;
}
// The terminal went: a session the daemon keeps carries on
@@ -2470,7 +2470,7 @@ const Shell = struct {
.pty_read => |pr| {
tookRead(s.io, pr.id);
s.output_seen = true;
- if (pr.id == core.active) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
+ if (pr.id == core.view().active) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
if (s.gens[pr.id] == pr.gen)
core.update(.{ .output = .{ .pane = @intCast(pr.id), .bytes = pr.bytes } });
s.gpa.free(pr.bytes);
@@ -2541,7 +2541,7 @@ const Shell = struct {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- core.setStatus(core.active, message.stamp(&mbuf, "lsp", text));
+ core.setStatus(core.view().active, message.stamp(&mbuf, "lsp", text));
s.lsp_gpa.free(text);
},
.pipe_done => |response_value| {
@@ -2621,11 +2621,11 @@ const Shell = struct {
};
const sc = s.term() orelse return;
- s.core.frontend.native_image_patches = sc.feed.shm.load(.acquire);
+ s.core.view().frontend.native_image_patches = sc.feed.shm.load(.acquire);
if (sc.caps_pending and sc.on and sc.vx.queries_done.load(.unordered)) {
sc.caps_pending = false;
sc.vx.enableDetectedFeatures(sc.tty.writer()) catch {};
- s.core.frontend.native_images = sc.vx.caps.kitty_graphics;
+ s.core.view().frontend.native_images = sc.vx.caps.kitty_graphics;
if (sc.vx.caps.kitty_graphics) kittyShmProbe(sc.tty.writer(), &sc.feed);
sc.vx.queueRefresh();
s.core.needs_frame = true;
@@ -2759,7 +2759,7 @@ const Shell = struct {
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
- const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.screen_h, s.core.screen_w) catch |err| {
+ const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
if (running) return s.core.restartFailed(pane, err);
return s.core.shellFailed(pane, err);
};
@@ -2924,7 +2924,7 @@ const Shell = struct {
const s = of(ctx);
if (!s.threads_ok) {
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return s.core.reportError(s.core.active, "pipe", error.WorkersUnavailable);
+ return s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable);
}
selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe);
}
@@ -3023,11 +3023,11 @@ test "TTY worker setup failures finish matching LSP and pipe requests" {
.inotify_fd = -1,
.threads_ok = true,
};
- core.lspRequest(core.active, .status, "");
+ core.lspRequest(core.view().active, .status, "");
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.active),
+ .pane = @intCast(core.view().active),
.offset = 0,
.arg = "",
};
diff --git a/src/upgrade.zig b/src/upgrade.zig
index b4003aa6..7819f216 100644
--- a/src/upgrade.zig
+++ b/src/upgrade.zig
@@ -76,7 +76,7 @@ fn inodeOf(path: [:0]const u8) ?u64 {
/// rebuilding (a stat). ponytail: explicit only, no watch and no automatic
/// upgrade.
pub fn noticeNewer(core: *pardes.Pardes) void {
- if (newer()) core.setMessage(core.active, pardes.newer_build_words);
+ if (newer()) core.setMessage(core.view().active, pardes.newer_build_words);
}
/// Whether to say a newer build is installed now (`noticeNewer`): the
@@ -414,7 +414,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
// keep its blocks for as long as this session runs.
if (rec.old >= 0) _ = libc.close(rec.old);
rec.old = -1;
- p.setMessage(p.active, if (rec.refused.len > 0)
+ p.setMessage(p.view().active, if (rec.refused.len > 0)
std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before"
else
"Upgrade: now " ++ version_line);
@@ -436,7 +436,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
var o = opts;
o.load_path = null;
const p = try pardes.Pardes.init(core_gpa, o);
- p.setMessage(p.active, std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore");
+ p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore");
return p;
}
}
diff --git a/src/views.zig b/src/views.zig
index 169bef63..0c96c792 100644
--- a/src/views.zig
+++ b/src/views.zig
@@ -3,22 +3,24 @@
//! scroll over the panes every view shares: their text, terminals, tags,
//! registers and messages.
//!
-//! The core still sees one view, the live one, in the fields it always had:
-//! a view's share of the session (`fields`) and of each pane (`PaneView`) is
-//! copied out when another view goes live (`park`) and back when it is live
-//! again (`unpark`). No line of the core reads a view through an
-//! indirection, and one view never parks: today's single client runs
-//! exactly as before.
+//! A view's share of the session is `Pardes.View`, one of `Pardes.views`,
+//! and the live one is `views[view]` (`Pardes.view()`): going into another
+//! is an index. Each view's share of a pane (`PaneView`) is still swapped:
+//! the live view's is in the pane's own fields, the others' in `Pane.pv`
+//! (copied out when another view goes live, `park`, and back, `unpark`),
+//! so the ~3,000 references to a pane's cursor, mode, scroll and geometry
+//! read it as they always did. A pane closing leaves every view's layout
+//! at once (`gone`).
//!
-//! A parked view is in no digest (Pardes.replica's `parked`, Pane's `pv`):
-//! a slot is written whenever its view goes out, so the live view's slot is
-//! stale by design, and a parked view that diverged shows when it is live
-//! again. The pump draws the other views by going into each and back
-//! (`drawOthers`), which leaves every digested field as it was; a replica
-//! that draws nothing skips it.
+//! The views are in the digest; the panes' shares of the views not live
+//! (Pane's `pv`) are not: a pane's slot is written whenever its view goes
+//! out, so the live view's is stale by design, and a share that diverged
+//! shows when its view is live again. A view drawn out of turn (`drawOne`,
+//! `within`) is put back after exactly as it was.
const std = @import("std");
const pardes = @import("pardes.zig");
const Pardes = pardes.Pardes;
+const View = Pardes.View;
const Pane = pardes.Pane;
const Text = pardes.panes.Text;
const File = pardes.panes.File;
@@ -28,26 +30,6 @@ const MAX_PANES = pardes.MAX_PANES;
/// Views at once: a window or terminal each.
pub const max = 4;
-/// The session's fields that are each view's own: its screen and layout,
-/// its focus, its pointer and gestures, its jumps, its key prefixes, and
-/// what drawing it keeps (its frame and its timings).
-pub const fields = [_][:0]const u8{
- "screen_w", "screen_h", "cell_pixels", "row_metrics",
- "ncol", "cols", "col_tags", "rects",
- "col_x", "col_w", "active",
- "jumps",
- "active_column",
- "frontend",
- "drag", "mouse_grab", "window_focused", "focus_told",
- "hover_col", "hover_row", "pointer_raw_col", "pointer_raw_row",
- "pointer_body_hit", "pointer_tag_hit", "raw_hover_intent", "pointer_inside",
- "last_click", "click_as", "chord_hold", "wheel_guard",
- "prefix", "register", "window_pick",
- "leader_keys", "leader_n", "header",
- "header_drag", "header_sweep", "header_scroll", "header_top",
- "chord_arg", "clip_pending",
-};
-
/// A pane's fields that are each view's own: where it is in the view's
/// layout, which of its texts has the keyboard, how far it is scrolled, and
/// what the view's step measured of it (its tag's rows, its bands).
@@ -56,8 +38,6 @@ const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_
/// The body's: its cursor, selections and mode. Its undo stays the pane's.
const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" };
-pub const View = Part(Pardes, &fields);
-
/// Named field by field, not taken from Pane's type: a pane holds its own.
pub const PaneView = struct {
focus: Pane.Focus = .body,
@@ -78,120 +58,80 @@ pub const PaneView = struct {
cols: u16 = 1,
rows: u16 = 1,
- /// In a dump (`Dumped`): what a pane's step works out again. Its `view`
+ /// In a dump (`Shares`): what a pane's step works out again. Its `view`
/// is dumped: the step after `unpark` reads it before it syncs.
pub const replica = .{ .derived = .{ "notices", "pan" } };
};
-/// A view not live: its share of the session, and the serial of each pane
-/// slot when it went out, by which the panes closed since leave its layout.
-pub const Parked = struct {
- view: View,
- serials: [MAX_PANES]u32 = @splat(0),
-};
-
-/// What a session's dump keeps of a view's share: all of it but what
-/// drawing keeps (Pardes.replica's local fields: its frame and its
-/// timings).
-const kept = blk: {
- @setEvalBranchQuota(100_000);
- var names: []const [:0]const u8 = &.{};
- for (fields) |name| {
- const local = for (Pardes.replica.local) |l| {
- if (std.mem.eql(u8, l, name)) break true;
- } else false;
- if (!local) names = names ++ &[_][:0]const u8{name};
- }
- const out: [names.len][:0]const u8 = names[0..names.len].*;
- break :blk out;
-};
-
-/// A view not live as a session's dump keeps it (dump.zig): its share of
-/// the session, its slots' serials, and its share of each pane. The live
-/// view is the core's own fields; its slot is stale, and no part of it.
-pub const Dumped = struct {
+/// The panes' shares of a view not live, as a session's dump keeps them
+/// (dump.zig): the live view's are the panes' own fields.
+pub const Shares = struct {
k: u8,
- view: Part(Pardes, &kept),
- serials: [MAX_PANES]u32 = @splat(0),
panes: []const Share = &.{},
pub const Share = struct { id: u16, pv: PaneView };
};
+/// A view not live as a dump before `Pardes.views` kept it: its share of
+/// the session beside its panes' (read once, by name, into `views[k]`).
+pub const OldDumped = struct {
+ k: u8,
+ view: View = .{},
+ panes: []const Shares.Share = &.{},
+};
+
fn bit(k: usize) u8 {
return @as(u8, 1) << @intCast(k);
}
-/// The views not live, as a dump keeps them: the slices `gpa`'s, what
-/// they hold the session's.
-pub fn dumped(p: *const Pardes, gpa: std.mem.Allocator) ![]Dumped {
- var out: std.ArrayList(Dumped) = .empty;
+/// The panes' shares of the views not live, as a dump keeps them: the
+/// slices `gpa`'s, what they hold the session's.
+pub fn dumped(p: *const Pardes, gpa: std.mem.Allocator) ![]Shares {
+ var out: std.ArrayList(Shares) = .empty;
errdefer {
for (out.items) |d| gpa.free(d.panes);
out.deinit(gpa);
}
for (0..max) |k| {
- if (k == p.view or !isOpen(p, @intCast(k))) continue;
- const slot = p.parked[k] orelse continue;
- var d: Dumped = .{ .k = @intCast(k), .view = undefined, .serials = slot.serials };
- copy(&kept, &d.view, &slot.view);
- var shares: std.ArrayList(Dumped.Share) = .empty;
+ if (k == p.live or !isOpen(p, @intCast(k))) continue;
+ var shares: std.ArrayList(Shares.Share) = .empty;
errdefer shares.deinit(gpa);
// A view not live has a share of every pane: written when it went
- // out, made with one made since (`installed`). `pv_known` says
- // which shares own their selections, not which there are.
+ // out, made with one made since (`installed`).
for (p.panes, 0..) |s, id| if (s) |pane| {
try shares.append(gpa, .{ .id = @intCast(id), .pv = pane.pv[k] });
};
- d.panes = try shares.toOwnedSlice(gpa);
- try out.append(gpa, d);
+ try out.append(gpa, .{ .k = @intCast(k), .panes = try shares.toOwnedSlice(gpa) });
}
return out.toOwnedSlice(gpa);
}
-/// The views a dump kept (`dumped`) parked again in `p`, a session just
-/// loaded with its live view: each its slot, each pane its share in it
-/// (one a view had none of as the live view has it). What they hold is the
-/// session's then, the slices the caller's; a failure moves nothing. A
-/// view the core says open that the dump has none of is not.
-pub fn undumped(p: *Pardes, others: []const Dumped) !void {
+/// The panes' shares a dump kept (`dumped`) parked again in `p`, a
+/// session just loaded with its views: each pane its share in each view
+/// (one a view had none of as the live view has it). What they hold is
+/// the session's then, the slices the caller's. A view the core says open
+/// that the dump has no shares of is not.
+pub fn undumped(p: *Pardes, others: []const Shares) void {
var take: u8 = 0;
- for (others) |d| if (d.k < max and d.k != p.view and isOpen(p, d.k) and take & bit(d.k) == 0) {
+ for (others) |d| if (d.k < max and d.k != p.live and isOpen(p, d.k) and take & bit(d.k) == 0) {
take |= bit(d.k);
};
- var made: u8 = 0;
- errdefer for (0..max) |k| if (made & bit(k) != 0) {
- p.gpa.destroy(p.parked[k].?);
- p.parked[k] = null;
- };
- if (take != 0) for (0..max) |k| if ((take | bit(p.view)) & bit(k) != 0 and p.parked[k] == null) {
- const slot = try p.gpa.create(Parked);
- slot.* = .{ .view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h } };
- p.parked[k] = slot;
- made |= bit(k);
- };
- // Nothing fails from here.
- p.views_open &= take | bit(p.view);
+ for (0..max) |k| if (k != p.live and isOpen(p, @intCast(k)) and take & bit(k) == 0) dropView(p, @intCast(k));
+ p.views_open &= take | bit(p.live);
p.views_away &= p.views_open;
// The live view's slot owning nothing, as `installed` makes it.
for (p.panes) |s| if (s) |pane| {
- if (take != 0) pane.pv[p.view] = fresh(pane);
- pane.pv_known |= bit(p.view);
+ if (take != 0) pane.pv[p.live] = fresh(pane);
+ pane.pv_known |= bit(p.live);
};
var left = take;
for (others) |d| {
- var view = d.view;
if (left & bit(d.k) == 0) {
// Refused (another build's, or twice): what it holds goes.
- for (&view.col_tags) |*t| t.deinit(p.gpa);
- if (view.chord_arg) |arg| p.gpa.free(arg);
for (d.panes) |sh| if (sh.pv.body.sels.len > 0) p.gpa.free(sh.pv.body.sels);
continue;
}
left &= ~bit(d.k);
- const slot = p.parked[d.k].?;
- slot.serials = d.serials;
- copy(&kept, &slot.view, &view);
for (d.panes) |sh| {
const pane = (if (sh.id < MAX_PANES) p.panes[sh.id] else null) orelse {
if (sh.pv.body.sels.len > 0) p.gpa.free(sh.pv.body.sels);
@@ -211,15 +151,34 @@ pub fn undumped(p: *Pardes, others: []const Dumped) !void {
}
}
+/// The views a dump before `Pardes.views` kept (`OldDumped`): each its
+/// share of the session into `views[k]`, the rest as `undumped`. What
+/// each view holds is the session's then; one refused is freed.
+pub fn undumpedOld(p: *Pardes, others: []const OldDumped, gpa: std.mem.Allocator) !void {
+ var shares: std.ArrayList(Shares) = .empty;
+ defer shares.deinit(gpa);
+ var took: u8 = 0;
+ for (others) |d| {
+ var view = d.view;
+ if (d.k >= max or d.k == p.live or !isOpen(p, d.k) or took & bit(d.k) != 0) {
+ freeView(p, &view);
+ continue;
+ }
+ took |= bit(d.k);
+ p.views[d.k] = view;
+ try shares.append(gpa, .{ .k = d.k, .panes = d.panes });
+ }
+ undumped(p, shares.items);
+}
+
/// The live view alone, as view 0: every other closed. A session loaded
/// for one client (a Restore, `-l`) is one view.
pub fn only(p: *Pardes) void {
p.views_away = 0;
- for (0..max) |k| if (k != p.view) close(p, @intCast(k));
- emptied(p, p.view);
- const k = p.view;
+ for (0..max) |k| if (k != p.live) close(p, @intCast(k));
+ const k = p.live;
if (k == 0) return;
- std.mem.swap(?*Parked, &p.parked[0], &p.parked[k]);
+ std.mem.swap(?View, &p.views[0], &p.views[k]);
for (p.panes) |s| if (s) |pane| {
// The live slot is stale: as `installed` makes it, owning nothing.
pane.pv[0] = fresh(pane);
@@ -227,7 +186,7 @@ pub fn only(p: *Pardes) void {
if (pane.sized_by == k) pane.sized_by = 0;
if (pane.prompt_view == k) pane.prompt_view = 0;
};
- p.view = 0;
+ p.live = 0;
p.views_open = 1;
}
@@ -317,7 +276,7 @@ fn fresh(pane: *const Pane) PaneView {
/// A new pane is in each other view as it was made, there to be shown.
pub fn installed(p: *Pardes, pane: *Pane) void {
- pane.sized_by = p.view;
+ pane.sized_by = p.live;
if (!several(p)) return;
// The live view's slot too, owning nothing: a pane closed before its
// view next parks is torn down with that slot never written, and
@@ -330,30 +289,46 @@ pub fn installed(p: *Pardes, pane: *Pane) void {
/// A pane going: the other views' selections of it go too.
pub fn tornDown(p: *Pardes, pane: *Pane) void {
- for (0..max) |k| if (k != p.view and pane.pv_known & (@as(u8, 1) << @intCast(k)) != 0) {
+ for (0..max) |k| if (k != p.live and pane.pv_known & (@as(u8, 1) << @intCast(k)) != 0) {
const sels = pane.pv[k].body.sels;
if (sels.len > 0) p.gpa.free(sels);
pane.pv[k].body.sels = &.{};
};
}
-fn park(p: *Pardes) void {
- const slot = p.parked[p.view].?;
- copy(&fields, &slot.view, p);
- for (p.panes, 0..) |s, id| {
- const pane = s orelse {
- slot.serials[id] = 0;
- continue;
- };
- slot.serials[id] = pane.serial;
- pane.pv[p.view] = extract(pane);
+/// Pane `id` closed: it leaves the layout of every view not live, and the
+/// keyboard of one it had moves to that view's first pane left (the live
+/// view's is the closing's to move, panes.removePane).
+pub fn gone(p: *Pardes, id: usize) void {
+ if (!several(p)) return;
+ for (&p.views, 0..) |*slot, k| {
+ if (k == p.live) continue;
+ const v = &(slot.* orelse continue);
+ for (v.cols[0..v.ncol]) |*col| {
+ var n: usize = 0;
+ for (col.panes[0..col.n]) |other| if (other != id) {
+ col.panes[n] = other;
+ n += 1;
+ };
+ col.n = n;
+ }
+ if (v.active != id) continue;
+ v.active = for (v.cols[0..v.ncol]) |col| {
+ if (col.n > 0) break col.panes[0];
+ } else for (p.panes, 0..) |s, i| {
+ if (s != null and i != id) break i;
+ } else 0;
}
}
+fn park(p: *Pardes) void {
+ for (p.panes) |s| if (s) |pane| {
+ pane.pv[p.live] = extract(pane);
+ };
+}
+
fn unpark(p: *Pardes, k: u8) void {
- const slot = p.parked[k].?;
- copy(&fields, p, &slot.view);
- p.view = k;
+ p.live = k;
for (p.panes) |s| if (s) |pane| {
apply(pane, &pane.pv[k]);
// The live body owns the selections now; the slot, stale while its
@@ -362,28 +337,10 @@ fn unpark(p: *Pardes, k: u8) void {
pane.pv[k].body.sels = &.{};
pane.pv[k].body.nsel = 0;
};
- // The panes closed while it was out (a slot empty or another pane's
- // now) leave its layout, and its keyboard leaves them.
- for (0..p.ncol) |c| {
- var n: usize = 0;
- for (p.cols[c].panes[0..p.cols[c].n]) |id| {
- const pane = p.panes[id] orelse continue;
- if (pane.serial != slot.serials[id]) continue;
- p.cols[c].panes[n] = id;
- n += 1;
- }
- p.cols[c].n = n;
- }
- if (layout.findPane(p, p.active) == null) {
- for (0..p.ncol) |c| if (p.cols[c].n > 0) {
- p.active = p.cols[c].panes[0];
- break;
- };
- }
layout.compute(p);
// Its terminals' cursors moved while it was out: each pan follows.
for (p.panes, 0..) |s, id| if (s) |pane| {
- pane.pan = pardes.panes.terminal.panFor(p, pane, p.rects[id]);
+ pane.pan = pardes.panes.terminal.panFor(p, pane, p.view().rects[id]);
};
}
@@ -392,30 +349,18 @@ fn unpark(p: *Pardes, k: u8) void {
/// focus), it goes into the view's active column, as kakoune shows a buffer
/// in the window that asked for it.
pub fn show(p: *Pardes) void {
- if (p.panes[p.active] == null or layout.findPane(p, p.active) != null) return;
- const c = layout.firstColumn(p) orelse layout.columnBySerial(p, p.active_column) orelse p.ncol - 1;
- layout.acmePlace(p, c, null, p.active);
+ const v = p.view();
+ if (p.panes[v.active] == null or layout.findPane(p, v.active) != null) return;
+ const c = layout.firstColumn(p) orelse layout.columnBySerial(p, v.active_column) orelse v.ncol - 1;
+ layout.acmePlace(p, c, null, v.active);
}
-/// Into view `k`: the live one parked, `k`'s put in its place.
+/// Into view `k`: the live one's pane shares parked, `k`'s put in their place.
pub fn to(p: *Pardes, k: u8) void {
std.debug.assert(isOpen(p, k));
- if (k == p.view) return;
+ if (k == p.live) return;
park(p);
unpark(p, k);
- emptied(p, k);
-}
-
-/// View `k` is live: its slot, stale until it parks again (written whole
-/// then), keeps no pointer to what it handed the live fields. A rollback
-/// copy walks every slot (src/rollback.zig): one left there, freed by the
-/// live view and the memory another's since, would be saved and its old
-/// bytes put back over the other's. (A pane's share holds no pointer but
-/// its selections, which `unpark` hands over.)
-fn emptied(p: *Pardes, k: u8) void {
- const slot = p.parked[k] orelse return;
- slot.view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h };
- slot.view.col_tags = @splat(.{ .what = .column, .gpa = p.gpa });
}
/// A new view, as the live one is laid out and focused, with its panes
@@ -426,26 +371,20 @@ pub fn open(p: *Pardes) ?u8 {
const k: u8 = for (0..max) |i| {
if (!isOpen(p, @intCast(i))) break @intCast(i);
} else return null;
- // Each live view parks too: its slot is made with the first other.
- for ([_]u8{ p.view, k }) |i| if (p.parked[i] == null) {
- const slot = p.gpa.create(Parked) catch return null;
- slot.* = .{ .view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h } };
- p.parked[i] = slot;
- };
- const slot = p.parked[k].?;
- slot.* = .{ .view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h } };
+ const live = p.view();
+ p.views[k] = .{ .screen_w = live.screen_w, .screen_h = live.screen_h };
+ const v = &p.views[k].?;
inline for (sized ++ laid_out ++ .{"frontend"}) |name|
- @field(slot.view, name) = @field(p, name);
+ @field(v, name) = @field(live, name);
// A query's mark on the jumps is the view's that asked it.
- slot.view.jumps.force = false;
- slot.view.col_tags = @splat(.{ .what = .column, .gpa = p.gpa });
- for (p.panes, 0..) |s, id| {
+ v.jumps.force = false;
+ v.col_tags = @splat(.{ .what = .column, .gpa = p.gpa });
+ for (p.panes) |s| {
const pane = s orelse continue;
- slot.serials[id] = pane.serial;
pane.pv[k] = fresh(pane);
- pane.pv_known |= @as(u8, 1) << @intCast(k);
+ pane.pv_known |= bit(k);
}
- p.views_open |= @as(u8, 1) << @intCast(k);
+ p.views_open |= bit(k);
return k;
}
@@ -464,51 +403,56 @@ pub fn closeKeeping(p: *Pardes, k: u8) void {
to(p, k);
// Never into one kept for a rejoin (`away`): that one is its client's.
const other = looked(p, k).?;
- const slot = p.parked[other].?;
+ const v = &p.views[other].?;
// Its size too: the terminals it sized keep theirs, no shell redrawn for
// a size it is given back at the rejoin.
- const force = slot.view.jumps.force;
- inline for (sized ++ laid_out) |name| @field(slot.view, name) = @field(p, name);
- slot.view.jumps.force = force;
- for (p.panes, 0..) |s, id| {
- const pane = s orelse {
- slot.serials[id] = 0;
- continue;
- };
- if (pane.pv_known & (@as(u8, 1) << @intCast(other)) != 0 and pane.pv[other].body.sels.len > 0) p.gpa.free(pane.pv[other].body.sels);
- slot.serials[id] = pane.serial;
+ const force = v.jumps.force;
+ inline for (sized ++ laid_out) |name| @field(v, name) = @field(p.views[k].?, name);
+ v.jumps.force = force;
+ for (p.panes) |s| if (s) |pane| {
+ if (pane.pv_known & bit(other) != 0 and pane.pv[other].body.sels.len > 0) p.gpa.free(pane.pv[other].body.sels);
pane.pv[other] = fresh(pane);
- pane.pv_known |= @as(u8, 1) << @intCast(other);
- }
+ pane.pv_known |= bit(other);
+ };
close(p, k);
}
+/// What view `v`'s own share holds, freed.
+fn freeView(p: *Pardes, v: *View) void {
+ for (&v.col_tags) |*t| t.deinit(p.gpa);
+ if (v.chord_arg) |a| p.gpa.free(a);
+}
+
+/// View `k` closed outright (not live): its share and its panes' shares freed.
+fn dropView(p: *Pardes, k: u8) void {
+ if (p.views[k]) |*v| freeView(p, v);
+ p.views[k] = null;
+ for (p.panes) |s| if (s) |pane| {
+ if (pane.pv_known & bit(k) != 0) {
+ const sels = pane.pv[k].body.sels;
+ if (sels.len > 0) p.gpa.free(sels);
+ }
+ pane.pv[k].body.sels = &.{};
+ pane.pv_known &= ~bit(k);
+ // A name it was drafting goes with it.
+ if (pane.prompt == .name and pane.prompt_view == k) pane.closePrompt();
+ };
+ p.views_open &= ~bit(k);
+ p.views_away &= ~bit(k);
+}
+
/// View `k` gone, and all it held; the live one moves to another first.
/// The last view someone looks at stays: a session without a client keeps
/// its own. One kept for a rejoin (`away`) goes whenever it is closed.
pub fn close(p: *Pardes, k: u8) void {
if (!isOpen(p, k) or @popCount(p.views_open) == 1 or (!isAway(p, k) and count(p) == 1)) return;
- if (k == p.view) {
+ if (k == p.live) {
const other: u8 = looked(p, k) orelse for (0..max) |i| {
if (i != k and isOpen(p, @intCast(i))) break @intCast(i);
} else unreachable;
- park(p);
- unpark(p, other);
- emptied(p, other);
+ to(p, other);
}
- const v = &p.parked[k].?.view;
- for (&v.col_tags) |*t| t.deinit(p.gpa);
- if (v.chord_arg) |a| p.gpa.free(a);
- for (p.panes) |s| if (s) |pane| {
- const sels = pane.pv[k].body.sels;
- if (sels.len > 0) p.gpa.free(sels);
- pane.pv[k].body.sels = &.{};
- pane.pv_known &= ~(@as(u8, 1) << @intCast(k));
- // A name it was drafting goes with it.
- if (pane.prompt == .name and pane.prompt_view == k) pane.closePrompt();
- };
- p.views_open &= ~(@as(u8, 1) << @intCast(k));
- p.views_away &= ~(@as(u8, 1) << @intCast(k));
+ dropView(p, k);
}
/// View `k`'s client gone a moment, to join again for it (an Upgrade's
@@ -519,130 +463,71 @@ pub fn close(p: *Pardes, k: u8) void {
/// goes into another someone looks at, or into a copy of this one of its own.
pub fn away(p: *Pardes, k: u8) void {
if (!isOpen(p, k)) return;
- if (k == p.view) if (looked(p, k) orelse open(p)) |other| to(p, other);
+ if (k == p.live) if (looked(p, k) orelse open(p)) |other| to(p, other);
p.views_away |= bit(k);
}
-/// The session's end: what each view not live holds.
+/// The session's end: what each view holds.
pub fn deinit(p: *Pardes) void {
- for (0..max) |i| {
- const k: u8 = @intCast(i);
- const slot = p.parked[k] orelse continue;
- if (k != p.view and isOpen(p, k)) {
- const v = &slot.view;
- for (&v.col_tags) |*t| t.deinit(p.gpa);
- if (v.chord_arg) |a| p.gpa.free(a);
- }
- p.gpa.destroy(slot);
- }
+ for (&p.views) |*slot| if (slot.*) |*v| freeView(p, v);
}
+pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void };
+
/// Each view but the live one drawn and presented, the live one put back
-/// after exactly as it was: no digested field moves, so a replica that
-/// draws nothing (and skips this) stays the same. A view drawn keeps
-/// nothing of its drawing: whatever its unpark brought inside a changed
-/// text is not kept, and is done again when it is next live. Before the live one's frame: the surface after the pump is its.
+/// after exactly as it was (`drawOne`). Before the live one's frame: the
+/// surface after the pump is its.
pub fn drawOthers(p: *Pardes, h: pardes.Host) !void {
- const live = p.view;
- const v = h.vtable;
- park(p);
- defer {
- copy(&fields, p, &p.parked[live].?.view);
- emptied(p, live);
- p.view = live;
- for (p.panes) |s| if (s) |pane| {
- const pv = &pane.pv[live];
- copy(&pane_fields, pane, pv);
- copy(&body_fields, &pane.body, &pv.body);
- if (!pane.isTerminal()) {
- pane.cols = pv.cols;
- pane.rows = pv.rows;
- }
- if (pane.file) |*f| f.scroll = pv.scroll;
- };
- }
for (0..max) |i| {
const k: u8 = @intCast(i);
- if (k == live or !isOpen(p, k) or (p.undrawn | p.views_away) & bit(k) != 0) continue;
+ if (k == p.live or !isOpen(p, k) or (p.undrawn | p.views_away) & bit(k) != 0) continue;
// No post_present: what a shell acknowledges there moves the
// session's pointer and hover, which are the live view's to move;
// a view's panels are acknowledged when it is live and drawn.
- try drawParked(p, k, .{ .ctx = h.ctx, .f = v.present });
+ try drawOne(p, k, .{ .ctx = h.ctx, .f = h.vtable.present });
}
}
-pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void };
-
-/// Parked view `k` unparked, drawn and presented. `unpark` hands each
-/// slot's selections to its body; drawn, the view is out again, and they
-/// are the slot's again (else a frame drawn would take them from a view,
-/// and a replica that draws nothing would keep them).
-fn drawParked(p: *Pardes, k: u8, present: Present) !void {
- try unparked(p, k, present, drawLive);
-}
-
fn drawLive(present: Present, p: *Pardes) anyerror!void {
_ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept });
const surface = try p.render(p.frame_arena.allocator());
if (present.f) |f| f(present.ctx, surface);
}
-/// `f(ctx, p)` with parked view `k` unparked, its slot's selections its own
-/// again after (`drawParked`).
-fn unparked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) !void {
- var sels: [MAX_PANES]struct { []Text.SelRange, u16 } = undefined;
- for (p.panes, 0..) |s, id| if (s) |pane| {
- sels[id] = .{ pane.pv[k].body.sels, pane.pv[k].body.nsel };
- };
- unpark(p, k);
- defer for (p.panes, 0..) |s, id| if (s) |pane| {
- pane.pv[k].body.sels = sels[id][0];
- pane.pv[k].body.nsel = sels[id][1];
- };
- try f(ctx, p);
-}
-
-/// View `k` drawn and presented outside any step, by a replica client
-/// (src/replica.zig) whose own it is: as `drawOthers` draws one, the live
-/// view put back after exactly as it was, so the replica's digest is the
-/// authority's still. No post_present, as there.
+/// View `k` drawn and presented outside any step (the pump's other views,
+/// a replica client's own): the live view put back after exactly as it
+/// was, so the digest is the same. No post_present.
pub fn drawOne(p: *Pardes, k: u8, present: Present) !void {
- if (k == p.view or !isOpen(p, k)) return drawLive(present, p);
- const Draw = struct {
- fn draw(pr: Present, q: *Pardes, kk: u8) anyerror!void {
- try drawParked(q, kk, pr);
- }
- };
- try withParked(p, k, present, Draw.draw);
+ try within(p, k, present, drawLive);
}
/// `f(ctx, p)` with view `k` live, outside any step, and the live view put
/// back after exactly as it was, as `drawOne` draws one: what a replica
/// client's frontend reads of its own view (its pointer's cells, its size)
-/// while another client's input was the session's last. `f` reads only.
+/// while another client's input was the session's last. What going into
+/// `k` and drawing it made of it (its layout worked out, a cursor brought
+/// inside a changed text) is not kept: it is done again, in every replica
+/// alike, when `k` is next live by an input.
pub fn within(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) !void {
- if (k == p.view or !isOpen(p, k)) return f(ctx, p);
- const Read = struct {
- fn read(x: @TypeOf(ctx), q: *Pardes, kk: u8) anyerror!void {
- try unparked(q, kk, x, f);
- }
+ if (k == p.live or !isOpen(p, k)) return f(ctx, p);
+ const live = p.live;
+ const kept = p.views[k];
+ var sels: [MAX_PANES]struct { []Text.SelRange, u16 } = undefined;
+ for (p.panes, 0..) |s, id| if (s) |pane| {
+ sels[id] = .{ pane.pv[k].body.sels, pane.pv[k].body.nsel };
};
- try withParked(p, k, ctx, Read.read);
-}
-
-/// The live view parked, `f(ctx, p, k)`, and the live view put back after
-/// exactly as it was.
-fn withParked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes, u8) anyerror!void) !void {
- const live = p.view;
park(p);
+ unpark(p, k);
defer {
- copy(&fields, p, &p.parked[live].?.view);
- // Its slot and its panes' shares, stale while it is live, keep no
- // pointer to what they handed back, as `unpark` leaves them: a
- // replica's rollback copy walks them (`emptied`).
- emptied(p, live);
- p.view = live;
- for (p.panes) |s| if (s) |pane| {
+ p.views[k] = kept;
+ p.live = live;
+ for (p.panes, 0..) |s, id| if (s) |pane| {
+ // `k`'s slot its selections again (else a frame drawn would
+ // take them from a view, and a replica that draws nothing
+ // would keep them); the live view's fields its own again, and
+ // its slot, stale while it is live, owning nothing.
+ pane.pv[k].body.sels = sels[id][0];
+ pane.pv[k].body.nsel = sels[id][1];
const pv = &pane.pv[live];
copy(&pane_fields, pane, pv);
copy(&body_fields, &pane.body, &pv.body);
@@ -655,7 +540,7 @@ fn withParked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa
pv.body.nsel = 0;
};
}
- try f(ctx, p, k);
+ try f(ctx, p);
}
// ---- tests ----
@@ -723,30 +608,30 @@ test "each view has its own layout and focus over the same panes" {
defer p.deinit();
_ = try p.setTestFile("one\ntwo\n");
const k = p.openView().?;
- const ncol = p.ncol;
+ const ncol = p.view().ncol;
p.toView(k);
p.update(.{ .command = "Newcol" });
p.update(.{ .command = "New" });
- const made = p.active;
+ const made = p.view().active;
try testing.expect(made != 0);
- try testing.expectEqual(ncol + 1, p.ncol);
+ try testing.expectEqual(ncol + 1, p.view().ncol);
p.toView(0);
- try testing.expectEqual(ncol, p.ncol);
- try testing.expectEqual(@as(usize, 0), p.active);
+ try testing.expectEqual(ncol, p.view().ncol);
+ try testing.expectEqual(@as(usize, 0), p.view().active);
try testing.expect(layout.findPane(p, made) == null);
- try testing.expectEqual(pardes.Rect{}, p.rects[made]);
+ try testing.expectEqual(pardes.Rect{}, p.view().rects[made]);
// The pane is the session's: focused here, this view shows it too.
- p.active = made;
+ p.view().active = made;
p.sync();
try testing.expect(layout.findPane(p, made) != null);
- try testing.expect(p.rects[made].h > 0);
+ try testing.expect(p.view().rects[made].h > 0);
// Closed here, it leaves the other view's layout, and its keyboard.
try p.removePane(made, null);
p.sync();
p.toView(k);
try testing.expect(layout.findPane(p, made) == null);
- try testing.expect(p.panes[p.active] != null);
- try testing.expect(layout.findPane(p, p.active) != null);
+ try testing.expect(p.panes[p.view().active] != null);
+ try testing.expect(layout.findPane(p, p.view().active) != null);
}
test "registers are the session's: yanked in one view, put in another" {
@@ -766,14 +651,14 @@ test "a terminal shown at two sizes takes the size of the view that typed into i
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
- const term = p.panes[p.active].?;
+ const term = p.panes[p.view().active].?;
try testing.expect(term.isTerminal());
const small = .{ term.cols, term.rows };
const k = p.openView().?;
p.toView(k);
p.update(.{ .resize = .{ .cols = 120, .rows = 40 } });
// Shown bigger here, it keeps the size of the view that typed last.
- try testing.expect(p.rects[p.active].w > 80);
+ try testing.expect(p.view().rects[p.view().active].w > 80);
try testing.expectEqual(small, .{ term.cols, term.rows });
p.update(.{ .key = .{ .cp = Key.right } });
try testing.expect(term.cols > small[0] and term.rows > small[1]);
@@ -786,7 +671,7 @@ test "a terminal shown at two sizes takes the size of the view that typed into i
// That view gone, the one left sizes it.
p.toView(k);
p.closeView(0);
- try testing.expectEqual(k, p.view);
+ try testing.expectEqual(k, p.live);
try testing.expectEqual(big, .{ term.cols, term.rows });
}
@@ -808,17 +693,17 @@ test "a view closing leaves the others as they were" {
cursorTo(p, pane, 70);
p.toView(0);
cursorTo(p, pane, 10);
- const ncol = p.ncol;
+ const ncol = p.view().ncol;
// The live one closing: the session goes into another.
p.toView(b);
p.closeView(b);
- try testing.expect(p.view != b);
+ try testing.expect(p.live != b);
try testing.expectEqual(@as(usize, 2), count(p));
p.toView(a);
try testing.expectEqual(@as(i32, 70), pane.body.cur_row);
p.closeView(0);
- try testing.expectEqual(a, p.view);
- try testing.expectEqual(ncol, p.ncol);
+ try testing.expectEqual(a, p.live);
+ try testing.expectEqual(ncol, p.view().ncol);
// The last stays.
p.closeView(a);
try testing.expectEqual(@as(usize, 1), count(p));
@@ -837,23 +722,23 @@ test "the last client's view going leaves the session its layout, which a rejoin
p.update(.{ .resize = .{ .cols = 120, .rows = 40 } });
p.update(.{ .command = "Newcol" });
p.update(.{ .command = "New" });
- const made = p.active;
- const ncol = p.ncol;
- p.active = 0;
+ const made = p.view().active;
+ const ncol = p.view().ncol;
+ p.view().active = 0;
p.sync();
cursorTo(p, pane, 60);
p.leaveView(k);
try testing.expectEqual(@as(usize, 1), count(p));
- try testing.expectEqual(ncol, p.ncol);
+ try testing.expectEqual(ncol, p.view().ncol);
try testing.expect(layout.findPane(p, made) != null);
try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
- try testing.expectEqual(@as(u16, 120), p.screen_w);
+ try testing.expectEqual(@as(u16, 120), p.view().screen_w);
// Its client back (a view copied from the live one): all of it again.
const again = p.openView().?;
p.toView(again);
- try testing.expectEqual(ncol, p.ncol);
+ try testing.expectEqual(ncol, p.view().ncol);
try testing.expect(layout.findPane(p, made) != null);
- try testing.expectEqual(@as(usize, 0), p.active);
+ try testing.expectEqual(@as(usize, 0), p.view().active);
try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
}
@@ -869,13 +754,13 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien
for (ks, &made) |k, *m| {
p.toView(k);
p.update(.{ .command = "New" });
- m.* = p.active;
+ m.* = p.view().active;
}
// Both let go to upgrade, the live view one of theirs: theirs are kept,
// and the session's own is live.
for (ks) |k| p.awayView(k);
try testing.expectEqual(@as(usize, 1), count(p));
- try testing.expect(!isAway(p, p.view));
+ try testing.expect(!isAway(p, p.live));
// The new build loads the dump; each client is back in its own view.
const bytes = try pardes.dump.dumpBytes(p);
defer gpa.free(bytes);
@@ -885,7 +770,7 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien
try testing.expect(isAway(q, k));
try testing.expect(q.rejoinView(k));
q.toView(k);
- try testing.expectEqual(m, q.active);
+ try testing.expectEqual(m, q.view().active);
try testing.expect(layout.findPane(q, m) != null);
try testing.expect(layout.findPane(q, made[1 - i]) == null);
}
@@ -912,7 +797,7 @@ test "drawing the other views leaves the live one as it was, to the digest" {
cursorTo(p, pane, 95);
const before = pardes.walk.digest(Pardes, p);
try drawOthers(p, .{});
- try testing.expectEqual(@as(u8, 0), p.view);
+ try testing.expectEqual(@as(u8, 0), p.live);
try testing.expectEqual(before, pardes.walk.digest(Pardes, p));
p.toView(k);
try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
@@ -961,7 +846,7 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 20 });
defer p.deinit();
- const id = p.active;
+ const id = p.view().active;
const term = p.panes[id].?;
const k = p.openView().?;
p.toView(k);
@@ -983,7 +868,7 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" {
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const s = try p.render(arena.allocator());
- const r = p.rects[id];
+ const r = p.view().rects[id];
// The cursor's row, the last, is on screen in the short view, inside
// the pane, and so is the line it is on.
const cursor = s.cursor.?;
@@ -1014,7 +899,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o
p.toView(0);
p.toView(k);
cursorTo(p, pane, 30);
- const ncol = p.ncol;
+ const ncol = p.view().ncol;
const bytes = try pardes.dump.dumpBytes(p);
defer gpa.free(bytes);
const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null);
@@ -1026,16 +911,16 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o
const lp = loaded.panes[id].?;
loaded.toView(0);
try testing.expectEqual(@as(i32, 119), lp.body.cur_row);
- try testing.expectEqual(ncol - 1, loaded.ncol);
+ try testing.expectEqual(ncol - 1, loaded.view().ncol);
loaded.toView(k);
try testing.expectEqual(@as(i32, 30), lp.body.cur_row);
- try testing.expectEqual(ncol, loaded.ncol);
+ try testing.expectEqual(ncol, loaded.view().ncol);
// For one client: the view live when dumped, as view 0.
const one = try pardes.dump.initFromDump(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes);
defer one.deinit();
try testing.expectEqual(@as(usize, 1), count(one));
- try testing.expectEqual(@as(u8, 0), one.view);
- try testing.expectEqual(ncol, one.ncol);
+ try testing.expectEqual(@as(u8, 0), one.live);
+ try testing.expectEqual(ncol, one.view().ncol);
try testing.expectEqual(@as(i32, 30), one.panes[id].?.body.cur_row);
try testing.expectEqual(@as(?u8, 1), one.openView());
}
diff --git a/test/column_drag.zig b/test/column_drag.zig
index 013d536f..e64656e3 100644
--- a/test/column_drag.zig
+++ b/test/column_drag.zig
@@ -30,13 +30,14 @@ const Snapshot = struct {
};
fn expectOrder(p: *Pardes, before: []const Snapshot, order: []const usize) !void {
- try std.testing.expectEqual(order.len, p.ncol);
+ const v = p.view();
+ try std.testing.expectEqual(order.len, v.ncol);
for (order, 0..) |original, column| {
const saved = before[original];
- try std.testing.expectEqual(saved.weight, p.cols[column].weight);
- try std.testing.expectEqual(saved.serial, p.cols[column].serial);
- try std.testing.expectEqual(saved.count, p.cols[column].n);
- try std.testing.expectEqualSlices(usize, saved.panes[0..saved.count], p.cols[column].panes[0..p.cols[column].n]);
+ try std.testing.expectEqual(saved.weight, v.cols[column].weight);
+ try std.testing.expectEqual(saved.serial, v.cols[column].serial);
+ try std.testing.expectEqual(saved.count, v.cols[column].n);
+ try std.testing.expectEqualSlices(usize, saved.panes[0..saved.count], v.cols[column].panes[0..p.view().cols[column].n]);
try std.testing.expectEqualStrings(saved.tag, pardes.tagline.columnTag(p, column));
}
}
@@ -45,19 +46,19 @@ test "column grip drag moves only its interval and keeps tag caret with the colu
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 180, .rows = 30 });
defer p.deinit();
_ = try p.setTestFile("body\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
for (0..3) |_| {
- try std.testing.expect(p.executeBuiltinLine(p.active, "New"));
- const id = p.active;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
+ const id = p.view().active;
try std.testing.expect(layout.splitColumn(p, id, id, false));
}
- p.active = p.cols[1].panes[0];
- try std.testing.expect(p.executeBuiltinLine(p.active, "New"));
- const active = p.active;
- try std.testing.expectEqual(@as(usize, 2), p.cols[1].n);
+ p.view().active = p.view().cols[1].panes[0];
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
+ const active = p.view().active;
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n);
for ([_]u64{ 2, 3, 5, 7 }, 0..) |weight, column| {
- p.cols[column].weight = weight;
- p.col_tags[column].own = try p.gpa.dupe(u8, ([_][]const u8{ "zero column header", "one column header", "two column header", "three column header" })[column]);
+ p.view().cols[column].weight = weight;
+ p.view().col_tags[column].own = try p.gpa.dupe(u8, ([_][]const u8{ "zero column header", "one column header", "two column header", "three column header" })[column]);
}
p.update(.tick);
var frame = std.heap.ArenaAllocator.init(p.gpa);
@@ -65,8 +66,8 @@ test "column grip drag moves only its interval and keeps tag caret with the colu
_ = try p.render(frame.allocator());
var before: [4]Snapshot = undefined;
for (&before, 0..) |*saved, column| {
- saved.* = .{ .weight = p.cols[column].weight, .serial = p.cols[column].serial, .count = p.cols[column].n, .tag = pardes.tagline.columnTag(p, column) };
- @memcpy(saved.panes[0..saved.count], p.cols[column].panes[0..saved.count]);
+ saved.* = .{ .weight = p.view().cols[column].weight, .serial = p.view().cols[column].serial, .count = p.view().cols[column].n, .tag = pardes.tagline.columnTag(p, column) };
+ @memcpy(saved.panes[0..saved.count], p.view().cols[column].panes[0..saved.count]);
}
const layer = try tagLayer(p, 1);
const stale = headerMouse(layer, 4, .press);
@@ -75,25 +76,25 @@ test "column grip drag moves only its interval and keeps tag caret with the colu
try std.testing.expectEqual(@as(?usize, 1), p.headerColumn());
const caret = pardes.tagline.focusedHeader(p).?.cur_col;
const anchor = pardes.tagline.focusedHeader(p).?.vsel;
- const scroll = p.header_scroll;
- const target = p.col_x[3] + p.col_w[3] - 2;
- const last_rect = p.rects[p.cols[3].panes[0]];
+ const scroll = p.view().header_scroll;
+ const target = p.view().col_x[3] + p.view().col_w[3] - 2;
+ const last_rect = p.view().rects[p.view().cols[3].panes[0]];
const last_columns = (try tagLayer(p, 3)).cols;
- mouse(p, .press, p.col_x[1]);
- try std.testing.expect(p.drag == .column_move);
+ mouse(p, .press, p.view().col_x[1]);
+ try std.testing.expect(p.view().drag == .column_move);
mouse(p, .drag, target);
_ = try p.render(frame.allocator());
- try std.testing.expectEqual(p.col_w[3] - pardes.TAG_TEXT_INSET - 1, (try tagLayer(p, 3)).viewport.w);
- try std.testing.expectEqual(last_rect, p.rects[p.cols[3].panes[0]]);
+ try std.testing.expectEqual(p.view().col_w[3] - pardes.TAG_TEXT_INSET - 1, (try tagLayer(p, 3)).viewport.w);
+ try std.testing.expectEqual(last_rect, p.view().rects[p.view().cols[3].panes[0]]);
try std.testing.expectEqual(last_columns, (try tagLayer(p, 3)).cols);
try expectOrder(p, &before, &.{ 0, 1, 2, 3 });
mouse(p, .release, target);
try expectOrder(p, &before, &.{ 0, 2, 3, 1 });
- try std.testing.expectEqual(active, p.active);
+ try std.testing.expectEqual(active, p.view().active);
try std.testing.expectEqual(@as(?usize, 3), p.headerColumn());
try std.testing.expectEqual(caret, pardes.tagline.focusedHeader(p).?.cur_col);
try std.testing.expectEqual(anchor, pardes.tagline.focusedHeader(p).?.vsel);
- try std.testing.expectEqual(scroll, p.header_scroll);
+ try std.testing.expectEqual(scroll, p.view().header_scroll);
// The old tag envelope must not edit the new occupant of its old index,
// including the interval before hosts request another rendered frame.
p.update(.{ .mouse = stale });
@@ -101,43 +102,43 @@ test "column grip drag moves only its interval and keeps tag caret with the colu
try std.testing.expectEqual(caret, pardes.tagline.focusedHeader(p).?.cur_col);
_ = try p.render(frame.allocator());
try std.testing.expectEqual(before[1].serial, (try tagLayer(p, 3)).serial);
- try std.testing.expectEqual(p.col_w[3] - pardes.TAG_TEXT_INSET, (try tagLayer(p, 3)).viewport.w);
- mouse(p, .press, p.col_x[3]);
- const back = p.col_x[1] + config.GUTTER;
+ try std.testing.expectEqual(p.view().col_w[3] - pardes.TAG_TEXT_INSET, (try tagLayer(p, 3)).viewport.w);
+ mouse(p, .press, p.view().col_x[3]);
+ const back = p.view().col_x[1] + config.GUTTER;
mouse(p, .drag, back);
mouse(p, .release, back);
try expectOrder(p, &before, &.{ 0, 1, 2, 3 });
try std.testing.expectEqual(@as(?usize, 1), p.headerColumn());
try std.testing.expectEqual(caret, pardes.tagline.focusedHeader(p).?.cur_col);
- try std.testing.expectEqual(active, p.active);
+ try std.testing.expectEqual(active, p.view().active);
// A structural change between press and release must not retarget the
// in-flight drag to whichever column now occupies the original index.
- mouse(p, .press, p.col_x[1]);
+ mouse(p, .press, p.view().col_x[1]);
layout.reorderColumn(p, 1, 2);
- mouse(p, .release, p.col_x[0] + config.GUTTER);
+ mouse(p, .release, p.view().col_x[0] + config.GUTTER);
try expectOrder(p, &before, &.{ 1, 0, 2, 3 });
try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
}
test "column grip is separate from compact text and the resize seam" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 });
defer p.deinit();
_ = try p.setTestFile("body\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- try std.testing.expect(layout.splitColumn(p, p.active, p.active, false));
+ try std.testing.expect(layout.splitColumn(p, p.view().active, p.view().active, false));
p.update(.tick);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
const layer = try tagLayer(p, 1);
- try std.testing.expectEqual(p.col_x[1] + pardes.TAG_TEXT_INSET, layer.viewport.x);
+ try std.testing.expectEqual(p.view().col_x[1] + pardes.TAG_TEXT_INSET, layer.viewport.x);
const surface = &p.surface;
- for (0..p.ncol) |column| {
- const pane_id = p.cols[column].panes[0];
- const rect = p.rects[pane_id];
- try std.testing.expectEqual(p.col_x[column], rect.x);
+ for (0..p.view().ncol) |column| {
+ const pane_id = p.view().cols[column].panes[0];
+ const rect = p.view().rects[pane_id];
+ try std.testing.expectEqual(p.view().col_x[column], rect.x);
try std.testing.expectEqual(rect.x + pardes.TAG_TEXT_INSET, (try tagLayer(p, column)).viewport.x);
for (p.surface.tagLayers()) |pane_layer| {
if (pane_layer.rows > 0 and pane_layer.kind == .pane and pane_layer.id == pane_id)
@@ -152,17 +153,17 @@ test "column grip is separate from compact text and the resize seam" {
try std.testing.expectEqual(pardes.FontRole.tagline, surface.at(rect.x + pardes.TAG_TEXT_INSET, pane_tag_y).style.font_role);
}
p.update(.{ .mouse = headerMouse(layer, 0, .press) });
- try std.testing.expect(p.drag != .column_move);
- try std.testing.expect(p.header_drag);
+ try std.testing.expect(p.view().drag != .column_move);
+ try std.testing.expect(p.view().header_drag);
p.update(.{ .mouse = headerMouse(layer, 0, .release) });
try std.testing.expectEqual(@as(i32, 0), pardes.tagline.focusedHeader(p).?.cur_col);
- mouse(p, .press, p.col_x[1] + config.GUTTER - 1);
- try std.testing.expect(p.drag == .column_move);
- mouse(p, .release, p.col_x[1] + config.GUTTER - 1);
- const seam = p.col_x[0] + p.col_w[0] - 1;
- const body_row = p.rects[p.cols[0].panes[0]].y + pardes.BOX_H + 1;
+ mouse(p, .press, p.view().col_x[1] + config.GUTTER - 1);
+ try std.testing.expect(p.view().drag == .column_move);
+ mouse(p, .release, p.view().col_x[1] + config.GUTTER - 1);
+ const seam = p.view().col_x[0] + p.view().col_w[0] - 1;
+ const body_row = p.view().rects[p.view().cols[0].panes[0]].y + pardes.BOX_H + 1;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = seam, .row = body_row } });
- try std.testing.expect(p.drag == .border_v);
+ try std.testing.expect(p.view().drag == .border_v);
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = seam, .row = body_row } });
}
@@ -170,14 +171,14 @@ test "column grips stay blank, and muted across focus and hover until grabbed" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
defer p.deinit();
_ = try p.setTestFile("left\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- try std.testing.expect(layout.splitColumn(p, p.active, p.active, false));
+ try std.testing.expect(layout.splitColumn(p, p.view().active, p.view().active, false));
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
- for (0..p.ncol) |active_column| {
- p.active = p.cols[active_column].panes[0];
- const x = p.col_x[active_column];
+ for (0..p.view().ncol) |active_column| {
+ p.view().active = p.view().cols[active_column].panes[0];
+ const x = p.view().col_x[active_column];
p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = x, .row = pardes.TOPBAR_H } });
for ([_]bool{ false, true }) |dragging| {
if (dragging) mouse(p, .press, x);
@@ -185,14 +186,14 @@ test "column grips stay blank, and muted across focus and hover until grabbed" {
const surface = try p.render(frame.allocator());
const muted: pardes.Color = .{ .rgb = p.chromeTheme().column_box_dim };
const lit: pardes.Color = .{ .rgb = p.chromeTheme().column_box };
- for (0..p.ncol) |column| {
+ for (0..p.view().ncol) |column| {
for (0..config.GUTTER) |offset| {
- const cell = surface.at(p.col_x[column] + @as(u16, @intCast(offset)), pardes.TOPBAR_H);
+ const cell = surface.at(p.view().col_x[column] + @as(u16, @intCast(offset)), pardes.TOPBAR_H);
try std.testing.expectEqualStrings(" ", cell.grapheme());
try std.testing.expectEqual(if (dragging and column == active_column) lit else muted, cell.style.bg);
try std.testing.expectEqual(pardes.FontRole.tagline, cell.style.font_role);
}
- try std.testing.expectEqual(p.col_x[column] + pardes.TAG_TEXT_INSET, (try tagLayer(p, column)).viewport.x);
+ try std.testing.expectEqual(p.view().col_x[column] + pardes.TAG_TEXT_INSET, (try tagLayer(p, column)).viewport.x);
}
if (dragging) mouse(p, .release, x);
}
@@ -204,21 +205,21 @@ test "column grip dropped in its own place moves the column's left edge" {
defer p.deinit();
_ = try p.setTestFile("body\n");
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- try std.testing.expect(layout.splitColumn(p, p.active, p.active, false));
+ try std.testing.expect(layout.splitColumn(p, p.view().active, p.view().active, false));
p.update(.tick);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const serials = .{ p.cols[0].serial, p.cols[1].serial };
- const edge = p.col_x[1];
- const total = p.col_w[0] + p.col_w[1];
+ const serials = .{ p.view().cols[0].serial, p.view().cols[1].serial };
+ const edge = p.view().col_x[1];
+ const total = p.view().col_w[0] + p.view().col_w[1];
// A click in place, from either grip cell, changes nothing.
for (0..config.GUTTER) |offset| {
const x = edge + @as(u16, @intCast(offset));
mouse(p, .press, x);
mouse(p, .release, x);
_ = try p.render(frame.allocator());
- try std.testing.expectEqual(edge, p.col_x[1]);
+ try std.testing.expectEqual(edge, p.view().col_x[1]);
}
// Grabbed by its second cell and dropped 7 cells left: the edge follows.
mouse(p, .press, edge + 1);
@@ -226,15 +227,15 @@ test "column grip dropped in its own place moves the column's left edge" {
_ = try p.render(frame.allocator());
mouse(p, .release, edge + 1 - 7);
_ = try p.render(frame.allocator());
- try std.testing.expectEqual(edge - 7, p.col_x[1]);
- try std.testing.expectEqual(total, p.col_w[0] + p.col_w[1]);
- try std.testing.expectEqual(serials[0], p.cols[0].serial);
- try std.testing.expectEqual(serials[1], p.cols[1].serial);
+ try std.testing.expectEqual(edge - 7, p.view().col_x[1]);
+ try std.testing.expectEqual(total, p.view().col_w[0] + p.view().col_w[1]);
+ try std.testing.expectEqual(serials[0], p.view().cols[0].serial);
+ try std.testing.expectEqual(serials[1], p.view().cols[1].serial);
// Past the neighbour's middle it is still a reorder, not a resize.
- mouse(p, .press, p.col_x[1]);
- mouse(p, .release, p.col_x[0] + 1);
- try std.testing.expectEqual(serials[1], p.cols[0].serial);
- try std.testing.expectEqual(serials[0], p.cols[1].serial);
+ mouse(p, .press, p.view().col_x[1]);
+ mouse(p, .release, p.view().col_x[0] + 1);
+ try std.testing.expectEqual(serials[1], p.view().cols[0].serial);
+ try std.testing.expectEqual(serials[0], p.view().cols[1].serial);
}
/// The column of the drag preview's rail, checked to run the full height
@@ -267,19 +268,19 @@ test "column grip drag previews where the column lands, in the seam beside its r
defer p.deinit();
_ = try p.setTestFile("body\n");
for (0..2) |_| {
- try std.testing.expect(p.executeBuiltinLine(p.active, "New"));
- try std.testing.expect(layout.splitColumn(p, p.active, p.active, false));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "New"));
+ try std.testing.expect(layout.splitColumn(p, p.view().active, p.view().active, false));
}
- try std.testing.expectEqual(@as(usize, 3), p.ncol);
+ try std.testing.expectEqual(@as(usize, 3), p.view().ncol);
p.update(.tick);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const serials = .{ p.cols[0].serial, p.cols[1].serial, p.cols[2].serial };
+ const serials = .{ p.view().cols[0].serial, p.view().cols[1].serial, p.view().cols[2].serial };
// Held on its own grip it lands nowhere new: no rail.
- mouse(p, .press, p.col_x[1]);
- mouse(p, .drag, p.col_x[1] + 1);
+ mouse(p, .press, p.view().col_x[1]);
+ mouse(p, .drag, p.view().col_x[1] + 1);
try std.testing.expectEqual(@as(?u16, null), try previewRail(p, &frame));
// Over the first column's left half it goes first. The window edge has
// no seam, and the gutter there is the GUI's scroll rail, so the rail
@@ -288,33 +289,33 @@ test "column grip drag previews where the column lands, in the seam beside its r
try std.testing.expectEqual(@as(?u16, config.GUTTER - 1), try previewRail(p, &frame));
// The pointer is over the first column's "New", but a carried column
// aims at a place: no word lights under it.
- for (0..p.screen_w) |x| try std.testing.expect(!std.meta.eql(p.surface.at(@intCast(x), pardes.TOPBAR_H).style.bg, pardes.Color{ .rgb = p.theme().sel_bg }));
+ for (0..p.view().screen_w) |x| try std.testing.expect(!std.meta.eql(p.surface.at(@intCast(x), pardes.TOPBAR_H).style.bg, pardes.Color{ .rgb = p.theme().sel_bg }));
mouse(p, .release, 3);
- try std.testing.expectEqual(serials[1], p.cols[0].serial);
- try std.testing.expectEqual(serials[0], p.cols[1].serial);
+ try std.testing.expectEqual(serials[1], p.view().cols[0].serial);
+ try std.testing.expectEqual(serials[0], p.view().cols[1].serial);
// Past the middle column's middle it lands after it: the rail is in the
// seam cell left of the last column's rule, where a border drag's is.
- mouse(p, .press, p.col_x[0]);
- const past = p.col_x[1] + p.col_w[1] - 2;
+ mouse(p, .press, p.view().col_x[0]);
+ const past = p.view().col_x[1] + p.view().col_w[1] - 2;
mouse(p, .drag, past);
- try std.testing.expectEqual(@as(?u16, p.col_x[2] - 1), try previewRail(p, &frame));
+ try std.testing.expectEqual(@as(?u16, p.view().col_x[2] - 1), try previewRail(p, &frame));
// Past the last column's middle: the window's last cell.
- mouse(p, .drag, p.col_x[2] + p.col_w[2] - 1);
- try std.testing.expectEqual(@as(?u16, p.screen_w - 1), try previewRail(p, &frame));
- mouse(p, .release, p.col_x[2] + p.col_w[2] - 1);
- try std.testing.expectEqual(serials[0], p.cols[0].serial);
- try std.testing.expectEqual(serials[2], p.cols[1].serial);
- try std.testing.expectEqual(serials[1], p.cols[2].serial);
+ mouse(p, .drag, p.view().col_x[2] + p.view().col_w[2] - 1);
+ try std.testing.expectEqual(@as(?u16, p.view().screen_w - 1), try previewRail(p, &frame));
+ mouse(p, .release, p.view().col_x[2] + p.view().col_w[2] - 1);
+ try std.testing.expectEqual(serials[0], p.view().cols[0].serial);
+ try std.testing.expectEqual(serials[2], p.view().cols[1].serial);
+ try std.testing.expectEqual(serials[1], p.view().cols[2].serial);
// Short of a neighbour's middle the left edge moves, and the preview
// is the seam that edge will have: exactly where the release puts it.
- const edge = p.col_x[2];
+ const edge = p.view().col_x[2];
mouse(p, .press, edge + 1);
mouse(p, .drag, edge + 1 - 6);
try std.testing.expectEqual(@as(?u16, edge - 6 - 1), try previewRail(p, &frame));
mouse(p, .release, edge + 1 - 6);
_ = try p.render(frame.allocator());
- try std.testing.expectEqual(edge - 6, p.col_x[2]);
+ try std.testing.expectEqual(edge - 6, p.view().col_x[2]);
try std.testing.expectEqual(@as(?u16, null), try previewRail(p, &frame));
}
diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig
index 939232fc..6ee50f77 100644
--- a/test/fs_namespace.zig
+++ b/test/fs_namespace.zig
@@ -89,8 +89,8 @@ test "transactional restore preserves host capabilities and advances pane identi
const pane = try p.setTestFile("before\n");
p.lsp_ask.seq = 41;
p.pipe.seq = 73;
- if (@hasField(pardes.CellPixels, "w")) p.cell_pixels = .{ .w = 9, .h = 18 };
- p.frontend.native_images = true;
+ if (@hasField(pardes.CellPixels, "w")) p.view().cell_pixels = .{ .w = 9, .h = 18 };
+ p.view().frontend.native_images = true;
p.fs.socket_path = "/tmp/session.sock";
p.fs.tcp_address = .{ .ip4 = .loopback(5640) };
try pardes.dump.dumpState(p);
@@ -98,13 +98,13 @@ test "transactional restore preserves host capabilities and advances pane identi
defer restored.deinit();
try std.testing.expectEqual(@as(u32, 41), restored.lsp_ask.seq);
try std.testing.expectEqual(@as(u32, 73), restored.pipe.seq);
- try std.testing.expectEqual(p.cell_pixels, restored.cell_pixels);
- try std.testing.expect(restored.frontend.native_images);
+ try std.testing.expectEqual(p.view().cell_pixels, restored.view().cell_pixels);
+ try std.testing.expect(restored.view().frontend.native_images);
// The dump's pane, its serial too; a new one is past the old session's.
try std.testing.expectEqual(pane.serial, restored.panes[0].?.serial);
try std.testing.expect(restored.next_serial >= p.next_serial);
- try std.testing.expectEqual(p.screen_w, restored.screen_w);
- try std.testing.expectEqual(p.screen_h, restored.screen_h);
+ try std.testing.expectEqual(p.view().screen_w, restored.view().screen_w);
+ try std.testing.expectEqual(p.view().screen_h, restored.view().screen_h);
try std.testing.expect(p.panes[0] == pane);
try std.testing.expectEqualStrings("before\n", pane.file.?.content);
try std.testing.expectError(error.BadDump, pardes.dump.restore(
@@ -263,7 +263,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation"
const name = try std.fmt.bufPrint(&path, "/virtual/pane/{d}/body", .{source.serial});
const slot = p.freeSlot().?;
const serial = p.next_serial;
- const columns = p.cols;
+ const columns = p.view().cols;
allocator.fail_index = allocator.alloc_index + failure;
const opened = pardes.panes.File.open(p, slot, name, 0) catch |err| {
try std.testing.expect(err == error.OutOfMemory or err == error.ReadFailed or err == error.WriteFailed);
@@ -271,7 +271,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation"
try std.testing.expect(!p.reserved_slots[slot]);
try std.testing.expectEqual(serial, p.next_serial);
try std.testing.expectEqual(slot, p.freeSlot().?);
- try std.testing.expectEqualDeep(columns, p.cols);
+ try std.testing.expectEqualDeep(columns, p.view().cols);
try std.testing.expectEqual(@as(usize, 0), p.effects_len);
try std.testing.expectEqualStrings("/source/directory", source.cwdSlice());
allocator.fail_index = std.math.maxInt(usize);
diff --git a/test/hxdiff.zig b/test/hxdiff.zig
index 1cb4d86f..03b135e2 100644
--- a/test/hxdiff.zig
+++ b/test/hxdiff.zig
@@ -407,7 +407,7 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result
// modal cursor tracking the shell cursor below the output)
core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } });
pump(core);
- if (core.panes[core.active]) |pane| {
+ if (core.panes[core.view().active]) |pane| {
pane.body.cur_row = 0;
pane.body.cur_col = 0;
pane.body.cur_pinned = true;
@@ -492,7 +492,7 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result
}
// one contract result line off the active pane's final state
- const pane = core.panes[core.active] orelse return error.NoActivePane;
+ const pane = core.panes[core.view().active] orelse return error.NoActivePane;
var text: []const u8 = undefined;
if (pane.file) |f| {
text = f.content;
diff --git a/test/kitty.zig b/test/kitty.zig
index f222f9cf..70e20139 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -71,7 +71,7 @@ const Rig = struct {
std.testing.log_level = .err;
// A core boots one shell or the classic three.
const p = try Pardes.init(gpa, .{ .cols = 120, .rows = 40, .shells = if (shells > 1) 3 else 1 });
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
p.update(.{ .resize = .{ .cols = 120, .rows = 40, .cell_pixels = .{ .w = 10, .h = 20 } } });
for (p.panes) |slot| if (slot) |each| {
each.body.mode = .tty;
@@ -141,7 +141,7 @@ const Rig = struct {
/// The top-left cell of pane `id`'s body, in screen cells.
fn origin(r: *Rig, id: u8) struct { x: u16, y: u16 } {
- const rect = r.p.rects[id];
+ const rect = r.p.view().rects[id];
return .{ .x = rect.x + config.GUTTER, .y = r.p.bodyTop(r.pane(id), rect) };
}
@@ -1200,7 +1200,7 @@ test "kitty: an image wider than its pane is cut at the pane's edge, never drawn
var r = try Rig.init(3);
defer r.deinit();
// The classic boot: two columns. Pane 0 is in the left one.
- const rect = r.p.rects[0];
+ const rect = r.p.view().rects[0];
const o = r.origin(0);
const right = rect.x + rect.w;
// 2x1 cells at its last-but-one column: one cell is the pane's.
@@ -1319,7 +1319,7 @@ test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is
// The glyph art a tty draws there is the tty's test (tui.zig).
var r = try Rig.init(1);
defer r.deinit();
- r.p.frontend.native_images = false;
+ r.p.view().frontend.native_images = false;
r.p.update(.{ .resize = .{ .cols = 120, .rows = 40, .cell_pixels = .{ .w = 8, .h = 16 } } });
r.drain();
// Not the frame's arena: each frame resets that.
diff --git a/test/mode.zig b/test/mode.zig
index a03d9dc1..cb93b73e 100644
--- a/test/mode.zig
+++ b/test/mode.zig
@@ -13,7 +13,7 @@ fn clickModeTag(p: *Pardes) !void {
const pane = p.panes[0].?;
const text = try pardes.tagline.tagText(p, p.scratch.allocator(), pane);
const col = std.mem.indexOf(u8, text, "Mode") orelse return error.MissingModeTag;
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const row = rect.y;
for ([_]pardes.Mouse.Kind{ .press, .release }) |kind|
p.update(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(col)), .row = row } });
diff --git a/test/output.zig b/test/output.zig
index 7fb9f237..d7b8a816 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -69,7 +69,7 @@ test "search tint survives wrapping and theme changes while selections remain au
fn outputCell(p: *Pardes, surface: *pardes.Surface, id: usize, byte: usize) *pardes.Cell {
const pane = p.panes[id].?;
const line = modal.lineSlice(pane.file.?.content, 0);
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + @as(u16, @intCast(panes.File.displayWidth(line[0..byte])));
const y = p.bodyTop(pane, rect);
return surface.at(x, y);
@@ -213,22 +213,22 @@ test "references fill the asking text's query pane: sorted under their files, th
try std.testing.expectEqual(@as(usize, 6), results.query.?.total);
// A list answered, not a query typed: the keyboard on its current row in
// normal mode; n, Enter: the keyboard on that ref in the text
- try std.testing.expectEqual(qid, p.active);
+ try std.testing.expectEqual(qid, p.view().active);
try std.testing.expect(results.body.mode == .normal and results.body.cur_row > 0);
p.update(.{ .key = .{ .cp = 'n' } });
try std.testing.expectEqual(@as(?usize, 3), source.places.current);
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 4), source.body.cur_row);
p.update(.{ .key = .{ .cp = 'N' } });
try std.testing.expectEqual(@as(?usize, 2), source.places.current);
// n in the owner steps them, round the end without a word
- p.active = 0;
+ p.view().active = 0;
p.update(.{ .key = .{ .cp = 'n' } });
try std.testing.expectEqual(@as(?usize, 3), source.places.current);
p.update(.{ .key = .{ .cp = 'n' } });
try std.testing.expectEqual(@as(?usize, 0), source.places.current);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
}
test "location sorting leaves mixed prose alone and preserves newline shape" {
@@ -267,8 +267,8 @@ test "a single language location opens the full spaced filename" {
defer p.deinit();
p.lspRequest(0, .references, "");
pardes.lsp.Ask.lspResponse(p, p.lsp_ask.wait.?.id, "with space.zig:2:1 second\n");
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/with space.zig"));
- try std.testing.expectEqual(@as(i32, 1), p.panes[p.active].?.body.cur_row);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/with space.zig"));
+ try std.testing.expectEqual(@as(i32, 1), p.panes[p.view().active].?.body.cur_row);
for (p.panes) |slot| {
const pane = slot orelse continue;
if (pane.file) |file| try std.testing.expect(file.output == null);
@@ -348,7 +348,7 @@ test "result sorting allocation failures preserve the previous answer and naviga
try std.testing.expectEqualStrings("before", result.file.?.output.?.arg());
try std.testing.expectEqual(id, source.search_pane.?);
try std.testing.expectEqual(@as(usize, 0), source.search_row.?);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(owner, p.look_walk_owner);
}
}
@@ -385,7 +385,7 @@ test "Mini asks for no watch on its pane" {
defer p.deinit();
try p.panes[0].?.setOwnedCwd(dir);
try std.testing.expect(p.executeBuiltinLine(0, "Mini build.zig"));
- const id = p.active;
+ const id = p.view().active;
try std.testing.expect(id != 0);
try std.testing.expect(p.executeBuiltinLine(id, "Mini build.zig"));
while (p.nextEffect()) |effect| switch (effect) {
@@ -401,20 +401,20 @@ test "Mini dump preserves its exact virtual snapshot and body writes detach colo
var command_buf: [128]u8 = undefined;
const command = try std.fmt.bufPrint(&command_buf, "Mini /virtual/pane/{d}/body", .{source.serial});
try std.testing.expect(p.executeBuiltinLine(0, command));
- const id = p.active;
+ const id = p.view().active;
const before = p.panes[id].?.file.?;
try std.testing.expect(before.mini != null);
try pardes.dump.dumpState(p);
panes.File.setContent(p, &source.file.?, try p.gpa.dupe(u8, "changed\n"));
const restored = try pardes.dump.initFromDump(std.testing.allocator, .{ .tty_only = true }, p.dump_out.?);
defer restored.deinit();
- const mini = restored.panes[restored.active].?;
+ const mini = restored.panes[restored.view().active].?;
try std.testing.expectEqualStrings(before.content, mini.file.?.content);
try std.testing.expectEqualStrings(before.mini.?.source, mini.file.?.mini.?.source);
try std.testing.expectEqualSlices(u8, before.mini.?.colors, mini.file.?.mini.?.colors);
try std.testing.expect(before.content.ptr != mini.file.?.content.ptr);
while (restored.nextEffect()) |effect| switch (effect) {
- .watch => |watch| try std.testing.expect(watch.pane != restored.active),
+ .watch => |watch| try std.testing.expect(watch.pane != restored.view().active),
else => {},
};
var body_buf: [128]u8 = undefined;
@@ -438,7 +438,7 @@ test "Mini syntax colors survive themes and rendering without source access" {
defer p.deinit();
try p.panes[0].?.setOwnedCwd(dir);
try panes.mini.open(p, 0, "demo.zig");
- const id = p.active;
+ const id = p.view().active;
const mini = p.panes[id].?;
const keyword = std.mem.indexOfScalar(u8, mini.file.?.mini.?.colors, @backingInt(pardes.syntax.Syn.keyword)) orelse return error.MissingKeywordColor;
// Direct pane construction bypasses the host update's layout sync.
@@ -452,7 +452,7 @@ test "Mini syntax colors survive themes and rendering without source access" {
for (0..4) |_| {
mini.file.?.syntax_dirty = true;
const surface = try p.render(frame.allocator());
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(mini) + @as(u16, @intCast(column));
const y = p.bodyTop(mini, rect) + @as(u16, @intCast(position.row));
try std.testing.expectEqualDeep(pardes.Color{ .rgb = p.theme().kw }, surface.at(x, y).style.fg);
@@ -468,7 +468,7 @@ test "DumpConfig prints the startup path" {
const p = try Pardes.init(std.testing.allocator, .{ .startup_config_path = path });
defer p.deinit();
try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig"));
- try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.file.?.content, "Startup config: " ++ path ++ "\n") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.panes[p.view().active].?.file.?.content, "Startup config: " ++ path ++ "\n") != null);
}
/// The file Config names, in a fresh temporary directory: `pardes/init`
@@ -489,19 +489,19 @@ test "Config opens the startup file, and a second Config goes back to its pane"
const path = try configFixture(&tmp, "Theme orchard\n", &buf);
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .startup_config_path = path });
defer p.deinit();
- const first = p.active;
+ const first = p.view().active;
try std.testing.expect(p.executeBuiltinLine(first, "Config"));
- const opened = p.active;
+ const opened = p.view().active;
try std.testing.expect(opened != first);
const f = p.panes[opened].?.file.?;
try std.testing.expectEqualStrings(path, f.path);
try std.testing.expectEqualStrings("Theme orchard\n", f.content);
try std.testing.expect(f.output == null);
- p.active = first;
+ p.view().active = first;
try std.testing.expect(p.executeBuiltinLine(first, "Config"));
- try std.testing.expectEqual(opened, p.active);
+ try std.testing.expectEqual(opened, p.view().active);
var named: usize = 0;
for (p.panes) |slot| if (slot) |pane| if (pane.file) |file| {
named += @intFromBool(std.mem.eql(u8, file.path, path));
@@ -516,10 +516,10 @@ test "Config with no startup file opens a pane of its name, and Save makes its d
const path = try configFixture(&tmp, null, &buf);
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .startup_config_path = path });
defer p.deinit();
- const first = p.active;
+ const first = p.view().active;
try std.testing.expect(p.executeBuiltinLine(first, "Config"));
- const opened = p.active;
+ const opened = p.view().active;
try std.testing.expect(opened != first);
const f = p.panes[opened].?.file.?;
try std.testing.expectEqualStrings(path, f.path);
@@ -527,9 +527,9 @@ test "Config with no startup file opens a pane of its name, and Save makes its d
try std.testing.expect(f.output == null);
// Again: the same pane, not a second one.
- p.active = first;
+ p.view().active = first;
try std.testing.expect(p.executeBuiltinLine(first, "Config"));
- try std.testing.expectEqual(opened, p.active);
+ try std.testing.expectEqual(opened, p.view().active);
try std.testing.expectError(error.FileNotFound, tmp.dir.statFile(std.testing.io, "pardes", .{}));
// Save's effect, as a host performs it.
@@ -559,22 +559,22 @@ test "a window's setting builtins (TaglineSize, Font) reach the report DumpConfi
.font => continue,
else => setting.word,
};
- try std.testing.expect(p.executeBuiltinLine(p.active, command));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, command));
}
if (comptime font_picker) {
const before_invalid = p.settings.font.tagline_percent;
- try std.testing.expect(p.executeBuiltinLine(p.active, "TaglineSize 0"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "TaglineSize 0"));
try std.testing.expectEqual(before_invalid, p.settings.font.tagline_percent);
const installed = fonts.list(font_arena.allocator(), null);
if (installed.len > 0) {
chosen_font = installed[0].name;
const command = try std.fmt.bufPrint(&buf, "Font {s}", .{installed[0].name});
- try std.testing.expect(p.executeBuiltinLine(p.active, command));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, command));
}
}
- try std.testing.expect(p.executeBuiltinLine(p.active, "DumpConfig"));
- const report = p.panes[p.active].?.file.?.content;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "DumpConfig"));
+ const report = p.panes[p.view().active].?.file.?.content;
// The toggles, Theme and Shell are test/behaviour/settings.zig's, through
// the root ctl; what is left is a window's (fonts).
const tagline = if (!builtins.viewCapabilities(p).tagline_font_size)
@@ -662,7 +662,7 @@ test "LookNext/LookPrev skips formatted context and selects comment match locati
.{ .key = 'N', .match = 0 },
}) |step| {
lookKey(p, step.key);
- try std.testing.expectEqual(id, p.active);
+ try std.testing.expectEqual(id, p.view().active);
const row = matches[step.match];
try std.testing.expectEqual(@as(i32, @intCast(row)), result.body.cur_row);
const line = modal.lineSlice(file.content, row);
@@ -696,12 +696,12 @@ test "LookNext/LookPrev selects one output location per row and opens nothing" {
defer p.deinit();
p.locations_config.layout = .@"inline";
p.update(.{ .resize = .{ .cols = 100, .rows = 40 } });
- const rid = try walkFixture(p, p.active, paths.cwd, "one");
+ const rid = try walkFixture(p, p.view().active, paths.cwd, "one");
const results = p.panes[rid].?;
const panes_before = p.freeSlot();
lookKey(p, 'n');
- try std.testing.expectEqual(rid, p.active);
+ try std.testing.expectEqual(rid, p.view().active);
try std.testing.expectEqual(panes_before, p.freeSlot());
try std.testing.expect(results.body.vsel.active and results.body.vsel.explicit);
try std.testing.expectEqualStrings("build.zig:1:1", selectedOutputText(results) orelse "");
@@ -718,8 +718,8 @@ test "LookNext/LookPrev selects one output location per row and opens nothing" {
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(p.freeSlot() != panes_before);
- try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/build.zig"));
- try std.testing.expectEqual(panes.Output.Grain.word, panes.Output.grain(p.panes[p.active].?.file.?.output));
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/build.zig"));
+ try std.testing.expectEqual(panes.Output.Grain.word, panes.Output.grain(p.panes[p.view().active].?.file.?.output));
}
test "LookPrev exactly reverses LookNext across output panes and the ring seam" {
@@ -730,16 +730,16 @@ test "LookPrev exactly reverses LookNext across output panes and the ring seam"
defer p.deinit();
p.locations_config.layout = .@"inline";
p.update(.{ .resize = .{ .cols = 100, .rows = 40 } });
- const first = try walkFixture(p, p.active, paths.cwd, "one");
+ const first = try walkFixture(p, p.view().active, paths.cwd, "one");
p.update(.{ .key = .{ .cp = 'n', .alt = true } });
- const second = try walkFixture(p, p.active, paths.cwd, "two");
+ const second = try walkFixture(p, p.view().active, paths.cwd, "two");
try std.testing.expect(first != second);
const Mark = struct { pane: usize, row: i32, col: i32 };
const here = struct {
fn at(pp: *Pardes) Mark {
- const pane = pp.panes[pp.active].?;
- return .{ .pane = pp.active, .row = pane.body.cur_row, .col = pane.body.cur_col };
+ const pane = pp.panes[pp.view().active].?;
+ return .{ .pane = pp.view().active, .row = pane.body.cur_row, .col = pane.body.cur_col };
}
}.at;
lookKey(p, 'n');
@@ -805,7 +805,7 @@ test "identical result refresh keeps warm content caches without allocation" {
const deallocations = allocator.deallocations;
allocator.fail_index = allocator.alloc_index;
defer allocator.fail_index = std.math.maxInt(usize);
- p.active = id;
+ p.view().active = id;
source.search_pane = null;
source.search_row = null;
p.look_walk_owner = null;
@@ -830,7 +830,7 @@ test "identical result refresh keeps warm content caches without allocation" {
try std.testing.expectEqual(@as(usize, 1), file.scroll);
try std.testing.expectEqual(@as(i32, 3), result.hscroll);
try std.testing.expectEqualStrings("after", file.output.?.arg());
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(id, source.search_pane.?);
try std.testing.expectEqual(@as(usize, 1), source.search_row.?);
try std.testing.expectEqual(result.serial, p.look_walk_owner.?);
@@ -897,7 +897,7 @@ test "rejected result refresh frees incoming text and leaves the existing output
try std.testing.expectEqual(free_slot, p.freeSlot());
try std.testing.expectEqual(id, source.search_pane.?);
try std.testing.expectEqual(@as(usize, 1), source.search_row.?);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
}
try std.testing.expect(allocator.has_induced_failure);
}
@@ -1309,7 +1309,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne
try std.testing.expectEqual(@as(usize, 6), marked);
const number = std.mem.indexOf(u8, file.content, "42").?;
try std.testing.expectEqual(@backingInt(pardes.syntax.Syn.number), file.highlights[number]);
- p.active = id;
+ p.view().active = id;
pane.body.mode = .normal;
pardes.look.armLookWalk(p, id);
for ([_]struct { key: u21, match: usize }{ .{ .key = 'n', .match = 0 }, .{ .key = 'n', .match = 1 }, .{ .key = 'N', .match = 0 } }) |step| {
@@ -1333,7 +1333,7 @@ test "stacked search and LSP results retain source tint navigation and dump owne
try std.testing.expectEqual(before.location_end, after.location_end);
try std.testing.expectEqualSlices(u8, before.colors, after.colors);
}
- restored.active = id;
+ restored.view().active = id;
pardes.look.armLookWalk(restored, id);
// The dot came back on the match it was on; the walk goes on
// from it both ways, N wrapping to the last as it does live.
diff --git a/test/panes.zig b/test/panes.zig
index 2a24e62e..e0c383fd 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -35,7 +35,7 @@ const TagLayerTests = struct {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 16 });
defer p.deinit();
const pane = try p.setTestFile("body\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
p.gpa.free(pane.file.?.path);
pane.file.?.path = try p.gpa.dupe(u8, "/x");
try setTag(pane, " " ++ &@as([38]u8, @splat('a')) ++ "\t界 END");
@@ -46,7 +46,7 @@ const TagLayerTests = struct {
const text = try pardes.tagline.tagText(p, frame.allocator(), pane);
const at = std.mem.indexOf(u8, text, "END").?;
const col = panes.File.displayWidth(text[0..at]);
- try std.testing.expect(col > p.rects[0].w);
+ try std.testing.expect(col > p.view().rects[0].w);
try std.testing.expect(col + 3 < layer.cols);
try std.testing.expectEqualStrings("E", layer.cells[col].grapheme());
try std.testing.expectEqual(@as(u16, 0), pane.tag_scroll);
@@ -74,9 +74,9 @@ const TagLayerTests = struct {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 });
defer p.deinit();
_ = try p.setTestFile("body\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 5, .tagline_h = 10 };
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const second = p.active;
+ const second = p.view().active;
try std.testing.expect(layout.splitColumn(p, second, second, false));
p.update(.tick);
var frame = std.heap.ArenaAllocator.init(p.gpa);
@@ -85,13 +85,13 @@ const TagLayerTests = struct {
const layer = try findLayer(p, .pane, second);
const edge = @as(f32, @floatFromInt(layer.viewport.x)) * 10;
p.update(.{ .mouse = mouse(layer, edge - 0.1, .press) });
- try std.testing.expect(p.drag == .move);
- try std.testing.expectEqual(second, p.drag.move.id);
+ try std.testing.expect(p.view().drag == .move);
+ try std.testing.expectEqual(second, p.view().drag.move.id);
p.update(.{ .mouse = mouse(layer, edge - 0.1, .release) });
try std.testing.expectEqualStrings(" ", p.surface.at(layer.viewport.x - 1, layer.viewport.y).grapheme());
p.update(.{ .mouse = mouse(layer, edge + 0.1, .press) });
p.update(.{ .mouse = mouse(layer, edge + 0.1, .release) });
- try std.testing.expectEqual(second, p.active);
+ try std.testing.expectEqual(second, p.view().active);
// The first cell of the tag is its path: a click there drafts a name.
try std.testing.expect(p.panes[second].?.prompt == .name);
try std.testing.expectEqual(@as(i32, 0), p.panes[second].?.input.cur_col);
@@ -106,14 +106,14 @@ const TagLayerTests = struct {
p.update(.{ .mouse = mouse(left_layer, start_x, .press) });
p.update(.{ .mouse = mouse(layer, beyond_x, .drag) });
p.update(.{ .mouse = mouse(layer, beyond_x, .release) });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- const end_col = left_layer.capacity(p.row_metrics) - 1;
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ const end_col = left_layer.capacity(p.view().row_metrics) - 1;
try std.testing.expectEqual(panes.File.rawAtDisplay(left_text, end_col), @as(usize, @intCast(left.tag.cur_col)));
try std.testing.expect(left.sel[0].state == .done and left.sel[0].r0 == 0);
p.update(.{ .key = .{ .cp = Key.escape } });
const long = &@as([60]u8, @splat('a')) ++ "界END";
p.global_tag.own = try p.gpa.dupe(u8, long);
- for (p.col_tags[0..p.ncol]) |*tag| tag.own = try p.gpa.dupe(u8, long);
+ for (p.view().col_tags[0..p.view().ncol]) |*tag| tag.own = try p.gpa.dupe(u8, long);
_ = try p.render(frame.allocator());
for ([_]Kind{ .workspace, .column }) |kind| {
const id: usize = if (kind == .column) 1 else 0;
@@ -131,7 +131,7 @@ const TagLayerTests = struct {
// Rows relative to where the pane's body and tag are, whatever height its
// tag has (a tag wraps onto more rows when it is long).
fn paneAt(p: *Pardes, r: anytype) *pardes.Pane {
- for (p.panes, 0..) |slot, id| if (slot) |pane| if (std.meta.eql(p.rects[id], r)) return pane;
+ for (p.panes, 0..) |slot, id| if (slot) |pane| if (std.meta.eql(p.view().rects[id], r)) return pane;
unreachable;
}
fn bodyY(p: *Pardes, r: anytype) u16 {
@@ -156,7 +156,7 @@ const BodyHitTests = struct {
if (!syntax.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 64, .rows = 18 });
defer p.deinit();
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
const pane = try TreeContextTests.setZigFile(p, "const Box = struct {\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([60][16]u8, @splat(" // body\n".*))) ++ " }\n};\n");
try std.testing.expect(p.executeBuiltinLine(0, "TreeContext"));
pane.scrollBy(10);
@@ -205,7 +205,7 @@ const LineNumberLookTests = struct {
if (!syntax.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 64, .rows = 18 });
defer p.deinit();
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
const pane = try TreeContextTests.setZigFile(p, "const Box = struct {\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([60][16]u8, @splat(" // body\n".*))) ++ " }\n};\n");
try std.testing.expect(p.executeBuiltinLine(0, "TreeContext"));
pane.scrollBy(30);
@@ -264,7 +264,7 @@ const TreeContextTests = struct {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 64, .rows = 18 });
defer p.deinit();
const pane = try setZigFile(p, "const Box = struct {\n\n // omitted member comment\n\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*))) ++ " }\n};\n");
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
try std.testing.expect(p.executeBuiltinLine(0, "TreeContext"));
pane.scrollBy(10);
var frame = std.heap.ArenaAllocator.init(p.gpa);
@@ -302,7 +302,7 @@ const TreeContextTests = struct {
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(i32, 0), pane.scroll());
pardes.look.lookAt(p, 0, "/tree-context.zig:60");
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row);
const surface = try p.render(frame.allocator());
const visible = pane.wrapRow(pane.body.cur_row, pane.body.cur_col);
@@ -310,7 +310,7 @@ const TreeContextTests = struct {
try std.testing.expect(visible.row < pane.rows);
try std.testing.expectEqual(@as(i32, 59), pane.wrapAt(visible.row).line);
const cursor = surface.cursor orelse return error.MissingLookCursor;
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const y = p.bodyTop(pane, rect);
try std.testing.expectEqual(y + @as(u16, @intCast(visible.row)), cursor.y);
}
@@ -333,7 +333,7 @@ const TreeContextTests = struct {
try std.testing.expectEqual(@as(u16, 4), pane.context_rows);
for (0..4) |row| try std.testing.expectEqual(@as(i32, @intCast(row)), pane.wrapAt(@intCast(row)).line);
try std.testing.expectEqual(@as(i32, 7), pane.wrapAt(pane.context_rows).line);
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
const y = p.bodyTop(pane, rect);
ClickCursorTests.click(p, .left, x + 6, y);
@@ -344,7 +344,7 @@ const TreeContextTests = struct {
try std.testing.expectEqual(x + 6, cursor.x);
// Read the body top again: the click cleared the announcement band the
// builtin above put up, and the body moved back up with it.
- try std.testing.expectEqual(p.bodyTop(pane, p.rects[0]), cursor.y);
+ try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[0]), cursor.y);
p.update(.{ .key = .{ .cp = 'i' } });
p.update(.{ .key = .{ .cp = 'Z', .text = "Z" } });
try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "const ZBox = struct {"));
@@ -384,7 +384,7 @@ const TreeContextTests = struct {
p.sync();
const surface = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u16, 3), pane.context_rows);
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const y = p.bodyTop(pane, rect);
var glyph_x: ?u16 = null;
for (0..surface.cols) |col| {
@@ -399,7 +399,7 @@ const TreeContextTests = struct {
try std.testing.expectEqual(x, cursor.x);
// Read the body top again: the click cleared the announcement band the
// builtin above put up, so the body moved with it.
- try std.testing.expectEqual(p.bodyTop(pane, p.rects[0]), cursor.y);
+ try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[0]), cursor.y);
panes.File.setContent(p, &pane.file.?, try p.gpa.dupe(u8, std.mem.asBytes(&@as([18][28]u8, @splat("// no enclosing declaration\n".*)))));
p.sync();
_ = try p.render(frame.allocator());
@@ -458,7 +458,7 @@ const TtySelectionTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER;
const y = p.bodyTop(pane, rect);
JumpSelectionTests.drag(p, x + 1, y, x + 3, y);
@@ -486,7 +486,7 @@ const TtySelectionTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER;
const y = p.bodyTop(pane, rect);
JumpSelectionTests.drag(p, x + @as(u16, if (prompt) 0 else 1), y, x + 3, y + @as(u16, if (prompt) 0 else 1));
@@ -550,14 +550,14 @@ const TtySelectionTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const source = p.rects[0];
+ const source = p.view().rects[0];
const sx = source.x + config.GUTTER;
const sy = bodyY(p, source);
JumpSelectionTests.drag(p, sx + 1, sy, sx + 3, sy + 1);
try std.testing.expectEqualStrings("lpha\nbrav", p.registers.text(p.gpa, '"') orelse return error.MissingAutomaticTtyYank);
try noChildInput(p);
- const target = p.rects[1];
+ const target = p.view().rects[1];
const tx = target.x + config.GUTTER + 2;
const ty = bodyY(p, target);
// Over a program that tracks the mouse B1 is its own, so
@@ -628,7 +628,7 @@ const TtySelectionTests = struct {
if (bracketed) "\x1b[200~one\ntwo\x1b[201~" else "one\rtwo",
childInput(p, &buf),
);
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
// Ctrl-Shift-V is the other store: it ASKS, types nothing yet, and
// the answer lands at the program rather than in an edit buffer. A
@@ -638,10 +638,10 @@ const TtySelectionTests = struct {
.{ .cp = 'V', .ctrl = true },
}) |chord| {
p.update(.{ .key = chord });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
try std.testing.expectEqualStrings("", childInput(p, &buf));
p.update(.{ .paste = "from-desktop" });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
try std.testing.expectEqualStrings(
if (bracketed) "\x1b[200~from-desktop\x1b[201~" else "from-desktop",
childInput(p, &buf),
@@ -669,7 +669,7 @@ const ClickCursorTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
const y = p.bodyTop(pane, rect);
// The pane reaches the screen's bottom: its last row is the edge.
@@ -693,7 +693,7 @@ const ClickCursorTests = struct {
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
const y = bodyY(p, rect);
JumpSelectionTests.drag(p, x + 1, y + 4, x + 3, y + 4);
@@ -757,14 +757,14 @@ const JumpSelectionTests = struct {
layout.compute(p);
try LookResetTests.seed(source, "source held text");
try LookResetTests.seed(destination, "destination held text");
- p.active = 0;
- p.jumps.n = 2;
- p.jumps.cur = 1;
- p.jumps.list[0] = .{ .pane = @intCast(id), .serial = destination.serial, .line = 3, .col = 2 };
- p.jumps.list[1] = .{ .pane = 0, .serial = source.serial, .line = 2, .col = 1 };
+ p.view().active = 0;
+ p.view().jumps.n = 2;
+ p.view().jumps.cur = 1;
+ p.view().jumps.list[0] = .{ .pane = @intCast(id), .serial = destination.serial, .line = 3, .col = 2 };
+ p.view().jumps.list[1] = .{ .pane = 0, .serial = source.serial, .line = 2, .col = 1 };
p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
- try std.testing.expectEqual(id, p.active);
- try std.testing.expectEqual(@as(usize, 0), p.jumps.cur);
+ try std.testing.expectEqual(id, p.view().active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().jumps.cur);
try LookResetTests.cleared(source);
try LookResetTests.cleared(destination);
try std.testing.expect(!source.body.vsel.active and !destination.body.vsel.active);
@@ -774,8 +774,8 @@ const JumpSelectionTests = struct {
try LookResetTests.seed(source, "new source held text");
try LookResetTests.seed(destination, "new destination held text");
p.update(.{ .key = .{ .cp = 'i', .ctrl = true } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expectEqual(@as(usize, 1), p.jumps.cur);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur);
try LookResetTests.cleared(source);
try LookResetTests.cleared(destination);
try std.testing.expect(!source.body.vsel.active and !destination.body.vsel.active);
@@ -808,7 +808,7 @@ const TagNameTintTests = struct {
// tag's own to say whether it is in the name.
const shown = try pardes.tagline.shownTag(p, arena.allocator(), pane);
const base = std.mem.lastIndexOfScalar(u8, name, '/') orelse return error.MissingDirectory;
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const left = rect.x + pardes.TAG_TEXT_INSET;
var visible_name: usize = 0;
for (0..pane.tag_rows) |row| {
@@ -872,8 +872,8 @@ const TagNameTintTests = struct {
const col: i32 = @intCast(panes.File.rawDisplayCol(modal.lineSlice(shown.text, pos.row), pos.col));
pane.sel[0] = .{ .state = .done, .c0 = col, .c1 = col + 1, .r0 = @intCast(pos.row), .r1 = @intCast(pos.row) };
const surface = try p.render(arena.allocator());
- const x = p.rects[0].x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(col));
- const y = tagY(p, p.rects[0]) + @as(u16, @intCast(pos.row));
+ const x = p.view().rects[0].x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(col));
+ const y = tagY(p, p.view().rects[0]) + @as(u16, @intCast(pos.row));
try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().sel_fg }, surface.at(x, y).style.fg);
try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().sel_fg }, surface.at(x + 1, y).style.fg);
}
@@ -893,8 +893,8 @@ const TagNameTintTests = struct {
var arena = std.heap.ArenaAllocator.init(p.gpa);
defer arena.deinit();
const surface = try p.render(arena.allocator());
- const x = p.rects[0].x + pardes.TAG_TEXT_INSET;
- const y = tagY(p, p.rects[0]);
+ const x = p.view().rects[0].x + pardes.TAG_TEXT_INSET;
+ const y = tagY(p, p.view().rects[0]);
const fg = active_fg;
// The directory in the ink; the name tinted, never in it.
const chrome = p.chromeTheme();
@@ -955,7 +955,7 @@ test "a tag that exactly fills its row stays one row, its caret at the edge as a
// The layer's caret is past the last character; the grid's, on the pane's
// last cell, since it has none past it.
try std.testing.expectEqual(@as(u16, @intCast(width)), surface.tag_layers[0].cursor.?.x);
- try std.testing.expectEqual(p.rects[0].x + p.rects[0].w - 1, surface.cursor.?.x);
+ try std.testing.expectEqual(p.view().rects[0].x + p.view().rects[0].w - 1, surface.cursor.?.x);
}
test "terminal overlay recoloring never materializes unrelated history" {
@@ -979,7 +979,7 @@ test "terminal overlay recoloring never materializes unrelated history" {
_ = frame.reset(.retain_capacity);
const surface = try p.render(frame.allocator());
try testing.expect(p.shell_rows.pane == null);
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const body_y = bodyY(p, rect);
const cell = surface.at(rect.x + config.GUTTER, body_y);
try testing.expectEqualStrings("c", cell.grapheme());
@@ -1025,7 +1025,7 @@ test "terminal output keeps following new rows after scrollback eviction" {
try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, full, "\n"), last));
_ = frame.reset(.retain_capacity);
const surface = try p.render(frame.allocator());
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER;
const y = (bodyY(p, rect)) + pane.rows - 2;
for (last, 0..) |byte, col| {
@@ -1493,7 +1493,7 @@ test "Save on a scratch does not watch a path the host could not create" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 });
defer p.deinit();
try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const id = p.active;
+ const id = p.view().active;
while (p.nextEffect()) |_| {}
p.host = .{ .ctx = p, .vtable = &.{ .write_file = Refusing.write } };
const file = &p.panes[id].?.file.?;
@@ -1544,9 +1544,9 @@ test "unplaced terminal panes keep their allocated grid until placement" {
while (p.nextEffect()) |_| {}
const id = p.freeSlot().?;
const pane = try p.newShell(id, "");
- try std.testing.expectEqual(pardes.Rect{}, p.rects[id]);
+ try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]);
p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "unplaced\r\n" } });
- try std.testing.expectEqual(pardes.Rect{}, p.rects[id]);
+ try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]);
try std.testing.expectEqual(@as(u16, 100), pane.cols);
try std.testing.expectEqual(@as(u16, 30), pane.rows);
try std.testing.expectEqual(pane.cols, pane.terminal.?.vt.cols);
@@ -1556,9 +1556,9 @@ test "unplaced terminal panes keep their allocated grid until placement" {
}
pardes.layout.insert(p, 0, 1, id);
p.update(.tick);
- try std.testing.expect(p.rects[id].w > 0 and p.rects[id].h > pardes.BOX_H);
- try std.testing.expectEqual(p.rects[id].w - config.GUTTER, pane.cols);
- try std.testing.expectEqual(bodyH(p, p.rects[id]), pane.rows);
+ try std.testing.expect(p.view().rects[id].w > 0 and p.view().rects[id].h > pardes.BOX_H);
+ try std.testing.expectEqual(p.view().rects[id].w - config.GUTTER, pane.cols);
+ try std.testing.expectEqual(bodyH(p, p.view().rects[id]), pane.rows);
}
test "document panes ignore terminal output without allocating terminal state" {
@@ -1589,29 +1589,29 @@ test "removed and recycled pane slots have no stale geometry" {
const original = try p.newDocPane(id);
pardes.layout.insert(p, 0, 1, id);
layout.compute(p);
- try std.testing.expect(p.rects[id].w > 0 and p.rects[id].h > 0);
+ try std.testing.expect(p.view().rects[id].w > 0 and p.view().rects[id].h > 0);
layout.removePane(p, id);
layout.compute(p);
- try std.testing.expectEqual(pardes.Rect{}, p.rects[id]);
+ try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]);
try pardes.panes.deinitPane(p, original);
p.panes[id] = null;
- p.rects[id] = .{ .x = 10, .y = 5, .w = 20, .h = 10 };
+ p.view().rects[id] = .{ .x = 10, .y = 5, .w = 20, .h = 10 };
const replacement = try p.newDocPane(id);
try std.testing.expect(replacement.serial != original.serial);
- try std.testing.expectEqual(pardes.Rect{}, p.rects[id]);
+ try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]);
pardes.layout.insert(p, 0, 1, id);
for ([_]u16{ 1, 2, 3, 10 }) |size| {
p.update(.{ .resize = .{ .cols = size, .rows = size } });
- for (p.rects) |rect| {
+ for (p.view().rects) |rect| {
try std.testing.expect(rect.x + rect.w <= size);
try std.testing.expect(rect.y + rect.h <= size);
}
}
- p.ncol = 0;
+ p.view().ncol = 0;
layout.compute(p);
- for (p.rects) |rect| try std.testing.expectEqual(pardes.Rect{}, rect);
+ for (p.view().rects) |rect| try std.testing.expectEqual(pardes.Rect{}, rect);
}
const FileTests = struct {
@@ -1743,11 +1743,11 @@ const OutputTests = struct {
try std.testing.expectEqual(i == 0 or i == 4, panes.Output.isResultRow(file, i));
if (i != 5) try std.testing.expect(!row.mark_occurrence);
}
- p.active = result_id;
+ p.view().active = result_id;
result.body.cur_row = 4;
result.body.cur_col = " ╰─ ".len;
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
try pardes.dump.dumpState(p);
const restored = try pardes.dump.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?);
@@ -1797,7 +1797,7 @@ const OutputTests = struct {
try std.testing.expect(file.location_rows[5].mark_occurrence);
try std.testing.expect(!file.location_rows[5].declaration);
try std.testing.expect(!panes.Output.isWalkRow(file, 1, modal.lineSlice(file.content, 1)));
- p.active = result_id;
+ p.view().active = result_id;
result.body.cur_row = 0;
result.body.cur_col = 0;
p.update(.{ .key = .{ .cp = ' ' } });
@@ -1808,7 +1808,7 @@ const OutputTests = struct {
// Enter on the selected signature address must open source, not a path
// accidentally prefixed with tree glyphs.
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
p.settings.callstack_depth = 16;
try pardes.dump.dumpState(p);
@@ -1827,8 +1827,8 @@ const OutputTests = struct {
// Narrow enough that the location itself wraps. The repeated guide
// consumes cells, but neither changes the source address nor steals
// a click from the wrapped portion of that address.
- p.active = result_id;
- p.row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
+ p.view().active = result_id;
+ p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 };
p.update(.{ .resize = .{ .cols = 28, .rows = 40 } });
result.file.?.scroll = 0;
var frame = std.heap.ArenaAllocator.init(p.gpa);
@@ -1842,14 +1842,14 @@ const OutputTests = struct {
const shown = try panes.File.bodyText(frame.allocator(), result, file);
const shown_line = modal.lineSlice(shown, wrapped);
try std.testing.expect(std.mem.startsWith(u8, shown_line[panes.File.gutterWidth(result)..], "│ │ "));
- const rect = p.rects[result_id];
+ const rect = p.view().rects[result_id];
const press: pardes.Mouse = .{ .button = .right, .kind = .press, .col = @intCast(rect.x + config.GUTTER + panes.File.gutterWidth(result) + w.pad + 1), .row = @intCast(p.bodyTop(result, rect) + wrapped) };
var release = press;
release.kind = .release;
p.update(.{ .mouse = press });
p.update(.{ .mouse = release });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
}
@@ -2047,7 +2047,7 @@ const OutputTests = struct {
result.scrollBy(-1000);
layout.compute(p);
const surface = try p.render(frame.allocator());
- const rect = p.rects[pane.search_pane.?];
+ const rect = p.view().rects[pane.search_pane.?];
const body_y = bodyY(p, rect);
for (file.location_rows, 0..) |row, index| {
if (!row.declaration) continue;
@@ -2077,14 +2077,14 @@ const OutputTests = struct {
defer p.deinit();
_ = try p.setTestFile("notes\n");
try std.testing.expect(p.executeBuiltinLine(0, "Help"));
- const id = p.active;
+ const id = p.view().active;
const help = p.panes[id].?;
for ("gevkk") |key| p.update(.{ .key = .{ .cp = key } });
try std.testing.expect(help.body.vsel.active);
try std.testing.expect(help.body.vsel.row > 5);
try std.testing.expect(help.body.cur_row != help.body.vsel.row);
for (" h?") |key| p.update(.{ .key = .{ .cp = key } });
- try std.testing.expectEqual(id, p.active);
+ try std.testing.expectEqual(id, p.view().active);
const content = help.file.?.content;
try std.testing.expect(std.mem.startsWith(u8, content, "pardes builtins under SPC h\n"));
const at = std.mem.indexOf(u8, content, "Tutor") orelse return error.MissingTutorRow;
@@ -2093,13 +2093,13 @@ const OutputTests = struct {
var frame: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer frame.deinit();
_ = try p.render(frame.allocator());
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(help) + @as(u16, @intCast(at - line_start + 2));
const y = (bodyY(p, rect)) + @as(u16, @intCast(row));
p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = x, .row = y } });
- try std.testing.expect(p.active != id);
- const tutor = p.panes[p.active].?.file orelse return error.MissingTutor;
+ try std.testing.expect(p.view().active != id);
+ const tutor = p.panes[p.view().active].?.file orelse return error.MissingTutor;
try std.testing.expect(std.mem.indexOf(u8, tutor.content, "PARDES TUTOR") != null);
}
@@ -2114,7 +2114,7 @@ const OutputTests = struct {
if (slot != null and slot.?.file != null and slot.?.file.?.output != null) break id;
} else return error.MissingResults;
const result = p.panes[id].?;
- p.active = id;
+ p.view().active = id;
for ("Cv3") |key| p.update(.{ .key = .{ .cp = key } });
try std.testing.expect(result.body.nsel > 0);
try std.testing.expect(result.body.select);
@@ -2162,15 +2162,15 @@ const OutputTests = struct {
defer frame.deinit();
_ = try p.render(frame.allocator());
p.presented();
- const rect = p.rects[id];
+ const rect = p.view().rects[id];
const x = rect.x + config.GUTTER + panes.File.gutterWidth(result);
const y = bodyY(p, rect);
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x + 2, .row = y + 1 } });
- try std.testing.expect(p.drag == .select);
+ try std.testing.expect(p.view().drag == .select);
try std.testing.expectEqual(.dragging, result.sel[@backingInt(config.select_button)].state);
try fillResults(p, 0, "/", .{ .query = .hover }, "", try p.gpa.dupe(u8, "short\n"), null);
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x + 2, .row = y + 1 } });
for (result.sel) |selection| try std.testing.expectEqual(.none, selection.state);
try std.testing.expect(!result.body.vsel.active);
@@ -2429,7 +2429,7 @@ const TerminalTests = struct {
fn modeStyleDiffs(p: *Pardes, pane: *Pane, gpa: std.mem.Allocator, note: []const u8) !usize {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const rows: usize = bodyH(p, r);
@@ -2690,7 +2690,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const red: pardes.Color = .{ .index = 1 };
@@ -2745,7 +2745,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -2793,7 +2793,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const body_h = bodyH(p, r);
@@ -2832,7 +2832,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const red: pardes.Color = .{ .index = 1 };
@@ -2869,7 +2869,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const red: pardes.Color = .{ .index = 1 };
@@ -2951,7 +2951,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
p.shell_rows.stale = true;
@@ -3029,7 +3029,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const rows: usize = bodyH(p, r);
@@ -3091,7 +3091,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
p.shell_rows.stale = true;
@@ -3127,7 +3127,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
p.shell_rows.stale = true;
@@ -3160,7 +3160,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
const s = try p.render(frame.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3203,7 +3203,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3241,7 +3241,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3279,7 +3279,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3315,7 +3315,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const blue: pardes.Color = .{ .index = 4 };
@@ -3358,7 +3358,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3411,7 +3411,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3465,7 +3465,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
const body_h = bodyH(p, r);
@@ -3560,7 +3560,7 @@ const TerminalTests = struct {
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
- const r = p.rects[0];
+ const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = bodyY(p, r);
@@ -3662,7 +3662,7 @@ test "Zig keywords keep every rendered byte colored across line-number widths" {
const surface = try p.render(frame.allocator());
var seen: usize = 0;
var if_position: ?struct { x: u16, y: u16 } = null;
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const body_y = bodyY(p, rect);
for (body_y..body_y + bodyH(p, rect)) |y| {
for (rect.x + config.GUTTER..rect.x + rect.w - 1) |x| {
@@ -3710,7 +3710,7 @@ test "terminal overlays preserve trailing blank styles without coloring inserted
pane.ovl = .{ .row = 0, .rows = 3, .text = try gpa.dupe(u8, "A\n\n") };
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
const x = rect.x + config.GUTTER;
const y = bodyY(p, rect);
const palette = p.theme().palette.?;
@@ -3791,11 +3791,11 @@ test "a terminal keeps its tag and two body rows through a squeeze, a drag and a
const floor = p.panes[term].?.tag_rows + layout.min_body_rows;
// Squeezed by the weights: the others give it its floor.
p.panes[term].?.vweight = 0.01;
- for (p.cols[col].panes[0..p.cols[col].n]) |k| if (k != term) {
+ for (p.view().cols[col].panes[0..p.view().cols[col].n]) |k| if (k != term) {
p.panes[k].?.vweight = 1000;
};
p.sync();
- try std.testing.expectEqual(floor, p.rects[term].h);
+ try std.testing.expectEqual(floor, p.view().rects[term].h);
var rows: ?u16 = null;
while (p.nextEffect()) |effect| if (effect == .resize_pty and effect.resize_pty.pane == term) {
rows = effect.resize_pty.rows;
@@ -3804,17 +3804,17 @@ test "a terminal keeps its tag and two body rows through a squeeze, a drag and a
// A drag of the grip under it up to its tag stops at the floor; one
// the other way takes a text pane down to its tag alone.
const k = layout.findPane(p, term).?.idx;
- if (k + 1 < p.cols[col].n) {
- layout.applyRowSplit(p, col, k, p.rects[term].y);
+ if (k + 1 < p.view().cols[col].n) {
+ layout.applyRowSplit(p, col, k, p.view().rects[term].y);
p.sync();
- try std.testing.expectEqual(floor, p.rects[term].h);
- const text = p.cols[col].panes[k + 1];
- layout.applyRowSplit(p, col, k, p.screen_h);
+ try std.testing.expectEqual(floor, p.view().rects[term].h);
+ const text = p.view().cols[col].panes[k + 1];
+ layout.applyRowSplit(p, col, k, p.view().screen_h);
p.sync();
- try std.testing.expect(p.rects[text].h <= p.panes[text].?.tag_rows);
+ try std.testing.expect(p.view().rects[text].h <= p.panes[text].?.tag_rows);
}
// A window too short for all: the terminal keeps its floor still.
p.update(.{ .resize = .{ .cols = 100, .rows = 10 } });
p.sync();
- try std.testing.expect(p.rects[term].h >= p.panes[term].?.tag_rows + layout.min_body_rows);
+ try std.testing.expect(p.view().rects[term].h >= p.panes[term].?.tag_rows + layout.min_body_rows);
}
diff --git a/test/pdf.zig b/test/pdf.zig
index da1cb45d..5de72876 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -107,14 +107,14 @@ const PdfLinkTests = struct {
const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/links.pdf", .{dir_buf[0..len]});
defer std.testing.allocator.free(path);
const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 100, .rows = 36 });
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
p.panes[0].?.pdf.?.fit = .height;
return p;
}
fn cellAt(p: *Pardes, x: f32, y: f32) !Cell {
const pane = p.panes[0].?;
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
var best: ?Cell = null;
var distance: f32 = std.math.inf(f32);
for (rect.y..rect.y + rect.h) |row| for (rect.x..rect.x + rect.w) |col| {
@@ -200,8 +200,8 @@ const PdfLinkTests = struct {
pardes.look.lookAt(p, choices_id, "https://example.com/embedded");
try expectOpened(p, "https://example.com/embedded");
pardes.look.lookAt(p, choices_id, "target.txt");
- try std.testing.expectEqualStrings("chosen file\n", p.panes[p.active].?.file.?.content);
- p.active = 0;
+ try std.testing.expectEqualStrings("chosen file\n", p.panes[p.view().active].?.file.?.content);
+ p.view().active = 0;
_ = try p.render(frame.allocator());
click(p, try textCell(p, "https://example.com/same"));
try expectOpened(p, "https://example.com/same");
@@ -376,16 +376,16 @@ test "PdfSections Look follows the exact owning PDF, not an equal path" {
const first_row = std.mem.sliceTo(first_output.file.?.content, '\n');
const target = first_row[0 .. std.mem.indexOfScalar(u8, first_row, ' ') orelse first_row.len];
pardes.look.lookAt(p, first_output_id, target);
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
pardes.look.lookAt(p, duplicate_output_id, target);
- try std.testing.expectEqual(duplicate_id, p.active);
+ try std.testing.expectEqual(duplicate_id, p.view().active);
// Once the original document is gone, its output cannot reinterpret an
// old ordinal against the still-open equal-path duplicate.
try std.testing.expect(pardes.test_api.runBuiltin(p, "Del", 0, "", null));
- p.active = first_output_id;
+ p.view().active = first_output_id;
pardes.look.lookAt(p, first_output_id, target);
- try std.testing.expectEqual(first_output_id, p.active);
+ try std.testing.expectEqual(first_output_id, p.view().active);
}
test "SDL PDF raster policy is materially denser than Kitty" {
@@ -437,7 +437,7 @@ test "watched PDF reload replaces MuPDF state and preserves the reading view" {
const sections = p.panes[sections_id].?;
try std.testing.expect(sections.file.?.content.len > 0);
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
state.fit = .height;
state.tint = .full;
state.pan_x = 1234;
@@ -554,7 +554,7 @@ test "PDF reload does not re-center an already revealed matching search" {
const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/search.pdf", .{tmp.sub_path});
const p = try Pardes.init(gpa, .{ .file = path, .cols = 80, .rows = 28 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
const pane = p.panes[0].?;
const state = pane.pdf.?;
try state.setSearchQuery(p.pdf_gpa, "Pardes");
@@ -614,14 +614,14 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
try std.testing.expectEqual(PdfFitMode.width, pane.pdf.?.fit);
try std.testing.expectEqual(@as(u16, 0), pane.pdf.?.pan_x);
try std.testing.expectEqual(@as(u16, 0), pane.pdf.?.pan_y);
- try std.testing.expectEqual(@as(u16, 8), p.cell_pixels.w);
- try std.testing.expectEqual(@as(u16, 16), p.cell_pixels.h);
+ try std.testing.expectEqual(@as(u16, 8), p.view().cell_pixels.w);
+ try std.testing.expectEqual(@as(u16, 16), p.view().cell_pixels.h);
const initial_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane);
const expected_tag = try std.fmt.allocPrint(p.scratch.allocator(), "{s} [1/{d}]{s}", .{ pane.pdf.?.path, pane.pdf.?.page_count, pane_tail });
try std.testing.expectEqualStrings(expected_tag, initial_tag);
try std.testing.expect(std.mem.endsWith(u8, initial_tag, pane_tail));
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const first = try p.render(frame.allocator());
@@ -668,7 +668,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
// replacing page pixels. Document placement, not texture identity, moves.
p.update(.{ .key = .{ .cp = 'j' } });
try std.testing.expectEqual(@as(usize, 0), pane.pdf.?.page);
- try std.testing.expectEqual(@as(f64, p.cell_pixels.h), pane.pdf.?.document_scroll_y);
+ try std.testing.expectEqual(@as(f64, p.view().cell_pixels.h), pane.pdf.?.document_scroll_y);
try std.testing.expectEqual(
first_place.revision,
panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision,
@@ -682,7 +682,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
pane.pdf.?.document_scroll_y = 0;
p.update(.{ .key = .{ .cp = '3' } });
p.update(.{ .key = .{ .cp = 'j' } });
- try std.testing.expectEqual(@as(f64, p.cell_pixels.h * 3), pane.pdf.?.document_scroll_y);
+ try std.testing.expectEqual(@as(f64, p.view().cell_pixels.h * 3), pane.pdf.?.document_scroll_y);
// Counts survive a shared multi-key prefix. An invalid continuation is
// consumed and clears both prefix and count before the following action.
@@ -690,7 +690,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
p.update(.{ .key = .{ .cp = '2' } });
p.update(.{ .key = .{ .cp = 'g' } });
p.update(.{ .key = .{ .cp = 'j' } });
- try std.testing.expectEqual(@as(f64, p.cell_pixels.h * 2), pane.pdf.?.document_scroll_y);
+ try std.testing.expectEqual(@as(f64, p.view().cell_pixels.h * 2), pane.pdf.?.document_scroll_y);
pane.pdf.?.document_scroll_y = 0;
p.update(.{ .key = .{ .cp = '4' } });
p.update(.{ .key = .{ .cp = 'g' } });
@@ -712,7 +712,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
p.update(.{ .key = .{ .cp = '2' } });
p.update(.{ .key = .{ .cp = 'u', .ctrl = true } });
try std.testing.expectEqual(@as(f64, 0), pane.pdf.?.document_scroll_y);
- pane.pdf.?.document_scroll_y = @as(f64, p.cell_pixels.h) * 4;
+ pane.pdf.?.document_scroll_y = @as(f64, p.view().cell_pixels.h) * 4;
p.update(.{ .key = .{ .cp = '3' } });
p.update(.{ .key = .{ .cp = 'k' } });
try std.testing.expectEqual(row_scroll, pane.pdf.?.document_scroll_y);
@@ -784,7 +784,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
pane.pdf.?.document_scroll_y = before_boundary_scroll;
p.update(.{ .key = .{ .cp = 'j' } });
- try std.testing.expectEqual(before_boundary_scroll + p.cell_pixels.h, pane.pdf.?.document_scroll_y);
+ try std.testing.expectEqual(before_boundary_scroll + p.view().cell_pixels.h, pane.pdf.?.document_scroll_y);
_ = frame.reset(.retain_capacity);
const second = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 2), second.placements.items.len);
@@ -897,13 +897,13 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
// here is the unlooked +Search buffer, so focus lands THERE. Enter is what
// jumps, and the document query survives both.
p.update(.{ .key = .{ .cp = 'n' } });
- try std.testing.expectEqual(results_id, p.active);
+ try std.testing.expectEqual(results_id, p.view().active);
const results_pane = p.panes[results_id].?;
try std.testing.expect(results_pane.body.vsel.active and results_pane.body.vsel.explicit);
try std.testing.expectEqual(@as(i32, 0), results_pane.body.cur_row);
try std.testing.expectEqual(@as(i32, 0), results_pane.body.cur_col);
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqualStrings("Pardes", pane.pdf.?.search_query);
// Search state is owned and untruncated, and changing pages invalidates
@@ -951,7 +951,7 @@ test "a fling's banded pages show the reader exactly what whole pages would" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .file = "docs/design.pdf", .cols = 120, .rows = 40 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
const pane = p.panes[0].?;
const pv = pane.pdf.?;
var frame = std.heap.ArenaAllocator.init(gpa);
@@ -1055,7 +1055,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
defer gpa.free(path);
const p = try Pardes.init(gpa, .{ .file = path, .cols = 120, .rows = 40 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
const pane = p.panes[0].?;
const pv = pane.pdf.?;
var frame = std.heap.ArenaAllocator.init(gpa);
@@ -1175,7 +1175,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
const right = @max(quad.ur.x, quad.lr.x);
const top = @min(quad.ul.y, quad.ur.y);
const bottom = @max(quad.ll.y, quad.lr.y);
- const rect = p.rects[0];
+ const rect = p.view().rects[0];
var inside: usize = 0;
for (rect.y..rect.y + rect.h) |row| for (rect.x..rect.x + rect.w) |col| {
const point = panes.Pdf.panePointAtPage(p, pane, 0, @intCast(col), @intCast(row), false) orelse continue;
@@ -1216,7 +1216,7 @@ test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape lea
defer p.deinit();
const pane = p.panes[0].?;
const pv = pane.pdf.?;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
// A second pane, then focus it and come back: `Last` has somewhere to go
// and the PDF is where the keys land.
@@ -1224,11 +1224,11 @@ test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape lea
p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
p.update(.{ .key = .{ .cp = 'j' } });
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().active);
p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
p.update(.{ .key = .{ .cp = 'k' } });
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
// Everything a reader can see over the page: a search overlay and a live
// word selection.
@@ -1248,7 +1248,7 @@ test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape lea
// Escape drops the overlay and the selection, keeps the reading position,
// and does NOT hand the keyboard to another pane.
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expect(pv.selection == null and pv.selection_text.len == 0);
try std.testing.expectEqual(@as(usize, 0), pv.search_query.len);
try std.testing.expect(pv.search_results == null);
@@ -1260,28 +1260,28 @@ test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape lea
// With nothing left to drop, Escape goes back a pane as anywhere else,
// and leaves the document as it found it.
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().active);
try std.testing.expectEqual(page_before, pv.page);
try std.testing.expectEqual(scroll_before, pv.document_scroll_y);
// Shift-Escape goes at once, over a selection too.
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try std.testing.expectEqual(
panes.Pdf.SelectionUpdate.changed,
pv.setSelection(p.pdf_gpa, quad.ul, quad.lr, false),
);
p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
- try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().active);
try std.testing.expect(pv.selection != null);
// A text-only page shows neither: one Escape drops them and goes.
- p.frontend.native_images = false;
+ p.view().frontend.native_images = false;
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
try pv.setSearchQuery(p.pdf_gpa, "Pardes");
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.view().active);
try std.testing.expect(pv.selection == null and pv.search_query.len == 0);
}
@@ -1298,7 +1298,7 @@ test "PDF continuous strip renders every intersecting short page" {
const pane = p.panes[0].?;
const pv = pane.pdf.?;
try std.testing.expect(pv.page_count > 3);
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
// A legal wide MediaBox can make more than three pages intersect one
// viewport. Seed tiny matching rasters so this tests transport/cache
@@ -1372,7 +1372,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
defer p.deinit();
const pane = p.panes[0].?;
const pv = pane.pdf.?;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -1496,7 +1496,7 @@ test "PDF resize preserves page-relative document position" {
defer p.deinit();
const pane = p.panes[0].?;
const pv = pane.pdf.?;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -1508,7 +1508,7 @@ test "PDF resize preserves page-relative document position" {
p.update(.{ .resize = .{
.cols = 100,
.rows = 24,
- .cell_pixels = p.cell_pixels,
+ .cell_pixels = p.view().cell_pixels,
} });
try std.testing.expect(!pv.layout_valid);
try std.testing.expect(pv.layout_anchor_pending);
@@ -1524,7 +1524,7 @@ test "PDF resize preserves page-relative document position" {
p.update(.{ .resize = .{
.cols = 100,
.rows = 24,
- .cell_pixels = p.cell_pixels,
+ .cell_pixels = p.view().cell_pixels,
} });
try std.testing.expectEqual(held, pv.document_scroll_y);
try std.testing.expect(pv.layout_valid);
@@ -1547,7 +1547,7 @@ test "PDF pane geometry change preserves its page-relative position" {
p.sync(); // rects for the new column, exactly as the two-pane boot did
const pane = p.panes[0].?;
const pv = pane.pdf.?;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
@@ -1561,8 +1561,8 @@ test "PDF pane geometry change preserves its page-relative position" {
// A divider/split changes rects through computeGeom without emitting a
// shell resize. panes.Pdf.ensurePaneLayout anchors against the old layout
// before rebuilding it for this wider pane.
- const sibling_weight = p.cols[1].weight;
- p.cols[0].weight = sibling_weight * 6;
+ const sibling_weight = p.view().cols[1].weight;
+ p.view().cols[0].weight = sibling_weight * 6;
layout.compute(p);
try std.testing.expect(panes.Pdf.paneViewport(p, pane).?.pixel_w != old_width);
try std.testing.expect(pv.layout_valid);
@@ -1577,7 +1577,7 @@ test "PDF pane geometry change preserves its page-relative position" {
// An explicit pending reveal wins over an implicit layout anchor.
pv.page = 2;
pv.scroll_to_page_pending = true;
- p.cols[0].weight = sibling_weight * 2;
+ p.view().cols[0].weight = sibling_weight * 2;
layout.compute(p);
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
@@ -1599,7 +1599,7 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" {
defer p.deinit();
const pane = p.panes[0].?;
const pv = pane.pdf.?;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
var page_hits = try pv.document.search(gpa, 0, "Pardes");
defer page_hits.deinit(gpa);
@@ -1634,8 +1634,8 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" {
// distinct fit-width crops. The search/reveal math must use the same
// reported metrics as placement, whatever a backend reports.
p.update(.{ .resize = .{
- .cols = p.screen_w,
- .rows = p.screen_h,
+ .cols = p.view().screen_w,
+ .rows = p.view().screen_h,
.cell_pixels = .{ .w = 16, .h = 4 },
} });
@@ -1709,7 +1709,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.page);
p.update(.{ .key = .{ .cp = 'k' } });
try std.testing.expectEqual(@as(usize, 0), pane.pdf.?.page);
- const fallback_rect = p.rects[0];
+ const fallback_rect = p.view().rects[0];
const fallback_col = fallback_rect.x + config.GUTTER + 1;
const fallback_row = fallback_rect.y + BOX_H + 1;
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = fallback_col, .row = fallback_row } });
@@ -1719,7 +1719,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expect(pane.pdf.?.selection == null);
pane.sel[sel_slot].state = .none;
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
const plain_revision = (try shownAll(p, frame.allocator()))[0].revision;
@@ -1757,9 +1757,9 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
const pixel_y = geometry.dst.y + @as(u32, @intCast(
@as(u64, source_y - geometry.src.y) * geometry.dst.h / geometry.src.h,
));
- const r = p.rects[0];
- const base_col: i32 = @intCast(r.x + config.GUTTER + pixel_x / p.cell_pixels.w);
- const base_row: i32 = @intCast(r.y + BOX_H + pixel_y / p.cell_pixels.h);
+ const r = p.view().rects[0];
+ const base_col: i32 = @intCast(r.x + config.GUTTER + pixel_x / p.view().cell_pixels.w);
+ const base_row: i32 = @intCast(r.y + BOX_H + pixel_y / p.view().cell_pixels.h);
var selected_col: ?u16 = null;
var selected_row: u16 = 0;
@@ -1807,7 +1807,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
// of a gesture rather than observation.
{
const delay = config.look_preview_delay_frames;
- const active_before = p.active;
+ const active_before = p.view().active;
const page_before = pv.page;
const scroll_before = pv.document_scroll_y;
const sels_before = pane.sel;
@@ -1823,9 +1823,9 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
const query_before = try gpa.dupe(u8, pv.search_query);
defer gpa.free(query_before);
const search_hit_before = pv.search_hit;
- const jumps_before = .{ p.jumps.n, p.jumps.cur, p.n_look_src };
+ const jumps_before = .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src };
const effects_before = p.effects_len;
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
const hover_motion = Event{ .mouse = .{
.button = .none,
@@ -1862,7 +1862,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
_ = try p.render(frame.allocator());
try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision != hovered_revision);
- try std.testing.expectEqual(active_before, p.active);
+ try std.testing.expectEqual(active_before, p.view().active);
try std.testing.expectEqual(page_before, pv.page);
try std.testing.expectEqual(scroll_before, pv.document_scroll_y);
try std.testing.expect(std.meta.eql(sels_before, pane.sel));
@@ -1875,9 +1875,9 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expect(std.meta.eql(selection_head_before, pv.selection_head));
try std.testing.expectEqualStrings(query_before, pv.search_query);
try std.testing.expectEqual(search_hit_before, pv.search_hit);
- try std.testing.expectEqual(jumps_before, .{ p.jumps.n, p.jumps.cur, p.n_look_src });
+ try std.testing.expectEqual(jumps_before, .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src });
try std.testing.expectEqual(effects_before, p.effects_len);
- try std.testing.expect(p.drag == .none);
+ try std.testing.expect(p.view().drag == .none);
}
// A native right-click resolves the same MuPDF-snapped word and feeds it
@@ -1928,16 +1928,16 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
panes.Pdf.toggleFit(pane); // restore the reading-width geometry
try std.testing.expect(pv.search_reveal_pending);
pv.search_reveal_pending = false;
- const original_cell_pixels = p.cell_pixels;
+ const original_cell_pixels = p.view().cell_pixels;
p.update(.{ .resize = .{
- .cols = p.screen_w,
- .rows = p.screen_h,
- .cell_pixels = p.cell_pixels,
+ .cols = p.view().screen_w,
+ .rows = p.view().screen_h,
+ .cell_pixels = p.view().cell_pixels,
} });
try std.testing.expect(!pv.search_reveal_pending);
p.update(.{ .resize = .{
- .cols = p.screen_w,
- .rows = p.screen_h,
+ .cols = p.view().screen_w,
+ .rows = p.view().screen_h,
.cell_pixels = .{
.w = original_cell_pixels.w,
.h = original_cell_pixels.h + 1,
@@ -1955,8 +1955,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
(try shownAll(p, frame.allocator()))[0].revision,
);
p.update(.{ .resize = .{
- .cols = p.screen_w,
- .rows = p.screen_h,
+ .cols = p.view().screen_w,
+ .rows = p.view().screen_h,
.cell_pixels = original_cell_pixels,
} });
_ = frame.reset(.retain_capacity);
@@ -2005,7 +2005,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
.col = drag_col,
.row = drag_row,
} });
- try std.testing.expect(p.drag.select.pdf.selection_changed);
+ try std.testing.expect(p.view().drag.select.pdf.selection_changed);
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
try std.testing.expectEqual(
@@ -2058,7 +2058,7 @@ test "Esc back into a PDF keeps the offset within its page" {
const p = try Pardes.init(gpa, .{ .file = path, .cols = 80, .rows = 28 });
defer p.deinit();
p.update(.{ .resize = .{ .cols = 80, .rows = 28 } });
- const doc = p.active;
+ const doc = p.view().active;
const dp = p.panes[doc].?;
try std.testing.expect(dp.pdf != null);
p.sync();
@@ -2070,12 +2070,12 @@ test "Esc back into a PDF keeps the offset within its page" {
pv.scroll_to_page_pending = false;
p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc
p.sync();
- const shell = p.active;
+ const shell = p.view().active;
try std.testing.expect(shell != doc);
p.update(.{ .key = .{ .cp = Key.escape } }); // Esc: back into the PDF
p.sync();
- try std.testing.expectEqual(doc, p.active);
+ try std.testing.expectEqual(doc, p.view().active);
// The jumps stack records a PDF as its PAGE, so returning revealed the page
// you were already on — and a reveal sets `document_scroll_y` to that page's
@@ -2090,20 +2090,20 @@ test "PDF Back and Forward clear selections and land on recorded pages" {
if (!pdf_enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .file = "docs/design.pdf", .cols = 80, .rows = 28 });
defer p.deinit();
- p.frontend.native_images = true;
+ p.view().frontend.native_images = true;
const pane = p.panes[0].?;
const state = pane.pdf.?;
try std.testing.expect(state.page_count > 1);
try std.testing.expect(state.focusLocation(p.pdf_gpa, 2, 0));
- p.jumps.n = 2;
- p.jumps.cur = 1;
- p.jumps.list[0] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 0 };
- p.jumps.list[1] = .{ .pane = 0, .serial = pane.serial, .line = 2, .col = 0 };
+ p.view().jumps.n = 2;
+ p.view().jumps.cur = 1;
+ p.view().jumps.list[0] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 0 };
+ p.view().jumps.list[1] = .{ .pane = 0, .serial = pane.serial, .line = 2, .col = 0 };
for ([_]u21{ 'o', 'i' }, 0..) |key, destination| {
try std.testing.expectEqual(panes.Pdf.SelectionUpdate.changed, state.setSelection(p.pdf_gpa, .{ .x = 0, .y = 0 }, .{ .x = 1, .y = 1 }, true));
try std.testing.expect(state.selection != null and state.selection_text.len > 0);
p.update(.{ .key = .{ .cp = key, .ctrl = true } });
- try std.testing.expectEqual(destination, p.jumps.cur);
+ try std.testing.expectEqual(destination, p.view().jumps.cur);
try std.testing.expectEqual(destination, state.page);
try std.testing.expect(state.selection == null);
try std.testing.expect(state.selection_page == null);
@@ -2167,18 +2167,18 @@ test "a PDF's jumps: Back after a far jump returns to the exact offset, two plac
if (!pdf_enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .file = jumpPdf(), .cols = 80, .rows = 28 });
defer p.deinit();
- p.frontend.native_images = true;
- const id = p.active;
+ p.view().frontend.native_images = true;
+ const id = p.view().active;
const pane = p.panes[id].?;
const pv = pane.pdf.?;
try jumpFrame(p);
try std.testing.expect(pv.page_count > 3);
// Two places on page 1, more than a body apart: two entries.
- const before = p.jumps.n;
+ const before = p.view().jumps.n;
_ = try stripAtPlace(p, pane, 1, 0.05);
const near = try stripAtPlace(p, pane, 1, 0.8);
- try std.testing.expectEqual(before + 2, p.jumps.n);
- try std.testing.expect(p.jumps.list[p.jumps.n - 1].pdf);
+ try std.testing.expectEqual(before + 2, p.view().jumps.n);
+ try std.testing.expect(p.view().jumps.list[p.view().jumps.n - 1].pdf);
// A far jump (a Look at a page), then Back: the exact offset, not the
// page's top, and its page.
look.lookAt(p, id, if (pv.page_count > 3000) ":3000" else ":4");
@@ -2189,12 +2189,12 @@ test "a PDF's jumps: Back after a far jump returns to the exact offset, two plac
try std.testing.expectEqual(@as(usize, 1), pv.page);
try std.testing.expectApproxEqAbs(near, pv.document_scroll_y, 0.5);
// A wheel's small steps are the same visit: the entry follows them.
- const n = p.jumps.n;
+ const n = p.view().jumps.n;
for (0..4) |_| {
_ = panes.Pdf.scrollPane(p, pane, 30, true);
try jumpFrame(p);
}
- try std.testing.expectEqual(n, p.jumps.n);
+ try std.testing.expectEqual(n, p.view().jumps.n);
}
test "a PDF's jumps keep to the PDF, and a closed PDF reopens at its place" {
@@ -2207,21 +2207,21 @@ test "a PDF's jumps keep to the PDF, and a closed PDF reopens at its place" {
const path = try std.fmt.bufPrint(&path_buf, "{s}/docs/design.pdf", .{cwd});
const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 80, .rows = 28 });
defer p.deinit();
- p.frontend.native_images = true;
- const doc = p.active;
+ p.view().frontend.native_images = true;
+ const doc = p.view().active;
const pane = p.panes[doc].?;
try jumpFrame(p);
const first = try stripAtPlace(p, pane, 1, 0.3);
// A text between, then a far place in the PDF.
look.lookAt(p, doc, "../build.zig:10");
try jumpFrame(p);
- try std.testing.expect(p.active != doc);
- p.active = doc;
+ try std.testing.expect(p.view().active != doc);
+ p.view().active = doc;
_ = try stripAtPlace(p, pane, 3, 0.5);
// Back from the PDF keeps to it: its own earlier place, not the text.
pardes.Jump.jumpBy(p, -1);
try jumpFrame(p);
- try std.testing.expectEqual(doc, p.active);
+ try std.testing.expectEqual(doc, p.view().active);
try std.testing.expectApproxEqAbs(first, pane.pdf.?.document_scroll_y, 0.5);
// Closed, its entries stay; Back from the text reopens it at the place.
pardes.Jump.jumpBy(p, 1);
@@ -2229,15 +2229,15 @@ test "a PDF's jumps keep to the PDF, and a closed PDF reopens at its place" {
try p.removePane(doc, null);
try jumpFrame(p);
var closed = false;
- for (p.jumps.list[0..p.jumps.n]) |j| closed = closed or (j.serial == 0 and j.pdf);
+ for (p.view().jumps.list[0..p.view().jumps.n]) |j| closed = closed or (j.serial == 0 and j.pdf);
try std.testing.expect(closed);
var tries: usize = 0;
while (tries < 4) : (tries += 1) {
pardes.Jump.jumpBy(p, -1);
try jumpFrame(p);
- if (p.panes[p.active].?.pdf != null) break;
+ if (p.panes[p.view().active].?.pdf != null) break;
}
- const reopened = p.panes[p.active].?;
+ const reopened = p.panes[p.view().active].?;
try std.testing.expect(reopened.pdf != null);
const pv = reopened.pdf.?;
// The newest PDF place before the text: page 4, half way down.
diff --git a/test/perf-baseline-gui-debug.json b/test/perf-baseline-gui-debug.json
index 0bf89243..4c687484 100644
--- a/test/perf-baseline-gui-debug.json
+++ b/test/perf-baseline-gui-debug.json
@@ -1 +1 @@
-{"harness":"4fb8a759a45cd6fa","build":{"compiler":"0.17.0","target":"x86_64-linux.5.10...7.2-gnu.2.38","cpu":"x86_64","driver_optimize":"fast","core_optimize":"debug","c_optimize":"fast","terminal_optimize":"safe","platform":"gui","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400}],"cells":[{"op":"open","fixture":"medium","min_us":2290,"med_us":2523,"p90_us":2642,"max_us":2642},{"op":"render","fixture":"medium","min_us":96,"med_us":97,"p90_us":99,"max_us":99},{"op":"key-down","fixture":"medium","min_us":104,"med_us":106,"p90_us":113,"max_us":113},{"op":"key-right","fixture":"medium","min_us":105,"med_us":107,"p90_us":111,"max_us":112},{"op":"page-down","fixture":"medium","min_us":104,"med_us":107,"p90_us":121,"max_us":125},{"op":"wheel","fixture":"medium","min_us":101,"med_us":104,"p90_us":105,"max_us":106},{"op":"edit-char","fixture":"medium","min_us":1023,"med_us":1293,"p90_us":1447,"max_us":1467},{"op":"edit-twin","fixture":"medium","min_us":1089,"med_us":1340,"p90_us":1418,"max_us":1441},{"op":"body-2m","fixture":"medium","min_us":5061,"med_us":8829,"p90_us":11118,"max_us":11667},{"op":"body-appends","fixture":"medium","min_us":149285,"med_us":210882,"p90_us":266047,"max_us":279235},{"op":"deep-sel","fixture":"medium","min_us":87,"med_us":90,"p90_us":96,"max_us":96}]}
+{"harness":"626d3244f10269ee","build":{"compiler":"0.17.0","target":"x86_64-linux.5.10...7.2-gnu.2.38","cpu":"x86_64","driver_optimize":"fast","core_optimize":"debug","c_optimize":"fast","terminal_optimize":"safe","platform":"gui","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400}],"cells":[{"op":"open","fixture":"medium","min_us":2290,"med_us":2523,"p90_us":2642,"max_us":2642},{"op":"render","fixture":"medium","min_us":96,"med_us":97,"p90_us":99,"max_us":99},{"op":"key-down","fixture":"medium","min_us":104,"med_us":106,"p90_us":113,"max_us":113},{"op":"key-right","fixture":"medium","min_us":105,"med_us":107,"p90_us":111,"max_us":112},{"op":"page-down","fixture":"medium","min_us":104,"med_us":107,"p90_us":121,"max_us":125},{"op":"wheel","fixture":"medium","min_us":101,"med_us":104,"p90_us":105,"max_us":106},{"op":"edit-char","fixture":"medium","min_us":1023,"med_us":1293,"p90_us":1447,"max_us":1467},{"op":"edit-twin","fixture":"medium","min_us":1089,"med_us":1340,"p90_us":1418,"max_us":1441},{"op":"body-2m","fixture":"medium","min_us":5061,"med_us":8829,"p90_us":11118,"max_us":11667},{"op":"body-appends","fixture":"medium","min_us":149285,"med_us":210882,"p90_us":266047,"max_us":279235},{"op":"deep-sel","fixture":"medium","min_us":87,"med_us":90,"p90_us":96,"max_us":96}]}
diff --git a/test/perf-baseline-tui-debug.json b/test/perf-baseline-tui-debug.json
index e98d37c2..66a2f2da 100644
--- a/test/perf-baseline-tui-debug.json
+++ b/test/perf-baseline-tui-debug.json
@@ -1 +1 @@
-{"harness":"4fb8a759a45cd6fa","build":{"compiler":"0.17.0","target":"x86_64-linux.5.10...7.2-gnu.2.38","cpu":"x86_64","driver_optimize":"fast","core_optimize":"debug","c_optimize":"fast","terminal_optimize":"safe","platform":"tui","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400}],"cells":[{"op":"open","fixture":"medium","min_us":1820,"med_us":2128,"p90_us":2500,"max_us":3046},{"op":"render","fixture":"medium","min_us":90,"med_us":96,"p90_us":98,"max_us":101},{"op":"key-down","fixture":"medium","min_us":101,"med_us":103,"p90_us":105,"max_us":114},{"op":"key-right","fixture":"medium","min_us":101,"med_us":103,"p90_us":106,"max_us":112},{"op":"page-down","fixture":"medium","min_us":97,"med_us":102,"p90_us":103,"max_us":105},{"op":"wheel","fixture":"medium","min_us":97,"med_us":102,"p90_us":112,"max_us":160},{"op":"edit-char","fixture":"medium","min_us":838,"med_us":899,"p90_us":1129,"max_us":1167},{"op":"edit-twin","fixture":"medium","min_us":869,"med_us":1099,"p90_us":1321,"max_us":1393},{"op":"body-2m","fixture":"medium","min_us":4820,"med_us":8314,"p90_us":11931,"max_us":12182},{"op":"body-appends","fixture":"medium","min_us":125039,"med_us":170714,"p90_us":213376,"max_us":232728},{"op":"deep-sel","fixture":"medium","min_us":90,"med_us":92,"p90_us":96,"max_us":101}]}
+{"harness":"626d3244f10269ee","build":{"compiler":"0.17.0","target":"x86_64-linux.5.10...7.2-gnu.2.38","cpu":"x86_64","driver_optimize":"fast","core_optimize":"debug","c_optimize":"fast","terminal_optimize":"safe","platform":"tui","grammars":"full","mupdf":true,"jpx":true,"tracy":false,"terminal_simd":true,"prebuilt_shaders":false},"cols":120,"rows":40,"reps":10,"only":"medium","fixtures":[{"name":"small","lines":1000,"cols":60,"bytes":62694},{"name":"medium","lines":50000,"cols":60,"bytes":3201944},{"name":"large","lines":300000,"cols":60,"bytes":19464444},{"name":"longline","lines":400,"cols":8000,"bytes":3200400}],"cells":[{"op":"open","fixture":"medium","min_us":1820,"med_us":2128,"p90_us":2500,"max_us":3046},{"op":"render","fixture":"medium","min_us":90,"med_us":96,"p90_us":98,"max_us":101},{"op":"key-down","fixture":"medium","min_us":101,"med_us":103,"p90_us":105,"max_us":114},{"op":"key-right","fixture":"medium","min_us":101,"med_us":103,"p90_us":106,"max_us":112},{"op":"page-down","fixture":"medium","min_us":97,"med_us":102,"p90_us":103,"max_us":105},{"op":"wheel","fixture":"medium","min_us":97,"med_us":102,"p90_us":112,"max_us":160},{"op":"edit-char","fixture":"medium","min_us":838,"med_us":899,"p90_us":1129,"max_us":1167},{"op":"edit-twin","fixture":"medium","min_us":869,"med_us":1099,"p90_us":1321,"max_us":1393},{"op":"body-2m","fixture":"medium","min_us":4820,"med_us":8314,"p90_us":11931,"max_us":12182},{"op":"body-appends","fixture":"medium","min_us":125039,"med_us":170714,"p90_us":213376,"max_us":232728},{"op":"deep-sel","fixture":"medium","min_us":90,"med_us":92,"p90_us":96,"max_us":101}]}
diff --git a/test/perf.zig b/test/perf.zig
index 55b64a99..fbe6fa49 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -564,13 +564,13 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
pardes.look.lookAt(core, 0, path);
pump(core);
const id = filePane(core) orelse return error.OpenDidNotOpenFile;
- core.active = id;
+ core.view().active = id;
const pane = core.panes[id].?;
_ = try frame(core);
if (op == .edit_twin) {
if (!core.executeBuiltinLine(id, "Zerox")) return error.ZeroxRefused;
pump(core);
- core.active = id;
+ core.view().active = id;
_ = try frame(core);
}
if (op == .edit_char or op == .edit_twin) {
@@ -589,7 +589,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
if (op != .deep_selection) seek(pane, fx, n);
_ = try frame(core); // settle the view at the new spot, untimed
const before = .{ .row = pane.body.cur_row, .col = pane.body.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len };
- const rect = core.rects[id];
+ const rect = core.view().rects[id];
const wheel_col = rect.x + pardes.config.GUTTER;
const wheel_row = rect.y + pardes.BOX_H;
const t0 = nowNs();
@@ -768,7 +768,7 @@ fn terminalBatch(buffer: []u8, batch: usize, cols: u16) ![]const u8 {
fn checkTerminalTail(core: *pardes.Pardes, surface: *pardes.Surface, batch: usize) !void {
const pane = core.panes[0] orelse return error.MissingTerminal;
- const rect = core.rects[0];
+ const rect = core.view().rects[0];
const x = rect.x + pardes.config.GUTTER;
const y = rect.y + pardes.BOX_H + pardes.panes.terminal.gridCursor(pane).y;
var expected_buffer: [32]u8 = undefined;
@@ -1486,9 +1486,9 @@ fn miniMeasurement(fallback: std.mem.Allocator, probe: MiniProbe, path: []const
if (core) |p| {
pump(p);
try pardes.panes.mini.open(p, 0, path);
- for (p.panes, 0..) |slot, id| if (slot != null and id != p.active) try p.removePane(id, null);
+ for (p.panes, 0..) |slot, id| if (slot != null and id != p.view().active) try p.removePane(id, null);
pump(p);
- const file = p.panes[p.active].?.file.?;
+ const file = p.panes[p.view().active].?.file.?;
try checkMini(.{ .content = file.content, .colors = file.mini.?.colors }, expected);
}
var frame_hash: ?u64 = null;
diff --git a/test/replicas.zig b/test/replicas.zig
index 338dae16..f50fb04f 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -274,7 +274,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
// Where a wheel over the shell lands in the session's view (the first
// client's); the others' views put it elsewhere, and their wheels hit
// whatever is there.
- const sr = a.core.rects[shell];
+ const sr = a.core.view().rects[shell];
const wheel_at: ?[2]u16 = if (sr.h > 2) .{ sr.x + sr.w / 2, sr.y + sr.h / 2 } else null;
// What the shell's program prints: a full-screen program, a shell's
diff --git a/test/session.zig b/test/session.zig
index 4919c0a3..db33d7b0 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -278,9 +278,9 @@ pub const Session = struct {
const p = pardesOf(s);
const gpa = p.gpa;
const name = p.takeRestore() orelse return;
- const bytes = pardes.dump.restoreBytes(p, gpa, name) catch |err| return p.reportError(p.active, "Restore", err);
+ const bytes = pardes.dump.restoreBytes(p, gpa, name) catch |err| return p.reportError(p.view().active, "Restore", err);
defer gpa.free(bytes);
- const nc = pardes.dump.restore(p, bytes, name) catch |err| return p.reportError(p.active, "Restore", err);
+ const nc = pardes.dump.restore(p, bytes, name) catch |err| return p.reportError(p.view().active, "Restore", err);
p.deinit();
s.core = nc;
s.drain();