summaryrefslogtreecommitdiffstats
path: root/vendor/strip-ansi-escapes/README.md
blob: adb95a31ffa75710191c05ff4fb0f25b039aeea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
![Continuous integration](https://github.com/luser/strip-ansi-escapes/workflows/Continuous%20integration/badge.svg)  [![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)

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.

```rust
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.

```rust
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

  * Apache License, Version 2.0 ([`LICENSE-APACHE`](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
  * MIT license ([`LICENSE-MIT`](./LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.