diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-18 09:33:08 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-18 09:33:08 +0200 |
| commit | f1951f2ee1e83d802030c257d4a1df099ec08976 (patch) | |
| tree | bce1d38cc5b78e4cb5d80d6e0d316267bb15cb9f /internal/display | |
| parent | d845cf3208c3bbdb7e3dd3041d1ae491b88d4d21 (diff) | |
feat: add fixed load scale (--loadmax), load peak reset (r key), update README
- config: add LoadMax float64 field; loadmax key in ~/.loadbarsrc; written by 'w'
- main: add --loadmax flag (overrides rc file when > 0)
- display: newRunState initialises loadPeak from LoadMax when fixed
- display: updateLoadPeak accepts loadMax param; short-circuits to fixed value when set
- display: add 'r' hotkey to reset auto-scale peak to floor (2.0); no-op when fixed
- tooltip: loadTooltipLines shows 'Max:' label when scale is fixed, 'Peak:' for auto
- README: document 4/l load toggle, r reset, --showload, --loadmax, load average bars section; fix --cpumode entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/display')
| -rw-r--r-- | internal/display/display.go | 36 | ||||
| -rw-r--r-- | internal/display/tooltip.go | 14 |
2 files changed, 38 insertions, 12 deletions
diff --git a/internal/display/display.go b/internal/display/display.go index ffe5ca2..555e904 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -106,7 +106,13 @@ func newRunState(cfg *config.Config, winW, winH int32) *runState { showMem: cfg.ShowMem, showNet: cfg.ShowNet, showLoad: cfg.ShowLoad, - loadPeak: 2.0, // minimum floor ensures meaningful scale on idle systems + // Use the fixed cap when set; otherwise start at the auto-scale floor of 2.0. + loadPeak: func() float64 { + if cfg.LoadMax > 0 { + return cfg.LoadMax + } + return 2.0 + }(), showSeparators: cfg.ShowSeparators, extended: cfg.Extended, winW: winW, @@ -182,6 +188,15 @@ func handleKey(sym sdl.Keycode, window *sdl.Window, cfg *config.Config, state *r case sdl.K_4, sdl.K_l: state.showLoad = !state.showLoad fmt.Println("==> Toggled show load:", state.showLoad) + case sdl.K_r: + // Reset load auto-scale peak to the floor so the bar rescales immediately. + // Has no effect when loadmax is fixed (cfg.LoadMax > 0). + if cfg.LoadMax == 0 { + state.loadPeak = 2.0 + fmt.Println("==> Load peak reset to auto-scale floor (2.0)") + } else { + fmt.Println("==> Load peak reset ignored (fixed loadmax =", cfg.LoadMax, ")") + } case sdl.K_e: state.extended = !state.extended fmt.Println("==> Toggled extended (peak line):", state.extended) @@ -303,7 +318,7 @@ func drawFrame(renderer *sdl.Renderer, src stats.Source, cfg *config.Config, sta renderer.Clear() if state.showLoad { // Update the global load peak before drawing so bar scale is current. - updateLoadPeak(snap, state) + updateLoadPeak(snap, state, cfg.LoadMax) } drawBars(renderer, snap, cfg, state, numBars) if state.showAvgLine { @@ -730,7 +745,7 @@ func drawMemBarSmoothed(renderer *sdl.Renderer, h *stats.HostStats, smoothed *st } func printHotkeys() { - fmt.Println("=> Hotkeys: 1=cores 2/m=mem 3/n=net 4/l=load e=extended g=avg line i=io avg s=separators h=help q=quit w=write config a/y=cpu avg d/c=net avg f/v=link scale arrows=resize") + fmt.Println("=> Hotkeys: 1=cores 2/m=mem 3/n=net 4/l=load r=reset load peak e=extended g=avg line i=io avg s=separators h=help q=quit w=write config a/y=cpu avg d/c=net avg f/v=link scale arrows=resize") } // scaleLinkUp moves cfg.NetLink to the next higher link speed in linkScales. @@ -887,11 +902,16 @@ func drawNetBarSmoothed(renderer *sdl.Renderer, h *stats.HostStats, cfg *config. return prev } -// updateLoadPeak decays the global load peak and updates it with the current -// maximum 1-min load across all hosts. The floor of 2.0 prevents a zero scale -// on idle systems. The slow per-frame decay (× 0.9999) lets the scale recover -// gradually after a spike rather than snapping back immediately. -func updateLoadPeak(snap map[string]*stats.HostStats, state *runState) { +// updateLoadPeak maintains the load scale used by the bar renderer. +// When loadMax > 0, the scale is pinned to that fixed value every frame +// (no decay, no tracking). When loadMax == 0, auto-scale is used: the +// global peak decays slowly (× 0.9999 per frame) with a floor of 2.0, +// and is updated with the current maximum 1-min load across all hosts. +func updateLoadPeak(snap map[string]*stats.HostStats, state *runState, loadMax float64) { + if loadMax > 0 { + state.loadPeak = loadMax // fixed scale: override every frame, skip auto logic + return + } state.loadPeak *= 0.9999 // slow per-frame decay toward idle baseline if state.loadPeak < 2.0 { state.loadPeak = 2.0 diff --git a/internal/display/tooltip.go b/internal/display/tooltip.go index e5cf951..77ee365 100644 --- a/internal/display/tooltip.go +++ b/internal/display/tooltip.go @@ -37,7 +37,7 @@ func tooltipLines(bar *barDescriptor, snap map[string]*stats.HostStats, cfg *con case barNet: return netTooltipLines(bar, cfg, state) case barLoad: - return loadTooltipLines(bar, h, state) + return loadTooltipLines(bar, h, cfg, state) } return nil } @@ -101,8 +101,10 @@ func netTooltipLines(bar *barDescriptor, cfg *config.Config, state *runState) [] } // loadTooltipLines returns tooltip text for a load-average bar showing -// the smoothed 1/5/15-min averages and the current global peak scale. -func loadTooltipLines(bar *barDescriptor, h *stats.HostStats, state *runState) []string { +// the 1/5/15-min averages and the current scale reference. +// When cfg.LoadMax > 0 the scale is fixed and the label reads "Max:"; +// otherwise it tracks the auto-scale peak and reads "Peak:". +func loadTooltipLines(bar *barDescriptor, h *stats.HostStats, cfg *config.Config, state *runState) []string { lines := []string{fmt.Sprintf("%s [load]", bar.host)} l1, err1 := strconv.ParseFloat(strings.TrimSpace(h.LoadAvg1), 64) l5, err5 := strconv.ParseFloat(strings.TrimSpace(h.LoadAvg5), 64) @@ -111,11 +113,15 @@ func loadTooltipLines(bar *barDescriptor, h *stats.HostStats, state *runState) [ lines = append(lines, "No data yet") return lines } + scaleLabel := "Peak: " + if cfg.LoadMax > 0 { + scaleLabel = "Max: " + } lines = append(lines, fmt.Sprintf("1min: %.2f", l1), fmt.Sprintf("5min: %.2f", l5), fmt.Sprintf("15min: %.2f", l15), - fmt.Sprintf("Peak: %.2f", state.loadPeak), + fmt.Sprintf(scaleLabel+"%.2f", state.loadPeak), ) return lines } |
