Crate strip_ansi_escapes [] [src]

A crate for stripping ANSI escape sequences from byte sequences.

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.

The simplest interface provided is the strip function, which takes a byte slice and returns a Vec of bytes with escape sequences removed. For writing bytes directly to a writer, you may prefer using the Writer struct, which implements Write and strips escape sequences as they are written.

Example

use std::io::{self, Write};

let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors)?;
io::stdout().write_all(&plain_bytes)?;

Structs

Writer

Writer wraps an underlying type that implements Write, stripping ANSI escape sequences from bytes written to it before passing them to the underlying writer.

Functions

strip

Strip ANSI escapes from data and return the remaining bytes as a Vec<u8>.