package matrix
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/matrix.vte/Vte/index.html
Module VteSource
Virtual terminal emulator.
A virtual terminal emulator (VTE) processes raw byte streams containing ANSI/VT100 escape sequences and maintains the resulting terminal state: a visible Grid.t, cursor position, style, scrollback history, and mode flags.
The emulator maintains two screen buffers. The primary screen has optional scrollback history; the alternate screen is a temporary buffer used by full-screen applications like vi or less and never accumulates scrollback. The VTE automatically switches between buffers in response to DECSET/DECRST sequences.
Dirty tracking. Grid, cursor, and style mutations flip a dirty flag (see is_dirty and dirty_rows). Metadata changes such as title updates or mode toggles do not mark the VTE dirty; track those separately if you display them.
Thread safety. Values of type t are mutable and not thread-safe.
Invariants
- Cursor row satisfies
0 <= row < rows t. Column satisfies0 <= col <= cols t;col = cols tencodes the pending-wrap column required by DECAWM. - Scroll region is always within [
0;{!rows} - 1]. - The active grid is either primary or alternate, never both.
- Scrollback only accumulates on the primary screen.
The type for virtual terminal emulators.
Constructors
val create :
?scrollback:int ->
?glyph_pool:Glyph.Pool.t ->
?width_method:Glyph.width_method ->
?respect_alpha:bool ->
?default_fg:Ansi.Color.t ->
?default_bg:Ansi.Color.t ->
rows:int ->
cols:int ->
unit ->
tcreate ~rows ~cols () is a VTE with the given dimensions and:
scrollbackis the maximum number of scrollback lines stored in a ring buffer. Defaults to10000. Use0to disable. Only applies to the primary screen.glyph_poolis a shared grapheme pool for multi-width character storage. If omitted a fresh pool is created and shared between both grids and the scrollback.width_methodis the grapheme width computation method. Defaults to`Unicode. SeeGlyph.width_method.respect_alphaenables alpha blending for semi-transparent colours. Defaults tofalse.default_fgis the opaque foreground colour used when the current style has no explicit foreground. Defaults toAnsi.Color.white.default_bgis the opaque background colour used when the current style has no explicit background, and for clearing grids on resize or reset. Defaults toAnsi.Color.black.
rows and cols are clamped to a minimum of 1. The returned VTE has both screens cleared with default_bg, cursor at (0, 0) and visible, auto-wrap on, all other modes off, and the scroll region spanning the full screen.
Terminal dimensions
resize t ~rows ~cols resizes both grids to the given dimensions. Both grids are cleared after the resize. Cursor and scroll region are clamped to the new bounds. Scrollback content is preserved; compressed lines adapt to the new width during decompression.
rows and cols are clamped to a minimum of 1. Marks all rows dirty.
Input processing
feed t buf ofs len processes len bytes starting at offset ofs in buf as terminal input.
Accepts partial and interleaved text/escape sequences. Invalid or unrecognised sequences are silently ignored. Updates the active grid, cursor, title, style, and mode flags.
ofs and len must satisfy 0 <= ofs and ofs + len <= Bytes.length buf. Out-of-bounds access is undefined behaviour.
O(len), amortised constant time per byte.
feed_string t s is feed t (Bytes.unsafe_of_string s) 0 (String.length s).
Terminal state
grid t is the active visible grid (primary or alternate).
Warning. The grid is mutable and shared with t. External modifications break dirty tracking and may cause rendering inconsistencies.
is_alternate_screen t is true iff the alternate screen is active. Switched via DECSET/DECRST 47, 1047, or 1049.
Defaults to false.
Dirty tracking
is_dirty t is true iff grid, cursor, or style state changed since the last clear_dirty.
Note. OSC title updates and mode toggles do not flip the dirty flag.
dirty_rows t is the list of zero-based row indices modified since the last clear_dirty, sorted ascending. O(k) where k is the number of dirty rows.
is_cursor_dirty t is true iff cursor position or visibility changed since the last clear_dirty.
clear_dirty t resets the dirty flag, dirty row set, and cursor dirty flag. Does not alter content.
Cursor
cursor_pos t is the cursor position (row, col). Satisfies 0 <= row < rows t and 0 <= col <= cols t. col can equal cols t in pending-wrap state when auto-wrap is enabled.
cursor_visible t is true iff the cursor is visible. Controlled via DECTCEM (CSI ?25h/l). Defaults to true.
set_cursor_pos t ~row ~col moves the cursor. row is clamped to [0, rows-1], col to [0, cols]. Marks cursor dirty if the position changes.
set_cursor_visible t v shows or hides the cursor. Marks cursor dirty if visibility changes.
Scrollback
scrollback_capacity t is the maximum number of scrollback lines. 0 if scrollback is disabled.
scrollback_size t is the current number of lines in the scrollback buffer. 0 if scrollback is disabled, empty, or the alternate screen is active. Satisfies 0 <= scrollback_size t <= scrollback_capacity t.
scrollback_lines t is the scrollback content as plain-text strings ordered oldest to newest. Style information is discarded. Trailing spaces are trimmed during compression. Empty if scrollback is disabled, empty, or the alternate screen is active. O(scrollback_size).
render_with_scrollback t ~offset dst renders a snapshot combining scrollback history and the live screen into dst.
The top rows of dst are filled with scrollback lines (oldest at the top) and the remaining rows with the current screen. offset is the number of lines above the live screen the snapshot extends: 0 shows only the live terminal. offset is clamped to [0, scrollback_size].
dst should have the same width as t for correct glyph placement; smaller widths clip decompressed graphemes. On the alternate screen (no scrollback) this is equivalent to Grid.blit ~src:(grid t) ~dst.
O(Grid.height dst × cols).
Terminal modes
auto_wrap_mode t is true iff auto-wrap (DECAWM) is active. When enabled, writing past the right margin wraps to the next line. Controlled via CSI ?7h/l. Defaults to true.
insert_mode t is true iff insert mode (IRM) is active. Characters push existing content right instead of replacing it. Controlled via CSI 4h/l. Defaults to false.
cursor_key_mode t is true iff cursor keys use application mode (DECCKM). Application mode sends ESC O A instead of ESC [ A for arrow keys. Controlled via CSI ?1h/l. Defaults to false.
bracketed_paste_mode t is true iff bracketed paste is active. Pasted text is wrapped with ESC [ 200 ~ / ESC [ 201 ~ markers. Controlled via CSI ?2004h/l. Defaults to false.
origin_mode t is true iff origin mode (DECOM) is active. In origin mode, CUP/HVP coordinates are relative to the scroll region.
Note. DECOM handling is not wired yet; this accessor always returns false in the current release.
Scrolling
scroll_up t n scrolls the current scroll region up by n lines. Lines leaving the top enter scrollback only when the primary screen is active, scrollback is enabled, and the region starts at row 0. Newly exposed rows are cleared with the default transparent background. No effect if n <= 0.
Marks all rows in the scroll region dirty.
scroll_down t n scrolls the current scroll region down by n lines. Blank rows are inserted at the top; lines leaving the bottom are discarded (never saved to scrollback). No effect if n <= 0.
Marks all rows in the scroll region dirty.
See also scroll_up.
Terminal control
reset t resets t to its initial state. Clears both grids and scrollback, moves cursor to (0, 0) and makes it visible, resets style to default, sets auto-wrap on and all other modes off, resets scroll region to full screen, and switches to the primary screen. Dimensions are unchanged. Equivalent to RIS (ESC c).
Marks all rows dirty.