diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 16:50:34 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 16:53:19 -0300 |
| commit | 9863a63b614d200852853825031189364dcacfdc (patch) | |
| tree | d235648a2ac14b3e311746ced3433ed6865e2061 /core/Term.zig | |
| parent | 6544f73a6b50e5ba68564beea7784593bb54348e (diff) | |
| parent | bad506bd45846e012246a33b5d3097b3e92f02bc (diff) | |
| download | pardes-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 'core/Term.zig')
| -rw-r--r-- | core/Term.zig | 228 |
1 files changed, 129 insertions, 99 deletions
diff --git a/core/Term.zig b/core/Term.zig index 6ef9b0a5..580db4fa 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -50,14 +50,9 @@ pub const Painted = iface.Painted; pub const PaintedRow = iface.PaintedRow; pub const ImagesAt = iface.ImagesAt; pub const EchoCell = iface.EchoCell; -pub const Peer = iface.Peer; -pub const Applied = iface.Applied; -pub const Encoder = iface.Encoder; -pub const Track = iface.Track; -pub const Replica = iface.Replica; fn the() *const iface.Ops { - return ops orelse unreachable; // no State, Encoder or Replica is made without it + return ops orelse unreachable; // no State is made without it } /// A terminal pane's terminal: the module's handle, and the walk's hooks @@ -73,11 +68,7 @@ pub const State = struct { written: bool = true, /// The emulator as its program has made it, for the replay digest. - /// Under screen-state terminals the emulator is the authority's, and a - /// replica's is what the last delta made it: compared as screens - /// (test/replicas.zig), not step by step. pub fn digest(s: *const State, h: *walk.Hasher) void { - if (tape.screenState()) return; s.digestScreen(h, true); } @@ -140,10 +131,8 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State { /// session's machine's) as its emulator reads it, made the tape's answer /// (P30: the device's answer as it was, as a file's bytes are): the session /// reads it, a temporary file deleted and shared memory unlinked there once, -/// and every replica is handed the same bytes, or the same failure. Under -/// screen state a replica feeds no emulator: the read is the session's. +/// and every replica is handed the same bytes, or the same failure. fn media(ctx: *const anyopaque, read: *const fn (*const anyopaque) iface.MediumError![]u8, gpa: std.mem.Allocator) iface.MediumError![]u8 { - if (tape.screenState()) return read(ctx); return tape.valueIn(.medium, gpa, readMedium, .{ read, ctx }); } @@ -236,16 +225,11 @@ pub fn follow(s: *State) void { the().follow(s.impl); } -/// Its grid reflowed, now or when `resizeDeferred` makes it. -pub fn resize(s: *State, cols: u16, rows: u16, later: bool) void { +/// Its grid reflowed. +pub fn resize(s: *State, cols: u16, rows: u16) void { writes +%= 1; s.written = true; - the().resize(s.impl, cols, rows, later); -} - -pub fn resizeDeferred(s: *State) bool { - writes +%= 1; - return the().resizeDeferred(s.impl); + the().resize(s.impl, cols, rows); } /// Its cells' size in pixels (kitty graphics, CSI 14/16 t). @@ -365,12 +349,6 @@ pub fn promptPrefix(tab: u16, s: ?*State, row: i32, raw: []const u8) usize { }; } -/// A step read its rows: its replicas must hold them for the step's -/// replay. -pub fn markRead(s: *State) void { - the().markRead(s.impl); -} - /// What a predicted echo reads of a cell of its active area. pub fn echoCell(s: *const State, x: u16, y: u16) ?EchoCell { return the().echoCell(s.impl, x, y); @@ -425,82 +403,134 @@ pub fn hasImages(s: ?*const State) bool { return o.hasImages(if (s) |state| state.impl else null); } -// ---- its replicas ---- - -pub fn encoder(gpa: std.mem.Allocator) !*Encoder { - return the().encoder(gpa); -} - -pub fn encoderFree(e: *Encoder) void { - the().encoderFree(e); -} - -pub fn track(gpa: std.mem.Allocator) !*Track { - return the().track(gpa); -} - -/// A peer's track of it let go (`s` null: it is gone). -pub fn untrack(t: *Track, gpa: std.mem.Allocator, s: ?*State) void { - the().untrack(t, gpa, if (s) |state| state.impl else null); -} - -/// What a peer is owed of it, a delta against what the peer was sent. -pub fn encode(s: *State, e: *Encoder, t: *Track, peer: *Peer, out: *std.Io.Writer) !bool { - return the().encode(s.impl, e, t, peer, out); -} - -/// Rows of it a replica holds as holes. -pub fn encodeRows(s: *State, e: *Encoder, t: *Track, lo: u64, hi: u64, out: *std.Io.Writer) !void { - return the().encodeRows(s.impl, e, t, lo, hi, out); -} - -/// Whether a step read its rows since `clearRead`. -pub fn wasRead(s: *const State) bool { - return the().wasRead(s.impl); -} - -pub fn clearRead(s: *State) void { - the().clearRead(s.impl); -} +// ---- the boundary (S1): every call of the core's into its terminal ---- -/// A replica's side of one terminal: made, freed, where its active area -/// begins, and the history rows it does not hold. -pub fn replica(gpa: std.mem.Allocator) !*Replica { - return the().replica(gpa); -} - -pub fn replicaFree(r: *Replica, gpa: std.mem.Allocator) void { - the().replicaFree(r, gpa); -} - -pub fn replicaTop(r: *const Replica) u64 { - return the().replicaTop(r); -} - -pub fn missing(r: *const Replica, lo: u64, hi: u64, out: *std.ArrayList([2]u64), gpa: std.mem.Allocator) !void { - return the().missing(r, lo, hi, out, gpa); -} - -/// A replica's side: a delta applied, rows applied, the rows its view -/// shows, rows blank until they come. -pub fn apply(s: *State, r: *Replica, bytes: []const u8) !Applied { - return the().apply(s.impl, r, bytes); -} - -pub fn applyRows(s: *State, r: *Replica, bytes: []const u8) !void { - return the().applyRows(s.impl, r, bytes); -} - -pub fn shown(s: *State, r: *const Replica) [2]u64 { - return the().shown(s.impl, r); -} +/// Every call of the core's (core/, but this file and the module's own +/// core/term/) into a terminal, by entry, its files and how many in each +/// (a test's among them), and its rule: the emulator is outside the +/// rollback copy and its digest is the terminal's (`State.digest`, which +/// covers what abi/term.zig `replicated` lists a step reads, but the +/// history's text). A READ from a step is covered by the digest or is +/// said not to be; a WRITE outside the copy is never made by a unit kept +/// to replay, or its record puts it back exactly; a LOCAL entry +/// (abi/term.zig `local`) is never read into a step's state. A new call +/// fails the test below until it is listed here with its rule (round 6's +/// and pardes-image-loop's tables, kept as a test). +pub const calls = [_]struct { []const u8, []const u8, []const u8 }{ + // ---- writes: outside the copy ---- + .{ "open", "dump.zig:1 panes.zig:1", "WRITE: a terminal made by a step (a shell's pane) or a load; a copy held across a pane's opening is let go (replica.zig `confirm`: serials)" }, + .{ "close", "panes.zig:1", "WRITE: let go by a step that closes its pane: a copy held across it is let go (retiring panes); a unit that closes one is never kept over a copy" }, + .{ "revive", "dump.zig:1", "WRITE: a load's (a join's dump, a Restore): no copy is held" }, + .{ "reload", "panes.zig:1", "WRITE: a join's step remakes each terminal written since its last reload, on every side (panes.reloadTerminals, the session's choice taped, the snapshot's hash compared)" }, + .{ "feed", "keys.zig:1 panes.zig:3", "WRITE: the pty's bytes in a unit, every side in the tape's order; a unit that feeds lets a copy held ahead go (`Term.writes`), so none is replayed (keys.zig's: a test's)" }, + .{ "viewTo", "replica.zig:2", "WRITE: a rollback puts each view back by its row (`putViews`), exact since a reflow keeps a view a row (pardes-term-join-6)" }, + .{ "scroll", "Core.zig:2 panes.zig:1", "WRITE: a step moves the view; outside the copy, put back by `putViews`" }, + .{ "follow", "panes.zig:1", "WRITE: a step puts the view on the output; put back by `putViews`" }, + .{ "resize", "panes.zig:1", "WRITE: a step's reflow; a speculation owes it (`touchTerminal`): its input is taken when confirmed, never as speculated" }, + .{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" }, + .{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest); only the session writes it to the pty (pty_write is off the tape)" }, + // ---- reads by a step: in the digest ---- + .{ "grid", "Core.zig:8 ansi.zig:4 body_layer.zig:5 draw.zig:3 dump.zig:4 echo.zig:8 edit.zig:1 exec.zig:3 keys.zig:3 layout.zig:2 mouse.zig:1 panes.zig:6 replica.zig:4", "READ: the size, the view, the cursor: in the digest (ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, + .{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's)" }, + .{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" }, + .{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" }, + .{ "hasImages", "replica.zig:3 tagline.zig:1", "READ: whether it holds a kitty image (the tag's prefix): in the digest" }, + .{ "key", "keys.zig:1", "READ: a key's bytes for the pty from its modes (in the digest): a write the session makes" }, + .{ "mouse", "mouse.zig:4", "READ: a report's bytes from its modes (in the digest); the last cell told is the pane's (in the copy)" }, + .{ "wheel", "mouse.zig:1", "READ: a wheel's report from its modes (in the digest)" }, + .{ "paste", "edit.zig:1", "READ: a paste's bracketing from its modes (in the digest)" }, + .{ "promptMoves", "keys.zig:1", "READ: the cursor keys a click at its prompt types, from the prompt's cells and the cursor (in the digest)" }, + .{ "page", "Core.zig:1 ninep/ctl.zig:1", "PURE: a pager's parse of bytes the step holds; no emulator" }, + .{ "filter", "File.zig:1", "PURE: a pager's colours from the theme; no emulator" }, + .{ "spanColor", "File.zig:2", "PURE: as `filter`" }, + // ---- reads by a step: NOT in the digest (the history's text) ---- + .{ "scrollback", "Core.zig:3 Effect.zig:1 dump.zig:1 ninep/pane.zig:1 ninep/screen.zig:2", "READ, NOT COVERED: the history's text (a 9P read, a Save, an exit dump): each side fed the same bytes; a parting there is found when it reaches the core's state" }, + .{ "scrollbackLen", "ninep/ctl.zig:1 ninep/pane.zig:1", "READ, NOT COVERED: the history's text's length (its row count is in the digest)" }, + .{ "commandOutput", "ninep/pty.zig:1", "READ, NOT COVERED: a command's output rows (a 9P pty/run): taped as the session's answer" }, + .{ "textRows", "edit.zig:2", "READ, NOT COVERED: every row's text, the history's among them (a selection, a Look over a shell)" }, + .{ "viewport", "body_layer.zig:1 replica.zig:1", "READ: the view's rows' text (body_layer.zig: a draw's; replica.zig: a test's)" }, + .{ "editRows", "ansi.zig:1", "READ: rows' text for a draw" }, + // ---- local ---- + .{ "due", "Core.zig:1", "LOCAL: its next wake (a blink, an animation): the loop's, never a step's state" }, + .{ "cellPixels", "ansi.zig:1 panes.zig:2", "LOCAL: a frontend's draw sets its view's cell size (ansi.zig); a step sets the view's (in the digest) before each feed (panes.zig), so a reply to CSI 16 t is the step's" }, + .{ "echoCell", "echo.zig:1", "LOCAL: the predicted echo's judge reads a cell; the echo is no core state" }, + .{ "paint", "ansi.zig:1", "LOCAL: its cells drawn" }, + .{ "images", "ansi.zig:1", "LOCAL: its kitty images drawn" }, + .{ "start", "tape.zig:1", "LOCAL: the module's start, a test's (its own process's)" }, + .{ "emulatorOf", "Core.zig:2 ninep/pty.zig:3", "the module's state itself: tests only" }, +}; -pub fn blank(s: *State, r: *const Replica, lo: u64, hi: u64) void { - the().blank(s.impl, r, lo, hi); +test "every call of the core's into a terminal is listed with its rule (S1): a new read, writer or local use fails until it is" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var dir = try std.Io.Dir.cwd().openDir(io, "core", .{ .iterate = true }); + defer dir.close(io); + var walker = try dir.walk(gpa); + defer walker.deinit(); + var wrong: usize = 0; + var counts: std.StringHashMapUnmanaged(usize) = .empty; + defer { + var it = counts.keyIterator(); + while (it.next()) |k| gpa.free(k.*); + counts.deinit(gpa); + } + while (try walker.next(io)) |e| { + if (e.kind != .file or !std.mem.endsWith(u8, e.basename, ".zig")) continue; + if (std.mem.eql(u8, e.path, "Term.zig") or std.mem.startsWith(u8, e.path, "term/")) continue; + const src = try e.dir.readFileAlloc(io, e.basename, gpa, .limited(16 << 20)); + defer gpa.free(src); + var lines = std.mem.splitScalar(u8, src, '\n'); + while (lines.next()) |line| { + if (std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), "//")) continue; + var at: usize = 0; + while (std.mem.indexOfPos(u8, line, at, "Term.")) |i| { + at = i + 5; + var end = at; + while (end < line.len and (std.ascii.isAlphanumeric(line[end]) or line[end] == '_')) end += 1; + if (end == at or end >= line.len or line[end] != '(' or !std.ascii.isLower(line[at])) continue; + if (i > 0 and (std.ascii.isAlphanumeric(line[i - 1]) or line[i - 1] == '_')) continue; + const k = try std.fmt.allocPrint(gpa, "{s} {s}", .{ line[at..end], e.path }); + const got = try counts.getOrPut(gpa, k); + if (got.found_existing) { + gpa.free(k); + got.value_ptr.* += 1; + } else got.value_ptr.* = 1; + } + } + } + // Each listed file's count is what the tree has, and nothing else calls. + for (calls) |c| { + var files = std.mem.tokenizeScalar(u8, c[1], ' '); + while (files.next()) |fc| { + const colon = std.mem.lastIndexOfScalar(u8, fc, ':').?; + const want = try std.fmt.parseInt(usize, fc[colon + 1 ..], 10); + var buf: [256]u8 = undefined; + const pair = try std.fmt.bufPrint(&buf, "{s} {s}", .{ c[0], fc[0..colon] }); + const have = counts.get(pair) orelse 0; + if (have == want) continue; + wrong += 1; + std.debug.print("core/{s}: {d} calls of Term.{s}, Term.zig's `calls` says {d}: {s}\n", .{ fc[0..colon], have, c[0], want, c[2] }); + } + } + var it = counts.iterator(); + while (it.next()) |kv| { + const space = std.mem.indexOfScalar(u8, kv.key_ptr.*, ' ').?; + const name = kv.key_ptr.*[0..space]; + const file = kv.key_ptr.*[space + 1 ..]; + if (listedCall(name, file)) continue; + wrong += 1; + std.debug.print("core/{s}: {d} calls of Term.{s}, not in Term.zig's `calls`: list it with its rule (a step's read the digest covers, a write the copy puts back, a local use)\n", .{ file, kv.value_ptr.*, name }); + } + try std.testing.expectEqual(@as(usize, 0), wrong); } -pub fn dumpScreen(s: *State, w: *std.Io.Writer) !void { - return the().dumpScreen(s.impl, w); +fn listedCall(name: []const u8, file: []const u8) bool { + for (calls) |c| { + if (!std.mem.eql(u8, c[0], name)) continue; + var files = std.mem.tokenizeScalar(u8, c[1], ' '); + while (files.next()) |fc| if (std.mem.eql(u8, fc[0..std.mem.lastIndexOfScalar(u8, fc, ':').?], file)) return true; + } + return false; } // ---- a core without a terminal (core-test's) ---- |
