mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 17:55:08 +00:00
fix(status): keep compact header single-line on tight widths
This commit is contained in:
@@ -167,27 +167,39 @@ func renderHeader(m MetricsSnapshot, errMsg string, animFrame int, termWidth int
|
|||||||
if m.Hardware.RefreshRate != "" {
|
if m.Hardware.RefreshRate != "" {
|
||||||
infoParts = append(infoParts, m.Hardware.RefreshRate)
|
infoParts = append(infoParts, m.Hardware.RefreshRate)
|
||||||
}
|
}
|
||||||
|
optionalInfoParts := []string{}
|
||||||
if !compactHeader && m.Hardware.OSVersion != "" {
|
if !compactHeader && m.Hardware.OSVersion != "" {
|
||||||
infoParts = append(infoParts, m.Hardware.OSVersion)
|
optionalInfoParts = append(optionalInfoParts, m.Hardware.OSVersion)
|
||||||
}
|
}
|
||||||
if !compactHeader && m.Uptime != "" {
|
if !compactHeader && m.Uptime != "" {
|
||||||
infoParts = append(infoParts, subtleStyle.Render("up "+m.Uptime))
|
optionalInfoParts = append(optionalInfoParts, subtleStyle.Render("up "+m.Uptime))
|
||||||
}
|
}
|
||||||
|
|
||||||
headLeft := title + " " + scoreText
|
headLeft := title + " " + scoreText
|
||||||
baseLines := wrapToWidth(headLeft, termWidth)
|
headerLine := headLeft
|
||||||
headerLines := append([]string{}, baseLines...)
|
if termWidth > 0 && lipgloss.Width(headerLine) > termWidth {
|
||||||
if len(infoParts) > 0 {
|
headerLine = wrapToWidth(headLeft, termWidth)[0]
|
||||||
headRight := strings.Join(infoParts, " · ")
|
}
|
||||||
combined := headLeft + " " + headRight
|
if termWidth > 0 {
|
||||||
if lipgloss.Width(combined) <= termWidth {
|
allParts := append(append([]string{}, infoParts...), optionalInfoParts...)
|
||||||
headerLines = wrapToWidth(combined, termWidth)
|
if len(allParts) > 0 {
|
||||||
} else {
|
combined := headLeft + " " + strings.Join(allParts, " · ")
|
||||||
wrappedRight := wrapToWidth(headRight, termWidth)
|
if lipgloss.Width(combined) <= termWidth {
|
||||||
headerLines = append(baseLines, wrappedRight...)
|
headerLine = combined
|
||||||
|
} else {
|
||||||
|
// When width is tight, drop lower-priority tail (OS and uptime) as a group.
|
||||||
|
fitParts := append([]string{}, infoParts...)
|
||||||
|
for len(fitParts) > 0 {
|
||||||
|
candidate := headLeft + " " + strings.Join(fitParts, " · ")
|
||||||
|
if lipgloss.Width(candidate) <= termWidth {
|
||||||
|
headerLine = candidate
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fitParts = fitParts[:len(fitParts)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
|
|||||||
@@ -982,6 +982,34 @@ func TestRenderHeaderHidesOSAndUptimeOnNarrowWidth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderHeaderDropsLowPriorityInfoToStaySingleLine(t *testing.T) {
|
||||||
|
m := MetricsSnapshot{
|
||||||
|
HealthScore: 90,
|
||||||
|
Hardware: HardwareInfo{
|
||||||
|
Model: "MacBook Pro",
|
||||||
|
CPUModel: "Apple M2 Pro",
|
||||||
|
TotalRAM: "32.0 GB",
|
||||||
|
DiskSize: "460.4 GB",
|
||||||
|
RefreshRate: "60Hz",
|
||||||
|
OSVersion: "macOS 26.3",
|
||||||
|
},
|
||||||
|
GPU: []GPUStatus{{CoreCount: 19}},
|
||||||
|
Uptime: "9d 13h",
|
||||||
|
}
|
||||||
|
|
||||||
|
header, _ := renderHeader(m, "", 0, 100, true)
|
||||||
|
plain := stripANSI(header)
|
||||||
|
if strings.Contains(plain, "\n") {
|
||||||
|
t.Fatalf("renderHeader() should stay single line when trimming low-priority fields, got %q", plain)
|
||||||
|
}
|
||||||
|
if strings.Contains(plain, "macOS 26.3") {
|
||||||
|
t.Fatalf("renderHeader() should drop os version when width is tight, got %q", plain)
|
||||||
|
}
|
||||||
|
if strings.Contains(plain, "up 9d 13h") {
|
||||||
|
t.Fatalf("renderHeader() should drop uptime when width is tight, got %q", plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRenderCardWrapsOnNarrowWidth(t *testing.T) {
|
func TestRenderCardWrapsOnNarrowWidth(t *testing.T) {
|
||||||
card := cardData{
|
card := cardData{
|
||||||
icon: iconCPU,
|
icon: iconCPU,
|
||||||
|
|||||||
Reference in New Issue
Block a user