Skip to main content

scrub_controls

Function scrub_controls 

Source
pub fn scrub_controls(input: &str) -> String
Expand description

Strip ANSI escape sequences and C0/C1 control codes except tab/newline/CR.

Defends against:

  • CSI sequences (\x1b[…) — can clear screen, move cursor, query position
  • OSC sequences (\x1b]…\x07 or \x1b]…\x1b\) — can set terminal title, manipulate clipboard, or write to hyperlink targets
  • C0 controls (0x00..0x1F) except \t \n \r — can ring bell, backspace, etc.
  • C1 controls (0x80..0x9F in UTF-8 as U+0080..U+009F) — alternate CSI forms
  • Bare ESC (\x1b not followed by a recognised intro)