From 5354090b6122faf0d18e246a55e8a4ead0955394 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:17:45 -0300 Subject: Term: output and view through the interface: Term.feed takes one read and the rows the core keeps positions on and gives back a Term.Told (where each went, erased or not, cleared, alive, a pin missed), Term.grid is the plain record of the view and the cursor (total, offset, len, the cursor, whether it shows, the view's row or null while it follows), Term.scroll, Term.follow, Term.viewTo, Term.resize (now or for later) and Term.resizeDeferred move it, Term.cellPixels sizes its cells in pixels and Term.replies hands over what it answered its program; the core's half is the core's: Pane.feedOutput and its row tracking (the edit copy's rows, the cursors and selections, their undo and the pointer's rows, gathered as rows and moved as the feed told, ingestWithPositions's core) and Pane.followOutput, Pane.resizeGrid and Pane.panFor in panes.zig with panes.resizeDeferred, the cursor a program shows read from the grid where the body draws it, tape.viewOnly beside tape.authorityOnly; scrollbar, gridOffset, gridCursor, visibleCursor, viewOf, atBottom and their types go; nothing else changes --- src/replica.zig | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/replica.zig') diff --git a/src/replica.zig b/src/replica.zig index 635ada75..9a2c80a7 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -673,7 +673,7 @@ pub const Replica = struct { /// Its terminals' screen state, as the authority's deltas made it. screens: [pardes.MAX_PANES]?ScreenOf = @splat(null), - /// Each terminal's view (`terminal.viewOf`) as the copy was taken, or + /// Each terminal's view (`Term.grid`'s view) as the copy was taken, or /// as the last delta since set it: the copy holds no emulator, and a /// speculation may move a view, so a rollback puts these back. views: [pardes.MAX_PANES]View = @splat(.{}), @@ -1090,12 +1090,12 @@ pub const Replica = struct { fn keepViews(r: *Replica) void { if (!r.t.screen_state) return; - for (r.core().panes, &r.views) |slot, *v| v.* = .{ .at = if (slot) |pane| terminal.viewOf(pane) else null }; + for (r.core().panes, &r.views) |slot, *v| v.* = .{ .at = if (slot) |pane| if (pane.terminal) |state| pardes.Term.grid(state).view else null else null }; } fn putViews(r: *Replica, after: usize) void { if (!r.t.screen_state) return; - for (r.core().panes, r.views) |slot, v| if (v.after == after) if (slot) |pane| if (pane.terminal != null) terminal.viewTo(pane, v.at); + for (r.core().panes, r.views) |slot, v| if (v.after == after) if (slot) |pane| if (pane.terminal) |state| pardes.Term.viewTo(state, v.at); } /// Whether its core loaded from the dump is the session as it was @@ -1182,7 +1182,7 @@ pub const Replica = struct { c.shell_rows.markStale(pane); // Its view is the authority's now: a rollback puts it back // here, and what was applied over a terminal goes on top. - if (r.copy.held) r.views[m.pane] = .{ .at = terminal.viewOf(pane), .after = r.since.items.len }; + if (r.copy.held) r.views[m.pane] = .{ .at = if (pane.terminal) |held| pardes.Term.grid(held).view else null, .after = r.since.items.len }; r.overTerminals(); var seq: [4]u8 = undefined; std.mem.writeInt(u32, &seq, applied.seq, .little); @@ -1903,7 +1903,7 @@ pub const Peers = struct { for (ps.list) |slot| if (slot) |peer| peer.send(&.{ &head, &ps.head, bytes }); ps.t.buf.clearRetainingCapacity(); // The sizes its steps gave terminals, now: the next flush says so. - if (ps.t.core) |core| terminal.resizeDeferred(core); + if (ps.t.core) |core| pardes.panes.resizeDeferred(core); } /// After each of the session's pumps: its unit sent, the clients that @@ -2219,7 +2219,7 @@ pub const Peers = struct { fn stop(ps: *Peers, core: *Pardes) void { if (!ps.recording) return; - terminal.resizeDeferred(core); + pardes.panes.resizeDeferred(core); ps.screens.deinit(core); if (core.host.vtable == &ps.t.vtable) core.host = ps.t.real; tape.on = null; @@ -3093,7 +3093,7 @@ fn key(r: *Replica, cp: u21, sent: *std.ArrayListUnmanaged([]u8)) !void { /// What the session sends a peer: its terminals' changes (`.flush`), or, /// around a step's unit (Peers.input), the rows the step read that the /// peer lacks (`.fill`), after which the caller gives terminals the sizes -/// the step gave them (`terminal.resizeDeferred`), then the unit. +/// the step gave them (`panes.resizeDeferred`), then the unit. fn deliver(a: *Authority, screens: *Screens, peer: u16, r: *Replica, comptime what: enum { flush, fill }) !void { const gpa = std.testing.allocator; var msgs: std.ArrayListUnmanaged([]u8) = .empty; @@ -3583,7 +3583,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, const u = try std.testing.allocator.dupe(u8, try au.take(msg)); defer std.testing.allocator.free(u); try deliver(au, sc, pe, rr, .fill); - terminal.resizeDeferred(au.core); + pardes.panes.resizeDeferred(au.core); rr.confirm(u); rr.settle(); } @@ -3609,7 +3609,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, const back = try gpa.dupe(u8, try a.unit(0, a.seq)); defer gpa.free(back); try deliver(a, &screens, peer, r, .fill); - terminal.resizeDeferred(a.core); + pardes.panes.resizeDeferred(a.core); r.confirm(back); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -3656,7 +3656,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); try std.testing.expectEqual(sent.items.len, r.applied); const here = r.core().panes[shell].?; - try std.testing.expect(terminal.viewOf(here) != null); + try std.testing.expect(pardes.Term.grid(here.terminal).view != null); // The shell prints while they wait: its unit, then its delta, which // sets the view the authority's (at the bottom still): what was applied // goes on top of it again. @@ -3666,7 +3666,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves try deliver(a, &screens, peer, r, .flush); r.settle(); try std.testing.expectEqual(sent.items.len, r.applied); - try std.testing.expect(terminal.viewOf(r.core().panes[shell].?) != null); + try std.testing.expect(pardes.Term.grid(r.core().panes[shell].?.terminal).view != null); // The authority takes them in order, the terminal sent before each and // the rows its step read after, as the session's loop does. for (sent.items) |m| { @@ -3684,19 +3684,19 @@ test "pardes's own keys over a terminal's history apply at once: its view moves try std.testing.expect(r.diverged == null and r.quiet()); try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); try std.testing.expectEqual(digestOf(a), r.digest()); - try std.testing.expect(terminal.viewOf(a.core.panes[shell].?) != null); - try std.testing.expectEqual(terminal.viewOf(a.core.panes[shell].?), terminal.viewOf(r.core().panes[shell].?)); + try std.testing.expect(pardes.Term.grid(a.core.panes[shell].?.terminal).view != null); + try std.testing.expectEqual(pardes.Term.grid(a.core.panes[shell].?.terminal).view, pardes.Term.grid(r.core().panes[shell].?.terminal).view); // A rollback with nothing confirmed on top puts the view back: one more // key up, and another's unit first. try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = 'u', .ctrl = true } }))); - const before = terminal.viewOf(a.core.panes[shell].?); - try std.testing.expect(terminal.viewOf(r.core().panes[shell].?).? < before.?); + const before = pardes.Term.grid(a.core.panes[shell].?.terminal).view; + try std.testing.expect(pardes.Term.grid(r.core().panes[shell].?.terminal).view.? < before.?); r.confirm(try a.local(.{ .focus = false })); r.settle(); const last = try gpa.dupe(u8, try a.take(sent.items[sent.items.len - 1])); defer gpa.free(last); r.toConfirmed(); - try std.testing.expectEqual(before, terminal.viewOf(r.core().panes[shell].?)); + try std.testing.expectEqual(before, pardes.Term.grid(r.core().panes[shell].?.terminal).view); r.dirty = true; r.settle(); try deliver(a, &screens, peer, r, .fill); @@ -3707,7 +3707,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); try std.testing.expect(r.diverged == null and r.quiet()); try std.testing.expectEqual(digestOf(a), r.digest()); - try std.testing.expectEqual(terminal.viewOf(a.core.panes[shell].?), terminal.viewOf(r.core().panes[shell].?)); + try std.testing.expectEqual(pardes.Term.grid(a.core.panes[shell].?.terminal).view, pardes.Term.grid(r.core().panes[shell].?.terminal).view); } test "a replica joined from the session's dump replays the units after it" { -- cgit v1.3