feat(tui): responsive table layout for all tabs
Extract shared computeTableLayout() into table_helpers.go — takes column definitions with short/full headers, min/max widths, and a flex column that absorbs surplus space. All tabs now use it: - Alerts: CONFIG column is flex, NAME/TYPE/SENT expand with width - Maint: TITLE column is flex, TYPE/MONITORS/STATUS/dates expand - Nodes: NAME column is flex, REGION/LAST SEEN/VERSION expand - Users: PUBLIC KEY column is flex, USERNAME expands - Sites: uses same colDef type (keeps special dual-flex for NAME+HISTORY) Headers auto-switch short/full based on available width across all tabs.
This commit is contained in:
@@ -148,8 +148,26 @@ func (m Model) viewAlertsTab() string {
|
||||
return "\n No alert channels configured. Press [n] to add one."
|
||||
}
|
||||
|
||||
maxName := 0
|
||||
for _, a := range m.alerts {
|
||||
if n := len([]rune(a.Name)); n > maxName {
|
||||
maxName = n
|
||||
}
|
||||
}
|
||||
|
||||
cols := []colDef{
|
||||
{"#", "#", 4, 4, false},
|
||||
{"", "", 3, 3, false},
|
||||
{"NAME", "NAME", 10, 20, false},
|
||||
{"TYPE", "TYPE", 10, 12, false},
|
||||
{"CONFIG", "CONFIG", 15, 40, true},
|
||||
{"SENT", "LAST SENT", 8, 12, false},
|
||||
}
|
||||
headers, widths := m.computeTableLayout(cols, 0)
|
||||
nameW := widths[2]
|
||||
|
||||
return m.renderTable(
|
||||
[]string{"#", "", "NAME", "TYPE", "CONFIG", "LAST SENT"},
|
||||
headers,
|
||||
len(m.alerts),
|
||||
func(start, end int) [][]string {
|
||||
var rows [][]string
|
||||
@@ -159,7 +177,7 @@ func (m Model) viewAlertsTab() string {
|
||||
rows = append(rows, []string{
|
||||
fmt.Sprintf("%d", i+1),
|
||||
fmtAlertHealth(h),
|
||||
m.zones.Mark(fmt.Sprintf("alert-%d", i), limitStr(a.Name, 15)),
|
||||
m.zones.Mark(fmt.Sprintf("alert-%d", i), limitStr(a.Name, nameW-2)),
|
||||
fmtAlertType(a.Type),
|
||||
fmtAlertConfig(struct {
|
||||
Type string
|
||||
@@ -170,7 +188,7 @@ func (m Model) viewAlertsTab() string {
|
||||
}
|
||||
return rows
|
||||
},
|
||||
nil, nil,
|
||||
widths, nil,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user