#ansi #escape #terminal

no-std ansitok

A library for parsing ANSI Escape Codes

2 unstable releases

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

#859 in Parser implementations

Download history 5635/week @ 2023-01-29 10532/week @ 2023-02-05 13189/week @ 2023-02-12 8891/week @ 2023-02-19 8267/week @ 2023-02-26 7980/week @ 2023-03-05 7704/week @ 2023-03-12 6005/week @ 2023-03-19 8085/week @ 2023-03-26 6496/week @ 2023-04-02 5956/week @ 2023-04-09 6139/week @ 2023-04-16 5761/week @ 2023-04-23 5339/week @ 2023-04-30 4266/week @ 2023-05-07 6220/week @ 2023-05-14

21,861 downloads per month
Used in 46 crates (4 directly)

MIT license

56KB
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
~20K SLoC