ntdiff is a Golang Terminal Diff viewer for the Bubble Tea Framework and other TUIs. It parses unified diffs and provides an interactive split-pane terminal interface to explore code changes.
- Split-Pane Layout: List of changed files with addition/deletion counts on the left; scrollable, colorized unified diff viewport on the right.
- Dynamic Adjustments: Responsive UI that adapts to terminal resize events automatically.
- Syntax Highlighting: Uses Lip Gloss to colorize diff components (additions in green, deletions in red, hunk headers in cyan, diff headers in magenta).
- Interactive Navigation: Smooth pane switching (
Taborh/l) and scrolling/list navigation (↑/↓ork/j). - Flexible Inputs: Automatically detects piped stdin, accepts direct file/directory paths, or runs
git difffallback. - WebAssembly Ready: Full browser demo utilizing the Ghostty terminal emulator engine (
ghostty-web) viabooba.
go install github.com/NimbleMarkets/ntdiff/cmd/ntdiff@latest# Run git diff inside a repository
ntdiff
# Read a diff from a file
ntdiff patch.diff
# Compare two files or directories outside a git repository
ntdiff file1.txt file2.txt
# Pipe a command output directly
git diff HEAD~1 | ntdiffntdiff can also be integrated into other Bubble Tea applications as a model.
package main
import (
"fmt"
"os"
tea "charm.land/bubbletea/v2"
"github.com/NimbleMarkets/ntdiff/diff"
)
func main() {
diffText := `diff --git a/hello.txt b/hello.txt
--- a/hello.txt
+++ b/hello.txt
@@ -1,1 +1,2 @@
hello
+world!
`
model := diff.NewModel()
model.LoadDiff(diffText)
p := tea.NewProgram(model)
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
os.Exit(1)
}
}We have migrated to Bubble Tea v2. You should import ntdiff as so:
import "github.com/NimbleMarkets/ntdiff/diff"Please note that the dependencies are tied to charm.land/bubbletea/v2 and charm.land/lipgloss/v2 for WebAssembly and rendering enhancements.
ntdiff features a browser-based demo that runs the compiled WebAssembly binary inside a native high-fidelity web terminal engine (ghostty-web).
# Build the WebAssembly site assets
task build-wasm-site
# Serve locally at http://localhost:8000/ntdiff/
task serve-wasm-site