ratatui-toolkit

A comprehensive collection of reusable TUI components for ratatui, the Rust terminal UI library.
Features
| Component | Description |
|---|---|
| ResizableSplit | Draggable split panels (vertical/horizontal) with mouse support |
| TreeView | Generic tree widget with expand/collapse, navigation, and selection |
| FileSystemTree | File browser with devicons and sorting |
| MarkdownRenderer | Render markdown to styled ratatui Text |
| Toast | Toast notifications with auto-expiry and severity levels |
| Dialog | Modal dialogs (Info/Success/Warning/Error/Confirm) |
| Button | Clickable buttons with hover states |
| HotkeyFooter | Keyboard shortcut display footer |
| MenuBar | Horizontal menu bar with icons |
| StatusBar | Customizable status bar |
| StatusLineStacked | Neovim-style powerline status |
| TermTui | Terminal emulator with mprocs-style copy mode |
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or with specific features:
[]
= { = "0.1", = false, = ["tree", "split", "toast"] }
Feature Flags
| Feature | Default | Description |
|---|---|---|
markdown |
✅ | Markdown rendering to ratatui Text |
tree |
✅ | Generic tree view widget |
dialog |
✅ | Modal dialog components |
toast |
✅ | Toast notification system |
split |
✅ | Resizable split panels |
menu |
✅ | Menu bar component |
statusbar |
✅ | Status bar components |
hotkey |
✅ | Hotkey footer and modal |
terminal |
✅ | Terminal emulator (TermTui) |
file-tree |
❌ | File system tree with devicons |
full |
❌ | Enable all features |
Quick Start
use *;
use *;
// Create a resizable split
let split = new
.ratio
.min_ratio
.max_ratio;
// Create a toast notification
let toast = new
.level
.duration;
// Render markdown
let text = render_markdown;
Examples
Run examples with:
Resizable Split
use ;
let mut split = new
.ratio
.min_ratio
.max_ratio;
// Handle mouse events
if let Some = split.handle_mouse
// Render
let = split.split;
frame.render_widget;
frame.render_widget;
Tree View
use ;
// Build tree structure
let root = new
.with_children;
let mut state = new;
let tree = new;
// Handle navigation
state.handle_key; // Move down
state.handle_key; // Expand
state.handle_key; // Collapse
Toast Notifications
use ;
use Duration;
let mut manager = new
.max_toasts
.default_duration;
// Add toasts
manager.push;
manager.push;
manager.push;
manager.push;
// Update and render
manager.tick; // Remove expired toasts
render_toasts;
Markdown Rendering
use ;
// Simple rendering
let text = render_markdown;
// Custom styling with syntax highlighting
let style = default;
let text = render_markdown_with_style;
// Interactive widget with scroll management
let mut scroll_manager = new;
let widget = new
.with_style;
frame.render_stateful_widget;
Markdown Features:
- Syntax highlighting for code blocks
- Configurable themes
- Scroll management for long documents
- Expandable/collapsible sections
Terminal Emulator (TermTui)
use ;
// Spawn a terminal with default shell
let shell = var.unwrap_or;
let mut term = spawn_with_command?;
// Handle input
term.handle_key;
term.handle_mouse;
// Render
term.render;
Default Keybindings:
Ctrl+X- Enter copy modeCtrl+Shift+C- Copy selection
Copy Mode:
h/j/k/lor arrows - NavigatevorSpace- Start selectionyorEnter- Copy and exitw/b- Word navigation0/$- Line start/endg/G- Top/bottomEscorq- Exit copy mode
Customizable Keybindings
All interactive components expose their keybindings through configuration structs, allowing full customization:
TermTui
use ;
use ;
// Create custom keybindings
let mut bindings = default;
bindings.enter_copy_mode = new;
let term = spawn_with_command?
.with_keybindings;
TreeView
use ;
use KeyCode;
let bindings = new
.with_next
.with_previous
.with_expand
.with_collapse;
let navigator = with_keybindings;
Available Keybinding Configs
| Component | Config Struct | Builder Method |
|---|---|---|
| TermTui | TermTuiKeyBindings |
.with_keybindings() |
| TreeView | TreeKeyBindings |
TreeNavigator::with_keybindings() |
Architecture
Module Structure
All components follow a consistent module organization pattern for maintainability:
src/component_name/
├── mod.rs # Type definition only (struct/enum)
├── constructors/ # Constructors and builders (new, with_*, builder)
│ ├── mod.rs
│ ├── new.rs
│ └── with_*.rs
├── methods/ # Instance methods (&self, &mut self)
│ ├── mod.rs
│ └── method_name.rs
└── traits/ # Trait implementations (Widget, Default, etc.)
├── mod.rs
└── trait_name.rs
This structure ensures:
- Single responsibility: Each file contains one impl block
- Easy navigation: Find constructors in
constructors/, methods inmethods/ - Consistent patterns: All components organized identically
Component Pattern
All components follow ratatui's Widget and StatefulWidget patterns:
// Stateless widget
// Stateful widget
Mouse Support
Components support mouse interaction through a consistent API:
// Handle mouse events
if let Some = component.handle_mouse
Comparison with Alternatives
| Crate | Focus | Components |
|---|---|---|
| ratatui-toolkit | Comprehensive component library | 17+ components |
tui-textarea |
Text editing | Textarea only |
tui-tree-widget |
Tree views | Tree only |
ratatui-image |
Image rendering | Images only |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).