Skip to main content

TextInput

Struct TextInput 

Source
pub struct TextInput {
Show 14 fields pub err: Option<String>, pub prompt: String, pub placeholder: String, pub echo_mode: EchoMode, pub echo_character: char, pub cursor: Cursor, pub prompt_style: Style, pub text_style: Style, pub placeholder_style: Style, pub completion_style: Style, pub char_limit: usize, pub width: usize, pub key_map: KeyMap, pub show_suggestions: bool, /* private fields */
}
Expand description

Single-line text input model.

Fields§

§err: Option<String>

Current error from validation.

§prompt: String

Prompt displayed before input.

§placeholder: String

Placeholder text when empty.

§echo_mode: EchoMode

Echo mode (normal, password, none).

§echo_character: char

Character to display in password mode.

§cursor: Cursor

Cursor model.

§prompt_style: Style

Style for the prompt.

§text_style: Style

Style for the text.

§placeholder_style: Style

Style for the placeholder.

§completion_style: Style

Style for completions.

§char_limit: usize

Maximum characters allowed (0 = no limit).

§width: usize

Maximum display width (0 = no limit).

§key_map: KeyMap

Key bindings.

§show_suggestions: bool

Whether to show suggestions.

Implementations§

Source§

impl TextInput

Source

pub fn new() -> Self

Creates a new text input with default settings.

Source

pub fn set_prompt(&mut self, prompt: impl Into<String>)

Sets the prompt string.

Source

pub fn set_placeholder(&mut self, placeholder: impl Into<String>)

Sets the placeholder text.

Source

pub fn set_echo_mode(&mut self, mode: EchoMode)

Sets the echo mode.

Source

pub fn set_value(&mut self, s: &str)

Sets the value of the text input.

Source

pub fn value(&self) -> String

Returns the current value as a string.

Source

pub fn position(&self) -> usize

Returns the cursor position.

Source

pub fn set_cursor(&mut self, pos: usize)

Sets the cursor position.

Source

pub fn cursor_start(&mut self)

Moves cursor to start of input.

Source

pub fn cursor_end(&mut self)

Moves cursor to end of input.

Source

pub fn focused(&self) -> bool

Returns whether the input is focused.

Source

pub fn focus(&mut self) -> Option<Cmd>

Focuses the input and returns the cursor blink command.

Source

pub fn blur(&mut self)

Blurs the input.

Source

pub fn reset(&mut self)

Resets the input to empty.

Source

pub fn set_suggestions(&mut self, suggestions: &[&str])

Sets the suggestions list.

Source

pub fn set_validate<F>(&mut self, f: F)
where F: Fn(&str) -> Option<String> + Send + Sync + 'static,

Sets the validation function.

Source

pub fn available_suggestions(&self) -> Vec<String>

Returns available suggestions as strings.

Source

pub fn matched_suggestions(&self) -> Vec<String>

Returns matched suggestions as strings.

Source

pub fn current_suggestion_index(&self) -> usize

Returns the current suggestion index.

Source

pub fn current_suggestion(&self) -> String

Returns the current suggestion.

Source

pub fn update(&mut self, msg: Message) -> Option<Cmd>

Updates the text input based on messages.

Source

pub fn view(&self) -> String

Renders the text input.

Trait Implementations§

Source§

impl Clone for TextInput

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextInput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextInput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Model for TextInput

Source§

fn init(&self) -> Option<Cmd>

Initialize the text input.

If focused and cursor is in blink mode, returns a blink command.

Source§

fn update(&mut self, msg: Message) -> Option<Cmd>

Update the text input state based on incoming messages.

Handles:

  • KeyMsg - Keyboard input for text entry and navigation
  • PasteMsg - Paste operations
  • Cursor blink messages
Source§

fn view(&self) -> String

Render the text input.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more