github.com/wtfutil/wtf@v0.43.0/utils/colors.go (about) 1 package utils 2 3 import "fmt" 4 5 // ColorizePercent provides a standard way to colorize percentages for which 6 // large numbers are good (green) and small numbers are bad (red). 7 func ColorizePercent(percent float64) string { 8 var color string 9 10 switch { 11 case percent >= 70: 12 color = "green" 13 case percent >= 35: 14 color = "yellow" 15 case percent < 0: 16 color = "grey" 17 default: 18 color = "red" 19 } 20 21 return fmt.Sprintf("[%s]%v[%s]", color, percent, "white") 22 }