3 releases (breaking)

0.3.0 Jan 30, 2025
0.2.0 Oct 18, 2022
0.1.1 Oct 18, 2022
0.1.0 Jul 19, 2022

#385 in Parser implementations

Download history 17398/week @ 2025-01-08 17626/week @ 2025-01-15 17746/week @ 2025-01-22 18615/week @ 2025-01-29 19086/week @ 2025-02-05 18016/week @ 2025-02-12 18086/week @ 2025-02-19 17750/week @ 2025-02-26 19679/week @ 2025-03-05 21060/week @ 2025-03-12 23322/week @ 2025-03-19 18764/week @ 2025-03-26 20335/week @ 2025-04-02 44246/week @ 2025-04-09 32600/week @ 2025-04-16 19402/week @ 2025-04-23

118,931 downloads per month
Used in 138 crates (6 directly)

MIT license

58KB
1K SLoC

ansi escape codes tokenization

gitlab crates.io docs.rs build status

This is a library for parsing ANSI escape sequences.

The list of covered sequences.

  • Cursor Position
  • Cursor {Up, Down, Forward, Backward}
  • Cursor {Save, Restore}
  • Erase Display
  • Erase Line
  • Set Graphics mode
  • Set/Reset Text Mode

Usage

let text = "\x1b[31;1;4mHello World\x1b[0m";

for e in parse_ansi(text) {
    match e.kind() {
        ElementKind::Text => {
            println!("Got a text: {:?}", &text[e.range()],);
        }
        _ => {
            println!(
                "Got an escape sequence: {:?} from {:#?} to {:#?}",
                e.kind(),
                e.start(),
                e.end()
            );
        }
    }
}

no_std support

no_std is supported via disabling the std feature in your Cargo.toml.

Notes

The project got an insiration from https://gitlab.com/davidbittner/ansi-parser.

Dependencies

~1MB
~21K SLoC