package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Text/index.html
Module Mosaic_ui.Text
Styled text display with wrapping, truncation, and selection.
Rich text rendering with styled fragments.
A text node renders styled content into the grid, handling line breaks and optional word/character wrapping. Content can be plain text (via set_content) or structured rich text with per-run styles (via set_fragments or set_spans).
Internally backed by a Text_buffer.t and Text_surface.t.
Representations
Text supports two content representations:
- Content: a plain string set via
set_contentor thecontentparameter ofcreate. Styled with Default style. - Fragments/Spans: structured styled content set via
set_fragmentsorset_spans. Fragments support nested style hierarchies; spans are flat styled text chunks.
Style merging
Styles merge hierarchically: parent styles provide the base and child overrides apply on top, preserving unspecified parent attributes. The text_style parameter provides the base style for all content.
See Text_input for single-line editing and Textarea for multi-line editing.
Types
type fragment = | Text of {text : string;style : Ansi.Style.t option;
}| Span of {style : Ansi.Style.t option;children : fragment list;
}(*Structured text fragments for rich text composition.
Text: leaf node with text and optional style override.Span: container applying an optional style to allchildren.
A flat styled text chunk. style overrides the default text style when Some; None inherits the default.
Fragment builder
Convenience constructors for fragment values.
module Fragment : sig ... endConstruction
val create :
parent:Renderable.t ->
?index:int ->
?id:string ->
?style:Toffee.Style.t ->
?visible:bool ->
?z_index:int ->
?opacity:float ->
?content:string ->
?text_style:Ansi.Style.t ->
?wrap:Text_surface.wrap ->
?selectable:bool ->
?selection_bg:Ansi.Color.t ->
?selection_fg:Ansi.Color.t ->
?tab_width:int ->
?truncate:bool ->
unit ->
tcreate ~parent () is a text node attached to parent with:
content: plain text content. Defaults to"".text_style: base visual style for all content. Defaults toAnsi.Style.default.wrap: wrapping mode. Defaults to`None.selectable: whether text can be selected. Defaults totrue.selection_bg: background color for selected text. Defaults toNone.selection_fg: foreground color for selected text. Defaults toNone.tab_width: tab stop width. Defaults to2.truncate: whether to truncate with ellipsis whenwrap = `None. Defaults tofalse.
Accessors
val node : t -> Renderable.tnode t is the underlying renderable.
val buffer : t -> Text_buffer.tbuffer t is the underlying text buffer.
val surface : t -> Text_surface.tsurface t is the underlying text surface.
Props
module Props : sig ... endapply_props t props applies props to t, triggering the minimum necessary layout and render updates.
Content
val set_content : t -> string -> unitset_content t s sets plain text content styled with set_text_style. Invalidates display lines and marks layout dirty.
set_fragments t fragments replaces content with fragments. Normalization merges adjacent text with identical styles, removes empty fragments, and flattens empty spans. No-op if the normalized result equals the current fragments.
fragments_equal a b is true iff a and b are structurally equal.
val plain_text : t -> stringplain_text t is the concatenation of all fragment texts, without styling.
spans t is the current fragments as a flat span list. Cached; recomputed on fragment changes.
set_spans t spans replaces content with flat spans. Converts to fragments internally.
val clear_spans : t -> unitclear_spans t removes all content.
val set_styled_text : t -> Text_buffer.span list -> unitset_styled_text t spans sets pre-styled buffer content directly. After calling this, apply_props will not overwrite content from Props.
val set_text_style : t -> Ansi.Style.t -> unitset_text_style t s changes the base text style. Invalidates the span cache if the style differs.
Wrapping
val set_wrap : t -> Text_surface.wrap -> unitset_wrap t mode changes the wrapping mode. Delegates to Text_surface.set_wrap.
val set_tab_width : t -> int -> unitset_tab_width t w changes the tab stop width. Delegates to Text_buffer.set_tab_width.
Selection
val set_selectable : t -> bool -> unitset_selectable t v enables or disables text selection.
val set_selection_bg : t -> Ansi.Color.t option -> unitset_selection_bg t color sets the selection background color.
val set_selection_fg : t -> Ansi.Color.t option -> unitset_selection_fg t color sets the selection foreground color.
val selected_text : t -> stringselected_text t is the currently selected text. Returns "" if no selection is active.
Highlights
val add_highlight : t -> Text_buffer.Highlight.t -> unitadd_highlight t h adds a highlight overlay and requests a render.
val remove_highlights_by_ref : t -> int -> unitremove_highlights_by_ref t ref_id removes highlights by Text_buffer.Highlight.ref_id and requests a render.
val clear_highlights : t -> unitclear_highlights t removes all highlights and requests a render.
Query
val line_count : t -> intline_count t is the number of logical lines.
val display_line_count : t -> intdisplay_line_count t is the number of wrapped display lines.
Formatting
val pp : Format.formatter -> t -> unitpp ppf t formats t on ppf for debugging.