Mosaic_ui.TextStyled 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.
Text supports two content representations:
set_content or the content parameter of create. Styled with Default style.set_fragments or set_spans. Fragments support nested style hierarchies; spans are flat styled text chunks.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.
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 all children.A flat styled text chunk. style overrides the default text style when Some; None inherits the default.
Convenience constructors for fragment values.
module Fragment : sig ... endval 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 to Ansi.Style.default.wrap: wrapping mode. Defaults to `None.selectable: whether text can be selected. Defaults to true.selection_bg: background color for selected text. Defaults to None.selection_fg: foreground color for selected text. Defaults to None.tab_width: tab stop width. Defaults to 2.truncate: whether to truncate with ellipsis when wrap = `None. Defaults to false.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.
module Props : sig ... endapply_props t props applies props to t, triggering the minimum necessary layout and render updates.
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.
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.
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.
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.
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.
val pp : Format.formatter -> t -> unitpp ppf t formats t on ppf for debugging.