Function anstream::adapter::strip_bytes

source ·
pub fn strip_bytes(data: &[u8]) -> StrippedBytes<'_> 
Expand description

Strip ANSI escapes from bytes, returning the printable content

This can be used to take output from a program that includes escape sequences and write it somewhere that does not easily support them, such as a log file.

§Example

use std::io::Write as _;

let styled_text = "\x1b[32mfoo\x1b[m bar";
let plain_str = anstream::adapter::strip_bytes(styled_text.as_bytes()).into_vec();
assert_eq!(plain_str.as_slice(), &b"foo bar"[..]);