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