Ratatui CLI TUI Feature Guide
Ratatui CLI TUI Feature Guide
Quick Start
Launch the interactive dashboard:
audio-ninja tuiOr with a custom daemon URL:
audio-ninja --daemon http://192.168.1.100:8080 tuiOverview
The Audio Ninja CLI now features a modern Terminal User Interface (TUI) built with Ratatui. It provides:
- 5 Interactive Screens: Dashboard, Speakers, Layout, Transport, Calibration
- Real-time Data: Status, statistics, and system information
- Keyboard-First Navigation: Arrow keys, vim keybindings, and intuitive shortcuts
- Beautiful Colors: Professional color scheme with cyan, yellow, and green accents
- Error Reporting: Clear error messages in the footer
Screen Descriptions
1. Dashboard
The main status screen showing:
- Daemon Status: Current daemon health and information
- Statistics: System-wide audio metrics
Keyboard: [←→] to navigate tabs, [q] to quit
2. Speakers
Management interface for connected speakers:
- Lists all currently connected speakers
- Shows speaker details (ID, status, capabilities)
- Press [d] to initiate speaker discovery
Commands:
- [d] - Discover speakers on the network
- [↑↓] - Select speaker
- [←→] - Switch tabs
3. Layout
Speaker layout configuration interface:
- Displays current layout (e.g., stereo, 5.1, 7.1)
- Available presets: stereo, 5.1, 7.1, custom
- Switch between layouts easily
Available Presets:
stereo- 2.0 (Front Left, Front Right)5.1- 5.1 (FL, FR, C, SW, SL, SR)7.1- 7.1 (FL, FR, C, SW, SL, SR, BL, BR)
4. Transport
Playback control and monitoring:
- Current playback status
- Quick controls for Play, Stop, Resume
- Stream information and timing
Controls:
- [P] - Play
- [S] - Stop
- [R] - Resume/Pause
5. Calibration
Room calibration status and control:
- Current calibration state
- Measurement and solving progress
- Apply calibration filters
Controls:
- [C] - Start new calibration
- [A] - Apply calibration results
Keyboard Reference
Navigation
| Key | Action |
|---|---|
← or p | Previous screen/tab |
→ or n | Next screen/tab |
↑ or k | Select item above |
↓ or j | Select item below |
Operations
| Key | Action |
|---|---|
r | Refresh current screen data |
d | Discover speakers (Speakers screen) |
c | Start calibration (Calibration screen) |
a | Apply calibration (Calibration screen) |
p | Play (Transport screen) |
s | Stop (Transport screen) |
r | Resume (Transport screen) |
General
| Key | Action |
|---|---|
q | Quit application |
Esc | Quit application |
Color Scheme
- Cyan - Screen titles and borders
- Green - Section headers
- Yellow - Highlighted elements, keyboard hints
- White - Default text
- Red - Error messages
Implementation Details
Architecture
crates/cli/src/
├── main.rs # CLI entry point with TUI mode
├── tui/
│ ├── mod.rs # Module exports
│ ├── app.rs # Application state (App, Screen)
│ ├── ui.rs # Rendering logic (draw functions)
│ └── handler.rs # Input handling (keyboard events)
└── ...Data Flow
- User runs
audio-ninja tui - TUI initializes and loads initial data from daemon API
- Event loop runs with 250ms input poll timeout
- Keyboard input updates app state
- Frame is redrawn with new state
- Loop continues until user quits
Key Components
App State (app.rs):
- Tracks current screen
- Holds API response data
- Manages selection indices
- Error message storage
Rendering (ui.rs):
- Layout management with constraints
- Per-screen rendering logic
- Widget composition and styling
- Real-time data display
Input Handler (handler.rs):
- Async keyboard event polling
- Vim-style keybindings
- Modifier-aware shortcuts
- Graceful input handling
API Integration
The TUI fetches data from the daemon REST API:
| Endpoint | Purpose |
|---|---|
/api/v1/status | Daemon status |
/api/v1/info | Daemon information |
/api/v1/speakers | List speakers |
/api/v1/speakers/discover | Start discovery |
/api/v1/layout | Current layout |
/api/v1/transport/status | Playback status |
/api/v1/calibration/status | Calibration status |
/api/v1/stats | System statistics |
Advanced Usage
Custom Daemon URL
# Connect to remote daemon
audio-ninja --daemon http://192.168.1.100:8080 tui
# Use environment variable (not yet supported, but can be added)
export AUDIO_NINJA_DAEMON=http://remote-host:8080
audio-ninja tuiFuture Features (Planned)
- Auto-refresh with configurable intervals
- Multi-speaker level metering
- Latency visualization
- Interactive speaker calibration
- Scene management
- Mouse support
- Settings/preferences screen
Troubleshooting
TUI won't start
Problem: "Failed to connect to daemon"
Solution: Ensure daemon is running on the correct address
# Start daemon first
cargo run -p audio-ninja-daemon --release
# Then run TUI in another terminal
audio-ninja tuiGarbled display
Problem: Terminal colors or text rendering issues
Solution:
- Ensure terminal supports 256 colors
- Try
TERM=xterm-256color audio-ninja tui - Check terminal is large enough (minimum 80x24)
Keyboard not responding
Problem: Keys seem unresponsive
Solution:
- Press [q] and restart
- Ensure no other program is capturing input
- Try in a different terminal emulator
Performance Notes
- Memory: Minimal footprint (~5-10MB)
- CPU: Low idle usage (<1%)
- Refresh Rate: 60 FPS maximum (250ms input poll)
- Network: Async API calls, no blocking I/O
Build Instructions
# Build CLI with TUI support
cargo build -p audio-ninja-cli --release
# Run binary
./target/release/audio-ninja tui
# Or run directly
cargo run -p audio-ninja-cli --release -- tuiTesting
The TUI state machine is tested:
# Run tests including TUI state tests
cargo test -p audio-ninja-cli
# Test with daemon running
cargo run -p audio-ninja-daemon --release &
cargo test -p audio-ninja-cli --test e2e_daemon_cliContribution Guidelines
When contributing to the TUI:
- Keep screen components in separate functions
- Add keyboard hints to help text
- Use consistent color scheme
- Test on terminals with limited space (80x24)
- Maintain async/await patterns
- Document new shortcuts in this guide
Example Workflow
# Terminal 1: Start daemon
cargo run -p audio-ninja-daemon --release
# Terminal 2: Run TUI
cargo run -p audio-ninja-cli --release -- tui
# In TUI:
# 1. Press [→] to go to Speakers screen
# 2. Press [d] to discover speakers
# 3. Press [→] to go to Layout screen
# 4. View available presets
# 5. Press [→] to go to Transport
# 6. Press [p] to start playback
# 7. Press [q] to quit