feat: add watch mode for auto-refreshing diffs#96
feat: add watch mode for auto-refreshing diffs#96vertti wants to merge 8 commits intodlvhdr:mainfrom
Conversation
Add --watch/-w, --watch-cmd, and --watch-interval flags to enable periodic diff command execution and UI refresh.
RunCmd executes a shell command and returns stdout with ANSI stripped.
Allows resetting the diff cache when input changes (needed for watch mode).
Schedule periodic ticks that re-run the watch command, compare output, and refresh the file tree and diff viewer when changes are detected. Preserves cursor position across refreshes. Empty diffs no longer quit when watch mode is enabled.
In watch mode, skip stdin and run the watch command for initial data. Allow empty initial output so the TUI starts and keeps ticking.
Displays "watching: <cmd>" in the footer when watch mode is active.
- Add watchInFlight guard to prevent overlapping fetches on slow commands - Discard stderr in watch.RunCmd to avoid corrupting TUI display - Use log.Warn consistently for transient watch command failures - Add watch mode flags and usage section to README - Add watch example to cobra Example string
|
hmm I a bit wary of introducing this complexity. How do the alternatives look? e.g. using the watch command or entr |
|
Totally fair concern! I looked into this before going the built-in route. The core problem is that For what it's worth, every TUI app I checked builds refresh in for the same reason:
The implementation here follows the standard Bubble Tea tick -> fetch -> message pattern (~60 lines of actual logic), so it shouldn't add much maintenance surface. That said, if you had a specific approach in mind that I haven't considered, happy to explore it! |
|
ok thanks for the detailed response - looks like you did your research :) |
Summary
When working on a branch, it's useful to leave diffnav open in a terminal tab and have it automatically reflect the latest changes. This adds
--watchmode, which periodically re-runs a diff command and refreshes the TUI.diffnav --watch diffnav --watch --watch-cmd "git diff main..." --watch-interval 5sDetails
--watch(-w),--watch-cmd(default:git diff),--watch-interval(default:2s)ClearCacheon diffviewer for clean re-renders on refresh