diff options
author | Wolfy-J <[email protected]> | 2018-09-26 22:30:53 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-26 22:30:53 +0300 |
commit | a206fc3270ea6e469b1704f15f2f15a9f6a14bbd (patch) | |
tree | 68bc61c49f84db861976659abed3784bb7e304a9 /cmd/util/cprint.go | |
parent | d24c43aaeff897394eca140478c73dd146f8710a (diff) |
improved debug handlers
Diffstat (limited to 'cmd/util/cprint.go')
-rw-r--r-- | cmd/util/cprint.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/util/cprint.go b/cmd/util/cprint.go new file mode 100644 index 00000000..0985de62 --- /dev/null +++ b/cmd/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...) +} |