Module Mosaic_mlx Source MLX-compatible wrappers for Mosaic .
This module re-exports the full Mosaic API with child arguments changed from positional to optional, matching the MLX JSX convention where children are passed as ~children.
All types, modules, helpers, and non-overridden elements are inherited unchanged from Mosaic ; see that module for their documentation. Only the elements listed below are overridden.
include module type of Mosaic Re-exportsTerminal ANSI escape sequences: colors (Ansi.Color), styles (Ansi.Style), and attributes (Ansi.Attr).
module Border = Matrix.Grid.Border Border character sets for box-drawing. Provides Border.single, Border.rounded, Border.heavy, Border.double, and Border.ascii.
Input event types for keyboard, mouse, and paste events.
Mutable cell-level drawing surface.
Geometry typesSource type 'a size = 'a Toffee .Geometry.Size.t = { width : 'a ; height : 'a ; } The type for 2-dimensional sizes. See size and size_wh .
Source type 'a rect = 'a Toffee .Geometry.Rect.t = { left : 'a ; right : 'a ; top : 'a ; bottom : 'a ; } Source type 'a point = 'a Toffee .Geometry.Point.t = { x : 'a ; y : 'a ; } The type for 2-dimensional points.
Source type 'a line = 'a Toffee .Geometry.Line.t = { start : 'a ; end_ : 'a ; } Source type dimension = Toffee .Style.Dimension.t The type for CSS dimensions: a fixed length, a percentage, or auto. Create values with px , pct , or auto .
Source type length_percentage = Toffee .Style.Length_percentage.t The type for CSS length-or-percentage values. Produced by helpers such as padding , gap , and gap_xy .
Source type length_percentage_auto = Toffee .Style.Length_percentage_auto.t The type for CSS length-or-percentage-or-auto values. Produced by helpers such as margin , margin_xy , and inset .
A contiguous run of text with a single visual style. Used by code for syntax highlighting via its ~spans argument.
Layout enum modulesCSS display property controlling box generation and child layout algorithm.
CSS position property controlling normal flow participation.
CSS flex-direction property.
Alignment along the cross/block axis (align-items, align-self, justify-items, justify-self).
Distribution of space between and around content items (align-content, justify-content).
CSS grid-auto-flow property.
Grid moduleGrid layout constructors for defining tracks and placing items.
Companion types for the select widget.
Companion types for the table widget.
Companion types for the tree widget.
Companion types for the spinner widget.
Companion types for the slider widget.
Companion types for the markdown widget.
Syntax themes: maps capture-group names to terminal styles.
ViewsThe type for view nodes parameterized by message type 'msg. Event handlers embedded in a node return 'msg option: Some msg dispatches the message into the update loop; None ignores the event.
Build values of this type with the element constructors (box , text , input , etc.) and compose them with fragment .
Source val map : ('a -> 'b ) -> 'a t -> 'b t map f view is view with every message transformed by f.
Use map to embed a child component whose message type differs from the parent's.
CommandsSide-effects issued by the application.
SubscriptionsOngoing event interests declared by the application.
ApplicationSource type ('model, 'msg) app = { init : unit -> 'model * 'msg Cmd.t ; init () is the initial model and any startup commands. Called once before the first render.
update : 'msg -> 'model -> 'model * 'msg Cmd.t ; update msg model is the new model and any side-effects produced in response to msg. Called once per dispatched message.
view : 'model -> 'msg t ; view model is the UI description for model. Called on every render cycle when the model has changed.
subscriptions : 'model -> 'msg Sub.t ; subscriptions model is the set of events the application wants to receive given model. Re-evaluated after every update.
} The type for a Mosaic application. Provide a value of this type to run .
RunningSource val run :
?matrix :Matrix.app ->
?process_perform :((unit -> unit) -> unit) ->
('model , 'msg ) app ->
unitrun ?matrix ?process_perform app starts app and blocks until the application exits (via Cmd.quit or an OS signal).
matrix -- the low-level terminal backend. Defaults to a backend with target_fps = Some 60. and a hidden cursor.process_perform -- controls how Cmd.t.Perform callbacks are executed. Receives a thunk that wraps the user callback with the dispatch function already wired in. The default spawns a native Thread per callback so that long-running operations (e.g. HTTP requests) never block the UI loop.Eio integration. Pass a matrix and process_perform built with the matrix_eio library:
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let matrix =
Matrix_eio.create ~sw ~clock:(Eio.Stdenv.clock env) ~stdin:env#stdin
~stdout:env#stdout ()
in
let process_perform thunk =
Eio.Fiber.fork_daemon ~sw (fun () ->
thunk ();
`Stop_daemon)
in
Mosaic.run ~matrix ~process_perform { init; update; view; subscriptions }Daemon fibers are cancelled when the switch completes, so long-running perform operations do not block application shutdown.
Dimension helperspx n is a dimension of exactly n terminal columns or rows.
pct n is a dimension of n percent of the parent's available space.
auto is the automatic dimension, letting the layout engine determine the size.
size ~width ~height is a fixed size with the given width and height measured in terminal cells.
size_wh w h is a size with the given w width and h height dimensions.
gap n is a uniform gap of n cells applied to both axes of a flex or grid container.
gap_xy x y is a gap of x cells on the horizontal axis and y cells on the vertical axis.
padding n is a uniform padding of n cells on all four sides.
padding_xy x y is padding of x cells on the left and right sides and y cells on the top and bottom sides.
padding_lrtb l r t b is padding of l cells on the left, r on the right, t on the top, and b on the bottom.
margin n is a uniform margin of n cells on all four sides.
margin_xy x y is margin of x cells on the left and right sides and y cells on the top and bottom sides.
margin_lrtb l r t b is margin of l cells on the left, r on the right, t on the top, and b on the bottom.
inset n is a uniform inset of n cells on all four sides, used with position = `Absolute or position = `Fixed.
inset_lrtb l r t b is inset of l cells on the left, r on the right, t on the top, and b on the bottom.
UI elementsEvery element constructor accepts a large set of optional layout and styling arguments that mirror CSS flexbox and grid properties. Arguments shared across all elements are listed once here; only element-specific arguments are documented on each constructor.
Common layout argumentskey -- reconciler identity hint for list items.id -- unique identifier used by Cmd.focus .display -- layout mode (Display.t.Flex , Display.t.Grid , Display.t.Block , ...).box_sizing -- whether size includes padding and border.position -- positioning scheme (Position.t.Relative , Position.t.Absolute ).overflow -- how overflowing content is handled per axis.scrollbar_width -- width reserved for overflow scrollbars.text_align -- text alignment within the element.inset -- position offsets for absolutely-positioned elements.flex_direction, flex_wrap, justify_content, align_items, align_content, align_self, flex_grow, flex_shrink, flex_basis -- flexbox properties.justify_items, justify_self -- grid alignment properties.size, min_size, max_size -- element dimensions.aspect_ratio -- width-to-height ratio constraint.gap -- spacing between flex or grid children.padding -- inner spacing between border and content.margin -- outer spacing outside the border.border_width -- widths of each border side in cells.grid_template_rows, grid_template_columns, grid_auto_rows, grid_auto_columns, grid_auto_flow, grid_template_areas, grid_template_column_names, grid_template_row_names, grid_row, grid_column -- CSS grid properties.visible -- when false the element takes no space and is not rendered. Defaults to true.z_index -- stacking order for overlapping elements.opacity -- alpha in [0.;1.]; 1. is fully opaque.focusable -- when true the element can receive keyboard focus. Defaults to false.autofocus -- when true the element receives focus on mount. Defaults to false.buffered -- when true renders to an off-screen buffer. Defaults to false.live -- when true the element re-renders every frame even when the model has not changed. Defaults to false.ref -- callback invoked with the rendered Mosaic_ui.Renderable.t after each frame.on_mouse -- mouse event handler for this element.on_key -- key event handler for this element.on_paste -- paste event handler for this element.empty is the empty view that renders nothing and occupies no space. Useful as a placeholder.
embed r wraps a pre-rendered Mosaic_ui.Renderable.t as a view node. Use this to integrate non-TEA rendering into the view tree.
slider () is an interactive range slider.
Slider-specific optional arguments:
orientation -- `Horizontal or `Vertical. Defaults to `Horizontal.value -- current thumb position. Defaults to 0..min -- minimum value of the range. Defaults to 0..max -- maximum value of the range. Defaults to 1..viewport_size -- size of the visible viewport relative to the total range; used to size the thumb proportionally.track_color -- color of the slider track.thumb_color -- color of the slider thumb.on_value_change -- callback fired when the value changes; receives the new value and returns an optional message.select items is a vertical list from which the user can choose one item.
See tab_select for a horizontal tab-bar variant.
Select-specific optional arguments:
selected_index -- zero-based index of the highlighted item. Defaults to 0.background -- background color of unselected items.text_color -- foreground color of unselected items.focused_background -- background when the widget has focus.focused_text_color -- foreground when the widget has focus.selected_background -- background of the selected item.selected_text_color -- foreground of the selected item.description_color -- color of item description text.selected_description_color -- description color for the selected item.show_description -- when true shows item descriptions. Defaults to true.show_scroll_indicator -- when true shows a scroll indicator when the list overflows. Defaults to false.wrap_selection -- when true wraps the selection from the last item back to the first and vice versa. Defaults to false.item_spacing -- number of blank lines between items. Defaults to 0.fast_scroll_step -- number of items skipped per fast-scroll action (e.g. Page Down). Defaults to 5.on_change -- fired when the highlighted index changes; receives the new index.on_activate -- fired when the user confirms the selection (e.g. by pressing Enter); receives the confirmed index.tab_select items is a horizontal tab-bar selector.
See select for the vertical list variant.
Tab-select-specific optional arguments:
selected -- zero-based index of the active tab. Defaults to 0.tab_width -- fixed width for each tab in cells. Defaults to 12.background -- background color of inactive tabs.text_color -- foreground color of inactive tabs.focused_background -- background when the widget has focus.focused_text_color -- foreground when the widget has focus.selected_background -- background of the active tab.selected_text_color -- foreground of the active tab.description_color -- color of tab description text.selected_description_color -- description color for the active tab.show_underline -- when true draws an underline below tabs. Defaults to true.show_description -- when true shows tab descriptions. Defaults to false.show_scroll_arrows -- when true shows arrows when tabs overflow the available width. Defaults to true.wrap_selection -- when true wraps from the last tab to the first and vice versa. Defaults to false.on_change -- fired when the active tab index changes.on_activate -- fired when the user confirms the tab selection.canvas draw is a free-form drawing surface. draw c ~delta is called on every frame with a fresh Canvas.t c and the elapsed time delta in seconds since the previous frame. The canvas fills its allocated layout area.
Canvas-specific optional arguments:
respect_alpha -- when true the canvas composites with alpha blending. Defaults to true.spinner () is an animated activity indicator.
Spinner-specific optional arguments:
frame_set -- the animation frame sequence. Defaults to Spinner.dots .color -- foreground color of the spinner character. Defaults to white.progress_bar () is a read-only progress indicator.
Progress-bar-specific optional arguments:
value -- current progress value. Defaults to 0..min -- value representing 0% progress. Defaults to 0..max -- value representing 100% progress. Defaults to 1..orientation -- `Horizontal or `Vertical. Defaults to `Horizontal.filled_color -- color of the filled portion of the bar. Defaults to medium gray.empty_color -- color of the unfilled portion of the bar. Defaults to dark gray.scroll_bar () is a standalone scroll-bar widget. Use this when you manage scroll state externally; for automatic scrolling consider scroll_box instead.
Scroll-bar-specific optional arguments:
orientation -- `Horizontal or `Vertical. Defaults to `Vertical.show_arrows -- when true renders arrow buttons at each end. Defaults to false.track_color -- color of the scroll track. Defaults to dark gray.thumb_color -- color of the scroll thumb. Defaults to medium gray.arrow_fg -- foreground color of the arrow buttons. Defaults to white.arrow_bg -- background color of the arrow buttons. Defaults to the terminal default.on_change -- fired when the scroll position changes; receives the new position in scroll units.table () is a scrollable data table.
Table-specific optional arguments:
columns -- column definitions (Table.column ), including headers and sizing. Defaults to [].rows -- table data as a list of cell arrays. Each array must have the same length as columns. Defaults to [].selected_row -- zero-based index of the highlighted row. Defaults to 0.border -- when true draws an outer border. Defaults to true.border_style -- character set for the outer border. Defaults to Border.single.show_header -- when true renders a header row. Defaults to true.show_column_separator -- when true draws vertical lines between columns. Defaults to false.show_row_separator -- when true draws horizontal lines between rows. Defaults to false.cell_padding -- horizontal padding in cells within each cell. Defaults to 0.header_color -- foreground color of the header row.header_background -- background color of the header row.text_color -- foreground color of body cells.background -- background color of body cells.selected_text_color -- foreground of the selected row.selected_background -- background of the selected row.focused_selected_text_color -- foreground of the selected row when the table has focus.focused_selected_background -- background of the selected row when the table has focus.row_styles -- repeating list of styles applied to body rows, useful for alternating row colors.wrap_selection -- when true wraps selection past the last or first row. Defaults to false.fast_scroll_step -- rows skipped per fast-scroll action. Defaults to 5.on_change -- fired when the selected row index changes.on_activate -- fired when the user confirms the selected row (e.g. by pressing Enter).tree () is an interactive collapsible tree view.
Tree-specific optional arguments:
items -- the root-level Tree.item nodes. Defaults to [].selected_index -- zero-based flat index of the highlighted item. Defaults to 0.expand_depth -- number of levels expanded on first render. 0 collapses all; use max_int to expand everything. Defaults to 0.indent_size -- cells of indentation per nesting level. Defaults to 2.show_guides -- when true draws vertical guide lines. Defaults to false.guide_style -- border character set used for guide lines.expand_icon -- string shown next to collapsible nodes when collapsed. Defaults to "▶".collapse_icon -- string shown next to collapsible nodes when expanded. Defaults to "▼".leaf_icon -- string shown next to leaf nodes. Defaults to " ".background -- background color of unselected items.text_color -- foreground color of unselected items.selected_background -- background of the selected item.selected_text_color -- foreground of the selected item.focused_selected_background -- background of the selected item when the widget has focus.focused_selected_text_color -- foreground of the selected item when the widget has focus.guide_color -- color of the vertical guide lines.icon_color -- color of the expand/collapse/leaf icons.wrap_selection -- when true wraps selection past the last or first visible item. Defaults to false.fast_scroll_step -- items skipped per fast-scroll action. Defaults to 5.on_change -- fired when the selected index changes.on_activate -- fired when the user confirms the selection.on_expand -- fired when a node is expanded or collapsed; receives the flat index and true if expanded, false if collapsed. Internal modulesThe virtual-DOM reconciler used by run .
Overridden elementsEach element below replaces its Mosaic counterpart solely to turn the positional children argument into ?children with a trailing unit. All other arguments, defaults, and semantics are identical to Mosaic ; refer to the corresponding entry there for details.
For text-based elements (text , code , markdown ) children is string list whose items are concatenated.
Source val fragment : ?children :'msg t list -> unit -> 'msg t Like Mosaic.code . children is a string list whose items are concatenated. Defaults to [].
Like Mosaic.markdown . children is a string list whose items are concatenated. Defaults to [].
Like Mosaic.line_number . children defaults to []; pass the wrapped element (e.g. a code ) as a single-item list.