printer/templateprinter.go
changeset 89 3758bb5f0979
parent 85 a4464c0b0c36
child 90 b1da6dc9f689
--- a/printer/templateprinter.go	Sun May 07 17:15:00 2017 +0200
+++ b/printer/templateprinter.go	Sun May 07 17:32:33 2017 +0200
@@ -20,9 +20,6 @@
 	"github.com/McKael/madonctl/printer/colors"
 )
 
-// ColorMode defines the color behaviour: 0=auto, 1=forced, 2=disabled
-var ColorMode int
-
 // disableColors can be set to true to disable the color template function
 var disableColors bool
 
@@ -34,6 +31,8 @@
 
 // NewPrinterTemplate returns a Template ResourcePrinter
 // For TemplatePrinter, the options parameter contains the template string.
+// The "color_mode" option defines the color behaviour: it can be
+// "auto" (default), "on" (forced), "off" (disabled).
 func NewPrinterTemplate(options Options) (*TemplatePrinter, error) {
 	tmpl := options["template"]
 	if tmpl == "" {
@@ -50,7 +49,8 @@
 
 	// Update disableColors.
 	// In auto-mode, check if stdout is a TTY.
-	if ColorMode == 2 || (ColorMode == 0 && !isatty.IsTerminal(os.Stdout.Fd())) {
+	colorMode := options["color_mode"]
+	if colorMode == "off" || (colorMode != "on" && !isatty.IsTerminal(os.Stdout.Fd())) {
 		disableColors = true
 	}