diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 20:31:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 20:31:32 -0300 |
| commit | 0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (patch) | |
| tree | f2e288668decded9276ebc45907f16d651b06f9e /core/views.zig | |
| parent | 2ab05b536bc3b063666b5aaab497157adc2a9120 (diff) | |
| parent | bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (diff) | |
| download | pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.tar.gz pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.zip | |
integration: a pane's and a view's slot as types, with the regular-expression fixes and the fixes the real loops asked for: pardes-ids (Pane.Id and View.Id through the entries, the events, the effects, the Host table and the device messages) and pardes-merge21, merged without a textual conflict; one call site written since on the old type follows (core/draw.zig: the twin test's file_changed event, .pane = .at(0)); tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/views.zig')
| -rw-r--r-- | core/views.zig | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/core/views.zig b/core/views.zig index 9d627a17..9985288d 100644 --- a/core/views.zig +++ b/core/views.zig @@ -579,25 +579,25 @@ test "each view has its own cursor and scroll, and an edit in one is in the othe const text = try numbered(gpa, 200); defer gpa.free(text); const pane = try p.setTestFile(text); - try testing.expectEqual(@as(?u8, 1), p.openView()); + try testing.expectEqual(@as(?View.Id, .at(1)), p.openView()); cursorTo(p, pane, 119); const scrolled = pane.file.?.scroll; try testing.expect(scrolled > 0); // The other view is where the session was when it came. - p.toView(1); + p.toView(.at(1)); try testing.expectEqual(@as(i32, 0), pane.body.cur_row); try testing.expectEqual(@as(usize, 0), pane.file.?.scroll); typeKeys(p, "ix"); escape(p); try testing.expectEqual(Text.Mode.normal, pane.body.mode); - p.toView(0); + p.toView(.at(0)); try testing.expectEqual(@as(i32, 119), pane.body.cur_row); try testing.expectEqual(scrolled, pane.file.?.scroll); try testing.expect(std.mem.startsWith(u8, pane.file.?.content, "xline 1\n")); // Its mode is its own: insert here leaves the other in normal. typeKeys(p, "i"); try testing.expectEqual(Text.Mode.insert, pane.body.mode); - p.toView(1); + p.toView(.at(1)); try testing.expectEqual(Text.Mode.normal, pane.body.mode); } @@ -614,7 +614,7 @@ test "each view has its own layout and focus over the same panes" { const made = p.view().active; try testing.expect(made != 0); try testing.expectEqual(ncol + 1, p.view().ncol); - p.toView(0); + p.toView(.at(0)); try testing.expectEqual(ncol, p.view().ncol); try testing.expectEqual(@as(usize, 0), p.view().active); try testing.expect(layout.findPane(p, made) == null); @@ -663,15 +663,15 @@ test "a terminal shown at two sizes takes the size of the view that typed into i p.update(.{ .key = .{ .cp = Key.right } }); try testing.expect(term.cols > small[0] and term.rows > small[1]); const big = .{ term.cols, term.rows }; - p.toView(0); + p.toView(.at(0)); p.sync(); try testing.expectEqual(big, .{ term.cols, term.rows }); p.update(.{ .key = .{ .cp = Key.right } }); try testing.expectEqual(small, .{ term.cols, term.rows }); // That view gone, the one left sizes it. p.toView(k); - p.closeView(0); - try testing.expectEqual(k, p.live); + p.closeView(.at(0)); + try testing.expectEqual(k.index(), p.live); try testing.expectEqual(big, .{ term.cols, term.rows }); } @@ -691,18 +691,18 @@ test "a view closing leaves the others as they were" { typeKeys(p, "xy"); p.toView(a); cursorTo(p, pane, 70); - p.toView(0); + p.toView(.at(0)); cursorTo(p, pane, 10); const ncol = p.view().ncol; // The live one closing: the session goes into another. p.toView(b); p.closeView(b); - try testing.expect(p.live != b); + try testing.expect(p.live != b.index()); try testing.expectEqual(@as(usize, 2), count(p)); p.toView(a); try testing.expectEqual(@as(i32, 70), pane.body.cur_row); - p.closeView(0); - try testing.expectEqual(a, p.live); + p.closeView(.at(0)); + try testing.expectEqual(a.index(), p.live); try testing.expectEqual(ncol, p.view().ncol); // The last stays. p.closeView(a); @@ -749,7 +749,7 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien defer p.deinit(); _ = try p.setTestFile("one\ntwo\n"); // Two clients, each a pane of its own in its own view. - const ks: [2]u8 = .{ p.openView().?, p.openView().? }; + const ks: [2]View.Id = .{ p.openView().?, p.openView().? }; var made: [2]usize = undefined; for (ks, &made) |k, *m| { p.toView(k); @@ -767,7 +767,7 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien const q = try pardes.dump.load(gpa, opts, bytes, null); defer q.deinit(); for (ks, made, 0..) |k, m, i| { - try testing.expect(isAway(q, k)); + try testing.expect(isAway(q, k.index())); try testing.expect(q.rejoinView(k)); q.toView(k); try testing.expectEqual(m, q.view().active); @@ -776,10 +776,10 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien } try testing.expect(!q.rejoinView(ks[0])); // A client that never comes back: its view goes when a join has no room. - p.toView(0); - try testing.expectEqual(@as(?u8, 3), p.openView()); + p.toView(.at(0)); + try testing.expectEqual(@as(?View.Id, .at(3)), p.openView()); try testing.expectEqual(ks[0], p.openView()); - try testing.expect(!isAway(p, ks[0]) and isAway(p, ks[1])); + try testing.expect(!isAway(p, ks[0].index()) and isAway(p, ks[1].index())); } test "drawing another view leaves the live one as it was, to the digest" { @@ -793,10 +793,10 @@ test "drawing another view leaves the live one as it was, to the digest" { p.toView(k); cursorTo(p, pane, 60); typeKeys(p, "dd"); - p.toView(0); + p.toView(.at(0)); cursorTo(p, pane, 95); const before = pardes.walk.digest(Pardes, p); - _ = try drawOne(p, k, .{ .ctx = null, .f = null }); + _ = try drawOne(p, k.index(), .{ .ctx = null, .f = null }); try testing.expectEqual(@as(u8, 0), p.live); try testing.expectEqual(before, pardes.walk.digest(Pardes, p)); p.toView(k); @@ -812,9 +812,9 @@ test "a view drawn while another is live keeps its own cursors" { p.toView(k); p.update(.{ .key = .{ .cp = 'C', .text = "C" } }); try testing.expectEqual(@as(u16, 1), pane.body.nsel); - p.toView(0); + p.toView(.at(0)); const before = pardes.walk.digest(Pardes, p); - _ = try drawOne(p, k, .{ .ctx = null, .f = null }); + _ = try drawOne(p, k.index(), .{ .ctx = null, .f = null }); try testing.expectEqual(before, pardes.walk.digest(Pardes, p)); p.toView(k); try testing.expectEqual(@as(u16, 1), pane.body.nsel); @@ -831,7 +831,7 @@ test "a view not live keeps its place in a text another view edits" { p.toView(k); cursorTo(p, pane, 100); const scrolled = pane.file.?.scroll; - p.toView(0); + p.toView(.at(0)); // Three lines put above it, one taken below it. typeKeys(p, "xyppp"); cursorTo(p, pane, 150); @@ -859,10 +859,10 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" { defer out.deinit(gpa); for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i}); try out.appendSlice(gpa, "LAST$ "); - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = out.items } }); // Sized for the tall view, it fits there whole: nothing is passed over. try testing.expectEqual(@as(u16, 0), term.pan); - p.toView(0); + p.toView(.at(0)); p.sync(); try testing.expectEqual(rows, term.rows); try testing.expect(term.pan > 0); @@ -897,7 +897,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o cursorTo(p, pane, 119); p.toView(k); p.update(.{ .command = "Newcol" }); - p.toView(0); + p.toView(.at(0)); p.toView(k); cursorTo(p, pane, 30); const ncol = p.view().ncol; @@ -910,7 +910,7 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o defer gpa.free(again); try testing.expectEqualSlices(u8, bytes, again); const lp = loaded.panes[id].?; - loaded.toView(0); + loaded.toView(.at(0)); try testing.expectEqual(@as(i32, 119), lp.body.cur_row); try testing.expectEqual(ncol - 1, loaded.view().ncol); loaded.toView(k); @@ -923,5 +923,21 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o try testing.expectEqual(@as(u8, 0), one.live); try testing.expectEqual(ncol, one.view().ncol); try testing.expectEqual(@as(i32, 30), one.panes[id].?.body.cur_row); - try testing.expectEqual(@as(?u8, 1), one.openView()); + try testing.expectEqual(@as(?View.Id, .at(1)), one.openView()); +} + +test "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" { + // An enum coerces into nothing but itself (an enum literal into it, it + // into a union of it): two distinct enum types never stand for each + // other, so `p.toView(pane_id)` or `p.setMessage(view_id, ..)` does not + // compile. What is left to show is that they are two, and a byte each. + comptime { + std.debug.assert(Pane.Id != View.Id); + for (.{ Pane.Id, View.Id }) |T| { + const e = @typeInfo(T).@"enum"; + std.debug.assert(e.tag_type == u8 and e.mode == .nonexhaustive and @sizeOf(T) == 1); + } + } + for (0..MAX_PANES) |i| try testing.expectEqual(i, Pane.Id.at(i).index()); + for (0..max) |k| try testing.expectEqual(k, View.Id.at(k).index()); } |
