10 releases

0.2.0 Nov 27, 2023
0.1.6 Nov 29, 2019
0.1.4 Oct 31, 2019
0.0.2 Oct 25, 2019

#102 in Parser implementations

Download history 177207/week @ 2023-12-23 293587/week @ 2023-12-30 368002/week @ 2024-01-06 403147/week @ 2024-01-13 429776/week @ 2024-01-20 400941/week @ 2024-01-27 399636/week @ 2024-02-03 404316/week @ 2024-02-10 405503/week @ 2024-02-17 429764/week @ 2024-02-24 405896/week @ 2024-03-02 404811/week @ 2024-03-09 413600/week @ 2024-03-16 413566/week @ 2024-03-23 444781/week @ 2024-03-30 360998/week @ 2024-04-06

1,697,172 downloads per month
Used in 2,680 crates (3 directly)

MIT/Apache

82KB
1.5K SLoC

Stable Status Beta Status Nightly Status crates.io docs.rs MIT Apache 2.0 LOC

ANSI Escape Sequences provider & parser

A Rust library which provides an ANSI escape sequences (or codes, whatever you like more) and a parser allowing you to parse data from the STDIN (or /dev/tty) in the raw mode.

Sequences provider

Terminal support

Not all ANSI escape sequences are supported by all terminals. You can use the interactive-test to test them. Checkout the repository and then:

$ cd anes-rs
$ cargo run --bin interactive-test

Examples

Click to show Cargo.toml.
[dependencies]
anes = "0.1"

An example how to retrieve the ANSI escape sequence as a String:

use anes::SaveCursorPosition;

fn main() {
    let string = format!("{}", SaveCursorPosition);
    assert_eq!(&string, "\x1B7");
}

An example how to use the ANSI escape sequence:

use std::io::{Result, Write};

use anes::execute;

fn main() -> Result<()> {
    let mut stdout = std::io::stdout();
    execute!(
        &mut stdout,
        anes::SaveCursorPosition,
        anes::MoveCursorTo(10, 10),
        anes::RestoreCursorPosition
    )?;
    Ok(())
}

Sequences parser

You have to enable parser feature in order to use the parser. It's disabled by default.

Examples

Click to show Cargo.toml.
[dependencies]
anes = { version = "0.1", features = ["parser"] }

An example how to parse cursor position:

use anes::parser::{Parser, Sequence};

let mut parser = Parser::default();
parser.advance(b"\x1B[20;10R", false);

assert_eq!(Some(Sequence::CursorPosition(10, 20)), parser.next());
assert!(parser.next().is_none());

License

The ANES crate is dual-licensed under Apache 2.0 and MIT terms.

Copyrights in the ANES project are retained by their contributors. No copyright assignment is required to contribute to the ANES project.

Dependencies