github.com/mgutz/ansi is not maintained
Problem to solve
github.com/mgutz/ansi is not maintained.
Proposal
github.com/mgutz/ansi could be replaced by github.com/muesli/termenv that is already used in the project.
Implementation plan
Note: This plan was drafted during an AI-assisted triage of the backlog and has not been validated by a maintainer. Treat it as a starting point: file paths, line numbers, and the approach may need adjusting.
The dependency has one call site left, so the swap is small. The catch is that the previous attempt (!3141 (closed)) rebuilt the whole palette on a termenv.Output derived from s.StdOut, and termenv re-runs its own TTY probe on that writer. When a command starts the pager, s.StdOut becomes an *io.PipeWriter (internal/iostreams/iostreams.go:263), termenv sees a non-*os.File, resolves the profile to termenv.Ascii, and every style call becomes a no-op. That is why a maintainer saw no color at all on a fully truecolor-capable terminal. glab already decides for itself whether color is allowed (s.ColorEnabled() && s.IsaTTY), so the fix must not hand that decision back to termenv's writer probe.
- In
internal/iostreams/color.go, replace the singleansi.ColorFunc(ansiName)call at the end ofmakeColorFunc(line 106) with a local lookup that emits the escape sequences directly, in the same style as the truecolor and 256-color gray branches that already sit above it in the same function. Add an unexportedmap[string]stringfrom the eight names used incolorPaletteto their SGR parameters:magentato0;35,cyanto0;36,redto0;31,yellowto0;33,blueto0;34,greento0;32,black+hto0;90,default+bto0;1;39. Returnfunc(t string) string { return "\x1b[" + params + "m" + t + "\x1b[0m" }, and return the identity function for an unknown name. - Keep
makeColorFunc's signature, theisColorfulOutputgate, andisTrueColorSupported/is256ColorSupportedas they are. Do not move profile detection ontos.StdOut. If a reviewer prefers going throughtermenvinstead of writing the sequences by hand, build the output once with an explicit profile (termenv.WithProfile(...)ortermenv.WithTTY(true)) driven byglab's ownisTrueColorSupported/is256ColorSupported, never by lettingtermenv.NewOutputprobe the writer. - Remove the
github.com/mgutz/ansiimport frominternal/iostreams/color.go:12, rungo mod tidy, and confirmgrep -rn mgutz --include='*.go' .returns nothing outsidevendor/. - Verify against the existing assertions in
internal/iostreams/color_test.go:Test_makeColorFunc(line 104) already pins the exact bytes forblack+handgreenon the basic-ANSI path, so it must pass unchanged. Add cases to that same table for the remaining names (magenta,cyan,red,yellow,blue,default+b) withterm: "xterm-16color"so all eight are covered. - Add one regression test in
internal/iostreams/color_test.gothat builds a palette for a paged stream: setIsaTTYtrue, pointStdOutat anio.Pipewriter, and assertColor().Green("text")still contains an escape sequence. This is the case that sank !3141 (closed) and nothing in the suite catches it today. - No help text or flags change, so
make gen-docsis not needed. Rungo test ./internal/iostreams/...andmake lint.