| Crates.io | rat-text |
| lib.rs | rat-text |
| version | 1.1.0 |
| created_at | 2024-08-25 16:16:14.646428+00 |
| updated_at | 2025-09-07 18:35:27.22022+00 |
| description | ratatui text input widgets |
| homepage | |
| repository | https://github.com/thscharler/rat-salsa |
| max_upload_size | |
| id | 1351217 |
| size | 913,598 |
This crate is a part of rat-salsa.
For examples see rat-text GitHub or an extended example mdedit.rs in
rat-salsa GitHub.
Features for all widgets:
Undo/redo
Sync another widget
Support double-width characters
Range based text styling
Wrapped text
Clipboard trait to link to some clipboard implementation.
There is no general solution for clipboards but this way you can integrate one of the many crates that try to do this.
Builtin scrolling. Uses rat-scrolled.
Lots of text manipulation functions.
Single line text input widget.
// actual text is held in the state:
state.textinput.set_value("sample");
// render
TextInput::new()
.style(Style::default().white().on_dark_gray())
.select_style(Style::default().black().on_yellow())
.render(txt_area, frame.buffer_mut(), &mut state.textinput);
// during event-handling
match text_input::handle_events(&mut state.textinput, true /*focused*/, event) {
TextOutcome::Continue => { /* no handling */ }
TextOutcome::Unchanged => { /* event recognized, but no changes */ }
TextOutcome::Changed => { /* render required */ }
TextOutcome::TextChanged => { /* actual edit */ }
}
Textarea with tendencies to being an editor.
Uses ropey as backend and iset to manage the text-styles.
// text is stored in the state
state.textarea.set_text("some text");
// render
TextArea::new()
.block(Block::bordered())
.vscroll(
Scroll::new()
.scroll_by(1)
.policy(ScrollbarPolicy::Always),
)
.hscroll(Scroll::new().policy(ScrollbarPolicy::Always))
.styles(istate.theme.textarea_style())
.text_style([
Style::new().red(),
Style::new().underlined(),
Style::new().green(),
Style::new().on_yellow(),
])
.render(layout[2], frame.buffer_mut(), &mut state.textarea);
// event-handling
match text_area::handle_events(&mut state.textarea, true /* focused */, event) {
TextOutcome::Continue => { /* no handling */ }
TextOutcome::Unchanged => { /* event recognized, but no changes */ }
TextOutcome::Changed => { /* render required */ }
TextOutcome::TextChanged => { /* actual edit */ }
}
There is an extended example mdedit.rs for TextArea in
rat-salsa
Single line text input with a text-mask for allowed input.
Nice to have for structured text input.
The widgets
use this as base.
DateInput with chrono format patterns.
NumberInput with format_num_pattern backend. A bit similar to javas DecimalFormat.
Line numbers widget that can be combined with TextArea.