From 292ddaaa29a8253ea1672572496c2693ba24d820 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 10:43:59 -0300 Subject: echo: judged when a terminal is fed, its delta's entry folded in (the old road's deletion, piece 7 of 8; echo.zig STAYS, round 7's ruling): `Echo.delta` had one caller left, `fed` (the screen-state replica's `screen` went in piece 3), so its body is `fed`'s, judged at the grid's active top on the echo's own pane; the words that said `delta` (the module's doc, `grace_ns`, `stale_ns`, `tops`, the Rig's comments) say output; nothing else changes; core-test 911/1068, shell-test 1110/1113 (the Rig's tests among them), `--echo --seeds 2 --rtt 30,207` rc 0 (30 ms: 50.1 -> 8.5 ms p50 with prediction; 207 ms: 239.3 -> 8.6; diverged 0, unequal 0, secret frames 0, drawn wrong 0) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/echo.zig | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'core/echo.zig') diff --git a/core/echo.zig b/core/echo.zig index 3b59788d..93b877b8 100644 --- a/core/echo.zig +++ b/core/echo.zig @@ -18,9 +18,10 @@ //! never drawn where the completion was not. //! //! Judged as mosh does, once the authority confirmed the key and `grace` -//! passed: at a delta, a cell the screen shows goes, and one it does not is -//! a misprediction, and every prediction goes. With no delta (nothing -//! changed: no echo), a frame judges it `stale` later. Shown at once at a +//! passed: when the terminal is fed a unit's output (`fed`), a cell the +//! screen shows goes, and one it does not is a misprediction, and every +//! prediction goes. With no output (no echo), a frame judges it `stale` +//! later. Shown at once at a //! shell's prompt (pardes's OSC 133 marks say its line editor echoes); //! elsewhere only once an echo was confirmed there since the last key that //! was not predicted (`cat`, a shell without marks), and underlined; never @@ -37,12 +38,12 @@ const Key = pardes.Key; const ms = std.time.ns_per_ms; /// After the authority confirmed a key, how long its echo has to come back -/// before a delta that does not show it makes a misprediction (mosh's +/// before output that does not show it makes a misprediction (mosh's /// ECHO_TIMEOUT): the shell's echo, then the authority's next frame. // ponytail: fixed; a loaded host's later echo makes a drawn character go and // come back. The echo delay measured per terminal would be the bound. pub const grace_ns = 50 * ms; -/// With no delta at all, how much longer a frame waits to judge a key. +/// With no output at all, how much longer a frame waits to judge a key. pub const stale_ns = 250 * ms; const never = std.math.maxInt(u64); /// Cells predicted at once: a line typed a round trip ahead. @@ -73,7 +74,7 @@ pub const Echo = struct { view: u8 = 0, pane: u8 = 0, serial: u32 = 0, - /// Each terminal's last delta: its active area's first row, absolute. + /// Each terminal's active area's first row, absolute, as last fed. tops: [pardes.MAX_PANES]u64 = @splat(0), cells: [max]Cell = undefined, n: u8 = 0, @@ -347,7 +348,7 @@ pub const Echo = struct { }; if (e.wait <= seq and e.wait_due == never) { // The authority stepped a key this did not predict, after every - // one it did: its deltas from here show that key's doing, which + // one it did: its output from here shows that key's doing, which // no prediction knew of. They go, judged neither way. e.wait_due = due; e.drop(); @@ -355,30 +356,24 @@ pub const Echo = struct { e.catchUp(c); } - /// Terminal `id`'s delta was applied, its active area's first row now - /// `top`. - pub fn delta(e: *Echo, c: *Pardes, id: u8, top: u64) void { - if (id == e.pane and top != e.tops[id] and (e.n > 0 or e.cursor != null)) { + /// The emulators were fed a unit's output (the session's echo among + /// it, perhaps): judged, the active area's first row its grid's. + /// ponytail: at the history's cap that row stops moving as the output + /// scrolls; a guess there is judged wrong and taken back, never kept. + pub fn fed(e: *Echo, c: *Pardes) void { + const pane = c.panes[e.pane] orelse return; + const g = Term.grid(pane.terminal orelse return); + const top = g.total - g.len; + if (top != e.tops[e.pane] and (e.n > 0 or e.cursor != null)) { // Scrolled: the rows predicted are others now. - e.tops[id] = top; + e.tops[e.pane] = top; return e.lose(); } - e.tops[id] = top; - if (id == e.pane) e.judge(c, 0); + e.tops[e.pane] = top; + e.judge(c, 0); e.catchUp(c); } - /// The pty's bytes road: the emulators were fed a unit's output (the - /// session's echo among it, perhaps): judged as at a delta, the active - /// area's first row its grid's. ponytail: at the history's cap that - /// row stops moving as the output scrolls; a guess there is judged - /// wrong and taken back, never kept. - pub fn fed(e: *Echo, c: *Pardes) void { - const pane = c.panes[e.pane] orelse return; - const g = Term.grid(pane.terminal orelse return); - e.delta(c, e.pane, g.total - g.len); - } - /// Once a frame: what is stale judged. Whether to draw. pub fn frame(e: *Echo, c: *Pardes) bool { if (e.n > 0 or e.cursor != null) e.judge(c, stale_ns); @@ -671,8 +666,8 @@ test "keys typed at a shell's prompt are drawn at once, and the authority's echo try testing.expectEqual(@as(u8, 's'), (try g.drawn(&arena, 3)).cp); // The authority's core draws no overlay of its own. try testing.expect(g.a.core.echo == null); - // The authority takes them, its shell echoes, the delta lands after the - // grace: confirmed, and the screen's own cells and cursor shown. + // The authority takes them, its shell echoes, its output lands after + // the grace: confirmed, and the screen's own cells and cursor shown. try g.take(l); try g.take(s); try testing.expectEqualStrings("ls", g.written.items); @@ -711,7 +706,7 @@ test "a password prompt shows nothing typed, and a full-screen program is not pr try testing.expectEqual(@as(u32, 1), g.r.echo.stats.predicted); try testing.expectEqual(@as(u8, ' '), (try g.drawn(&arena, x)).cp); try g.take(k); - // No echo, so no delta: a frame lets it go once it is stale. + // No echo, so no output: a frame lets it go once it is stale. g.later(grace_ns + stale_ns); _ = g.r.echoFrame(); try testing.expectEqual(@as(u8, 0), g.r.echo.n); -- cgit v1.3