From 647d43272d89d0dd0118d2443634255ab496b9fa Mon Sep 17 00:00:00 2001 From: Michael Sanford Date: Sat, 28 Nov 2026 09:04:33 -0500 Subject: [PATCH] feat(ui): mark MEM% as sorted alongside MEM MB MEM% and MEM MB are the same working set over a per-tick constant, so they always order identically; only MEM MB carried the arrow, making MEM% look unsortable. The memory sort now marks both and is labelled "MEM". --- README.md | 2 +- docs/index.html | 2 +- internal/ui/model.go | 2 +- internal/ui/panels/procs.go | 6 ++++ internal/ui/panels/procs_test.go | 50 ++++++++++++++++++++++++++------ 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2c1898f..56393c9 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ A self-contained, single-binary terminal system monitor for Windows, inspired by | `q` / `Ctrl+C` | Quit | | `↑` / `↓`, `k` / `j` | Scroll process list | | `PgUp` / `PgDn`, `Ctrl+U` / `Ctrl+D`, `Home` / `End` | Page, half-page, jump to top / bottom | -| `s` | Cycle sort column (CPU% → MEM MB → PID → Name → DISK R → DISK W) | +| `s` | Cycle sort column (CPU% → MEM → PID → Name → DISK R → DISK W) | | `d` | Invert sort order | | `t` | Toggle tree view (htop-style parent → child) | | `x` | Kill selected process (confirmation required) | diff --git a/docs/index.html b/docs/index.html index a9a2d41..7a63192 100644 --- a/docs/index.html +++ b/docs/index.html @@ -502,7 +502,7 @@

Keyboard shortcuts

s - Cycle sort column — CPU% → Mem MB → PID → Name → Disk R → Disk W + Cycle sort column — CPU% → Mem → PID → Name → Disk R → Disk W d diff --git a/internal/ui/model.go b/internal/ui/model.go index 7825dc9..d516065 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -72,7 +72,7 @@ const ( sortFieldCount ) -var sortLabels = [...]string{"CPU%", "MEM MB", "PID", "Name", "DISK R", "DISK W"} +var sortLabels = [...]string{"CPU%", "MEM", "PID", "Name", "DISK R", "DISK W"} // Messages exchanged within the Bubble Tea update loop. type tickMsg time.Time diff --git a/internal/ui/panels/procs.go b/internal/ui/panels/procs.go index bd50fd9..92ef103 100644 --- a/internal/ui/panels/procs.go +++ b/internal/ui/panels/procs.go @@ -93,6 +93,12 @@ func BuildColumns(termW, sortCol int, ascending bool) []table.Column { if sortCol >= 0 && sortCol < len(titles) { titles[sortCol] += " " + arrow // plain text — no lipgloss, avoids byte-vs-rune width mismatch } + // MEM% and MEM MB are the same working set over a per-tick constant, so they + // share one ordering: the memory sort marks both rather than leaving MEM% the + // one numeric column that looks unsortable. "MEM% ↓" fits memPctW. + if sortCol == ColMemMB { + titles[ColMemPct] += " " + arrow + } return []table.Column{ {Title: titles[ColPID], Width: PidW}, diff --git a/internal/ui/panels/procs_test.go b/internal/ui/panels/procs_test.go index 865a077..34055bc 100644 --- a/internal/ui/panels/procs_test.go +++ b/internal/ui/panels/procs_test.go @@ -382,26 +382,58 @@ func TestBuildColumns_NameFloorsOnNarrowTerminals(t *testing.T) { func TestBuildColumns_SortArrowIsPlainText(t *testing.T) { // Styling headers with lipgloss breaks bubbles/table alignment, because the // ANSI bytes count against the column width. - cols := BuildColumns(120, ColMemMB, false) - if !strings.HasSuffix(cols[ColMemMB].Title, "↓") { - t.Errorf("descending sort should mark the column with ↓, got %q", cols[ColMemMB].Title) + cols := BuildColumns(120, ColCPU, false) + if !strings.HasSuffix(cols[ColCPU].Title, "↓") { + t.Errorf("descending sort should mark the column with ↓, got %q", cols[ColCPU].Title) } - if strings.Contains(cols[ColMemMB].Title, "\x1b") { - t.Errorf("header contains ANSI escapes: %q", cols[ColMemMB].Title) + if strings.Contains(cols[ColCPU].Title, "\x1b") { + t.Errorf("header contains ANSI escapes: %q", cols[ColCPU].Title) } - asc := BuildColumns(120, ColMemMB, true) - if !strings.HasSuffix(asc[ColMemMB].Title, "↑") { - t.Errorf("ascending sort should mark the column with ↑, got %q", asc[ColMemMB].Title) + asc := BuildColumns(120, ColCPU, true) + if !strings.HasSuffix(asc[ColCPU].Title, "↑") { + t.Errorf("ascending sort should mark the column with ↑, got %q", asc[ColCPU].Title) } for i, c := range cols { - if i != ColMemMB && (strings.Contains(c.Title, "↑") || strings.Contains(c.Title, "↓")) { + if i != ColCPU && (strings.Contains(c.Title, "↑") || strings.Contains(c.Title, "↓")) { t.Errorf("column %d should carry no arrow, got %q", i, c.Title) } } } +// MEM% and MEM MB order identically, so the memory sort marks both — and MEM% +// stays unmarked under every other sort. +func TestBuildColumns_MemorySortMarksBothMemoryColumns(t *testing.T) { + for _, asc := range []bool{false, true} { + arrow := "↓" + if asc { + arrow = "↑" + } + cols := BuildColumns(120, ColMemMB, asc) + for _, i := range []int{ColMemPct, ColMemMB} { + if !strings.HasSuffix(cols[i].Title, arrow) { + t.Errorf("asc=%v: column %d = %q, want %s", asc, i, cols[i].Title, arrow) + } + if w := len([]rune(cols[i].Title)); w > cols[i].Width { + t.Errorf("asc=%v: header %q (%d) overflows width %d", asc, cols[i].Title, w, cols[i].Width) + } + } + for i, c := range cols { + if i != ColMemPct && i != ColMemMB && strings.ContainsAny(c.Title, "↑↓") { + t.Errorf("asc=%v: column %d should carry no arrow, got %q", asc, i, c.Title) + } + } + } + for f := 0; f < 6; f++ { + if col := SortColFor(f); col != ColMemMB { + if t0 := BuildColumns(120, col, false)[ColMemPct].Title; t0 != "MEM%" { + t.Errorf("sort field %d marked MEM%%: %q", f, t0) + } + } + } +} + func TestBuildRows_FormatsOneRowPerProcess(t *testing.T) { procs := []collector.ProcSnapshot{ {PID: 42, Name: "test.exe", CPUPct: 12.34, MemPct: 5.67, MemMB: 89.1, ReadBps: 1536, WriteBps: 0},