fix(tui): rewire theme watcher lost in tab-view rewrite#3505
Merged
Conversation
Custom theme hot reload stopped working when the tab-view rewrite dropped the ThemeWatcher wiring: nothing constructed the watcher or emitted ThemeFileChangedMsg anymore. Create the watcher in SetProgram (its callback injects the message via program.Send), point it at the applied theme, re-target it in applyThemeChanged (single funnel for picker selection, preview, cancel and hot reload), and stop it in cleanupManagedResources so both exit paths release the fsnotify handle. Add an e2e regression test driving the full loop through tuitest plus unit tests for the watcher lifecycle wiring. Fixes #3501
dgageot
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3501
Editing
~/.cagent/themes/*.yamlwhile the TUI runs did nothing until restart, despite the docs promising auto-reload on save.Root cause
The tab-view rewrite (0069cad) rewrote
pkg/tui/tui.goand kept only theThemeFileChangedMsghandler: nothing constructedstyles.ThemeWatcheror emitted the message anymore (NewThemeWatcherhad no non-test caller). Confirmed by reproduction: an e2e test editing the active theme file times out waiting for the hot-reload on main, and passes with this change.Fix
SetProgramwiring; atomic saves already handled by the watcher (directory watching, rename/basename matching)TestTheme_HotReloadapplyThemeChanged, the single funnel for picker selection, preview, cancel and hot reloadStop()incleanupManagedResources, reached from both normal exit and external cancellatione2e/tui/theme_test.go(red/green verified against main) pluspkg/tui/theme_watcher_wiring_test.goNotes
themeWatchersits behind a smallthemeFileWatcherinterface so unit tests can recordWatch/Stopcalls.SetProgram) is a no-op; built-in-only refs already no-op inside the watcher.p.Sendafter program termination is a documented no-op in bubbletea v2, so a late debounce callback cannot block or crash.ThemeChangedMsgis sequenced after the change notification), so a single write could race fsnotify attachment. The 700ms poll interval exceeds the 500ms debounce so rewrites cannot starve the timer.docs/features/tui/index.mdneeds no change: its hot-reload claim is accurate again.Validation
go build ./...go test -race ./e2e/tui/ ./pkg/tui/ ./pkg/tui/styles/ ./cmd/root/golangci-lint run pkg/tui/... e2e/tui/...reports 0 issues