diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-18 10:10:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-18 10:10:39 +0200 |
| commit | 69f5017434298f1ffd4cdc30c30b95d0f4bd344f (patch) | |
| tree | c41a378bc8c4c7338f392cde7a4185658d4dfb12 /internal/config | |
| parent | f1951f2ee1e83d802030c257d4a1df099ec08976 (diff) | |
refactor: enforce Go best practices (function size, ordering, formatting)
- config: split set() (62L) into setSizeAndTuning() + setDisplayFlags()
- collector: split Run() (70L) into Run + startLocalScanner + startRemoteScanner
+ parseCollectorStream + dispatchCollectorLine; each <30L
- collector: remove unused script_embed.go (RemoteScript was dead code)
- display: move newRunState constructor before Run() per constructor-first rule
- display: replace loadPeak IIFE with a plain initLoadPeak variable
- display: split handleKey() (114L) into handleToggleKeys + handleAdjustAndSave
+ handleResizeKeys; add nil guard in handleResizeKeys for test safety
- display: split drawNetBarSmoothed() (75L) into drawNetBarSmoothed +
smoothNetUtilization + drawNetHalves; each <30L
- all: gofmt -w to fix formatting drift in display and config files
All tests pass (go test ./...).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 3625341..d9b367c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,16 +14,16 @@ import ( // Config holds all loadbars configuration (file + CLI). // Defaults match the Perl Shared.pm %C. type Config struct { - Hosts []string // Each entry is "host" or "host:user" - Title string - BarWidth int - CPUAverage int - Extended bool - HasAgent bool - Height int - MaxWidth int - NetAverage int - NetLink string + Hosts []string // Each entry is "host" or "host:user" + Title string + BarWidth int + CPUAverage int + Extended bool + HasAgent bool + Height int + MaxWidth int + NetAverage int + NetLink string ShowAvgLine bool ShowIOAvgLine bool CPUMode int // constants.CPUModeAverage / CPUModeCores / CPUModeOff @@ -40,14 +40,14 @@ type Config struct { // Default returns a Config with default values. func Default() Config { return Config{ - BarWidth: 1200, - CPUAverage: 10, - Extended: false, - HasAgent: false, - Height: 150, - MaxWidth: 1900, - NetAverage: 15, - NetLink: "gbit", + BarWidth: 1200, + CPUAverage: 10, + Extended: false, + HasAgent: false, + Height: 150, + MaxWidth: 1900, + NetAverage: 15, + NetLink: "gbit", CPUMode: constants.CPUModeAverage, // start with aggregate bar only ShowMem: false, ShowNet: false, @@ -137,7 +137,14 @@ func (c *Config) parseReader(f *os.File) error { return scanner.Err() } +// set applies a single key=value pair to the config, delegating to focused helpers. func (c *Config) set(key, val string) { + c.setSizeAndTuning(key, val) + c.setDisplayFlags(key, val) +} + +// setSizeAndTuning handles window dimension, SSH, sampling, and identity keys. +func (c *Config) setSizeAndTuning(key, val string) { switch key { case "title": c.Title = val @@ -149,8 +156,6 @@ func (c *Config) set(key, val string) { if n, err := strconv.Atoi(val); err == nil { c.CPUAverage = n } - case "extended": - c.Extended = parseBool(val) case "hasagent": c.HasAgent = parseBool(val) case "height": @@ -167,6 +172,22 @@ func (c *Config) set(key, val string) { } case "netlink": c.NetLink = val + case "maxbarsperrow": + if n, err := strconv.Atoi(val); err == nil { + c.MaxBarsPerRow = n + } + case "sshopts": + c.SSHOpts = val + case "cluster": + c.Cluster = val + } +} + +// setDisplayFlags handles keys that control what is shown and how CPU/load are scaled. +func (c *Config) setDisplayFlags(key, val string) { + switch key { + case "extended": + c.Extended = parseBool(val) case "showavgline": c.ShowAvgLine = parseBool(val) case "showioavgline": @@ -196,14 +217,6 @@ func (c *Config) set(key, val string) { } case "showseparators": c.ShowSeparators = parseBool(val) - case "maxbarsperrow": - if n, err := strconv.Atoi(val); err == nil { - c.MaxBarsPerRow = n - } - case "sshopts": - c.SSHOpts = val - case "cluster": - c.Cluster = val } } |
