package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Text_input/index.html
Module Mosaic_ui.Text_input
Single-line text input with cursor, selection, and clipboard.
Single-line text input widget.
A text input provides keyboard-driven single-line editing with horizontal scrolling, selection highlighting, cursor display, and placeholder text. Supports undo/redo, word-level navigation, and configurable visual styling. Newlines are always stripped from content.
The widget fires four callbacks:
on_input: after every text change (keystroke-level).on_change: when the committed value differs on blur or submit. See Callbacks.on_submit: when Enter is pressed.on_cursor: when cursor position or selection changes.
See Textarea for multi-line editing.
Construction
val create :
parent:Renderable.t ->
?index:int ->
?id:string ->
?style:Toffee.Style.t ->
?visible:bool ->
?z_index:int ->
?opacity:float ->
?value:string ->
?cursor:int ->
?selection:(int * int) option ->
?placeholder:string ->
?max_length:int ->
?text_color:Ansi.Color.t ->
?background_color:Ansi.Color.t ->
?focused_text_color:Ansi.Color.t ->
?focused_background_color:Ansi.Color.t ->
?placeholder_color:Ansi.Color.t ->
?selection_color:Ansi.Color.t ->
?selection_fg:Ansi.Color.t ->
?cursor_style:[ `Block | `Line | `Underline ] ->
?cursor_color:Ansi.Color.t ->
?cursor_blinking:bool ->
?on_input:(string -> unit) ->
?on_change:(string -> unit) ->
?on_submit:(string -> unit) ->
?on_cursor:(cursor:int -> selection:(int * int) option -> unit) ->
unit ->
tcreate ~parent () is a text input attached to parent with:
value: initial text content. Newlines are stripped. Defaults to"".cursor: optional controlled cursor grapheme offset.selection: optional controlled selection range. When provided asSome (lo, hi), selection is normalized/clamped.placeholder: text shown when empty. Defaults to"".max_length: maximum grapheme cluster count. Defaults to1000.text_color: unfocused text color. Defaults toAnsi.Color.t.White.background_color: unfocused background. Defaults toAnsi.Color.default.focused_text_color: focused text color. Defaults toAnsi.Color.t.White.focused_background_color: focused background. Defaults toAnsi.Color.default.placeholder_color: placeholder text color. Defaults toAnsi.Color.t.Bright_black.selection_color: selection background. Defaults toAnsi.Color.t.Blue.selection_fg: selection foreground. WhenNone, uses the normal text color. Defaults toNone.cursor_style: cursor shape when focused. Defaults to`Block.cursor_color: cursor color when focused. Defaults toAnsi.Color.t.White.cursor_blinking: whether the cursor blinks. Defaults totrue.on_input: called after every text change.on_change: called when committed value changes (blur or submit).on_submit: called when Enter is pressed.on_cursor: called when cursor position or selection changes.
Accessors
val node : t -> Renderable.tnode t is the underlying renderable.
val buffer : t -> Edit_buffer.tbuffer t is the underlying edit buffer.
Props
module Props : sig ... endapply_props t props updates t to match props. When value differs, the buffer content is replaced (newlines stripped). Requests a render.
Value
val value : t -> stringvalue t is the current text content.
val cursor : t -> intcursor t is the current cursor grapheme offset.
val selection : t -> (int * int) optionselection t is the active selection as normalized grapheme offsets, if any.
val set_value : t -> string -> unitset_value t s replaces the text content with s (newlines stripped). Resets scroll to 0 and ensures cursor visibility.
Callbacks
val set_on_input : t -> (string -> unit) option -> unitset_on_input t f sets the keystroke-level input callback. None clears it.
val set_on_change : t -> (string -> unit) option -> unitset_on_change t f sets the committed-value change callback. None clears it.
The callback fires on blur or submit, only when the value has changed since focus was gained (or since the last on_change firing).
val set_on_submit : t -> (string -> unit) option -> unitset_on_submit t f sets the Enter-key submit callback. None clears it. Fires on_change before the submit callback.
val set_on_cursor :
t ->
(cursor:int -> selection:(int * int) option -> unit) option ->
unitset_on_cursor t f sets the cursor/selection change callback. None clears it.
Paste
val handle_paste : t -> string -> unithandle_paste t text inserts text as if pasted, stripping newlines. Fires on_input if the buffer changed.
Formatting
val pp : Format.formatter -> t -> unitpp ppf t formats t on ppf for debugging.