4 releases (breaking)
| 0.4.0 | Sep 20, 2025 |
|---|---|
| 0.3.0 | Sep 20, 2025 |
| 0.2.0 | Sep 14, 2025 |
| 0.1.0 | Dec 27, 2024 |
#1077 in Algorithms
135 downloads per month
35KB
710 lines
Virtual terminal state machine implementation.
This library provides the lowest-level handling of a virtual terminal stream, recognizing escape sequences and other control characters and returning a series of events that should either write to the terminal buffer or modify the terminal's higher-level state.
For example, given the sequence "\x1b[10;10H" this library can report that
this is a control sequence with function character H and the parameters
[10, 10], but it's up to the caller to interpret that as a command
to move the cursor to row 10, column 10.
As with so many libraries like this, the state machine is based on the work of Paul Flo Williams in A parser for DEC’s ANSI-compatible video terminals, though any flaws are mine. This implementation does not aim to be fully compatible with VT100 or its successors. In particular, it implements a Unicode-native machine that does not support legacy character sets.
The main entry point in this crate is VtMachine, which implements the
state machine. Pass each new character to VtMachine::write_u8char, which
then returns a series of events that the character caused.
If you are recieving the terminal data as a byte stream (likely!) then
you can use ::u8char::stream::U8CharStream to translate the incoming
bytes into a series of u8char values to pass to your VtMachine. The
"report" example demonstrates that usage pattern.
Virtual terminal state machine implementation.
This library provides the lowest-level handling of a virtual terminal stream, recognizing escape sequences and other control characters and delivering them to a caller-provided handler.
For example, given the sequence "\x1b[10;10H" this library can report that
this is a control sequence with function character H and the parameters
[10, 10], but it's up to the provided handler to interpret that as a command
to move the cursor to row 10, column 10.
As with so many libraries like this, the state machine is based on the work of Paul Flo Williams in A parser for DEC’s ANSI-compatible video terminals, though any flaws are mine. This implementation does not aim to be fully compatible with VT100 or its successors. In particular, it implements a Unicode-native machine that does not support legacy character sets.
Dependencies
~48KB