TermUI.Widgets.TextInput (TermUI v0.2.0)
View SourceTextInput widget for single-line and multi-line text input.
Provides text editing with cursor movement, auto-growing height, and scrolling for content that exceeds the visible area.
Usage
TextInput.new(
value: "",
placeholder: "Enter text...",
width: 40,
multiline: true,
max_visible_lines: 5
)Features
- Single-line and multi-line modes
- Ctrl+Enter for newline insertion (multiline)
- Auto-growing height up to max_visible_lines
- Scrollable area when content exceeds visible lines
- Cursor movement and text editing
- Placeholder text support
- Focus state handling
Keyboard Controls
- Left/Right: Move cursor horizontally
- Up/Down: Move cursor between lines (multiline)
- Home/End: Move to start/end of line
- Ctrl+Home/End: Move to start/end of text
- Backspace: Delete character before cursor
- Delete: Delete character at cursor
- Ctrl+Enter: Insert newline (multiline mode)
- Enter: Submit (single-line) or insert newline if configured
- Escape: Blur input
Summary
Functions
Clear the text input.
Get the cursor position as {row, col}.
Get the number of lines.
Get the current text value.
Creates new TextInput widget props.
Set focus state.
Set the text value programmatically.
Functions
Clear the text input.
@spec get_cursor(map()) :: {non_neg_integer(), non_neg_integer()}
Get the cursor position as {row, col}.
@spec get_line_count(map()) :: non_neg_integer()
Get the number of lines.
Get the current text value.
Creates new TextInput widget props.
Options
:value- Initial text value (default: ""):placeholder- Placeholder text when empty (default: ""):width- Widget width in characters (default: 40):multiline- Enable multi-line mode (default: false):max_lines- Maximum number of lines allowed, nil for unlimited (default: nil):max_visible_lines- Lines visible before scrolling (default: 5):on_change- Callback when value changes: fn(value) -> any:on_submit- Callback when submitted: fn(value) -> any:enter_submits- Enter key submits instead of newline in multiline (default: false):disabled- Disable input (default: false):style- Text style:focused_style- Style when focused:placeholder_style- Placeholder text style
Set focus state.
Set the text value programmatically.