robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
65.6 KiB1600 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local tt = require('test.functional.testterm')
4local Screen = require('test.functional.ui.screen')
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local assert_alive = n.assert_alive
8local clear = n.clear
9local command = n.command
10local feed = n.feed
11local eq = t.eq
12local fn = n.fn
13local api = n.api
14local exec = n.exec
15local exec_lua = n.exec_lua
16local eval = n.eval
17local sleep = vim.uv.sleep
18local pcall_err = t.pcall_err
19local testprg = n.testprg
20local expect_exitcode = tt.expect_exitcode
21
22local mousemodels = { 'extend', 'popup', 'popup_setpos' }
23
24for _, model in ipairs(mousemodels) do
25  describe('statusline clicks with mousemodel=' .. model, function()
26    local screen
27
28    before_each(function()
29      clear()
30      screen = Screen.new(40, 8)
31      screen:add_extra_attr_ids {
32        [100] = { bold = true, reverse = true, foreground = Screen.colors.Blue },
33      }
34      command('set laststatus=2 mousemodel=' .. model)
35      exec([=[
36        function! MyClickFunc(minwid, clicks, button, mods)
37          let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
38          if a:mods !=# '    '
39            let g:testvar ..= '(' .. a:mods .. ')'
40          endif
41        endfunction
42        let g:testvar = ''
43      ]=])
44    end)
45
46    it('works', function()
47      api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
48      api.nvim_input_mouse('left', 'press', '', 0, 6, 16)
49      eq('', eval('g:testvar'))
50      api.nvim_input_mouse('right', 'press', '', 0, 6, 29)
51      eq('', eval('g:testvar'))
52      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
53      eq('0 1 l', eval('g:testvar'))
54      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
55      eq('0 2 l', eval('g:testvar'))
56      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
57      eq('0 3 l', eval('g:testvar'))
58      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
59      eq('0 4 l', eval('g:testvar'))
60      api.nvim_input_mouse('right', 'press', '', 0, 6, 28)
61      eq('0 1 r', eval('g:testvar'))
62      api.nvim_input_mouse('right', 'press', '', 0, 6, 28)
63      eq('0 2 r', eval('g:testvar'))
64      api.nvim_input_mouse('right', 'press', '', 0, 6, 28)
65      eq('0 3 r', eval('g:testvar'))
66      api.nvim_input_mouse('right', 'press', '', 0, 6, 28)
67      eq('0 4 r', eval('g:testvar'))
68      api.nvim_input_mouse('x1', 'press', '', 0, 6, 17)
69      eq('0 1 x1', eval('g:testvar'))
70      api.nvim_input_mouse('x1', 'press', '', 0, 6, 17)
71      eq('0 2 x1', eval('g:testvar'))
72      api.nvim_input_mouse('x1', 'press', '', 0, 6, 17)
73      eq('0 3 x1', eval('g:testvar'))
74      api.nvim_input_mouse('x1', 'press', '', 0, 6, 17)
75      eq('0 4 x1', eval('g:testvar'))
76      api.nvim_input_mouse('x2', 'press', '', 0, 6, 28)
77      eq('0 1 x2', eval('g:testvar'))
78      api.nvim_input_mouse('x2', 'press', '', 0, 6, 28)
79      eq('0 2 x2', eval('g:testvar'))
80      api.nvim_input_mouse('x2', 'press', '', 0, 6, 28)
81      eq('0 3 x2', eval('g:testvar'))
82      api.nvim_input_mouse('x2', 'press', '', 0, 6, 28)
83      eq('0 4 x2', eval('g:testvar'))
84    end)
85
86    it('works with control characters and highlight', function()
87      api.nvim_set_option_value('statusline', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {})
88      screen:expect {
89        grid = [[
90        ^                                        |
91        {1:~                                       }|*5
92        {3:^I}{100:^A^I^A^I}{3:^A                            }|
93                                                |
94      ]],
95      }
96      api.nvim_input_mouse('right', 'press', '', 0, 6, 3)
97      eq('', eval('g:testvar'))
98      api.nvim_input_mouse('left', 'press', '', 0, 6, 8)
99      eq('', eval('g:testvar'))
100      api.nvim_input_mouse('right', 'press', '', 0, 6, 4)
101      eq('0 1 r', eval('g:testvar'))
102      api.nvim_input_mouse('left', 'press', '', 0, 6, 7)
103      eq('0 1 l', eval('g:testvar'))
104    end)
105
106    it('works with combined highlight attributes', function()
107      screen:add_extra_attr_ids({
108        [131] = { reverse = true, bold = true, background = Screen.colors.LightMagenta },
109        [132] = {
110          reverse = true,
111          foreground = Screen.colors.Magenta,
112          bold = true,
113          background = Screen.colors.LightMagenta,
114        },
115        [133] = { reverse = true, bold = true, foreground = Screen.colors.Magenta1 },
116        [134] = {
117          bold = true,
118          background = Screen.colors.LightMagenta,
119          reverse = true,
120          undercurl = true,
121          special = Screen.colors.Red,
122        },
123        [135] = {
124          bold = true,
125          background = Screen.colors.LightMagenta,
126          reverse = true,
127          undercurl = true,
128          foreground = Screen.colors.Fuchsia,
129          special = Screen.colors.Red,
130        },
131      })
132
133      api.nvim_set_option_value(
134        'statusline',
135        '\t%#Pmenu#foo%$SpellBad$bar%$String$baz%#Constant#qux',
136        {}
137      )
138
139      screen:expect([[
140        ^                                        |
141        {1:~                                       }|*5
142        {3:^I}{131:foo}{134:bar}{135:baz}{133:qux                          }|
143                                                |
144      ]])
145    end)
146
147    it('works for winbar', function()
148      api.nvim_set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
149      api.nvim_input_mouse('left', 'press', '', 0, 0, 17)
150      eq('0 1 l', eval('g:testvar'))
151      api.nvim_input_mouse('right', 'press', '', 0, 0, 17)
152      eq('0 1 r', eval('g:testvar'))
153    end)
154
155    it('works for winbar in floating window', function()
156      api.nvim_open_win(
157        0,
158        true,
159        { width = 30, height = 4, relative = 'editor', row = 1, col = 5, border = 'single' }
160      )
161      api.nvim_set_option_value(
162        'winbar',
163        'Not clicky stuff %0@MyClickFunc@Clicky stuff%T',
164        { scope = 'local' }
165      )
166      api.nvim_input_mouse('left', 'press', '', 0, 2, 23)
167      eq('0 1 l', eval('g:testvar'))
168    end)
169
170    it('works when there are multiple windows', function()
171      command('split')
172      api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
173      api.nvim_set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
174      api.nvim_input_mouse('left', 'press', '', 0, 0, 17)
175      eq('0 1 l', eval('g:testvar'))
176      api.nvim_input_mouse('right', 'press', '', 0, 4, 17)
177      eq('0 1 r', eval('g:testvar'))
178      api.nvim_input_mouse('middle', 'press', '', 0, 3, 17)
179      eq('0 1 m', eval('g:testvar'))
180      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
181      eq('0 1 l', eval('g:testvar'))
182    end)
183
184    it('works with Lua function', function()
185      exec_lua([[
186      function clicky_func(minwid, clicks, button, mods)
187        vim.g.testvar = string.format("%d %d %s", minwid, clicks, button)
188      end
189      ]])
190      api.nvim_set_option_value(
191        'statusline',
192        'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T',
193        {}
194      )
195      api.nvim_input_mouse('left', 'press', '', 0, 6, 17)
196      eq('0 1 l', eval('g:testvar'))
197    end)
198
199    it('ignores unsupported click items', function()
200      command('tabnew | tabprevious')
201      api.nvim_set_option_value('statusline', '%2TNot clicky stuff%T', {})
202      api.nvim_input_mouse('left', 'press', '', 0, 6, 0)
203      eq(1, api.nvim_get_current_tabpage())
204      api.nvim_set_option_value('statusline', '%2XNot clicky stuff%X', {})
205      api.nvim_input_mouse('left', 'press', '', 0, 6, 0)
206      eq(2, #api.nvim_list_tabpages())
207    end)
208
209    it("right click works when statusline isn't focused #18994", function()
210      api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
211      api.nvim_input_mouse('right', 'press', '', 0, 6, 17)
212      eq('0 1 r', eval('g:testvar'))
213      api.nvim_input_mouse('right', 'press', '', 0, 6, 17)
214      eq('0 2 r', eval('g:testvar'))
215    end)
216
217    it('works with modifiers #18994', function()
218      api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
219      -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
220      api.nvim_input_mouse('left', 'press', 'S', 0, 6, 17)
221      eq('0 1 l(s   )', eval('g:testvar'))
222      api.nvim_input_mouse('right', 'press', 'S', 0, 6, 17)
223      eq('0 1 r(s   )', eval('g:testvar'))
224      api.nvim_input_mouse('left', 'press', 'A', 0, 6, 17)
225      eq('0 1 l(  a )', eval('g:testvar'))
226      api.nvim_input_mouse('right', 'press', 'A', 0, 6, 17)
227      eq('0 1 r(  a )', eval('g:testvar'))
228      api.nvim_input_mouse('left', 'press', 'AS', 0, 6, 17)
229      eq('0 1 l(s a )', eval('g:testvar'))
230      api.nvim_input_mouse('right', 'press', 'AS', 0, 6, 17)
231      eq('0 1 r(s a )', eval('g:testvar'))
232      api.nvim_input_mouse('left', 'press', 'T', 0, 6, 17)
233      eq('0 1 l(   m)', eval('g:testvar'))
234      api.nvim_input_mouse('right', 'press', 'T', 0, 6, 17)
235      eq('0 1 r(   m)', eval('g:testvar'))
236      api.nvim_input_mouse('left', 'press', 'TS', 0, 6, 17)
237      eq('0 1 l(s  m)', eval('g:testvar'))
238      api.nvim_input_mouse('right', 'press', 'TS', 0, 6, 17)
239      eq('0 1 r(s  m)', eval('g:testvar'))
240      api.nvim_input_mouse('left', 'press', 'C', 0, 6, 17)
241      eq('0 1 l( c  )', eval('g:testvar'))
242      -- <C-RightMouse> is for tag jump
243    end)
244
245    it('works for global statusline with vertical splits #19186', function()
246      command('set laststatus=3')
247      api.nvim_set_option_value(
248        'statusline',
249        '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T',
250        {}
251      )
252      command('vsplit')
253      screen:expect {
254        grid = [[
255        ^                    │                   |
256        {1:~                   }│{1:~                  }|*5
257        {3:Clicky stuff                Clicky stuff}|
258                                                |
259      ]],
260      }
261
262      -- clickable area on the right
263      api.nvim_input_mouse('left', 'press', '', 0, 6, 35)
264      eq('0 1 l', eval('g:testvar'))
265      api.nvim_input_mouse('right', 'press', '', 0, 6, 35)
266      eq('0 1 r', eval('g:testvar'))
267
268      -- clickable area on the left
269      api.nvim_input_mouse('left', 'press', '', 0, 6, 5)
270      eq('0 1 l', eval('g:testvar'))
271      api.nvim_input_mouse('right', 'press', '', 0, 6, 5)
272      eq('0 1 r', eval('g:testvar'))
273    end)
274
275    it('no memory leak with zero-width click labels', function()
276      command([[
277      let &stl = '%@Test@%T%@MyClickFunc@%=%T%@Test@'
278      ]])
279      api.nvim_input_mouse('left', 'press', '', 0, 6, 0)
280      eq('0 1 l', eval('g:testvar'))
281      api.nvim_input_mouse('right', 'press', '', 0, 6, 39)
282      eq('0 1 r', eval('g:testvar'))
283    end)
284
285    it('no memory leak with truncated click labels', function()
286      command([[
287      let &stl = '%@MyClickFunc@foo%X' .. repeat('a', 40) .. '%<t%@Test@bar%X%@Test@baz'
288      ]])
289      api.nvim_input_mouse('left', 'press', '', 0, 6, 2)
290      eq('0 1 l', eval('g:testvar'))
291    end)
292  end)
293end
294
295describe('global statusline', function()
296  local screen
297
298  before_each(function()
299    clear()
300    screen = Screen.new(60, 16)
301    screen:add_extra_attr_ids {
302      [100] = { foreground = Screen.colors.Magenta1, bold = true },
303    }
304    command('set laststatus=3')
305    command('set ruler')
306  end)
307
308  it('works', function()
309    screen:expect([[
310      ^                                                            |
311      {1:~                                                           }|*13
312      {3:[No Name]                                 0,0-1          All}|
313                                                                  |
314    ]])
315
316    feed('i<CR><CR>')
317    screen:expect([[
318                                                                  |*2
319      ^                                                            |
320      {1:~                                                           }|*11
321      {3:[No Name] [+]                             3,1            All}|
322      {5:-- INSERT --}                                                |
323    ]])
324  end)
325
326  it('works with splits', function()
327    command('vsplit | split | vsplit | vsplit | wincmd l | split | 2wincmd l | split')
328    screen:expect([[
329                          │                │ │^                    |
330      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|*3
331      {1:~                   }├────────────────┤{1:~}│{1:~                   }|
332      {1:~                   }│                │{1:~}│{1:~                   }|
333      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|
334      {1:~                   }│{1:~               }│{1:~}├────────────────────|
335      {1:~                   }│{1:~               }│{1:~}│                    |
336      ────────────────────┴────────────────┴─┤{1:~                   }|
337                                             │{1:~                   }|
338      {1:~                                      }│{1:~                   }|*3
339      {3:[No Name]                                 0,0-1          All}|
340                                                                  |
341    ]])
342  end)
343
344  it('works when switching between values of laststatus', function()
345    command('set laststatus=1')
346    screen:expect([[
347      ^                                                            |
348      {1:~                                                           }|*14
349                                                0,0-1          All|
350    ]])
351
352    command('set laststatus=3')
353    screen:expect([[
354      ^                                                            |
355      {1:~                                                           }|*13
356      {3:[No Name]                                 0,0-1          All}|
357                                                                  |
358    ]])
359
360    command('vsplit | split | vsplit | vsplit | wincmd l | split | 2wincmd l | split')
361    command('set laststatus=2')
362    screen:expect([[
363                          │                │ │^                    |
364      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|*3
365      {1:~                   }│{2:<-1          All}│{1:~}│{1:~                   }|
366      {1:~                   }│                │{1:~}│{1:~                   }|
367      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|
368      {1:~                   }│{1:~               }│{1:~}│{3:< 0,0-1          All}|
369      {1:~                   }│{1:~               }│{1:~}│                    |
370      {2:< 0,0-1          All <-1          All <}│{1:~                   }|
371                                             │{1:~                   }|
372      {1:~                                      }│{1:~                   }|*3
373      {2:[No Name]            0,0-1          All < 0,0-1          All}|
374                                                                  |
375    ]])
376
377    command('set laststatus=3')
378    screen:expect([[
379                          │                │ │^                    |
380      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|*3
381      {1:~                   }├────────────────┤{1:~}│{1:~                   }|
382      {1:~                   }│                │{1:~}│{1:~                   }|
383      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|
384      {1:~                   }│{1:~               }│{1:~}├────────────────────|
385      {1:~                   }│{1:~               }│{1:~}│                    |
386      ────────────────────┴────────────────┴─┤{1:~                   }|
387                                             │{1:~                   }|
388      {1:~                                      }│{1:~                   }|*3
389      {3:[No Name]                                 0,0-1          All}|
390                                                                  |
391    ]])
392
393    command('set laststatus=0')
394    screen:expect([[
395                          │                │ │^                    |
396      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|*3
397      {1:~                   }│{2:<-1          All}│{1:~}│{1:~                   }|
398      {1:~                   }│                │{1:~}│{1:~                   }|
399      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|
400      {1:~                   }│{1:~               }│{1:~}│{3:< 0,0-1          All}|
401      {1:~                   }│{1:~               }│{1:~}│                    |
402      {2:< 0,0-1          All <-1          All <}│{1:~                   }|
403                                             │{1:~                   }|
404      {1:~                                      }│{1:~                   }|*4
405                                                0,0-1          All|
406    ]])
407
408    command('set laststatus=3')
409    screen:expect([[
410                          │                │ │^                    |
411      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|*3
412      {1:~                   }├────────────────┤{1:~}│{1:~                   }|
413      {1:~                   }│                │{1:~}│{1:~                   }|
414      {1:~                   }│{1:~               }│{1:~}│{1:~                   }|
415      {1:~                   }│{1:~               }│{1:~}├────────────────────|
416      {1:~                   }│{1:~               }│{1:~}│                    |
417      ────────────────────┴────────────────┴─┤{1:~                   }|
418                                             │{1:~                   }|
419      {1:~                                      }│{1:~                   }|*3
420      {3:[No Name]                                 0,0-1          All}|
421                                                                  |
422    ]])
423  end)
424
425  it('leaving laststatus=3 does not push a window past the last row', function()
426    command('split | wincmd j | vsplit | split')
427    command('wincmd t')
428    command('resize 1000')
429    command('set laststatus=2')
430    command('resize 1000')
431    screen:expect([[
432      ^                                                            |
433      {1:~                                                           }|*9
434      {3:[No Name]                                 0,0-1          All}|
435                                    │                             |
436      {2:[No Name]   0,0-1          All}│{1:~                            }|
437                                    │{1:~                            }|
438      {2:[No Name]   0,0-1          All [No Name]  0,0-1          All}|
439                                                                  |
440    ]])
441  end)
442
443  it('win_move_statusline() can reduce cmdheight to 1', function()
444    eq(1, api.nvim_get_option_value('cmdheight', {}))
445    fn.win_move_statusline(0, -1)
446    eq(2, api.nvim_get_option_value('cmdheight', {}))
447    fn.win_move_statusline(0, -1)
448    eq(3, api.nvim_get_option_value('cmdheight', {}))
449    fn.win_move_statusline(0, 1)
450    eq(2, api.nvim_get_option_value('cmdheight', {}))
451    fn.win_move_statusline(0, 1)
452    eq(1, api.nvim_get_option_value('cmdheight', {}))
453  end)
454
455  it('mouse dragging can reduce cmdheight to 1', function()
456    command('set mouse=a')
457    api.nvim_input_mouse('left', 'press', '', 0, 14, 10)
458    eq(1, api.nvim_get_option_value('cmdheight', {}))
459    api.nvim_input_mouse('left', 'drag', '', 0, 13, 10)
460    eq(2, api.nvim_get_option_value('cmdheight', {}))
461    api.nvim_input_mouse('left', 'drag', '', 0, 12, 10)
462    eq(3, api.nvim_get_option_value('cmdheight', {}))
463    api.nvim_input_mouse('left', 'drag', '', 0, 13, 10)
464    eq(2, api.nvim_get_option_value('cmdheight', {}))
465    api.nvim_input_mouse('left', 'drag', '', 0, 14, 10)
466    eq(1, api.nvim_get_option_value('cmdheight', {}))
467    api.nvim_input_mouse('left', 'drag', '', 0, 15, 10)
468    eq(1, api.nvim_get_option_value('cmdheight', {}))
469    api.nvim_input_mouse('left', 'drag', '', 0, 14, 10)
470    eq(1, api.nvim_get_option_value('cmdheight', {}))
471  end)
472
473  it('cmdline row is correct after setting cmdheight #20514', function()
474    command('botright split test/functional/fixtures/bigfile.txt')
475    api.nvim_set_option_value('cmdheight', 1, {})
476    feed('L')
477    screen:expect([[
478                                                                  |
479      {1:~                                                           }|*5
480      ────────────────────────────────────────────────────────────|
481      0000;<control>;Cc;0;BN;;;;;N;NULL;;;;                       |
482      0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;;           |
483      0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;;              |
484      0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;                |
485      0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;        |
486      0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;                    |
487      ^0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;                |
488      {3:test/functional/fixtures/bigfile.txt      7,1            Top}|
489                                                                  |
490    ]])
491    feed('j')
492    screen:expect([[
493                                                                  |
494      {1:~                                                           }|*5
495      ────────────────────────────────────────────────────────────|
496      0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;;           |
497      0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;;              |
498      0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;                |
499      0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;        |
500      0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;                    |
501      0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;                |
502      ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;;                       |
503      {3:test/functional/fixtures/bigfile.txt      8,1             0%}|
504                                                                  |
505    ]])
506    api.nvim_set_option_value('showtabline', 2, {})
507    screen:expect([[
508      {5: }{100:2}{5: t/f/f/bigfile.txt }{2:                                       }|
509                                                                  |
510      {1:~                                                           }|*5
511      ────────────────────────────────────────────────────────────|
512      0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;;              |
513      0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;                |
514      0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;        |
515      0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;                    |
516      0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;                |
517      ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;;                       |
518      {3:test/functional/fixtures/bigfile.txt      8,1             0%}|
519                                                                  |
520    ]])
521    api.nvim_set_option_value('cmdheight', 0, {})
522    screen:expect([[
523      {5: }{100:2}{5: t/f/f/bigfile.txt }{2:                                       }|
524                                                                  |
525      {1:~                                                           }|*5
526      ────────────────────────────────────────────────────────────|
527      0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;;           |
528      0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;;              |
529      0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;                |
530      0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;        |
531      0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;                    |
532      0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;                |
533      ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;;                       |
534      {3:test/functional/fixtures/bigfile.txt      8,1             0%}|
535    ]])
536    api.nvim_set_option_value('cmdheight', 1, {})
537    screen:expect([[
538      {5: }{100:2}{5: t/f/f/bigfile.txt }{2:                                       }|
539                                                                  |
540      {1:~                                                           }|*5
541      ────────────────────────────────────────────────────────────|
542      0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;;              |
543      0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;                |
544      0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;        |
545      0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;                    |
546      0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;                |
547      ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;;                       |
548      {3:test/functional/fixtures/bigfile.txt      8,1             0%}|
549                                                                  |
550    ]])
551  end)
552
553  it('vertical separator connector is not lost when switching window', function()
554    screen:add_extra_attr_ids {
555      [101] = { background = tonumber('0x282828') },
556      [102] = { bold = true, background = tonumber('0x282828'), foreground = Screen.colors.Blue1 },
557    }
558    command('hi NormalNC guibg=#282828')
559    command('vsplit | wincmd l | split')
560    -- Cursor is in top-right. Move to bottom-right.
561    feed('<C-w>j')
562    -- Verify the ├ connector is present.
563    screen:expect([[
564      {101:                              }│{101:                             }|
565      {102:~                             }│{102:~                            }|*6
566      {102:~                             }├─────────────────────────────|
567      {102:~                             }│^                             |
568      {102:~                             }│{1:~                            }|*5
569      {3:[No Name]                                 0,0-1          All}|
570                                                                  |
571    ]])
572    -- Navigate from bottom-right to left.
573    feed('<C-w>h')
574    -- The ├ connector must still be present.
575    screen:expect([[
576      ^                              │{101:                             }|
577      {1:~                             }│{102:~                            }|*6
578      {1:~                             }├─────────────────────────────|
579      {1:~                             }│{101:                             }|
580      {1:~                             }│{102:~                            }|*5
581      {3:[No Name]                                 0,0-1          All}|
582                                                                  |
583    ]])
584  end)
585
586  it('horizontal separator connector is not lost when switching window', function()
587    screen:add_extra_attr_ids {
588      [101] = { background = tonumber('0x282828') },
589      [102] = { bold = true, background = tonumber('0x282828'), foreground = Screen.colors.Blue1 },
590    }
591    command('hi NormalNC guibg=#282828')
592    command('split | wincmd j | vsplit')
593    -- Cursor is in bottom-left. Move to bottom-right.
594    feed('<C-w>l')
595    -- Verify the ┬ connector is present.
596    screen:expect([[
597      {101:                                                            }|
598      {102:~                                                           }|*6
599      ──────────────────────────────┬─────────────────────────────|
600      {101:                              }│^                             |
601      {102:~                             }│{1:~                            }|*5
602      {3:[No Name]                                 0,0-1          All}|
603                                                                  |
604    ]])
605    -- Navigate from bottom-right to top.
606    feed('<C-w>k')
607    -- The ┬ connector must still be present.
608    screen:expect([[
609      ^                                                            |
610      {1:~                                                           }|*6
611      ──────────────────────────────┬─────────────────────────────|
612      {101:                              }│{101:                             }|
613      {102:~                             }│{102:~                            }|*5
614      {3:[No Name]                                 0,0-1          All}|
615                                                                  |
616    ]])
617  end)
618
619  it('horizontal separators unchanged when failing to split-move window', function()
620    exec([[
621      botright split
622      let &winwidth = &columns
623      let &winminwidth = &columns
624    ]])
625    eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd L'))
626    command('mode')
627    screen:expect([[
628                                                                  |
629      {1:~                                                           }|*5
630      ────────────────────────────────────────────────────────────|
631      ^                                                            |
632      {1:~                                                           }|*6
633      {3:[No Name]                                 0,0-1          All}|
634                                                                  |
635    ]])
636
637    -- Shouldn't gain a hsep if the global statusline is turned off.
638    command('set laststatus=2')
639    eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd L'))
640    command('mode')
641    screen:expect([[
642                                                                  |
643      {1:~                                                           }|*5
644      {2:[No Name]                                 0,0-1          All}|
645      ^                                                            |
646      {1:~                                                           }|*6
647      {3:[No Name]                                 0,0-1          All}|
648                                                                  |
649    ]])
650  end)
651end)
652
653describe('statusline', function()
654  local screen
655  before_each(function()
656    clear()
657    screen = Screen.new(40, 8)
658    screen:add_extra_attr_ids {
659      [100] = { bold = true, reverse = true, foreground = Screen.colors.Blue },
660      [101] = { reverse = true, bold = true, foreground = Screen.colors.SlateBlue },
661    }
662  end)
663
664  it('does not crash if it has Arabic characters #19447', function()
665    api.nvim_set_option_value('statusline', 'غً', {})
666    api.nvim_set_option_value('laststatus', 2, {})
667    command('redraw!')
668    assert_alive()
669  end)
670
671  it('is redrawn with :resize from <Cmd> mapping #19629', function()
672    exec([[
673      set laststatus=2
674      nnoremap <Up> <cmd>resize -1<CR>
675      nnoremap <Down> <cmd>resize +1<CR>
676    ]])
677    feed('<Up>')
678    screen:expect([[
679      ^                                        |
680      {1:~                                       }|*4
681      {3:[No Name]                               }|
682                                              |*2
683    ]])
684    feed('<Down>')
685    screen:expect([[
686      ^                                        |
687      {1:~                                       }|*5
688      {3:[No Name]                               }|
689                                              |
690    ]])
691  end)
692
693  it('does not contain showmcd with showcmdloc=statusline when too narrow', function()
694    command('set showcmd')
695    command('set showcmdloc=statusline')
696    command('1vsplit')
697    screen:expect([[
698      ^ │                                      |
699      {1:~}│{1:~                                     }|*5
700      {3:< }{2:[No Name]                             }|
701                                              |
702    ]])
703    feed('1234')
704    screen:expect_unchanged()
705  end)
706
707  it('does not redraw unnecessarily after K_EVENT', function()
708    -- does not redraw on vim.schedule (#17937)
709    command([[
710      set laststatus=2
711      let g:counter = 0
712      func Status()
713        let g:counter += 1
714        lua vim.schedule(function() end)
715        return g:counter
716      endfunc
717      set statusline=%!Status()
718    ]])
719    sleep(50)
720    eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
721    -- also in insert mode
722    feed('i')
723    sleep(50)
724    eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
725    -- does not redraw on timer call (#14303)
726    command([[
727      let g:counter = 0
728      func Timer(timer)
729      endfunc
730      call timer_start(1, 'Timer', {'repeat': 100})
731    ]])
732    sleep(50)
733    eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter'))
734  end)
735
736  it('is redrawn on various state changes', function()
737    -- recording state change #22683
738    command('set ls=2 stl=%{repeat(reg_recording(),5)}')
739    local s1 = [[
740      ^                                        |
741      {1:~                                       }|*5
742      {3:                                        }|
743                                              |
744    ]]
745    screen:expect(s1)
746    feed('qQ')
747    screen:expect([[
748      ^                                        |
749      {1:~                                       }|*5
750      {3:QQQQQ                                   }|
751      {5:recording @Q}                            |
752    ]])
753    feed('q')
754    screen:expect(s1)
755
756    -- Visual mode change #23932
757    command('set ls=2 stl=%{mode(1)}')
758    local s2 = [[
759      ^                                        |
760      {1:~                                       }|*5
761      {3:n                                       }|
762                                              |
763    ]]
764    screen:expect(s2)
765    feed('v')
766    screen:expect([[
767      {17:^ }                                       |
768      {1:~                                       }|*5
769      {3:v                                       }|
770      {5:-- VISUAL --}                            |
771    ]])
772    feed('V')
773    screen:expect([[
774      {17:^ }                                       |
775      {1:~                                       }|*5
776      {3:V                                       }|
777      {5:-- VISUAL LINE --}                       |
778    ]])
779    feed('<C-V>')
780    screen:expect([[
781      {17:^ }                                       |
782      {1:~                                       }|*5
783      {3:^V                                      }|
784      {5:-- VISUAL BLOCK --}                      |
785    ]])
786    feed('<Esc>')
787    screen:expect(s2)
788
789    -- Visual selection other end change #36280
790    exec([[
791      function! DebugVisualSelection()
792        return printf("v %s %s", col("v"), col("."))
793      endfunction
794      set statusline=%!DebugVisualSelection()
795    ]])
796    feed('iabc<Esc>v')
797    screen:expect([[
798      ab{17:^c}                                     |
799      {1:~                                       }|*5
800      {3:v 3 3                                   }|
801      {5:-- VISUAL --}                            |
802    ]])
803    feed('iw')
804    screen:expect([[
805      {17:ab^c}                                     |
806      {1:~                                       }|*5
807      {3:v 1 3                                   }|
808      {5:-- VISUAL --}                            |
809    ]])
810  end)
811
812  it('ruler is redrawn in cmdline with redrawstatus #22804', function()
813    command([[
814      let g:n = 'initial value'
815      set ls=1 ru ruf=%{g:n}
816      redraw
817      let g:n = 'other value'
818      redrawstatus
819    ]])
820    screen:expect([[
821      ^                                        |
822      {1:~                                       }|*6
823                            other value       |
824    ]])
825  end)
826
827  it('ruler is cleared when window without statusline is closed', function()
828    local cfg = { relative = 'editor', row = 1, col = 1, height = 1, width = 1 }
829    local win = api.nvim_open_win(0, true, cfg)
830    -- Last line ruler does not take on window-local highlights #38777
831    command('hi link MsgArea Normal | setlocal winhl=Normal:Statement | set ruler laststatus=2')
832    screen:expect([[
833                                              |
834      {1:~}{15:^ }{1:                                      }|
835      {1:~                                       }|*4
836      {2:[No Name]             0,0-1          All}|
837                            0,0-1          All|
838    ]])
839    api.nvim_win_close(win, true)
840    screen:expect([[
841      ^                                        |
842      {1:~                                       }|*5
843      {3:[No Name]             0,0-1          All}|
844                                              |
845    ]])
846  end)
847
848  it('hidden moves ruler to cmdline', function()
849    -- Use long ruler to check 'ruler' with 'rulerformat' set has correct width.
850    command [[
851      set ruler rulerformat=%{winnr()}longlonglong ls=0 winwidth=10
852      split
853      wincmd b
854      vsplit
855      wincmd t
856      wincmd |
857      mode
858    ]]
859    -- Window 1 is current. It has a statusline, so cmdline should show the
860    -- last window's ruler, which has no statusline.
861    command '1wincmd w'
862    screen:expect([[
863      ^                                        |
864      {1:~                                       }|*2
865      {3:[No Name]                  1longlonglong}|
866                          │                   |
867      {1:~                   }│{1:~                  }|*2
868                            3longlonglong     |
869    ]])
870    -- Window 2 is current. It has no statusline, so cmdline should show its
871    -- ruler instead.
872    command '2wincmd w'
873    screen:expect([[
874                                              |
875      {1:~                                       }|*2
876      {2:[No Name]                  1longlonglong}|
877      ^                    │                   |
878      {1:~                   }│{1:~                  }|*2
879                            2longlonglong     |
880    ]])
881    -- Window 3 is current. Cmdline should again show its ruler.
882    command '3wincmd w'
883    screen:expect([[
884                                              |
885      {1:~                                       }|*2
886      {2:[No Name]                  1longlonglong}|
887                          │^                   |
888      {1:~                   }│{1:~                  }|*2
889                            3longlonglong     |
890    ]])
891  end)
892
893  it('uses "stl" and "stlnc" fillchars even if they are the same #19803', function()
894    command('hi clear StatusLine')
895    command('hi clear StatusLineNC')
896    command('vsplit')
897    screen:expect([[
898      ^                    │                   |
899      {1:~                   }│{1:~                  }|*5
900      [No Name]            [No Name]          |
901                                              |
902    ]])
903  end)
904
905  it('showcmdloc=statusline works with vertical splits', function()
906    command('rightbelow vsplit')
907    command('set showcmd showcmdloc=statusline')
908    feed('1234')
909    screen:expect([[
910                         │^                    |
911      {1:~                  }│{1:~                   }|*5
912      {2:[No Name]           }{3:<o Name] 1234       }|
913                                              |
914    ]])
915    feed('<Esc>')
916    command('set laststatus=3')
917    feed('1234')
918    screen:expect([[
919                         │^                    |
920      {1:~                  }│{1:~                   }|*5
921      {3:[No Name]                    1234       }|
922                                              |
923    ]])
924  end)
925
926  it('keymap is shown with vertical splits #27269', function()
927    command('setlocal keymap=dvorak')
928    command('rightbelow vsplit')
929    screen:expect([[
930                         │^                    |
931      {1:~                  }│{1:~                   }|*5
932      {2:[No Name]  <en-dv>  }{3:[No Name]   <en-dv> }|
933                                              |
934    ]])
935
936    command('set laststatus=3')
937    screen:expect([[
938                         │^                    |
939      {1:~                  }│{1:~                   }|*5
940      {3:[No Name]                       <en-dv> }|
941                                              |
942    ]])
943  end)
944
945  it("nested call from nvim_eval_statusline() doesn't overwrite items #32259", function()
946    exec_lua('vim.o.laststatus = 2')
947    exec_lua([[vim.o.statusline = '%#Special#B:%{nvim_eval_statusline("%f", []).str}']])
948    screen:expect([[
949      ^                                        |
950      {1:~                                       }|*5
951      {101:B:[No Name]                             }|
952                                              |
953    ]])
954  end)
955
956  it('truncation inside nested nvim_eval_statusline does not crash #36616', function()
957    exec_lua(function()
958      function _G.statusline_truncating()
959        local win = vim.api.nvim_get_current_win()
960        local res = vim.api.nvim_eval_statusline('%f', { winid = win, maxwidth = 5 })
961        return res.str
962      end
963      vim.o.laststatus = 2
964      vim.o.statusline = '%#Special#B:%{%v:lua.statusline_truncating()%}'
965    end)
966    local truncated = exec_lua(function()
967      return vim.api.nvim_eval_statusline('%f', { maxwidth = 5 }).str
968    end)
969    local rendered = exec_lua(function()
970      return vim.api.nvim_eval_statusline(
971        vim.o.statusline,
972        { winid = vim.api.nvim_get_current_win() }
973      ).str
974    end)
975    eq('B:' .. truncated, rendered)
976  end)
977
978  it('truncation inside nested nvim_eval_statusline correctly adjusts highlights', function()
979    exec_lua('vim.o.laststatus = 2')
980    exec_lua([[vim.o.statusline = "%{%repeat('%#Error#',20)%}"]])
981    exec_lua([[
982      vim.o.statusline = "%l%l%l%l%{%nvim_eval_statusline('test%#Error#%l%<',{'maxwidth':4,'highlights':1}).highlights%}"
983    ]])
984    screen:expect([[
985      ^                                        |
986      {1:~                                       }|*5
987      {3:< 'groups': ['StatusLine'], 'start': 0}]}|
988                                              |
989    ]])
990  end)
991
992  it('no cmdline ruler for autocmd window #39938', function()
993    command('set ruler laststatus=2')
994    api.nvim_create_autocmd('BufDelete', { command = 'redrawstatus' })
995    screen:expect([[
996      ^                                        |
997      {1:~                                       }|*5
998      {3:[No Name]             0,0-1          All}|
999                                              |
1000    ]])
1001    api.nvim_exec_autocmds('BufDelete', { buf = api.nvim_create_buf(true, true) })
1002    screen:expect_unchanged(true)
1003  end)
1004
1005  it('active window is correct after nvim_exec_autocmds({buf}) #40153', function()
1006    command('set laststatus=2')
1007    local caller_win = api.nvim_get_current_win()
1008    command('split')
1009    local target = api.nvim_create_buf(true, false)
1010    api.nvim_set_current_buf(target)
1011    api.nvim_set_current_win(caller_win)
1012    exec_lua(function(buf)
1013      _G.in_aucmd_statusline = false
1014      _G.statusline_contexts = {}
1015      _G.Status = function()
1016        local current = vim.api.nvim_get_current_win()
1017        local statusline = vim.g.statusline_winid
1018        local focus = current == statusline
1019        table.insert(_G.statusline_contexts, {
1020          current = current,
1021          focus = focus,
1022          in_aucmd = _G.in_aucmd_statusline,
1023          statusline = statusline,
1024        })
1025        return focus and 'CUR' or 'nc'
1026      end
1027      vim.o.statusline = '%!v:lua.Status()'
1028      vim.api.nvim_create_autocmd('User', {
1029        buffer = buf,
1030        callback = function(ev)
1031          _G.in_aucmd_statusline = true
1032          vim.api.nvim__redraw({ buf = ev.buf, statusline = true })
1033          _G.in_aucmd_statusline = false
1034        end,
1035      })
1036    end, target)
1037    -- Ignore statusline evaluations from setup; only the autocmd redraw matters.
1038    exec_lua('_G.statusline_contexts = {}')
1039    api.nvim_exec_autocmds('User', { buf = target })
1040    screen:expect([[
1041                                              |
1042      {1:~                                       }|*2
1043      {2:nc                                      }|
1044      ^                                        |
1045      {1:~                                       }|
1046      {3:CUR                                     }|
1047                                              |
1048    ]])
1049    -- `%!` may evaluate during the callback, but must not see the target as focused.
1050    eq(
1051      {},
1052      exec_lua(function(win)
1053        return vim
1054          .iter(_G.statusline_contexts)
1055          :filter(function(context)
1056            return context.in_aucmd and context.focus and context.current ~= win
1057          end)
1058          :totable()
1059      end, caller_win)
1060    )
1061  end)
1062
1063  it('statusline evaluation during nvim_exec_autocmds({buf}) #40153', function()
1064    command('set laststatus=2')
1065    local caller_win = api.nvim_get_current_win()
1066    command('split')
1067    local target = api.nvim_create_buf(true, false)
1068    api.nvim_set_current_buf(target)
1069    api.nvim_set_current_win(caller_win)
1070    exec_lua(function(buf)
1071      _G.in_aucmd_statusline = false
1072      _G.statusline_contexts = {}
1073      _G.Status = function()
1074        table.insert(_G.statusline_contexts, {
1075          in_aucmd = _G.in_aucmd_statusline,
1076          current = vim.api.nvim_get_current_win(),
1077          actual = tonumber(vim.g.actual_curwin or -1),
1078        })
1079        return vim.api.nvim_get_current_win() == tonumber(vim.g.actual_curwin or -1) and 'CUR'
1080          or 'nc'
1081      end
1082      -- `%{%...%}` sets g:actual_curwin while evaluating the statusline.
1083      vim.o.statusline = '%{%v:lua.Status()%}'
1084      vim.api.nvim_create_autocmd('User', {
1085        buffer = buf,
1086        callback = function(ev)
1087          _G.in_aucmd_statusline = true
1088          vim.api.nvim__redraw({ buf = ev.buf, statusline = true })
1089          _G.in_aucmd_statusline = false
1090        end,
1091      })
1092    end, target)
1093    screen:expect([[
1094                                              |
1095      {1:~                                       }|*2
1096      {2:nc                                      }|
1097      ^                                        |
1098      {1:~                                       }|
1099      {3:CUR                                     }|
1100                                              |
1101    ]])
1102    -- Ignore statusline evaluations from setup; only the autocmd redraw matters.
1103    exec_lua('_G.statusline_contexts = {}')
1104    api.nvim_exec_autocmds('User', { buf = target })
1105    screen:expect({ unchanged = true })
1106    local contexts = exec_lua(function()
1107      return _G.statusline_contexts
1108    end)
1109    eq(true, #contexts > 0)
1110    eq(caller_win, contexts[#contexts].actual)
1111  end)
1112
1113  it('%P %L updates in other windows', function()
1114    screen:try_resize(40, 14)
1115    command('set laststatus=2 statusline=%P\\ %L | split')
1116    feed(':put=range(10)<cr>dgg')
1117    screen:expect([[
1118      ^                                        |
1119      {1:~                                       }|*5
1120      {3:All 1                                   }|
1121                                              |
1122      {1:~                                       }|*4
1123      {2:All 1                                   }|
1124      --No lines in buffer--                  |
1125    ]])
1126  end)
1127
1128  it('works with highlight scopes', function()
1129    screen:add_extra_attr_ids({
1130      [131] = {
1131        bold = true,
1132        reverse = true,
1133        background = Screen.colors.Green,
1134      },
1135      [132] = {
1136        bold = true,
1137        reverse = true,
1138        background = Screen.colors.Green,
1139        foreground = Screen.colors.Red,
1140      },
1141      [133] = {
1142        bold = true,
1143        reverse = true,
1144        background = Screen.colors.Green,
1145        foreground = Screen.colors.Red,
1146        underline = true,
1147      },
1148      [134] = {
1149        bold = true,
1150        reverse = true,
1151        background = Screen.colors.Green,
1152        underline = true,
1153      },
1154    })
1155    command('hi User1 guibg=green')
1156    command('hi User2 guifg=red')
1157    command('hi User3 gui=underline')
1158    command('set laststatus=2')
1159    command('set statusline=a%#User1#b%$User2$c%#(%$User3$d%#)e')
1160    screen:expect([[
1161      ^                                        |
1162      {1:~                                       }|*5
1163      {3:a}{131:b}{132:c}{133:d}{132:e                                   }|
1164                                              |
1165    ]])
1166    command('set statusline=a%$User1$b%$User2$c%#(%$User3$d%#)e')
1167    screen:expect_unchanged()
1168    command('set statusline=a%#(%#User1#b%#(%$User2$c%#(%$User3$d%#)e%#)f%#)g')
1169    screen:expect([[
1170      ^                                        |
1171      {1:~                                       }|*5
1172      {3:a}{131:b}{132:c}{133:d}{132:e}{131:f}{3:g                                 }|
1173                                              |
1174    ]])
1175    command('set statusline=a%#(%#User1#b%#(%$User2$c%#)d%#(%$User3$e%#)f%#)g')
1176    screen:expect([[
1177      ^                                        |
1178      {1:~                                       }|*5
1179      {3:a}{131:b}{132:c}{131:d}{134:e}{131:f}{3:g                                 }|
1180                                              |
1181    ]])
1182  end)
1183end)
1184
1185describe('default statusline', function()
1186  local screen
1187
1188  before_each(function()
1189    clear()
1190    screen = Screen.new(60, 16)
1191    screen:add_extra_attr_ids {
1192      [100] = { foreground = Screen.colors.Magenta1, bold = true },
1193      [131] = { foreground = Screen.colors.NvimDarkGreen },
1194    }
1195    command('set laststatus=2')
1196    command('set ruler')
1197  end)
1198
1199  it('setting statusline to empty string sets default statusline', function()
1200    exec_lua("vim.o.statusline = 'asdf'")
1201    eq('asdf', eval('&statusline'))
1202    screen:expect([[
1203      ^                                                            |
1204      {1:~                                                           }|*13
1205      {3:asdf                                                        }|
1206                                                                  |
1207    ]])
1208
1209    local default_statusline = table.concat({
1210      '%<',
1211      '%f',
1212      "%( %h%w%m%r%{ v:lua.require('vim._core.util').term_exitcode() }%)",
1213      '%= ',
1214      '%(%-10S %)',
1215      "%{ &busy > 0 ? '◐\226\128\175' : '' }",
1216      "%(%{ luaeval('(package.loaded[''vim.ui''] and vim.api.nvim_get_current_win() == tonumber(vim.g.actual_curwin or -1) and vim.ui.progress_status()) or '''' ')} %)",
1217      "%{% luaeval('(package.loaded[''vim.diagnostic''] and next(vim.diagnostic.count(0)) and vim.diagnostic.status() .. '' '') or '''' ') %}",
1218      '%(%k %)',
1219      "%{% &ruler ? &rulerformat : '' %}",
1220    })
1221
1222    exec_lua("vim.o.statusline = ''")
1223    eq(default_statusline, eval('&statusline'))
1224    screen:expect([[
1225      ^                                                            |
1226      {1:~                                                           }|*13
1227      {3:[No Name]                                 0,0-1          All}|
1228                                                                  |
1229    ]])
1230
1231    -- Reset to default (via the correct scope) if there's an error.
1232    command('setglobal statusline=%{a%}')
1233    eq(default_statusline, eval('&statusline'))
1234    eq(default_statusline, eval('&g:statusline'))
1235    eq('', eval('&l:statusline'))
1236    command('redrawstatus') -- like Vim, statusline isn't immediately redrawn after an error
1237    screen:expect([[
1238      ^                                                            |
1239      {1:~                                                           }|*13
1240      {3:[No Name]                                 0,0-1          All}|
1241      {9:E121: Undefined variable: a}                                 |
1242    ]])
1243    command('setlocal statusline=%{b%}')
1244    eq(default_statusline, eval('&statusline'))
1245    eq(default_statusline, eval('&g:statusline'))
1246    eq('', eval('&l:statusline'))
1247    command('redrawstatus') -- like Vim, statusline isn't immediately redrawn after an error
1248    screen:expect([[
1249      ^                                                            |
1250      {1:~                                                           }|*13
1251      {3:[No Name]                                 0,0-1          All}|
1252      {9:E121: Undefined variable: b}                                 |
1253    ]])
1254  end)
1255
1256  it('shows busy status when buffer is set to be busy', function()
1257    exec_lua("vim.o.statusline = ''")
1258
1259    screen:expect([[
1260      ^                                                            |
1261      {1:~                                                           }|*13
1262      {3:[No Name]                                 0,0-1          All}|
1263                                                                  |
1264    ]])
1265    exec_lua('vim.o.busy = 1')
1266    screen:expect([[
1267      ^                                                            |
1268      {1:~                                                           }|*13
1269      {3:[No Name]                               ◐ 0,0-1          All}|
1270                                                                  |
1271    ]])
1272
1273    exec_lua('vim.o.busy = 0')
1274    screen:expect([[
1275      ^                                                            |
1276      {1:~                                                           }|*13
1277      {3:[No Name]                                 0,0-1          All}|
1278                                                                  |
1279    ]])
1280  end)
1281
1282  it('shows exit code when terminal exits #14986', function()
1283    exec_lua("vim.o.statusline = ''")
1284    api.nvim_set_option_value('shell', testprg('shell-test'), {})
1285    api.nvim_set_option_value('shellcmdflag', 'EXIT', {})
1286    api.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
1287    command('terminal 9')
1288    screen:expect({ any = '%[Exit:\226\128\1759%]' })
1289    expect_exitcode(9)
1290  end)
1291
1292  it('shows and updates progress status', function()
1293    exec_lua("vim.o.statusline = ''")
1294    local function get_progress()
1295      return exec_lua(function()
1296        return vim.ui.progress_status()
1297      end)
1298    end
1299
1300    eq('', get_progress())
1301    ---@type integer|string
1302    local id1 = api.nvim_echo(
1303      { { 'searching...' } },
1304      true,
1305      { kind = 'progress', source = 'tests', title = 'test', status = 'running', percent = 10 }
1306    )
1307    eq('10%(1)', get_progress())
1308
1309    api.nvim_echo({ { 'searching' } }, true, {
1310      id = id1,
1311      kind = 'progress',
1312      source = 'tests',
1313      percent = 50,
1314      status = 'running',
1315      title = 'terminal(ripgrep)',
1316    })
1317    eq('50%(1)', get_progress())
1318
1319    api.nvim_echo({ { 'searching...' } }, true, {
1320      kind = 'progress',
1321      source = 'tests',
1322      title = 'second-item',
1323      status = 'running',
1324      percent = 20,
1325    })
1326    eq('35%(2)', get_progress())
1327
1328    api.nvim_echo({ { 'searching' } }, true, {
1329      id = id1,
1330      kind = 'progress',
1331      source = 'tests',
1332      percent = 100,
1333      status = 'success',
1334      title = 'terminal(ripgrep)',
1335    })
1336    eq('20%(1)', get_progress())
1337
1338    exec('redrawstatus')
1339    screen:expect([[
1340      ^                                                            |
1341      {1:~                                                           }|*13
1342      {3:[No Name]                          20%(1) 0,0-1          All}|
1343      {131:terminal(ripgrep)}: {19:100% }searching                           |
1344    ]])
1345
1346    -- Progress_status only shown on active window
1347    exec('split')
1348    screen:expect([[
1349      ^                                                            |
1350      {1:~                                                           }|*6
1351      {3:[No Name]                          20%(1) 0,0-1          All}|
1352                                                                  |
1353      {1:~                                                           }|*5
1354      {2:[No Name]                                 0,0-1          All}|
1355      {131:terminal(ripgrep)}: {19:100% }searching                           |
1356    ]])
1357
1358    exec('wincmd w')
1359    screen:expect([[
1360                                                                  |
1361      {1:~                                                           }|*6
1362      {2:[No Name]                                 0,0-1          All}|
1363      ^                                                            |
1364      {1:~                                                           }|*5
1365      {3:[No Name]                          20%(1) 0,0-1          All}|
1366      {131:terminal(ripgrep)}: {19:100% }searching                           |
1367    ]])
1368  end)
1369end)
1370
1371describe('default rulerformat', function()
1372  local screen
1373
1374  before_each(function()
1375    clear()
1376    screen = Screen.new(60, 16)
1377    command('set ruler')
1378  end)
1379
1380  it('setting rulerformat to empty string sets default rulerformat', function()
1381    exec_lua("vim.o.rulerformat = 'hjkl'")
1382    eq('hjkl', eval('&rulerformat'))
1383    screen:expect([[
1384      ^                                                            |
1385      {1:~                                                           }|*14
1386                                                hjkl              |
1387    ]])
1388
1389    local default_rulerformat = '%18(%l,%c%V%= %P%)%<'
1390
1391    exec_lua("vim.o.rulerformat = ''")
1392    eq(default_rulerformat, eval('&rulerformat'))
1393    screen:expect([[
1394      ^                                                            |
1395      {1:~                                                           }|*14
1396                                                0,0-1          All|
1397    ]])
1398
1399    -- Reset to default if there's an error.
1400    command('set rulerformat=%{a%}')
1401    eq(default_rulerformat, eval('&rulerformat'))
1402    eq(default_rulerformat, eval('&g:rulerformat'))
1403    eq(default_rulerformat, eval('&l:rulerformat'))
1404    command('redrawstatus') -- like Vim, rulerformat isn't immediately redrawn after an error
1405    screen:expect([[
1406      ^                                                            |
1407      {1:~                                                           }|*14
1408      {9:E121: Undefined variable: a}               0,0-1          All|
1409    ]])
1410  end)
1411end)
1412
1413describe("'statusline' in floatwin", function()
1414  local screen
1415  before_each(function()
1416    clear()
1417    screen = Screen.new(30, 20)
1418    screen:add_extra_attr_ids({
1419      [101] = { foreground = Screen.colors.Magenta1, bold = true },
1420      [102] = {
1421        foreground = Screen.colors.Magenta1,
1422        underline = true,
1423        background = Screen.colors.LightGray,
1424        bold = true,
1425      },
1426    })
1427  end)
1428
1429  it('controlled by ":setlocal statusline" and "style" and "laststatus"', function()
1430    local buf = api.nvim_create_buf(false, false)
1431    api.nvim_buf_set_lines(buf, 0, -1, false, { '1', '2', '3', '4' })
1432    local cfg = {
1433      relative = 'editor',
1434      row = 1,
1435      col = 1,
1436      height = 4,
1437      width = 10,
1438      border = 'single',
1439    }
1440    local win = api.nvim_open_win(buf, true, cfg)
1441    local set_stl = [[setlocal stl=%f\ %m]]
1442    command('set laststatus=2')
1443    command(set_stl)
1444    local has_stl = [[
1445                                    |
1446      {1:~}{4:┌──────────┐}{1:                 }|
1447      {1:~}{4:│^1         │}{1:                 }|
1448      {1:~}{4:│2         │}{1:                 }|
1449      {1:~}{4:│3         │}{1:                 }|
1450      {1:~}{4:│4         │}{1:                 }|
1451      {1:~}{4:│}{3:<Name] [+]}{4:│}{1:                 }|
1452      {1:~}{4:└──────────┘}{1:                 }|
1453      {1:~                             }|*10
1454      {2:[No Name]                     }|
1455                                    |
1456    ]]
1457    screen:expect(has_stl)
1458
1459    -- setting the style will clear the statusline expression for floating windows
1460    api.nvim_win_set_config(win, { style = 'minimal' })
1461    local without_stl = [[
1462                                    |
1463      {1:~}{4:┌──────────┐}{1:                 }|
1464      {1:~}{4:│^1         │}{1:                 }|
1465      {1:~}{4:│2         │}{1:                 }|
1466      {1:~}{4:│3         │}{1:                 }|
1467      {1:~}{4:│4         │}{1:                 }|
1468      {1:~}{4:└──────────┘}{1:                 }|
1469      {1:~                             }|*11
1470      {2:[No Name]                     }|
1471                                    |
1472    ]]
1473    screen:expect(without_stl)
1474
1475    -- no statusline is displayed because the statusline option was cleared
1476    api.nvim_win_set_config(win, cfg)
1477    screen:expect_unchanged()
1478
1479    -- displayed after the option is reset
1480    command(set_stl)
1481    screen:expect(has_stl)
1482
1483    -- Show in a new window in a new tab, then return to the previous tab;
1484    -- remove the statusline of the new window, When re-entering this new tab,
1485    -- the statusline of the new window is cleared
1486    command('tabnew')
1487    local win2 = api.nvim_open_win(buf, false, cfg)
1488    command(set_stl)
1489    screen:expect([[
1490      {24: }{102:2}{24:+ [No Name] }{5: }{101:2}{5:+ [No Name] }{2: }{24:X}|
1491      ^ {4:┌──────────┐}                 |
1492      {1:~}{4:│1         │}{1:                 }|
1493      {1:~}{4:│2         │}{1:                 }|
1494      {1:~}{4:│3         │}{1:                 }|
1495      {1:~}{4:│4         │}{1:                 }|
1496      {1:~}{4:└──────────┘}{1:                 }|
1497      {1:~                             }|*11
1498      {3:[No Name]                     }|
1499                                    |
1500    ]])
1501    command('tabfirst')
1502    api.nvim_win_set_config(win2, { style = 'minimal' })
1503    screen:expect([[
1504      {5: }{101:2}{5:+ [No Name] }{24: }{102:2}{24:+ [No Name] }{2: }{24:X}|
1505       {4:┌──────────┐}                 |
1506      {1:~}{4:│^1         │}{1:                 }|
1507      {1:~}{4:│2         │}{1:                 }|
1508      {1:~}{4:│3         │}{1:                 }|
1509      {1:~}{4:│4         │}{1:                 }|
1510      {1:~}{4:│}{3:<Name] [+]}{4:│}{1:                 }|
1511      {1:~}{4:└──────────┘}{1:                 }|
1512      {1:~                             }|*10
1513      {2:[No Name]                     }|
1514                                    |
1515    ]])
1516    command('tabnext')
1517    screen:expect([[
1518      {24: }{102:2}{24:+ [No Name] }{5: }{101:2}{5:+ [No Name] }{2: }{24:X}|
1519      ^ {4:┌──────────┐}                 |
1520      {1:~}{4:│1         │}{1:                 }|
1521      {1:~}{4:│2         │}{1:                 }|
1522      {1:~}{4:│3         │}{1:                 }|
1523      {1:~}{4:│4         │}{1:                 }|
1524      {1:~}{4:└──────────┘}{1:                 }|
1525      {1:~                             }|*11
1526      {3:[No Name]                     }|
1527                                    |
1528    ]])
1529    -- clear statusline when laststatus is 3
1530    command('tabclose | set laststatus=2')
1531    screen:expect([[
1532                                    |
1533      {1:~}{4:┌──────────┐}{1:                 }|
1534      {1:~}{4:│^1         │}{1:                 }|
1535      {1:~}{4:│2         │}{1:                 }|
1536      {1:~}{4:│3         │}{1:                 }|
1537      {1:~}{4:│4         │}{1:                 }|
1538      {1:~}{4:│}{3:<Name] [+]}{4:│}{1:                 }|
1539      {1:~}{4:└──────────┘}{1:                 }|
1540      {1:~                             }|*10
1541      {2:[No Name]                     }|
1542                                    |
1543    ]])
1544    command('set laststatus=0')
1545    screen:expect([[
1546                                    |
1547      {1:~}{4:┌──────────┐}{1:                 }|
1548      {1:~}{4:│^1         │}{1:                 }|
1549      {1:~}{4:│2         │}{1:                 }|
1550      {1:~}{4:│3         │}{1:                 }|
1551      {1:~}{4:│4         │}{1:                 }|
1552      {1:~}{4:└──────────┘}{1:                 }|
1553      {1:~                             }|*12
1554                                    |
1555    ]])
1556
1557    command('set laststatus=3')
1558    screen:expect([[
1559                                    |
1560      {1:~}{4:┌──────────┐}{1:                 }|
1561      {1:~}{4:│^1         │}{1:                 }|
1562      {1:~}{4:│2         │}{1:                 }|
1563      {1:~}{4:│3         │}{1:                 }|
1564      {1:~}{4:│4         │}{1:                 }|
1565      {1:~}{4:└──────────┘}{1:                 }|
1566      {1:~                             }|*11
1567      {3:[No Name] [+]                 }|
1568                                    |
1569    ]])
1570    api.nvim_buf_set_name(buf, 'stl_test')
1571    screen:expect([[
1572                                    |
1573      {1:~}{4:┌──────────┐}{1:                 }|
1574      {1:~}{4:│^1         │}{1:                 }|
1575      {1:~}{4:│2         │}{1:                 }|
1576      {1:~}{4:│3         │}{1:                 }|
1577      {1:~}{4:│4         │}{1:                 }|
1578      {1:~}{4:└──────────┘}{1:                 }|
1579      {1:~                             }|*11
1580      {3:stl_test [+]                  }|
1581                                    |
1582    ]])
1583  end)
1584
1585  it("clears inherited window-local 'statusline' on creation", function()
1586    command('set laststatus=2')
1587    api.nvim_set_option_value('statusline', 'global', {})
1588    local curwin = api.nvim_get_current_win()
1589    api.nvim_set_option_value('statusline', 'split-local', { win = curwin })
1590    api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, height = 2, width = 4 })
1591    screen:expect([[
1592                                    |
1593      {1:~}{4:^    }{1:                         }|
1594      {1:~}{11:~   }{1:                         }|
1595      {1:~                             }|*15
1596      {2:split-local                   }|
1597                                    |
1598    ]])
1599  end)
1600end)