Bläddra i källkod

Added enable/disable API to global object

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 10 år sedan
förälder
incheckning
3c61341995
1 ändrade filer med 11 tillägg och 3 borttagningar
  1. 11 3
      color/color.go

+ 11 - 3
color/color.go

@@ -101,7 +101,7 @@ func outer(n string) inner {
 	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)
+			return fmt.Sprintf("%v", msg)
 		}
 
 		b := new(bytes.Buffer)
@@ -127,12 +127,12 @@ func New() *Color {
 	return &Color{}
 }
 
-// Disable disables the package.
+// Disable disables the colors and styles.
 func (c *Color) Disable() {
 	c.disabled = true
 }
 
-// Enable enables the package.
+// Enable enables the colors and styles.
 func (c *Color) Enable() {
 	c.disabled = false
 }
@@ -237,6 +237,14 @@ func (c *Color) Strikeout(msg interface{}, styles ...string) string {
 	return strikeout(msg, styles, c)
 }
 
+func Disable() {
+	global.disabled = true
+}
+
+func Enable() {
+	global.disabled = false
+}
+
 func Black(msg interface{}, styles ...string) string {
 	return global.Black(msg, styles...)
 }