• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Jan-2022-

examples/H20-Jan-2022-1915

src/H20-Jan-2022-220143

.cargo-checksum.jsonH A D03-May-202289 11

Cargo.tomlH A D20-Jan-2022989 2624

LICENSE-APACHEH A D20-Jan-202210.6 KiB202169

LICENSE-MITH A D20-Jan-20221 KiB2622

README.mdH A D20-Jan-20221.7 KiB5940

README.md

1[![Build Status](https://travis-ci.org/luser/strip-ansi-escapes.svg?branch=master)](https://travis-ci.org/luser/strip-ansi-escapes)  [![crates.io](https://img.shields.io/crates/v/strip-ansi-escapes.svg)](https://crates.io/crates/strip-ansi-escapes) [![](https://docs.rs/strip-ansi-escapes/badge.svg)](https://docs.rs/strip-ansi-escapes)
2
3A crate for stripping ANSI escape sequences from byte sequences.
4
5This can be used to take output from a program that includes escape sequences and write
6it somewhere that does not easily support them, such as a log file.
7
8# Examples
9
10The `strip` function accepts bytes and returns a `Vec` of bytes with ANSI escape sequences removed.
11
12```rust
13extern crate strip_ansi_escapes;
14
15use std::io::{self, Write};
16
17fn work() -> io::Result<()> {
18  let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
19  let plain_bytes = strip_ansi_escapes::strip(&bytes_with_colors)?;
20  io::stdout().write_all(&plain_bytes)?;
21  Ok(())
22}
23
24fn main() {
25    work().unwrap();
26}
27```
28
29For writing directly to a writer, the `Writer` struct may be preferable.
30
31```rust
32extern crate strip_ansi_escapes;
33
34use std::io::{self, Write};
35use strip_ansi_escapes::Writer;
36
37fn work() -> io::Result<()> {
38  let bytes_with_colors = b"\x1b[32mfoo\x1b[m bar";
39  let mut writer = Writer::new(io::stdout());
40  // Only `foo bar` will be written to stdout
41  writer.write_all(bytes_with_colors)?;
42  Ok(())
43}
44
45fn main() {
46    work().unwrap();
47}
48```
49
50# License
51
52Licensed under either of
53
54  * Apache License, Version 2.0 ([`LICENSE-APACHE`](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
55  * MIT license ([`LICENSE-MIT`](./LICENSE-MIT) or http://opensource.org/licenses/MIT)
56
57at your option.
58
59