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

#301 in Parser implementations

Download history 16968/week @ 2024-12-07 16868/week @ 2024-12-14 11706/week @ 2024-12-21 13422/week @ 2024-12-28 17150/week @ 2025-01-04 17263/week @ 2025-01-11 18916/week @ 2025-01-18 16404/week @ 2025-01-25 19797/week @ 2025-02-01 19222/week @ 2025-02-08 16828/week @ 2025-02-15 18647/week @ 2025-02-22 18235/week @ 2025-03-01 20909/week @ 2025-03-08 22581/week @ 2025-03-15 18073/week @ 2025-03-22

82,350 downloads per month
Used in 132 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