mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-15 23:38:24 +00:00
Create printer pkg, fix color force enable/disable
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
42
internal/printer/printer.go
Normal file
42
internal/printer/printer.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package printer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var (
|
||||
errorColor = color.New(color.FgRed, color.Bold)
|
||||
warningColor = color.New(color.FgYellow, color.Bold)
|
||||
successColor = color.New(color.FgGreen)
|
||||
)
|
||||
|
||||
func init() {
|
||||
colors := UseColors()
|
||||
if colors == nil {
|
||||
return
|
||||
}
|
||||
if *colors {
|
||||
errorColor.EnableColor()
|
||||
warningColor.EnableColor()
|
||||
successColor.EnableColor()
|
||||
} else {
|
||||
errorColor.DisableColor()
|
||||
warningColor.DisableColor()
|
||||
successColor.DisableColor()
|
||||
}
|
||||
}
|
||||
|
||||
func Error(w io.Writer, format string, args ...interface{}) {
|
||||
fmt.Fprintf(w, color.RedString("error: ")+format+"\n", args...)
|
||||
}
|
||||
|
||||
func Warning(w io.Writer, format string, args ...interface{}) {
|
||||
fmt.Fprintf(w, color.YellowString("warning: ")+format+"\n", args...)
|
||||
}
|
||||
|
||||
func Success(w io.Writer, format string, args ...interface{}) {
|
||||
fmt.Fprintf(w, color.GreenString(fmt.Sprintf(format+"\n", args...)))
|
||||
}
|
Reference in New Issue
Block a user