github.com/3JoB/go-json@v0.10.4/color.go (about) 1 package json 2 3 import ( 4 "fmt" 5 6 "github.com/3JoB/go-json/internal/encoder" 7 ) 8 9 type ( 10 ColorFormat = encoder.ColorFormat 11 12 ColorScheme = encoder.ColorScheme 13 ) 14 15 const escape = "\x1b" 16 17 type colorAttr int 18 19 //nolint:deadcode,varcheck 20 const ( 21 fgBlackColor colorAttr = iota + 30 22 fgRedColor 23 fgGreenColor 24 fgYellowColor 25 fgBlueColor 26 fgMagentaColor 27 fgCyanColor 28 fgWhiteColor 29 ) 30 31 //nolint:deadcode,varcheck 32 const ( 33 fgHiBlackColor colorAttr = iota + 90 34 fgHiRedColor 35 fgHiGreenColor 36 fgHiYellowColor 37 fgHiBlueColor 38 fgHiMagentaColor 39 fgHiCyanColor 40 fgHiWhiteColor 41 ) 42 43 func createColorFormat(attr colorAttr) ColorFormat { 44 return ColorFormat{ 45 Header: wrapColor(attr), 46 Footer: resetColor(), 47 } 48 } 49 50 func wrapColor(attr colorAttr) string { 51 return fmt.Sprintf("%s[%dm", escape, attr) 52 } 53 54 func resetColor() string { 55 return wrapColor(colorAttr(0)) 56 } 57 58 var ( 59 DefaultColorScheme = &ColorScheme{ 60 Int: createColorFormat(fgHiMagentaColor), 61 Uint: createColorFormat(fgHiMagentaColor), 62 Float: createColorFormat(fgHiMagentaColor), 63 Bool: createColorFormat(fgHiYellowColor), 64 String: createColorFormat(fgHiGreenColor), 65 Binary: createColorFormat(fgHiRedColor), 66 ObjectKey: createColorFormat(fgHiCyanColor), 67 Null: createColorFormat(fgBlueColor), 68 } 69 )