Expand description
§tui-realm-textarea
tui-realm-textarea is a tui-realm implementation of a textarea component. The tree engine is based on Orange-trees.
§Get Started
§Adding tui-realm-textarea as dependency
tui-realm-textarea = "2"Or if you don’t use Crossterm, define the backend as you would do with tui-realm:
tui-realm-textarea = { version = "2", default-features = false, features = [ "termion" ] }§Features ⚙️
These features can be enabled in tui-realm-textarea:
clipboardenables system clipboard supportsearchenables the string search in the textarea
§Component API
Commands:
| Cmd | Result | Behaviour |
|---|---|---|
Custom($TEXTAREA_CMD_NEWLINE) | None | Insert newline |
Custom($TEXTAREA_CMD_DEL_LINE_BY_END) | None | Delete line by end to current position |
Custom($TEXTAREA_CMD_DEL_LINE_BY_HEAD) | None | Delete line by head to current position |
Custom($TEXTAREA_CMD_DEL_WORD) | None | Delete the current word |
Custom($TEXTAREA_CMD_DEL_NEXT_WORD) | None | Delete the next word |
Custom($TEXTAREA_CMD_MOVE_WORD_FORWARD) | None | Move to the next word |
Custom($TEXTAREA_CMD_MOVE_WORD_BACK) | None | Move to the previous word |
Custom($TEXTAREA_CMD_MOVE_PARAGRAPH_BACK) | None | Move to the previous paragraph |
Custom($TEXTAREA_CMD_MOVE_PARAGRAPH_FORWARD) | None | Move to the next paragraph |
Custom($TEXTAREA_CMD_MOVE_TOP) | None | Move to the beginning of the file |
Custom($TEXTAREA_CMD_MOVE_BOTTOM) | None | Move to the end of the file |
Custom($TEXTAREA_CMD_UNDO) | None | Undo last change |
Custom($TEXTAREA_CMD_REDO) | None | Redo last change |
Custom($TEXTAREA_CMD_PASTE) | None | Paste the current content of the buffer |
Custom($TEXTAREA_CMD_SEARCH_BACK) | None | Go to the previous search match |
Custom($TEXTAREA_CMD_SEARCH_FORWARD) | None | Go to the next search match |
Cancel | None | Delete next char |
Delete | None | Delete previous char |
GoTo(Begin) | None | Go to the head of the line |
GoTo(End) | None | Go to the end of the line |
Move(Down) | None | Move to the line below |
Move(Up) | None | Move to the line above |
Move(Left) | None | Move cursor to the left |
Move(Right) | None | Move cursor to the right |
Scroll(Up) | None | Move by scroll_step lines up |
Scroll(Down) | None | Move by scroll_step lines down |
Type(ch) | None | Type a char in the editor |
Submit | Submit | Get current lines |
❗ Paste command is supported only if the
clipboardfeature is enabled
State: the state returned is a Vec(String) containing the lines in the text area.
Properties:
Borders(Borders): set borders properties for componentCustom($TREE_IDENT_SIZE, Size): Set space to render for each each depth levelCustom($TEXTAREA_MAX_HISTORY, Payload(One(Usize))): Set the history steps to recordCustom($TEXTAREA_CURSOR_STYLE, Style): Set the cursor styleCustom($TEXTAREA_CURSOR_LINE_STYLE, Style): Set the current line styleCustom($TEXTAREA_FOOTER_FMT, Payload(Tup2(Str, Style))): Set the format and the style for the footer barCustom($TEXTAREA_LINE_NUMBER_STYLE, Style): set the style for the line numberCustom($TEXTAREA_STATUS_FMT, Payload(Tup2(Str, Style))): Set the format and the style for the status barCustom($TEXTAREA_SEARCH_PATTERN, String: Set search patternCustom($TEXTAREA_SEARCH_STYLE, Style: Set search styleCustom($TEXTAREA_SINGLE_LINE, Style: Act as single-line inputStyle(Style): Set the general style for the textareaCustom($TEXTAREA_TAB_SIZE, Size): Set the tab size to displayFocusStyle(Style): inactive styleScrollStep(Length): Defines the maximum amount of rows to scrollTitle(Title): Set box title
§Footer and status format
The status and footer bars support a special syntax. The following keys can be inserted into the string:
{ROW}: current row{COL}: current column
§Example
use std::{fs, io::{self, BufRead}};
use tuirealm::{
application::PollStrategy,
command::{Cmd, CmdResult, Direction, Position},
event::{Event, Key, KeyEvent, KeyModifiers},
props::{Alignment, AttrValue, Attribute, BorderType, Borders, Color, Style, TextModifiers},
terminal::TerminalBridge,
Application, Component, EventListenerCfg, MockComponent, NoUserEvent, State, StateValue,
Update,
};
use tui_realm_textarea::TextArea;
let textarea = match fs::File::open("README.md") {
Ok(reader) => TextArea::new(
io::BufReader::new(reader)
.lines()
.map(|l| l.unwrap())
.collect::<_>(),
),
Err(_) => TextArea::default(),
};
let component = textarea
.borders(
Borders::default()
.color(Color::LightYellow)
.modifiers(BorderType::Double),
)
.cursor_line_style(Style::default())
.cursor_style(Style::default().add_modifier(TextModifiers::REVERSED))
.footer_bar("Press <ESC> to quit", Style::default())
.line_number_style(
Style::default()
.fg(Color::LightBlue)
.add_modifier(TextModifiers::ITALIC),
)
.max_histories(64)
.scroll_step(4)
.status_bar(
"README.md Ln {ROW}, Col {COL}",
Style::default().add_modifier(TextModifiers::REVERSED),
)
.tab_length(4)
.title("Editing README.md", Alignment::Left);Structs§
- Text
Area - textarea tui-realm component
Constants§
- TEXTAREA_
CMD_ DEL_ LINE_ BY_ END - TEXTAREA_
CMD_ DEL_ LINE_ BY_ HEAD - TEXTAREA_
CMD_ DEL_ NEXT_ WORD - TEXTAREA_
CMD_ DEL_ WORD - TEXTAREA_
CMD_ MOVE_ BOTTOM - TEXTAREA_
CMD_ MOVE_ PARAGRAPH_ BACK - TEXTAREA_
CMD_ MOVE_ PARAGRAPH_ FORWARD - TEXTAREA_
CMD_ MOVE_ TOP - TEXTAREA_
CMD_ MOVE_ WORD_ BACK - TEXTAREA_
CMD_ MOVE_ WORD_ FORWARD - TEXTAREA_
CMD_ NEWLINE - TEXTAREA_
CMD_ REDO - TEXTAREA_
CMD_ UNDO - TEXTAREA_
CURSOR_ LINE_ STYLE - TEXTAREA_
CURSOR_ STYLE - TEXTAREA_
FOOTER_ FMT - TEXTAREA_
HARD_ TAB - TEXTAREA_
LAYOUT_ MARGIN - TEXTAREA_
LINE_ NUMBER_ STYLE - TEXTAREA_
MAX_ HISTORY - TEXTAREA_
SINGLE_ LINE - TEXTAREA_
STATUS_ FMT - TEXTAREA_
TAB_ SIZE