16 unstable releases (7 breaking)

0.8.0 Apr 25, 2021
0.7.0 Oct 5, 2020
0.6.5 May 10, 2019
0.5.3 May 4, 2019
0.1.0 Apr 27, 2019

#620 in Parser implementations

Download history 1890/week @ 2022-06-09 1965/week @ 2022-06-16 1862/week @ 2022-06-23 2188/week @ 2022-06-30 1637/week @ 2022-07-07 2610/week @ 2022-07-14 1325/week @ 2022-07-21 1072/week @ 2022-07-28 877/week @ 2022-08-04 725/week @ 2022-08-11 814/week @ 2022-08-18 534/week @ 2022-08-25 828/week @ 2022-09-01 1127/week @ 2022-09-08 713/week @ 2022-09-15 680/week @ 2022-09-22

3,406 downloads per month
Used in 15 crates (8 directly)

MPL-2.0 license

26KB
706 lines

pipeline status docs deps license downloads

Ansi Escape Sequence Parser

For a complete list of implemented sequences, see the documentation.

This is done through a pulldown type parser, where an iterator is exposed. This essentially turns all of the ANSI sequences into enums and splits the string at every location that there was an ANSI Sequence.

Example:

use ansi_parser::{Output, AnsiParser};
use ansi_parser::AnsiSequence;

fn main() {
    //Parse the first two blocks in the list
    //By parsing it this way, it allows you to iterate over the
    //elements returned.
    //
    //The parser only every holds a reference to the data,
    //so there is no allocation.
    let parsed: Vec<Output> = "This is \u{1b}[3Asome text!"
        .ansi_parse()
        .take(2)
        .collect();

    assert_eq!(
        vec![
            Output::TextBlock("This is "),
            Output::Escape(AnsiSequence::CursorUp(3))
        ],
        parsed
    );

    for block in parsed.into_iter() {
        match block {
            Output::TextBlock(text) => println!("{}", text),
            Output::Escape(seq)     => println!("{}", seq)
        }
    }
}

no_std support

no_std is supported via disabling the std feature in your Cargo.toml.

Dependencies

~1.5MB
~29K SLoC