Add ANSI.replay to collapse captured repaints - #623
Draft
GoodForOneFare wants to merge 1 commit into
Draft
Conversation
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>
GoodForOneFare
force-pushed
the
gordo-ansi-replay
branch
from
August 11, 2026 18:07
b7fb285 to
50500ac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tl;dr - add
ANSI.replaythat removes noise from log files piped fromcli-uioutput.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 uplog 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.