Class VtParser
java.lang.Object
org.aesh.terminal.parser.VtParser
Table-driven ANSI/VT escape sequence parser based on Paul Flo Williams'
DEC-compatible parser.
The parser uses a pre-computed short[14][256] transition table where
each entry encodes (action << 4) | nextState. This guarantees
completeness (every byte in every state has a defined transition) and
correctness (matches DEC VT220-VT525 observable behavior).
Deviations from Williams:
- Colon (0x3A) is treated as a subparameter separator in CSI/DCS
sequences, not as an error. This is required for SGR extended
color sequences (
38:2:R:G:B). - BEL (0x07) terminates OSC strings (xterm convention).
Usage:
VtParser parser = new VtParser(new VtHandler() {
public void csiDispatch(int finalChar, int[] params, int paramCount,
int[] intermediates, int intermediateCount,
boolean hasSubParams) {
// handle CSI sequence
}
// ... other callbacks
});
parser.advance(bytes, 0, length);
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance(byte[] data, int offset, int length) Advances the parser with a block of input bytes.voidadvance(int b) Advances the parser with a single byte or code point.voidadvance(int[] codePoints, int offset, int length) Advances the parser with a block of code points.voidreset()Resets the parser to ground state.
-
Constructor Details
-
VtParser
Creates a new parser with the given handler.- Parameters:
handler- the callback handler for parsed sequences
-
-
Method Details
-
advance
public void advance(byte[] data, int offset, int length) Advances the parser with a block of input bytes.- Parameters:
data- the input bytesoffset- the start offsetlength- the number of bytes to process
-
advance
public void advance(int[] codePoints, int offset, int length) Advances the parser with a block of code points. Code points > 255 are treated as printable characters in the ground state and as ignored characters in other states.- Parameters:
codePoints- the input code pointsoffset- the start offsetlength- the number of code points to process
-
advance
public void advance(int b) Advances the parser with a single byte or code point. Values 0-255 use the transition table directly. Values > 255 are treated as printable in ground state, ignored otherwise.- Parameters:
b- the byte (0-255) or code point (> 255)
-
reset
public void reset()Resets the parser to ground state.
-