summaryrefslogtreecommitdiff
path: root/abi/term.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 16:50:34 -0300
committerGabriel Schneider <[email protected]>2026-11-22 16:53:19 -0300
commit9863a63b614d200852853825031189364dcacfdc (patch)
treed235648a2ac14b3e311746ced3433ed6865e2061 /abi/term.zig
parent6544f73a6b50e5ba68564beea7784593bb54348e (diff)
parentbad506bd45846e012246a33b5d3097b3e92f02bc (diff)
downloadpardes-9863a63b614d200852853825031189364dcacfdc.tar.gz
pardes-9863a63b614d200852853825031189364dcacfdc.zip
integration: the old road deleted and the emulator's boundary on the gathered line: pardes-merge56 (`qvwrwxtu`: the installed tree and the source view's changes to their last slice) and pardes-term-join-9 (`twssqzqw`, fourteen changes on pardes-merge55: every client's terminals by the pty's bytes and nothing else: the delta protocol, its flow control and core/term/screen_state.zig deleted (-3,605 +504 lines), the wire at 30, one soak; S1: abi/term.zig's Ops in replicated and local, the terminal's digest covering what a step reads, every call of the core's into a terminal listed with its rule as a test; a client's own join again judged after its goodbye; a pty's size one fact the core hands its host for every fork, adopt and resize; a closed view sizes no terminal); no textual conflict; one semantic one, resolved here: core/jj.zig's Churn test (the layers' last round) called Authority.init and Replica.init with the road's flag the deletion took away: the argument removed; core-test 916/1073 (157 skipped), shell-test 1115/1118; its gate: .scratch/sketch/reorg/merge57, the numbers in PARDES.md (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'abi/term.zig')
-rw-r--r--abi/term.zig114
1 files changed, 34 insertions, 80 deletions
diff --git a/abi/term.zig b/abi/term.zig
index 187b99e5..d6c48f96 100644
--- a/abi/term.zig
+++ b/abi/term.zig
@@ -1,8 +1,8 @@
//! The terminal as the core sees it (docs/next-terminal.md, Phase 1): the
//! entries (`Ops`) a terminal module gives the core, and the records they
-//! take and give. A terminal's state, its replicas' encoder and tracks are
-//! handles the core holds and never looks into; what it knows of them it is
-//! told here, as numbers, bytes, text and cells. core/term/term.zig is the
+//! take and give. A terminal's state is a handle the core holds and never
+//! looks into; what it knows of it it is told here, as numbers, bytes, text
+//! and cells. core/term/term.zig is the
//! one implementation (ghostty-vt behind it); core/Term.zig is the core's
//! side of it.
const std = @import("std");
@@ -12,12 +12,6 @@ const CellStyle = plain.CellStyle;
/// A terminal: its emulator, its parse and what is kept beside it.
pub const State = opaque {};
-/// What a session's authority keeps to encode its terminals for its peers
-/// (one for all of them), and what it keeps of one terminal for them.
-pub const Encoder = opaque {};
-pub const Track = opaque {};
-/// A replica's side of one terminal: what it was sent.
-pub const Replica = opaque {};
/// Where the view and the cursor are, in rows counted from the top of the
/// history: `total` rows, the view's top at `offset`, `len` of them shown.
@@ -35,7 +29,7 @@ pub const Grid = struct {
/// The view's top row while it is scrolled to one, null while it
/// follows the output.
view: ?usize = null,
- /// Its grid's width (a pane's may differ while a resize is deferred).
+ /// Its grid's width.
cols: u16 = 0,
};
@@ -240,50 +234,6 @@ pub const ImagesAt = struct {
/// marked it input, and its style's identity.
pub const EchoCell = struct { cp: u21, input: bool, style: u32 };
-// ---- its replicas ----
-
-/// Deltas a peer may have in flight. At 207 ms and 60 frames a second about
-/// 13 are; past the bound a peer gets nothing until an acknowledgement, and
-/// then the newest state, the ones between skipped.
-pub const flight_bound = 32;
-
-/// What the authority knows of one peer of one terminal.
-pub const Peer = struct {
- /// The version last sent, which the next delta is against; 0: none, so
- /// the next starts the replica afresh.
- sent: u32 = 0,
- /// The versions in flight, oldest first.
- flight: [flight_bound]u32 = undefined,
- n: u8 = 0,
- /// The history rows its replica holds as holes, absolute, as the
- /// replica keeps them (Replica.apply's rule, from what it was sent):
- /// what `fill` sends before a step reads them.
- top: u64 = 0,
- holes: std.ArrayListUnmanaged([2]u64) = .empty,
-
- pub fn deinit(peer: *Peer, gpa: std.mem.Allocator) void {
- peer.holes.deinit(gpa);
- }
-
- /// Every version up to `seq` has landed.
- pub fn ack(peer: *Peer, seq: u32) void {
- var i: u8 = 0;
- while (i < peer.n and peer.flight[i] <= seq) i += 1;
- std.mem.copyForwards(u32, peer.flight[0 .. peer.n - i], peer.flight[i..peer.n]);
- peer.n -= i;
- }
-
- /// Start the peer afresh: it lost its state, or never had one.
- pub fn reset(peer: *Peer) void {
- var holes = peer.holes;
- holes.clearRetainingCapacity();
- peer.* = .{ .holes = holes };
- }
-};
-
-/// A delta applied: its version, and what its authority sent beside it.
-pub const Applied = struct { seq: u32, extra: []const u8 };
-
/// What the dump keeps of a terminal beside its emulator, by name as every
/// dump is (core/walk.zig, through the core's `Term.State`).
pub const Parts = struct {
@@ -368,8 +318,7 @@ pub const Ops = struct {
viewTo: *const fn (s: *State, at: ?usize) void,
scroll: *const fn (s: *State, delta: i32) void,
follow: *const fn (s: *State) void,
- resize: *const fn (s: *State, cols: u16, rows: u16, later: bool) void,
- resizeDeferred: *const fn (s: *State) bool,
+ resize: *const fn (s: *State, cols: u16, rows: u16) void,
cellPixels: *const fn (s: *State, w: u32, h: u32) void,
replies: *const fn (s: *State) []const u8,
@@ -397,7 +346,6 @@ pub const Ops = struct {
/// How much of its row `row` (from the top of its history) the prompt
/// it starts with is; null for a row no prompt starts.
promptCut: *const fn (s: *State, row: i32) ?PromptCut,
- markRead: *const fn (s: *State) void,
/// What a predicted echo reads of cell `x`, `y` of its active area.
echoCell: *const fn (s: *const State, x: u16, y: u16) ?EchoCell,
@@ -419,28 +367,34 @@ pub const Ops = struct {
/// placeholder cells blanked in `frame` (`frame_cols` wide).
images: *const fn (s: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.ArrayList(plain.Placement), frame: []plain.Cell, frame_cols: u16) void,
hasImages: *const fn (s: ?*const State) bool,
+};
- // ---- its replicas ----
- encoder: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Encoder,
- encoderFree: *const fn (e: *Encoder) void,
- track: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Track,
- /// A peer's track of it let go (`s` null: it is gone).
- untrack: *const fn (t: *Track, gpa: std.mem.Allocator, s: ?*State) void,
- /// What a peer is owed of it, a delta against what the peer was sent.
- encode: *const fn (s: *State, e: *Encoder, t: *Track, peer: *Peer, out: *std.Io.Writer) anyerror!bool,
- /// Rows of it a replica holds as holes.
- encodeRows: *const fn (s: *State, e: *Encoder, t: *Track, lo: u64, hi: u64, out: *std.Io.Writer) anyerror!void,
- wasRead: *const fn (s: *const State) bool,
- clearRead: *const fn (s: *State) void,
- replica: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Replica,
- replicaFree: *const fn (r: *Replica, gpa: std.mem.Allocator) void,
- /// The absolute row its replica's active area begins at.
- replicaTop: *const fn (r: *const Replica) u64,
- /// History rows `lo..hi` it does not hold.
- missing: *const fn (r: *const Replica, lo: u64, hi: u64, out: *std.ArrayList([2]u64), gpa: std.mem.Allocator) error{OutOfMemory}!void,
- apply: *const fn (s: *State, r: *Replica, bytes: []const u8) anyerror!Applied,
- applyRows: *const fn (s: *State, r: *Replica, bytes: []const u8) anyerror!void,
- shown: *const fn (s: *State, r: *const Replica) [2]u64,
- blank: *const fn (s: *State, r: *const Replica, lo: u64, hi: u64) void,
- dumpScreen: *const fn (s: *State, w: *std.Io.Writer) error{WriteFailed}!void,
+/// `Ops` in its two groups (S1: the emulator's boundary). REPLICATED: what
+/// every side agrees on by construction, each side's emulator fed the same
+/// bytes in the tape's order: written only by a step or a load, read by a
+/// step as the terminal's digest covers it (core/term/terminal.zig
+/// `digest`), or by a draw. LOCAL: this process's own (its frontend's cell
+/// size, the pixels and images it draws, its next wake, the module's start
+/// and its allocator), never what a step's digested state is computed from.
+/// core/Term.zig's `calls` lists every call of the core's into either, by
+/// file, with its rule: a new one fails its test until it is listed.
+pub const replicated = [_][]const u8{
+ "open", "close", "revive", "digest", "parts", "snapshot", "load", "reload",
+ "media", "feed", "grid", "viewTo", "scroll", "follow", "resize", "replies",
+ "key", "mouse", "wheel", "paste", "modes", "promptMoves", "prompt", "commandOutput",
+ "endOutputHere", "scrollback", "scrollbackLen", "textRows", "viewport", "editRows", "promptCut", "page",
+ "filter", "spanColor", "hasImages",
};
+pub const local = [_][]const u8{ "start", "stop", "gpa", "due", "cellPixels", "echoCell", "paint", "images" };
+
+comptime {
+ @setEvalBranchQuota(100_000);
+ for (@typeInfo(Ops).@"struct".field_names) |fname| {
+ var n = 0;
+ for (replicated ++ local) |name| {
+ if (std.mem.eql(u8, name, fname)) n += 1;
+ }
+ if (n != 1) @compileError("term.Ops." ++ fname ++ ": in neither group or in both (abi/term.zig `replicated`, `local`): say which, and why");
+ }
+ for (replicated ++ local) |name| if (!@hasField(Ops, name)) @compileError("term.Ops has no " ++ name);
+}