summaryrefslogtreecommitdiff
path: root/core/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 22:06:32 -0300
committerGabriel Schneider <[email protected]>2026-11-20 00:38:51 -0300
commit2662a45ac245e574987bf6876f4470aed89da09c (patch)
treec582032cde0cb742a67e2dd548022f7b83f8d1fd /core/panes.zig
parentba10cc4ff30d08d27ad35576df04a03282b6521b (diff)
downloadpardes-2662a45ac245e574987bf6876f4470aed89da09c.tar.gz
pardes-2662a45ac245e574987bf6876f4470aed89da09c.zip
replica: the bytes kind of replica made right and joinable (P29, P32; the brief's step 2: 2a, 2b, 2c and 2d in one change): the one rule in place of two, the faults shown first (a session's output kept over a copy held ahead was fed again by a rollback: the digests apart; the pages an emulator gained while a copy was held were the epoch's and freed with it: a crash in PageList.increaseCapacity in the rollback's replay): every replica's emulators on the C heap (panes.emulatorGpa), Term.writes counting the writes into emulators, a unit whose replay wrote one never kept over a copy taken ahead, never taken as moving nothing (tape.feedsTerminal), a client's input that owed a reflow always replayed when confirmed; a speculation moves a terminal's view under bytes as under screen state; tape.unit_max (1 MiB) and Tape.cut, which the session's Peers sets, so a pump's reads are cut into units under it; the join: whole terminals in a joiner's dump, every replica the session included reloading each live terminal in the step that opens or reopens a view (panes.reloadTerminals), the session's hash taped (Site.reload) and compared, kitty records left out of it, the cell pixels set first as a feed does; .positions and .prompt compared with the replica's own emulator on replay; replicas load kitty images by direct data only (Term.direct); Peers.bytes for the soak; six tests (core/replica.zig, bytes:); tui core-test 848/997 (149 skipped), shell-test 1033/1036, pane-test 183/184, term-test 17/17, kitty-test 45/45, behaviour-test 275/275 and --replay 0, process-test 2 of 144 (the base's), image- and kitty-harness pass, unit-test bytes: 22/22; gui unit-test 1633/1637 (the perf check's BaselineHarnessMismatch); the soaks in klrvlrly's
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/panes.zig')
-rw-r--r--core/panes.zig44
1 files changed, 36 insertions, 8 deletions
diff --git a/core/panes.zig b/core/panes.zig
index 56a8e82a..61c57541 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -966,15 +966,17 @@ pub const Pane = struct {
/// replica by its authority (the next delta says), on such an authority
/// once the step's unit is out (`resizeDeferred`).
pub fn resizeGrid(pane: *Pane, cols: u16, rows: u16) void {
- // A screen-state client's speculation does what its replay does
- // (its selections, never the grid): it waits for no round trip.
- if (!tape.screenState() and tape.authorityOnly("resize a terminal")) return;
+ // A client's speculation does what its replay does (its
+ // selections) but the grid: it waits for no round trip. Under bytes
+ // it owes the grid (`touchTerminal`): its input is replayed when
+ // confirmed, never taken as speculated (replica.zig `confirm`).
const state = pane.terminal orelse return;
if (cols != pane.cols) for (0..pane.sel.len) |button| {
pane.clearPointerSelection(button);
pane.sel[button].state = .none;
};
if (tape.screenReplica()) return;
+ if (tape.speculating()) return tape.touchTerminal();
// A client typing at another size than the last typist's read
// history rows its replay held as holes, and the rows came
// renumbered (2026-10-30): the authority's waits for the unit.
@@ -1117,6 +1119,31 @@ pub const Term = @import("Term.zig");
/// not follow the output (no memory for its pin), so it was reset.
pub const positions_lost = "terminal edit position reset: out of memory";
+/// At a join (Core's openView, rejoinView): under bytes, every live
+/// terminal made again from its own snapshot, on every side alike, the
+/// session included (Term.reload): an emulator loaded from a snapshot holds
+/// its rows in other pages than one fed from its start, and ghostty prunes
+/// its history a page at a time, so the joiner, loaded from the session's
+/// dump made next, and the replicas there before it, would part. The
+/// session's snapshot's hash is taped, and each replica's own compared
+/// with it: a check of the whole emulator at every join.
+pub fn reloadTerminals(p: *Pardes) void {
+ if (tape.screenState()) return;
+ for (p.panes) |slot| if (slot) |pane| if (pane.terminal) |state| {
+ // Its cells' size in pixels as a feed sets it (`feedOutput`): a
+ // frontend's draw sets its own view's between steps (ansi.zig), a
+ // window's other than a terminal's, and the snapshot holds it.
+ Term.cellPixels(state, p.view().cell_pixels.w, p.view().cell_pixels.h);
+ const mine: ?u64 = Term.reload(state) catch null;
+ p.shell_rows.markStale(pane);
+ if (tape.value(.reload, sameHash, .{mine}) != mine) tape.diverged("a terminal reloaded at a join is not the session's");
+ };
+}
+
+fn sameHash(h: ?u64) ?u64 {
+ return h;
+}
+
/// The sizes steps gave terminals (`Pane.resizeGrid`), made: between
/// units, on an authority with screen-state replicas (replica.Peers.unit).
pub fn resizeDeferred(p: *Pardes) void {
@@ -1147,16 +1174,17 @@ pub fn createTerminal(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
return pane;
}
-/// A screen-state replica's emulators' allocator (`Term.State.gpa`): the C
-/// heap, outside its rollback epoch: written by deltas while a copy is
-/// held, no part of it is ever a copy's to save or put back.
+/// A replica's emulators' allocator (`Term.State.gpa`): the C heap,
+/// outside its rollback epoch: written (by the session's bytes or deltas)
+/// while a copy is held, no part of it is ever a copy's to save or put
+/// back, or the pages an emulator gains then are freed with the copy.
pub const emulator_gpa = std.heap.c_allocator;
/// What a terminal's emulator is made with, by `createTerminal` or a pane's
/// load (dump.loadPane, a closed terminal brought back): `gpa`, but on a
-/// screen-state replica `emulator_gpa`.
+/// replica `emulator_gpa`.
pub fn emulatorGpa(gpa: std.mem.Allocator) std.mem.Allocator {
- return if (tape.screenReplica()) emulator_gpa else gpa;
+ return if (tape.replaying()) emulator_gpa else gpa;
}
// ---- the session's pane slots: making, finding, closing and freeing panes, and their prompts ----