diff options
-rw-r--r-- | cmd/rr/debug/listener.go | 2 | ||||
-rw-r--r-- | cmd/rr/utils/cprint.go | 24 |
2 files changed, 11 insertions, 15 deletions
diff --git a/cmd/rr/debug/listener.go b/cmd/rr/debug/listener.go index 5239538b..393e2b2e 100644 --- a/cmd/rr/debug/listener.go +++ b/cmd/rr/debug/listener.go @@ -89,5 +89,5 @@ func statusColor(status int) string { return utils.Sprintf("<yellow>%v</reset>", status) } - return utils.Sprintf("<red+hb>%v</reset>", status) + return utils.Sprintf("<red>%v</reset>", status) } 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...) } |