Skip to main content

strip_ansi

Function strip_ansi 

Source
fn strip_ansi(chunk: &mut Vec<u8>)
Expand description

Phase β (lite): strip ANSI control sequences from a PTY chunk so the overlay’s plain-text ChunkList doesn’t render them as garbled literal characters.

Three families to handle (everything bash emits during init and most programs emit during normal output):

  1. CSI sequences — ESC [ <params> <final> where params are 0x30..=0x3F (digits, ;, ?, etc.) and final is 0x40..=0x7E (letters + punctuation). Covers \x1b[m (reset), \x1b[?25h/l (cursor visibility), color codes, cursor moves.

  2. OSC sequences — ESC ] <text> BEL (or ESC ] <text> ESC \). Covers \x1b]0;<title>\x07 (set window title — emitted by Git Bash on every command).

  3. Lone control chars — \r (carriage return without newline), \x07 (bell), \x08 (backspace). CRLF → LF for the chunk list. Lone \r passes through so collapse_cr can operate on the pending buffer across PTY reads (see below).

Things we DON’T handle yet (Phase γ territory):

  • Alt-screen apps (\x1b[?1049h) — left in the stream.
  • Cursor positioning escapes within the same line.
  • OSC 633 (shell integration markers).