pub struct TextArea<'a> { /* private fields */ }Expand description
Text area widget.
Backend used is ropey, so large texts are no problem. Editing time increases with the number of styles applied. Everything below a million styles should be fine.
For emoji support this uses unicode_display_width which helps with those double-width emojis. Input of emojis strongly depends on the terminal. It may or may not work. And even with display there are sometimes strange glitches that I haven’t found yet.
Keyboard and mouse are implemented for crossterm, but it should be easy to extend to other event-types. Every interaction is available as function on the state.
Scrolling doesn’t depend on the cursor, but the editing and move functions take care that the cursor stays visible.
Wordwrap is not available. For display only use Paragraph, as for editing: why?
You can directly access the underlying Rope for readonly purposes, and conversion from/to byte/char positions are available. That should probably be enough to write a parser that generates some styling.
The cursor must set externally on the ratatui Frame as usual. screen_cursor gives you the correct value. There is the inverse too set_screen_cursor For more interactions you can use screen_to_col, and try_col_to_screen. They calculate everything, even in the presence of more complex graphemes and those double-width emojis.
§Stateful
This widget implements StatefulWidget, you can use it with
TextAreaState to handle common actions.
Implementations§
Source§impl<'a> TextArea<'a>
impl<'a> TextArea<'a>
Sourcepub fn styles_opt(self, styles: Option<TextStyle>) -> Self
pub fn styles_opt(self, styles: Option<TextStyle>) -> Self
Set the combined style.
Sourcepub fn focus_style(self, style: Style) -> Self
pub fn focus_style(self, style: Style) -> Self
Style when focused.
Sourcepub fn select_style(self, style: Style) -> Self
pub fn select_style(self, style: Style) -> Self
Selection style.
Sourcepub fn text_style<T: IntoIterator<Item = Style>>(self, styles: T) -> Self
pub fn text_style<T: IntoIterator<Item = Style>>(self, styles: T) -> Self
List of text-styles.
Use TextAreaState::add_style() to refer a text range to one of these styles.
Sourcepub fn text_style_map<T: Into<Style>>(self, styles: HashMap<usize, T>) -> Self
pub fn text_style_map<T: Into<Style>>(self, styles: HashMap<usize, T>) -> Self
Map of style_id -> text_style.
Use TextAreaState::add_style() to refer a text range to one of these styles.
Sourcepub fn set_horizontal_max_offset(self, offset: usize) -> Self
pub fn set_horizontal_max_offset(self, offset: usize) -> Self
Set a maximum horizontal offset that will be used even if there is no horizontal scrollbar set.
This widget doesn’t try to find a maximum text-length for all lines.
Default is 255
Sourcepub fn set_horizontal_overscroll(self, overscroll: usize) -> Self
pub fn set_horizontal_overscroll(self, overscroll: usize) -> Self
Set a horizontal overscroll that will be used even if there is no horizontal scrollbar set.
Default is 16384
Trait Implementations§
Source§impl<'a> StatefulWidget for &TextArea<'a>
impl<'a> StatefulWidget for &TextArea<'a>
Source§impl StatefulWidget for TextArea<'_>
impl StatefulWidget for TextArea<'_>
Auto Trait Implementations§
impl<'a> Freeze for TextArea<'a>
impl<'a> RefUnwindSafe for TextArea<'a>
impl<'a> Send for TextArea<'a>
impl<'a> Sync for TextArea<'a>
impl<'a> Unpin for TextArea<'a>
impl<'a> UnwindSafe for TextArea<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more