Skip to content

Commit 2c3ad73

Browse files
committed
Wrap error title to terminal width
1 parent 8bac894 commit 2c3ad73

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

internal/ui/components/error_display.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package components
22

33
import (
44
"strings"
5+
"unicode/utf8"
56

67
"github.com/localstack/lstk/internal/output"
78
"github.com/localstack/lstk/internal/ui/styles"
@@ -34,8 +35,19 @@ func (e ErrorDisplay) View(maxWidth int) string {
3435

3536
var sb strings.Builder
3637

37-
sb.WriteString(styles.ErrorTitle.Render("✗ " + e.event.Title))
38-
sb.WriteString("\n")
38+
titlePrefix := "✗ "
39+
prefixWidth := utf8.RuneCountInString(titlePrefix)
40+
titleWidth := maxWidth - prefixWidth
41+
titleLines := wrap.SoftWrap(e.event.Title, titleWidth)
42+
for i, line := range titleLines {
43+
if i == 0 {
44+
sb.WriteString(styles.ErrorTitle.Render(titlePrefix + line))
45+
} else {
46+
sb.WriteString(strings.Repeat(" ", prefixWidth))
47+
sb.WriteString(styles.ErrorTitle.Render(line))
48+
}
49+
sb.WriteString("\n")
50+
}
3951

4052
if e.event.Summary != "" {
4153
prefix := "> "

internal/ui/components/error_display_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ func TestErrorDisplay_MultiActionRenders(t *testing.T) {
8484
}
8585
}
8686

87+
func TestErrorDisplay_TitleWrapsToWidth(t *testing.T) {
88+
t.Parallel()
89+
90+
e := NewErrorDisplay()
91+
longTitle := "license validation failed for localstack-pro:4.14.1.dev206: license validation failed: your token is invalid"
92+
e = e.Show(output.ErrorEvent{Title: longTitle})
93+
94+
view := e.View(50)
95+
lines := strings.Split(view, "\n")
96+
// The title should be wrapped across multiple lines, not truncated
97+
fullText := strings.Join(lines, " ")
98+
if !strings.Contains(fullText, "invalid") {
99+
t.Fatalf("expected wrapped title to contain full text, got: %q", view)
100+
}
101+
// Each line should not exceed the width
102+
for _, line := range lines {
103+
if len([]rune(line)) > 50 {
104+
t.Errorf("line exceeds max width: %q (%d runes)", line, len([]rune(line)))
105+
}
106+
}
107+
}
108+
87109
func TestErrorDisplay_MinimalEvent(t *testing.T) {
88110
t.Parallel()
89111

0 commit comments

Comments
 (0)