2 unstable releases

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

#1106 in Parser implementations

Download history 7277/week @ 2024-01-06 7006/week @ 2024-01-13 8545/week @ 2024-01-20 8591/week @ 2024-01-27 8309/week @ 2024-02-03 7744/week @ 2024-02-10 7488/week @ 2024-02-17 7409/week @ 2024-02-24 9251/week @ 2024-03-02 8634/week @ 2024-03-09 9040/week @ 2024-03-16 8661/week @ 2024-03-23 8485/week @ 2024-03-30 9273/week @ 2024-04-06 9934/week @ 2024-04-13 7705/week @ 2024-04-20

36,925 downloads per month
Used in 97 crates (4 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