package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.canvas/Miaou_canvas/Canvas/index.html
Module Miaou_canvas.CanvasSource
Canvas — a driver-agnostic, cell-level 2D surface for TUI rendering.
A canvas is a mutable grid of cells, where each cell holds a UTF-8 grapheme cluster and a style (foreground/background color, bold, dim, underline, reverse).
Canvases can be rendered to ANSI strings via to_ansi for use with the existing view pipeline, or iterated over via iter so that a driver can transfer cells to its own buffer format (e.g. the matrix driver's Matrix_buffer).
Types
type style = {fg : int;(*Foreground color,
*)-1= defaultbg : int;(*Background color,
*)-1= defaultbold : bool;dim : bool;underline : bool;reverse : bool;
}Visual style for a single cell.
Colors use 256-color palette indices: -1 means "default terminal color", 0–255 are the standard 256-color palette values.
A mutable 2D grid of cells.
Border drawing styles for draw_box.
Border character set used by draw_box. Exposed so callers can supply custom border glyphs via draw_box_with_chars.
Placement and blend mode for one compositing layer.
Constants
An empty cell: a single space with default_style.
Creation
create ~rows ~cols allocates a canvas filled with empty_cell.
Dimensions
Cell access
set_char t ~row ~col ~char ~style sets the cell at (row, col). Out-of-bounds writes are silently ignored.
get_cell t ~row ~col returns the cell at (row, col).
Drawing primitives
val fill_rect :
t ->
row:int ->
col:int ->
width:int ->
height:int ->
char:string ->
style:style ->
unitfill_rect t ~row ~col ~width ~height ~char ~style fills a rectangular region. Out-of-bounds portions are clipped.
clear t resets every cell to empty_cell.
draw_text t ~row ~col ~style text writes a plain-text string horizontally starting at (row, col). Each UTF-8 grapheme cluster occupies one cell. The text must not contain ANSI escape sequences. Out-of-bounds portions are clipped.
draw_hline t ~row ~col ~len ~char ~style draws a horizontal line.
draw_vline t ~row ~col ~len ~char ~style draws a vertical line.
val draw_box :
t ->
row:int ->
col:int ->
width:int ->
height:int ->
border:border_style ->
style:style ->
unitdraw_box t ~row ~col ~width ~height ~border ~style draws a rectangular border. The border occupies 1 cell on each side, so the interior is (width - 2) x (height - 2). Boxes smaller than 2x2 are silently ignored.
val draw_box_with_chars :
t ->
row:int ->
col:int ->
width:int ->
height:int ->
chars:border_chars ->
style:style ->
unitdraw_box_with_chars t ~row ~col ~width ~height ~chars ~style draws a box using custom border characters.
Composition
blit ~src ~dst ~row ~col copies non-empty cells from src onto dst at offset (row, col). Only cells whose char is not " " (space) are copied, making spaces transparent. Out-of-bounds portions are clipped.
blit_all ~src ~dst ~row ~col copies all cells from src onto dst at offset (row, col), including spaces. Out-of-bounds portions are clipped.
compose_new ~rows ~cols ~layers creates a new empty canvas and applies compose with layers.
Output
to_ansi t renders the canvas to an ANSI-escaped string suitable for terminal display. Rows are separated by newlines. Style changes are tracked so that SGR codes are only emitted when the style actually changes between cells.
to_ansi_with_defaults ~default_fg ~default_bg t renders the canvas with fallback colors for cells that don't specify fg/bg (i.e., -1). Use this to ensure canvas content is visible regardless of terminal theme - pass the current theme's text and background colors.
Iteration
iter t ~f calls f ~row ~col cell for every cell in row-major order. This is the primary integration point for drivers: iterate the canvas and transfer cells to the driver's own buffer format.
Border utilities
border_chars_of_style style returns the character set for a given border style.