pub fn sanitise(value: &str) -> StringExpand description
Make one value safe to print in a terminal.
Removes every C0 and C1 control character, the escape that introduces an ANSI sequence along with the sequence itself, and the Unicode characters that reorder or hide text: the bidirectional overrides, the zero-width joiners at the start of a value, and the deprecated tag characters that terminals may swallow entirely. Tabs and newlines become spaces. Everything else — every language, every emoji — is left exactly as it was.
use majordomus_cli::environment::text::sanitise;
assert_eq!(sanitise("feature/přehled"), "feature/přehled");
assert_eq!(sanitise("a\u{1b}[31mred\u{1b}[0m"), "ared");
assert_eq!(sanitise("two\nlines\tin one"), "two lines in one");
assert_eq!(sanitise("\u{202e}gnorts"), "gnorts", "a right-to-left override is removed");
assert_eq!(sanitise("\u{7}bell"), "bell");