fix(tui): retain phase progress in narrow bars
- commit
- 7f38ec6b7919d732158d9676374a4d5c2bca616e
- author
- brice · · 2026-08-06 06:43 UTC
- parent
- d3cdac6
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +12 -2
M packages/tui/rightbar.go +4 -1
| @@ -224,7 +224,10 @@ func truncateRightBarPhaseLine(text string, width int) string { | |||
| 224 | 224 | prefix := text[:nameStart] | |
| 225 | 225 | suffix := text[nameEnd:] | |
| 226 | 226 | nameWidth := width - visibleWidth(prefix) - visibleWidth(suffix) | |
| 227 | - | if nameWidth <= 0 { | |
| 227 | + | if nameWidth == 0 { | |
| 228 | + | return prefix + suffix | |
| 229 | + | } | |
| 230 | + | if nameWidth < 0 { | |
| 228 | 231 | return truncateRightBarLine(text, width) | |
| 229 | 232 | } | |
| 230 | 233 | return prefix + truncateRightBarLine(text[nameStart:nameEnd], nameWidth) + suffix | |
| @@ -224,7 +224,10 @@ func truncateRightBarPhaseLine(text string, width int) string { | |||||
| 224 | prefix := text[:nameStart] | 224 | prefix := text[:nameStart] | ||
| 225 | suffix := text[nameEnd:] | 225 | suffix := text[nameEnd:] | ||
| 226 | nameWidth := width - visibleWidth(prefix) - visibleWidth(suffix) | 226 | nameWidth := width - visibleWidth(prefix) - visibleWidth(suffix) | ||
| 227 | - | if nameWidth <= 0 { | 227 | + | if nameWidth == 0 { |
| 228 | + | return prefix + suffix | |||
| 229 | + | } | |||
| 230 | + | if nameWidth < 0 { | |||
| 228 | return truncateRightBarLine(text, width) | 231 | return truncateRightBarLine(text, width) | ||
| 229 | } | 232 | } | ||
| 230 | return prefix + truncateRightBarLine(text[nameStart:nameEnd], nameWidth) + suffix | 233 | return prefix + truncateRightBarLine(text[nameStart:nameEnd], nameWidth) + suffix | ||
M packages/tui/rightbar_test.go +8 -1
| @@ -106,6 +106,13 @@ func TestRenderRightBarPreservesPhaseProgressWhenTitleIsClipped(t *testing.T) { | |||
| 106 | 106 | } | |
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | + | func TestTruncateRightBarPhaseLinePreservesProgressWithoutRoomForName(t *testing.T) { | |
| 110 | + | got := truncateRightBarPhaseLine("[>] Current phase 0/1", 9) | |
| 111 | + | if want := "[>] 0/1"; got != want { | |
| 112 | + | t.Fatalf("truncated phase = %q, want %q", got, want) | |
| 113 | + | } | |
| 114 | + | } | |
| 115 | + | ||
| 109 | 116 | func TestRenderRightBarUsesChecklistIndentEllipsisAndBoldPhases(t *testing.T) { | |
| 110 | 117 | lines := RenderRightBar(Dark, []RightBarWidget{{ | |
| 111 | 118 | Extension: "tasked-phases", | |
| @@ -123,7 +130,7 @@ func TestRenderRightBarUsesChecklistIndentEllipsisAndBoldPhases(t *testing.T) { | |||
| 123 | 130 | if len(plainLines) < 4 { | |
| 124 | 131 | t.Fatalf("checklist rows are missing: %q", plain) | |
| 125 | 132 | } | |
| 126 | - | expectedTask := truncateRightBarLine(" [ ] Sort the leftover star stickers", 35) | |
| 133 | + | const expectedTask = " [ ] Sort the leftover star sti..." | |
| 127 | 134 | if got := strings.TrimRight(plainLines[3], " "); got != expectedTask { | |
| 128 | 135 | t.Fatalf("task row = %q, want clipped row %q", got, expectedTask) | |
| 129 | 136 | } | |
| @@ -106,6 +106,13 @@ func TestRenderRightBarPreservesPhaseProgressWhenTitleIsClipped(t *testing.T) { | |||||
| 106 | } | 106 | } | ||
| 107 | } | 107 | } | ||
| 108 | 108 | ||||
| 109 | + | func TestTruncateRightBarPhaseLinePreservesProgressWithoutRoomForName(t *testing.T) { | |||
| 110 | + | got := truncateRightBarPhaseLine("[>] Current phase 0/1", 9) | |||
| 111 | + | if want := "[>] 0/1"; got != want { | |||
| 112 | + | t.Fatalf("truncated phase = %q, want %q", got, want) | |||
| 113 | + | } | |||
| 114 | + | } | |||
| 115 | + | ||||
| 109 | func TestRenderRightBarUsesChecklistIndentEllipsisAndBoldPhases(t *testing.T) { | 116 | func TestRenderRightBarUsesChecklistIndentEllipsisAndBoldPhases(t *testing.T) { | ||
| 110 | lines := RenderRightBar(Dark, []RightBarWidget{{ | 117 | lines := RenderRightBar(Dark, []RightBarWidget{{ | ||
| 111 | Extension: "tasked-phases", | 118 | Extension: "tasked-phases", | ||
| @@ -123,7 +130,7 @@ func TestRenderRightBarUsesChecklistIndentEllipsisAndBoldPhases(t *testing.T) { | |||||
| 123 | if len(plainLines) < 4 { | 130 | if len(plainLines) < 4 { | ||
| 124 | t.Fatalf("checklist rows are missing: %q", plain) | 131 | t.Fatalf("checklist rows are missing: %q", plain) | ||
| 125 | } | 132 | } | ||
| 126 | - | expectedTask := truncateRightBarLine(" [ ] Sort the leftover star stickers", 35) | 133 | + | const expectedTask = " [ ] Sort the leftover star sti..." |
| 127 | if got := strings.TrimRight(plainLines[3], " "); got != expectedTask { | 134 | if got := strings.TrimRight(plainLines[3], " "); got != expectedTask { | ||
| 128 | t.Fatalf("task row = %q, want clipped row %q", got, expectedTask) | 135 | t.Fatalf("task row = %q, want clipped row %q", got, expectedTask) | ||
| 129 | } | 136 | } | ||