pub fn sanitize(input: &str) -> Cow<'_, str>Expand description
Sanitize untrusted text for safe terminal display.
§Fast Path
If no ESC (0x1B) found and no forbidden C0 controls, returns borrowed input with zero allocation.
§Slow Path
Strips all escape sequences and forbidden C0 controls, returns owned String.
§What Gets Stripped
- ESC (0x1B) and all following CSI/OSC/DCS/APC sequences
- C0 controls except: TAB (0x09), LF (0x0A), CR (0x0D)
- C1 controls (U+0080..U+009F) — these are the 8-bit equivalents of ESC-prefixed sequences and some terminals honor them
- DEL (0x7F)
§What Gets Preserved
- TAB, LF, CR (allowed control characters)
- All printable ASCII (0x20-0x7E)
- All valid UTF-8 sequences above U+009F