github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/util/configv3/color.go (about) 1 package configv3 2 3 import "strconv" 4 5 const ( 6 // DefaultColorEnabled is the default CFConfig value for ColorEnabled. 7 DefaultColorEnabled = "" 8 9 // ColorDisabled means that no colors/bolding will be displayed. 10 ColorDisabled ColorSetting = iota 11 12 // ColorEnabled means colors/bolding will be displayed. 13 ColorEnabled 14 15 // ColorAuto means that the UI should decide if colors/bolding will be 16 // enabled. 17 ColorAuto 18 ) 19 20 // ColorSetting is a trinary operator that represents if the display should 21 // have colors enabled, disabled, or automatically detected. 22 type ColorSetting int 23 24 // ColorEnabled returns the color setting based off: 25 // 1. The $CF_COLOR environment variable if set (0/1/t/f/true/false) 26 // 2. The 'ColorEnabled' value in the .cf/config.json if set 27 // 3. Defaults to ColorEnabled if nothing is set 28 func (config *Config) ColorEnabled() ColorSetting { 29 if config.ENV.CFColor != "" { 30 val, err := strconv.ParseBool(config.ENV.CFColor) 31 if err == nil { 32 return config.boolToColorSetting(val) 33 } 34 } 35 36 val, err := strconv.ParseBool(config.ConfigFile.ColorEnabled) 37 if err != nil { 38 return ColorEnabled 39 } 40 return config.boolToColorSetting(val) 41 } 42 43 func (config *Config) boolToColorSetting(val bool) ColorSetting { 44 if val { 45 return ColorEnabled 46 } 47 48 return ColorDisabled 49 }