package terminfo
import (
)
type ColorLevel uint
const (
ColorLevelNone ColorLevel = iota
ColorLevelBasic
ColorLevelHundreds
ColorLevelMillions
)
func ( ColorLevel) () string {
switch {
case ColorLevelBasic:
return "basic"
case ColorLevelHundreds:
return "hundreds"
case ColorLevelMillions:
return "millions"
}
return "none"
}
func ( ColorLevel) () string {
switch {
case ColorLevelBasic:
return "terminal"
case ColorLevelHundreds:
return "terminal256"
case ColorLevelMillions:
return "terminal16m"
}
return "noop"
}
func () (ColorLevel, error) {
, , := os.Getenv("COLORTERM"), os.Getenv("TERM_PROGRAM"), os.Getenv("FORCE_COLOR")
switch {
case strings.Contains(, "truecolor") || strings.Contains(, "24bit") || == "Hyper":
return ColorLevelMillions, nil
case != "" || != "":
return ColorLevelBasic, nil
case == "Apple_Terminal":
return ColorLevelHundreds, nil
case == "iTerm.app":
:= os.Getenv("TERM_PROGRAM_VERSION")
if == "" {
return ColorLevelHundreds, nil
}
, := strconv.Atoi(strings.Split(, ".")[0])
if != nil {
return ColorLevelNone, ErrInvalidTermProgramVersion
}
if == 3 {
return ColorLevelMillions, nil
}
return ColorLevelHundreds, nil
}
if := os.Getenv("TERM"); != "" {
, := Load()
if != nil {
return ColorLevelNone,
}
, := .Nums[MaxColors]
switch {
case ! || <= 16:
return ColorLevelNone, nil
case && >= 256:
return ColorLevelHundreds, nil
}
}
return ColorLevelBasic, nil
}