Crate vt_push_parser

Crate vt_push_parser 

Source
Expand description

A streaming push parser for the VT/xterm protocol.

Use VTPushParser::feed_with to feed bytes into the parser, handling the VTEvents as they are emitted.

use vt_push_parser::VTPushParser;
use vt_push_parser::event::VTEvent;

let mut parser = VTPushParser::new();
let mut output = String::new();
parser.feed_with(b"\x1b[32mHello, world!\x1b[0m", &mut |event: VTEvent| {
    output.push_str(&format!("{:?}", event));
});
assert_eq!(output, "Csi('32', '', 'm')Raw('Hello, world!')Csi('0', '', 'm')");

§Interest

The parser can be configured to only emit certain types of events by setting the INTEREST parameter. Other event types will be parsed and discarded.

For example, to only emit CSI (and Raw) events:

use vt_push_parser::{VTPushParser, VT_PARSER_INTEREST_CSI};

let mut parser = VTPushParser::new_with_interest::<VT_PARSER_INTEREST_CSI>();

§Input parsing

This crate is designed to be used for parsing terminal output, but it can also be used for parsing input. Input is not always well-formed, however and may contain mode-switching escapes that require the parser to turn off its normal parsing behaviours (ie: bracketed-paste mode, xterm mouse events, etc).

The capture::VTCapturePushParser is useful for parsing input that may work in this way.

Modules§

ascii
ASCII control codes.
capture
Raw-input-capturing push parser.
event
Event types.
iter
Iterator wrapper around VTPushParser.
signature
Escape sequence signature matching.

Structs§

VTPushParser
A push parser for the VT/xterm protocol.

Constants§

VT_PARSER_INTEREST_ALL
Request all events from parser.
VT_PARSER_INTEREST_CSI
Request CSI events from parser.
VT_PARSER_INTEREST_DCS
Request DCS events from parser.
VT_PARSER_INTEREST_DEFAULT
Default interest level.
VT_PARSER_INTEREST_ESCAPE_RECOVERY
Request escape recovery events from parser.
VT_PARSER_INTEREST_NONE
No events from parser (ie, only emits VTEvent::Raw events)
VT_PARSER_INTEREST_OSC
Request OSC events from parser.
VT_PARSER_INTEREST_OTHER
Request other events from parser.

Traits§

VTEventCallback
Receives a single VTEvent.
VTEventCallbackAbortable
Receives a single VTEvent, returning a boolean indicating whether to continue parsing (true) or stop parsing (false).