Skip to main content

Model

Struct Model 

Source
pub struct Model {
Show 20 fields pub err: Option<String>, pub prompt: String, pub placeholder: String, pub show_line_numbers: bool, pub end_of_buffer_character: char, pub key_map: KeyMap, pub virtual_cursor: Model, pub char_limit: usize, pub max_height: usize, pub max_width: usize, pub dynamic_height: bool, pub min_height: usize, pub max_content_height: usize, pub styles: Styles, pub use_virtual_cursor: bool, pub prompt_func: Option<Box<dyn Fn(PromptInfo) -> String + Send + Sync>>, pub prompt_width: usize, pub width: usize, pub height: usize, pub focus: bool, /* private fields */
}
Expand description

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

Fields§

§err: Option<String>

The validation error, if any.

§prompt: String

Prompt is printed at the beginning of each line.

§placeholder: String

Placeholder is the text displayed when the user hasn’t entered anything yet.

§show_line_numbers: bool

ShowLineNumbers, if enabled, causes line numbers to be printed after the prompt.

§end_of_buffer_character: char

EndOfBufferCharacter is displayed at the end of the input.

§key_map: KeyMap

KeyMap encodes the keybindings recognized by the widget.

§virtual_cursor: Model

virtualCursor manages the virtual cursor.

§char_limit: usize

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

§max_height: usize

MaxHeight is the maximum height of the text area in rows. If 0 or less, there’s no limit.

§max_width: usize

MaxWidth is the maximum width of the text area in columns. If 0 or less, there’s no limit.

§dynamic_height: bool

DynamicHeight, when true, causes the textarea to automatically grow and shrink its height to fit the content. The height is clamped between MinHeight and MaxHeight.

§min_height: usize

MinHeight is the minimum height of the text area in rows when DynamicHeight is enabled. If 0 or less, defaults to 1.

§max_content_height: usize

MaxContentHeight is the maximum content height in visual rows (accounting for soft wraps). When 0, the content guard falls back to the legacy MaxHeight behavior.

§styles: Styles

Styling. Styles are defined in Styles.

§use_virtual_cursor: bool

useVirtualCursor determines whether or not to use the virtual cursor.

§prompt_func: Option<Box<dyn Fn(PromptInfo) -> String + Send + Sync>>

If prompt_func is set, it replaces Prompt as a generator for prompt strings at the beginning of each line.

§prompt_width: usize

prompt_width is the width of the prompt.

§width: usize

width is the maximum number of characters that can be displayed at once.

§height: usize

height is the maximum number of lines that can be displayed at once.

§focus: bool

focus indicates whether user input focus should be on this input component.

Implementations§

Source§

impl Model

Source

pub fn styles(&self) -> &Styles

Styles returns the current styles for the textarea.

Source

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

SetStyles updates styling for the textarea.

Source

pub fn virtual_cursor(&self) -> bool

VirtualCursor returns whether or not the virtual cursor is enabled.

Source

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

SetVirtualCursor sets whether or not to use the virtual cursor.

Source

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

SetValue sets the value of the text input.

Source

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

InsertString inserts a string at the cursor position.

Source

pub fn insert_rune(&mut self, r: char)

InsertRune inserts a rune at the cursor position.

Source

pub fn value(&self) -> String

Value returns the value of the text input. Value returns the value of the textarea.

Source

pub fn length(&self) -> usize

Length returns the number of characters currently in the text input.

Source

pub fn line_count(&self) -> usize

LineCount returns the number of lines that are currently in the text input.

Source

pub fn line(&self) -> usize

Line returns the 0-indexed row position of the cursor.

Source

pub fn column(&self) -> usize

Column returns the 0-indexed column position of the cursor.

Source

pub fn scroll_y_offset(&self) -> usize

ScrollYOffset returns the Y offset (top row) index of the current view, which can be used to calculate the current scroll position.

Source

pub fn set_scroll_y_offset(&mut self, offset: usize)

SetScrollYOffset sets the Y offset (top row) index of the current view, clamping to the viewport’s scrollable range.

This is exposed so integration tests can position the view the same way the upstream in-package tests use viewport.SetYOffset.

Source

pub fn scroll_percent(&self) -> f64

ScrollPercent returns the amount of the textarea that is currently scrolled through, clamped between 0 and 1.

Source

pub fn cursor_down(&mut self)

CursorDown moves the cursor down by one line.

Source

pub fn cursor_up(&mut self)

CursorUp moves the cursor up by one line.

Source

pub fn cursor_position(&self) -> (usize, usize)

CursorPosition returns the current (row, col) of the cursor within the (soft-wrapped) value.

This is exposed so integration tests can assert on cursor placement the same way the upstream in-package tests do.

Source

pub fn set_cursor_position(&mut self, row: usize, col: usize)

SetCursorPosition sets the raw (row, col) of the cursor.

This is exposed so integration tests can position the cursor the same way the upstream in-package tests do.

Source

pub fn set_cursor_column(&mut self, col: usize)

SetCursorColumn 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 hidden.

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 word(&self) -> String

Word returns the word at the cursor position. A word is delimited by spaces or line-breaks.

Source

pub fn line_info(&self) -> LineInfo

LineInfo returns the number of characters from the start of the (soft-wrapped) line and the (soft-wrapped) line width.

Source

pub fn width(&self) -> usize

Width returns the width of the textarea.

Source

pub fn move_to_begin(&mut self)

MoveToBegin moves the cursor to the beginning of the input.

Source

pub fn move_to_end(&mut self)

MoveToEnd moves the cursor to the end of the input.

Source

pub fn page_up(&mut self)

PageUp moves the cursor up by one page. First call snaps to the first visible line, subsequent calls move up by a full page.

Source

pub fn page_down(&mut self)

PageDown moves the cursor down by one page. First call snaps to the last visible line, subsequent calls move down by a full page.

Source

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

SetWidth sets the width of the textarea to fit exactly within the given width.

Source

pub fn set_prompt_func( &mut self, prompt_width: usize, f: Box<dyn Fn(PromptInfo) -> String + Send + Sync>, )

SetPromptFunc supersedes the Prompt field and sets a dynamic prompt instead.

Source

pub fn height(&self) -> usize

Height returns the current height of the textarea.

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 and the textarea is focused.

Source

pub fn set_height(&mut self, h: usize)

SetHeight sets the height of the textarea.

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 text area in its current state.

Source

pub fn prompt_view(&self, display_line: usize) -> String

promptView renders a single line of the prompt.

Source

pub fn cursor_line_number(&self) -> usize

cursorLineNumber returns the line number that the cursor is on. This accounts for soft wrapped lines.

Source

pub fn total_visual_lines(&self) -> usize

TotalVisualLines returns the total number of display lines across all logical lines, accounting for soft wraps.

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.