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 = "^1.1.0"

Or if you don’t use Crossterm, define the backend as you would do with tui-realm:

tui-realm-textarea = { version = "^1.1.0", default-features = false, features = [ "with-termion" ] }
Features ⚙️

These features can be enabled in tui-realm-textarea:

  • clipboard enables system clipboard support
  • search enables the string search in the textarea

Component API

Commands:

CmdResultBehaviour
Custom($TEXTAREA_CMD_NEWLINE)NoneInsert newline
Custom($TEXTAREA_CMD_DEL_LINE_BY_END)NoneDelete line by end to current position
Custom($TEXTAREA_CMD_DEL_LINE_BY_HEAD)NoneDelete line by head to current position
Custom($TEXTAREA_CMD_DEL_WORD)NoneDelete the current word
Custom($TEXTAREA_CMD_DEL_NEXT_WORD)NoneDelete the next word
Custom($TEXTAREA_CMD_MOVE_WORD_FORWARD)NoneMove to the next word
Custom($TEXTAREA_CMD_MOVE_WORD_BACK)NoneMove to the previous word
Custom($TEXTAREA_CMD_MOVE_PARAGRAPH_BACK)NoneMove to the previous paragraph
Custom($TEXTAREA_CMD_MOVE_PARAGRAPH_FORWARD)NoneMove to the next paragraph
Custom($TEXTAREA_CMD_MOVE_TOP)NoneMove to the beginning of the file
Custom($TEXTAREA_CMD_MOVE_BOTTOM)NoneMove to the end of the file
Custom($TEXTAREA_CMD_UNDO)NoneUndo last change
Custom($TEXTAREA_CMD_REDO)NoneRedo last change
Custom($TEXTAREA_CMD_PASTE)NonePaste the current content of the buffer
Custom($TEXTAREA_CMD_SEARCH_BACK)NoneGo to the previous search match
Custom($TEXTAREA_CMD_SEARCH_FORWARD)NoneGo to the next search match
CancelNoneDelete next char
DeleteNoneDelete previous char
GoTo(Begin)NoneGo to the head of the line
GoTo(End)NoneGo to the end of the line
Move(Down)NoneMove to the line below
Move(Up)NoneMove to the line above
Move(Left)NoneMove cursor to the left
Move(Right)NoneMove cursor to the right
Scroll(Up)NoneMove by scroll_step lines up
Scroll(Down)NoneMove by scroll_step lines down
Type(ch)NoneType a char in the editor
SubmitSubmitGet current lines

❗ Paste command is supported only if the clipboard feature is enabled

State: the state returned is a Vec(String) containing the lines in the text area.

Properties:

  • Borders(Borders): set borders properties for component
  • Custom($TREE_IDENT_SIZE, Size): Set space to render for each each depth level
  • Custom($TEXTAREA_MAX_HISTORY, Payload(One(Usize))): Set the history steps to record
  • Custom($TEXTAREA_CURSOR_STYLE, Style): Set the cursor style
  • Custom($TEXTAREA_CURSOR_LINE_STYLE, Style): Set the current line style
  • Custom($TEXTAREA_FOOTER_FMT, Payload(Tup2(Str, Style))): Set the format and the style for the footer bar
  • Custom($TEXTAREA_LINE_NUMBER_STYLE, Style): set the style for the line number
  • Custom($TEXTAREA_STATUS_FMT, Payload(Tup2(Str, Style))): Set the format and the style for the status bar
  • Custom($TEXTAREA_SEARCH_PATTERN, String: Set search pattern
  • Custom($TEXTAREA_SEARCH_STYLE, Style: Set search style
  • Style(Style): Set the general style for the textarea
  • Custom($TEXTAREA_TAB_SIZE, Size): Set the tab size to display
  • FocusStyle(Style): inactive style
  • ScrollStep(Length): Defines the maximum amount of rows to scroll
  • Title(Title): Set box titleù

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);
Run

Structs

Constants