4 releases

Uses old Rust 2015

0.2.1 Jan 14, 2025
0.2.0 Aug 9, 2023
0.1.2 Aug 8, 2023
0.1.1 Aug 24, 2021
0.1.0 Feb 2, 2018

#23 in Command-line interface

Download history 113662/week @ 2024-10-21 115757/week @ 2024-10-28 120881/week @ 2024-11-04 123421/week @ 2024-11-11 136006/week @ 2024-11-18 120182/week @ 2024-11-25 131821/week @ 2024-12-02 126946/week @ 2024-12-09 135627/week @ 2024-12-16 69447/week @ 2024-12-23 76931/week @ 2024-12-30 138375/week @ 2025-01-06 156715/week @ 2025-01-13 142915/week @ 2025-01-20 149144/week @ 2025-01-27 161705/week @ 2025-02-03

617,790 downloads per month
Used in 555 crates (179 directly)

Apache-2.0/MIT

10KB
126 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

~245–390KB