WatchDiff ๐ญ
A professional-grade file watcher with beautiful TUI, multiple diff algorithms, and comprehensive patch export capabilities, written in Rust.
Features
Core Capabilities
- ๐ High Performance: Built with Rust for maximum speed and efficiency
- ๐จ Beautiful TUI: Rich terminal interface with scrollable diff log and file list
- ๐ Syntax Highlighting: Full syntax highlighting for 25+ programming languages in diffs
- ๐ Smart Filtering: Respects
.gitignorepatterns automatically - ๐ Real-time Diffs: Shows beautiful diffs for text file changes as they happen
- โจ๏ธ Easy CLI: Multiple output formats and intuitive keyboard shortcuts
- ๐งต Async: Non-blocking file watching with threaded architecture
Advanced Features
- ๐ง Multiple Diff Algorithms: Choose from Myers, Patience, or LCS algorithms
- ๐ค Patch Export: Export changes as unified diffs, Git patches, or multifile bundles
- ๐ Rich Statistics: Comprehensive diff statistics with addition/deletion ratios
- ๐๏ธ Modular Architecture: Clean separation of concerns with trait-based design
- ๐ฏ Professional Tools: Enterprise-grade patch management and export functionality
Installation
From Cargo
Build from Source
Usage
Basic Usage
# Watch current directory with TUI
# Watch specific directory
# Watch with text output
# Watch only specific file types
# JSON output for scripting
Advanced Usage
# Use different diff algorithms
# Export patches while watching
# Combine algorithm and export
User Interface
TUI Mode (Default)
WatchDiff features a modern, responsive terminal user interface built with ratatui. The interface is designed for maximum productivity and ease of use.
Interface Layout
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Changes (โโ to scroll, PgUp/PgDn, Home/End) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [12:34:56] MODIFIED src/main.rs โ
โ --- src/main.rs โ
โ +++ src/main.rs โ
โ @@ -15,7 +15,8 @@ โ
โ - fn main() { โ
โ + fn main() -> Result<()> { โ
โ let cli = Cli::parse(); โ
โ + println!("Starting WatchDiff..."); โ
โ โ
โ [12:34:52] CREATED docs/api.md โ
โ Preview: โ
โ # API Documentation โ
โ This document describes the WatchDiff API... โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Watched Files (847) (โโ to scroll) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ src/main.rs โ
โ src/lib.rs โ
โ src/cli.rs โ
โ src/watcher.rs โ
โ src/diff.rs โ
โ src/tui.rs โ
โ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Status โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Press q to quit, h for help, โโ to scroll diff โ
โ Events: 23 | Files watched: 847 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Panel Breakdown
๐ Top Panel - Changes Log (70% height)
- Real-time scrollable feed of file changes
- Color-coded event types:
- ๐ข CREATED - New files (green)
- ๐ก MODIFIED - Changed files (yellow)
- ๐ด DELETED - Removed files (red)
- ๐ต MOVED - Renamed/moved files (blue)
- Full syntax highlighting for 25+ languages including:
- Rust, Python, JavaScript, TypeScript, Java, C/C++, Go
- HTML, CSS, JSON, YAML, TOML, XML, Markdown
- Bash, SQL, Dockerfile, and many more
- Unified diff format with intelligent syntax preservation
- Timestamps for each event
- Syntax-highlighted content preview for new files
- Scrollbar for long change lists
๐ Middle Panel - File List (25% height)
- Live list of all watched files
- File count indicator
- Alternating row colors for readability
- Horizontal scrolling for long paths
- Respects .gitignore patterns
โน๏ธ Bottom Panel - Status Bar (5% height)
- Real-time statistics (event count, file count)
- Keyboard shortcuts reminder
- Application status indicators
Visual Features
- Color Coding: Intuitive colors for different change types
- Responsive Layout: Adapts to terminal size changes
- Smooth Scrolling: Efficient scrolling through large change logs
- Typography: Clear, readable text with proper spacing
- Borders: Clean visual separation between panels
- Icons: Unicode symbols for better visual hierarchy
Keyboard Shortcuts
| Key | Action |
|---|---|
q, Esc |
Quit application |
h, F1 |
Toggle help screen |
โ, k |
Scroll diff log up |
โ, j |
Scroll diff log down |
PgUp |
Scroll diff log up (fast) |
PgDn |
Scroll diff log down (fast) |
Home |
Go to top of diff log |
End |
Go to bottom of diff log |
โ, โ |
Scroll file list |
Help Screen
Press h or F1 to open the interactive help screen:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Help โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ WatchDiff - File Watching Tool โ
โ โ
โ Keyboard Shortcuts: โ
โ โ
โ q, Esc - Quit the application โ
โ h, F1 - Show/hide this help โ
โ โ, k - Scroll diff log up โ
โ โ, j - Scroll diff log down โ
โ PgUp - Scroll diff log up (fast) โ
โ PgDn - Scroll diff log down (fast) โ
โ Home - Go to top of diff log โ
โ End - Go to bottom of diff log โ
โ โ, โ - Scroll file list โ
โ โ
โ Features: โ
โ โ
โ โข Real-time file change monitoring โ
โ โข Respects .gitignore patterns โ
โ โข Shows diffs for text file changes โ
โ โข Scrollable diff log and file list โ
โ โข High performance with async processing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Alternative Output Modes
For non-interactive use cases, WatchDiff supports several output formats:
Text Mode (--output text)
) {
)
JSON Mode (--output json)
Compact Mode (--output compact)
Format Legend:
C= CreatedM= ModifiedD= DeletedV= Moved
CLI Options
Options:
-m, --mode <MODE> File watching mode [auto|native|polling]
--max-events <N> Maximum events to store [default: 1000]
-v, --verbose Enable verbose logging
--no-color Disable colored output
--extensions <EXTS> File extensions to watch (e.g., rs,py,js)
--ignore <PATTERNS> Additional patterns to ignore
--context <N> Number of diff context lines [default: 3]
--output <FORMAT> Output format [tui|json|text|compact]
--poll-interval <MS> Polling interval in ms [default: 1000]
--algorithm <ALG> Diff algorithm [myers|patience|lcs] [default: myers]
--export-dir <DIR> Export patches to directory (TUI mode only)
Diff Algorithms
WatchDiff supports multiple diff algorithms, each optimized for different scenarios:
| Algorithm | Best For | Characteristics |
|---|---|---|
| Myers | General purpose | Fast, widely used, good balance |
| Patience | Code refactoring | Better handling of moved code blocks |
| LCS | Minimal changes | Produces smallest possible diffs |
Export Functionality
When using --export-dir, WatchDiff automatically saves patches in multiple formats:
- Unified diffs (
.patchfiles) - Standard diff format - Git patches (
.git.patchfiles) - Git-compatible format - Multifile patches - Combined patches for multiple files
- Patch bundles - Organized directory structure with manifest
Examples
Development Workflow
# Watch Rust project files only
# Watch with additional ignores
# JSON output piped to file
CI/CD Integration
# Compact format for build scripts
# Export patches for review process
Programmatic Usage
WatchDiff can also be used as a Rust library with a powerful API:
use ;
// Generate diffs with different algorithms
let generator = new;
let result = generator.generate;
// Format as unified diff
let formatted = format_unified;
// Export to file
let exporter = unified;
exporter.export_diff?;
// Get statistics
println!;
Library Features
- Trait-based architecture for extensible diff algorithms
- Multiple export formats (unified, Git patch, side-by-side)
- Rich diff statistics and metadata
- Professional patch management capabilities
- Comprehensive test coverage
See examples/advanced_usage.rs for complete usage examples.
Architecture
WatchDiff is built with modern Rust practices and clean architecture:
Module Organization
src/
โโโ core/ # Core file watching and event handling
โ โโโ events.rs # Event definitions and processing
โ โโโ filter.rs # File filtering with .gitignore support
โ โโโ watcher.rs # File system monitoring
โโโ diff/ # Modular diff generation system
โ โโโ algorithms.rs # Trait-based algorithm implementations
โ โโโ generator.rs # High-level diff generation
โ โโโ formatter.rs # Multiple output formats
โโโ export/ # Professional patch export capabilities
โโโ ui/ # Terminal user interface
โโโ highlight.rs # Syntax highlighting integration
Key Dependencies
- File Watching:
notifycrate for cross-platform filesystem events - TUI:
ratatuiwithcrosstermfor beautiful terminal interfaces - Syntax Highlighting:
syntectcrate for 25+ programming languages - CLI:
clapfor robust argument parsing with derive macros - Diffing:
similarcrate with multiple algorithm implementations - Filtering:
ignorecrate for comprehensive.gitignoresupport - Async:
tokiofor non-blocking operations - Date/Time:
chronofor export timestamps and metadata
Design Principles
- Trait-based Design: Extensible algorithms via traits
- Separation of Concerns: Clear module boundaries
- Type Safety: Comprehensive type system usage
- Performance: Zero-cost abstractions and efficient algorithms
- Testability: Each module independently testable with comprehensive coverage
Performance
- Handles thousands of files efficiently
- Memory-bounded event history (configurable)
- Native filesystem events (with polling fallback)
- Optimized diff generation
- Background processing threads
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please open issues or pull requests.