fix(defaults): detect 'background'/'termguicolors' on UI attach #40175

Problem:  Terminal background and truecolor detection runs only at startup,
          gated on a UI being attached. A headless server has no UI then, so
          `'background'` and `'termguicolors'` are never detected and remote
          UIs ignore the terminal's theme.
Solution: Also (re)detect on UIEnter. The most recently attached terminal
          wins; an explicit user value is preserved.
This commit is contained in:
Barrett Ruth
2026-06-20 19:09:34 -05:00
committed by GitHub
parent 6284c1163a
commit 74f163c67d
6 changed files with 429 additions and 242 deletions

View File

@@ -368,7 +368,11 @@ local options = {
desc = [=[
When set to "dark" or "light", adjusts the default color groups for
that background type. The |TUI| or other UI sets this on startup
if it can detect the background color.
if it can detect the background color, and re-detects it whenever a UI
attaches later, unless 'background' was set explicitly. When multiple
terminal UIs are attached they share one value, taken from whichever
terminal reports its background last (which may not be the most
recently attached one, since it depends on response speed).
This option does NOT change the background color, it tells Nvim what
the "inherited" (terminal/GUI) background looks like.