github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/zlog/internal/terminal/color.go (about) 1 package terminal 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 const ( 9 Black Color = iota + 30 10 Red 11 Green 12 Yellow 13 Blue 14 Magenta 15 Cyan 16 Gray 17 ) 18 19 type Color uint8 20 21 // Format adds the coloring to the given string. 22 func (c Color) Format(s string) string { 23 return fmt.Sprintf("\x1b[%dm%s\x1b[0m", uint8(c), s) 24 } 25 26 func CheckIsTerminal(w io.Writer) bool { 27 return checkIfTerminal(w) 28 }