/
color.go
118 lines (96 loc) · 4.43 KB
/
color.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package jpp
import (
"fmt"
au "github.com/logrusorgru/aurora"
)
// ColorScheme is used for specifying the output color or SGR
// using https://github.com/fatih/color
type ColorScheme struct {
Null ColoredFormat
Bool ColoredFormat
Number ColoredFormat
String ColoredFormat
FieldName ColoredFormat
}
var (
// DefaultScheme is plain color scheme that doesn't specify
// any colors or SGRs.
// Note that the default color scheme for CLI tool is not this.
DefaultScheme = &ColorScheme{
Null: NoColor,
Bool: NoColor,
Number: NoColor,
String: NoColor,
FieldName: NoColor,
}
)
// ColoredFormat formats according to a format specifier and returns the resulting string.
type ColoredFormat = func(string, ...interface{}) string
// NoColor formats according to a format specifier and returns the resulting string.
func NoColor(format string, args ...interface{}) string {
return fmt.Sprintf(format, args...)
}
// Black formats according to a format specifier and returns the resulting string colored by black.
func Black(format string, args ...interface{}) string {
return au.Sprintf(au.Black(format), args...)
}
// Red formats according to a format specifier and returns the resulting string colored by red.
func Red(format string, args ...interface{}) string {
return au.Sprintf(au.Red(format), args...)
}
// Green formats according to a format specifier and returns the resulting string colored by green.
func Green(format string, args ...interface{}) string {
return au.Sprintf(au.Green(format), args...)
}
// Brown formats according to a format specifier and returns the resulting string colored by brown.
func Brown(format string, args ...interface{}) string {
return au.Sprintf(au.Brown(format), args...)
}
// Blue formats according to a format specifier and returns the resulting string colored by blue.
func Blue(format string, args ...interface{}) string {
return au.Sprintf(au.Blue(format), args...)
}
// Magenta formats according to a format specifier and returns the resulting string colored by magenta.
func Magenta(format string, args ...interface{}) string {
return au.Sprintf(au.Magenta(format), args...)
}
// Cyan formats according to a format specifier and returns the resulting string colored by cyan.
func Cyan(format string, args ...interface{}) string {
return au.Sprintf(au.Cyan(format), args...)
}
// Gray formats according to a format specifier and returns the resulting string colored by gray.
func Gray(format string, args ...interface{}) string {
return au.Sprintf(au.Gray(uint8(12), format), args...)
}
// BoldBlack formats according to a format specifier and returns the resulting bold string colored by black.
func BoldBlack(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.BlackFg|au.BoldFm), args...)
}
// BoldRed formats according to a format specifier and returns the resulting bold string colored by red.
func BoldRed(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.RedFg|au.BoldFm), args...)
}
// BoldGreen formats according to a format specifier and returns the resulting bold string colored by green.
func BoldGreen(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.GreenFg|au.BoldFm), args...)
}
// BoldBrown formats according to a format specifier and returns the resulting bold string colored by brown.
func BoldBrown(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.BrownFg|au.BoldFm), args...)
}
// BoldBlue formats according to a format specifier and returns the resulting bold string colored by blue.
func BoldBlue(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.BlueFg|au.BoldFm), args...)
}
// BoldMagenta formats according to a format specifier and returns the resulting bold string colored by magenta.
func BoldMagenta(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.MagentaFg|au.BoldFm), args...)
}
// BoldCyan formats according to a format specifier and returns the resulting bold string colored by cyan.
func BoldCyan(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(format, au.CyanFg|au.BoldFm), args...)
}
// BoldGray formats according to a format specifier and returns the resulting bold string colored by gray.
func BoldGray(format string, args ...interface{}) string {
return au.Sprintf(au.Colorize(au.Gray(uint8(12), format), au.BoldFm), args...)
}