refactor(tui): two-tier responsive table layout (compact/wide at 120 cols)
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:
@@ -15,77 +15,10 @@ var (
|
||||
|
||||
type StyleOverride func(row, col int) *lipgloss.Style
|
||||
|
||||
type colDef struct {
|
||||
short string
|
||||
full string
|
||||
minWidth int
|
||||
maxWidth int
|
||||
flex bool
|
||||
}
|
||||
const wideBreakpoint = 120
|
||||
|
||||
func (m Model) computeTableLayout(cols []colDef, maxContentWidth int) ([]string, []int) {
|
||||
numCols := len(cols)
|
||||
borderOverhead := 2 + (numCols - 1)
|
||||
usable := m.termWidth - chromePadH - 2 - borderOverhead
|
||||
if usable < 40 {
|
||||
usable = 40
|
||||
}
|
||||
|
||||
fixedMin := 0
|
||||
flexIdx := -1
|
||||
for i, c := range cols {
|
||||
if c.flex {
|
||||
flexIdx = i
|
||||
continue
|
||||
}
|
||||
fixedMin += c.minWidth
|
||||
}
|
||||
|
||||
flexW := usable - fixedMin
|
||||
if maxContentWidth > 0 && flexW > maxContentWidth {
|
||||
flexW = maxContentWidth
|
||||
}
|
||||
if flexW < 8 {
|
||||
flexW = 8
|
||||
}
|
||||
|
||||
surplus := usable - fixedMin - flexW
|
||||
if surplus < 0 {
|
||||
surplus = 0
|
||||
}
|
||||
|
||||
headers := make([]string, numCols)
|
||||
widths := make([]int, numCols)
|
||||
for i, c := range cols {
|
||||
if c.flex {
|
||||
headers[i] = c.full
|
||||
widths[i] = flexW
|
||||
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 && flexIdx >= 0 {
|
||||
widths[flexIdx] += surplus
|
||||
}
|
||||
|
||||
return headers, widths
|
||||
func (m Model) isWide() bool {
|
||||
return m.termWidth >= wideBreakpoint
|
||||
}
|
||||
|
||||
func (m Model) renderTable(headers []string, items int, buildRows func(start, end int) [][]string, colWidths []int, styleOverride StyleOverride) string {
|
||||
|
||||
Reference in New Issue
Block a user