From d1d5d3cfb18841604bba2057eeb3598f729b4475 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 02:56:53 -0300 Subject: client #1, the views indexed: a view's share of the session is Pardes.View (the ~42 fields views.fields named: size, cell metrics, columns, rects, focus, jumps, pointer, gestures, prefixes, frontend), one of Pardes.views[4] (null when closed), the live one views[live] through Pardes.view() (index field `view` renamed `live`); going into another view is the index plus the panes' shares, which stay swapped (park and unpark now move only Pane.pv); views.zig loses fields, Part over Pardes, Parked, kept, emptied and the session half of every copy, and a pane closing leaves every view's layout at once (views.gone, at the two places a slot is freed) instead of the serials each parked view kept; drawOne and within put the drawn view's own share back whole; the views are in the digest now (tape's per-field parts name views[k].field), so a fresh view's col_x/col_w default to zeros, not undefined; the dump keeps every open view in the core and the panes' shares of the others under `shares`; an image from before (live view as the core's own fields, the rest under `views`) loads them into views[] once; the ~2,400 references rewritten mechanically from the compiler's errors (p.active is p.view().active, `const v = p.view()` hoisted in 823 places), Kind.zig (4 lines) and addon_test.zig (3) among them, macos.zig by pattern (not compiled here); tape's watched host writes read the live view's frontend and active; perf.zig's accessor lines change its harness hash, the debug baselines re-keyed to it (their numbers the base's); no golden changes; gates: core-test 956/956 both, unit-test 1487/1488 tui and 1530/1531 gui, behaviour-test 248/248 both, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed tui, replicas ok Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/keys.zig | 196 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 99 insertions(+), 97 deletions(-) (limited to 'src/keys.zig') 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 /// `; 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); -- cgit v1.3