diff options
author | Wolfy-J <[email protected]> | 2018-07-08 21:12:37 -0700 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-08 21:12:37 -0700 |
commit | c78c38d07ecc7a9fb9ac089c2aee18d8e51db601 (patch) | |
tree | 97421672d0972fe9dcb23c55302f5960dccdce80 /cmd/rr/utils/cprint.go | |
parent | ca92fcaf9b2290b3bf2124eed6b0db6860010712 (diff) |
mod updated
Diffstat (limited to 'cmd/rr/utils/cprint.go')
-rw-r--r-- | cmd/rr/utils/cprint.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/rr/utils/cprint.go b/cmd/rr/utils/cprint.go new file mode 100644 index 00000000..020975ec --- /dev/null +++ b/cmd/rr/utils/cprint.go @@ -0,0 +1,28 @@ +package utils + +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...) +} |