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/Handover.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/Handover.zig')
| -rw-r--r-- | src/Handover.zig | 133 |
1 files changed, 68 insertions, 65 deletions
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); } |
