robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #41114 from epithet/default-ruler-as-expressiondab5fab948

master
39.2 KiB932 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local tt = require('test.functional.testterm')
6local describe, it, before_each = t.describe, t.it, t.before_each
7local feed_data = tt.feed_data
8local feed_csi = tt.feed_csi
9local feed, clear = n.feed, n.clear
10local poke_eventloop = n.poke_eventloop
11local exec_lua = n.exec_lua
12local command = n.command
13local retry = t.retry
14local eq = t.eq
15local eval = n.eval
16local skip = t.skip
17local is_os = t.is_os
18local testprg = n.testprg
19local api = n.api
20
21describe(':terminal window', function()
22  before_each(clear)
23
24  it('sets local values of window options #29325', function()
25    command('setglobal wrap list')
26    command('terminal')
27    eq({ 0, 0, 1 }, eval('[&l:wrap, &wrap, &g:wrap]'))
28    eq({ 0, 0, 1 }, eval('[&l:list, &list, &g:list]'))
29    command('enew')
30    eq({ 1, 1, 1 }, eval('[&l:wrap, &wrap, &g:wrap]'))
31    eq({ 1, 1, 1 }, eval('[&l:list, &list, &g:list]'))
32    command('buffer #')
33    eq({ 0, 0, 1 }, eval('[&l:wrap, &wrap, &g:wrap]'))
34    eq({ 0, 0, 1 }, eval('[&l:list, &list, &g:list]'))
35    command('new')
36    eq({ 1, 1, 1 }, eval('[&l:wrap, &wrap, &g:wrap]'))
37    eq({ 1, 1, 1 }, eval('[&l:list, &list, &g:list]'))
38  end)
39
40  it('keeps the cursor put on resize when the line above it is full width', function()
41    local screen = Screen.new(50, 7)
42    local buf = api.nvim_create_buf(true, true)
43    local chan = api.nvim_open_term(buf, {})
44    api.nvim_win_set_buf(0, buf)
45    feed('i')
46    api.nvim_chan_send(chan, 'l1\r\nl2\r\nl3\r\nl4\r\n' .. ('A'):rep(50) .. '\r\nX')
47    screen:expect([[
48      l1                                                |
49      l2                                                |
50      l3                                                |
51      l4                                                |
52      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|
53      X^                                                 |
54      {5:-- TERMINAL --}                                    |
55    ]])
56    screen:try_resize(50, 6)
57    screen:expect([[
58      l2                                                |
59      l3                                                |
60      l4                                                |
61      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|
62      X^                                                 |
63      {5:-- TERMINAL --}                                    |
64    ]])
65  end)
66
67  it('resets horizontal scroll on resize #35331', function()
68    skip(is_os('win'), 'Too flaky on Windows')
69    local screen = tt.setup_screen(0, { testprg('shell-test'), 'INTERACT' })
70    command('set statusline=%{win_getid()} splitright')
71    screen:expect([[
72      interact $ ^                                       |
73                                                        |*5
74      {5:-- TERMINAL --}                                    |
75    ]])
76    feed_data(('A'):rep(30))
77    screen:expect([[
78      interact $ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA^         |
79                                                        |*5
80      {5:-- TERMINAL --}                                    |
81    ]])
82    command('vnew | wincmd p')
83    screen:expect([[
84      interact $ AAAAAAAAAAAAA│                         |
85      AAAAAAAAAAAAAAAAA^       │{100:~                        }|
86                              │{100:~                        }|*3
87      {120:1000                     }{2:1001                     }|
88      {5:-- TERMINAL --}                                    |
89    ]])
90
91    feed([[<C-\><C-N><C-W>o]])
92    screen:expect([[
93      interact $ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA         |
94      ^                                                  |
95                                                        |*5
96    ]])
97    -- Window with less room scrolls anyway to keep its cursor in-view.
98    feed('gg$20<C-W>v')
99    screen:expect([[
100      interact $ AAAAAAAAAAAAAAAAAA│$ AAAAAAAAAAAAAAAAA^A|
101      AAAAAAAAAAAA                 │AAA                 |
102                                   │                    |*3
103      {119:1000                          }{120:1002                }|
104                                                        |
105    ]])
106  end)
107end)
108
109describe(':terminal window', function()
110  local screen
111
112  before_each(function()
113    clear()
114    screen = tt.setup_screen()
115  end)
116
117  it('sets topline correctly #8556', function()
118    skip(is_os('win'))
119    -- Test has hardcoded assumptions of dimensions.
120    eq(7, eval('&lines'))
121    feed_data('\n\n\n') -- Add blank lines.
122    -- Terminal/shell contents must exceed the height of this window.
123    command('topleft 1split')
124    eq('terminal', eval('&buftype'))
125    feed([[i<cr>]])
126    -- Check topline _while_ in terminal-mode.
127    retry(nil, nil, function()
128      eq(6, eval('winsaveview()["topline"]'))
129    end)
130  end)
131
132  describe("with 'number'", function()
133    it('wraps text', function()
134      feed([[<C-\><C-N>]])
135      feed([[:set numberwidth=1 number<CR>i]])
136      screen:expect([[
137        {121:1 }tty ready                                       |
138        {121:2 }rows: 6, cols: 48                               |
139        {121:3 }^                                                |
140        {121:4 }                                                |
141        {121:5 }                                                |
142        {121:6 }                                                |
143        {5:-- TERMINAL --}                                    |
144      ]])
145      feed_data('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
146      screen:expect([[
147        {121:1 }tty ready                                       |
148        {121:2 }rows: 6, cols: 48                               |
149        {121:3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV|
150        {121:4 }WXYZ^                                            |
151        {121:5 }                                                |
152        {121:6 }                                                |
153        {5:-- TERMINAL --}                                    |
154      ]])
155
156      -- numberwidth=9
157      feed([[<C-\><C-N>]])
158      feed([[:set numberwidth=9 number<CR>i]])
159      screen:expect([[
160        {121:       1 }tty ready                                |
161        {121:       2 }rows: 6, cols: 48                        |
162        {121:       3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
163        {121:       4 }PQRSTUVWXYZrows: 6, cols: 41             |
164        {121:       5 }^                                         |
165        {121:       6 }                                         |
166        {5:-- TERMINAL --}                                    |
167      ]])
168      feed_data(' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
169      screen:expect([[
170        {121:       1 }tty ready                                |
171        {121:       2 }rows: 6, cols: 48                        |
172        {121:       3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
173        {121:       4 }PQRSTUVWXYZrows: 6, cols: 41             |
174        {121:       5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN|
175        {121:       6 }OPQRSTUVWXYZ^                             |
176        {5:-- TERMINAL --}                                    |
177      ]])
178    end)
179  end)
180
181  describe("with 'statuscolumn'", function()
182    it('wraps text', function()
183      command([[set number statuscolumn=++%l\ \ ]])
184      screen:expect([[
185        {121:++1  }tty ready                                    |
186        {121:++2  }rows: 6, cols: 45                            |
187        {121:++3  }^                                             |
188        {121:++4  }                                             |
189        {121:++5  }                                             |
190        {121:++6  }                                             |
191        {5:-- TERMINAL --}                                    |
192      ]])
193      feed_data('\n\n\n\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
194      screen:expect([[
195        {121:++4  }                                             |
196        {121:++5  }                                             |
197        {121:++6  }                                             |
198        {121:++7  }                                             |
199        {121:++8  }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS|
200        {121:++9  }TUVWXYZ^                                      |
201        {5:-- TERMINAL --}                                    |
202      ]])
203      feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
204      screen:expect([[
205        {121:++{MATCH: [78]}  }                                            |
206        {121:++{MATCH: [89]}  }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
207        {121:++{MATCH:[ 1][09]}  }STUVWXYZ                                    |
208        {121:++{MATCH:1[01]}  }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
209        {121:++{MATCH:1[12]}  }STUVWXYZrows: 6, cols: 44                   |
210        {121:++{MATCH:1[23]}  }^                                            |
211        {5:-- TERMINAL --}                                    |
212      ]])
213    end)
214  end)
215
216  describe("with 'colorcolumn'", function()
217    before_each(function()
218      feed([[<C-\><C-N>]])
219      screen:expect([[
220        tty ready                                         |
221        ^                                                  |
222                                                          |*5
223      ]])
224      feed(':set colorcolumn=20<CR>i')
225    end)
226
227    it('wont show the color column', function()
228      screen:expect([[
229        tty ready                                         |
230        ^                                                  |
231                                                          |*4
232        {5:-- TERMINAL --}                                    |
233      ]])
234    end)
235  end)
236
237  describe('with fold set', function()
238    before_each(function()
239      feed([[<C-\><C-N>:set foldenable foldmethod=manual<CR>i]])
240      feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
241      screen:expect([[
242        tty ready                                         |
243        line1                                             |
244        line2                                             |
245        line3                                             |
246        line4                                             |
247        ^                                                  |
248        {5:-- TERMINAL --}                                    |
249      ]])
250    end)
251
252    it('wont show any folds', function()
253      feed([[<C-\><C-N>ggvGzf]])
254      poke_eventloop()
255      screen:expect([[
256        ^tty ready                                         |
257        line1                                             |
258        line2                                             |
259        line3                                             |
260        line4                                             |
261                                                          |*2
262      ]])
263    end)
264  end)
265
266  it('redrawn when restoring cursorline/column', function()
267    screen:set_default_attr_ids({
268      [1] = { bold = true },
269      [2] = { foreground = 130 },
270      [3] = { foreground = 130, underline = true },
271      [12] = { underline = true },
272      [19] = { background = 7 },
273    })
274
275    feed([[<C-\><C-N>]])
276    command('setlocal cursorline')
277    screen:expect([[
278      tty ready                                         |
279      {12:^                                                  }|
280                                                        |*5
281    ]])
282    feed('i')
283    screen:expect([[
284      tty ready                                         |
285      ^                                                  |
286                                                        |*4
287      {1:-- TERMINAL --}                                    |
288    ]])
289    feed([[<C-\><C-N>]])
290    screen:expect([[
291      tty ready                                         |
292      {12:^                                                  }|
293                                                        |*5
294    ]])
295
296    command('setlocal number')
297    screen:expect([[
298      {2:  1 }tty ready                                     |
299      {3:  2 }{12:^rows: 6, cols: 46                             }|
300      {2:  3 }                                              |
301      {2:  4 }                                              |
302      {2:  5 }                                              |
303      {2:  6 }                                              |
304                                                        |
305    ]])
306    feed('i')
307    screen:expect([[
308      {2:  1 }tty ready                                     |
309      {2:  2 }rows: 6, cols: 46                             |
310      {3:  3 }^                                              |
311      {2:  4 }                                              |
312      {2:  5 }                                              |
313      {2:  6 }                                              |
314      {1:-- TERMINAL --}                                    |
315    ]])
316    feed([[<C-\><C-N>]])
317    screen:expect([[
318      {2:  1 }tty ready                                     |
319      {2:  2 }rows: 6, cols: 46                             |
320      {3:  3 }{12:^                                              }|
321      {2:  4 }                                              |
322      {2:  5 }                                              |
323      {2:  6 }                                              |
324                                                        |
325    ]])
326
327    command('setlocal nonumber nocursorline cursorcolumn')
328    screen:expect([[
329      {19:t}ty ready                                         |
330      {19:r}ows: 6, cols: 46                                 |
331      ^rows: 6, cols: 50                                 |
332      {19: }                                                 |*3
333                                                        |
334    ]])
335    feed('i')
336    screen:expect([[
337      tty ready                                         |
338      rows: 6, cols: 46                                 |
339      rows: 6, cols: 50                                 |
340      ^                                                  |
341                                                        |*2
342      {1:-- TERMINAL --}                                    |
343    ]])
344    feed([[<C-\><C-N>]])
345    screen:expect([[
346      {19:t}ty ready                                         |
347      {19:r}ows: 6, cols: 46                                 |
348      {19:r}ows: 6, cols: 50                                 |
349      ^                                                  |
350      {19: }                                                 |*2
351                                                        |
352    ]])
353  end)
354
355  it('redraws cursor info in terminal mode', function()
356    command('file AMOGUS | set laststatus=2 ruler')
357    screen:expect([[
358      tty ready                                         |
359      rows: 5, cols: 50                                 |
360      ^                                                  |
361                                                        |*2
362      {120:AMOGUS [-]                      3,0-1          All}|
363      {5:-- TERMINAL --}                                    |
364    ]])
365    feed_data('you are the imposter')
366    screen:expect([[
367      tty ready                                         |
368      rows: 5, cols: 50                                 |
369      you are the imposter^                              |
370                                                        |*2
371      {120:AMOGUS [-]                      3,21           All}|
372      {5:-- TERMINAL --}                                    |
373    ]])
374    feed([[<C-\><C-N>]])
375    screen:expect([[
376      tty ready                                         |
377      rows: 5, cols: 50                                 |
378      you are the imposte^r                              |
379                                                        |*2
380      {120:AMOGUS [-]                      3,20           All}|
381                                                        |
382    ]])
383  end)
384
385  it('redraws stale statuslines and mode when not updating screen', function()
386    command('file foo | set ruler | vsplit')
387    screen:expect([[
388      tty ready                │tty ready               |
389      rows: 5, cols: 25        │rows: 5, cols: 25       |
390      ^                         │                        |
391                               │                        |*2
392      {120:<o [-] 3,0-1          All }{119:< [-] 2,0-1          All}|
393      {5:-- TERMINAL --}                                    |
394    ]])
395    command("call win_execute(win_getid(winnr('#')), 'call cursor(1, 1)')")
396    screen:expect([[
397      tty ready                │tty ready               |
398      rows: 5, cols: 25        │rows: 5, cols: 25       |
399      ^                         │                        |
400                               │                        |*2
401      {120:<o [-] 3,0-1          All }{119:< [-] 1,1            All}|
402      {5:-- TERMINAL --}                                    |
403    ]])
404    command('echo ""')
405    screen:expect_unchanged()
406  end)
407
408  it('has correct topline if scrolled by events', function()
409    local lines = {}
410    for i = 1, 10 do
411      table.insert(lines, 'cool line ' .. i)
412    end
413    feed_data(lines)
414    feed_csi('1;1H') -- Cursor to 1,1 (after any scrollback)
415
416    -- :sleep (with leeway) until the refresh_terminal uv timer event triggers before we move the
417    -- cursor. Check that the next terminal_check tails topline correctly.
418    command('set ruler | sleep 20m | call nvim_win_set_cursor(0, [1, 0])')
419    screen:expect([[
420      ^cool line 5                                       |
421      cool line 6                                       |
422      cool line 7                                       |
423      cool line 8                                       |
424      cool line 9                                       |
425      cool line 10                                      |
426      {5:-- TERMINAL --}                  6,1            Bot|
427    ]])
428    command('call nvim_win_set_cursor(0, [1, 0])')
429    screen:expect_unchanged()
430
431    feed_csi('2;5H') -- Cursor to 2,5 (after any scrollback)
432    screen:expect([[
433      cool line 5                                       |
434      cool^ line 6                                       |
435      cool line 7                                       |
436      cool line 8                                       |
437      cool line 9                                       |
438      cool line 10                                      |
439      {5:-- TERMINAL --}                  7,5            Bot|
440    ]])
441    -- Check topline correct after leaving terminal mode.
442    -- The new cursor position is one column left of the terminal's actual cursor position.
443    command('stopinsert | call nvim_win_set_cursor(0, [1, 0])')
444    screen:expect([[
445      cool line 5                                       |
446      coo^l line 6                                       |
447      cool line 7                                       |
448      cool line 8                                       |
449      cool line 9                                       |
450      cool line 10                                      |
451                                      7,4            Bot|
452    ]])
453  end)
454
455  it('updates terminal size', function()
456    skip(is_os('win'), "Windows doesn't show all lines?")
457    screen:set_default_attr_ids({
458      [1] = { reverse = true },
459      [2] = { background = 225, foreground = Screen.colors.Gray0 },
460      [3] = { bold = true },
461      [4] = { foreground = 12 },
462      [5] = { reverse = true, bold = true },
463      [17] = { background = 2, foreground = Screen.colors.Grey0 },
464      [18] = { background = 2, foreground = 8 },
465      [19] = { underline = true, foreground = Screen.colors.Grey0, background = 7 },
466      [20] = { underline = true, foreground = 5, background = 7 },
467    })
468
469    command('file foo | vsplit')
470    screen:expect([[
471      tty ready                │tty ready               |
472      rows: 5, cols: 25        │rows: 5, cols: 25       |
473      ^                         │                        |
474                               │                        |*2
475      {17:foo [-]                   }{18:foo [-]                 }|
476      {3:-- TERMINAL --}                                    |
477    ]])
478    command('tab split')
479    screen:expect([[
480      {19: }{20:2}{19: foo }{3: foo }{1:                                     }{19:X}|
481      tty ready                                         |
482      rows: 5, cols: 25                                 |
483      rows: 5, cols: 50                                 |
484      ^                                                  |
485                                                        |
486      {3:-- TERMINAL --}                                    |
487    ]])
488
489    command('quit | botright split')
490    -- NOTE: right window's cursor not on the last line, so it's not tailing.
491    screen:expect([[
492      rows: 5, cols: 50        │rows: 5, cols: 25       |
493      rows: 2, cols: 50        │rows: 5, cols: 50       |
494      {18:foo [-]                   foo [-]                 }|
495      rows: 2, cols: 50                                 |
496      ^                                                  |
497      {17:foo [-]                                           }|
498      {3:-- TERMINAL --}                                    |
499    ]])
500    command('quit')
501    screen:expect([[
502      rows: 5, cols: 25        │tty ready               |
503      rows: 5, cols: 50        │rows: 5, cols: 25       |
504      rows: 2, cols: 50        │rows: 5, cols: 50       |
505      rows: 5, cols: 25        │rows: 2, cols: 50       |
506      ^                         │rows: 5, cols: 25       |
507      {17:foo [-]                   }{18:foo [-]                 }|
508      {3:-- TERMINAL --}                                    |
509    ]])
510    command('call nvim_open_win(0, 0, #{relative: "editor", row: 0, col: 0, width: 40, height: 3})')
511    screen:expect([[
512      {2:rows: 5, cols: 25                       }          |
513      {2:rows: 5, cols: 40                       } 25       |
514      {2:                                        } 50       |
515      rows: 5, cols: 40        │rows: 2, cols: 50       |
516      ^                         │rows: 5, cols: 25       |
517      {17:foo [-]                   }{18:foo [-]                 }|
518      {3:-- TERMINAL --}                                    |
519    ]])
520    command('fclose!')
521    screen:expect([[
522      rows: 2, cols: 50        │tty ready               |
523      rows: 5, cols: 25        │rows: 5, cols: 25       |
524      rows: 5, cols: 40        │rows: 5, cols: 50       |
525      rows: 5, cols: 25        │rows: 2, cols: 50       |
526      ^                         │rows: 5, cols: 25       |
527      {17:foo [-]                   }{18:foo [-]                 }|
528      {3:-- TERMINAL --}                                    |
529    ]])
530    command('tab split')
531    screen:expect([[
532      {19: }{20:2}{19: foo }{3: foo }{1:                                     }{19:X}|
533      rows: 5, cols: 25                                 |
534      rows: 5, cols: 40                                 |
535      rows: 5, cols: 25                                 |
536      rows: 5, cols: 50                                 |
537      ^                                                  |
538      {3:-- TERMINAL --}                                    |
539    ]])
540    command('tabfirst | tabonly')
541    screen:expect([[
542      rows: 5, cols: 40        │tty ready               |
543      rows: 5, cols: 25        │rows: 5, cols: 25       |
544      rows: 5, cols: 50        │rows: 5, cols: 50       |
545      rows: 5, cols: 25        │rows: 2, cols: 50       |
546      ^                         │rows: 5, cols: 25       |
547      {17:foo [-]                   }{18:foo [-]                 }|
548      {3:-- TERMINAL --}                                    |
549    ]])
550
551    -- Sizing logic should only consider the final buffer shown in a window, even if autocommands
552    -- changed it at the last moment.
553    exec_lua(function()
554      vim.g.fired = 0
555      vim.api.nvim_create_autocmd('BufHidden', {
556        callback = function(ev)
557          vim.api.nvim_win_set_buf(vim.fn.win_findbuf(ev.buf)[1], vim.fn.bufnr('foo'))
558          vim.g.fired = vim.g.fired + 1
559          return vim.g.fired == 2
560        end,
561      })
562    end)
563    command('botright new')
564    screen:expect([[
565      rows: 2, cols: 25        │rows: 5, cols: 25       |
566                               │rows: 5, cols: 50       |
567      {18:foo [-]                   foo [-]                 }|
568      ^                                                  |
569      {4:~                                                 }|
570      {5:[No Name]                                         }|
571                                                        |
572    ]])
573    command('quit')
574    eq(1, eval('g:fired'))
575    screen:expect([[
576      rows: 5, cols: 50        │tty ready               |
577      rows: 5, cols: 25        │rows: 5, cols: 25       |
578      rows: 2, cols: 25        │rows: 5, cols: 50       |
579      rows: 5, cols: 25        │rows: 2, cols: 50       |
580      ^                         │rows: 5, cols: 25       |
581      {17:foo [-]                   }{18:foo [-]                 }|
582                                                        |
583    ]])
584    -- Check it doesn't use the size of the closed window in the other tab page; size should only
585    -- change via the :wincmd below. Hide tabline so it doesn't affect sizes.
586    command('set showtabline=0 | tabnew | tabprevious | wincmd > | tabonly')
587    eq(2, eval('g:fired'))
588    screen:expect([[
589      rows: 5, cols: 25         │tty ready              |
590      rows: 2, cols: 25         │rows: 5, cols: 25      |
591      rows: 5, cols: 25         │rows: 5, cols: 50      |
592      rows: 5, cols: 26         │rows: 2, cols: 50      |
593      ^                          │rows: 5, cols: 25      |
594      {17:foo [-]                    }{18:foo [-]                }|
595                                                        |
596    ]])
597    n.expect([[
598      tty ready
599      rows: 5, cols: 25
600      rows: 5, cols: 50
601      rows: 2, cols: 50
602      rows: 5, cols: 25
603      rows: 5, cols: 40
604      rows: 5, cols: 25
605      rows: 5, cols: 50
606      rows: 5, cols: 25
607      rows: 2, cols: 25
608      rows: 5, cols: 25
609      rows: 5, cols: 26
610      ]])
611  end)
612
613  it('restores window options when switching terminals', function()
614    -- Make this a screen test to also check for proper redrawing.
615    screen:set_default_attr_ids({
616      [1] = { bold = true },
617      [2] = { foreground = Screen.colors.Gray0, background = 7, underline = true },
618      [3] = { foreground = 5, background = 7, underline = true },
619      [4] = { reverse = true },
620      [5] = { bold = true, foreground = 5 },
621      [6] = { foreground = 12 },
622      [7] = { reverse = true, bold = true },
623      [12] = { underline = true },
624      [17] = { foreground = Screen.colors.Gray0, background = 2 },
625      [18] = { foreground = 8, background = 2 },
626      [19] = { background = 7 },
627    })
628
629    feed([[<C-\><C-N>]])
630    command([[
631      file foo
632      setlocal cursorline
633      vsplit
634      setlocal nocursorline cursorcolumn cursorlineopt=number
635    ]])
636    screen:expect([[
637      {19:t}ty ready                │tty ready               |
638      ^rows: 5, cols: 25        │{12:rows: 5, cols: 25       }|
639      {19: }                        │                        |*3
640      {17:foo [-]                   }{18:foo [-]                 }|
641                                                        |
642    ]])
643
644    feed('i')
645    screen:expect([[
646      tty ready                │tty ready               |
647      rows: 5, cols: 25        │{12:rows: 5, cols: 25       }|
648      ^                         │                        |
649                               │                        |*2
650      {17:foo [-]                   }{18:foo [-]                 }|
651      {1:-- TERMINAL --}                                    |
652    ]])
653    command('wincmd p')
654    screen:expect([[
655      {19:t}ty ready                │tty ready               |
656      {19:r}ows: 5, cols: 25        │rows: 5, cols: 25       |
657                               │^                        |
658      {19: }                        │                        |*2
659      {18:foo [-]                   }{17:foo [-]                 }|
660      {1:-- TERMINAL --}                                    |
661    ]])
662    feed([[<C-\><C-N>]])
663    screen:expect([[
664      {19:t}ty ready                │tty ready               |
665      {19:r}ows: 5, cols: 25        │rows: 5, cols: 25       |
666                               │{12:^                        }|
667      {19: }                        │                        |*2
668      {18:foo [-]                   }{17:foo [-]                 }|
669                                                        |
670    ]])
671
672    -- Ensure things work when switching tabpages.
673    command('tab split | setlocal cursorline cursorcolumn')
674    screen:expect([[
675      {2: }{3:2}{2: foo }{1: foo }{4:                                     }{2:X}|
676      {19:t}ty ready                                         |
677      {19:r}ows: 5, cols: 25                                 |
678      {12:^rows: 5, cols: 50                                 }|
679      {19: }                                                 |*2
680                                                        |
681    ]])
682    feed('i')
683    screen:expect([[
684      {2: }{3:2}{2: foo }{1: foo }{4:                                     }{2:X}|
685      tty ready                                         |
686      rows: 5, cols: 25                                 |
687      rows: 5, cols: 50                                 |
688      ^                                                  |
689                                                        |
690      {1:-- TERMINAL --}                                    |
691    ]])
692    command('tabprevious')
693    screen:expect([[
694      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
695      {19:r}ows: 5, cols: 25        │rows: 5, cols: 25       |
696      rows: 5, cols: 50        │rows: 5, cols: 50       |
697      {19: }                        │^                        |
698      {19: }                        │                        |
699      {18:foo [-]                   }{17:foo [-]                 }|
700      {1:-- TERMINAL --}                                    |
701    ]])
702    feed([[<C-\><C-N>]])
703    screen:expect([[
704      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
705      {19:r}ows: 5, cols: 25        │rows: 5, cols: 25       |
706      rows: 5, cols: 50        │rows: 5, cols: 50       |
707      {19: }                        │{12:^                        }|
708      {19: }                        │                        |
709      {18:foo [-]                   }{17:foo [-]                 }|
710                                                        |
711    ]])
712    command('tabnext')
713    screen:expect([[
714      {2: }{3:2}{2: foo }{1: foo }{4:                                     }{2:X}|
715      {19:t}ty ready                                         |
716      {19:r}ows: 5, cols: 25                                 |
717      {19:r}ows: 5, cols: 50                                 |
718      {12:^                                                  }|
719      {19: }                                                 |
720                                                        |
721    ]])
722
723    -- Closing windows shouldn't break things.
724    command('tabprevious')
725    feed('i')
726    screen:expect([[
727      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
728      {19:r}ows: 5, cols: 25        │rows: 5, cols: 25       |
729      rows: 5, cols: 50        │rows: 5, cols: 50       |
730      {19: }                        │^                        |
731      {19: }                        │                        |
732      {18:foo [-]                   }{17:foo [-]                 }|
733      {1:-- TERMINAL --}                                    |
734    ]])
735    command('quit')
736    screen:expect([[
737      {1: foo }{2: foo }{4:                                       }{2:X}|
738      tty ready                                         |
739      rows: 5, cols: 25                                 |
740      rows: 5, cols: 50                                 |
741      ^                                                  |
742                                                        |
743      {1:-- TERMINAL --}                                    |
744    ]])
745    feed([[<C-\><C-N>]])
746    screen:expect([[
747      {1: foo }{2: foo }{4:                                       }{2:X}|
748      {19:t}ty ready                                         |
749      {19:r}ows: 5, cols: 25                                 |
750      {19:r}ows: 5, cols: 50                                 |
751      ^                                                  |
752      {19: }                                                 |
753                                                        |
754    ]])
755
756    -- Switching to a non-terminal.
757    command('vnew')
758    feed([[<C-W>pi]])
759    screen:expect([[
760      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
761                               │rows: 5, cols: 25       |
762      {6:~                        }│rows: 5, cols: 50       |
763      {6:~                        }│^                        |
764      {6:~                        }│                        |
765      {4:[No Name]                 }{17:foo [-]                 }|
766      {1:-- TERMINAL --}                                    |
767    ]])
768    command('wincmd p')
769    screen:expect([[
770      {1: }{5:2}{1: [No Name] }{2: foo }{4:                               }{2:X}|
771      ^                         │{19:r}ows: 5, cols: 25       |
772      {6:~                        }│{19:r}ows: 5, cols: 50       |
773      {6:~                        }│                        |
774      {6:~                        }│{19: }                       |
775      {7:[No Name]                 }{18:foo [-]                 }|
776                                                        |
777    ]])
778
779    command('wincmd l | enew | setlocal cursorline nocursorcolumn')
780    screen:expect([[
781      {1: }{5:2}{1: [No Name] }{2: foo }{4:                               }{2:X}|
782                               │{12:^                        }|
783      {6:~                        }│{6:~                       }|*3
784      {4:[No Name]                 }{7:[No Name]               }|
785                                                        |
786    ]])
787    command('buffer # | startinsert')
788    screen:expect([[
789      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
790                               │rows: 5, cols: 25       |
791      {6:~                        }│rows: 5, cols: 50       |
792      {6:~                        }│^                        |
793      {6:~                        }│                        |
794      {4:[No Name]                 }{17:foo [-]                 }|
795      {1:-- TERMINAL --}                                    |
796    ]])
797    -- Switching to another buffer shouldn't change window options there. #37484
798    command('buffer # | call setline(1, ["aaa", "bbb", "ccc"]) | normal! jl')
799    screen:expect([[
800      {1: }{5:2}{1:+ [No Name] }{2: foo }{4:                              }{2:X}|
801                               │aaa                     |
802      {6:~                        }│{12:b^bb                     }|
803      {6:~                        }│ccc                     |
804      {6:~                        }│{6:~                       }|
805      {4:[No Name]                 }{7:[No Name] [+]           }|
806                                                        |
807    ]])
808    -- Window options are restored when switching back to the terminal buffer.
809    command('buffer #')
810    screen:expect([[
811      {1: }{5:2}{1: foo }{2: foo }{4:                                     }{2:X}|
812                               │{19:r}ows: 5, cols: 25       |
813      {6:~                        }│{19:r}ows: 5, cols: 50       |
814      {6:~                        }│^                        |
815      {6:~                        }│{19: }                       |
816      {4:[No Name]                 }{17:foo [-]                 }|
817                                                        |
818    ]])
819    -- 'cursorlineopt' should still be "number".
820    eq('number', eval('&l:cursorlineopt'))
821  end)
822
823  it('not unnecessarily redrawn by events', function()
824    eq('t', eval('mode()'))
825    exec_lua(function()
826      _G.redraws = {}
827      local ns = vim.api.nvim_create_namespace('test')
828      vim.api.nvim_set_decoration_provider(ns, {
829        on_start = function()
830          table.insert(_G.redraws, 'start')
831        end,
832        on_win = function(_, win)
833          table.insert(_G.redraws, 'win ' .. win)
834        end,
835        on_end = function()
836          table.insert(_G.redraws, 'end')
837        end,
838      })
839      -- Setting a decoration provider typically causes an initial redraw.
840      vim.cmd.redraw()
841      _G.redraws = {}
842    end)
843
844    -- The event we sent above to set up the test shouldn't have caused a redraw.
845    -- For good measure, also poke the event loop.
846    poke_eventloop()
847    eq({}, exec_lua('return _G.redraws'))
848
849    -- Redraws if we do something useful, of course.
850    feed_data('foo')
851    screen:expect { any = 'foo' }
852    eq({ 'start', 'win 1000', 'end' }, exec_lua('return _G.redraws'))
853  end)
854end)
855
856describe(':terminal with multigrid', function()
857  local screen
858
859  before_each(function()
860    clear()
861    screen = tt.setup_screen(0, nil, 50, nil, { ext_multigrid = true })
862  end)
863
864  it('resizes to requested size', function()
865    screen:expect([[
866    ## grid 1
867      [2:--------------------------------------------------]|*6
868      [3:--------------------------------------------------]|
869    ## grid 2
870      tty ready                                         |
871      ^                                                  |
872                                                        |*4
873    ## grid 3
874      {5:-- TERMINAL --}                                    |
875    ]])
876
877    screen:try_resize_grid(2, 20, 10)
878    if is_os('win') then
879      screen:expect { any = 'rows: 10, cols: 20' }
880    else
881      screen:expect([[
882      ## grid 1
883        [2:--------------------------------------------------]|*6
884        [3:--------------------------------------------------]|
885      ## grid 2
886        tty ready           |
887        rows: 10, cols: 20  |
888        ^                    |
889                            |*7
890      ## grid 3
891        {5:-- TERMINAL --}                                    |
892      ]])
893    end
894
895    screen:try_resize_grid(2, 70, 3)
896    if is_os('win') then
897      screen:expect { any = 'rows: 3, cols: 70' }
898    else
899      screen:expect([[
900      ## grid 1
901        [2:--------------------------------------------------]|*6
902        [3:--------------------------------------------------]|
903      ## grid 2
904        rows: 10, cols: 20                                                    |
905        rows: 3, cols: 70                                                     |
906        ^                                                                      |
907      ## grid 3
908        {5:-- TERMINAL --}                                    |
909      ]])
910    end
911
912    screen:try_resize_grid(2, 0, 0)
913    if is_os('win') then
914      screen:expect { any = 'rows: 6, cols: 50' }
915    else
916      screen:expect([[
917      ## grid 1
918        [2:--------------------------------------------------]|*6
919        [3:--------------------------------------------------]|
920      ## grid 2
921        tty ready                                         |
922        rows: 10, cols: 20                                |
923        rows: 3, cols: 70                                 |
924        rows: 6, cols: 50                                 |
925        ^                                                  |
926                                                          |
927      ## grid 3
928        {5:-- TERMINAL --}                                    |
929      ]])
930    end
931  end)
932end)