feat: add watch mode for auto-refreshing diffs#96
Conversation
|
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 :) |
|
|
||
| cfg.Watch = config.WatchConfig{ | ||
| Enabled: watchFlag, | ||
| Cmd: watchCmd, |
There was a problem hiding this comment.
I'm not sure about these living in the config. You'd usually want to pipe
stuff into diffnav. I think a shell alias is more appropriate. I am down with
There was a problem hiding this comment.
Your comment got cut off — "I am down with" ...?
Two options I see:
- Remove
WatchConfigfromConfigstruct entirely, pass watch params as a separate arg toui.New() - Keep as-is —
WatchConfigis already excluded from YAML persistence withyaml:"-"
Let me know which you'd prefer (or what you had in mind).
There was a problem hiding this comment.
Oh man sorry about that!
Having a default for the watch interval makes sense.
Do you have a use case for having a default watch cmd?
So the config would look like:
defaults:
watchInterval: 2sThere was a problem hiding this comment.
Good call — no real use case for a default watch command in config. WatchConfig is already yaml:"-" so nothing is persisted. I've made --watch-cmd imply --watch so users don't need both flags. If config-file watchInterval is wanted later, happy to add that as a follow-up.
|
Nit: I think Maybe we can just remove the |
8ba46f3 to
c6342e4
Compare
|
@dlvhdr Re: |
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
Passing --watch-cmd now automatically enables watch mode, so users don't need to specify both --watch and --watch-cmd.
|
thanks for adding this feature :) |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [dlvhdr/diffnav](https://github.com/dlvhdr/diffnav) | minor | `v0.10.0` → `v0.11.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>dlvhdr/diffnav (dlvhdr/diffnav)</summary> ### [`v0.11.0`](https://github.com/dlvhdr/diffnav/releases/tag/v0.11.0) [Compare Source](dlvhdr/diffnav@v0.10.0...v0.11.0) ### v0.11.0 #### Notable Features - Search (accessed via <kbd>t</kbd>) now shows the filename first and has icons - <kbd>n/p/N</kbd> is used to navigate to next/previous file - If used with `git show`, and there's a commit preamble present, pressing <kbd>m</kbd> will show the commit info. It's also shown in the header - There's finally a scrollbar in the diffview - Thanks to new contributor [@​vertti](https://github.com/vertti) `diffnav` now supports a `watch` flag which will run `git diff` by default (but can be controlled). It will run the command while maintaining the UI state Once again, thanks to [@​pablospe](https://github.com/pablospe) for his awesome contributions! #### Changelog - [`0957bb1`](dlvhdr/diffnav@0957bb1) chore: upgrade deps ([#​114](dlvhdr/diffnav#114)) - [`4a31deb`](dlvhdr/diffnav@4a31deb) ci: add basic CI workflow ([#​113](dlvhdr/diffnav#113)) - [`dc735a5`](dlvhdr/diffnav@dc735a5) feat(search): show filename first + icons ([#​105](dlvhdr/diffnav#105)) - [`822adc6`](dlvhdr/diffnav@822adc6) feat: Add shift+tab as alias for tab to switch panels ([#​109](dlvhdr/diffnav#109)) - [`41f1c16`](dlvhdr/diffnav@41f1c16) feat: add F1 key to toggle help overlay ([#​101](dlvhdr/diffnav#101)) - [`c899b9e`](dlvhdr/diffnav@c899b9e) feat: add n (next file) and p/N (previous file) shortcuts to jump between files ([#​98](dlvhdr/diffnav#98)) - [`e651360`](dlvhdr/diffnav@e651360) feat: add scrollbar to diff viewer ([#​112](dlvhdr/diffnav#112)) - [`e616b2a`](dlvhdr/diffnav@e616b2a) feat: add watch mode for auto-refreshing diffs ([#​96](dlvhdr/diffnav#96)) - [`19503d8`](dlvhdr/diffnav@19503d8) feat: commit info overlay with `m` key ([#​103](dlvhdr/diffnav#103)) - [`e215560`](dlvhdr/diffnav@e215560) feat: show commit info when used as a pager for git show ([#​97](dlvhdr/diffnav#97)) - [`2898ff7`](dlvhdr/diffnav@2898ff7) fix: sidebar search crashes ([#​95](dlvhdr/diffnav#95)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44OS42IiwidXBkYXRlZEluVmVyIjoiNDMuODkuNiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
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