2017-02-16 03:02:13 +00:00
|
|
|
package config
|
|
|
|
|
2017-02-16 03:49:41 +00:00
|
|
|
// defaults
|
2020-01-02 14:00:55 +00:00
|
|
|
var defaultSwitches = []*Switch{
|
2017-02-16 03:02:13 +00:00
|
|
|
&Switch{
|
2017-02-16 04:06:05 +00:00
|
|
|
Key: "sortReversed",
|
|
|
|
Val: false,
|
2018-09-17 01:33:52 +00:00
|
|
|
Label: "Reverse sort order",
|
2017-02-16 03:02:13 +00:00
|
|
|
},
|
|
|
|
&Switch{
|
2017-02-16 04:06:05 +00:00
|
|
|
Key: "allContainers",
|
2017-02-19 03:58:42 +00:00
|
|
|
Val: true,
|
2018-09-17 01:33:52 +00:00
|
|
|
Label: "Show all containers",
|
|
|
|
},
|
|
|
|
&Switch{
|
|
|
|
Key: "fullRowCursor",
|
|
|
|
Val: true,
|
|
|
|
Label: "Highlight entire cursor row (vs. name only)",
|
2017-02-16 03:02:13 +00:00
|
|
|
},
|
|
|
|
&Switch{
|
2017-02-16 04:06:05 +00:00
|
|
|
Key: "enableHeader",
|
2017-02-19 03:58:42 +00:00
|
|
|
Val: true,
|
2018-09-17 01:33:52 +00:00
|
|
|
Label: "Enable status header",
|
2017-02-16 03:02:13 +00:00
|
|
|
},
|
2018-01-11 15:19:00 +00:00
|
|
|
&Switch{
|
|
|
|
Key: "scaleCpu",
|
|
|
|
Val: false,
|
|
|
|
Label: "Show CPU as %% of system total",
|
|
|
|
},
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Switch struct {
|
2017-02-16 04:06:05 +00:00
|
|
|
Key string
|
|
|
|
Val bool
|
|
|
|
Label string
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 02:33:29 +00:00
|
|
|
// GetSwitch returns Switch by key
|
2017-02-16 04:06:05 +00:00
|
|
|
func GetSwitch(k string) *Switch {
|
2020-01-02 14:00:55 +00:00
|
|
|
lock.RLock()
|
|
|
|
defer lock.RUnlock()
|
|
|
|
|
2017-02-16 03:49:41 +00:00
|
|
|
for _, sw := range GlobalSwitches {
|
2017-02-16 04:06:05 +00:00
|
|
|
if sw.Key == k {
|
|
|
|
return sw
|
2017-02-16 03:49:41 +00:00
|
|
|
}
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|
2017-02-16 04:06:05 +00:00
|
|
|
return &Switch{} // default
|
|
|
|
}
|
|
|
|
|
2019-03-07 02:33:29 +00:00
|
|
|
// GetSwitchVal returns Switch value by key
|
2017-02-16 04:06:05 +00:00
|
|
|
func GetSwitchVal(k string) bool {
|
|
|
|
return GetSwitch(k).Val
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 16:15:18 +00:00
|
|
|
func UpdateSwitch(k string, val bool) {
|
|
|
|
sw := GetSwitch(k)
|
2020-01-02 14:00:55 +00:00
|
|
|
|
|
|
|
lock.Lock()
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
2018-01-11 16:15:18 +00:00
|
|
|
if sw.Val != val {
|
2020-01-02 14:00:55 +00:00
|
|
|
log.Noticef("config change [%s]: %t -> %t", k, sw.Val, val)
|
2018-01-11 16:15:18 +00:00
|
|
|
sw.Val = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 03:02:13 +00:00
|
|
|
// Toggle a boolean switch
|
|
|
|
func Toggle(k string) {
|
2017-02-16 04:06:05 +00:00
|
|
|
sw := GetSwitch(k)
|
2020-01-02 14:00:55 +00:00
|
|
|
|
|
|
|
lock.Lock()
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
2020-01-02 23:02:53 +00:00
|
|
|
sw.Val = !sw.Val
|
|
|
|
log.Noticef("config change [%s]: %t -> %t", k, !sw.Val, sw.Val)
|
2017-02-16 04:06:05 +00:00
|
|
|
//log.Errorf("ignoring toggle for non-existant switch: %s", k)
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|