File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package components
22
33import (
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 := "> "
Original file line number Diff line number Diff 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+
87109func TestErrorDisplay_MinimalEvent (t * testing.T ) {
88110 t .Parallel ()
89111
You can’t perform that action at this time.
0 commit comments