[][src]Crate term_parser

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.


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);



An Iterator that returns Actions read from a std::io::Reader.



An action, as described in Paul Williams' ANSI-compatible video terminal parser. To prevent heap allocation, intermediate and param bytes use arrays instead of Vecs. Be sure to only read intermediates_count bytes from intermediates and params_count bytes from params.