blob: 020975ec38dad266033c091d96ecd0af981fa07b (
plain)
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
|
package utils
import (
"fmt"
"github.com/mgutz/ansi"
"regexp"
"strings"
)
var reg *regexp.Regexp
func init() {
reg, _ = regexp.Compile(`<([^>]+)>`)
}
// Printf works identically to fmt.Print but adds `<white+hb>color formatting support for CLI</reset>`.
func Printf(format string, args ...interface{}) {
fmt.Print(Sprintf(format, args...))
}
// Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`.
func Sprintf(format string, args ...interface{}) string {
format = reg.ReplaceAllStringFunc(format, func(s string) string {
return ansi.ColorCode(strings.Trim(s, "<>/"))
})
return fmt.Sprintf(format, args...)
}
|