pub struct TextInput { /* private fields */ }Expand description
A single-line text input widget.
Implementations§
Source§impl TextInput
impl TextInput
Sourcepub fn with_value(self, value: impl Into<String>) -> Self
pub fn with_value(self, value: impl Into<String>) -> Self
Set the text value (builder).
Sourcepub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
pub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
Set the placeholder text (builder).
Sourcepub fn with_max_length(self, max: usize) -> Self
pub fn with_max_length(self, max: usize) -> Self
Set maximum length in graphemes (builder).
Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Set base style (builder).
Sourcepub fn with_cursor_style(self, style: Style) -> Self
pub fn with_cursor_style(self, style: Style) -> Self
Set cursor style (builder).
Sourcepub fn with_placeholder_style(self, style: Style) -> Self
pub fn with_placeholder_style(self, style: Style) -> Self
Set placeholder style (builder).
Sourcepub fn with_selection_style(self, style: Style) -> Self
pub fn with_selection_style(self, style: Style) -> Self
Set selection style (builder).
Sourcepub fn with_focused(self, focused: bool) -> Self
pub fn with_focused(self, focused: bool) -> Self
Set whether the input is focused (builder).
Sourcepub fn set_value(&mut self, value: impl Into<String>)
pub fn set_value(&mut self, value: impl Into<String>)
Set the value, clamping cursor to valid range.
Sourcepub fn set_focused(&mut self, focused: bool)
pub fn set_focused(&mut self, focused: bool)
Set focus state.
Sourcepub fn cursor_position(&self, area: Rect) -> (u16, u16)
pub fn cursor_position(&self, area: Rect) -> (u16, u16)
Get the cursor screen position relative to a render area.
Returns (x, y) where x is the column and y is the row.
Useful for Frame::set_cursor().
Sourcepub fn selected_text(&self) -> Option<&str>
pub fn selected_text(&self) -> Option<&str>
Get selected text, if any.
Sourcepub fn handle_event(&mut self, event: &Event) -> bool
pub fn handle_event(&mut self, event: &Event) -> bool
Handle a terminal event.
Returns true if the state changed.
Sourcepub fn insert_text(&mut self, text: &str)
pub fn insert_text(&mut self, text: &str)
Insert text at the current cursor position.
This method:
- Replaces newlines and tabs with spaces.
- Filters out other control characters.
- Respects
max_length(truncating if necessary). - Efficiently inserts the result in one operation.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text.
Source§impl TextInput
impl TextInput
Sourcepub fn create_text_edit_command(
&self,
operation: TextEditOperation,
) -> Option<WidgetTextEditCmd>
pub fn create_text_edit_command( &self, operation: TextEditOperation, ) -> Option<WidgetTextEditCmd>
Create an undo command for the given text edit operation.
This creates a command that can be added to a HistoryManager for undo/redo support.
The command includes callbacks that will be called when the operation is undone or redone.
§Example
let mut input = TextInput::new();
let old_value = input.value().to_string();
// Perform the edit
input.set_value("new text");
// Create undo command
if let Some(cmd) = input.create_text_edit_command(TextEditOperation::SetValue {
old_value,
new_value: "new text".to_string(),
}) {
history.push(cmd);
}Sourcepub fn undo_id(&self) -> UndoWidgetId
pub fn undo_id(&self) -> UndoWidgetId
Get the undo widget ID.
This can be used to associate undo commands with this widget instance.