#escaping #parser #ansi #action #table #utf-8 #state

yanked term-parser

ANSI escape code parser

0.2.0 Aug 20, 2019
0.1.1 May 5, 2019
0.1.0 May 5, 2019

#125 in #escaping

MIT license

26KB
670 lines

term-parser

term-parser is a Rust crate for parsing ANSI escape codes.

Documentation


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 Actions 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