#ansi #escape #terminal

strip-ansi-escapes

Strip ANSI escape sequences from byte streams

2 releases

Uses old Rust 2015

0.1.1 Aug 24, 2021
0.1.0 Feb 2, 2018

#71 in Command-line interface

Download history 56010/week @ 2021-08-12 37872/week @ 2021-08-19 33218/week @ 2021-08-26 27670/week @ 2021-09-02 33111/week @ 2021-09-09 30896/week @ 2021-09-16 21438/week @ 2021-09-23 26017/week @ 2021-09-30 31193/week @ 2021-10-07 31953/week @ 2021-10-14 37423/week @ 2021-10-21 38357/week @ 2021-10-28 40453/week @ 2021-11-04 29771/week @ 2021-11-11 26921/week @ 2021-11-18 23913/week @ 2021-11-25

125,858 downloads per month
Used in 117 crates (31 directly)

Apache-2.0/MIT

9KB
144 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

~175KB