summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/sort.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-09 23:01:38 +0200
committerPaul Buetow <paul@buetow.org>2026-03-09 23:01:38 +0200
commit227de0db390fec4e1327a7cab6be4c1268848695 (patch)
treef70ff9f3b23db47db0e0aeafa1bb1aad5abc71a8 /internal/tui/dashboard/sort.go
parentbcaa22111ac619e317f7adfd60a1fc6bd4db8d29 (diff)
tui: add reverse sorting for dashboard tables (task 364)
Diffstat (limited to 'internal/tui/dashboard/sort.go')
-rw-r--r--internal/tui/dashboard/sort.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/internal/tui/dashboard/sort.go b/internal/tui/dashboard/sort.go
index 7d985a6..399d0c5 100644
--- a/internal/tui/dashboard/sort.go
+++ b/internal/tui/dashboard/sort.go
@@ -1,15 +1,34 @@
package dashboard
type tableSortState[K comparable] struct {
- active bool
- key K
+ active bool
+ key K
+ reverse bool
}
-func (s tableSortState[K]) toggled(key K) tableSortState[K] {
- if s.active && s.key == key {
+func (s tableSortState[K]) toggled(key K, reverse bool) tableSortState[K] {
+ if s.active && s.key == key && s.reverse == reverse {
return tableSortState[K]{}
}
- return tableSortState[K]{active: true, key: key}
+ return tableSortState[K]{active: true, key: key, reverse: reverse}
+}
+
+func (s tableSortState[K]) apply(cmp int) int {
+ if !s.reverse {
+ return cmp
+ }
+ return -cmp
+}
+
+func sortDirectionLabel(defaultAscending, reverse bool) string {
+ if defaultAscending != reverse {
+ return "asc"
+ }
+ return "desc"
+}
+
+func sortLabelWithDirection(name string, defaultAscending, reverse bool) string {
+ return name + " " + sortDirectionLabel(defaultAscending, reverse)
}
func compareUint64Desc(left, right uint64) int {