|
|
@@ -6,7 +6,7 @@ import (
|
|
|
)
|
|
|
|
|
|
type (
|
|
|
- inner func(interface{}, []string) string
|
|
|
+ inner func(interface{}, []string, *Color) string
|
|
|
)
|
|
|
|
|
|
// Color styles
|
|
|
@@ -98,7 +98,12 @@ var (
|
|
|
)
|
|
|
|
|
|
func outer(n string) inner {
|
|
|
- return func(msg interface{}, styles []string) string {
|
|
|
+ return func(msg interface{}, styles []string, c *Color) string {
|
|
|
+ // TODO: May be drop fmt to boost performance
|
|
|
+ if c.disabled {
|
|
|
+ return fmt.Sprintf("%s", msg)
|
|
|
+ }
|
|
|
+
|
|
|
b := new(bytes.Buffer)
|
|
|
b.WriteString("\x1b[")
|
|
|
b.WriteString(n)
|
|
|
@@ -107,13 +112,13 @@ func outer(n string) inner {
|
|
|
b.WriteString(s)
|
|
|
}
|
|
|
b.WriteString("m")
|
|
|
- // TODO: Replace fmt for performance
|
|
|
return fmt.Sprintf("%s%v\x1b[0m", b.String(), msg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type (
|
|
|
Color struct {
|
|
|
+ disabled bool
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -122,104 +127,114 @@ func New() *Color {
|
|
|
return &Color{}
|
|
|
}
|
|
|
|
|
|
+// Disable disables the package.
|
|
|
+func (c *Color) Disable() {
|
|
|
+ c.disabled = true
|
|
|
+}
|
|
|
+
|
|
|
+// Enable enables the package.
|
|
|
+func (c *Color) Enable() {
|
|
|
+ c.disabled = false
|
|
|
+}
|
|
|
+
|
|
|
func (c *Color) Black(msg interface{}, styles ...string) string {
|
|
|
- return black(msg, styles)
|
|
|
+ return black(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Red(msg interface{}, styles ...string) string {
|
|
|
- return red(msg, styles)
|
|
|
+ return red(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Green(msg interface{}, styles ...string) string {
|
|
|
- return green(msg, styles)
|
|
|
+ return green(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Yellow(msg interface{}, styles ...string) string {
|
|
|
- return yellow(msg, styles)
|
|
|
+ return yellow(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Blue(msg interface{}, styles ...string) string {
|
|
|
- return blue(msg, styles)
|
|
|
+ return blue(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Magenta(msg interface{}, styles ...string) string {
|
|
|
- return magenta(msg, styles)
|
|
|
+ return magenta(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Cyan(msg interface{}, styles ...string) string {
|
|
|
- return cyan(msg, styles)
|
|
|
+ return cyan(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) White(msg interface{}, styles ...string) string {
|
|
|
- return white(msg, styles)
|
|
|
+ return white(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Grey(msg interface{}, styles ...string) string {
|
|
|
- return grey(msg, styles)
|
|
|
+ return grey(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) BlackBg(msg interface{}, styles ...string) string {
|
|
|
- return blackBg(msg, styles)
|
|
|
+ return blackBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) RedBg(msg interface{}, styles ...string) string {
|
|
|
- return redBg(msg, styles)
|
|
|
+ return redBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) GreenBg(msg interface{}, styles ...string) string {
|
|
|
- return greenBg(msg, styles)
|
|
|
+ return greenBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) YellowBg(msg interface{}, styles ...string) string {
|
|
|
- return yellowBg(msg, styles)
|
|
|
+ return yellowBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) BlueBg(msg interface{}, styles ...string) string {
|
|
|
- return blueBg(msg, styles)
|
|
|
+ return blueBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) MagentaBg(msg interface{}, styles ...string) string {
|
|
|
- return magentaBg(msg, styles)
|
|
|
+ return magentaBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) CyanBg(msg interface{}, styles ...string) string {
|
|
|
- return cyanBg(msg, styles)
|
|
|
+ return cyanBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) WhiteBg(msg interface{}, styles ...string) string {
|
|
|
- return whiteBg(msg, styles)
|
|
|
+ return whiteBg(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Reset(msg interface{}, styles ...string) string {
|
|
|
- return reset(msg, styles)
|
|
|
+ return reset(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Bold(msg interface{}, styles ...string) string {
|
|
|
- return bolt(msg, styles)
|
|
|
+ return bolt(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Dim(msg interface{}, styles ...string) string {
|
|
|
- return dim(msg, styles)
|
|
|
+ return dim(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Italic(msg interface{}, styles ...string) string {
|
|
|
- return italic(msg, styles)
|
|
|
+ return italic(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Underline(msg interface{}, styles ...string) string {
|
|
|
- return underline(msg, styles)
|
|
|
+ return underline(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Inverse(msg interface{}, styles ...string) string {
|
|
|
- return inverse(msg, styles)
|
|
|
+ return inverse(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Hidden(msg interface{}, styles ...string) string {
|
|
|
- return hidden(msg, styles)
|
|
|
+ return hidden(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func (c *Color) Strikeout(msg interface{}, styles ...string) string {
|
|
|
- return strikeout(msg, styles)
|
|
|
+ return strikeout(msg, styles, c)
|
|
|
}
|
|
|
|
|
|
func Black(msg interface{}, styles ...string) string {
|