fix(iostreams): make background/color detection reachable, add --color mode

What

Makes color a single color setting (auto|never|always), resolved once into a colorprofile.Profile on IOStreams, and fixes light/dark background detection so it reaches existing users. There is no --color flag. Split out of the closed !3790 (closed).

Why

The first revision put one --color enum (auto|never|always|16|256|truecolor) in front of three separate settings: whether to color, how many colors, and light or dark. Review (@viktomas, @phikai) settled on a smaller design, and the flag turned out to be the wrong surface:

  • fang, which renders help and errors, reads its color level only from os.Environ(), so a cobra flag never reached it.
  • A persistent root flag added a line to the "Options inherited from parent commands" block of about 300 generated doc pages.

A forced 16-color depth was dropped for a similar reason. It could apply to io.Color(), but glamour has no 16-color stylesheet and fang can't take a profile, so it would have worked for only part of the output.

What changed

  • color (config key and GLAB_COLOR) decides whether glab colors output. never always wins, including in GitLab CI job logs. NO_COLOR applies when the value is auto.
  • Color profile: ColorEnabled() and the color palette read one resolved profile instead of re-detecting. glab's own TERM, COLORTERM, and NO_COLOR detection is kept; colorprofile is used as the value type only. colorprofile.Env reports ANSI for TERM=xterm-24bit and stays colored for NO_COLOR=yes, which differs from glab's current behavior.
  • glamour_style keeps the light/dark axis. auto now reaches real background detection, and a one-time migration turns a seeded dark into auto. If the config can't be written (a read-only or Nix-managed config directory), glab logs it under GLAB_DEBUG and keeps the in-memory value instead of failing the command.
  • Theme: GitLabColors gains a Warning color, which the yellow palette entry now uses, so warnings render amber instead of the terminal's ANSI yellow when truecolor is available. HuhTheme takes its colors from NewGitLabColors instead of a second copy.

The --color flag is gone, along with its PersistentPreRunE and the global cobra.EnableTraverseRunHooks, which existed only to make the flag reach repo-override commands.

Testing

Tests cover the profile resolution in internal/iostreams, the color key in cmd/glab and internal/config, the migration (including a read-only config directory), and color: never in CI logs. go test passes for every affected package. The only failures in the full run are five Cursor tests in internal/commands/govern/audit/sync, which fail the same way on main. go vet, gofmt, and make gen-docs are clean.

Closes the theming half of #8493 (light-background readability). #8239 (forcing 16 colors) is not implemented here, for the reason in "Why"; the plan is to close it with that explanation. Split from the closed !3790 (closed).

Edited by James Hebden

Merge request reports

Loading
Loading