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.
Text wrapping is available, hard line-breaks at the right margin, or decent word-wrapping.
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_pos, and pos_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>) -> TextArea<'a>
pub fn styles_opt(self, styles: Option<TextStyle>) -> TextArea<'a>
Set the combined style.
Sourcepub fn focus_style(self, style: Style) -> TextArea<'a>
pub fn focus_style(self, style: Style) -> TextArea<'a>
Style when focused.
Sourcepub fn select_style(self, style: Style) -> TextArea<'a>
pub fn select_style(self, style: Style) -> TextArea<'a>
Selection style.
Sourcepub fn cursor_style(self, style: impl Into<Style>) -> TextArea<'a>
pub fn cursor_style(self, style: impl Into<Style>) -> TextArea<'a>
Style for a rendered cursor.
Only used if cursor_type is RenderedCursor.
Sourcepub fn text_style_idx(self, idx: usize, style: Style) -> TextArea<'a>
pub fn text_style_idx(self, idx: usize, style: Style) -> TextArea<'a>
Indexed text-style.
Use TextAreaState::add_style() to refer a text range to one of these styles.
Sourcepub fn text_style<T>(self, styles: T) -> TextArea<'a>where
T: IntoIterator<Item = Style>,
pub fn text_style<T>(self, styles: T) -> TextArea<'a>where
T: IntoIterator<Item = Style>,
List of text-styles.
Use TextAreaState::add_style() to refer a text range to one of these styles.
Sourcepub fn text_style_map<T>(self, styles: HashMap<usize, T>) -> TextArea<'a>
pub fn text_style_map<T>(self, styles: HashMap<usize, T>) -> TextArea<'a>
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: u32) -> TextArea<'a>
pub fn set_horizontal_max_offset(self, offset: u32) -> TextArea<'a>
Maximum offset the horizontal scrollbar.
This widget doesn’t try to find a correct maximum value to show with the horizontal scroll bar, but uses this fixed value instead. This is the maximum offset that can be reached by using the scrollbar.
Finding the maximum line length for a text is rather expensive, so this widget doesn’t even try.
This doesn’t limit the column that can be reached with cursor positioning, just what can be done via the scrollbar.
See [self.set_horizontal_overscroll]
Default is 255.
Sourcepub fn set_horizontal_overscroll(self, overscroll: u32) -> TextArea<'a>
pub fn set_horizontal_overscroll(self, overscroll: u32) -> TextArea<'a>
Maximum overscroll that can be reached by using the horizontal scrollbar and dragging beyond the area of the widget.
See [self.set_horizontal_max_offset]
Default is 16384.
Trait Implementations§
Source§impl<'a> StatefulWidget for &TextArea<'a>
impl<'a> StatefulWidget for &TextArea<'a>
Source§type State = TextAreaState
type State = TextAreaState
Source§impl StatefulWidget for TextArea<'_>
impl StatefulWidget for TextArea<'_>
Source§type State = TextAreaState
type State = TextAreaState
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