Repository: cli/cli
File: pkg/iostreams/color.go (Go)

Code before:

const (
	NoTheme        = "none"
	DarkTheme      = "dark"
	LightTheme     = "light"
	highlightStyle = "black:yellow"
)

// Special cases like darkTableHeader / lightTableHeader are necessary when using color and modifiers
// (bold, underline, dim) because ansi.ColorFunc requires a foreground color and resets formats.
var (
	magenta          = ansi.ColorFunc("magenta")
	cyan             = ansi.ColorFunc("cyan")
	red              = ansi.ColorFunc("red")
	yellow           = ansi.ColorFunc("yellow")
	blue             = ansi.ColorFunc("blue")
	green            = ansi.ColorFunc("green")
	gray             = ansi.ColorFunc("black+h")
	bold             = ansi.ColorFunc("default+b")
	cyanBold         = ansi.ColorFunc("cyan+b")
	greenBold        = ansi.ColorFunc("green+b")
	highlightStart   = ansi.ColorCode(highlightStyle)
	highlight        = ansi.ColorFunc(highlightStyle)
	darkTableHeader  = ansi.ColorFunc("white+du")
	lightTableHeader = ansi.ColorFunc("black+hu")
	noneTableHeader  = ansi.ColorFunc("default+u")

	gray256 = func(t string) string {
		return fmt.Sprintf("\x1b[%d;5;%dm%s\x1b[m", 38, 242, t)
	}
)

// NewColorScheme initializes color logic based on provided terminal capabilities.
// Logic dealing with terminal theme detected, such as whether color is enabled, 8-bit color supported, true color supported,
// and terminal theme detected.
func NewColorScheme(enabled, is256enabled, trueColor bool, theme string) *ColorScheme {
	return &ColorScheme{
		enabled:      enabled,
		is256enabled: is256enabled,
		hasTrueColor: trueColor,
		theme:        theme,
	}
}

type ColorScheme struct {
	enabled      bool
	is256enabled bool
	hasTrueColor bool
	theme        string
}


Review comment (suggestion):
praise: I really like the decision to be intentional with what these colors are used for - it's very clear these are the options for table headers and shouldn't be used for anything else. I think this is a step in a great direction that we've discussed previously 😁 



Code after:

const (
	NoTheme        = "none"
	DarkTheme      = "dark"
	LightTheme     = "light"
	highlightStyle = "black:yellow"
)

// Special cases like darkThemeTableHeader / lightThemeTableHeader are necessary when using color and modifiers
// (bold, underline, dim) because ansi.ColorFunc requires a foreground color and resets formats.
var (
	magenta               = ansi.ColorFunc("magenta")
	cyan                  = ansi.ColorFunc("cyan")
	red                   = ansi.ColorFunc("red")
	yellow                = ansi.ColorFunc("yellow")
	blue                  = ansi.ColorFunc("blue")
	green                 = ansi.ColorFunc("green")
	gray                  = ansi.ColorFunc("black+h")
	bold                  = ansi.ColorFunc("default+b")
	cyanBold              = ansi.ColorFunc("cyan+b")
	greenBold             = ansi.ColorFunc("green+b")
	highlightStart        = ansi.ColorCode(highlightStyle)
	highlight             = ansi.ColorFunc(highlightStyle)
	darkThemeTableHeader  = ansi.ColorFunc("white+du")
	lightThemeTableHeader = ansi.ColorFunc("black+hu")
	noThemeTableHeader    = ansi.ColorFunc("default+u")

	gray256 = func(t string) string {
		return fmt.Sprintf("\x1b[%d;5;%dm%s\x1b[m", 38, 242, t)
	}
)

// NewColorScheme initializes color logic based on provided terminal capabilities.
// Logic dealing with terminal theme detected, such as whether color is enabled, 8-bit color supported, true color supported,
// and terminal theme detected.
func NewColorScheme(enabled, is256enabled, trueColor bool, theme string) *ColorScheme {
	return &ColorScheme{
		enabled:      enabled,
		is256enabled: is256enabled,
		hasTrueColor: trueColor,
		theme:        theme,
	}
}

type ColorScheme struct {
	enabled      bool
	is256enabled bool
	hasTrueColor bool
	theme        string
}