package matrix
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/matrix.ansi/Ansi/Parser/index.html
Module Ansi.ParserSource
Streaming escape sequence parser.
Streaming ANSI escape sequence parser.
Converts byte streams into high-level tokens representing ANSI escape sequences, SGR attributes, and plain text. The parser handles partial input: incomplete escape sequences and UTF-8 multi-byte characters at chunk boundaries are buffered until the next feed call.
Parsing never raises on malformed input. Unrecognized sequences become Unknown controls and invalid UTF-8 is replaced with U+FFFD. Maximum sequence lengths (max_escape_length for CSI, max_osc_length for OSC) prevent unbounded buffering.
Tokens
type control = | CUU of int(*Cursor Up by
*)nlines.| CUD of int(*Cursor Down by
*)nlines.| CUF of int(*Cursor Forward by
*)ncolumns.| CUB of int(*Cursor Backward by
*)ncolumns.| CNL of int(*Cursor Next Line (down
*)n, column 1).| CPL of int(*Cursor Previous Line (up
*)n, column 1).| CHA of int(*Cursor Horizontal Absolute to column
*)n.| VPA of int(*Vertical Position Absolute to row
*)n.| CUP of int * int(*Cursor Position to
*)(row, col).| ED of int(*Erase in Display.
*)| EL of int(*Erase in Line.
*)| IL of int(*Insert
*)nblank Lines.| DL of int(*Delete
*)nLines.| DCH of int(*Delete
*)nCharacters.| ICH of int(*Insert
*)nblank Characters.| OSC of int * string(*Generic OSC with code and payload.
*)| Hyperlink of ((string * string) list * string) option(*OSC 8 hyperlink.
*)Nonecloses the current hyperlink.Some (params, url)opens one, whereparamsare key=value pairs from the parameter string.| Reset(*RIS — reset to initial state (
*)ESC c).| DECSC(*Save cursor position (
*)ESC 7).| DECRC(*Restore cursor position (
*)ESC 8).| Unknown of string(*Unrecognized sequence, preserved as raw bytes.
*)
The type for control sequences other than SGR.
type sgr_attr = [ | `Reset| `Bold| `Dim| `Italic| `Underline| `Double_underline| `Blink| `Inverse| `Hidden| `Strikethrough| `Overline| `Framed| `Encircled| `No_bold| `No_dim| `No_italic| `No_underline| `No_blink| `No_inverse| `No_strikethrough| `No_overline| `No_framed| `No_encircled| `Fg of Color.t| `Bg of Color.t
]The type for SGR (Select Graphic Rendition) attributes. Represents individual style changes from a single SGR sequence. A sequence like ESC [ 1 ; 31 m produces [`Bold; `Fg Red].
The type for parsed tokens.
Parsers
The type for parsers. Mutable and not thread-safe.
reset p clears internal buffers and returns p to the default state. Discards buffered partial sequences.
Feeding
feed p buf ~off ~len f processes len bytes from buf starting at off, calling f for each complete token. Incomplete sequences are buffered until the next call.
parse s parses a complete string into tokens. Creates a temporary parser. Not suitable for streaming; use feed.
Inspection
has_pending p is true iff p has buffered data (incomplete escape sequences or pending UTF-8 bytes).
pending p is a copy of raw input bytes not yet consumed. Escape sequence bodies being accumulated (CSI parameters, OSC payloads) are stored in separate internal buffers and are not included. Use has_pending to avoid allocation when only checking for pending data.