# **rfgrep TUI (Terminal User Interface) Demonstration**
## **🎯 TUI Overview**
The rfgrep TUI is a modern, interactive terminal interface built with `ratatui` and `crossterm` that provides a powerful file search experience directly in the terminal.
## **✨ Key Features**
### **1. Interactive Search Interface**
- **Real-time search** with live results
- **Pattern input** with instant feedback
- **Multiple search modes**: Text, Word, Regex
- **Multiple algorithms**: Boyer-Moore, Regex, Simple, SIMD
### **2. Dual-Pane Layout**
- **Files Panel**: Shows all files containing matches
- **Matches Panel**: Displays search results with line numbers and content
- **Synchronized navigation** between files and matches
### **3. Advanced Navigation**
- **Keyboard shortcuts** for efficient navigation
- **Scrollable results** with visual scrollbars
- **File jumping** to specific matches
- **Context-aware highlighting**
### **4. Interactive Controls**
- **Live search refresh** without restarting
- **Mode switching** on the fly
- **Algorithm switching** for performance comparison
- **Case sensitivity toggle**
## **🎮 Controls and Shortcuts**
| `h` | Toggle Help | Show/hide help overlay |
| `q` | Quit | Exit the TUI |
| `↑/↓` or `j/k` | Navigate Matches | Move through search results |
| `←/→` or `h/l` | Navigate Files | Switch between files |
| `n/N` | Next/Previous Match | Jump to next/previous match |
| `c` | Toggle Case | Toggle case sensitivity |
| `m` | Cycle Mode | Switch between Text/Word/Regex |
| `a` | Cycle Algorithm | Switch search algorithms |
| `r` | Refresh Search | Re-run current search |
| `Enter` | Open File | Open current file in editor |
| `Page Up/Down` | Scroll | Scroll through results |
## **🖥️ Interface Layout**
```
┌─────────────────────────────────────────────────────────────┐
│ rfgrep TUI - Pattern: 'search_term' │ ← Header
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────────────────────────────────┐ │
│ │ Files │ │ Matches │ │ ← Main Content
│ │ ┌─────────┐ │ │ ┌─────┬─────────────────────────────────┐ │ │
│ │ │file1.txt│ │ │ │ 42 │ This line contains search_term │ │ │
│ │ │file2.rs │ │ │ │ 15 │ Another match in search_term │ │ │
│ │ │file3.md │ │ │ │ 78 │ More search_term results │ │ │
│ │ └─────────┘ │ │ └─────┴─────────────────────────────────┘ │ │
│ └─────────────┘ └─────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
```
## **🚀 Usage Examples**
### **Basic TUI Launch**
```bash
# Start TUI with a search pattern
rfgrep tui "function"
# Start TUI and enter pattern interactively
rfgrep tui
# Start TUI with specific algorithm
rfgrep tui "pattern" --algorithm boyer-moore
# Start TUI with case-sensitive search
rfgrep tui "Pattern" --case-sensitive
```
### **Advanced TUI Options**
```bash
# TUI with regex mode
rfgrep tui "\\b\\w+@\\w+\\.\\w+\\b" --mode regex
# TUI with context lines
rfgrep tui "error" --context-lines 3
# TUI with specific search path
rfgrep tui "TODO" --path src/
```
## **🔧 Technical Implementation**
### **Architecture**
- **Frontend**: `ratatui` for terminal UI rendering
- **Backend**: `crossterm` for terminal control
- **Search Engine**: Integrated with rfgrep's plugin system
- **Async Runtime**: Tokio for non-blocking operations
### **State Management**
```rust
pub struct TuiState {
pub pattern: String, // Current search pattern
pub matches: Vec<SearchMatch>, // Search results
pub current_file_index: usize, // Selected file
pub current_match_index: usize, // Selected match
pub files: Vec<String>, // Files with matches
pub search_mode: SearchMode, // Text/Word/Regex
pub algorithm: SearchAlgorithm, // Search algorithm
pub case_sensitive: bool, // Case sensitivity
pub context_lines: usize, // Context around matches
pub show_help: bool, // Help overlay state
pub status_message: String, // Status bar message
pub search_in_progress: bool, // Search state
pub scroll_offset: usize, // Scroll position
}
```
### **Key Components**
1. **TuiApp**: Main application controller
2. **TuiState**: Application state management
3. **UI Rendering**: Modular rendering functions
4. **Event Handling**: Keyboard input processing
5. **Search Integration**: Plugin system integration
## **🎨 Visual Features**
### **Color Coding**
- **Yellow**: Selected items and highlights
- **White**: Normal text
- **Dark Gray**: Status bar background
- **Bold**: Current selection emphasis
### **Interactive Elements**
- **Scrollbars**: Visual scroll indicators
- **Highlighting**: Current selection highlighting
- **Status Updates**: Real-time status messages
- **Help Overlay**: Context-sensitive help
### **Responsive Design**
- **Adaptive Layout**: Adjusts to terminal size
- **Scrollable Content**: Handles large result sets
- **Keyboard Navigation**: Full keyboard control
- **Mouse Support**: Optional mouse interaction
## **⚡ Performance Features**
### **Efficient Rendering**
- **Incremental Updates**: Only redraw changed areas
- **Lazy Loading**: Load results as needed
- **Memory Management**: Efficient state handling
### **Search Optimization**
- **Async Search**: Non-blocking search operations
- **Plugin Integration**: Leverages rfgrep's search engine
- **Real-time Updates**: Live search results
## **🛠️ Development Status**
### **Current Implementation**
- ✅ **Core TUI Framework**: Complete
- ✅ **Search Integration**: Complete
- ✅ **Navigation Controls**: Complete
- ✅ **UI Rendering**: Complete
- ✅ **Event Handling**: Complete
- ✅ **Help System**: Complete
### **Testing Status**
- ✅ **Unit Tests**: Comprehensive coverage
- ✅ **Integration Tests**: CLI integration tested
- ✅ **Performance Tests**: Benchmarking implemented
- ✅ **Stress Tests**: Memory and resource testing
## **🎯 Demo Scenarios**
### **Scenario 1: Code Search**
```bash
# Search for function definitions
rfgrep tui "fn " --mode regex --path src/
# Navigate through results
# Use ↑/↓ to browse matches
# Use ←/→ to switch files
# Press Enter to open file in editor
```
### **Scenario 2: Documentation Search**
```bash
# Search for TODO comments
rfgrep tui "TODO" --path docs/
# Use 'm' to cycle through search modes
# Use 'a' to try different algorithms
# Use 'c' to toggle case sensitivity
```
### **Scenario 3: Large Codebase Search**
```bash
# Search across entire project
rfgrep tui "error" --path . --context-lines 2
# Use Page Up/Down to scroll through results
# Use 'r' to refresh search
# Use 'h' to show help
```
## **🔍 Troubleshooting**
### **Common Issues**
1. **Terminal Compatibility**: Ensure terminal supports UTF-8
2. **Screen Size**: Minimum 80x24 terminal size recommended
3. **Keyboard Input**: Some terminals may have key mapping issues
### **Debug Mode**
```bash
# Run with debug logging
RUST_LOG=debug rfgrep tui "pattern"
```
## **📈 Future Enhancements**
### **Planned Features**
- **Fuzzy Search**: Approximate string matching
- **Search History**: Previous search patterns
- **Bookmarks**: Save interesting matches
- **Export Results**: Save search results to file
- **Custom Themes**: User-configurable colors
- **Plugin Integration**: Extensible search plugins
## **🎉 Conclusion**
The rfgrep TUI represents a significant advancement in terminal-based file search tools, providing:
- **Modern Interface**: Clean, intuitive design
- **Powerful Search**: Full rfgrep search capabilities
- **Efficient Navigation**: Keyboard-driven workflow
- **Real-time Interaction**: Live search and updates
- **Professional Quality**: Enterprise-ready implementation
**The TUI is fully functional and ready for production use!** 🚀
---
*This demonstration showcases the comprehensive TUI implementation in rfgrep v0.3.1, highlighting its modern design, powerful features, and professional-quality implementation.*