package matrix

  1. Overview
  2. Docs
Fast, modern terminal toolkit for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.1.0.tbz
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9

doc/matrix.input/Input/Parser/index.html

Module Input.ParserSource

Incremental input parser. See Parser.

Incremental input parser.

Consumes raw terminal bytes and emits user-facing events (Event.t) and capability responses (Event.Caps.event) through callbacks. A single parser instance drives both streams so callers do not need to run two parsers over the same bytes.

Warning. Not thread-safe; use one instance per input source.

Parsers

Sourcetype t

The type for parser state.

Sourceval create : unit -> t

create () is a fresh parser with empty buffers.

Feeding

Sourceval feed : t -> bytes -> int -> int -> now:float -> on_event:(Input__.Event.t -> unit) -> on_caps:(Input__.Event.Caps.event -> unit) -> unit

feed p buf off len ~now ~on_event ~on_caps consumes len bytes from buf starting at offset off.

Each parsed user event is passed to on_event; each capability response is passed to on_caps. Incomplete escape sequences are buffered and combined with subsequent calls.

now is the current time in seconds since the epoch, used to schedule flush deadlines for ambiguous sequences.

Draining

Sourceval drain : t -> now:float -> on_event:(Input__.Event.t -> unit) -> on_caps:(Input__.Event.Caps.event -> unit) -> unit

drain p ~now ~on_event ~on_caps emits any pending escape sequences whose deadline has passed. A lone Event.Key.Escape only appears after this drain when the terminal splits a modifier sequence across reads. Call after deadline has elapsed.

Sourceval deadline : t -> float option

deadline p is the absolute timestamp (seconds since the epoch) at which the next drain should fire, or None when no drain is scheduled.

State

Sourceval pending : t -> bytes

pending p is a copy of the incomplete data buffered so far. Useful for diagnostics and tests.

Sourceval reset : t -> unit

reset p clears all parser state, dropping any buffered partial sequences and capability tracking.