Skip to content

Add ANSI.replay to collapse captured repaints - #623

Draft
GoodForOneFare wants to merge 1 commit into
mainfrom
gordo-ansi-replay
Draft

Add ANSI.replay to collapse captured repaints#623
GoodForOneFare wants to merge 1 commit into
mainfrom
gordo-ansi-replay

Conversation

@GoodForOneFare

@GoodForOneFare GoodForOneFare commented Aug 11, 2026

Copy link
Copy Markdown
Member

tl;dr - add ANSI.replay that removes noise from log files piped from cli-ui output.

Spinners and progress bars repaint by moving the cursor, so a capture of the stream (a log file, StdoutRouter's duplicate output, test output) holds one frame per tick. ANSI.strip_codes deletes those control sequences instead of applying them, which leaves every frame side by side rather than overwriting: \r disappears, and CSI_SEQUENCE matches neither the parameterless (\e[K) nor the private (\e[?25l) forms, so those survive as text.

ANSI.replay applies the stream's viewport-independent controls -- CR/LF/BS, relative cursor moves, erase-line, insert/delete-line, cursor save/restore -- to a line grid and returns the text the repaints settled on. Presentation sequences and control-string payloads (OSC, DCS) are dropped, as a terminal drops them, and so are operations that assume a viewport (absolute positioning, display erasure): a capture does not record scrolling, so a screen coordinate has no buffer row to map onto. Shopify's dev CLI attaches its dev up log to error reports, where a 450KB capture replays to 41KB of what the developer actually saw.

There is no viewport: a capture has no scrollback to lose, so height is unbounded and cursor moves, gap padding and insert-line are capped instead. Only rows a control sequence conjures count against that cap, so an ordinary long capture never exhausts it.

@GoodForOneFare GoodForOneFare self-assigned this Aug 11, 2026
Spinners and progress bars repaint by moving the cursor, so a capture of the
stream (a log file, StdoutRouter's duplicate output, test output) holds one
frame per tick. ANSI.strip_codes deletes those control sequences instead of
applying them, which leaves every frame side by side rather than overwriting:
\r disappears, and CSI_SEQUENCE matches neither the parameterless (\e[K) nor
the private (\e[?25l) forms, so those survive as text.

ANSI.replay applies the stream's viewport-independent controls -- CR/LF/BS,
relative cursor moves, erase-line, insert/delete-line, cursor save/restore --
to a line grid and returns the text the repaints settled on. Presentation
sequences and control-string payloads (OSC, DCS) are dropped, as a terminal
drops them, and so are operations that assume a viewport (absolute
positioning, display erasure): a capture does not record scrolling, so a
screen coordinate has no buffer row to map onto. Shopify's dev CLI attaches
its `dev up` log to error reports, where a 450KB capture replays to 41KB of
what the developer actually saw.

The stream is parsed by the VT500-series state machine
(https://vt100.net/emu/dec_ansi_parser), so aborted, garbled, cut-off, and
control-embedded sequences resolve the way a real terminal resolves them.
Printable runs, string payloads, and well-formed CSI bodies move in bulk; a
fuzz test pins the rest of the input space to no-raise, valid-UTF-8,
control-free output.

There is no viewport: a capture has no scrollback to lose, so height is
unbounded and cursor moves, gap padding and insert-line are capped instead.
Only rows a control sequence conjures count against that cap, so an ordinary
long capture never exhausts it.

Co-authored-by: River <river@shopify.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant