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 /test/column_drag.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 'test/column_drag.zig')
| -rw-r--r-- | test/column_drag.zig | 177 |
1 files changed, 89 insertions, 88 deletions
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)); } |
