ratkit

Core runtime and 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 |
| StatusLineStacked | Neovim-style powerline status |
| TermTui | Terminal emulator with mprocs-style copy mode |
Installation
Add the core runtime to your Cargo.toml:
[]
= "0.1"
For the full bundle of components:
[]
= { = "0.1", = ["all"] }
For selected components:
[]
= { = "0.1", = false, = ["tree-view", "resizable-grid", "toast"] }
Feature Flags
ratkit ships as a core runtime with optional components. By default only the
core runtime is enabled; opt in to specific components or use the all feature
to pull everything.
= { = "0.1", = false, = ["tree-view", "toast"] }
| Feature | Description |
|---|---|
default |
Core runtime only (Runner + Layout Manager) |
all |
All widgets and services |
full |
Alias for all |
widgets |
All UI widgets |
services |
All service components |
| Feature | Component |
|---|---|
button |
Button widget |
pane |
Pane widget |
dialog |
Modal dialog components |
toast |
Toast notification system |
statusline |
Powerline-style statusline |
scroll |
Scrollable content helpers |
menu-bar |
Menu bar component |
resizable-grid |
Resizable split panels |
tree-view |
Generic tree view widget |
widget-event |
Widget event helpers |
termtui |
Terminal emulator (TermTui) |
markdown-preview |
Markdown preview widget |
code-diff |
Code diff widget |
ai-chat |
AI chat widget |
hotkey-footer |
Hotkey footer widget |
file-system-tree |
File browser with devicons and sorting |
theme-picker |
Theme picker widget |
file-watcher |
File watcher service |
git-watcher |
Git watcher service |
repo-watcher |
Repo watcher service |
hotkey-service |
Hotkey service |
Quick Start
use *;
use ;
use Duration;
// 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;
For a multi-pane layout with drag-resize, see examples/split_demo.rs.
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
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 |
|---|---|---|
| ratkit | 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).