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: StringPrompt is printed at the beginning of each line.
placeholder: StringPlaceholder is the text displayed when the user hasn’t entered anything yet.
show_line_numbers: boolShowLineNumbers, if enabled, causes line numbers to be printed after the prompt.
end_of_buffer_character: charEndOfBufferCharacter is displayed at the end of the input.
key_map: KeyMapKeyMap encodes the keybindings recognized by the widget.
virtual_cursor: ModelvirtualCursor manages the virtual cursor.
char_limit: usizeCharLimit is the maximum number of characters this input element will accept. If 0 or less, there’s no limit.
max_height: usizeMaxHeight is the maximum height of the text area in rows. If 0 or less, there’s no limit.
max_width: usizeMaxWidth is the maximum width of the text area in columns. If 0 or less, there’s no limit.
dynamic_height: boolDynamicHeight, 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: usizeMinHeight is the minimum height of the text area in rows when DynamicHeight is enabled. If 0 or less, defaults to 1.
max_content_height: usizeMaxContentHeight 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: StylesStyling. Styles are defined in Styles.
use_virtual_cursor: booluseVirtualCursor 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: usizeprompt_width is the width of the prompt.
width: usizewidth is the maximum number of characters that can be displayed at once.
height: usizeheight is the maximum number of lines that can be displayed at once.
focus: boolfocus indicates whether user input focus should be on this input component.
Implementations§
Source§impl Model
impl Model
Sourcepub fn set_styles(&mut self, s: Styles)
pub fn set_styles(&mut self, s: Styles)
SetStyles updates styling for the textarea.
Sourcepub fn virtual_cursor(&self) -> bool
pub fn virtual_cursor(&self) -> bool
VirtualCursor returns whether or not the virtual cursor is enabled.
Sourcepub fn set_virtual_cursor(&mut self, v: bool)
pub fn set_virtual_cursor(&mut self, v: bool)
SetVirtualCursor sets whether or not to use the virtual cursor.
Sourcepub fn insert_string(&mut self, s: &str)
pub fn insert_string(&mut self, s: &str)
InsertString inserts a string at the cursor position.
Sourcepub fn insert_rune(&mut self, r: char)
pub fn insert_rune(&mut self, r: char)
InsertRune inserts a rune at the cursor position.
Sourcepub fn value(&self) -> String
pub fn value(&self) -> String
Value returns the value of the text input. Value returns the value of the textarea.
Sourcepub fn length(&self) -> usize
pub fn length(&self) -> usize
Length returns the number of characters currently in the text input.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
LineCount returns the number of lines that are currently in the text input.
Sourcepub fn scroll_y_offset(&self) -> usize
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.
Sourcepub fn set_scroll_y_offset(&mut self, offset: usize)
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.
Sourcepub fn scroll_percent(&self) -> f64
pub fn scroll_percent(&self) -> f64
ScrollPercent returns the amount of the textarea that is currently scrolled through, clamped between 0 and 1.
Sourcepub fn cursor_down(&mut self)
pub fn cursor_down(&mut self)
CursorDown moves the cursor down by one line.
Sourcepub fn cursor_position(&self) -> (usize, usize)
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.
Sourcepub fn set_cursor_position(&mut self, row: usize, col: usize)
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.
Sourcepub fn set_cursor_column(&mut self, col: usize)
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.
Sourcepub fn cursor_start(&mut self)
pub fn cursor_start(&mut self)
CursorStart moves the cursor to the start of the input field.
Sourcepub fn cursor_end(&mut self)
pub fn cursor_end(&mut self)
CursorEnd moves the cursor to the end of the input field.
Sourcepub fn focus(&mut self) -> Cmd
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.
Sourcepub fn blur(&mut self)
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.
Sourcepub fn word(&self) -> String
pub fn word(&self) -> String
Word returns the word at the cursor position. A word is delimited by spaces or line-breaks.
Sourcepub fn line_info(&self) -> LineInfo
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.
Sourcepub fn move_to_begin(&mut self)
pub fn move_to_begin(&mut self)
MoveToBegin moves the cursor to the beginning of the input.
Sourcepub fn move_to_end(&mut self)
pub fn move_to_end(&mut self)
MoveToEnd moves the cursor to the end of the input.
Sourcepub fn page_up(&mut self)
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.
Sourcepub fn page_down(&mut self)
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.
Sourcepub fn set_width(&mut self, w: usize)
pub fn set_width(&mut self, w: usize)
SetWidth sets the width of the textarea to fit exactly within the given width.
Sourcepub fn set_prompt_func(
&mut self,
prompt_width: usize,
f: Box<dyn Fn(PromptInfo) -> String + Send + Sync>,
)
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.
Sourcepub fn cursor(&self) -> Option<Cursor>
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.
Sourcepub fn set_height(&mut self, h: usize)
pub fn set_height(&mut self, h: usize)
SetHeight sets the height of the textarea.
Sourcepub fn prompt_view(&self, display_line: usize) -> String
pub fn prompt_view(&self, display_line: usize) -> String
promptView renders a single line of the prompt.
Sourcepub fn cursor_line_number(&self) -> usize
pub fn cursor_line_number(&self) -> usize
cursorLineNumber returns the line number that the cursor is on. This accounts for soft wrapped lines.
Sourcepub fn total_visual_lines(&self) -> usize
pub fn total_visual_lines(&self) -> usize
TotalVisualLines returns the total number of display lines across all logical lines, accounting for soft wraps.