4 releases

Uses old Rust 2015

new 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

#19 in Command-line interface

Download history 121051/week @ 2024-09-27 109690/week @ 2024-10-04 106318/week @ 2024-10-11 114698/week @ 2024-10-18 115901/week @ 2024-10-25 118630/week @ 2024-11-01 119776/week @ 2024-11-08 138012/week @ 2024-11-15 123162/week @ 2024-11-22 129429/week @ 2024-11-29 128673/week @ 2024-12-06 121405/week @ 2024-12-13 94221/week @ 2024-12-20 72738/week @ 2024-12-27 122602/week @ 2025-01-03 126955/week @ 2025-01-10

439,094 downloads per month
Used in 547 crates (176 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

~250–390KB