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):
Suggestion: Would you open to some small inline comments here to help indicate that `dark` is referring to the theme, not a color as the other color vars do? 

```suggestion
	darkTableHeader  = ansi.ColorFunc("white+du") // for dark theme
	lightTableHeader = ansi.ColorFunc("black+hu") // for light theme
	noneTableHeader  = ansi.ColorFunc("default+u")
```

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
}