2 unstable releases

0.2.0 Oct 18, 2022
0.1.1 Oct 18, 2022
0.1.0 Jul 19, 2022

#1386 in Parser implementations

Download history 12953/week @ 2024-07-19 13338/week @ 2024-07-26 11820/week @ 2024-08-02 11962/week @ 2024-08-09 11035/week @ 2024-08-16 11606/week @ 2024-08-23 12049/week @ 2024-08-30 11214/week @ 2024-09-06 10573/week @ 2024-09-13 12017/week @ 2024-09-20 13025/week @ 2024-09-27 13719/week @ 2024-10-04 14047/week @ 2024-10-11 15664/week @ 2024-10-18 14399/week @ 2024-10-25 14253/week @ 2024-11-01

60,378 downloads per month
Used in 122 crates (6 directly)

MIT license

57KB
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

use ansitok::{parse_ansi, Output};

fn main() {
    let text = "\x1b[31;1;4mHello World\x1b[0m";

    for output in parse_ansi(text) {
        match output {
            Output::Text(text) => println!("Got a text: {:?}", text),
            Output::Escape(esc) => println!("Got an escape sequence: {:?}", esc),
        }
    }
}

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
~23K SLoC