Skip to main content

sanitize_for_terminal

Function sanitize_for_terminal 

Source
pub fn sanitize_for_terminal(value: &str) -> Cow<'_, str>
Expand description

Replace every control character with '.'.

Keeps the string’s visual length stable (one replacement per removed character) so column-aligned table output does not shift, and returns Cow::Borrowed when there is nothing to strip, which is the overwhelmingly common case.

Unlike the scan-probe sanitizer, this strips \n, \r, and \t too. A single-line display value has no business containing them: \n fabricates extra output lines and \r lets a remote host overwrite the row it was printed on.