#ansi #escape #terminal

strip-ansi-escapes

Strip ANSI escape sequences from byte streams

1 unstable release

Uses old Rust 2015

0.1.0 Feb 2, 2018

#198 in Command-line interface

Download history 10502/week @ 2020-12-25 16761/week @ 2021-01-01 19056/week @ 2021-01-08 17138/week @ 2021-01-15 17124/week @ 2021-01-22 16566/week @ 2021-01-29 17019/week @ 2021-02-05 19035/week @ 2021-02-12 19311/week @ 2021-02-19 18463/week @ 2021-02-26 19746/week @ 2021-03-05 34402/week @ 2021-03-12 25308/week @ 2021-03-19 26159/week @ 2021-03-26 25804/week @ 2021-04-02 23065/week @ 2021-04-09

70,978 downloads per month
Used in 86 crates (21 directly)

Apache-2.0/MIT

10KB
143 lines

Build Status 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

~60KB