refactor(tui): two-tier responsive table layout (compact/wide at 120 cols)
CI / test (pull_request) Successful in 2m54s
CI / lint (pull_request) Failing after 1m12s
CI / vulncheck (pull_request) Successful in 56s

Replace continuous surplus distribution with two fixed layouts per table.
Breakpoint at 120 columns — matches how btop/k9s do it.

Compact (<120): short headers (LAT, UP%, RT, ST, MON, SENT, VER),
  tight fixed widths, no surplus guessing.

Wide (≥120): full headers (LATENCY, UPTIME, RETRIES, STATUS, MONITORS,
  LAST SENT, VERSION), generous widths.

Sites tab keeps content-aware NAME sizing + sparkline flex.
All other tabs (Alerts, Maint, Nodes, Users) use simple fixed tiers.

Removed old computeTableLayout/colDef/tierCol/pickTier — no longer needed.
This commit is contained in:
2026-05-28 15:50:23 -04:00
parent a84f4894f8
commit 5401266e83
6 changed files with 64 additions and 179 deletions
+26 -70
View File
@@ -341,31 +341,29 @@ type tableLayout struct {
}
func (m Model) computeLayout() tableLayout {
cols := []colDef{
{"#", "#", 4, 4, false},
{"", "", 0, 0, false}, // NAME (special)
{"TYPE", "TYPE", 8, 10, false},
{"STATUS", "STATUS", 8, 10, false},
{"LAT", "LATENCY", 7, 10, false},
{"UP%", "UPTIME", 8, 8, false},
{"", "", 0, 0, false}, // HISTORY (special)
{"SSL", "SSL", 5, 5, false},
{"RT", "RETRIES", 5, 9, false},
wide := m.isWide()
var fixed int
var headers []string
var widths []int
if wide {
// # NAME TYPE STATUS LATENCY UPTIME HISTORY SSL RETRIES
headers = []string{"#", "NAME", "TYPE", "STATUS", "LATENCY", "UPTIME", "HISTORY", "SSL", "RETRIES"}
widths = []int{4, 0, 10, 10, 10, 8, 0, 7, 9}
fixed = 4 + 10 + 10 + 10 + 8 + 7 + 9
} else {
// # NAME TYPE STATUS LAT UP% HISTORY SSL RT
headers = []string{"#", "NAME", "TYPE", "STATUS", "LAT", "UP%", "HISTORY", "SSL", "RT"}
widths = []int{4, 0, 8, 8, 7, 7, 0, 5, 5}
fixed = 4 + 8 + 8 + 7 + 7 + 5 + 5
}
numCols := len(cols)
borderOverhead := 2 + (numCols - 1) // left + right border + column separators
usable := m.termWidth - chromePadH - 2 - borderOverhead
if usable < 80 {
usable = 80
}
fixedMin := 0
for i, c := range cols {
if i == 1 || i == 6 {
continue
}
fixedMin += c.minWidth
numCols := len(headers)
borderOverhead := 2 + (numCols - 1)
avail := m.termWidth - chromePadH - 2 - borderOverhead - fixed
if avail < 20 {
avail = 20
}
maxName := 0
@@ -374,68 +372,26 @@ func (m Model) computeLayout() tableLayout {
maxName = n
}
}
maxName += 4 // icon + padding + error preview room
maxName += 4
avail := usable - fixedMin
nameW := avail / 2
if nameW > maxName {
nameW = maxName
}
sparkW := avail - nameW - 2
if nameW < 13 {
nameW = 13
}
if nameW > 40 {
nameW = 40
}
sparkW := avail - nameW
if sparkW < 10 {
sparkW = 10
}
if sparkW > 60 {
sparkW = 60
}
surplus := usable - fixedMin - nameW - sparkW - 2
if surplus < 0 {
surplus = 0
}
headers := make([]string, len(cols))
widths := make([]int, len(cols))
for i, c := range cols {
if i == 1 {
headers[i] = "NAME"
widths[i] = nameW
continue
}
if i == 6 {
headers[i] = "HISTORY"
widths[i] = sparkW + 2
continue
}
w := c.minWidth
expand := c.maxWidth - c.minWidth
if surplus >= expand {
w = c.maxWidth
surplus -= expand
} else if surplus > 0 {
w += surplus
surplus = 0
}
if w >= len(c.full)+2 {
headers[i] = c.full
} else {
headers[i] = c.short
}
widths[i] = w
}
if surplus > 0 {
widths[6] += surplus
}
widths[1] = nameW
widths[6] = sparkW
return tableLayout{
nameW: nameW,