Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ <h2>Keyboard shortcuts</h2>
</tr>
<tr>
<td class="td-keys"><kbd>s</kbd></td>
<td>Cycle sort column &mdash; CPU%&thinsp;→&thinsp;Mem MB&thinsp;→&thinsp;PID&thinsp;→&thinsp;Name&thinsp;→&thinsp;Disk R&thinsp;→&thinsp;Disk W</td>
<td>Cycle sort column &mdash; CPU%&thinsp;→&thinsp;Mem&thinsp;→&thinsp;PID&thinsp;→&thinsp;Name&thinsp;→&thinsp;Disk R&thinsp;→&thinsp;Disk W</td>
</tr>
<tr>
<td class="td-keys"><kbd>d</kbd></td>
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions internal/ui/panels/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
50 changes: 41 additions & 9 deletions internal/ui/panels/procs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down