1 | package log |
||
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | "github.com/mgutz/ansi" |
||
6 | "regexp" |
||
7 | "strings" |
||
8 | ) |
||
9 | |||
10 | var reg *regexp.Regexp |
||
11 | |||
12 | func init() { |
||
13 | reg, _ = regexp.Compile(`<([^>]+)>`) |
||
14 | } |
||
15 | |||
16 | // Printf works identically to fmt.Print but adds `<white+hb>color formatting support for CLI</reset>`. |
||
17 | func printf(format string, args ...interface{}) { |
||
18 | fmt.Print(sprintf(format, args...)) |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | } |
||
20 | |||
21 | // Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`. |
||
22 | func sprintf(format string, args ...interface{}) string { |
||
23 | format = reg.ReplaceAllStringFunc(format, func(s string) string { |
||
24 | return ansi.ColorCode(strings.Trim(s, "<>/")) |
||
25 | }) |
||
26 | |||
27 | return fmt.Sprintf(format, args...) |
||
0 ignored issues
–
show
|
|||
28 | } |
||
29 |