3 unstable releases

Uses old Rust 2015

0.2.0 Aug 9, 2023
0.1.2 Aug 8, 2023
0.1.1 Aug 24, 2021
0.1.0 Feb 2, 2018

#31 in Command-line interface

Download history 92349/week @ 2024-08-15 104819/week @ 2024-08-22 102027/week @ 2024-08-29 112588/week @ 2024-09-05 103664/week @ 2024-09-12 101032/week @ 2024-09-19 119606/week @ 2024-09-26 113662/week @ 2024-10-03 103892/week @ 2024-10-10 115422/week @ 2024-10-17 115884/week @ 2024-10-24 116817/week @ 2024-10-31 120493/week @ 2024-11-07 132244/week @ 2024-11-14 133938/week @ 2024-11-21 98996/week @ 2024-11-28

504,798 downloads per month
Used in 528 crates (166 directly)

Apache-2.0/MIT

10KB
129 lines

Continuous integration crates.io

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.

Examples

The strip function accepts bytes and returns a Vec of bytes with ANSI escape sequences removed.

extern crate strip_ansi_escapes;

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

fn work() -> io::Result<()> {
  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)?;
  Ok(())
}

fn main() {
    work().unwrap();
}

For writing directly to a writer, the Writer struct may be preferable.

extern crate strip_ansi_escapes;

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

fn work() -> io::Result<()> {
  let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
  let mut writer = Writer::new(io::stdout());
  // Only `foo bar` will be written to stdout
  writer.write_all(bytes_with_colors)?;
  Ok(())
}

fn main() {
    work().unwrap();
}

License

Licensed under either of

at your option.

Dependencies

~220KB