ctop/config/switch.go

69 lines
1.2 KiB
Go
Raw Normal View History

package config
// defaults
var switches = []*Switch{
&Switch{
Key: "sortReversed",
Val: false,
2018-09-17 01:33:52 +00:00
Label: "Reverse sort order",
},
&Switch{
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)",
},
&Switch{
Key: "enableHeader",
2017-02-19 03:58:42 +00:00
Val: true,
2018-09-17 01:33:52 +00:00
Label: "Enable status header",
},
2018-01-11 15:19:00 +00:00
&Switch{
Key: "scaleCpu",
Val: false,
Label: "Show CPU as %% of system total",
},
}
type Switch struct {
Key string
Val bool
Label string
}
// Return Switch by key
func GetSwitch(k string) *Switch {
for _, sw := range GlobalSwitches {
if sw.Key == k {
return sw
}
}
return &Switch{} // default
}
// Return Switch value by key
func GetSwitchVal(k string) bool {
return GetSwitch(k).Val
}
func UpdateSwitch(k string, val bool) {
sw := GetSwitch(k)
if sw.Val != val {
log.Noticef("config change: %s: %t -> %t", k, sw.Val, val)
sw.Val = val
}
}
// Toggle a boolean switch
func Toggle(k string) {
sw := GetSwitch(k)
newVal := sw.Val != true
log.Noticef("config change: %s: %t -> %t", k, sw.Val, newVal)
sw.Val = newVal
//log.Errorf("ignoring toggle for non-existant switch: %s", k)
}