github.com/markfisherdeloitte/godog@v0.7.9/colors/colors.go (about) 1 package colors 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 const ansiEscape = "\x1b" 9 10 // a color code type 11 type color int 12 13 // some ansi colors 14 const ( 15 black color = iota + 30 16 red 17 green 18 yellow 19 blue // unused 20 magenta // unused 21 cyan 22 white 23 ) 24 25 func colorize(s interface{}, c color) string { 26 return fmt.Sprintf("%s[%dm%v%s[0m", ansiEscape, c, s, ansiEscape) 27 } 28 29 type ColorFunc func(interface{}) string 30 31 func Bold(fn ColorFunc) ColorFunc { 32 return ColorFunc(func(input interface{}) string { 33 return strings.Replace(fn(input), ansiEscape+"[", ansiEscape+"[1;", 1) 34 }) 35 } 36 37 func Green(s interface{}) string { 38 return colorize(s, green) 39 } 40 41 func Red(s interface{}) string { 42 return colorize(s, red) 43 } 44 45 func Cyan(s interface{}) string { 46 return colorize(s, cyan) 47 } 48 49 func Black(s interface{}) string { 50 return colorize(s, black) 51 } 52 53 func Yellow(s interface{}) string { 54 return colorize(s, yellow) 55 } 56 57 func White(s interface{}) string { 58 return colorize(s, white) 59 }