ratatui-interact
Interactive TUI components for ratatui with focus management and mouse support.
Ratatui doesn't include built-in focus navigation or mouse click handling. This library fills that gap with ready-to-use interactive widgets and a flexible composition system.
Features
- Focus Management - Tab/Shift+Tab navigation with
FocusManager<T> - Mouse Click Support - Click regions with hit-testing via
ClickRegionandClickRegionRegistry - Interactive Widgets - CheckBox, Input, Button, Select, ContextMenu, MenuBar, PopupDialog
- Display Widgets - ParagraphExt, Toast, Progress, MarqueeText, Spinner, MousePointer
- Navigation Widgets - ListPicker, TreeView, FileExplorer, Accordion
- Layout Widgets - TabView, SplitPane
- Viewer Widgets - ScrollableContent, LogViewer, DiffViewer, StepDisplay
- Utilities - ANSI parsing, display helpers, View/Copy mode, exit strategies
- Composition Traits -
Focusable,Clickable,Containerfor building custom components
Installation
Add to your Cargo.toml:
[]
= "0.4"
Or from git:
[]
= { = "https://github.com/Brainwires/ratatui-interact.git" }
Quick Start
use *;
// Define focusable elements
// Set up focus manager
let mut focus = new;
focus.register;
focus.register;
focus.register;
// Create component states
let mut input_state = new;
let mut checkbox_state = new;
let button_state = enabled;
// Handle keyboard events
match event
// Render with focus awareness
let input = new
.label
.focused;
let click_region = input.render_stateful;
// Handle mouse clicks
if let Some = click_region.contains
Components
Interactive Components
| Component | Description |
|---|---|
| CheckBox | Toggleable checkbox with multiple symbol styles (ASCII, Unicode, checkmark) |
| Input | Text input with cursor, insertion, deletion, and navigation |
| TextArea | Multi-line text input with cursor, line numbers, scrolling, and word wrap |
| Button | Multiple variants: SingleLine, Block, Toggle, Icon+Text |
| Select | Dropdown select box with popup options, keyboard/mouse navigation |
| ContextMenu | Right-click popup menu with actions, separators, shortcuts, and submenus |
| MenuBar | Traditional File/Edit/View/Help style menu bar with dropdowns, submenus, and shortcuts |
| PopupDialog | Container for modal dialogs with focus management |
| HotkeyDialog | Hotkey configuration dialog with search, categories, and trait-based customization |
Display Components
| Component | Description |
|---|---|
| AnimatedText | Animated text with color effects (pulse, wave, rainbow, gradient, sparkle) |
| ParagraphExt | Extended paragraph with word-wrapping and scrolling |
| Toast | Transient notification popup with auto-expiration and style variants |
| Progress | Progress bar with label, percentage, and step counter |
| MarqueeText | Scrolling text for long content in limited space (continuous, bounce, static modes) |
| Spinner | Animated loading indicator with 12 frame styles (dots, braille, line, etc.) |
| MousePointer | Visual indicator at mouse cursor position with customizable styles |
Navigation Components
| Component | Description |
|---|---|
| ListPicker | Scrollable list with selection cursor for picking items |
| TreeView | Collapsible tree view with selection and customizable rendering |
| FileExplorer | File browser with multi-select, search, and hidden file toggle |
| Accordion | Collapsible sections with single or multiple expansion modes |
| Breadcrumb | Hierarchical navigation path with ellipsis collapsing and keyboard/mouse support |
Layout Components
| Component | Description |
|---|---|
| TabView | Tab bar with content switching, supports top/bottom/left/right positions |
| SplitPane | Resizable split pane with drag-to-resize divider, horizontal/vertical orientations |
Viewer Components
| Component | Description |
|---|---|
| ScrollableContent | Scrollable text pane with focus support, keyboard/mouse navigation, and View/Copy mode for native terminal text selection |
| LogViewer | Scrollable log viewer with line numbers, search, and log-level coloring |
| DiffViewer | Diff viewer with unified and side-by-side modes, hunk navigation, search, and syntax highlighting |
| StepDisplay | Multi-step progress display with sub-steps and output areas |
Utilities
ANSI Parser
Parse ANSI escape codes to ratatui styles:
use parse_ansi_to_spans;
let text = "\x1b[31mRed\x1b[0m Normal";
let spans = parse_ansi_to_spans;
Supports: SGR codes (bold, italic, colors), 256-color mode, RGB mode.
Display Utilities
use ;
let truncated = truncate_to_width; // "Hello..."
let padded = pad_to_width; // "Hi "
let clean = clean_for_display;
let size = format_size; // "1.5 KB"
View/Copy Mode & Exit Strategies
use ;
// Enter view/copy mode for native terminal text selection
let mode = enter?;
mode.print_lines?;
// ... wait for user input ...
mode.exit?;
// Choose exit strategy
let strategy = PrintContent; // or ExitStrategy::RestoreConsole
strategy.execute?;
Examples
See examples/README.md for detailed code examples of each component.
Run the examples:
# Interactive Components
# Display & Viewer Components
# Navigation & Layout Components
# Combined Demo (requires filesystem feature)
Comparison with Alternatives
| Feature | ratatui-interact | rat-focus | tui-input |
|---|---|---|---|
| Focus management | ✅ Generic FocusManager<T> |
✅ FocusFlag based |
❌ |
| Mouse click regions | ✅ ClickRegion with hit-testing |
✅ Area-based | ❌ |
| Ready-to-use widgets | ✅ Many (see above) | ❌ | ✅ Input only |
| Composition traits | ✅ Focusable, Clickable, Container | ❌ | ❌ |
License
MIT