summaryrefslogtreecommitdiff
path: root/internal/display/display.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-14 21:17:31 +0200
committerPaul Buetow <paul@buetow.org>2026-02-14 21:17:31 +0200
commit2265b31a6eeaae8d6aac52e1fa32a33863733192 (patch)
treec463dd798f2c7b18734fedf39d020f7f74cfd4f6 /internal/display/display.go
parentb1f0ce01fb6ece8628cf0499690a003cdac28f7f (diff)
Implement f/v hotkeys for link scale and add hotkey unit tests
Add missing f/v hotkey handlers to cycle NetLink through mbit/10mbit/100mbit/gbit/10gbit, closing the gap between README documentation and actual implementation. Add 13 unit tests covering all hotkey behaviors including visual pixel assertions for toggles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/display/display.go')
-rw-r--r--internal/display/display.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/display/display.go b/internal/display/display.go
index 2d1c927..b5ed092 100644
--- a/internal/display/display.go
+++ b/internal/display/display.go
@@ -174,6 +174,10 @@ func handleKey(sym sdl.Keycode, window *sdl.Window, cfg *config.Config, state *r
cfg.NetAverage--
}
fmt.Println("==> Net average samples:", cfg.NetAverage)
+ case sdl.K_f:
+ scaleLinkUp(cfg)
+ case sdl.K_v:
+ scaleLinkDown(cfg)
case sdl.K_h:
printHotkeys()
case sdl.K_n:
@@ -553,6 +557,43 @@ func printNetInterfaceHelp(snap map[string]*stats.HostStats, cfg *config.Config,
}
// netLinkBytesPerSec returns link speed in bytes/sec from cfg.NetLink (e.g. "gbit", "10gbit", "100mbit", or numeric mbit).
+
+// linkScales lists the supported network link speeds in ascending order,
+// used by the f/v hotkeys to cycle through link scale values.
+var linkScales = []string{"mbit", "10mbit", "100mbit", "gbit", "10gbit"}
+
+// scaleLinkUp moves cfg.NetLink to the next higher link speed in linkScales.
+// Clamps at the maximum (10gbit).
+func scaleLinkUp(cfg *config.Config) {
+ idx := linkScaleIndex(cfg.NetLink)
+ if idx < len(linkScales)-1 {
+ cfg.NetLink = linkScales[idx+1]
+ }
+ fmt.Println("==> Link scale:", cfg.NetLink)
+}
+
+// scaleLinkDown moves cfg.NetLink to the next lower link speed in linkScales.
+// Clamps at the minimum (mbit).
+func scaleLinkDown(cfg *config.Config) {
+ idx := linkScaleIndex(cfg.NetLink)
+ if idx > 0 {
+ cfg.NetLink = linkScales[idx-1]
+ }
+ fmt.Println("==> Link scale:", cfg.NetLink)
+}
+
+// linkScaleIndex returns the index of the current NetLink value in linkScales.
+// Defaults to 3 (gbit) if the value is not recognized.
+func linkScaleIndex(netLink string) int {
+ s := strings.ToLower(strings.TrimSpace(netLink))
+ for i, v := range linkScales {
+ if s == v {
+ return i
+ }
+ }
+ return 3 // default: gbit
+}
+
func netLinkBytesPerSec(cfg *config.Config) int64 {
s := strings.ToLower(strings.TrimSpace(cfg.NetLink))
switch s {