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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
local feed, nvim_dir, execute = helpers.feed, helpers.nvim_dir, helpers.execute
local wait = helpers.wait
local feed_data = thelpers.feed_data
if helpers.pending_win32(pending) then return end
describe('terminal scrollback', function()
local screen
before_each(function()
clear()
screen = thelpers.screen_setup()
end)
after_each(function()
screen:detach()
end)
describe('when the limit is crossed', function()
before_each(function()
local lines = {}
for i = 1, 30 do
table.insert(lines, 'line'..tostring(i))
end
table.insert(lines, '')
feed_data(lines)
screen:expect([[
line26 |
line27 |
line28 |
line29 |
line30 |
{1: } |
{3:-- TERMINAL --} |
]])
end)
it('will delete extra lines at the top', function()
feed('<c-\\><c-n>gg')
screen:expect([[
^line16 |
line17 |
line18 |
line19 |
line20 |
line21 |
|
]])
end)
end)
describe('with the cursor at the last row', function()
before_each(function()
feed_data({'line1', 'line2', 'line3', 'line4', ''})
screen:expect([[
tty ready |
line1 |
line2 |
line3 |
line4 |
{1: } |
{3:-- TERMINAL --} |
]])
end)
describe('and 1 line is printed', function()
before_each(function() feed_data({'line5', ''}) end)
it('will hide the top line', function()
screen:expect([[
line1 |
line2 |
line3 |
line4 |
line5 |
{1: } |
{3:-- TERMINAL --} |
]])
eq(7, curbuf('line_count'))
end)
describe('and then 3 more lines are printed', function()
before_each(function() feed_data({'line6', 'line7', 'line8'}) end)
it('will hide the top 4 lines', function()
screen:expect([[
line3 |
line4 |
line5 |
line6 |
line7 |
line8{1: } |
{3:-- TERMINAL --} |
]])
feed('<c-\\><c-n>6k')
screen:expect([[
^line2 |
line3 |
line4 |
line5 |
line6 |
line7 |
|
]])
feed('gg')
screen:expect([[
^tty ready |
line1 |
line2 |
line3 |
line4 |
line5 |
|
]])
feed('G')
screen:expect([[
line3 |
line4 |
line5 |
line6 |
line7 |
^line8{2: } |
|
]])
end)
end)
end)
describe('and the height is decreased by 1', function()
local function will_hide_top_line()
screen:try_resize(screen._width, screen._height - 1)
screen:expect([[
line2 |
line3 |
line4 |
rows: 5, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
end
it('will hide top line', will_hide_top_line)
describe('and then decreased by 2', function()
before_each(function()
will_hide_top_line()
screen:try_resize(screen._width, screen._height - 2)
end)
it('will hide the top 3 lines', function()
screen:expect([[
rows: 5, cols: 50 |
rows: 3, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
eq(8, curbuf('line_count'))
feed('<c-\\><c-n>3k')
screen:expect([[
^line4 |
rows: 5, cols: 50 |
rows: 3, cols: 50 |
|
]])
end)
end)
end)
end)
describe('with empty lines after the cursor', function()
describe('and the height is decreased by 2', function()
before_each(function()
screen:try_resize(screen._width, screen._height - 2)
end)
local function will_delete_last_two_lines()
screen:expect([[
tty ready |
rows: 4, cols: 50 |
{1: } |
|
{3:-- TERMINAL --} |
]])
eq(4, curbuf('line_count'))
end
it('will delete the last two empty lines', will_delete_last_two_lines)
describe('and then decreased by 1', function()
before_each(function()
will_delete_last_two_lines()
screen:try_resize(screen._width, screen._height - 1)
end)
it('will delete the last line and hide the first', function()
screen:expect([[
rows: 4, cols: 50 |
rows: 3, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
eq(4, curbuf('line_count'))
feed('<c-\\><c-n>gg')
screen:expect([[
^tty ready |
rows: 4, cols: 50 |
rows: 3, cols: 50 |
|
]])
feed('a')
screen:expect([[
rows: 4, cols: 50 |
rows: 3, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
end)
end)
end)
end)
describe('with 4 lines hidden in the scrollback', function()
before_each(function()
feed_data({'line1', 'line2', 'line3', 'line4', ''})
screen:expect([[
tty ready |
line1 |
line2 |
line3 |
line4 |
{1: } |
{3:-- TERMINAL --} |
]])
screen:try_resize(screen._width, screen._height - 3)
screen:expect([[
line4 |
rows: 3, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
eq(7, curbuf('line_count'))
end)
describe('and the height is increased by 1', function()
local function pop_then_push()
screen:try_resize(screen._width, screen._height + 1)
screen:expect([[
line4 |
rows: 3, cols: 50 |
rows: 4, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
end
it('will pop 1 line and then push it back', pop_then_push)
describe('and then by 3', function()
before_each(function()
pop_then_push()
eq(8, curbuf('line_count'))
screen:try_resize(screen._width, screen._height + 3)
end)
local function pop3_then_push1()
screen:expect([[
line2 |
line3 |
line4 |
rows: 3, cols: 50 |
rows: 4, cols: 50 |
rows: 7, cols: 50 |
{1: } |
{3:-- TERMINAL --} |
]])
eq(9, curbuf('line_count'))
feed('<c-\\><c-n>gg')
screen:expect([[
^tty ready |
line1 |
line2 |
line3 |
line4 |
rows: 3, cols: 50 |
rows: 4, cols: 50 |
|
]])
end
it('will pop 3 lines and then push one back', pop3_then_push1)
describe('and then by 4', function()
before_each(function()
pop3_then_push1()
feed('Gi')
screen:try_resize(screen._width, screen._height + 4)
end)
it('will show all lines and leave a blank one at the end', function()
screen:expect([[
tty ready |
line1 |
line2 |
line3 |
line4 |
rows: 3, cols: 50 |
rows: 4, cols: 50 |
rows: 7, cols: 50 |
rows: 11, cols: 50 |
{1: } |
|
{3:-- TERMINAL --} |
]])
-- since there's an empty line after the cursor, the buffer line
-- count equals the terminal screen height
eq(11, curbuf('line_count'))
end)
end)
end)
end)
end)
end)
describe('terminal prints more lines than the screen height and exits', function()
it('will push extra lines to scrollback', function()
clear()
local screen = Screen.new(50, 7)
screen:attach({rgb=false})
execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
wait()
screen:expect([[
line6 |
line7 |
line8 |
line9 |
|
[Process exited 0] |
-- TERMINAL -- |
]])
feed('<cr>')
-- closes the buffer correctly after pressing a key
screen:expect([[
^ |
~ |
~ |
~ |
~ |
~ |
|
]])
end)
end)
|