1package style 2 3import ( 4 "text/template" 5 6 "github.com/gookit/color" 7) 8 9var ( 10 FgWhite = FromBasicFg(color.FgWhite) 11 FgLightWhite = FromBasicFg(color.FgLightWhite) 12 FgBlack = FromBasicFg(color.FgBlack) 13 FgBlackLighter = FromBasicFg(color.FgBlack.Light()) 14 FgCyan = FromBasicFg(color.FgCyan) 15 FgRed = FromBasicFg(color.FgRed) 16 FgGreen = FromBasicFg(color.FgGreen) 17 FgBlue = FromBasicFg(color.FgBlue) 18 FgYellow = FromBasicFg(color.FgYellow) 19 FgMagenta = FromBasicFg(color.FgMagenta) 20 FgDefault = FromBasicFg(color.FgDefault) 21 22 BgWhite = FromBasicBg(color.BgWhite) 23 BgBlack = FromBasicBg(color.BgBlack) 24 BgRed = FromBasicBg(color.BgRed) 25 BgGreen = FromBasicBg(color.BgGreen) 26 BgYellow = FromBasicBg(color.BgYellow) 27 BgBlue = FromBasicBg(color.BgBlue) 28 BgMagenta = FromBasicBg(color.BgMagenta) 29 BgCyan = FromBasicBg(color.BgCyan) 30 31 // will not print any colour escape codes, including the reset escape code 32 Nothing = New() 33 34 AttrUnderline = New().SetUnderline() 35 AttrBold = New().SetBold() 36 37 ColorMap = map[string]struct { 38 Foreground TextStyle 39 Background TextStyle 40 }{ 41 "default": {FgWhite, BgBlack}, 42 "black": {FgBlack, BgBlack}, 43 "red": {FgRed, BgRed}, 44 "green": {FgGreen, BgGreen}, 45 "yellow": {FgYellow, BgYellow}, 46 "blue": {FgBlue, BgBlue}, 47 "magenta": {FgMagenta, BgMagenta}, 48 "cyan": {FgCyan, BgCyan}, 49 "white": {FgWhite, BgWhite}, 50 } 51) 52 53func FromBasicFg(fg color.Color) TextStyle { 54 return New().SetFg(NewBasicColor(fg)) 55} 56 57func FromBasicBg(bg color.Color) TextStyle { 58 return New().SetBg(NewBasicColor(bg)) 59} 60 61func TemplateFuncMapAddColors(m template.FuncMap) template.FuncMap { 62 for k, v := range ColorMap { 63 m[k] = v.Foreground.Sprint 64 } 65 m["underline"] = color.OpUnderscore.Sprint 66 m["bold"] = color.OpBold.Sprint 67 return m 68} 69