Skip to content

Reload all runtime files on SIGUSR1 - #4239

Open
SotoAugusto wants to merge 2 commits into
micro-editor:masterfrom
SotoAugusto:feature/sigusr1-reload
Open

SotoAugusto wants to merge 2 commits into
micro-editor:masterfrom
SotoAugusto:feature/sigusr1-reload

Conversation

@SotoAugusto

Copy link
Copy Markdown

Right now, when a desktop theme switcher (matugen, Omarchy, etc.) rewrites a colorscheme, micro instances that are already open keep the old colors until you run reload in each one. This came up in #3736 (now #4197), where SIGUSR1 was suggested because kitty uses it. Helix does the same thing for :config-reload.

With this PR, micro on Unix-like systems runs the same reload as the reload command when it gets SIGUSR1:

pkill -USR1 -x micro

Changes:

  • action.Reload() exposes the reload that ReloadCmd already does.
  • cmd/micro: SIGUSR1 goes into its own channel and is handled in the DoEvent() select loop, so the reload runs on the main loop and the next iteration redraws. The signal setup lives in build-tagged files (signal_posix.go / signal_other.go), following the same split as actions_posix.go / actions_other.go. Windows and plan9 get a no-op.
  • help/commands.md documents it next to reload.

I used the full reload on purpose instead of config.Reload(). config.Reload() re-runs InitCommands() / InitBindings() without re-running plugins, so it loses commands registered by plugins. For example, after config.Reload(), > comment fails with Unknown command. That matches the "other plugins don't really work" report in #4197. That's a separate bug, and I can open an issue for it if you want.

Testing (Linux, in a pty with COLORTERM=truecolor):

  • I changed the active colorscheme's color-link default from #ff0000 to #00ff00 and sent SIGUSR1. The running instance redrew with 38;2;0;255;0 and kept running. On master nothing changes.
  • The comment command still works after the signal.
  • go test ./cmd/micro ./internal/... passes. It cross-builds for windows, darwin, freebsd and openbsd.

About the signal choice: #1888 asks for SIGUSR1 to trigger a save. I went with SIGUSR1 to match kitty and Helix. If you'd rather keep it for #1888, switching this to SIGUSR2 is a one-line change.

Expose the same reload that the `reload` command performs, so that it
can be triggered from outside of a `BufPane`.
This allows external tools, e.g. desktop theme switchers, to apply a
changed colorscheme or configuration to all running micro instances
(`pkill -USR1 -x micro`), like kitty and helix already do.

Unlike `config.Reload()` the full `reload` is used, since the former
reinitializes the commands and bindings without rerunning the plugins,
which loses e.g. the commands registered by plugins.
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