Skip to main content

scrub_controls_keep_sgr

Function scrub_controls_keep_sgr 

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

Same as scrub_controls but preserves CSI sequences whose final byte is m — i.e. SGR (Select Graphic Rendition): colour, bold, italic, underline, strikethrough, faint, reverse-video, etc.

SGR is purely cosmetic — it changes how subsequent text is drawn but never moves the cursor, queries terminal state, touches the clipboard, sets the window title, or otherwise reaches outside the display rectangle. Allowing it through is what less, git, bat, and every other “safe ANSI” tool does, and it lets trusted internal output (e.g. the /codingplan SetupReport’s locked-model rows that render in the terminal’s theme red) survive sanitisation without each caller having to roll its own emission path.

Use this on trusted output — strings the app itself builds (slash-command return text, status lines, setup reports). Do NOT use it on text that came from a remote LLM or any other untrusted channel: SGR can still be used to hide content (faint, black-on- black) or impersonate UI chrome (✓ in green next to a lie), so LLM streams continue to go through the strict scrub_controls.