pub trait EscapeNonPrintablePosixExt: AsRef<str> {
// Provided method
fn escape_non_printable(&self) -> Cow<'_, str> { ... }
}Expand description
Extension trait for anything that can behave like a string to make it easy to
escape control characters into a printable, cat -v-style representation.
Intended to help prevent control characters being printed and interpreted by the terminal when printing history as well as to ensure the commands that appear in the interactive search reflect the actual command run rather than just the printable characters.
The representation is the POSIX caret/meta notation used by cat -v:
- C0 controls (
0x00..=0x1F) and DEL (0x7F) become^followed by the character xor’d with0x40, so NUL is^@, tab is^I, ESC is^[, and DEL is^?. - C1 controls (
0x80..=0x9F) becomeM-^followed by their low 7 bits xor’d with0x40, so U+009B (single-byte CSI) isM-^[.
Everything else — including spaces and printable multi-byte Unicode — is left untouched.
Provided Methods§
fn escape_non_printable(&self) -> Cow<'_, str>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".