Skip to main content

TextArea

Struct TextArea 

Source
pub struct TextArea {
    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 focused_style: Styles,
    pub blurred_style: Styles,
    pub cursor: Cursor,
    pub char_limit: usize,
    pub max_height: usize,
    pub max_width: usize,
    /* private fields */
}
Expand description

Multi-line text area model.

Fields§

§err: Option<String>

Current error.

§prompt: String

Prompt string (displayed at start of each line).

§placeholder: String

Placeholder text.

§show_line_numbers: bool

Whether to show line numbers.

§end_of_buffer_character: char

End of buffer character.

§key_map: KeyMap

Key bindings.

§focused_style: Styles

Style for focused state.

§blurred_style: Styles

Style for blurred state.

§cursor: Cursor

Cursor model.

§char_limit: usize

Character limit (0 = no limit).

§max_height: usize

Maximum height in rows.

§max_width: usize

Maximum width in columns.

Implementations§

Source§

impl TextArea

Source

pub fn new() -> Self

Creates a new textarea with default settings.

Source

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

Sets the value of the textarea.

Source

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

Inserts a string at the cursor position.

Source

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

Inserts a single character at the cursor position.

Source

pub fn value(&self) -> String

Returns the current value as a string.

Source

pub fn length(&self) -> usize

Returns the total length in characters.

Source

pub fn line_count(&self) -> usize

Returns the number of lines.

Source

pub fn line(&self) -> usize

Returns the current line number (0-indexed).

Source

pub fn cursor_col(&self) -> usize

Returns the current cursor column (0-indexed, in characters).

Source

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

Returns the current cursor position (row, col) in character indices.

Source

pub fn cursor_byte_offset(&self) -> usize

Returns the cursor position as a byte offset into the string returned by Self::value.

Source

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

Sets the cursor position based on a byte offset into the string returned by Self::value.

If the offset points to the newline separator between lines, the cursor is placed at the end of the preceding line. Offsets beyond the end of the buffer clamp to the end.

Source

pub fn cursor_down(&mut self)

Moves cursor down one line.

Source

pub fn cursor_up(&mut self)

Moves cursor up one line.

Source

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

Sets cursor column position.

Source

pub fn cursor_start(&mut self)

Moves cursor to start of line.

Source

pub fn cursor_end(&mut self)

Moves cursor to end of line.

Source

pub fn cursor_left(&mut self)

Moves cursor left one character.

Source

pub fn cursor_right(&mut self)

Moves cursor right one character.

Source

pub fn focused(&self) -> bool

Returns whether the textarea is focused.

Source

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

Focuses the textarea.

Source

pub fn blur(&mut self)

Blurs the textarea.

Source

pub fn reset(&mut self)

Resets the textarea to empty.

Source

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

Sets the width of the textarea.

Source

pub fn width(&self) -> usize

Returns the width.

Source

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

Sets the height of the textarea.

Source

pub fn height(&self) -> usize

Returns the height.

Source

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

Updates the textarea based on messages.

Source

pub fn view(&self) -> String

Renders the textarea.

Trait Implementations§

Source§

impl Clone for TextArea

Source§

fn clone(&self) -> TextArea

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 TextArea

Source§

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

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

impl Default for TextArea

Source§

fn default() -> Self

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

impl Model for TextArea

Source§

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

Initialize the textarea and return a blink command if focused.

Source§

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

Update the textarea state based on incoming messages.

Source§

fn view(&self) -> String

Render the textarea.

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