robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
138.8 KiB4100 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each, after_each, pending, finally =
6  t.describe, t.it, t.before_each, t.after_each, t.pending, t.finally
7local clear, feed = n.clear, n.feed
8local eval = n.eval
9local eq = t.eq
10local neq = t.neq
11local command = n.command
12local set_method_error = n.set_method_error
13local api = n.api
14local async_meths = n.async_meths
15local nvim_prog = n.nvim_prog
16local testprg = n.testprg
17local exec = n.exec
18local exec_capture = n.exec_capture
19local exec_lua = n.exec_lua
20local poke_eventloop = n.poke_eventloop
21local assert_alive = n.assert_alive
22local retry = t.retry
23local is_os = t.is_os
24local fn = n.fn
25local skip = t.skip
26
27describe('ui/ext_messages', function()
28  local screen
29  local fname = 'Xtest_functional_ui_messages_spec'
30
31  before_each(function()
32    clear()
33    screen = Screen.new(25, 5, { rgb = true, ext_messages = true, ext_popupmenu = true })
34    screen:add_extra_attr_ids {
35      [100] = { undercurl = true, special = Screen.colors.Red },
36      [101] = { foreground = Screen.colors.Magenta1, bold = true },
37    }
38  end)
39  after_each(function()
40    os.remove(fname)
41  end)
42
43  it('msg_show kinds', function()
44    feed('iline 1\nline 2<esc>')
45
46    -- confirm is now cmdline prompt
47    feed(':echo confirm("test")<cr>')
48    screen:expect({
49      grid = [[
50        line 1                   |
51        line ^2                   |
52        {1:~                        }|*3
53      ]],
54      cmdline = { { content = { { '' } }, hl = 'MoreMsg', pos = 0, prompt = '[O]k: ' } },
55      messages = { { content = { { 'test', 6, 'MoreMsg' } }, kind = 'confirm' } },
56    })
57    feed('<cr>')
58    screen:expect({
59      grid = [[
60        line 1                   |
61        line ^2                   |
62        {1:~                        }|*3
63      ]],
64      messages = { { content = { { '1' } }, kind = 'echo' } },
65    })
66
67    -- :substitute confirm is now cmdline prompt
68    feed(':%s/i/X/gc<cr>')
69    screen:expect({
70      grid = [[
71        l{2:i}ne 1                   |
72        l{10:i}ne ^2                   |
73        {1:~                        }|*3
74      ]],
75      cmdline = {
76        {
77          content = { { '' } },
78          hl = 'Question',
79          pos = 0,
80          prompt = 'replace with X? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll up(^E)/down(^Y)',
81        },
82      },
83    })
84    feed('nq')
85
86    -- kind=wmsg (editing readonly file)
87    local byte = t.is_os('win') and 16 or 14
88    local writemsg = ('"Xtest_functional_ui_messages_spec" [New] 2L, %dB written'):format(byte)
89    command('write ' .. fname)
90    command('set readonly nohls')
91    feed('G$x')
92    screen:expect({
93      grid = [[
94        line 1                   |
95        line^                     |
96        {1:~                        }|*3
97      ]],
98      messages = {
99        {
100          content = { { writemsg } },
101          history = true,
102          id = 'nvim.bufwrite "Xtest_functional_ui_messages_spec"',
103          kind = 'progress',
104        },
105        {
106          content = { { 'W10: Warning: Changing a readonly file', 19, 'WarningMsg' } },
107          history = true,
108          kind = 'wmsg',
109        },
110      },
111    })
112
113    -- kind=wmsg ('wrapscan' after search reaches EOF)
114    command('silent undo')
115    feed('G$/i<CR>G$')
116    screen:expect {
117      grid = [[
118        line 1                   |
119        line ^2                   |
120        {1:~                        }|*3
121      ]],
122      messages = {
123        { content = { { '/i ' } }, kind = 'search_cmd' },
124        {
125          content = { { 'search hit BOTTOM, continuing at TOP', 19, 'WarningMsg' } },
126          kind = 'wmsg',
127        },
128      },
129    }
130
131    -- kind=emsg after :throw
132    feed(':throw "foo"<cr>')
133    screen:expect {
134      grid = [[
135        line 1                   |
136        line ^2                   |
137        {1:~                        }|*3
138      ]],
139      messages = {
140        {
141          content = { { 'Error in :\nE605: Exception not caught: foo', 9, 'ErrorMsg' } },
142          history = true,
143          kind = 'emsg',
144        },
145      },
146    }
147
148    -- kind=quickfix after :cnext
149    command("caddexpr [expand('%').':1:line1',expand('%').':2:line2']")
150    feed(':cnext<CR>$')
151    screen:expect {
152      grid = [[
153        line 1                   |
154        line ^2                   |
155        {1:~                        }|*3
156      ]],
157      messages = {
158        { content = { { '(2 of 2): line2' } }, history = true, kind = 'quickfix' },
159      },
160    }
161
162    -- search_cmd
163    feed('?line<CR>G$')
164    screen:expect({
165      grid = [[
166        line 1                   |
167        line ^2                   |
168        {1:~                        }|*3
169      ]],
170      messages = { { content = { { '?line ' } }, kind = 'search_cmd' } },
171    })
172
173    -- highlight
174    feed('G$:filter character highlight<CR>')
175    screen:expect({
176      grid = [[
177        line 1                   |
178        line ^2                   |
179        {1:~                        }|*3
180      ]],
181      messages = {
182        {
183          content = {
184            { '@character     ' },
185            { 'xxx', 26, '@character' },
186            { ' ' },
187            { 'links to', 18, 'Directory' },
188            { ' Character\n@character.special ' },
189            { 'xxx', 16, '@character.special' },
190            { ' ' },
191            { 'links to', 18, 'Directory' },
192            { ' SpecialChar' },
193          },
194          kind = 'list_cmd',
195        },
196      },
197    })
198
199    -- undo
200    feed('u')
201    screen:expect({
202      grid = [[
203        ^                         |
204        {1:~                        }|*4
205      ]],
206      condition = function()
207        local msg = screen.messages[1].content[1][2]:gsub('%d seconds?', '0 seconds')
208        eq('2 fewer lines; before #1  0 seconds ago', msg)
209        eq('undo', screen.messages[1].kind)
210        screen.messages = {}
211      end,
212    })
213    feed('u')
214    screen:expect({
215      grid = [[
216        ^                         |
217        {1:~                        }|*4
218      ]],
219      messages = {
220        { content = { { 'Already at oldest change' } }, history = true, kind = 'undo' },
221      },
222    })
223
224    command('silent redo | silent redo | redo')
225    screen:expect({
226      grid = [[
227        line 1                   |
228        line^                     |
229        {1:~                        }|*3
230      ]],
231      messages = {
232        { content = { { 'Already at newest change' } }, history = true, kind = 'undo' },
233      },
234    })
235
236    -- kind=completion
237    command('set noshowmode')
238    feed('i<C-n>')
239    screen:expect({
240      grid = [[
241        line 1                   |
242        line^                     |
243        {1:~                        }|*3
244      ]],
245      messages = { { content = { { 'The only match' } }, kind = 'completion' } },
246    })
247    feed('<Esc>l')
248    command('set showmode')
249
250    -- kind=echoerr for nvim_echo() err
251    feed(':call nvim_echo([["Error"], ["Message", "Special"]], 1, #{ err:1 })<CR>')
252    screen:expect({
253      grid = [[
254        line 1                   |
255        line^                     |
256        {1:~                        }|*3
257      ]],
258      messages = {
259        {
260          content = { { 'Error', 9, 'ErrorMsg' }, { 'Message', 16, 'Special' } },
261          history = true,
262          kind = 'echoerr',
263        },
264      },
265    })
266
267    -- kind=verbose for nvim_echo() verbose
268    feed(':call nvim_echo([["Verbose Message"]], 1, #{ verbose:1 })<CR>')
269    screen:expect({
270      grid = [[
271        line 1                   |
272        line^                     |
273        {1:~                        }|*3
274      ]],
275      messages = {
276        { content = { { 'Verbose Message' } }, history = true, kind = 'verbose' },
277      },
278    })
279
280    feed(':call nvim_echo([["Foo"]], 1, #{ kind:"list_cmd" })<CR>')
281    screen:expect({
282      grid = [[
283        line 1                   |
284        line^                     |
285        {1:~                        }|*3
286      ]],
287      messages = { { content = { { 'Foo' } }, history = true, kind = 'list_cmd' } },
288    })
289
290    -- kind=verbose for :verbose messages
291    feed(':1verbose filter Diff[AC] hi<CR>')
292    screen:expect({
293      grid = [[
294        line 1                   |
295        line^                     |
296        {1:~                        }|*3
297      ]],
298      messages = {
299        {
300          content = {
301            { 'DiffAdd        ' },
302            { 'xxx', 22, 'DiffAdd' },
303            { ' ' },
304            { 'ctermbg=', 18, 'Directory' },
305            { '81 ' },
306            { 'guibg=', 18, 'Directory' },
307            {
308              'LightBlue\n\tLast set from Lua (run Nvim with -V1 for more details)\nDiffChange     ',
309            },
310            { 'xxx', 4, 'DiffChange' },
311            { ' ' },
312            { 'ctermbg=', 18, 'Directory' },
313            { '225 ' },
314            { 'guibg=', 18, 'Directory' },
315            { 'LightMagenta\n\tLast set from Lua (run Nvim with -V1 for more details)' },
316          },
317          kind = 'list_cmd',
318        },
319      },
320    })
321
322    exec([[
323      set verbose=9
324      augroup group1
325        autocmd BufEnter * echoh "BufEnter"
326        autocmd BufWinEnter * bdelete
327        autocmd ExitPre pat1 foo
328        autocmd ExitPre pat2 bar
329      augroup END
330      augroup group2
331        autocmd ExitPre pat1 foo
332        autocmd ExitPre pat2 bar
333      augroup END
334    ]])
335    feed(':edit! foo<CR>')
336    screen:expect({
337      grid = [[
338        line 1                   |
339        ^line                     |
340        {1:~                        }|*3
341      ]],
342      messages = {
343        { content = { { 'finished sourcing nvim_exec2()' } }, history = true, kind = 'verbose' },
344        {
345          content = { { 'Executing BufEnter Autocommands for "*"' } },
346          history = true,
347          kind = 'verbose',
348        },
349        { content = { { 'autocommand echoh "BufEnter"' } }, history = true, kind = 'verbose' },
350        { content = { { '\n' } }, kind = '' },
351        {
352          content = { { 'Executing BufWinEnter Autocommands for "*"' } },
353          history = true,
354          kind = 'verbose',
355        },
356        { content = { { 'autocommand bdelete' } }, history = true, kind = 'verbose' },
357        { content = { { '\n' } }, kind = '' },
358      },
359    })
360    feed(':au ExitPre<CR>')
361    screen:expect({
362      grid = [[
363        line 1                   |
364        ^line                     |
365        {1:~                        }|*3
366      ]],
367      messages = {
368        {
369          content = {
370            { '--- Autocommands ---', 101, 'Title' },
371            { '\n' },
372            { 'group1', 101, 'Title' },
373            { '  ' },
374            { 'ExitPre', 101, 'Title' },
375            {
376              '\n    pat1      foo\n\tLast set from anonymous :source line 5\n    pat2      bar\n\tLast set from anonymous :source line 6\n',
377            },
378            { 'group2', 101, 'Title' },
379            { '  ' },
380            { 'ExitPre', 101, 'Title' },
381            {
382              '\n    pat1      foo\n\tLast set from anonymous :source line 9\n    pat2      bar\n\tLast set from anonymous :source line 10',
383            },
384          },
385          kind = 'list_cmd',
386        },
387      },
388    })
389    command('autocmd! group1')
390    command('autocmd! group2')
391    command('augroup! group1')
392    command('augroup! group2')
393    command('set verbose=0')
394
395    n.add_builddir_to_rtp()
396    feed(':help<CR>:tselect<CR>')
397    screen:expect({
398      grid = [[
399        ^*help.txt*      Nvim     |
400                                 |
401        {3:help.txt [Help][-][RO]   }|
402        line                     |
403        {2:<i_messages_spec [+][RO] }|
404      ]],
405      cmdline = {
406        {
407          content = { { '' } },
408          pos = 0,
409          -- Default vim.ui.select uses this prompt.
410          prompt = 'Type number and <Enter> (q or empty cancels): ',
411        },
412      },
413      -- Message depends on runtimepath, only test the static text...
414      condition = function()
415        for _, msg in ipairs(screen.messages) do
416          eq(false, msg.history)
417          eq('confirm', msg.kind)
418          local text = '' -- Concatenate all chunks.
419          for _, chunk in ipairs(msg.content) do
420            text = text .. (#chunk >= 2 and chunk[2] or chunk[1])
421          end
422          t.matches('^Select a tag:\n', text)
423          t.matches('1: > F%s+help%.txt%s+', text)
424        end
425        screen.messages = {}
426      end,
427    })
428    feed('<CR>:bdelete<CR>$')
429
430    -- kind=shell for :!cmd messages
431    local cmd = t.is_os('win') and 'echo stdout& echo stderr>&2& exit 3'
432      or '{ echo stdout; echo stderr >&2; exit 3; }'
433    feed((':!%s<CR>'):format(cmd))
434    screen:expect({
435      grid = [[
436        line 1                   |
437        line^                     |
438        {1:~                        }|*3
439      ]],
440      messages = {
441        {
442          content = { { (':!%s\r\n[No write since last change]\n'):format(cmd) } },
443          kind = 'shell_cmd',
444        },
445        {
446          content = { { ('stdout%s\n'):format(t.is_os('win') and '\r' or ''), 'StdoutMsg' } },
447          kind = 'shell_out',
448          append = true,
449        },
450        {
451          content = { { ('stderr%s\n'):format(t.is_os('win') and '\r' or ''), 9, 'StderrMsg' } },
452          kind = 'shell_err',
453          append = true,
454        },
455        { content = { { 'shell returned 3' } }, kind = 'shell_ret' },
456      },
457    })
458
459    feed(':registers .<CR>')
460    screen:expect({
461      grid = [[
462        line 1                   |
463        line^                     |
464        {1:~                        }|*3
465      ]],
466      messages = {
467        {
468          content = { { 'Type Name Content', 101, 'Title' }, { '\n  c  ".   ' } },
469          kind = 'list_cmd',
470        },
471      },
472    })
473
474    feed(':au ChanInfo * foo<CR>:au ChanInfo<CR>')
475    screen:expect({
476      grid = [[
477        line 1                   |
478        line^                     |
479        {1:~                        }|*3
480      ]],
481      messages = {
482        {
483          content = {
484            { '--- Autocommands ---', 101, 'Title' },
485            { '\n' },
486            { 'ChanInfo', 101, 'Title' },
487            { '\n    *         foo' },
488          },
489          kind = 'list_cmd',
490        },
491      },
492    })
493
494    feed(':1,2p<CR>')
495    screen:expect({
496      grid = [[
497        line 1                   |
498        ^line                     |
499        {1:~                        }|*3
500      ]],
501      messages = { { content = { { 'line 1\nline ' } }, kind = 'list_cmd' } },
502    })
503
504    -- single message for :global command #37726
505    feed(':g/line<CR>')
506    screen:expect({
507      grid = [[
508        line 1                   |
509        ^line                     |
510        {1:~                        }|*3
511      ]],
512      messages = { { content = { { 'line 1\nline ' } }, kind = 'list_cmd' } },
513    })
514
515    command('command Foo Bar')
516    feed(':command<CR>')
517    screen:expect({
518      grid = [[
519        line 1                   |
520        ^line                     |
521        {1:~                        }|*3
522      ]],
523      messages = {
524        {
525          content = {
526            { '    Name              Args Address Complete    Definition', 101, 'Title' },
527            { '\n    ' },
528            { 'Foo', 18, 'Directory' },
529            { '               0                        Bar' },
530          },
531          kind = 'list_cmd',
532        },
533      },
534    })
535
536    feed(':colorscheme<CR>')
537    screen:expect({
538      grid = [[
539        line 1                   |
540        ^line                     |
541        {1:~                        }|*3
542      ]],
543      messages = { { content = { { 'default' } }, history = true, kind = 'list_cmd' } },
544    })
545
546    feed(':version<CR>')
547    screen:expect({
548      grid = [[
549        line 1                   |
550        ^line                     |
551        {1:~                        }|*3
552      ]],
553      condition = function()
554        eq('list_cmd', screen.messages[1].kind)
555        screen.messages = {} -- Ignore build dependent :version content
556      end,
557    })
558
559    -- 3 empty message events, not for an empty chunk after a non-printable character
560    feed(':echo "foo\\n" | echo | echom "" | lua print()<CR>')
561    screen:expect({
562      grid = [[
563        line 1                   |
564        ^line                     |
565        {1:~                        }|*3
566      ]],
567      messages = {
568        { content = { { 'foo\n' } }, kind = 'echo' },
569        { content = {}, kind = 'empty' },
570        { content = {}, kind = 'empty' },
571        { content = {}, kind = 'empty' },
572      },
573    })
574
575    -- No empty message event for empty option value
576    feed(':set foldclose<CR>')
577    screen:expect({
578      grid = [[
579        line 1                   |
580        ^line                     |
581        {1:~                        }|*3
582      ]],
583      messages = { { content = { { '  foldclose=' } }, history = true, kind = 'list_cmd' } },
584    })
585
586    -- Indent message
587    feed('A2\nline 3<Esc>gg=G')
588    screen:expect({
589      grid = [[
590        ^line 1                   |
591        line 2                   |
592        line 3                   |
593        {1:~                        }|*2
594      ]],
595      messages = {
596        {
597          content = { { '3 lines indented ' } },
598          kind = 'progress',
599          id = 'nvim.indent',
600          history = true,
601        },
602      },
603    })
604  end)
605
606  it(':echoerr', function()
607    feed(':echoerr "raa"<cr>')
608    screen:expect {
609      grid = [[
610        ^                         |
611        {1:~                        }|*4
612      ]],
613      messages = { { content = { { 'raa', 9, 'ErrorMsg' } }, history = true, kind = 'echoerr' } },
614    }
615
616    -- cmdline in a later input cycle clears error message
617    feed(':')
618    screen:expect {
619      grid = [[
620        ^                         |
621        {1:~                        }|*4
622      ]],
623      cmdline = { { firstc = ':', content = { { '' } }, pos = 0 } },
624    }
625
626    feed('echoerr "bork" | echoerr "fail"<cr>')
627    screen:expect {
628      grid = [[
629        ^                         |
630        {1:~                        }|*4
631      ]],
632      messages = {
633        { content = { { 'bork', 9, 'ErrorMsg' } }, history = true, kind = 'echoerr' },
634        { content = { { 'fail', 9, 'ErrorMsg' } }, history = true, kind = 'echoerr' },
635      },
636    }
637
638    feed(':echoerr "extrafail"<cr>')
639    screen:expect {
640      grid = [[
641        ^                         |
642        {1:~                        }|*4
643      ]],
644      messages = {
645        {
646          content = { { 'extrafail', 9, 'ErrorMsg' } },
647          history = true,
648          kind = 'echoerr',
649        },
650      },
651    }
652
653    -- cmdline without interleaving wait/display keeps the error message
654    feed(':echoerr "problem" | let x = input("foo> ")<cr>')
655    screen:expect {
656      grid = [[
657        ^                         |
658        {1:~                        }|*4
659      ]],
660      messages = {
661        { content = { { 'problem', 9, 'ErrorMsg' } }, history = true, kind = 'echoerr' },
662      },
663      cmdline = { { prompt = 'foo> ', content = { { '' } }, pos = 0 } },
664    }
665
666    feed('solution<cr>')
667    screen:expect_unchanged()
668    eq('solution', eval('x'))
669
670    feed(':messages<cr>')
671    screen:expect {
672      grid = [[
673        ^                         |
674        {1:~                        }|*4
675      ]],
676      msg_history = {
677        { kind = 'echoerr', content = { { 'raa', 9, 'ErrorMsg' } } },
678        { kind = 'echoerr', content = { { 'bork', 9, 'ErrorMsg' } } },
679        { kind = 'echoerr', content = { { 'fail', 9, 'ErrorMsg' } } },
680        { kind = 'echoerr', content = { { 'extrafail', 9, 'ErrorMsg' } } },
681        { kind = 'echoerr', content = { { 'problem', 9, 'ErrorMsg' } } },
682      },
683    }
684  end)
685
686  it(':echoerr multiline', function()
687    exec_lua([[vim.g.multi = table.concat({ "bork", "fail" }, "\n")]])
688    feed(':echoerr g:multi<cr>')
689    screen:expect {
690      grid = [[
691        ^                         |
692        {1:~                        }|*4
693      ]],
694      messages = {
695        {
696          content = { { 'bork\nfail', 9, 'ErrorMsg' } },
697          history = true,
698          kind = 'echoerr',
699        },
700      },
701    }
702
703    feed(':messages<cr>')
704    screen:expect {
705      grid = [[
706        ^                         |
707        {1:~                        }|*4
708      ]],
709      msg_history = { { content = { { 'bork\nfail', 9, 'ErrorMsg' } }, kind = 'echoerr' } },
710    }
711  end)
712
713  it('shortmess-=S', function()
714    command('set shortmess-=S')
715    feed('iline 1\nline 2<esc>')
716
717    feed('/line<cr>')
718    screen:expect {
719      grid = [[
720        {10:^line} 1                   |
721        {10:line} 2                   |
722        {1:~                        }|*3
723      ]],
724      messages = { { content = { { '/line          W [1/2]' } }, kind = 'search_count' } },
725    }
726
727    feed('n')
728    screen:expect {
729      grid = [[
730        {10:line} 1                   |
731        {10:^line} 2                   |
732        {1:~                        }|*3
733      ]],
734      messages = { { content = { { '/line            [2/2]' } }, kind = 'search_count' } },
735    }
736  end)
737
738  it("doesn't crash with column adjustment #10069", function()
739    feed(':let [x,y] = [1,2]<cr>')
740    feed(':let x y<cr>')
741    screen:expect({
742      grid = [[
743        ^                         |
744        {1:~                        }|*4
745      ]],
746      messages = {
747        {
748          content = { { 'x                     #1\ny                     #2' } },
749          kind = 'list_cmd',
750        },
751      },
752    })
753  end)
754
755  it('&showmode', function()
756    command('imap <f2> <cmd>echomsg "stuff"<cr>')
757    feed('i')
758    screen:expect {
759      grid = [[
760        ^                         |
761        {1:~                        }|*4
762      ]],
763      showmode = { { '-- INSERT --', 5, 'ModeMsg' } },
764    }
765
766    feed('alphpabet<cr>alphanum<cr>')
767    screen:expect {
768      grid = [[
769        alphpabet                |
770        alphanum                 |
771        ^                         |
772        {1:~                        }|*2
773      ]],
774      showmode = { { '-- INSERT --', 5, 'ModeMsg' } },
775    }
776
777    feed('<c-x>')
778    screen:expect {
779      grid = [[
780        alphpabet                |
781        alphanum                 |
782        ^                         |
783        {1:~                        }|*2
784      ]],
785      showmode = { { '-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)', 5, 'ModeMsg' } },
786    }
787
788    feed('<c-p>')
789    screen:expect {
790      grid = [[
791        alphpabet                |
792        alphanum                 |
793        alphanum^                 |
794        {1:~                        }|*2
795      ]],
796      popupmenu = {
797        anchor = { 1, 2, 0 },
798        items = { { 'alphpabet', '', '', '' }, { 'alphanum', '', '', '' } },
799        pos = 1,
800      },
801      showmode = {
802        { '-- Keyword Local completion (^N^P) ', 5, 'ModeMsg' },
803        { 'match 1 of 2', 6, 'Question' },
804      },
805    }
806
807    -- echomsg and showmode don't overwrite each other, this is the same
808    -- as the TUI behavior with cmdheight=2 or larger.
809    feed('<f2>')
810    screen:expect {
811      grid = [[
812        alphpabet                |
813        alphanum                 |
814        alphanum^                 |
815        {1:~                        }|*2
816      ]],
817      popupmenu = {
818        anchor = { 1, 2, 0 },
819        items = { { 'alphpabet', '', '', '' }, { 'alphanum', '', '', '' } },
820        pos = 1,
821      },
822      messages = { { content = { { 'stuff' } }, history = true, kind = 'echomsg' } },
823      showmode = {
824        { '-- Keyword Local completion (^N^P) ', 5, 'ModeMsg' },
825        { 'match 1 of 2', 6, 'Question' },
826      },
827    }
828
829    feed('<c-p>')
830    screen:expect {
831      grid = [[
832        alphpabet                |
833        alphanum                 |
834        alphpabet^                |
835        {1:~                        }|*2
836      ]],
837      popupmenu = {
838        anchor = { 1, 2, 0 },
839        items = { { 'alphpabet', '', '', '' }, { 'alphanum', '', '', '' } },
840        pos = 0,
841      },
842      showmode = {
843        { '-- Keyword Local completion (^N^P) ', 5, 'ModeMsg' },
844        { 'match 2 of 2', 6, 'Question' },
845      },
846    }
847
848    feed('<esc>:messages<cr>')
849    screen:expect {
850      grid = [[
851        alphpabet                |
852        alphanum                 |
853        alphpabe^t                |
854        {1:~                        }|*2
855      ]],
856      msg_history = { { content = { { 'stuff' } }, kind = 'echomsg' } },
857    }
858  end)
859
860  it('&showmode with macro-recording message', function()
861    feed('qq')
862    screen:expect {
863      grid = [[
864        ^                         |
865        {1:~                        }|*4
866      ]],
867      showmode = { { 'recording @q', 5, 'ModeMsg' } },
868    }
869
870    feed('i')
871    screen:expect {
872      grid = [[
873        ^                         |
874        {1:~                        }|*4
875      ]],
876      showmode = { { '-- INSERT --recording @q', 5, 'ModeMsg' } },
877    }
878
879    feed('<esc>')
880    screen:expect {
881      grid = [[
882        ^                         |
883        {1:~                        }|*4
884      ]],
885      showmode = { { 'recording @q', 5, 'ModeMsg' } },
886    }
887
888    feed('q')
889    screen:expect([[
890      ^                         |
891      {1:~                        }|*4
892    ]])
893  end)
894
895  it('shows macro-recording message with &noshowmode', function()
896    command('set noshowmode')
897    feed('qq')
898    -- also check mode to avoid immediate success
899    screen:expect {
900      grid = [[
901        ^                         |
902        {1:~                        }|*4
903      ]],
904      showmode = { { 'recording @q', 5, 'ModeMsg' } },
905      mode = 'normal',
906    }
907
908    feed('i')
909    screen:expect {
910      grid = [[
911        ^                         |
912        {1:~                        }|*4
913      ]],
914      showmode = { { 'recording @q', 5, 'ModeMsg' } },
915      mode = 'insert',
916    }
917
918    feed('<esc>')
919    screen:expect {
920      grid = [[
921        ^                         |
922        {1:~                        }|*4
923      ]],
924      showmode = { { 'recording @q', 5, 'ModeMsg' } },
925      mode = 'normal',
926    }
927
928    feed('q')
929    screen:expect {
930      grid = [[
931        ^                         |
932        {1:~                        }|*4
933      ]],
934      mode = 'normal',
935    }
936  end)
937
938  it("supports 'showcmd' and 'ruler(format)'", function()
939    command('set showcmd ruler rulerformat=%12(%l,%c%V%=%P%)')
940    command('hi link MsgArea ErrorMsg')
941    screen:expect({
942      grid = [[
943        ^                         |
944        {1:~                        }|*4
945      ]],
946      ruler = { { '0,0-1    All', 9, 'MsgArea' } },
947    })
948    command('hi clear MsgArea')
949    feed('i')
950    screen:expect {
951      grid = [[
952        ^                         |
953        {1:~                        }|*4
954      ]],
955      showmode = { { '-- INSERT --', 5, 'ModeMsg' } },
956      ruler = { { '0,1      All', 'MsgArea' } },
957    }
958    feed('abcde<cr>12345<esc>')
959    screen:expect {
960      grid = [[
961        abcde                    |
962        1234^5                    |
963        {1:~                        }|*3
964      ]],
965      ruler = { { '2,5      All', 'MsgArea' } },
966    }
967    feed('d')
968    screen:expect {
969      grid = [[
970        abcde                    |
971        1234^5                    |
972        {1:~                        }|*3
973      ]],
974      showcmd = { { 'd' } },
975      ruler = { { '2,5      All', 'MsgArea' } },
976    }
977    feed('<esc>^')
978    screen:expect {
979      grid = [[
980        abcde                    |
981        ^12345                    |
982        {1:~                        }|*3
983      ]],
984      ruler = { { '2,1      All', 'MsgArea' } },
985    }
986    feed('<c-v>k2l')
987    screen:expect({
988      grid = [[
989        {17:ab^c}de                    |
990        {17:123}45                    |
991        {1:~                        }|*3
992      ]],
993      showmode = { { '-- VISUAL BLOCK --', 5, 'ModeMsg' } },
994      showcmd = { { '2x3' } },
995      ruler = { { '1,3      All', 'MsgArea' } },
996    })
997    feed('o<esc>d')
998    screen:expect {
999      grid = [[
1000        abcde                    |
1001        ^12345                    |
1002        {1:~                        }|*3
1003      ]],
1004      showcmd = { { 'd' } },
1005      ruler = { { '2,1      All', 'MsgArea' } },
1006    }
1007    feed('i')
1008    screen:expect {
1009      grid = [[
1010        abcde                    |
1011        ^12345                    |
1012        {1:~                        }|*3
1013      ]],
1014      showcmd = { { 'di' } },
1015      ruler = { { '2,1      All', 'MsgArea' } },
1016    }
1017    feed('w')
1018    screen:expect {
1019      grid = [[
1020        abcde                    |
1021        ^                         |
1022        {1:~                        }|*3
1023      ]],
1024      ruler = { { '2,0-1    All', 'MsgArea' } },
1025    }
1026    command('set rulerformat=Foo%#ErrorMsg#Bar')
1027    screen:expect({
1028      grid = [[
1029        abcde                    |
1030        ^                         |
1031        {1:~                        }|*3
1032      ]],
1033      ruler = { { 'Foo', 'MsgArea' }, { 'Bar', 9, 'ErrorMsg' } },
1034    })
1035    command('set rulerformat=')
1036
1037    -- when ruler is part of statusline it is not externalized.
1038    -- this will be added as part of future ext_statusline support
1039    command('set laststatus=2')
1040    screen:expect([[
1041      abcde                    |
1042      ^                         |
1043      {1:~                        }|*2
1044      {3:<] [+] 2,0-1          All}|
1045    ]])
1046    -- ruler of float is not part of statusline and is cleared when leaving the float #37649.
1047    command('set rulerformat=foo')
1048    api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, width = 10, height = 10 })
1049    screen:expect({
1050      grid = [[
1051        a{4:abcde     }              |
1052         {4:^          }              |
1053        {1:~}{11:~         }{1:              }|*2
1054        {2:[}{11:~         }{2:+]         foo}|
1055      ]],
1056      ruler = { { 'foo', 'MsgArea' } },
1057    })
1058    command('wincmd p')
1059    screen:expect([[
1060      a{4:abcde     }              |
1061      ^ {4:          }              |
1062      {1:~}{11:~         }{1:              }|*2
1063      {3:[}{11:~         }{3:+]         foo}|
1064    ]])
1065  end)
1066
1067  it('keeps history of message of different kinds', function()
1068    feed(':echomsg "howdy"<cr>')
1069    screen:expect {
1070      grid = [[
1071        ^                         |
1072        {1:~                        }|*4
1073      ]],
1074      messages = { { content = { { 'howdy' } }, history = true, kind = 'echomsg' } },
1075    }
1076
1077    -- always test a message without kind. If this one gets promoted to a
1078    -- category, add a new message without kind.
1079    feed('<c-c>')
1080    screen:expect {
1081      grid = [[
1082        ^                         |
1083        {1:~                        }|*4
1084      ]],
1085      messages = {
1086        {
1087          content = { { 'Type  :qa  and press <Enter> to exit Nvim' } },
1088          history = true,
1089          kind = '',
1090        },
1091      },
1092    }
1093
1094    feed(':echoerr "bork"<cr>')
1095    screen:expect {
1096      grid = [[
1097        ^                         |
1098        {1:~                        }|*4
1099      ]],
1100      messages = {
1101        { content = { { 'bork', 9, 'ErrorMsg' } }, history = true, kind = 'echoerr' },
1102      },
1103    }
1104
1105    feed(':echo "xyz"<cr>')
1106    screen:expect {
1107      grid = [[
1108        ^                         |
1109        {1:~                        }|*4
1110      ]],
1111      messages = { { content = { { 'xyz' } }, kind = 'echo' } },
1112    }
1113
1114    feed(':call nosuchfunction()<cr>')
1115    screen:expect {
1116      grid = [[
1117        ^                         |
1118        {1:~                        }|*4
1119      ]],
1120      messages = {
1121        {
1122          content = { { 'E117: Unknown function: nosuchfunction', 9, 'ErrorMsg' } },
1123          history = true,
1124          kind = 'emsg',
1125        },
1126      },
1127    }
1128
1129    feed(':messages<cr>')
1130    screen:expect {
1131      grid = [[
1132        ^                         |
1133        {1:~                        }|*4
1134      ]],
1135      msg_history = {
1136        { kind = 'echomsg', content = { { 'howdy' } } },
1137        { kind = '', content = { { 'Type  :qa  and press <Enter> to exit Nvim' } } },
1138        { kind = 'echoerr', content = { { 'bork', 9, 'ErrorMsg' } } },
1139        {
1140          kind = 'emsg',
1141          content = { { 'E117: Unknown function: nosuchfunction', 9, 'ErrorMsg' } },
1142        },
1143      },
1144    }
1145  end)
1146
1147  it("implies ext_cmdline but allows changing 'cmdheight'", function()
1148    eq(0, eval('&cmdheight'))
1149    feed(':set cmdheight=1')
1150    screen:expect {
1151      grid = [[
1152        ^                         |
1153        {1:~                        }|*4
1154      ]],
1155      cmdline = { { content = { { 'set cmdheight=1' } }, firstc = ':', pos = 15 } },
1156    }
1157
1158    feed('<cr>')
1159    screen:expect([[
1160      ^                         |
1161      {1:~                        }|*3
1162                               |
1163    ]])
1164    eq(1, eval('&cmdheight'))
1165
1166    feed(':set cmdheight=0')
1167    screen:expect {
1168      grid = [[
1169        ^                         |
1170        {1:~                        }|*3
1171                                 |
1172      ]],
1173      cmdline = { { content = { { 'set cmdheight=0' } }, firstc = ':', pos = 15 } },
1174    }
1175    feed('<cr>')
1176    screen:expect([[
1177      ^                         |
1178      {1:~                        }|*4
1179    ]])
1180    eq(0, eval('&cmdheight'))
1181  end)
1182
1183  it('supports multiline messages from lua', function()
1184    feed(':lua error("such\\nmultiline\\nerror")<cr>')
1185    screen:expect {
1186      grid = [[
1187        ^                         |
1188        {1:~                        }|*4
1189      ]],
1190      messages = {
1191        {
1192          content = {
1193            {
1194              [[E5108: Lua: [string ":lua"]:1: such
1195multiline
1196error
1197stack traceback:
1198	[C]: in function 'error'
1199	[string ":lua"]:1: in main chunk]],
1200              9,
1201              'ErrorMsg',
1202            },
1203          },
1204          history = true,
1205          kind = 'lua_error',
1206        },
1207      },
1208    }
1209  end)
1210
1211  it('supports multiline messages from rpc', function()
1212    feed(':call rpcrequest(1, "test_method")<cr>')
1213
1214    screen:expect {
1215      grid = [[
1216        ^                         |
1217        {1:~                        }|*4
1218      ]],
1219      messages = {
1220        {
1221          content = {
1222            {
1223              "Invoking 'test_method' on channel 1:\ncomplete\nerror\n\nmessage",
1224              9,
1225              'ErrorMsg',
1226            },
1227          },
1228          history = true,
1229          kind = 'rpc_error',
1230        },
1231      },
1232      request_cb = function(name)
1233        if name == 'test_method' then
1234          set_method_error('complete\nerror\n\nmessage')
1235        end
1236      end,
1237    }
1238  end)
1239
1240  it('supports multiline messages for :map', function()
1241    command('mapclear')
1242    command('nmap Y y$')
1243    command('nmap Q @@')
1244    command('nnoremap j k')
1245    feed(':map<cr>')
1246
1247    screen:expect {
1248      grid = [[
1249        ^                         |
1250        {1:~                        }|*4
1251      ]],
1252      messages = {
1253        {
1254          content = {
1255            { 'n  Q             @@\nn  Y             y$\nn  j           ' },
1256            { '*', 18, 'SpecialKey' },
1257            { ' k' },
1258          },
1259          kind = 'list_cmd',
1260        },
1261      },
1262    }
1263  end)
1264
1265  it('wildmode=list', function()
1266    screen:try_resize(25, 7)
1267    screen:set_option('ext_popupmenu', false)
1268
1269    command('set wildmenu wildmode=list')
1270    feed(':set wildm<tab>')
1271    screen:expect {
1272      grid = [[
1273        ^                         |
1274        {1:~                        }|*6
1275      ]],
1276      messages = { { content = { { 'wildmenu  wildmode\n' } }, kind = 'wildlist' } },
1277      cmdline = { { firstc = ':', content = { { 'set wildm' } }, pos = 9 } },
1278    }
1279  end)
1280
1281  it('hides prompt_for_number messages', function()
1282    command('set spell')
1283    feed('ihelllo<esc>')
1284
1285    feed('z=')
1286    screen:expect({
1287      grid = [[
1288        {100:helll^o}                   |
1289        {1:~                        }|*4
1290      ]],
1291      cmdline = {
1292        {
1293          content = { { '' } },
1294          pos = 0,
1295          prompt = 'Type number and <Enter> (q or empty cancels): ',
1296        },
1297      },
1298      messages = {
1299        {
1300          content = { { 'Change "helllo" to:\n1: "Hello"\n2: "Hallo"\n3: "Hullo"' } },
1301          kind = 'confirm',
1302        },
1303      },
1304    })
1305
1306    feed('1')
1307    screen:expect({
1308      grid = [[
1309        {100:helll^o}                   |
1310        {1:~                        }|*4
1311      ]],
1312      cmdline = {
1313        {
1314          content = { { '1' } },
1315          pos = 1,
1316          prompt = 'Type number and <Enter> (q or empty cancels): ',
1317        },
1318      },
1319    })
1320
1321    feed('<cr>')
1322    screen:expect([[
1323      ^Hello                    |
1324      {1:~                        }|*4
1325    ]])
1326
1327    async_meths.nvim_command("let g:n = inputlist(['input0', 'input1'])")
1328    screen:expect({
1329      grid = [[
1330        ^Hello                    |
1331        {1:~                        }|*4
1332      ]],
1333      cmdline = {
1334        {
1335          content = { { '' } },
1336          pos = 0,
1337          prompt = 'Type number and <Enter> (q or empty cancels): ',
1338        },
1339      },
1340      messages = { { content = { { 'input0\ninput1' } }, kind = 'confirm' } },
1341    })
1342
1343    feed('42<CR>')
1344    screen:expect({
1345      grid = [[
1346        ^Hello                    |
1347        {1:~                        }|*4
1348      ]],
1349      unchanged = true,
1350    })
1351    eq(42, eval('g:n'))
1352  end)
1353
1354  it('supports nvim_echo messages with multiple attrs', function()
1355    local chunks = { { 'wow, ', 'Search' }, { 'such\n\nvery ', 'ErrorMsg' }, { 'color', 'LineNr' } }
1356    async_meths.nvim_echo(chunks, true, {})
1357    screen:expect {
1358      grid = [[
1359        ^                         |
1360        {1:~                        }|*4
1361      ]],
1362      messages = {
1363        {
1364          content = {
1365            { 'wow, ', 10, 'Search' },
1366            { 'such\n\nvery ', 9, 'ErrorMsg' },
1367            { 'color', 8, 'LineNr' },
1368          },
1369          history = true,
1370          kind = 'echomsg',
1371        },
1372      },
1373    }
1374
1375    feed ':ls<cr>'
1376    screen:expect {
1377      grid = [[
1378        ^                         |
1379        {1:~                        }|*4
1380      ]],
1381      messages = {
1382        { content = { { '  1 %a   "[No Name]"                    line 1' } }, kind = 'list_cmd' },
1383      },
1384    }
1385
1386    feed ':messages<cr>'
1387    screen:expect {
1388      grid = [[
1389        ^                         |
1390        {1:~                        }|*4
1391      ]],
1392      msg_history = {
1393        {
1394          content = {
1395            { 'wow, ', 10, 'Search' },
1396            { 'such\n\nvery ', 9, 'ErrorMsg' },
1397            { 'color', 8, 'LineNr' },
1398          },
1399          kind = 'echomsg',
1400        },
1401      },
1402    }
1403  end)
1404
1405  it('does not truncate messages', function()
1406    command('write ' .. fname)
1407    screen:expect({
1408      messages = {
1409        {
1410          content = { { string.format('"%s" [New] 0L, 0B written', fname) } },
1411          kind = 'progress',
1412          id = 'nvim.bufwrite "Xtest_functional_ui_messages_spec"',
1413          history = true,
1414        },
1415      },
1416    })
1417  end)
1418
1419  it('does not do showmode unnecessarily #29086', function()
1420    local screen_showmode = screen._handle_msg_showmode
1421    local showmode = 0
1422    screen._handle_msg_showmode = function(...)
1423      screen_showmode(...)
1424      showmode = showmode + 1
1425    end
1426    screen:expect([[
1427      ^                         |
1428      {1:~                        }|*4
1429    ]])
1430    eq(0, showmode)
1431    feed('i')
1432    screen:expect({
1433      grid = [[
1434        ^                         |
1435        {1:~                        }|*4
1436      ]],
1437      showmode = { { '-- INSERT --', 5, 'ModeMsg' } },
1438    })
1439    eq(2, showmode)
1440    command('set noshowmode')
1441    feed('<Esc>')
1442    screen:expect([[
1443      ^                         |
1444      {1:~                        }|*4
1445    ]])
1446    eq(3, showmode)
1447    feed('i')
1448    screen:expect_unchanged()
1449    eq(3, showmode)
1450  end)
1451
1452  it('emits single message for multiline print())', function()
1453    exec_lua([[print("foo\nbar\nbaz")]])
1454    screen:expect({
1455      grid = [[
1456        ^                         |
1457        {1:~                        }|*4
1458      ]],
1459      messages = { { content = { { 'foo\nbar\nbaz' } }, history = true, kind = 'lua_print' } },
1460    })
1461    exec_lua([[print(vim.inspect({ foo = "bar" }))]])
1462    screen:expect({
1463      grid = [[
1464        ^                         |
1465        {1:~                        }|*4
1466      ]],
1467      messages = {
1468        { content = { { '{\n  foo = "bar"\n}' } }, history = true, kind = 'lua_print' },
1469      },
1470    })
1471    exec_lua([[vim.print({ foo = "bar" })]])
1472    screen:expect({
1473      grid = [[
1474        ^                         |
1475        {1:~                        }|*4
1476      ]],
1477      messages = {
1478        { content = { { '{\n  foo = "bar"\n}' } }, history = true, kind = 'lua_print' },
1479      },
1480    })
1481  end)
1482
1483  it('ruler redraw does not crash due to double grid_line_start()', function()
1484    exec_lua([[
1485      local ns = vim.api.nvim_create_namespace('')
1486      vim.ui_attach(ns, { ext_messages = true }, function(event, ...)
1487        if event == 'msg_ruler' then
1488          vim.api.nvim__redraw({ flush = true })
1489        end
1490      end)
1491      vim.o.ruler = true
1492      vim.o.laststatus = 0
1493    ]])
1494    feed('i')
1495    n.assert_alive()
1496  end)
1497
1498  it(':digraph contains newlines', function()
1499    command('digraph')
1500    screen:expect({
1501      condition = function()
1502        local nl = 0
1503        eq('list_cmd', screen.messages[1].kind)
1504        for _, chunk in ipairs(screen.messages[1].content) do
1505          nl = nl + (chunk[2]:find('\n') and 1 or 0)
1506        end
1507        eq(683, nl)
1508        screen.messages = {}
1509      end,
1510    })
1511  end)
1512
1513  it('g< mapping shows recent messages', function()
1514    feed(':echo "foo" | echo "bar" | echon "baz"<CR>')
1515    screen:expect({
1516      grid = [[
1517        ^                         |
1518        {1:~                        }|*4
1519      ]],
1520      messages = {
1521        { content = { { 'foo' } }, kind = 'echo' },
1522        { content = { { 'bar' } }, kind = 'echo' },
1523        { content = { { 'baz' } }, kind = 'echo', append = true },
1524      },
1525    })
1526    feed('g<lt>')
1527    screen:expect({
1528      grid = [[
1529        ^                         |
1530        {1:~                        }|*4
1531      ]],
1532      msg_history = {
1533        prev_cmd = true,
1534        { content = { { 'foo' } }, kind = 'echo' },
1535        { content = { { 'bar' } }, kind = 'echo' },
1536        { content = { { 'baz' } }, kind = 'echo', append = true },
1537      },
1538    })
1539    feed('@@')
1540    screen:expect({
1541      grid = [[
1542        ^                         |
1543        {1:~                        }|*4
1544      ]],
1545      messages = {
1546        {
1547          content = { { 'E748: No previously used register', 9, 'ErrorMsg' } },
1548          history = true,
1549          kind = 'emsg',
1550        },
1551      },
1552    })
1553    feed('g<lt>')
1554    screen:expect({
1555      grid = [[
1556        ^                         |
1557        {1:~                        }|*4
1558      ]],
1559      msg_history = {
1560        prev_cmd = true,
1561        { content = { { 'E748: No previously used register', 9, 'ErrorMsg' } }, kind = 'emsg' },
1562      },
1563    })
1564  end)
1565
1566  it('single event for multiple :set options', function()
1567    command('set sw ts sts')
1568    screen:expect({
1569      grid = [[
1570        ^                         |
1571        {1:~                        }|*4
1572      ]],
1573      messages = {
1574        { content = { { '  shiftwidth=8\n  tabstop=8\n  softtabstop=0' } }, kind = 'list_cmd' },
1575      },
1576    })
1577  end)
1578
1579  it('clears showmode after insert_expand mode', function()
1580    feed('i<C-N>')
1581    screen:expect({
1582      grid = [[
1583        ^                         |
1584        {1:~                        }|*4
1585      ]],
1586      showmode = {
1587        { '-- Keyword completion (^N^P) ', 5, 'ModeMsg' },
1588        { 'Pattern not found', 9, 'ErrorMsg' },
1589      },
1590    })
1591    feed('<Esc>')
1592    screen:expect([[
1593      ^                         |
1594      {1:~                        }|*4
1595    ]])
1596  end)
1597
1598  it(':echon sets append', function()
1599    command('echo "foo" | echon " bar" | echon " baz"')
1600    screen:expect({
1601      grid = [[
1602        ^                         |
1603        {1:~                        }|*4
1604      ]],
1605      messages = {
1606        { content = { { 'foo' } }, kind = 'echo' },
1607        { content = { { ' bar' } }, kind = 'echo', append = true },
1608        { content = { { ' baz' } }, kind = 'echo', append = true },
1609      },
1610    })
1611  end)
1612
1613  it('can capture execute("messages"))', function()
1614    feed('@@')
1615    screen:expect({
1616      grid = [[
1617        ^                         |
1618        {1:~                        }|*4
1619      ]],
1620      messages = {
1621        {
1622          content = { { 'E748: No previously used register', 9, 'ErrorMsg' } },
1623          history = true,
1624          kind = 'emsg',
1625        },
1626      },
1627    })
1628    feed(':let msg = execute("messages")<CR>')
1629    screen:expect_unchanged()
1630    eq('E748: No previously used register', eval('msg'):gsub('\n', ''))
1631  end)
1632
1633  it('single event for multi-expr :echo', function()
1634    command('echo 1 2 | echon 1 2')
1635    screen:expect({
1636      grid = [[
1637        ^                         |
1638        {1:~                        }|*4
1639      ]],
1640      messages = {
1641        { content = { { '1 2' } }, kind = 'echo' },
1642        { content = { { '12' } }, kind = 'echo', append = true },
1643      },
1644    })
1645  end)
1646
1647  it('completion message overwrites previous', function()
1648    command('set shortmess-=C | edit foo | edit bar | edit baz')
1649    feed('i<C-N>')
1650    screen:expect({
1651      grid = [[
1652        ^                         |
1653        {1:~                        }|*4
1654      ]],
1655      messages = {
1656        {
1657          content = { { 'Scanning tags.', 6, 'Question' } },
1658          kind = 'progress',
1659          id = 'nvim.completion',
1660        },
1661      },
1662      showmode = {
1663        { '-- Keyword completion (^N^P) ', 5, 'ModeMsg' },
1664        { 'Pattern not found', 9, 'ErrorMsg' },
1665      },
1666    })
1667  end)
1668
1669  it('trigger', function()
1670    command('echo "foo"')
1671    screen:expect({
1672      grid = [[
1673        ^                         |
1674        {1:~                        }|*4
1675      ]],
1676      messages = { { content = { { 'foo' } }, kind = 'echo', trigger = '' } },
1677    })
1678    command('map Q :echo "foo"<CR>')
1679    feed('Q')
1680    screen:expect({
1681      grid = [[
1682        ^                         |
1683        {1:~                        }|*4
1684      ]],
1685      messages = { { content = { { 'foo' } }, kind = 'echo', trigger = '' } },
1686    })
1687    feed(':echo "foo"<CR>')
1688    screen:expect({
1689      grid = [[
1690        ^                         |
1691        {1:~                        }|*4
1692      ]],
1693      messages = { { content = { { 'foo' } }, kind = 'echo', trigger = 'typed_cmd' } },
1694    })
1695  end)
1696end)
1697
1698describe('ui/builtin messages', function()
1699  local screen
1700  before_each(function()
1701    clear()
1702    screen = Screen.new(60, 7, { rgb = true, ext_popupmenu = true })
1703    screen:add_extra_attr_ids {
1704      [100] = { background = Screen.colors.LightRed },
1705      [101] = { background = Screen.colors.Grey20 },
1706      [102] = { foreground = Screen.colors.Magenta1, bold = true },
1707    }
1708  end)
1709
1710  it('supports multiline messages from rpc', function()
1711    feed(':call rpcrequest(1, "test_method")<cr>')
1712
1713    screen:expect {
1714      grid = [[
1715        {3:                                                            }|
1716        {9:Invoking 'test_method' on channel 1:}                        |
1717        {9:complete}                                                    |
1718        {9:error}                                                       |
1719                                                                    |
1720        {9:message}                                                     |
1721        {6:Press ENTER or type command to continue}^                     |
1722      ]],
1723      request_cb = function(name)
1724        if name == 'test_method' then
1725          set_method_error('complete\nerror\n\nmessage')
1726        end
1727      end,
1728    }
1729  end)
1730
1731  it('no cursor flicker during :write message (marks UI busy) #25974', function()
1732    local fname = 'Xtest_write_busy'
1733    finally(function()
1734      os.remove(fname)
1735    end)
1736    local busy_start, busy_stop = 0, 0
1737    screen._handle_busy_start = (function(orig)
1738      return function()
1739        orig(screen)
1740        busy_start = busy_start + 1
1741      end
1742    end)(screen._handle_busy_start)
1743    screen._handle_busy_stop = (function(orig)
1744      return function()
1745        orig(screen)
1746        busy_stop = busy_stop + 1
1747      end
1748    end)(screen._handle_busy_stop)
1749    command('write ' .. fname)
1750    screen:expect({ any = 'written' })
1751    eq(true, busy_start >= 1) -- cursor was hidden while the message was emitted
1752    eq(busy_start, busy_stop) -- balanced: cursor restored afterwards
1753  end)
1754
1755  it(':write message not clobbered by v:lua in statusline redraw #40616', function()
1756    local fname = 'Xtest_write_progress'
1757    finally(function()
1758      os.remove(fname)
1759    end)
1760    exec_lua(function()
1761      -- The Progress event fired by the ":write" message (since ff68fd6b8a84)
1762      -- evaluates statusline mid-message.
1763      _G.Statusline = function()
1764        return 'STL'
1765      end
1766      vim.o.laststatus = 2
1767      vim.o.statusline = '%{v:lua.Statusline()}'
1768      vim.api.nvim_create_autocmd('Progress', {
1769        callback = function()
1770          vim.cmd('redrawstatus!')
1771        end,
1772      })
1773    end)
1774    command('write ' .. fname)
1775    -- Should not be overwritten by "return Statusline(...)").
1776    screen:expect({ any = ('"%s".*written'):format(fname) })
1777  end)
1778
1779  it(':hi Group output', function()
1780    screen:try_resize(70, 7)
1781    feed(':hi ErrorMsg<cr>')
1782    screen:expect([[
1783                                                                            |
1784      {1:~                                                                     }|*2
1785      {3:                                                                      }|
1786      :hi ErrorMsg                                                          |
1787      ErrorMsg       {9:xxx} {18:ctermfg=}15 {18:ctermbg=}1 {18:guifg=}White {18:guibg=}Red         |
1788      {6:Press ENTER or type command to continue}^                               |
1789    ]])
1790
1791    feed('<cr>')
1792    screen:try_resize(30, 7)
1793    feed(':hi ErrorMsg<cr>')
1794    screen:expect([[
1795      :hi ErrorMsg                  |
1796      ErrorMsg       {9:xxx} {18:ctermfg=}15 |
1797                         {18:ctermbg=}1  |
1798                         {18:guifg=}White|
1799                         {18:guibg=}Red  |
1800      {6:Press ENTER or type command to}|
1801      {6: continue}^                     |
1802    ]])
1803    feed('<cr>')
1804
1805    -- screen size doesn't affect internal output #10285
1806    eq('ErrorMsg       xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red', exec_capture('hi ErrorMsg'))
1807  end)
1808
1809  it(':syntax list langGroup output', function()
1810    command('syntax on')
1811    exec([[
1812      syn match	vimComment	excludenl +\s"[^\-:.%#=*].*$+lc=1	contains=@vimCommentGroup,vimCommentString
1813      syn match	vimComment	+\<endif\s\+".*$+lc=5	contains=@vimCommentGroup,vimCommentString
1814      syn match	vimComment	+\<else\s\+".*$+lc=4	contains=@vimCommentGroup,vimCommentString
1815      hi link vimComment Comment
1816    ]])
1817    screen:try_resize(110, 7)
1818    feed(':syntax list vimComment<cr>')
1819    screen:expect([[
1820      {102:--- Syntax items ---}                                                                                          |
1821      vimComment     {18:xxx} {18:match} /\s"[^\-:.%#=*].*$/ms=s+1,lc=1  {18:excludenl} {18:contains}=@vimCommentGroup,vimCommentString |
1822                                                                                                                    |
1823                         {18:match} /\<endif\s\+".*$/ms=s+5,lc=5  {18:contains}=@vimCommentGroup,vimCommentString             |
1824                         {18:match} /\<else\s\+".*$/ms=s+4,lc=4  {18:contains}=@vimCommentGroup,vimCommentString              |
1825                         {18:links to} Comment                                                                           |
1826      {6:Press ENTER or type command to continue}^                                                                       |
1827    ]])
1828
1829    feed('<cr>')
1830    screen:try_resize(55, 7)
1831    feed(':syntax list vimComment<cr>')
1832    screen:expect([[
1833                                                             |
1834                         {18:match} /\<endif\s\+".*$/ms=s+5,lc=5  |
1835      {18:contains}=@vimCommentGroup,vimCommentString             |
1836                         {18:match} /\<else\s\+".*$/ms=s+4,lc=4  {18:c}|
1837      {18:ontains}=@vimCommentGroup,vimCommentString              |
1838                         {18:links to} Comment                    |
1839      {6:Press ENTER or type command to continue}^                |
1840    ]])
1841    feed('<cr>')
1842
1843    -- ignore final whitespace inside string
1844    -- luacheck: push ignore
1845    eq(
1846      t.dedent [[
1847        --- Syntax items ---
1848        vimComment     xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1  excludenl contains=@vimCommentGroup,vimCommentString 
1849                           match /\<endif\s\+".*$/ms=s+5,lc=5  contains=@vimCommentGroup,vimCommentString 
1850                           match /\<else\s\+".*$/ms=s+4,lc=4  contains=@vimCommentGroup,vimCommentString 
1851                           links to Comment]],
1852      exec_capture('syntax list vimComment')
1853    )
1854    -- luacheck: pop
1855  end)
1856
1857  it('no empty line after :silent #12099', function()
1858    exec([[
1859      func T1()
1860        silent !echo
1861        echo "message T1"
1862      endfunc
1863      func T2()
1864        silent lua print("lua message")
1865        echo "message T2"
1866      endfunc
1867      func T3()
1868        silent call nvim_out_write("api message\n")
1869        echo "message T3"
1870      endfunc
1871    ]])
1872    feed(':call T1()<CR>')
1873    screen:expect([[
1874      ^                                                            |
1875      {1:~                                                           }|*5
1876      message T1                                                  |
1877    ]])
1878    feed(':call T2()<CR>')
1879    screen:expect([[
1880      ^                                                            |
1881      {1:~                                                           }|*5
1882      message T2                                                  |
1883    ]])
1884    feed(':call T3()<CR>')
1885    screen:expect([[
1886      ^                                                            |
1887      {1:~                                                           }|*5
1888      message T3                                                  |
1889    ]])
1890  end)
1891
1892  it('supports ruler with laststatus=0', function()
1893    command('set laststatus=0 ruler rulerformat=%-15(%c%V\\ %p%%%)')
1894    screen:expect([[
1895      ^                                                            |
1896      {1:~                                                           }|*5
1897                                                   0-1 100%       |
1898    ]])
1899
1900    -- Ruler is cleared when it is no longer drawn.
1901    command('set noruler')
1902    screen:expect([[
1903      ^                                                            |
1904      {1:~                                                           }|*5
1905                                                                  |
1906    ]])
1907
1908    command('set ruler rulerformat&')
1909    screen:expect([[
1910      ^                                                            |
1911      {1:~                                                           }|*5
1912                                                0,0-1          All|
1913    ]])
1914
1915    command('hi MsgArea guibg=#333333')
1916    screen:expect([[
1917      ^                                                            |
1918      {1:~                                                           }|*5
1919      {101:                                          0,0-1          All}|
1920    ]])
1921  end)
1922
1923  it('supports echo with CRLF line separators', function()
1924    feed(':echo "line 1\\r\\nline 2"<cr>')
1925    screen:expect([[
1926                                                                  |
1927      {1:~                                                           }|*2
1928      {3:                                                            }|
1929      line 1                                                      |
1930      line 2                                                      |
1931      {6:Press ENTER or type command to continue}^                     |
1932    ]])
1933
1934    feed('<cr>:echo "abc\\rz"<cr>')
1935    screen:expect([[
1936      ^                                                            |
1937      {1:~                                                           }|*5
1938      zbc                                                         |
1939    ]])
1940  end)
1941
1942  it('redraws UPD_NOT_VALID correctly after message', function()
1943    -- edge case: only one window was set UPD_NOT_VALID. Original report
1944    -- used :make, but fake it using one command to set the current
1945    -- window UPD_NOT_VALID and another to show a long message.
1946    command('set more')
1947    feed(':new<cr><c-w><c-w>')
1948    screen:expect([[
1949                                                                  |
1950      {1:~                                                           }|
1951      {2:[No Name]                                                   }|
1952      ^                                                            |
1953      {1:~                                                           }|
1954      {3:[No Name]                                                   }|
1955      :new                                                        |
1956    ]])
1957
1958    feed(':set colorcolumn=10 | digraphs<cr>')
1959    screen:expect([[
1960      :set colorcolumn=10 | digraphs                              |
1961      NU {18:^@}  10    SH {18:^A}   1    SX {18:^B}   2    EX {18:^C}   3            |
1962      ET {18:^D}   4    EQ {18:^E}   5    AK {18:^F}   6    BL {18:^G}   7            |
1963      BS {18:^H}   8    HT {18:^I}   9    LF {18:^@}  10    VT {18:^K}  11            |
1964      FF {18:^L}  12    CR {18:^M}  13    SO {18:^N}  14    SI {18:^O}  15            |
1965      DL {18:^P}  16    D1 {18:^Q}  17    D2 {18:^R}  18    D3 {18:^S}  19            |
1966      {6:-- More --}^                                                  |
1967    ]])
1968
1969    feed('q')
1970    screen:expect([[
1971                                                                  |
1972      {1:~                                                           }|
1973      {2:[No Name]                                                   }|
1974      ^         {100: }                                                  |
1975      {1:~                                                           }|
1976      {3:[No Name]                                                   }|
1977                                                                  |
1978    ]])
1979
1980    -- edge case: just covers statusline
1981    feed(':set colorcolumn=5 | lua error("x\\n\\nx")<cr>')
1982    screen:expect([[
1983      {9:E5108: Lua: [string ":lua"]:1: x}                            |
1984                                                                  |
1985      {9:x}                                                           |
1986      {9:stack traceback:}                                            |
1987      {9:        [C]: in function 'error'}                            |
1988      {9:        [string ":lua"]:1: in main chunk}                    |
1989      {6:Press ENTER or type command to continue}^                     |
1990    ]])
1991
1992    feed('<cr>')
1993    screen:expect([[
1994                                                                  |
1995      {1:~                                                           }|
1996      {2:[No Name]                                                   }|
1997      ^    {100: }                                                       |
1998      {1:~                                                           }|
1999      {3:[No Name]                                                   }|
2000                                                                  |
2001    ]])
2002
2003    -- edge case: just covers lowest window line
2004    feed(':set colorcolumn=5 | lua error("x\\n\\n\\nx")<cr>')
2005    screen:expect([[
2006      {9:E5108: Lua: [string ":lua"]:1: x}                            |
2007                                                                  |*2
2008      {9:x}                                                           |
2009      {9:stack traceback:}                                            |
2010      {9:        [C]: in function 'error'}                            |
2011      {6:-- More --}^                                                  |
2012    ]])
2013
2014    feed('<cr>')
2015    screen:expect([[
2016                                                                  |*2
2017      {9:x}                                                           |
2018      {9:stack traceback:}                                            |
2019      {9:        [C]: in function 'error'}                            |
2020      {9:        [string ":lua"]:1: in main chunk}                    |
2021      {6:Press ENTER or type command to continue}^                     |
2022    ]])
2023  end)
2024
2025  it('supports nvim_echo messages with multiple attrs', function()
2026    local chunks = { { 'wow, ', 'Search' }, { 'such\n\nvery ', 'ErrorMsg' }, { 'color', 'LineNr' } }
2027    async_meths.nvim_echo(chunks, true, {})
2028    screen:expect([[
2029                                                                  |
2030      {1:~                                                           }|
2031      {3:                                                            }|
2032      {10:wow, }{9:such}                                                   |
2033                                                                  |
2034      {9:very }{8:color}                                                  |
2035      {6:Press ENTER or type command to continue}^                     |
2036    ]])
2037
2038    feed '<cr>'
2039    screen:expect([[
2040      ^                                                            |
2041      {1:~                                                           }|*5
2042                                                                  |
2043    ]])
2044
2045    feed ':messages<cr>'
2046    screen:expect([[
2047                                                                  |
2048      {1:~                                                           }|
2049      {3:                                                            }|
2050      {10:wow, }{9:such}                                                   |
2051                                                                  |
2052      {9:very }{8:color}                                                  |
2053      {6:Press ENTER or type command to continue}^                     |
2054    ]])
2055  end)
2056
2057  it('supports nvim_echo messages with emoji', function()
2058    -- stylua: ignore
2059    async_meths.nvim_echo({ { 'wow, 🏳️‍⚧️🧑‍🌾❤️😂🏴‍☠️\nvariant ❤️ one\nvariant ❤ two' } }, true, {})
2060
2061    screen:expect([[
2062                                                                  |
2063      {1:~                                                           }|
2064      {3:                                                            }|
2065      wow, 🏳️‍⚧️🧑‍🌾❤️😂🏴‍☠️                                             |
2066      variant ❤️ one                                              |
2067      variant ❤ two                                               |
2068      {6:Press ENTER or type command to continue}^                     |
2069    ]])
2070
2071    feed '<cr>'
2072    screen:expect([[
2073      ^                                                            |
2074      {1:~                                                           }|*5
2075                                                                  |
2076    ]])
2077
2078    feed ':messages<cr>'
2079    screen:expect([[
2080                                                                  |
2081      {1:~                                                           }|
2082      {3:                                                            }|
2083      wow, 🏳️‍⚧️🧑‍🌾❤️😂🏴‍☠️                                             |
2084      variant ❤️ one                                              |
2085      variant ❤ two                                               |
2086      {6:Press ENTER or type command to continue}^                     |
2087    ]])
2088  end)
2089
2090  it('prints lines in Ex mode correctly with a burst of carriage returns #19341', function()
2091    command('set number')
2092    api.nvim_buf_set_lines(0, 0, 0, true, { 'aaa', 'bbb', 'ccc' })
2093    -- Empty lines advance the cursor and print; a bare address moves and prints.
2094    feed('gg1q:<CR><CR>1<CR><CR>')
2095    screen:expect({ any = vim.pesc('" bbb') })
2096    feed('vi<CR>')
2097    screen:expect([[
2098      {8:  2 }^bbb                                                     |
2099      {8:  3 }ccc                                                     |
2100      {8:  4 }                                                        |
2101      {1:~                                                           }|*3
2102                                                                  |
2103    ]])
2104  end)
2105
2106  describe('echo messages are shown when immediately followed by', function()
2107    --- @param to_block  string           command to cause a blocking wait
2108    --- @param to_unblock  number|string  number: timeout for blocking screen
2109    ---                                   string: keys to stop the blocking wait
2110    local function test_flush_before_block(to_block, to_unblock)
2111      local timeout = type(to_unblock) == 'number' and to_unblock or nil
2112      exec(([[
2113        func PrintAndWait()
2114          echon "aaa\nbbb"
2115          %s
2116          echon "\nccc"
2117        endfunc
2118      ]]):format(to_block))
2119      feed(':call PrintAndWait()')
2120      screen:expect([[
2121                                                                    |
2122        {1:~                                                           }|*5
2123        :call PrintAndWait()^                                        |
2124      ]])
2125      feed('<CR>')
2126      screen:expect {
2127        grid = [[
2128                                                                      |
2129          {1:~                                                           }|*3
2130          {3:                                                            }|
2131          aaa                                                         |
2132          bbb^                                                         |
2133        ]],
2134        timeout = timeout,
2135      }
2136      if type(to_unblock) == 'string' then
2137        feed(to_unblock)
2138      end
2139      screen:expect([[
2140                                                                    |
2141        {1:~                                                           }|
2142        {3:                                                            }|
2143        aaa                                                         |
2144        bbb                                                         |
2145        ccc                                                         |
2146        {6:Press ENTER or type command to continue}^                     |
2147      ]])
2148    end
2149
2150    it('getchar()', function()
2151      test_flush_before_block([[call getchar()]], 'k')
2152    end)
2153
2154    it('wait()', function()
2155      test_flush_before_block([[call wait(300, '0')]], 100)
2156    end)
2157
2158    it('lua vim.wait()', function()
2159      test_flush_before_block([[lua vim.wait(300, function() end)]], 100)
2160    end)
2161  end)
2162
2163  it('consecutive calls to win_move_statusline() work after multiline message #21014', function()
2164    async_meths.nvim_exec(
2165      [[
2166      echo "\n"
2167      call win_move_statusline(0, -4)
2168      call win_move_statusline(0, 4)
2169    ]],
2170      false
2171    )
2172    screen:expect([[
2173                                                                  |
2174      {1:~                                                           }|*3
2175      {3:                                                            }|
2176                                                                  |
2177      {6:Press ENTER or type command to continue}^                     |
2178    ]])
2179    feed('<CR>')
2180    screen:expect([[
2181      ^                                                            |
2182      {1:~                                                           }|*5
2183                                                                  |
2184    ]])
2185    eq(1, api.nvim_get_option_value('cmdheight', {}))
2186  end)
2187
2188  it('using nvim_echo in VimResized does not cause hit-enter prompt #26139', function()
2189    command([[au VimResized * lua vim.api.nvim_echo({ { '123456' } }, true, {})]])
2190    screen:try_resize(60, 5)
2191    screen:expect([[
2192      ^                                                            |
2193      {1:~                                                           }|*3
2194                                                                  |
2195    ]])
2196    eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
2197  end)
2198
2199  it('bottom of screen is cleared after increasing &cmdheight #20360', function()
2200    command('set laststatus=2')
2201    screen:expect([[
2202      ^                                                            |
2203      {1:~                                                           }|*4
2204      {3:[No Name]                                                   }|
2205                                                                  |
2206    ]])
2207    command('set cmdheight=4')
2208    screen:expect([[
2209      ^                                                            |
2210      {1:~                                                           }|
2211      {3:[No Name]                                                   }|
2212                                                                  |*4
2213    ]])
2214  end)
2215
2216  it('supports :intro with cmdheight=0 #26505', function()
2217    screen:try_resize(80, 24)
2218    command('set cmdheight=0')
2219    feed(':intro<CR>')
2220    screen:expect([[
2221                                                                                      |*3
2222                                           {16:│} {26:╲} {26:││}                                     |
2223                                           {16:││}{26:╲╲││}                                     |
2224                                           {16:││} {26:╲} {26:│}                                     |
2225                                                                                      |
2226      {MATCH:.*}|
2227                        {1:────────────────────────────────────────────}                  |
2228                        Nvim is open source and freely distributable                  |
2229                                  https://neovim.io/#chat                             |
2230                        {1:────────────────────────────────────────────}                  |
2231                        type  {18::}{25:help nvim}{18:<Enter>}     if you are new!                   |
2232                        type  {18::}{25:checkhealth}{18:<Enter>}   to optimize Nvim                  |
2233                        type  {18::}{25:q}{18:<Enter>}             to exit                           |
2234                        type  {18::}{25:help}{18:<Enter>}          for help                          |
2235                        {1:────────────────────────────────────────────}                  |
2236                        type  {18::}{25:help news}{18:<Enter>}     for v{MATCH:%d+%.%d+} notes{MATCH: *}|
2237                        {1:────────────────────────────────────────────}                  |
2238                               Help poor children in Uganda!                          |
2239                        type  {18::}{25:help Kuwasha}{18:<Enter>}  for information                   |
2240                                                                                      |*2
2241      ^                                                                                |
2242    ]])
2243    feed('<CR>')
2244    assert_alive()
2245  end)
2246
2247  it(':intro with small screen #38396', function()
2248    screen:try_resize(80, 6)
2249    feed(':intro<CR>')
2250    screen:expect({ any = 'NVIM' })
2251    feed('<CR>')
2252    assert_alive()
2253  end)
2254
2255  it('no wait return before delayed exception error message', function()
2256    screen:try_resize(70, 7)
2257    feed('ia<esc>:lua vim.cmd.quit()<CR>')
2258    screen:expect({
2259      any = {
2260        '{9:.*Vim:E37: No write since.*}',
2261        '{6:Press ENTER or type command to continue}^',
2262      },
2263    })
2264  end)
2265end)
2266
2267it('calling screenstring() after redrawing between messages without UI #20999', function()
2268  clear()
2269  exec([[
2270    echo repeat('a', 100)
2271    redraw
2272    echo "\n"
2273    call screenstring(1, 1)
2274  ]])
2275  assert_alive()
2276end)
2277
2278describe('ui/ext_messages', function()
2279  local screen
2280
2281  before_each(function()
2282    clear { args_rm = { '--headless' }, args = { '--cmd', 'set shortmess-=I' } }
2283    screen = Screen.new(80, 24, { rgb = true, ext_messages = true, ext_popupmenu = true })
2284  end)
2285
2286  it('supports intro screen', function()
2287    -- intro message is not externalized. But check that it still works.
2288    -- Note parts of it depends on version or is indeterministic. We ignore those parts.
2289    local introscreen = [[
2290      ^                                                                                |
2291      {1:~                                                                               }|*2
2292      {1:~                                    }{16:│} {26:╲} {26:││}{1:                                     }|
2293      {1:~                                    }{16:││}{26:╲╲││}{1:                                     }|
2294      {1:~                                    }{16:││} {26:╲} {26:│}{1:                                     }|
2295      {1:~                                                                               }|
2296      {1:~{MATCH: +}}{26:NVIM {MATCH:%S+}}{1:{MATCH: +}}|
2297      {1:~                 ────────────────────────────────────────────                  }|
2298      {1:~                 }Nvim is open source and freely distributable{1:                  }|
2299      {1:~                           }https://neovim.io/#chat{1:                             }|
2300      {1:~                 ────────────────────────────────────────────                  }|
2301      {1:~                 }type  {18::}{25:help nvim}{18:<Enter>}     if you are new! {1:                  }|
2302      {1:~                 }type  {18::}{25:checkhealth}{18:<Enter>}   to optimize Nvim{1:                  }|
2303      {1:~                 }type  {18::}{25:q}{18:<Enter>}             to exit         {1:                  }|
2304      {1:~                 }type  {18::}{25:help}{18:<Enter>}          for help        {1:                  }|
2305      {1:~                 ────────────────────────────────────────────                  }|
2306      {1:~                 }type  {18::}{25:help news}{18:<Enter>}     for v{MATCH:%d+%.%d+} notes {1:{MATCH: +}}|
2307      {1:~                 ────────────────────────────────────────────                  }|
2308      {1:~                        }Help poor children in Uganda!{1:                          }|
2309      {1:~                 }type  {18::}{25:help Kuwasha}{18:<Enter>}  for information {1:                  }|
2310      {1:~                                                                               }|*3
2311    ]]
2312    local showmode = { { '-- INSERT --', 5, 'ModeMsg' } }
2313    screen:expect(introscreen)
2314
2315    -- <c-l> (same as :mode) does _not_ clear intro message
2316    feed('<c-l>i')
2317    screen:expect { grid = introscreen, showmode = showmode }
2318
2319    -- opening a float without focus also does not
2320    local win = api.nvim_open_win(api.nvim_create_buf(false, false), false, {
2321      relative = 'editor',
2322      height = 1,
2323      width = 5,
2324      row = 1,
2325      col = 5,
2326    })
2327    screen:expect {
2328      grid = [[
2329        ^                                                                                |
2330        {1:~    }{4:     }{1:                                                                      }|
2331        {1:~                                                                               }|
2332        {1:~                                    }{16:│} {26:╲} {26:││}{1:                                     }|
2333        {1:~                                    }{16:││}{26:╲╲││}{1:                                     }|
2334        {1:~                                    }{16:││} {26:╲} {26:│}{1:                                     }|
2335        {1:~                                                                               }|
2336        {1:~{MATCH: +}}{26:NVIM {MATCH:%S+}}{1:{MATCH: +}}|
2337        {1:~                 ────────────────────────────────────────────                  }|
2338        {1:~                 }Nvim is open source and freely distributable{1:                  }|
2339        {1:~                           }https://neovim.io/#chat{1:                             }|
2340        {1:~                 ────────────────────────────────────────────                  }|
2341        {1:~                 }type  {18::}{25:help nvim}{18:<Enter>}     if you are new! {1:                  }|
2342        {1:~                 }type  {18::}{25:checkhealth}{18:<Enter>}   to optimize Nvim{1:                  }|
2343        {1:~                 }type  {18::}{25:q}{18:<Enter>}             to exit         {1:                  }|
2344        {1:~                 }type  {18::}{25:help}{18:<Enter>}          for help        {1:                  }|
2345        {1:~                 ────────────────────────────────────────────                  }|
2346        {1:~                 }type  {18::}{25:help news}{18:<Enter>}     for v{MATCH:%d+%.%d+} notes {1:{MATCH: +}}|
2347        {1:~                 ────────────────────────────────────────────                  }|
2348        {1:~                        }Help poor children in Uganda!{1:                          }|
2349        {1:~                 }type  {18::}{25:help Kuwasha}{18:<Enter>}  for information {1:                  }|
2350        {1:~                                                                               }|*3
2351      ]],
2352      showmode = showmode,
2353    }
2354
2355    api.nvim_win_close(win, true)
2356    screen:expect { grid = introscreen, showmode = showmode }
2357
2358    -- but editing text does..
2359    feed('x')
2360    screen:expect {
2361      grid = [[
2362        x^                                                                               |
2363        {1:~                                                                               }|*23
2364      ]],
2365      showmode = showmode,
2366    }
2367
2368    feed('<esc>:intro<cr>')
2369    screen:expect {
2370      grid = [[
2371        ^                                                                                |
2372                                                                                        |*2
2373                                             {16:│} {26:╲} {26:││}                                     |
2374                                             {16:││}{26:╲╲││}                                     |
2375                                             {16:││} {26:╲} {26:│}                                     |
2376                                                                                        |
2377        {MATCH: +}{26:NVIM {MATCH:%S+}}{MATCH: +}|
2378                          {1:────────────────────────────────────────────}                  |
2379                          Nvim is open source and freely distributable                  |
2380                                    https://neovim.io/#chat                             |
2381                          {1:────────────────────────────────────────────}                  |
2382                          type  {18::}{25:help nvim}{18:<Enter>}     if you are new!                   |
2383                          type  {18::}{25:checkhealth}{18:<Enter>}   to optimize Nvim                  |
2384                          type  {18::}{25:q}{18:<Enter>}             to exit                           |
2385                          type  {18::}{25:help}{18:<Enter>}          for help                          |
2386                          {1:────────────────────────────────────────────}                  |
2387                          type  {18::}{25:help news}{18:<Enter>}     for v{MATCH:%d+%.%d+} notes {MATCH: +}|
2388                          {1:────────────────────────────────────────────}                  |
2389                                 Help poor children in Uganda!                          |
2390                          type  {18::}{25:help Kuwasha}{18:<Enter>}  for information                   |
2391                                                                                        |*3
2392      ]],
2393    }
2394
2395    feed('<cr>')
2396    screen:expect([[
2397      ^x                                                                               |
2398      {1:~                                                                               }|*23
2399    ]])
2400  end)
2401
2402  it('clears intro screen when new buffer is active', function()
2403    api.nvim_set_current_buf(api.nvim_create_buf(true, false))
2404    screen:expect([[
2405      ^                                                                                |
2406      {1:~                                                                               }|*23
2407    ]])
2408  end)
2409
2410  it('clears intro screen when new buffer is active in floating window', function()
2411    local win_opts = { relative = 'editor', height = 1, width = 5, row = 1, col = 5 }
2412    api.nvim_open_win(api.nvim_create_buf(false, false), true, win_opts)
2413    screen:expect([[
2414                                                                                      |
2415      {1:~    }{4:^     }{1:                                                                      }|
2416      {1:~                                                                               }|*22
2417    ]])
2418  end)
2419
2420  it('clears intro screen when initial buffer is active in floating window', function()
2421    local win_opts = { relative = 'editor', height = 1, width = 5, row = 1, col = 5 }
2422    api.nvim_open_win(api.nvim_get_current_buf(), true, win_opts)
2423    screen:expect([[
2424                                                                                      |
2425      {1:~    }{4:^     }{1:                                                                      }|
2426      {1:~                                                                               }|*22
2427    ]])
2428  end)
2429
2430  it('clears intro screen when initial window is converted to be floating', function()
2431    exec_lua([[
2432      local init_win_id = vim.api.nvim_get_current_win()
2433      vim.cmd('split')
2434      local win_opts = { relative = 'editor', height = 1, width = 5, row = 1, col = 5 }
2435      vim.api.nvim_win_set_config(init_win_id, win_opts)
2436      vim.api.nvim_set_current_win(init_win_id)
2437    ]])
2438    screen:expect([[
2439                                                                                      |
2440      {1:~    }{4:^     }{1:                                                                      }|
2441      {1:~                                                                               }|*22
2442    ]])
2443  end)
2444
2445  it('supports global statusline', function()
2446    feed(':set laststatus=3<cr>')
2447    feed(':sp<cr>')
2448    feed(':set cmdheight<cr>')
2449    screen:expect({
2450      grid = [[
2451        ^                                                                                |
2452        {1:~                                                                               }|*10
2453        ────────────────────────────────────────────────────────────────────────────────|
2454                                                                                        |
2455        {1:~                                                                               }|*10
2456        {3:[No Name]                                                                       }|
2457      ]],
2458      messages = { { content = { { '  cmdheight=0' } }, kind = 'list_cmd' } },
2459    })
2460
2461    feed('<c-w>+')
2462    feed(':set laststatus<cr>')
2463    screen:expect({
2464      grid = [[
2465        ^                                                                                |
2466        {1:~                                                                               }|*11
2467        ────────────────────────────────────────────────────────────────────────────────|
2468                                                                                        |
2469        {1:~                                                                               }|*9
2470        {3:[No Name]                                                                       }|
2471      ]],
2472      messages = { { content = { { '  laststatus=3' } }, kind = 'list_cmd' } },
2473    })
2474
2475    feed(':set mouse=a<cr>')
2476    api.nvim_input_mouse('left', 'press', '', 0, 12, 10)
2477    poke_eventloop()
2478    api.nvim_input_mouse('left', 'drag', '', 0, 11, 10)
2479    feed('<c-l>')
2480    feed(':set cmdheight<cr>')
2481    screen:expect({
2482      grid = [[
2483        ^                                                                                |
2484        {1:~                                                                               }|*10
2485        ────────────────────────────────────────────────────────────────────────────────|
2486                                                                                        |
2487        {1:~                                                                               }|*10
2488        {3:[No Name]                                                                       }|
2489      ]],
2490      messages = { { content = { { '  cmdheight=0' } }, kind = 'list_cmd' } },
2491    })
2492  end)
2493end)
2494
2495it('ui/ext_multigrid supports intro screen', function()
2496  clear { args_rm = { '--headless' }, args = { '--cmd', 'set shortmess-=I' } }
2497  local screen = Screen.new(80, 24, { rgb = true, ext_multigrid = true })
2498
2499  screen:expect {
2500    grid = [[
2501    ## grid 1
2502      [2:--------------------------------------------------------------------------------]|*23
2503      [3:--------------------------------------------------------------------------------]|
2504    ## grid 2
2505      ^                                                                                |
2506      {1:~                                                                               }|*2
2507      {1:~                                    }{16:│} {26:╲} {26:││}{1:                                     }|
2508      {1:~                                    }{16:││}{26:╲╲││}{1:                                     }|
2509      {1:~                                    }{16:││} {26:╲} {26:│}{1:                                     }|
2510      {1:~                                                                               }|
2511      {1:~{MATCH: +}}{26:NVIM {MATCH:%S+}}{1:{MATCH: +}}|
2512      {1:~                 ────────────────────────────────────────────                  }|
2513      {1:~                 }Nvim is open source and freely distributable{1:                  }|
2514      {1:~                           }https://neovim.io/#chat{1:                             }|
2515      {1:~                 ────────────────────────────────────────────                  }|
2516      {1:~                 }type  {18::}{25:help nvim}{18:<Enter>}     if you are new! {1:                  }|
2517      {1:~                 }type  {18::}{25:checkhealth}{18:<Enter>}   to optimize Nvim{1:                  }|
2518      {1:~                 }type  {18::}{25:q}{18:<Enter>}             to exit         {1:                  }|
2519      {1:~                 }type  {18::}{25:help}{18:<Enter>}          for help        {1:                  }|
2520      {1:~                 ────────────────────────────────────────────                  }|
2521      {1:~                 }type  {18::}{25:help news}{18:<Enter>}     for v{MATCH:%d+%.%d+} notes {1:{MATCH: +}}|
2522      {1:~                 ────────────────────────────────────────────                  }|
2523      {1:~                        }Help poor children in Uganda!{1:                          }|
2524      {1:~                 }type  {18::}{25:help Kuwasha}{18:<Enter>}  for information {1:                  }|
2525      {1:~                                                                               }|*2
2526    ## grid 3
2527                                                                                      |
2528    ]],
2529    win_viewport = {
2530      [2] = {
2531        win = 1000,
2532        topline = 0,
2533        botline = 2,
2534        curline = 0,
2535        curcol = 0,
2536        linecount = 1,
2537        sum_scroll_delta = 0,
2538      },
2539    },
2540  }
2541
2542  feed 'ix'
2543  screen:expect {
2544    grid = [[
2545    ## grid 1
2546      [2:--------------------------------------------------------------------------------]|*23
2547      [3:--------------------------------------------------------------------------------]|
2548    ## grid 2
2549      x^                                                                               |
2550      {1:~                                                                               }|*22
2551    ## grid 3
2552      {5:-- INSERT --}                                                                    |
2553    ]],
2554    win_viewport = {
2555      [2] = {
2556        win = 1000,
2557        topline = 0,
2558        botline = 2,
2559        curline = 0,
2560        curcol = 1,
2561        linecount = 1,
2562        sum_scroll_delta = 0,
2563      },
2564    },
2565  }
2566end)
2567
2568describe('ui/msg_puts_printf', function()
2569  it('output multibyte characters correctly', function()
2570    skip(not t.translations_enabled(), 'N/A: Nvim not built with ENABLE_TRANSLATIONS')
2571    local screen
2572    local cmd = ''
2573    local build_dir = t.paths.test_build_dir
2574    local locale_dir = build_dir .. '/share/locale/ja/LC_MESSAGES'
2575
2576    clear({ env = { LANG = 'ja_JP.UTF-8' } })
2577    screen = Screen.new(25, 5)
2578
2579    if is_os('win') then
2580      if os.execute('chcp 932 > NUL 2>&1') ~= 0 then
2581        pending('missing japanese language features', function() end)
2582        return
2583      else
2584        cmd = 'chcp 932 > NUL & '
2585      end
2586    else
2587      if not pcall(n.command, 'lang ja_JP.UTF-8') then
2588        pending('Locale ja_JP.UTF-8 not supported', function() end)
2589        return
2590      end
2591    end
2592
2593    fn.mkdir(locale_dir, 'p')
2594    fn.filecopy(build_dir .. '/src/nvim/po/ja.mo', locale_dir .. '/nvim.mo')
2595    -- "-Es" doesn't read stdin as commands, and the "Entering Ex mode" banner was removed, so
2596    -- ":print" a translated message via "-S" (silent mode suppresses ":echo" output). #40966
2597    t.write_file(
2598      'Xes_ja.vim',
2599      [[call setline(1, gettext("Entering Ex mode.  Type \"visual\" to go to Normal mode."))]]
2600        .. '\n'
2601        .. '.print\n'
2602    )
2603    finally(function()
2604      os.remove('Xes_ja.vim')
2605      n.rmdir(vim.fs.dirname(locale_dir))
2606    end)
2607
2608    cmd = cmd .. '"' .. nvim_prog .. '" -u NONE -i NONE -Es -S Xes_ja.vim'
2609    command([[call jobstart(']] .. cmd .. [[',{'term':v:true})]])
2610    screen:expect([[
2611      ^Exモードに入ります。ノー |
2612      マルモードに戻るには "vis|
2613      ual" と入力してください。|
2614      [Process exited 0]       |
2615                               |
2616    ]])
2617  end)
2618end)
2619
2620describe('pager', function()
2621  local screen
2622
2623  before_each(function()
2624    clear()
2625    screen = Screen.new(35, 8)
2626    screen:set_default_attr_ids({
2627      [1] = { bold = true, foreground = Screen.colors.Blue1 },
2628      [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
2629      [3] = {
2630        foreground = Screen.colors.Grey100,
2631        background = Screen.colors.Red,
2632        special = Screen.colors.Yellow,
2633      },
2634      [4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
2635      [5] = { special = Screen.colors.Yellow },
2636      [6] = { special = Screen.colors.Yellow, bold = true, foreground = Screen.colors.SeaGreen4 },
2637      [7] = { foreground = Screen.colors.Grey0, background = Screen.colors.Grey100 },
2638      [8] = { foreground = Screen.colors.Gray90, background = Screen.colors.Grey100 },
2639      [9] = { foreground = tonumber('0x00000c'), background = Screen.colors.Grey100 },
2640      [10] = { background = Screen.colors.Grey100, bold = true, foreground = tonumber('0xe5e5ff') },
2641      [11] = { background = Screen.colors.Grey100, bold = true, foreground = tonumber('0x2b8452') },
2642      [12] = { bold = true, reverse = true },
2643      [13] = { foreground = Screen.colors.Grey0 },
2644      [14] = { foreground = Screen.colors.Grey90 },
2645      [15] = { foreground = tonumber('0x00000c') },
2646      [16] = { bold = true, foreground = tonumber('0xe5e5ff') },
2647      [17] = { bold = true, foreground = tonumber('0x2b8452') },
2648    })
2649    command('set more')
2650
2651    exec_lua(
2652      '_G.x = ...',
2653      t.dedent [[
2654        Lorem ipsum dolor sit amet, consectetur
2655        adipisicing elit, sed do eiusmod tempor
2656        incididunt ut labore et dolore magna aliqua.
2657        Ut enim ad minim veniam, quis nostrud xercitation
2658        ullamco laboris nisi ut
2659        aliquip ex ea commodo consequat.
2660      ]]
2661    )
2662  end)
2663
2664  it('can be quit with echon', function()
2665    screen:try_resize(25, 5)
2666    feed(':echon join(map(range(0, &lines*10), "v:val"), "\\n")<cr>')
2667    screen:expect([[
2668      0                        |
2669      1                        |
2670      2                        |
2671      3                        |
2672      {4:-- More --}^               |
2673    ]])
2674    feed('q')
2675    screen:expect([[
2676      ^                         |
2677      {1:~                        }|*3
2678                               |
2679    ]])
2680  end)
2681
2682  it('can be quit with Lua #11224 #16537', function()
2683    screen:try_resize(40, 5)
2684    feed(':lua for i=0,10 do print(i) end<cr>')
2685    screen:expect([[
2686      0                                       |
2687      1                                       |
2688      2                                       |
2689      3                                       |
2690      {4:-- More --}^                              |
2691    ]])
2692    feed('q')
2693    screen:expect([[
2694      ^                                        |
2695      {1:~                                       }|*3
2696                                              |
2697    ]])
2698    feed(':mess<cr>')
2699    screen:expect([[
2700      0                                       |
2701      1                                       |
2702      2                                       |
2703      3                                       |
2704      {4:-- More --}^                              |
2705    ]])
2706    feed('G')
2707    screen:expect([[
2708      7                                       |
2709      8                                       |
2710      9                                       |
2711      10                                      |
2712      {4:Press ENTER or type command to continue}^ |
2713    ]])
2714    feed('<cr>')
2715  end)
2716
2717  it('handles wrapped lines with line scroll', function()
2718    feed(':lua error(_G.x)<cr>')
2719    screen:expect([[
2720      {2:E5108: Lua: [string ":lua"]:1: Lore}|
2721      {2:m ipsum dolor sit amet, consectetur}|
2722                                         |
2723      {2:adipisicing elit, sed do eiusmod te}|
2724      {2:mpor}                               |
2725      {2:incididunt ut labore et dolore magn}|
2726      {2:a aliqua.}                          |
2727      {4:-- More --}^                         |
2728    ]])
2729
2730    feed('j')
2731    screen:expect([[
2732      {2:m ipsum dolor sit amet, consectetur}|
2733                                         |
2734      {2:adipisicing elit, sed do eiusmod te}|
2735      {2:mpor}                               |
2736      {2:incididunt ut labore et dolore magn}|
2737      {2:a aliqua.}                          |
2738      {2:Ut enim ad minim veniam, quis nostr}|
2739      {4:-- More --}^                         |
2740    ]])
2741
2742    feed('k')
2743    screen:expect([[
2744      {2:E5108: Lua: [string ":lua"]:1: Lore}|
2745      {2:m ipsum dolor sit amet, consectetur}|
2746                                         |
2747      {2:adipisicing elit, sed do eiusmod te}|
2748      {2:mpor}                               |
2749      {2:incididunt ut labore et dolore magn}|
2750      {2:a aliqua.}                          |
2751      {4:-- More --}^                         |
2752    ]])
2753
2754    feed('j')
2755    screen:expect([[
2756      {2:m ipsum dolor sit amet, consectetur}|
2757                                         |
2758      {2:adipisicing elit, sed do eiusmod te}|
2759      {2:mpor}                               |
2760      {2:incididunt ut labore et dolore magn}|
2761      {2:a aliqua.}                          |
2762      {2:Ut enim ad minim veniam, quis nostr}|
2763      {4:-- More --}^                         |
2764    ]])
2765  end)
2766
2767  it('handles wrapped lines with page scroll', function()
2768    feed(':lua error(_G.x)<cr>')
2769    screen:expect([[
2770      {2:E5108: Lua: [string ":lua"]:1: Lore}|
2771      {2:m ipsum dolor sit amet, consectetur}|
2772                                         |
2773      {2:adipisicing elit, sed do eiusmod te}|
2774      {2:mpor}                               |
2775      {2:incididunt ut labore et dolore magn}|
2776      {2:a aliqua.}                          |
2777      {4:-- More --}^                         |
2778    ]])
2779    feed('d')
2780    screen:expect([[
2781      {2:mpor}                               |
2782      {2:incididunt ut labore et dolore magn}|
2783      {2:a aliqua.}                          |
2784      {2:Ut enim ad minim veniam, quis nostr}|
2785      {2:ud xercitation}                     |
2786      {2:ullamco laboris nisi ut}            |
2787      {2:aliquip ex ea commodo consequat.}   |
2788      {4:-- More --}^                         |
2789    ]])
2790    feed('u')
2791    screen:expect([[
2792      {2:E5108: Lua: [string ":lua"]:1: Lore}|
2793      {2:m ipsum dolor sit amet, consectetur}|
2794                                         |
2795      {2:adipisicing elit, sed do eiusmod te}|
2796      {2:mpor}                               |
2797      {2:incididunt ut labore et dolore magn}|
2798      {2:a aliqua.}                          |
2799      {4:-- More --}^                         |
2800    ]])
2801    feed('d')
2802    screen:expect([[
2803      {2:mpor}                               |
2804      {2:incididunt ut labore et dolore magn}|
2805      {2:a aliqua.}                          |
2806      {2:Ut enim ad minim veniam, quis nostr}|
2807      {2:ud xercitation}                     |
2808      {2:ullamco laboris nisi ut}            |
2809      {2:aliquip ex ea commodo consequat.}   |
2810      {4:-- More --}^                         |
2811    ]])
2812  end)
2813
2814  it('handles wrapped lines with line scroll and MsgArea highlight', function()
2815    command('hi MsgArea guisp=Yellow')
2816
2817    feed(':lua error(_G.x)<cr>')
2818    screen:expect([[
2819      {3:E5108: Lua: [string ":lua"]:1: Lore}|
2820      {3:m ipsum dolor sit amet, consectetur}|
2821      {5:                                   }|
2822      {3:adipisicing elit, sed do eiusmod te}|
2823      {3:mpor}{5:                               }|
2824      {3:incididunt ut labore et dolore magn}|
2825      {3:a aliqua.}{5:                          }|
2826      {6:-- More --}{5:^                         }|
2827    ]])
2828
2829    feed('j')
2830    screen:expect([[
2831      {3:m ipsum dolor sit amet, consectetur}|
2832      {5:                                   }|
2833      {3:adipisicing elit, sed do eiusmod te}|
2834      {3:mpor}{5:                               }|
2835      {3:incididunt ut labore et dolore magn}|
2836      {3:a aliqua.}{5:                          }|
2837      {3:Ut enim ad minim veniam, quis nostr}|
2838      {6:-- More --}{5:^                         }|
2839    ]])
2840
2841    feed('k')
2842    screen:expect([[
2843      {3:E5108: Lua: [string ":lua"]:1: Lore}|
2844      {3:m ipsum dolor sit amet, consectetur}|
2845      {5:                                   }|
2846      {3:adipisicing elit, sed do eiusmod te}|
2847      {3:mpor}{5:                               }|
2848      {3:incididunt ut labore et dolore magn}|
2849      {3:a aliqua.}{5:                          }|
2850      {6:-- More --}{5:^                         }|
2851    ]])
2852
2853    feed('j')
2854    screen:expect([[
2855      {3:m ipsum dolor sit amet, consectetur}|
2856      {5:                                   }|
2857      {3:adipisicing elit, sed do eiusmod te}|
2858      {3:mpor}{5:                               }|
2859      {3:incididunt ut labore et dolore magn}|
2860      {3:a aliqua.}{5:                          }|
2861      {3:Ut enim ad minim veniam, quis nostr}|
2862      {6:-- More --}{5:^                         }|
2863    ]])
2864  end)
2865
2866  it('handles wrapped lines with page scroll and MsgArea highlight', function()
2867    command('hi MsgArea guisp=Yellow')
2868    feed(':lua error(_G.x)<cr>')
2869    screen:expect([[
2870      {3:E5108: Lua: [string ":lua"]:1: Lore}|
2871      {3:m ipsum dolor sit amet, consectetur}|
2872      {5:                                   }|
2873      {3:adipisicing elit, sed do eiusmod te}|
2874      {3:mpor}{5:                               }|
2875      {3:incididunt ut labore et dolore magn}|
2876      {3:a aliqua.}{5:                          }|
2877      {6:-- More --}{5:^                         }|
2878    ]])
2879    feed('d')
2880    screen:expect([[
2881      {3:mpor}{5:                               }|
2882      {3:incididunt ut labore et dolore magn}|
2883      {3:a aliqua.}{5:                          }|
2884      {3:Ut enim ad minim veniam, quis nostr}|
2885      {3:ud xercitation}{5:                     }|
2886      {3:ullamco laboris nisi ut}{5:            }|
2887      {3:aliquip ex ea commodo consequat.}{5:   }|
2888      {6:-- More --}{5:^                         }|
2889    ]])
2890    feed('u')
2891    screen:expect([[
2892      {3:E5108: Lua: [string ":lua"]:1: Lore}|
2893      {3:m ipsum dolor sit amet, consectetur}|
2894      {5:                                   }|
2895      {3:adipisicing elit, sed do eiusmod te}|
2896      {3:mpor}{5:                               }|
2897      {3:incididunt ut labore et dolore magn}|
2898      {3:a aliqua.}{5:                          }|
2899      {6:-- More --}{5:^                         }|
2900    ]])
2901    feed('d')
2902    screen:expect([[
2903      {3:mpor}{5:                               }|
2904      {3:incididunt ut labore et dolore magn}|
2905      {3:a aliqua.}{5:                          }|
2906      {3:Ut enim ad minim veniam, quis nostr}|
2907      {3:ud xercitation}{5:                     }|
2908      {3:ullamco laboris nisi ut}{5:            }|
2909      {3:aliquip ex ea commodo consequat.}{5:   }|
2910      {6:-- More --}{5:^                         }|
2911    ]])
2912  end)
2913
2914  it('preserves MsgArea highlighting after more prompt', function()
2915    screen:try_resize(70, 6)
2916    command('hi MsgArea guisp=Yellow')
2917    command('map x Lorem ipsum labore et dolore magna aliqua')
2918    command('map y adipisicing elit')
2919    command('map z incididunt ut')
2920    command('map a labore et dolore')
2921    command('map b ex ea commodo')
2922    command('map xx yy')
2923    command('map xy yz')
2924    feed(':map<cr>')
2925    screen:expect([[
2926      {5:   a             labore et dolore                                     }|
2927      {5:   b             ex ea commodo                                        }|
2928      {5:   xy            yz                                                   }|
2929      {5:   xx            yy                                                   }|
2930      {5:   x             Lorem ipsum labore et dolore magna aliqua            }|
2931      {6:-- More --}{5:^                                                            }|
2932    ]])
2933    feed('j')
2934    screen:expect([[
2935      {5:   b             ex ea commodo                                        }|
2936      {5:   xy            yz                                                   }|
2937      {5:   xx            yy                                                   }|
2938      {5:   x             Lorem ipsum labore et dolore magna aliqua            }|
2939      {5:   y             adipisicing elit                                     }|
2940      {6:-- More --}{5:^                                                            }|
2941    ]])
2942    feed('j')
2943    screen:expect([[
2944      {5:   xy            yz                                                   }|
2945      {5:   xx            yy                                                   }|
2946      {5:   x             Lorem ipsum labore et dolore magna aliqua            }|
2947      {5:   y             adipisicing elit                                     }|
2948      {5:   z             incididunt ut                                        }|
2949      {6:Press ENTER or type command to continue}{5:^                               }|
2950    ]])
2951  end)
2952
2953  it('clears "-- more --" message', function()
2954    command('hi MsgArea guisp=Yellow blend=10')
2955    feed(':echon join(range(20), "\\n")<cr>')
2956    screen:expect([[
2957      {13:0}{14:                                  }|
2958      {15:1}{16:                                  }|
2959      {15:2}{16:                                  }|
2960      {15:3}{16:                                  }|
2961      {15:4}{16:                                  }|
2962      {15:5}{16:                                  }|
2963      {15:6}{16:                                  }|
2964      {17:--}{14: }{17:More}{14: }{17:--}{14:^                         }|
2965    ]])
2966
2967    feed('j')
2968    screen:expect([[
2969      {13:1}{14:                                  }|
2970      {15:2}{16:                                  }|
2971      {15:3}{16:                                  }|
2972      {15:4}{16:                                  }|
2973      {15:5}{16:                                  }|
2974      {15:6}{16:                                  }|
2975      {15:7}{16:                                  }|
2976      {17:--}{14: }{17:More}{14: }{17:--}{14:^                         }|
2977    ]])
2978
2979    feed('k')
2980    screen:expect([[
2981      {13:0}{14:                                  }|
2982      {15:1}{16:                                  }|
2983      {15:2}{16:                                  }|
2984      {15:3}{16:                                  }|
2985      {15:4}{16:                                  }|
2986      {15:5}{16:                                  }|
2987      {15:6}{16:                                  }|
2988      {17:--}{14: }{17:More}{14: }{17:--}{14:^                         }|
2989    ]])
2990
2991    feed('j')
2992    screen:expect([[
2993      {13:1}{14:                                  }|
2994      {15:2}{16:                                  }|
2995      {15:3}{16:                                  }|
2996      {15:4}{16:                                  }|
2997      {15:5}{16:                                  }|
2998      {15:6}{16:                                  }|
2999      {15:7}{16:                                  }|
3000      {17:--}{14: }{17:More}{14: }{17:--}{14:^                         }|
3001    ]])
3002  end)
3003
3004  it('with :!cmd does not crash on resize', function()
3005    skip(fn.executable('sleep') == 0, 'missing "sleep" command')
3006    feed(':!sleep 1<cr>')
3007    screen:expect([[
3008                                         |
3009      {1:~                                  }|*4
3010      {12:                                   }|
3011      :!sleep 1                          |
3012                                         |
3013    ]])
3014
3015    -- not processed while command is executing
3016    async_meths.nvim_ui_try_resize(35, 5)
3017
3018    -- TODO(bfredl): ideally it should be processed just
3019    -- before the "press ENTER" prompt though
3020    screen:expect([[
3021                                         |
3022      {1:~                                  }|*2
3023      {12:                                   }|
3024      :!sleep 1                          |
3025                                         |
3026      {4:Press ENTER or type command to cont}|
3027      {4:inue}^                               |
3028    ]])
3029
3030    feed('<cr>')
3031    screen:expect([[
3032      ^                                   |
3033      {1:~                                  }|*3
3034                                         |
3035    ]])
3036  end)
3037
3038  it('can be resized', function()
3039    feed(':lua error(_G.x)<cr>')
3040    screen:expect([[
3041      {2:E5108: Lua: [string ":lua"]:1: Lore}|
3042      {2:m ipsum dolor sit amet, consectetur}|
3043                                         |
3044      {2:adipisicing elit, sed do eiusmod te}|
3045      {2:mpor}                               |
3046      {2:incididunt ut labore et dolore magn}|
3047      {2:a aliqua.}                          |
3048      {4:-- More --}^                         |
3049    ]])
3050
3051    -- responds to resize, but text is not reflown
3052    screen:try_resize(45, 5)
3053    screen:expect([[
3054      {2:adipisicing elit, sed do eiusmod te}          |
3055      {2:mpor}                                         |
3056      {2:incididunt ut labore et dolore magn}          |
3057      {2:a aliqua.}                                    |
3058      {4:-- More --}^                                   |
3059    ]])
3060
3061    -- can create empty space, as the command hasn't output the text below yet.
3062    -- text is not reflown; existing lines get cut
3063    screen:try_resize(30, 12)
3064    screen:expect([[
3065      :lua error(_G.x)              |
3066      {2:E5108: Lua: [string ":lua"]:1:}|
3067      {2:m ipsum dolor sit amet, consec}|
3068      {2:tetur}                         |
3069      {2:adipisicing elit, sed do eiusm}|
3070      {2:mpore}                         |
3071      {2:incididunt ut labore et dolore}|
3072      {2:a aliqua.}                     |
3073                                    |*3
3074      {4:-- More --}^                    |
3075    ]])
3076
3077    -- continues in a mostly consistent state, but only new lines are
3078    -- wrapped at the new screen size.
3079    feed('<cr>')
3080    screen:expect([[
3081      {2:E5108: Lua: [string ":lua"]:1:}|
3082      {2:m ipsum dolor sit amet, consec}|
3083      {2:tetur}                         |
3084      {2:adipisicing elit, sed do eiusm}|
3085      {2:mpore}                         |
3086      {2:incididunt ut labore et dolore}|
3087      {2:a aliqua.}                     |
3088      {2:Ut enim ad minim veniam, quis }|
3089      {2:nostrud xercitation}           |
3090      {2:ullamco laboris nisi ut}       |
3091      {2:aliquip ex ea commodo consequa}|
3092      {4:-- More --}^                    |
3093    ]])
3094
3095    feed('<cr>')
3096    screen:expect([[
3097      {2:m ipsum dolor sit amet, consec}|
3098      {2:tetur}                         |
3099      {2:adipisicing elit, sed do eiusm}|
3100      {2:mpore}                         |
3101      {2:incididunt ut labore et dolore}|
3102      {2:a aliqua.}                     |
3103      {2:Ut enim ad minim veniam, quis }|
3104      {2:nostrud xercitation}           |
3105      {2:ullamco laboris nisi ut}       |
3106      {2:aliquip ex ea commodo consequa}|
3107      {2:t.}                            |
3108      {4:-- More --}^                    |
3109    ]])
3110
3111    feed('q')
3112    screen:expect([[
3113      ^                              |
3114      {1:~                             }|*10
3115                                    |
3116    ]])
3117  end)
3118
3119  it('with cmdheight=0 does not crash with g<', function()
3120    command('set cmdheight=0')
3121    feed(':ls<cr>')
3122    screen:expect([[
3123                                         |
3124      {1:~                                  }|
3125      {12:                                   }|
3126      :ls                                |
3127        1 %a   "[No Name]"               |
3128           line 1                        |
3129      {4:Press ENTER or type command to cont}|
3130      {4:inue}^                               |
3131    ]])
3132
3133    feed('<cr>')
3134    screen:expect([[
3135      ^                                   |
3136      {1:~                                  }|*7
3137    ]])
3138
3139    feed('g<lt>')
3140    screen:expect([[
3141                                         |
3142      {1:~                                  }|
3143      {12:                                   }|
3144      :ls                                |
3145        1 %a   "[No Name]"               |
3146           line 1                        |
3147      {4:Press ENTER or type command to cont}|
3148      {4:inue}^                               |
3149    ]])
3150
3151    feed('<cr>')
3152    screen:expect([[
3153      ^                                   |
3154      {1:~                                  }|*7
3155    ]])
3156  end)
3157
3158  it('g< shows blank line from :echo properly', function()
3159    screen:try_resize(60, 8)
3160    feed([[:echo 1 | echo "\n" | echo 2<CR>]])
3161    screen:expect([[
3162                                                                  |
3163      {1:~                                                           }|*2
3164      {12:                                                            }|
3165      1                                                           |
3166                                                                  |
3167      2                                                           |
3168      {4:Press ENTER or type command to continue}^                     |
3169    ]])
3170
3171    feed('<CR>')
3172    screen:expect([[
3173      ^                                                            |
3174      {1:~                                                           }|*6
3175                                                                  |
3176    ]])
3177
3178    feed('g<lt>')
3179    screen:expect([[
3180                                                                  |
3181      {1:~                                                           }|
3182      {12:                                                            }|
3183      :echo 1 | echo "\n" | echo 2                                |
3184      1                                                           |
3185                                                                  |
3186      2                                                           |
3187      {4:Press ENTER or type command to continue}^                     |
3188    ]])
3189
3190    feed('<CR>')
3191    screen:expect([[
3192      ^                                                            |
3193      {1:~                                                           }|*6
3194                                                                  |
3195    ]])
3196  end)
3197
3198  it('scrolling works properly when :echo output ends with newline', function()
3199    screen:try_resize(60, 6)
3200    feed([[:echo range(100)->join("\n") .. "\n"<CR>]])
3201    screen:expect([[
3202      0                                                           |
3203      1                                                           |
3204      2                                                           |
3205      3                                                           |
3206      4                                                           |
3207      {4:-- More --}^                                                  |
3208    ]])
3209    feed('G')
3210    screen:expect([[
3211      96                                                          |
3212      97                                                          |
3213      98                                                          |
3214      99                                                          |
3215                                                                  |
3216      {4:Press ENTER or type command to continue}^                     |
3217    ]])
3218    for _ = 1, 3 do
3219      feed('k')
3220      screen:expect([[
3221        95                                                          |
3222        96                                                          |
3223        97                                                          |
3224        98                                                          |
3225        99                                                          |
3226        {4:-- More --}^                                                  |
3227      ]])
3228      feed('k')
3229      screen:expect([[
3230        94                                                          |
3231        95                                                          |
3232        96                                                          |
3233        97                                                          |
3234        98                                                          |
3235        {4:-- More --}^                                                  |
3236      ]])
3237      feed('j')
3238      screen:expect([[
3239        95                                                          |
3240        96                                                          |
3241        97                                                          |
3242        98                                                          |
3243        99                                                          |
3244        {4:-- More --}^                                                  |
3245      ]])
3246      feed('j')
3247      screen:expect([[
3248        96                                                          |
3249        97                                                          |
3250        98                                                          |
3251        99                                                          |
3252                                                                    |
3253        {4:-- More --}^                                                  |
3254      ]])
3255      feed('j')
3256      screen:expect([[
3257        96                                                          |
3258        97                                                          |
3259        98                                                          |
3260        99                                                          |
3261                                                                    |
3262        {4:Press ENTER or type command to continue}^                     |
3263      ]])
3264    end
3265  end)
3266
3267  it('scrolling works properly when :!cmd output ends with newline #27902', function()
3268    screen:try_resize(60, 6)
3269    api.nvim_set_option_value('shell', testprg('shell-test'), {})
3270    api.nvim_set_option_value('shellcmdflag', 'REP 100', {})
3271    api.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
3272    feed([[:!foo<CR>]])
3273    screen:expect([[
3274      96: foo                                                     |
3275      97: foo                                                     |
3276      98: foo                                                     |
3277      99: foo                                                     |
3278                                                                  |
3279      {4:Press ENTER or type command to continue}^                     |
3280    ]])
3281    for _ = 1, 3 do
3282      feed('k')
3283      screen:expect([[
3284        95: foo                                                     |
3285        96: foo                                                     |
3286        97: foo                                                     |
3287        98: foo                                                     |
3288        99: foo                                                     |
3289        {4:-- More --}^                                                  |
3290      ]])
3291      feed('k')
3292      screen:expect([[
3293        94: foo                                                     |
3294        95: foo                                                     |
3295        96: foo                                                     |
3296        97: foo                                                     |
3297        98: foo                                                     |
3298        {4:-- More --}^                                                  |
3299      ]])
3300      feed('j')
3301      screen:expect([[
3302        95: foo                                                     |
3303        96: foo                                                     |
3304        97: foo                                                     |
3305        98: foo                                                     |
3306        99: foo                                                     |
3307        {4:-- More --}^                                                  |
3308      ]])
3309      feed('j')
3310      screen:expect([[
3311        96: foo                                                     |
3312        97: foo                                                     |
3313        98: foo                                                     |
3314        99: foo                                                     |
3315                                                                    |
3316        {4:-- More --}^                                                  |
3317      ]])
3318      feed('j')
3319      screen:expect([[
3320        96: foo                                                     |
3321        97: foo                                                     |
3322        98: foo                                                     |
3323        99: foo                                                     |
3324                                                                    |
3325        {4:Press ENTER or type command to continue}^                     |
3326      ]])
3327    end
3328  end)
3329end)
3330
3331it('pager works in headless mode with UI attached', function()
3332  clear()
3333  local child_server = assert(n.new_pipename())
3334  fn.jobstart({ nvim_prog, '--clean', '--headless', '--listen', child_server })
3335  retry(nil, nil, function()
3336    neq(nil, vim.uv.fs_stat(child_server))
3337  end)
3338
3339  local child_session = n.connect(child_server)
3340  local child_screen = Screen.new(40, 6, nil, child_session)
3341  child_screen._default_attr_ids = nil -- TODO: unskip with new color scheme
3342
3343  child_session:notify('nvim_command', [[echo range(100)->join("\n")]])
3344  child_screen:expect([[
3345    0                                       |
3346    1                                       |
3347    2                                       |
3348    3                                       |
3349    4                                       |
3350    -- More --^                              |
3351  ]])
3352
3353  child_session:request('nvim_input', 'G')
3354  child_screen:expect([[
3355    95                                      |
3356    96                                      |
3357    97                                      |
3358    98                                      |
3359    99                                      |
3360    Press ENTER or type command to continue^ |
3361  ]])
3362
3363  child_session:request('nvim_input', 'g')
3364  child_screen:expect([[
3365    0                                       |
3366    1                                       |
3367    2                                       |
3368    3                                       |
3369    4                                       |
3370    -- More --^                              |
3371  ]])
3372end)
3373
3374describe('progress-message', function()
3375  local screen
3376
3377  local function setup_autocmd(pattern)
3378    exec_lua(function()
3379      local grp = vim.api.nvim_create_augroup('ProgressListener', { clear = true })
3380      _G.progress_autocmd_result = nil
3381      vim.api.nvim_create_autocmd('Progress', {
3382        pattern = pattern,
3383        group = grp,
3384        callback = function(ev)
3385          _G.progress_autocmd_result = ev.data
3386        end,
3387      })
3388    end)
3389  end
3390
3391  local function assert_progress_autocmd(expected, context)
3392    local progress_autocmd_result = exec_lua(function()
3393      return _G.progress_autocmd_result
3394    end)
3395    eq(expected, progress_autocmd_result, context)
3396    exec_lua(function()
3397      _G.progress_autocmd_result = nil
3398    end)
3399  end
3400
3401  local function setup_screen(with_ext_msg)
3402    if with_ext_msg then
3403      screen = Screen.new(25, 5, { ext_messages = true })
3404      screen:add_extra_attr_ids {
3405        [100] = { undercurl = true, special = Screen.colors.Red },
3406        [101] = { foreground = Screen.colors.Magenta1, bold = true },
3407        [102] = { foreground = Screen.colors.NvimDarkGreen },
3408      }
3409    else
3410      screen = Screen.new(40, 5)
3411    end
3412  end
3413
3414  before_each(function()
3415    clear()
3416    setup_screen(true)
3417    setup_autocmd()
3418  end)
3419
3420  it('emitted by nvim_echo', function()
3421    local id = api.nvim_echo(
3422      { { 'test-message' } },
3423      true,
3424      { kind = 'progress', title = 'testsuit', percent = 10, status = 'running', source = 'tests' }
3425    )
3426
3427    screen:expect({
3428      grid = [[
3429        ^                         |
3430        {1:~                        }|*4
3431      ]],
3432      messages = {
3433        {
3434          content = {
3435            { 'testsuit', 6, 'MoreMsg' },
3436            { ': ' },
3437            { ' 10% ', 19, 'WarningMsg' },
3438            { 'test-message' },
3439          },
3440          history = true,
3441          id = 1,
3442          kind = 'progress',
3443        },
3444      },
3445    })
3446    assert_progress_autocmd({
3447      text = { 'test-message' },
3448      percent = 10,
3449      source = 'tests',
3450      status = 'running',
3451      title = 'testsuit',
3452      id = 1,
3453      data = {},
3454    }, 'progress autocmd receives progress messages')
3455
3456    -- can update progress messages
3457    api.nvim_echo({ { 'test-message-updated' } }, true, {
3458      id = id,
3459      kind = 'progress',
3460      source = 'tests',
3461      title = 'TestSuit',
3462      percent = 50,
3463      status = 'running',
3464    })
3465    screen:expect({
3466      grid = [[
3467        ^                         |
3468        {1:~                        }|*4
3469      ]],
3470      messages = {
3471        {
3472          content = {
3473            { 'TestSuit', 6, 'MoreMsg' },
3474            { ': ' },
3475            { ' 50% ', 19, 'WarningMsg' },
3476            { 'test-message-updated' },
3477          },
3478          history = true,
3479          id = 1,
3480          kind = 'progress',
3481        },
3482      },
3483    })
3484
3485    assert_progress_autocmd({
3486      text = { 'test-message-updated' },
3487      percent = 50,
3488      source = 'tests',
3489      status = 'running',
3490      title = 'TestSuit',
3491      id = 1,
3492      data = {},
3493    }, 'Progress autocmd receives progress update')
3494
3495    -- success status
3496    api.nvim_echo(
3497      { { 'test-message (success)' } },
3498      true,
3499      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 100, status = 'success' }
3500    )
3501    screen:expect({
3502      grid = [[
3503        ^                         |
3504        {1:~                        }|*4
3505      ]],
3506      messages = {
3507        {
3508          content = {
3509            { 'TestSuit', 102, 'OkMsg' },
3510            { ': ' },
3511            { '100% ', 19, 'WarningMsg' },
3512            { 'test-message (success)' },
3513          },
3514          history = true,
3515          id = 2,
3516          kind = 'progress',
3517        },
3518      },
3519    })
3520
3521    -- failed status
3522    api.nvim_echo(
3523      { { 'test-message (fail)' } },
3524      true,
3525      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 35, status = 'failed' }
3526    )
3527    screen:expect({
3528      grid = [[
3529        ^                         |
3530        {1:~                        }|*4
3531      ]],
3532      messages = {
3533        {
3534          content = {
3535            { 'TestSuit', 9, 'ErrorMsg' },
3536            { ': ' },
3537            { ' 35% ', 19, 'WarningMsg' },
3538            { 'test-message (fail)' },
3539          },
3540          history = true,
3541          id = 3,
3542          kind = 'progress',
3543        },
3544      },
3545    })
3546
3547    -- cancel status
3548    api.nvim_echo(
3549      { { 'test-message (cancel)' } },
3550      true,
3551      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 30, status = 'cancel' }
3552    )
3553    screen:expect({
3554      grid = [[
3555        ^                         |
3556        {1:~                        }|*4
3557      ]],
3558      messages = {
3559        {
3560          content = {
3561            { 'TestSuit', 19, 'WarningMsg' },
3562            { ': ' },
3563            { ' 30% ', 19, 'WarningMsg' },
3564            { 'test-message (cancel)' },
3565          },
3566          history = true,
3567          id = 4,
3568          kind = 'progress',
3569        },
3570      },
3571    })
3572
3573    -- without title and percent
3574    api.nvim_echo(
3575      { { 'test-message (no-tile or percent)' } },
3576      true,
3577      { kind = 'progress', source = 'tests', status = 'cancel' }
3578    )
3579    screen:expect({
3580      grid = [[
3581        ^                         |
3582        {1:~                        }|*4
3583      ]],
3584      messages = {
3585        {
3586          content = { { 'test-message (no-tile or percent)' } },
3587          history = true,
3588          id = 5,
3589          kind = 'progress',
3590        },
3591      },
3592    })
3593
3594    -- progress event can filter by source
3595    setup_autocmd('Tests')
3596    api.nvim_echo(
3597      { { 'test-message-updated' } },
3598      true,
3599      { id = id, kind = 'progress', source = 'other_source', percent = 80, status = 'running' }
3600    )
3601    assert_progress_autocmd(nil, 'No progress message with Tests source yet')
3602
3603    api.nvim_echo({ { 'test-message-updated' } }, true, {
3604      id = id,
3605      kind = 'progress',
3606      title = 'Title',
3607      percent = 100,
3608      status = 'success',
3609      source = 'Tests',
3610    })
3611    assert_progress_autocmd({
3612      text = { 'test-message-updated' },
3613      percent = 100,
3614      source = 'Tests',
3615      status = 'success',
3616      title = 'Title',
3617      id = 1,
3618      data = {},
3619    }, 'Progress autocmd receives progress update')
3620  end)
3621
3622  it('user-defined data', function()
3623    api.nvim_echo({ { 'test-message' } }, true, {
3624      kind = 'progress',
3625      title = 'TestSuit',
3626      percent = 10,
3627      source = 'tests',
3628      status = 'running',
3629      data = { test_attribute = 1 },
3630    })
3631
3632    screen:expect({
3633      grid = [[
3634        ^                         |
3635        {1:~                        }|*4
3636      ]],
3637      messages = {
3638        {
3639          content = {
3640            { 'TestSuit', 6, 'MoreMsg' },
3641            { ': ' },
3642            { ' 10% ', 19, 'WarningMsg' },
3643            { 'test-message' },
3644          },
3645          history = true,
3646          id = 1,
3647          kind = 'progress',
3648        },
3649      },
3650    })
3651    assert_progress_autocmd({
3652      text = { 'test-message' },
3653      percent = 10,
3654      source = 'tests',
3655      status = 'running',
3656      title = 'TestSuit',
3657      id = 1,
3658      data = { test_attribute = 1 },
3659    }, 'Progress autocmd receives progress messages')
3660  end)
3661
3662  it('validation', function()
3663    -- throws error if title, status, percent, data is used in non progress message
3664    eq(
3665      "Conflict: title/source/status/percent/data not allowed with kind='echo'",
3666      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, { title = 'TestSuit' })
3667    )
3668
3669    eq(
3670      "Conflict: title/source/status/percent/data not allowed with kind='echo'",
3671      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, { status = 'running' })
3672    )
3673
3674    eq(
3675      "Conflict: title/source/status/percent/data not allowed with kind='echo'",
3676      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, { percent = 0 })
3677    )
3678
3679    eq(
3680      "Conflict: title/source/status/percent/data not allowed with kind='echo'",
3681      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, { data = { tag = 'test' } })
3682    )
3683
3684    eq(
3685      "Conflict: title/source/status/percent/data not allowed with kind='echo'",
3686      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, { source = 'tests' })
3687    )
3688
3689    -- throws error if anything other then running/success/failed/cancel is used in status
3690    eq(
3691      "Invalid 'status': expected success|failed|running|cancel, got live",
3692      t.pcall_err(
3693        api.nvim_echo,
3694        { { 'test-message' } },
3695        false,
3696        { kind = 'progress', source = 'tests', status = 'live' }
3697      )
3698    )
3699
3700    -- throws error if parcent is not in 0-100
3701    eq(
3702      "Invalid 'percent': out of range",
3703      t.pcall_err(
3704        api.nvim_echo,
3705        { { 'test-message' } },
3706        false,
3707        { kind = 'progress', source = 'tests', status = 'running', percent = -1 }
3708      )
3709    )
3710
3711    eq(
3712      "Invalid 'percent': out of range",
3713      t.pcall_err(
3714        api.nvim_echo,
3715        { { 'test-message' } },
3716        false,
3717        { kind = 'progress', source = 'tests', status = 'running', percent = 101 }
3718      )
3719    )
3720
3721    -- throws error if data is not a dictionary
3722    eq(
3723      "Invalid 'data': expected Dict, got String",
3724      t.pcall_err(api.nvim_echo, { { 'test-message' } }, false, {
3725        kind = 'progress',
3726        source = 'tests',
3727        title = 'TestSuit',
3728        percent = 10,
3729        status = 'running',
3730        data = 'test',
3731      })
3732    )
3733
3734    -- throws error if source is not given
3735    eq(
3736      "Required: 'opts.source'",
3737      t.pcall_err(
3738        api.nvim_echo,
3739        { { 'test-message' } },
3740        false,
3741        { kind = 'progress', status = 'running' }
3742      )
3743    )
3744  end)
3745
3746  it('gets placed in history', function()
3747    local id = api.nvim_echo(
3748      { { 'test-message 10' } },
3749      true,
3750      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 10, status = 'running' }
3751    )
3752    eq('TestSuit:  10% test-message 10', exec_capture('messages'))
3753
3754    api.nvim_echo({ { 'test-message 20' } }, true, {
3755      id = id,
3756      kind = 'progress',
3757      source = 'tests',
3758      title = 'TestSuit',
3759      percent = 20,
3760      status = 'running',
3761    })
3762    eq('TestSuit:  10% test-message 10\nTestSuit:  20% test-message 20', exec_capture('messages'))
3763
3764    api.nvim_echo({ { 'middle msg' } }, true, {})
3765    eq(
3766      'TestSuit:  10% test-message 10\nTestSuit:  20% test-message 20\nmiddle msg',
3767      exec_capture('messages')
3768    )
3769    api.nvim_echo({ { 'test-message 30' } }, true, {
3770      id = id,
3771      kind = 'progress',
3772      source = 'tests',
3773      title = 'TestSuit',
3774      percent = 30,
3775      status = 'running',
3776    })
3777    eq(
3778      'TestSuit:  10% test-message 10\nTestSuit:  20% test-message 20\nmiddle msg\nTestSuit:  30% test-message 30',
3779      exec_capture('messages')
3780    )
3781
3782    api.nvim_echo({ { 'test-message 50' } }, true, {
3783      id = id,
3784      kind = 'progress',
3785      source = 'tests',
3786      title = 'TestSuit',
3787      percent = 50,
3788      status = 'running',
3789    })
3790    eq(
3791      'TestSuit:  10% test-message 10\nTestSuit:  20% test-message 20\nmiddle msg\nTestSuit:  30% test-message 30\nTestSuit:  50% test-message 50',
3792      exec_capture('messages')
3793    )
3794  end)
3795
3796  it('sets msg-id correctly', function()
3797    local id1 = api.nvim_echo(
3798      { { 'test-message 10' } },
3799      true,
3800      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 10, status = 'running' }
3801    )
3802    eq(1, id1)
3803
3804    local id2 = api.nvim_echo(
3805      { { 'test-message 20' } },
3806      true,
3807      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 20, status = 'running' }
3808    )
3809    eq(2, id2)
3810
3811    local id3 = api.nvim_echo({ { 'normal message' } }, true, {})
3812    eq(3, id3)
3813
3814    local id4 = api.nvim_echo({ { 'without history' } }, false, {})
3815    eq(4, id4)
3816
3817    local id5 = api.nvim_echo(
3818      { { 'test-message 30' } },
3819      true,
3820      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 30, status = 'running' }
3821    )
3822    eq(5, id5)
3823
3824    -- updating progress message does not create new msg-id
3825    local id5_update = api.nvim_echo({ { 'test-message 40' } }, true, {
3826      id = id5,
3827      kind = 'progress',
3828      source = 'tests',
3829      title = 'TestSuit',
3830      percent = 40,
3831      status = 'running',
3832    })
3833    eq(id5, id5_update)
3834
3835    local id6 = api.nvim_echo(
3836      { { 'test-message 30' } },
3837      true,
3838      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 30, status = 'running' }
3839    )
3840    eq(6, id6)
3841
3842    local id7 = api.nvim_echo({ { 'supports str-id' } }, true, {
3843      id = 'str-id',
3844      kind = 'progress',
3845      source = 'tests',
3846      title = 'TestSuit',
3847      percent = 30,
3848      status = 'running',
3849    })
3850    eq('str-id', id7)
3851
3852    -- internal messages are also assigned an ID (and thus advance the next progress ID)
3853    feed('@@')
3854    local id8 = api.nvim_echo(
3855      { { 'test-message 30' } },
3856      true,
3857      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 30, status = 'running' }
3858    )
3859    eq(8, id8)
3860  end)
3861
3862  it('msg-id is not inherited by the next message #41417', function()
3863    local fname = 'Xtest_progress_msgid'
3864    finally(function()
3865      os.remove(fname)
3866    end)
3867    -- The write emits nothing ('msg_silent'), but must still release its msg-id.
3868    command('silent write ' .. fname)
3869    feed(':echoerr "boom"<CR>')
3870    screen:expect({
3871      messages = {
3872        {
3873          content = { { 'boom', 9, 'ErrorMsg' } },
3874          history = true,
3875          id = 1,
3876          kind = 'echoerr',
3877        },
3878      },
3879    })
3880  end)
3881
3882  it('accepts caller-defined id (string)', function()
3883    -- string id works
3884    local id = api.nvim_echo({ { 'supports str-id' } }, true, {
3885      id = 'str-id',
3886      kind = 'progress',
3887      source = 'tests',
3888      title = 'TestSuit',
3889      percent = 30,
3890      status = 'running',
3891    })
3892    eq('str-id', id)
3893
3894    screen:expect({
3895      grid = [[
3896        ^                         |
3897        {1:~                        }|*4
3898      ]],
3899      messages = {
3900        {
3901          content = {
3902            { 'TestSuit', 6, 'MoreMsg' },
3903            { ': ' },
3904            { ' 30% ', 19, 'WarningMsg' },
3905            { 'supports str-id' },
3906          },
3907          history = true,
3908          id = 'str-id',
3909          kind = 'progress',
3910        },
3911      },
3912    })
3913
3914    local id_update = api.nvim_echo({ { 'supports str-id updated' } }, true, {
3915      id = id,
3916      kind = 'progress',
3917      source = 'tests',
3918      title = 'testsuit',
3919      percent = 40,
3920      status = 'running',
3921    })
3922    eq(id, id_update)
3923    assert_progress_autocmd({
3924      text = { 'supports str-id updated' },
3925      percent = 40,
3926      source = 'tests',
3927      status = 'running',
3928      title = 'testsuit',
3929      id = 'str-id',
3930      data = {},
3931    })
3932  end)
3933
3934  it('emitted by :write, not by :read #41193', function()
3935    local fname = 'Xtest_progress_bufwrite'
3936    finally(function()
3937      os.remove(fname)
3938    end)
3939    command('write ' .. fname)
3940    assert_progress_autocmd({
3941      data = {},
3942      id = ('nvim.bufwrite "%s"'):format(fname),
3943      source = 'nvim',
3944      status = 'success',
3945      text = { ('"%s" [New] 0L, 0B written'):format(fname) },
3946      title = '',
3947    })
3948
3949    -- ":read" is not a write: it must not start a progress that never ends.
3950    command('read ' .. fname)
3951    assert_progress_autocmd(nil)
3952
3953    -- A failed write ends the progress-msg.
3954    local events = exec_lua(function(f)
3955      local out = {}
3956      vim.api.nvim_create_autocmd('Progress', {
3957        callback = function(ev)
3958          table.insert(out, { id = ev.data.id, status = ev.data.status, text = ev.data.text[1] })
3959        end,
3960      })
3961      pcall(vim.cmd.write, ('%s/nodir'):format(f))
3962      return out
3963    end, fname)
3964    eq({ 'running', 'failed' }, { events[1].status, events[2].status })
3965    eq(events[1].id, events[2].id)
3966    t.matches('^E%d+:', events[2].text)
3967  end)
3968
3969  it('emitted by ins-completion scan', function()
3970    fn.writefile({ 'foobar', 'foobaz' }, 'Xdict')
3971    finally(function()
3972      os.remove('Xdict')
3973    end)
3974    exec_lua(function()
3975      _G.events = {}
3976      vim.api.nvim_create_autocmd('Progress', {
3977        callback = function(ev)
3978          table.insert(_G.events, ('%s %s'):format(ev.data.id, ev.data.status))
3979        end,
3980      })
3981    end)
3982    command('set shortmess-=C complete=kXdict')
3983    -- Ends when scanning ends, regardless of whether popupmenu is open.
3984    feed('ifoo<C-n>')
3985    eq({ 'nvim.completion running', 'nvim.completion success' }, exec_lua('return _G.events'))
3986  end)
3987
3988  it('tui displays progress message in proper format', function()
3989    clear()
3990    setup_screen(false)
3991    api.nvim_echo(
3992      { { 'test-message' } },
3993      true,
3994      { kind = 'progress', source = 'tests', title = 'TestSuit', percent = 10, status = 'running' }
3995    )
3996    screen:expect([[
3997      ^                                        |
3998      {1:~                                       }|*3
3999      {6:TestSuit}: {19: 10% }test-message             |
4000    ]])
4001  end)
4002
4003  it('works with history off', function()
4004    api.nvim_echo({ { 'test-message' } }, false, {
4005      kind = 'progress',
4006      title = 'TestSuit',
4007      percent = 10,
4008      source = 'tests',
4009      status = 'running',
4010    })
4011
4012    screen:expect({
4013      grid = [[
4014        ^                         |
4015        {1:~                        }|*4
4016      ]],
4017      messages = {
4018        {
4019          content = {
4020            { 'TestSuit', 6, 'MoreMsg' },
4021            { ': ' },
4022            { ' 10% ', 19, 'WarningMsg' },
4023            { 'test-message' },
4024          },
4025          id = 1,
4026          kind = 'progress',
4027        },
4028      },
4029    })
4030
4031    assert_progress_autocmd({
4032      text = { 'test-message' },
4033      percent = 10,
4034      source = 'tests',
4035      status = 'running',
4036      title = 'TestSuit',
4037      id = 1,
4038      data = {},
4039    }, 'progress autocmd receives progress messages')
4040  end)
4041
4042  it('can be hidden from cmdline with messagesopt-=progress:c', function()
4043    exec('set messagesopt-=progress:c')
4044    api.nvim_echo(
4045      { { 'test-message: not shown in cmdline' } },
4046      true,
4047      { kind = 'progress', source = 'tests', title = 'TestSuite', percent = 10, status = 'running' }
4048    )
4049    screen:expect([[
4050      ^                         |
4051      {1:~                        }|*4
4052    ]])
4053
4054    assert_progress_autocmd({
4055      text = { 'test-message: not shown in cmdline' },
4056      percent = 10,
4057      source = 'tests',
4058      status = 'running',
4059      title = 'TestSuite',
4060      id = 1,
4061      data = {},
4062    }, 'progress autocmd still receives progress even with progress messages hidden from cmd')
4063
4064    exec('set messagesopt+=progress:c')
4065    api.nvim_echo(
4066      { { 'test-message: shown in cmdline' } },
4067      true,
4068      { kind = 'progress', source = 'tests', title = 'TestSuite', percent = 10, status = 'running' }
4069    )
4070    screen:expect({
4071      grid = [[
4072        ^                         |
4073        {1:~                        }|*4
4074      ]],
4075      messages = {
4076        {
4077          content = {
4078            { 'TestSuite', 6, 'MoreMsg' },
4079            { ': ' },
4080            { ' 10% ', 19, 'WarningMsg' },
4081            { 'test-message: shown in cmdline' },
4082          },
4083          history = true,
4084          id = 2,
4085          kind = 'progress',
4086        },
4087      },
4088    })
4089
4090    assert_progress_autocmd({
4091      text = { 'test-message: shown in cmdline' },
4092      percent = 10,
4093      source = 'tests',
4094      status = 'running',
4095      title = 'TestSuite',
4096      id = 2,
4097      data = {},
4098    }, 'progress autocmd still receives progresswith progress messages shown in cmd')
4099  end)
4100end)