summaryrefslogtreecommitdiff
path: root/utils/cprint.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 20:31:05 +0300
committerWolfy-J <[email protected]>2018-06-10 20:31:05 +0300
commited3a0f2bb25077c7a32a54ddb3754f04ffbdccf3 (patch)
tree9a579e6ce81e7af5e3844fbcf590f9c8db26d90a /utils/cprint.go
parentade5cc504e2b082d0838cc93c3a185246fdc7834 (diff)
debug mode have been added
Diffstat (limited to 'utils/cprint.go')
-rw-r--r--utils/cprint.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/utils/cprint.go b/utils/cprint.go
new file mode 100644
index 00000000..f6f828f8
--- /dev/null
+++ b/utils/cprint.go
@@ -0,0 +1,32 @@
+package utils
+
+import (
+ "fmt"
+ "gopkg.in/AlecAivazis/survey.v1/core"
+ "regexp"
+ "strings"
+)
+
+// 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 {
+ 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, "<>/"))
+ })
+
+ out, err := core.RunTemplate(fmt.Sprintf(format, args...), nil)
+ if err != nil {
+ panic(err)
+ }
+
+ return out
+}