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

#352 in Parser implementations

Download history 18852/week @ 2025-02-09 16779/week @ 2025-02-16 18702/week @ 2025-02-23 18733/week @ 2025-03-02 21102/week @ 2025-03-09 22555/week @ 2025-03-16 20539/week @ 2025-03-23 19415/week @ 2025-03-30 35448/week @ 2025-04-06 40870/week @ 2025-04-13 23071/week @ 2025-04-20 19807/week @ 2025-04-27 20062/week @ 2025-05-04 19264/week @ 2025-05-11 20232/week @ 2025-05-18 20539/week @ 2025-05-25

81,985 downloads per month
Used in 142 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