package miaou-driver-matrix

  1. Overview
  2. Docs

Module Miaou_driver_matrix.Matrix_ansi_parserSource

ANSI escape sequence parser for the Matrix driver.

Parses ANSI-formatted strings (as produced by MIAOU widgets) into cell buffers. Handles:

  • 256-color foreground/background (ESC38;5;Nm, ESC[48;5;Nm) - Basic colors (ESC[30-37m, ESC[40-47m) - Bold, dim, underline, reverse - Reset (ESC[0m) - UTF-8 characters including multi-byte State Machine: - Normal: reading visible characters - EscapeStart: saw ESC (\027) - CSI: saw ESC[, accumulating parameters until 'm'
Sourcetype t

Parser state, maintains current style across parse calls.

Sourceval create : unit -> t

Create a new parser with default style.

Sourceval reset : t -> unit

Reset parser to initial state (default style).

Sourceval current_style : t -> Matrix_cell.style

Get the current style being applied by the parser.

Sourceval parse_into : t -> Matrix_buffer.t -> row:int -> col:int -> string -> int * int

Parse an ANSI string into the buffer starting at (row, col). Returns the (row, col) after the last written character. Handles newlines by advancing row and resetting col to 0.

Sourceval parse_line : t -> Matrix_buffer.t -> row:int -> col:int -> string -> int

Parse a single line (no newline handling) into buffer. Returns the column after last character.

Sourceval parse_into_batch : t -> Matrix_buffer.batch_ops -> row:int -> col:int -> string -> int * int

Parse into buffer using batch_ops for thread-safe access. Use within Matrix_buffer.with_back_buffer.

Sourceval parse_to_cells : t -> string -> (string * Matrix_cell.style) list

Parse string and return list of (char, style) pairs for inspection. Useful for testing. Does not write to buffer.

Sourceval visible_length : string -> int

Count visible characters in an ANSI string (excluding escape sequences).