Skip to content

Add ANSI.replay to collapse captured repaints - #625

Open
GoodForOneFare wants to merge 3 commits into
mainfrom
gordo-ansi-replay
Open

Add ANSI.replay to collapse captured repaints#625
GoodForOneFare wants to merge 3 commits into
mainfrom
gordo-ansi-replay

Conversation

@GoodForOneFare

@GoodForOneFare GoodForOneFare commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

Add ANSI.replay, which turns a captured terminal stream into the text left after cursor-driven repaints settle.

Spinners and progress bars repeatedly redraw the same screen area. A log capture stores every frame, and ANSI.strip_codes only removes escape sequences; it does not apply cursor movement or erasure. Replay applies the viewport-independent controls instead, so those frames collapse to the final output a developer saw.

For example, Shopify's dev CLI attaches dev up output to error reports. A representative 450 KB capture replays to 41 KB of useful text.

What replay models

  • CR/LF/BS and tab movement
  • Relative row and column movement
  • Erase-line and insert/delete-line
  • Cursor save and restore
  • Alternate-screen entry and exit
  • UTF-8 decoding of binary or mistagged captures
  • Grapheme clusters and two-column CJK/emoji cells

Presentation sequences and control-string payloads are consumed without producing text. Operations that require a viewport, such as absolute screen positioning and display erasure, are ignored because a capture does not record scrolling and therefore cannot map screen coordinates back to buffer rows.

The stream parser follows the VT500 state-machine shape, including malformed, aborted, embedded-control, and cut-off sequences. Resource limits apply only to rows and columns conjured by control sequences; ordinary captured output remains unbounded.

Scope boundary

This PR deliberately leaves the existing ANSI.strip_codes, ANSI.printing_width, Truncater, and Wrap behavior unchanged. Replay needs terminal-accurate column widths, so it includes a private Unicode 17 width helper and generated data, but existing layout APIs do not adopt it here.

Follow-up #624 aligns stripping, measurement, truncation, and wrapping on top of this PR. Replay and stripping still have different semantics: replay interprets cursor controls, while stripping only removes recognized sequences.

Limitations

The [1234] pids that are inserted into stream sometimes break ordering, so they may pick up extra characters (e.g., [12✅4]). This is acceptable, as the replayed logs are just for streamlined troubleshooting context.

Generate Unicode 17 wide-character ranges from pinned Unicode data and keep the width helper internal so existing layout APIs retain their current behavior.

Assisted-By: devx/b840c1e6-d979-473d-9216-a53477380bf1
Apply viewport-independent terminal controls to a line grid so captured spinner and progress-bar repaints collapse to their final output.

Parse streams with a VT-style state machine, discard presentation and alternate-screen content, and use the internal Unicode terminal-width helper for correct wide-glyph cursor placement without changing existing layout APIs.

Co-authored-by: River <river@shopify.com>

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Assisted-By: devx/b840c1e6-d979-473d-9216-a53477380bf1
Assisted-By: devx/b840c1e6-d979-473d-9216-a53477380bf1
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