Skip to content

config: hot-reload config files when changed on disk#4053

Closed
kdedev wants to merge 1 commit intomicro-editor:masterfrom
kdedev:feature/colorscheme-hot-reload
Closed

config: hot-reload config files when changed on disk#4053
kdedev wants to merge 1 commit intomicro-editor:masterfrom
kdedev:feature/colorscheme-hot-reload

Conversation

@kdedev
Copy link
Copy Markdown

@kdedev kdedev commented Mar 26, 2026

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`:

File Action
`colorschemes/.micro` `InitColorscheme` + `Redraw`
`settings.json` `ReadSettings` + `InitGlobalSettings` + `Redraw`
`bindings.json` `InitBindings`

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.

@kdedev kdedev force-pushed the feature/colorscheme-hot-reload branch 2 times, most recently from 66442f4 to eba574e Compare March 26, 2026 01:14
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.
@kdedev kdedev force-pushed the feature/colorscheme-hot-reload branch from eba574e to 6d36736 Compare March 26, 2026 01:15
@kdedev kdedev changed the title config: reload colorscheme when file changes config: hot-reload config files when changed on disk Mar 26, 2026
@kdedev kdedev closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant