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/panes.zig | 65 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'src/panes.zig') 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 } }); -- cgit v1.3