polish(tui): overhaul tab bar — consistent counts, active highlight, colored alerts
CI / test (pull_request) Successful in 2m33s
CI / lint (pull_request) Successful in 56s
CI / vulncheck (pull_request) Successful in 51s

Closes #89
This commit was merged in pull request #94.
This commit is contained in:
2026-06-05 17:14:07 -04:00
parent cc139bdb73
commit 69a8e0f7ba
2 changed files with 28 additions and 31 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ func applyTheme(t Theme) {
sparkDanger = string(t.Danger)
titleStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
activeTab = lipgloss.NewStyle().Border(lipgloss.NormalBorder(), false, false, true, false).BorderForeground(t.Accent).Foreground(t.Accent).Bold(true).Padding(0, 1)
activeTab = lipgloss.NewStyle().Background(t.Surface).Foreground(t.Accent).Bold(true).Padding(0, 1)
inactiveTab = lipgloss.NewStyle().Padding(0, 1).Foreground(t.Muted)
tableHeaderStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true).Padding(0, 1)
+27 -30
View File
@@ -190,45 +190,42 @@ func (m Model) viewDashboard() string {
return outerPad.Render(lipgloss.JoinVertical(lipgloss.Top, header, paddedContent, footer))
}
type tabEntry struct {
name string
count int
warn int
}
func (m Model) renderTabBar(stats dashboardStats) string {
var sitesLabel string
if stats.downCount > 0 {
sitesLabel = fmt.Sprintf("Sites (%d↓)", stats.downCount)
} else if stats.lateCount > 0 {
sitesLabel = fmt.Sprintf("Sites (%d⚠)", stats.lateCount)
} else if stats.totalMonitors > 0 {
sitesLabel = fmt.Sprintf("Sites (%d)", stats.totalMonitors)
} else {
sitesLabel = "Sites"
tabs := []tabEntry{
{"Sites", stats.totalMonitors, stats.downCount + stats.lateCount},
{"Alerts", len(m.alerts), 0},
{"Logs", 0, 0},
{"Nodes", len(m.nodes), stats.offlineNodes},
{"Maint", len(m.maintenanceWindows), stats.activeMaint},
}
var nodesLabel string
if stats.offlineNodes > 0 {
nodesLabel = fmt.Sprintf("Nodes (%d!)", stats.offlineNodes)
} else if len(m.nodes) > 0 {
nodesLabel = fmt.Sprintf("Nodes (%d)", len(m.nodes))
} else {
nodesLabel = "Nodes"
}
var maintLabel string
if stats.activeMaint > 0 {
maintLabel = fmt.Sprintf("Maint (%d)", stats.activeMaint)
} else {
maintLabel = "Maint"
}
tabs := []string{sitesLabel, "Alerts", "Logs", nodesLabel, maintLabel}
if m.isAdmin {
tabs = append(tabs, "Users")
tabs = append(tabs, tabEntry{"Users", len(m.users), 0})
}
countStyle := lipgloss.NewStyle().Foreground(m.theme.Muted)
var renderedTabs []string
for i, t := range tabs {
label := t.name
if t.count > 0 {
badge := countStyle.Render(fmt.Sprintf(" %d", t.count))
if t.warn > 0 {
badge = dangerStyle.Render(fmt.Sprintf(" %d", t.warn))
}
label += badge
}
var rendered string
if i == m.currentTab {
rendered = activeTab.Render(t)
rendered = activeTab.Render(label)
} else {
rendered = inactiveTab.Render(t)
rendered = inactiveTab.Render(label)
}
renderedTabs = append(renderedTabs, m.zones.Mark(fmt.Sprintf("tab-%d", i), rendered))
}