mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 05:30:07 +00:00
fix(status): wrap header and card output on narrow terminals
This commit is contained in:
@@ -131,6 +131,10 @@ type cardData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func renderHeader(m MetricsSnapshot, errMsg string, animFrame int, termWidth int, catHidden bool) (string, string) {
|
func renderHeader(m MetricsSnapshot, errMsg string, animFrame int, termWidth int, catHidden bool) (string, string) {
|
||||||
|
if termWidth <= 0 {
|
||||||
|
termWidth = 80
|
||||||
|
}
|
||||||
|
|
||||||
title := titleStyle.Render("Status")
|
title := titleStyle.Render("Status")
|
||||||
|
|
||||||
scoreStyle := getScoreStyle(m.HealthScore)
|
scoreStyle := getScoreStyle(m.HealthScore)
|
||||||
@@ -169,7 +173,20 @@ func renderHeader(m MetricsSnapshot, errMsg string, animFrame int, termWidth int
|
|||||||
infoParts = append(infoParts, subtleStyle.Render("up "+m.Uptime))
|
infoParts = append(infoParts, subtleStyle.Render("up "+m.Uptime))
|
||||||
}
|
}
|
||||||
|
|
||||||
headerLine := title + " " + scoreText + " " + strings.Join(infoParts, " · ")
|
headLeft := title + " " + scoreText
|
||||||
|
baseLines := wrapToWidth(headLeft, termWidth)
|
||||||
|
headerLines := append([]string{}, baseLines...)
|
||||||
|
if len(infoParts) > 0 {
|
||||||
|
headRight := strings.Join(infoParts, " · ")
|
||||||
|
combined := headLeft + " " + headRight
|
||||||
|
if lipgloss.Width(combined) <= termWidth {
|
||||||
|
headerLines = wrapToWidth(combined, termWidth)
|
||||||
|
} else {
|
||||||
|
wrappedRight := wrapToWidth(headRight, termWidth)
|
||||||
|
headerLines = append(baseLines, wrappedRight...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
headerLine := lipgloss.JoinVertical(lipgloss.Left, headerLines...)
|
||||||
|
|
||||||
// Show cat unless hidden - render mole centered below header
|
// Show cat unless hidden - render mole centered below header
|
||||||
var mole string
|
var mole string
|
||||||
@@ -596,18 +613,40 @@ func renderBatteryCard(batts []BatteryStatus, thermal ThermalStatus) cardData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func renderCard(data cardData, width int, height int) string {
|
func renderCard(data cardData, width int, height int) string {
|
||||||
titleText := data.icon + " " + data.title
|
if width <= 0 {
|
||||||
lineLen := max(width-lipgloss.Width(titleText)-2, 4)
|
width = colWidth
|
||||||
header := titleStyle.Render(titleText) + " " + lineStyle.Render(strings.Repeat("╌", lineLen))
|
}
|
||||||
content := header + "\n" + strings.Join(data.lines, "\n")
|
|
||||||
|
titleText := data.icon + " " + data.title
|
||||||
|
lineLen := width - lipgloss.Width(titleText) - 2
|
||||||
|
if lineLen < 0 {
|
||||||
|
lineLen = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
header := titleStyle.Render(titleText)
|
||||||
|
if lineLen > 0 {
|
||||||
|
header += " " + lineStyle.Render(strings.Repeat("╌", lineLen))
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := wrapToWidth(header, width)
|
||||||
|
for _, line := range data.lines {
|
||||||
|
lines = append(lines, wrapToWidth(line, width)...)
|
||||||
|
}
|
||||||
|
|
||||||
lines := strings.Split(content, "\n")
|
|
||||||
for len(lines) < height {
|
for len(lines) < height {
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
}
|
}
|
||||||
return strings.Join(lines, "\n")
|
return strings.Join(lines, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrapToWidth(text string, width int) []string {
|
||||||
|
if width <= 0 {
|
||||||
|
return []string{text}
|
||||||
|
}
|
||||||
|
wrapped := lipgloss.NewStyle().MaxWidth(width).Render(text)
|
||||||
|
return strings.Split(wrapped, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
func progressBar(percent float64) string {
|
func progressBar(percent float64) string {
|
||||||
total := 16
|
total := 16
|
||||||
if percent < 0 {
|
if percent < 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user