diff options
author | Wolfy-J <[email protected]> | 2018-06-11 21:27:41 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 21:27:41 +0300 |
commit | b9f800762fd642477fe45d4ef3c68f3a33ad7b6a (patch) | |
tree | 94f30690a2508810fdb7138935b064bfa606ddc3 /cmd/rr/utils/cprint.go | |
parent | 513e29f7b0b22c2eb03a374547894901950ab622 (diff) |
no library dependency
Diffstat (limited to 'cmd/rr/utils/cprint.go')
-rw-r--r-- | cmd/rr/utils/cprint.go | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/cmd/rr/utils/cprint.go b/cmd/rr/utils/cprint.go index f6f828f8..eb1aa0ad 100644 --- a/cmd/rr/utils/cprint.go +++ b/cmd/rr/utils/cprint.go @@ -2,11 +2,17 @@ package utils import ( "fmt" - "gopkg.in/AlecAivazis/survey.v1/core" "regexp" "strings" + "github.com/mgutz/ansi" ) +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...)) @@ -14,19 +20,9 @@ func Printf(format string, args ...interface{}) { // Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`. func Sprintf(format string, args ...interface{}) string { - r, err := regexp.Compile(`<([^>]+)>`) - if err != nil { - panic(err) - } - - format = r.ReplaceAllStringFunc(format, func(s string) string { - return fmt.Sprintf(`{{color "%s"}}`, strings.Trim(s, "<>/")) + format = reg.ReplaceAllStringFunc(format, func(s string) string { + return ansi.ColorCode(strings.Trim(s, "<>/")) }) - out, err := core.RunTemplate(fmt.Sprintf(format, args...), nil) - if err != nil { - panic(err) - } - - return out + return fmt.Sprintf(format, args...) } |