0.2.0 |
|
---|---|
0.1.1 |
|
0.1.0 |
|
#129 in #escaping
26KB
670 lines
term-parser
term-parser
is a Rust crate for parsing ANSI escape codes.
lib.rs
:
term-parser
is a Rust crate for parsing ANSI escape codes.
The parser is based on Paul Williams' ANSI-compatible video terminal parser modified to support UTF-8 input.
The implementation uses a static state transition table to minimize branches.
Usage
To read escape codes, create an ActionIter
from any std::io::Read
and consume the Action
s the iterator returns.
This crate comes with a "logger" example that will print a description of the actions produced by stdin.
To give it a try, run the following:
echo -n "\x1b[30mhello\x1b[0m" | cargo run --example logger
Below is the source for the logger example, which demonstrates how to read escape codes:
fn main() {
let stdin = std::io::stdin();
let stdin = stdin.lock();
let stdin = std::io::BufReader::new(stdin);
let action_iter = term_parser::ActionIter::new(stdin);
for action in action_iter {
println!("{:?}", action);
}
}
Dependencies
~10KB