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.
The type for single-line text inputs.
Constructionval 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 ->
t create ~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 as Some (lo, hi), selection is normalized/clamped.placeholder: text shown when empty. Defaults to "".max_length: maximum grapheme cluster count. Defaults to 1000.text_color: unfocused text color. Defaults to Ansi.Color.t.White .background_color: unfocused background. Defaults to Ansi.Color.default .focused_text_color: focused text color. Defaults to Ansi.Color.t.White .focused_background_color: focused background. Defaults to Ansi.Color.default .placeholder_color: placeholder text color. Defaults to Ansi.Color.t.Bright_black .selection_color: selection background. Defaults to Ansi.Color.t.Blue .selection_fg: selection foreground. When None, uses the normal text color. Defaults to None.cursor_style: cursor shape when focused. Defaults to `Block.cursor_color: cursor color when focused. Defaults to Ansi.Color.t.White .cursor_blinking: whether the cursor blinks. Defaults to true.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. Accessorsnode t is the underlying renderable.
buffer t is the underlying edit buffer.
Propsmodule Props : sig ... end apply_props t props updates t to match props. When value differs, the buffer content is replaced (newlines stripped). Requests a render.
Valuevalue t is the current text content.
cursor 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.
Callbacksset_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.
Pasteval handle_paste : t -> string -> unithandle_paste t text inserts text as if pasted, stripping newlines. Fires on_input if the buffer changed.
Formattingpp ppf t formats t on ppf for debugging.