fix(tui): move theme styles onto the Model to end cross-session races
applyTheme mutated ~18 package-global lipgloss styles while every SSH session's tea.Program read them concurrently from its own goroutine. Pressing T or opening a new connection raced other sessions' View and bled themes across users. Styles now live in an immutable per-Model struct built by newStyles; free formatter helpers that consumed the globals became Model methods.
This commit is contained in:
+11
-11
@@ -33,14 +33,14 @@ func (m Model) viewNodesTab() string {
|
||||
}
|
||||
region := node.Region
|
||||
if region == "" {
|
||||
region = subtleStyle.Render("—")
|
||||
region = m.st.subtleStyle.Render("—")
|
||||
}
|
||||
lastSeen := fmtNodeLastSeen(node.LastSeen)
|
||||
lastSeen := m.fmtNodeLastSeen(node.LastSeen)
|
||||
version := node.Version
|
||||
if version == "" {
|
||||
version = subtleStyle.Render("—")
|
||||
version = m.st.subtleStyle.Render("—")
|
||||
}
|
||||
status := fmtNodeStatus(node.LastSeen)
|
||||
status := m.fmtNodeStatus(node.LastSeen)
|
||||
rows = append(rows, []string{name, region, lastSeen, version, status})
|
||||
}
|
||||
return rows
|
||||
@@ -50,20 +50,20 @@ func (m Model) viewNodesTab() string {
|
||||
)
|
||||
}
|
||||
|
||||
func fmtNodeStatus(lastSeen time.Time) string {
|
||||
func (m Model) fmtNodeStatus(lastSeen time.Time) string {
|
||||
if lastSeen.IsZero() {
|
||||
return subtleStyle.Render("UNKNOWN")
|
||||
return m.st.subtleStyle.Render("UNKNOWN")
|
||||
}
|
||||
ago := time.Since(lastSeen)
|
||||
if ago < 60*time.Second {
|
||||
return specialStyle.Render("ONLINE")
|
||||
return m.st.specialStyle.Render("ONLINE")
|
||||
}
|
||||
if ago < 5*time.Minute {
|
||||
return warnStyle.Render("STALE")
|
||||
return m.st.warnStyle.Render("STALE")
|
||||
}
|
||||
return dangerStyle.Render("OFFLINE")
|
||||
return m.st.dangerStyle.Render("OFFLINE")
|
||||
}
|
||||
|
||||
func fmtNodeLastSeen(t time.Time) string {
|
||||
return fmtTimeAgo(t)
|
||||
func (m Model) fmtNodeLastSeen(t time.Time) string {
|
||||
return m.fmtTimeAgo(t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user