#ansi-escapes #ansi-term #terminal

no-std ansitok

A library for parsing ANSI Escape Codes

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

#10 in #ansi-escapes

Download history 23027/week @ 2026-03-03 173777/week @ 2026-03-10 120926/week @ 2026-03-17 107717/week @ 2026-03-24 118611/week @ 2026-03-31 136848/week @ 2026-04-07 117102/week @ 2026-04-14 119199/week @ 2026-04-21 127674/week @ 2026-04-28 82292/week @ 2026-05-05 80689/week @ 2026-05-12 78962/week @ 2026-05-19 85608/week @ 2026-05-26 80873/week @ 2026-06-02

337,257 downloads per month
Used in 316 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

~230–380KB