config: hot-reload config files when changed on disk#4054
Closed
KonTy wants to merge 1 commit intomicro-editor:masterfrom
Closed
config: hot-reload config files when changed on disk#4054KonTy wants to merge 1 commit intomicro-editor:masterfrom
KonTy wants to merge 1 commit intomicro-editor:masterfrom
Conversation
Add StartConfigWatcher in internal/config/watch.go. It takes a slice of WatchedFile values, each with a Path func and an OnChange callback, and polls them once per second. When a file is modified or the resolved path changes the callback fires. Callbacks run on a background goroutine — callers dispatch to the main thread via timerChan. Wire up three watchers in cmd/micro/micro.go: - colorschemes/<name>.micro → InitColorscheme + Redraw - settings.json → ReadSettings + InitGlobalSettings + Redraw - bindings.json → InitBindings This lets any external tool (theme managers, dotfile syncing, etc.) update micro's config files while the editor is open and have the changes applied immediately without a restart. No new dependencies.
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.
Add `StartConfigWatcher` in `internal/config/watch.go`. It accepts a slice of `WatchedFile` values — each with a `Path` func and an `OnChange` callback — and polls them once per second. When a file is modified or the resolved path changes, the callback fires on a background goroutine. Callers dispatch to the main thread via `timerChan`.
Wire up three watchers in `cmd/micro/micro.go`:
Why: Any external tool (theme managers, dotfile syncing, live config editors) can now update micro's config files while the editor is running and have the changes applied immediately — no restart required. The `Path` func is re-evaluated each tick, so switching colorschemes mid-session is also handled correctly.
Threading: all callbacks run on a background goroutine and post to `timerChan`, keeping every UI mutation on the main thread.
No new dependencies.