pratdiff is a colorful diff CLI tool in Rust implementing the Patience Diff algorithm (with a histogram extension for non-unique lines). It supports line-level and token-level colorization for files and directory trees.
src/
├── lib.rs - Core Patience Diff algorithm
├── bin/pratdiff.rs - CLI entry point (clap-based)
├── diff.rs - Core data structures: DiffItem, Hunk, Diffs
├── files.rs - File/directory I/O and diff dispatch
├── printer.rs - Output formatting and colorization
└── style.rs - Color style definitions (owo_colors)
Data flow: bin/pratdiff.rs → files.rs → lib.rs (diff algorithm) → printer.rs (render)
cargo build --release
cargo test # 12 unit tests in lib.rs + integration tests
cargo test <test_name> # Run a specific test- Token-level diffs:
tokenize_lines()inlib.rsapplies the same patience diff recursively at the token level for changed lines. Tokens include: whitespace, numbers, identifiers, and symbols. - Byte-oriented diff core:
lib.rsoperates directly on&[u8]slices. Both line-level and token-level diffing use the same concretediff(&[&[u8]], &[&[u8]])function. - Histogram fallback: When no unique lines exist for patience diff, falls back to histogram diff (counts occurrences, prefers rarer lines).
- Common prefix stripping:
--verbose-pathsdisables common path prefix removal in output headers.
-as filename means stdin- Binary files (non-UTF-8) are detected and reported but not diffed
- Unix inode checks prevent diffing a file against itself
- Color output auto-detects terminal; controllable via
--color=always|never|auto