summaryrefslogtreecommitdiff
path: root/cmd/rr/util/cprint.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-26 22:18:48 +0300
committerWolfy-J <[email protected]>2018-09-26 22:18:48 +0300
commitd24c43aaeff897394eca140478c73dd146f8710a (patch)
treeae7e9515aa11a7358349f7c822bf020a7c5f33ed /cmd/rr/util/cprint.go
parentabe62c0675f839586312cff1c83d6a4cb31dd9d5 (diff)
worker information extraction is now moved to external package
Diffstat (limited to 'cmd/rr/util/cprint.go')
-rw-r--r--cmd/rr/util/cprint.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/rr/util/cprint.go b/cmd/rr/util/cprint.go
new file mode 100644
index 00000000..0985de62
--- /dev/null
+++ b/cmd/rr/util/cprint.go
@@ -0,0 +1,28 @@
+package util
+
+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...)
+}