diff options
author | Wolfy-J <[email protected]> | 2018-06-03 12:54:43 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-03 12:54:43 +0300 |
commit | 36ea77baa5a41de10bd604cd0e5b5b3cafaaeb64 (patch) | |
tree | 13ca8abd454a6668f490eec2e44b1520bd3953fe /cmd/rr/utils/cprint.go | |
parent | b02611b7266589d888e054a1d2e4432ae370617d (diff) |
service bus, http service, rpc bus, cli commands, new configs
Diffstat (limited to 'cmd/rr/utils/cprint.go')
-rw-r--r-- | cmd/rr/utils/cprint.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd/rr/utils/cprint.go b/cmd/rr/utils/cprint.go new file mode 100644 index 00000000..f6f828f8 --- /dev/null +++ b/cmd/rr/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 +} |