4 Frames and bounded runs🔗ℹ

flush! triggers current-frame-hook with the current grid, but only when the rendered character grid actually changed – the check covers text and colors/attributes (current-frame-dedup?, on by default), so a color-only change is not mistaken for an idle frame. An idle loop therefore does not keep emitting frames. (screen-frame-log-enable! path) appends every frame as plain text to a file (#:diff? #t writes only the differences); (screen-frame-count) and (screen-frame-log-disable!) complete the API.

Deduped frames are also snapshotted into a bounded in-memory history (current-frame-history-size, 32 by default, 0 disables), so nothing is lost even though you only print changes:

  • (char-history) / (char-frame-at i) — frame text, oldest to newest;

  • (char-history-ref i) — the whole grid snapshot of frame i, so colors/attributes/cursor remain queryable after the fact;

  • (char-diff) / (frame-diff a b) — unified-diff text listing only changed rows (consecutive rows merged into one hunk); (char-diff #:styles? #t) also reports style changes;

  • (char-style-diff) / (style-diff ga gb) — only the color/attribute changes, as column ranges with old -> new (e.g. cols 0..3 fg(255,0,0) -> fg(0,0,0)); (grid-diff ga gb) combines both;

  • (char-log-enable! #:to port #:diff? #t) — print only the text+style diff of each changed frame; (char-log-disable!) stops it.

For deterministic debugging, char-run processes a finite list of events, rendering once per event and returning the sequence of frame strings (at most one frame per event plus the initial frame), so headless runs never flood output; with #:diff? #t it returns the first frame followed by one diff per change:

(char-run (list #\+ #\+ #\-)
          #:handle (lambda (ev) ...)
          #:render (lambda () ...)
          #:diff? #t
          #:rows 24 #:cols 80)