diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 02:56:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 04:13:33 -0300 |
| commit | d1d5d3cfb18841604bba2057eeb3598f729b4475 (patch) | |
| tree | 298c29ab8767852bf74eb86ad4d15acc4348f109 /src/builtins.zig | |
| parent | 33037ece5af9ae1c7048819bbbae3fc5e6fc4ade (diff) | |
| download | pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.tar.gz pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 82 |
1 files changed, 41 insertions, 41 deletions
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; |
