2 unstable releases

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

#1066 in Parser implementations

Download history 8758/week @ 2024-03-14 8783/week @ 2024-03-21 8350/week @ 2024-03-28 8619/week @ 2024-04-04 10604/week @ 2024-04-11 9414/week @ 2024-04-18 7568/week @ 2024-04-25 9695/week @ 2024-05-02 9543/week @ 2024-05-09 7986/week @ 2024-05-16 7559/week @ 2024-05-23 8628/week @ 2024-05-30 9243/week @ 2024-06-06 10309/week @ 2024-06-13 10978/week @ 2024-06-20 8825/week @ 2024-06-27

40,573 downloads per month
Used in 109 crates (5 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

~1.5MB
~24K SLoC