Skip to main content

Model

Struct Model 

Source
pub struct Model {
Show 14 fields pub err: Option<String>, pub prompt: String, pub placeholder: String, pub echo_mode: EchoMode, pub echo_character: char, pub use_virtual_cursor: bool, pub virtual_cursor: Model, pub char_limit: usize, pub styles: Styles, pub width: usize, pub key_map: KeyMap, pub focus: bool, pub validate: Option<ValidateFunc>, pub show_suggestions: bool, /* private fields */
}
Expand description

Model is the Bubble Tea model for this text input element.

Fields§

§err: Option<String>

The validation error, if any.

§prompt: String

General settings. The prompt shown before the input.

§placeholder: String

The placeholder shown when the input is empty.

§echo_mode: EchoMode

The echo mode of the input.

§echo_character: char

The character used for masking in EchoMode::EchoPassword.

§use_virtual_cursor: bool

use_virtual_cursor determines whether or not to use the virtual cursor.

§virtual_cursor: Model

Virtual cursor manager.

§char_limit: usize

CharLimit is the maximum amount of characters this input element will accept. If 0 or less, there’s no limit.

§styles: Styles

Styling. FocusedStyle and BlurredStyle are used to style the textarea in focused and blurred states.

§width: usize

Width is the maximum number of characters that can be displayed at once. It essentially treats the text field like a horizontally scrolling viewport. If 0 or less this setting is ignored.

§key_map: KeyMap

KeyMap encodes the keybindings recognized by the widget.

§focus: bool

focus indicates whether user input focus should be on this input component. When false, ignore keyboard input and hide the cursor.

§validate: Option<ValidateFunc>

Validate is a function that checks whether or not the text within the input is valid. If it is not valid, the Err field will be set to the error returned by the function.

§show_suggestions: bool

Should the input suggest to complete.

Implementations§

Source§

impl Model

Source

pub fn virtual_cursor(&self) -> bool

VirtualCursor returns whether the model is using a virtual cursor.

Source

pub fn set_virtual_cursor(&mut self, v: bool)

SetVirtualCursor sets whether the model should use a virtual cursor.

Source

pub fn styles(&self) -> &Styles

Styles returns the current set of styles.

Source

pub fn set_styles(&mut self, s: Styles)

SetStyles sets the styles for the text input.

Source

pub fn cursor(&self) -> Option<Cursor>

Cursor returns a real cursor for rendering in a Bubble Tea program. This requires that use_virtual_cursor is false.

Source

pub fn width(&self) -> usize

Width returns the width of the text input.

Source

pub fn set_width(&mut self, w: usize)

SetWidth sets the width of the text input.

Source

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

SetValue sets the value of the text input.

Source

pub fn value(&self) -> String

Value returns the value of the text input.

Source

pub fn position(&self) -> usize

Position returns the cursor position.

Source

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

SetCursor moves the cursor to the given position. If the position is out of bounds the cursor will be moved to the start or end accordingly.

Source

pub fn cursor_start(&mut self)

CursorStart moves the cursor to the start of the input field.

Source

pub fn cursor_end(&mut self)

CursorEnd moves the cursor to the end of the input field.

Source

pub fn focused(&self) -> bool

Focused returns the focus state on the model.

Source

pub fn focus(&mut self) -> Cmd

Focus sets the focus state on the model. When the model is in focus it can receive keyboard input and the cursor will be shown.

Source

pub fn blur(&mut self)

Blur removes the focus state on the model. When the model is blurred it can not receive keyboard input and the cursor will be hidden.

Source

pub fn reset(&mut self)

Reset sets the input to its default state with no input.

Source

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

SetSuggestions sets the suggestions for the input.

Source

pub fn update(&mut self, msg: &dyn Msg) -> Cmd

Update is the Bubble Tea update loop.

Source

pub fn view(&self) -> String

View renders the textinput in its current state.

Source

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

AvailableSuggestions returns the list of available suggestions.

Source

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

MatchedSuggestions returns the list of matched suggestions.

Source

pub fn current_suggestion_index(&self) -> usize

CurrentSuggestionIndex returns the currently selected suggestion index.

Source

pub fn current_suggestion(&self) -> String

CurrentSuggestion returns the currently selected suggestion.

Source

pub fn can_accept_suggestion(&self) -> bool

canAcceptSuggestion returns whether there is an acceptable suggestion to autocomplete the current value.

Trait Implementations§

Source§

impl Debug for Model

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Model

§

impl !UnwindSafe for Model

§

impl Freeze for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Msg for T
where T: Any + Send + Sync + Debug,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Helper to downcast to Any.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Consumes the boxed message and returns it as a Box<dyn Any>, so the program can move the concrete message out of the trait object (used to dispatch the commands carried by BatchMsg/SequenceMsg).
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.