diff options
author | Sean E. Russell <seanerussell@gmail.com> | 2018-12-26 22:06:55 -0600 |
---|---|---|
committer | Sean E. Russell <seanerussell@gmail.com> | 2018-12-26 23:15:44 -0600 |
commit | 5ee4b4a978f3b27513b680fe3297cb7bea7bcb1e (patch) | |
tree | 126eac7115a40328d3446def6f4a7afb0b46305e /main.go | |
parent | 7b77956fee4cd22b36fe5ba63a2aefa0304d567b (diff) |
Adds battery support
Cleans up mod file; adds flag for battery.
Adds documentation; fixes missing color sets for battery.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -32,14 +32,16 @@ var ( zoomInterval = 3 helpVisible = false averageLoad = false + battery = false percpuLoad = false - widgetCount = 6 + widgetCount = 7 fahrenheit = false configDir = appdir.New("gotop").UserConfig() logPath = filepath.Join(configDir, "errors.log") stderrLogger = log.New(os.Stderr, "", 0) cpu *w.CPU + batt *w.Batt mem *w.Mem proc *w.Proc net *w.Net @@ -61,6 +63,7 @@ Options: -p, --percpu Show each CPU in the CPU widget. -a, --averagecpu Show average CPU in the CPU widget. -f, --fahrenheit Show temperatures in fahrenheit. + -b, --battery Show battery charge over time (minimal overrides & sets false) Colorschemes: default @@ -81,6 +84,7 @@ Colorschemes: } averageLoad, _ = args["--averagecpu"].(bool) percpuLoad, _ = args["--percpu"].(bool) + battery, _ = args["--battery"].(bool) minimal, _ = args["--minimal"].(bool) if minimal { @@ -145,7 +149,12 @@ func setupGrid() { ui.Body.Set(0, 6, 6, 12, mem) ui.Body.Set(6, 6, 12, 12, proc) } else { - ui.Body.Set(0, 0, 12, 4, cpu) + if battery { + ui.Body.Set(0, 0, 8, 4, cpu) + ui.Body.Set(8, 0, 12, 4, batt) + } else { + ui.Body.Set(0, 0, 12, 4, cpu) + } ui.Body.Set(0, 4, 4, 6, disk) ui.Body.Set(0, 6, 4, 8, temp) @@ -192,6 +201,21 @@ func widgetColors() { if !minimal { temp.TempLow = ui.Color(colorscheme.TempLow) temp.TempHigh = ui.Color(colorscheme.TempHigh) + var battKeys []string + for key := range batt.Data { + battKeys = append(battKeys, key) + } + sort.Strings(battKeys) + bi := 0 + for _, v := range battKeys { + if bi >= len(colorscheme.BattLines) { + // assuming colorscheme for CPU lines is not empty + bi = 0 + } + c := colorscheme.BattLines[bi] + batt.LineColor[v] = ui.Color(c) + bi++ + } } } @@ -213,6 +237,10 @@ func initWidgets() { }() if !minimal { go func() { + batt = w.NewBatt(time.Minute, zoom) + wg.Done() + }() + go func() { net = w.NewNet() wg.Done() }() |