2 unstable releases

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

#1404 in Parser implementations

Download history 10586/week @ 2024-06-19 10583/week @ 2024-06-26 10286/week @ 2024-07-03 9168/week @ 2024-07-10 12392/week @ 2024-07-17 13671/week @ 2024-07-24 12981/week @ 2024-07-31 11954/week @ 2024-08-07 10989/week @ 2024-08-14 11606/week @ 2024-08-21 11277/week @ 2024-08-28 11890/week @ 2024-09-04 10798/week @ 2024-09-11 11359/week @ 2024-09-18 12598/week @ 2024-09-25 10502/week @ 2024-10-02

47,224 downloads per month
Used in 119 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