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 fromos.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 andGLAB_COLOR) decides whether glab colors output.neveralways wins, including in GitLab CI job logs.NO_COLORapplies when the value isauto.- Color profile:
ColorEnabled()and the color palette read one resolved profile instead of re-detecting. glab's ownTERM,COLORTERM, andNO_COLORdetection is kept;colorprofileis used as the value type only.colorprofile.Envreports ANSI forTERM=xterm-24bitand stays colored forNO_COLOR=yes, which differs from glab's current behavior. glamour_stylekeeps the light/dark axis.autonow reaches real background detection, and a one-time migration turns a seededdarkintoauto. If the config can't be written (a read-only or Nix-managed config directory), glab logs it underGLAB_DEBUGand keeps the in-memory value instead of failing the command.- Theme:
GitLabColorsgains aWarningcolor, which the yellow palette entry now uses, so warnings render amber instead of the terminal's ANSI yellow when truecolor is available.HuhThemetakes its colors fromNewGitLabColorsinstead 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.
Related
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).