1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
package tui
import (
"strings"
"testing"
)
func newInlineResizeTestApp(width, termHeight, inlineHeight int) (*App, *MockTerminal) {
term := NewMockTerminal(width, termHeight)
app := &App{
terminal: term,
inlineHeight: inlineHeight,
inlineStartRow: termHeight - inlineHeight,
inlineLayout: newInlineLayoutState(termHeight - inlineHeight),
buffer: NewBuffer(width, inlineHeight),
focus: newFocusManager(),
mounts: newMountState(),
}
return app, term
}
func rowText(term *MockTerminal, row int) string {
lines := strings.Split(term.String(), "\n")
if row < 0 || row >= len(lines) {
return ""
}
return strings.TrimRight(lines[row], " ")
}
func TestInlineResize_TerminalGrowth_ClearsOldWidgetRows(t *testing.T) {
app, term := newInlineResizeTestApp(80, 30, 6)
app.root = New(WithText("COMPOSER"))
app.needsFullRedraw = true
app.renderFrame()
if got := rowText(term, 24); got != "COMPOSER" {
t.Fatalf("precondition: row 24 = %q, want %q", got, "COMPOSER")
}
term.Resize(80, 40)
app.Dispatch(ResizeEvent{Width: 80, Height: 40})
app.renderFrame()
if got := rowText(term, 34); got != "COMPOSER" {
t.Fatalf("row 34 = %q, want %q", got, "COMPOSER")
}
for row := 24; row < 34; row++ {
if got := rowText(term, row); got != "" {
t.Fatalf("ghost row %d = %q, want blank", row, got)
}
}
}
func TestInlineResize_TerminalGrowth_RepeatedSteps(t *testing.T) {
app, term := newInlineResizeTestApp(80, 30, 6)
app.root = New(WithText("COMPOSER"))
app.needsFullRedraw = true
app.renderFrame()
term.Resize(80, 34)
app.Dispatch(ResizeEvent{Width: 80, Height: 34})
term.Resize(80, 42)
app.Dispatch(ResizeEvent{Width: 80, Height: 42})
app.renderFrame()
if got := rowText(term, 36); got != "COMPOSER" {
t.Fatalf("row 36 = %q, want %q", got, "COMPOSER")
}
for row := 24; row < 36; row++ {
if got := rowText(term, row); got != "" {
t.Fatalf("ghost row %d = %q, want blank", row, got)
}
}
}
func TestInlineResize_ShrinkBelowHeight_ClampsStartRow(t *testing.T) {
app, term := newInlineResizeTestApp(80, 8, 6)
app.root = New(WithText("COMPOSER"))
app.needsFullRedraw = true
app.renderFrame()
term.Resize(80, 4)
app.Dispatch(ResizeEvent{Width: 80, Height: 4})
if app.inlineStartRow != 0 {
t.Fatalf("inlineStartRow = %d, want 0 (clamped)", app.inlineStartRow)
}
app.renderFrame()
if _, cy := term.Cursor(); cy != 0 {
t.Fatalf("clear start row = %d, want 0", cy)
}
}
func TestExitAlternateScreen_TerminalShorterThanInlineHeight_ClampsStartRow(t *testing.T) {
app, term := newInlineResizeTestApp(80, 30, 6)
if err := app.EnterAlternateScreen(); err != nil {
t.Fatal(err)
}
term.Resize(80, 4)
app.Dispatch(ResizeEvent{Width: 80, Height: 4})
if err := app.ExitAlternateScreen(); err != nil {
t.Fatal(err)
}
if app.inlineStartRow != 0 {
t.Fatalf("inlineStartRow = %d, want 0 (clamped)", app.inlineStartRow)
}
}
func TestInlineResize_ShrinkBelowHeightThenGrow_ClampsClearRow(t *testing.T) {
app, term := newInlineResizeTestApp(80, 8, 6)
app.root = New(WithText("COMPOSER"))
app.needsFullRedraw = true
app.renderFrame()
term.Resize(80, 4)
app.Dispatch(ResizeEvent{Width: 80, Height: 4})
term.Resize(80, 8)
app.Dispatch(ResizeEvent{Width: 80, Height: 8})
app.renderFrame()
if _, cy := term.Cursor(); cy != 0 {
t.Fatalf("clear start row = %d, want 0 (clamped)", cy)
}
}
func TestInlineResize_TerminalShrink_UnchangedBehavior(t *testing.T) {
app, term := newInlineResizeTestApp(80, 40, 6)
app.root = New(WithText("COMPOSER"))
app.needsFullRedraw = true
app.renderFrame()
if got := rowText(term, 34); got != "COMPOSER" {
t.Fatalf("precondition: row 34 = %q, want %q", got, "COMPOSER")
}
term.SetCell(0, 23, NewCell('H', NewStyle()))
term.Resize(80, 30)
app.Dispatch(ResizeEvent{Width: 80, Height: 30})
app.renderFrame()
if got := rowText(term, 24); got != "COMPOSER" {
t.Fatalf("row 24 = %q, want %q", got, "COMPOSER")
}
if got := rowText(term, 23); got != "H" {
t.Fatalf("history row 23 = %q, want %q (must not be cleared)", got, "H")
}
}
|