robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI. 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each , after_each , finally = 8t . describe , t . it , t . before_each , t . after_each , t . finally 9local api , clear , command , exec_lua , feed =n . api , n . clear , n . command , n . exec_lua , n . feed 10 11local msg_timeout =400 12local function set_msg_target_zero_ch () 13exec_lua ( function () 14vim . o . messagesopt ='hit-enter,history:500,progress:c,timeout:' .. msg_timeout 15require ( 'vim._core.ui2' ). enable ( { msg ={ targets ='msg' } } ) 16vim . o . cmdheight =0 17end ) 18end 19 20describe ( 'messages2' , function () 21local screen 22before_each ( function () 23clear () 24screen =Screen . new () 25screen : add_extra_attr_ids ( { 26[ 100 ] ={ foreground =Screen . colors . Magenta1 , bold =true } , 27} ) 28exec_lua ( function () 29require ( 'vim._core.ui2' ). enable ( {} ) 30end ) 31end ) 32after_each ( function () 33-- Since ui2 module lasts until Nvim exits, there may be unfinished timers. 34-- Close unfinished timers to avoid 2s delay on exit with ASAN or TSAN. 35exec_lua ( function () 36vim . uv . walk ( function ( handle ) 37if not handle : is_closing () then 38handle : close () 39end 40end ) 41end ) 42end ) 43 44it ( 'multiline messages and pager' , function () 45command ( 'set ruler showcmd noshowmode | echo "foo\nbar"' ) 46screen : expect ( [[ 47^ | 48{1:~ }|*10 49{3: }| 50foo | 51bar | 52]] ) 53feed ( 'g' ) 54screen : expect ( [[ 55^ | 56{1:~ }|*10 57{3: }| 58foo | 59bar g | 60]] ) 61feed ( '<lt>' ) 62screen : expect ( [[ 63| 64{1:~ }|*9 65{3: }| 66^foo | 67bar | 681,1 All| 69]] ) 70-- Multiple messages in same event loop iteration are appended and shown in full. 71feed ( [[q:echo "foo" | echo "bar\nbaz\n"->repeat(&lines)<CR>]] ) 72screen : expect ( [[ 73^ | 74{1:~ }|*5 75{3: }| 76foo | 77bar | 78baz | 79bar | 80baz | 81bar | 82baz{6: [+23]} | 83]] ) 84-- Any key press resizes the cmdline and updates the spill indicator. 85feed ( 'j' ) 86screen : expect ( { any ={ '+29' } } ) 87command ( 'echo "foo"' ) 88-- New message clears spill indicator. 89screen : expect ( [[ 90^ | 91{1:~ }|*12 92foo 0,0-1 All| 93]] ) 94command ( 'echo "foo"' ) 95-- Ruler still positioned correctly after dupe message. 96screen : expect ( [[ 97^ | 98{1:~ }|*12 99foo(1) 0,0-1 All| 100]] ) 101command ( 'echo "foo"' ) 102-- Dupe counter increases beyond 1 103screen : expect ( [[ 104^ | 105{1:~ }|*12 106foo(2) 0,0-1 All| 107]] ) 108-- No error for ruler virt_text msg_row exceeding buffer length. 109command ( [[map Q <cmd>echo "foo\nbar" <bar> ls<CR>]] ) 110feed ( 'Q' ) 111screen : expect ( [[ 112^ | 113{1:~ }|*9 114{3: }| 115foo | 116bar | 1171 %a "[No Name]" line 1 | 118]] ) 119feed ( '<C-L>' ) 120screen : expect ( [[ 121^ | 122{1:~ }|*12 1230,0-1 All| 124]] ) 125-- g< shows messages from last command 126feed ( 'g<lt>' ) 127screen : expect ( [[ 128| 129{1:~ }|*8 130{3: }| 131^foo | 132bar | 1331 %a "[No Name]" line 1 | 1341,1 All| 135]] ) 136-- edit_unputchar() does not clear already updated screen #34515. 137feed ( 'qix<Esc>dwi<C-r>' ) 138screen : expect ( [[ 139{18:^"} | 140{1:~ }|*12 141^R 1,1 All| 142]] ) 143feed ( '-<Esc>' ) 144screen : expect ( [[ 145^x | 146{1:~ }|*12 1471,1 All| 148]] ) 149-- Switching tabpage closes expanded cmdline #37659. 150command ( 'tabnew | echo "foo\nbar"' ) 151screen : expect ( [[ 152{24: + [No Name] }{5: [No Name] }{2: }{24:X}| 153^ | 154{1:~ }|*9 155{3: }| 156foo | 157bar | 158]] ) 159feed ( 'gt' ) 160screen : expect ( [[ 161{5: + [No Name] }{24: [No Name] }{2: }{24:X}| 162^x | 163{1:~ }|*11 164foo{6: [+1]} 1,1 All| 165]] ) 166-- Don't enter the pager in insert mode. 167command ( 'tabonly | call nvim_echo([["foo\n"]]->repeat(&lines), 1, {}) | startinsert' ) 168screen : expect ( [[ 169^x | 170{1:~ }|*5 171{3: }| 172foo |*6 173foo{6: [+8]} | 174]] ) 175feed ( '<CR>' ) 176screen : expect ( [[ 177| 178^x | 179{1:~ }|*11 180foo{6: [+14]} 2,1 All| 181]] ) 182feed ( '<BS><Esc>' ) 183-- First multiline message expands cmdline, additional message updates spill indicator. 184command ( 'call nvim_echo([["foo\n"]]->repeat(&lines), 1, {}) | echo "bar"' ) 185screen : expect ( [[ 186^x | 187{1:~ }|*5 188{3: }| 189foo |*6 190foo{6: [+9]} | 191]] ) 192-- Do enter the pager in normal mode (with keybinding setup). 193-- Also checks that "messagesopt=pager:…" is normalized to the keytrans() form. 194command ( 'set messagesopt+=pager:<cr>' ) 195command ( 'nmap <Esc> <Cmd>fclose<CR>' ) 196feed ( '<CR>' ) 197screen : expect ( [[ 198^foo | 199foo |*12 2001,1 Top| 201]] ) 202command ( 'set messagesopt-=pager:<cr>' ) 203-- Changing 'laststatus' reveals the global statusline with a pager height 204-- exceeding the available lines: #38008. 205command ( 'set laststatus=3' ) 206screen : expect ( [[ 207^foo | 208foo |*11 209{3:[Pager] 1,1 Top}| 210| 211]] ) 212feed ( ':<C-F>' ) 213screen : expect ( [[ 214x | 215{1:~ }|*3 216─────────────────────────────────────────────────────| 217{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 218{1::}^ | 219{1:~ }|*5 220{3:[Command Line] 2,0-1 All}| 221| 222]] ) 223command ( 'wincmd +' ) 224screen : expect ( [[ 225x | 226{1:~ }|*2 227─────────────────────────────────────────────────────| 228{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 229{1::}^ | 230{1:~ }|*6 231{3:[Command Line] 2,0-1 All}| 232| 233]] ) 234command ( 'echo "foo"' ) 235screen : expect ( [[ 236x | 237{1:~ }|*2 238─────────────────────────────────────────────────────| 239{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 240{1::}^ | 241{1:~ }|*6 242{3:[Command Line] 2,0-1 All}| 243foo | 244]] ) 245-- <C-C> closes the cmdwin and drops back into pre-filled cmdline. The pager remains visible. 246feed ( '<C-C>' ) 247screen : expect ( [[ 248x | 249{1:~ }|*11 250{3:[Pager] 1,1 Top}| 251{16::}^ | 252]] ) 253feed ( '<Esc><Esc>' ) 254-- Can enter pager from cmdwin (use cmdwin.open() since "q" is consumed by the pager on_key 255-- callback before nv_record can read it). 256exec_lua ( [[require('vim._core.cmdwin').open(':')]] ) 257screen : expect ( [[ 258x | 259{1:~ }|*3 260─────────────────────────────────────────────────────| 261{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 262{1::}^ | 263{1:~ }|*5 264{3:[Command Line] 2,0-1 All}| 265| 266]] ) 267feed ( ':messages<CR>' ) 268-- Cmdwin stays open behind the pager: it is a regular window (#40312). 269screen : expect ( [[ 270^foo | 271foo |*4 272{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 273{1::} | 274{1:~ }|*5 275{3:[Pager] 1,1 Top}| 276{16::}{15:messages} | 277]] ) 278-- Closing the pager returns to the cmdwin, unchanged (it was never closed). 279feed ( 'q' ) 280screen : expect ( [[ 281x | 282{1:~ }|*3 283─────────────────────────────────────────────────────| 284{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) | 285{1::}^ | 286{1:~ }|*5 287{3:[Command Line] 2,0-1 All}| 288{16::}{15:messages} | 289]] ) 290-- Configured maximum height. 291command ( 'quit | lua require("vim._core.ui2").enable({msg = {pager = {height = 2 } } })' ) 292command ( 'messages' ) 293screen : expect ( [[ 294x | 295{1:~ }|*8 296{3: }| 297^foo | 298foo | 299{3:[Pager] 1,1 Top}| 300{16::}{15:messages} | 301]] ) 302end ) 303 304it ( 'new buffer, window and options after closing a buffer or switching tabpage' , function () 305command ( 'set nomodifiable | echom "foo" | messages' ) 306screen : expect ( [[ 307| 308{1:~ }|*10 309{3: }| 310^foo | 311foo | 312]] ) 313command ( 'bdelete | messages' ) 314screen : expect_unchanged () 315set_msg_target_zero_ch () 316command ( 'quit | echo "foo\nbar" | tabnew' ) 317screen : expect ( [[ 318{24: [No Name] }{5: [No Name] }{2: }{24:X}| 319^ | 320{1:~ }|*10 321{1:~ }{4:foo}| 322{1:~ }{4:bar}| 323]] ) 324end ) 325 326it ( 'screenclear and empty message clears messages' , function () 327command ( 'echo "foo"' ) 328screen : expect ( [[ 329^ | 330{1:~ }|*12 331foo | 332]] ) 333command ( 'mode' ) 334screen : expect ( [[ 335^ | 336{1:~ }|*12 337| 338]] ) 339command ( 'echo "foo"' ) 340screen : expect ( [[ 341^ | 342{1:~ }|*12 343foo | 344]] ) 345command ( 'echo ""' ) 346screen : expect ( [[ 347^ | 348{1:~ }|*12 349| 350]] ) 351-- A redraw indicates the start of messages in the cmdline, which empty should clear. 352command ( 'echo "foo" | redraw | echo "bar"' ) 353screen : expect ( [[ 354^ | 355{1:~ }|*12 356bar | 357]] ) 358command ( 'echo "foo" | redraw | echo ""' ) 359screen : expect ( [[ 360^ | 361{1:~ }|*12 362| 363]] ) 364set_msg_target_zero_ch () 365command ( 'echo "foo"' ) 366screen : expect ( [[ 367^ | 368{1:~ }|*12 369{1:~ }{4:foo}| 370]] ) 371command ( 'mode' ) 372screen : expect ( [[ 373^ | 374{1:~ }|*13 375]] ) 376-- But not with target='msg' 377command ( 'echo "foo"' ) 378screen : expect ( [[ 379^ | 380{1:~ }|*12 381{1:~ }{4:foo}| 382]] ) 383command ( 'echo ""' ) 384screen : expect_unchanged () 385-- Or a screen resize 386screen : try_resize ( screen . _width , screen . _height - 1 ) 387screen : expect ( [[ 388^ | 389{1:~ }|*11 390{1:~ }{4:foo}| 391]] ) 392-- Moved up when opening cmdline 393feed ( ':' ) 394screen : expect ( [[ 395| 396{1:~ }|*10 397{1:~ }{4:foo}| 398{16::}^ | 399]] ) 400-- Highlighter disabled when message is moved to cmdline #34884 401feed ( [[echo "bar\n"->repeat(&lines)<CR>]] ) 402screen : expect ( [[ 403^ | 404{1:~ }|*5 405foo | 406bar |*5 407bar{6: [+8]} | 408]] ) 409end ) 410 411it ( 'does not draw the message seperator with cmdheight=0' , function () 412command ( 'set laststatus=2 statusline=%f' ) 413command ( 'set cmdheight=0' ) 414command ( 'echo "hello"' ) 415 416screen : expect ( [[ 417^ | 418{1:~ }|*12 419hello | 420]] ) 421end ) 422 423it ( 'no prompt and newlines with Visual filter command #38273' , function () 424set_msg_target_zero_ch () 425feed ( 'V:w !printf foo<CR>' ) 426screen : expect ( [[ 427^ | 428{1:~ }|*12 429{1:~ }{4:foo}| 430]] ) 431end ) 432 433it ( 'empty kind after message that does not flush immediately' , function () 434command ( 'echon "foo" | echo' ) 435screen : expect ( [[ 436^ | 437{1:~ }|*12 438foo | 439]] ) 440end ) 441 442it ( "deleting buffer restores 'buftype'" , function () 443feed ( ':%bdelete<CR>' ) 444screen : expect ( [[ 445^ | 446{1:~ }|*12 4475 buffers deleted | 448]] ) 449-- Would trigger changed dialog if 'buftype' was not restored. 450command ( '%bdelete' ) 451screen : expect_unchanged () 452end ) 453 454it ( 'showmode does not overwrite important messages' , function () 455command ( 'set readonly' ) 456feed ( 'i' ) 457screen : expect ( [[ 458^ | 459{1:~ }|*12 460{19:W10: Warning: Changing a readonly file} | 461]] ) 462feed ( '<Esc>@@i' ) 463screen : expect ( [[ 464^ | 465{1:~ }|*12 466{9:E748: No previously used register} | 467]] ) 468end ) 469 470it ( 'showmode does not overwrite Visual word count #40824' , function () 471if t . is_os ( 'win' ) then 472t . pending ( 'FIXME #40843' ) 473end 474api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'one two' , 'three four' } ) 475feed ( 'Vj' ) 476screen : expect ( [[ 477{17:one two} | 478{17:^three four} | 479{1:~ }|*11 480{5:-- VISUAL LINE --} | 481]] ) 482feed ( 'g<C-G>' ) 483screen : expect ( [[ 484{17:one two} | 485{17:^three four} | 486{1:~ }|*11 487Selected 2 of 2 Lines; 4 of 4 Words; 19 of 19 Bytes | 488]] ) 489end ) 490 491it ( 'hit-enter prompt does not error for invalid window #35095' , function () 492command ( 'echo "foo\nbar"' ) 493screen : expect ( [[ 494^ | 495{1:~ }|*10 496{3: }| 497foo | 498bar | 499]] ) 500feed ( '<C-w>o' ) 501screen : expect ( [[ 502^ | 503{1:~ }|*12 504foo{6: [+1]} | 505]] ) 506end ) 507 508it ( 'entering cmdline below expanded messages' , function () 509command ( 'echo "foo\n"->repeat(&lines)' ) 510screen : expect ( [[ 511^ | 512{1:~ }|*5 513{3: }| 514foo |*6 515foo{6: [+8]} | 516]] ) 517-- Place cmdline below expanded messages: #37653, without "more" title #38481. 518feed ( ':call setline(1, "foo")' ) 519screen : expect ( [[ 520| 521{1:~ }|*4 522{3: }| 523foo |*6 524foo{6: [+8]} | 525{16::}{15:call} {25:setline}{16:(}{26:1}{16:,} {26:"foo"}{16:)}^ | 526]] ) 527-- No message closes expanded cmdline and keeps the entered command. 528feed ( '<CR>' ) 529screen : expect ( [[ 530^foo | 531{1:~ }|*12 532{16::}{15:call} {25:setline}{16:(}{26:1}{16:,} {26:"foo"}{16:)} | 533]] ) 534-- If command emits another message it is opened in the pager without focusing 535-- it, to closely mimic useful UI1 behavior. #41061 536command ( 'echo "foo\nbar"' ) 537feed ( ':echo "baz"<CR>' ) 538screen : expect ( [[ 539^foo | 540{1:~ }|*8 541{3: }| 542foo | 543bar | 544baz | 545{16::}{15:echo} {26:"baz"} | 546]] ) 547-- Moving the mouse does not dismiss the pager. 548api . nvim_input_mouse ( 'move' , '' , '' , 0 , 0 , 3 ) 549-- Subsequent typed commands are appended to the pager. 550feed ( ':echo "typed append"<CR>' ) 551screen : expect ( [[ 552^foo | 553{1:~ }|*7 554{3: }| 555foo | 556bar | 557baz | 558typed append | 559{16::}{15:echo} {26:"typed append"} | 560]] ) 561-- Any other typed key dismisses the pager. 562feed ( 'n' ) 563screen : expect ( [[ 564^foo | 565{1:~ }|*12 566{9:E35: No previous regular expression} | 567]] ) 568-- Non-typed key doesn't dismiss expanded cmdline #39221 569command ( 'nnoremap b :ls!<cr>:b<space>' ) 570feed ( 'b' ) 571screen : expect ( [[ 572foo | 573{1:~ }|*6 574{3: }| 5751 %a + "[No Name]" line 1 | 5762u a "[Cmd]" line 0 | 5773u a "[Dialog]" line 0 | 5784u a "[Msg]" line 0 | 5795u a "[Pager]" line 0 | 580{16::}{15:b} ^ | 581]] ) 582end ) 583 584it ( 'pager for consecutive command messages is not focused #41061' , function () 585local win =api . nvim_get_current_win () 586command ( 'nnoremap j gj' ) 587command ( 'echo "foo\nbar"' ) 588feed ( ':echo "baz"<CR>' ) 589screen : expect ( [[ 590^ | 591{1:~ }|*8 592{3: }| 593foo | 594bar | 595baz | 596{16::}{15:echo} {26:"baz"} | 597]] ) 598t . eq ( win , api . nvim_get_current_win ()) 599-- "g<" enters the pager (showing the previous command output). 600feed ( 'g<lt>' ) 601screen : expect ( [[ 602| 603{1:~ }|*10 604{3: }| 605^baz | 606| 607]] ) 608t . neq ( win , api . nvim_get_current_win ()) 609-- "q" closes the entered pager. 610feed ( 'q' ) 611t . eq ( win , api . nvim_get_current_win ()) 612-- ":messages" from inside the pager does not make the next unfocused pager steal focus. 613command ( 'echo "foo\nbar"' ) 614feed ( ':echo "baz"<CR>' ) 615feed ( 'g<lt>' ) 616n . poke_eventloop () 617t . neq ( win , api . nvim_get_current_win ()) 618feed ( ':messages<CR>' ) 619n . poke_eventloop () 620feed ( 'q' ) 621n . poke_eventloop () 622t . eq ( win , api . nvim_get_current_win ()) 623command ( 'echo "foo\nbar"' ) 624feed ( ':echo "baz"<CR>' ) 625n . poke_eventloop () 626t . eq ( win , api . nvim_get_current_win ()) 627feed ( 'j' ) 628screen : expect ( [[ 629^ | 630{1:~ }|*12 631{16::}{15:echo} {26:"baz"} | 632]] ) 633-- A typed command that emits no message keeps the pager; the next key dismisses it. 634command ( 'echo "foo\nbar"' ) 635feed ( ':echo "baz"<CR>' ) 636feed ( ':let g:x = 1<CR>' ) 637screen : expect ( [[ 638^ | 639{1:~ }|*8 640{3: }| 641foo | 642bar | 643baz | 644{16::}{15:let} {25:g:x} {15:=} {26:1} | 645]] ) 646feed ( 'j' ) 647screen : expect ( [[ 648^ | 649{1:~ }|*12 650{16::}{15:let} {25:g:x} {15:=} {26:1} | 651]] ) 652end ) 653 654it ( 'paging prompt dialog #35191' , function () 655screen : try_resize ( 71 , screen . _height ) 656-- Don't consume <Esc> when paging is not necessary. 657feed ( ':call confirm("Ok?")<CR>' ) 658screen : expect ( [[ 659| 660{1:~ }|*10 661{3: }| 662{6:Ok?} | 663{6:[O]k: }^ | 664]] ) 665feed ( '<Esc>' ) 666screen : expect ( [[ 667^ | 668{1:~ }|*12 669| 670]] ) 671local top =[[ 672| 673{1:~ }|*4 674{3: }| 6750 | 6761 | 6772 | 6783 | 6794 | 6805 | 6816{6: [+93]} | 682Type number and <Enter> (q or empty cancels): ^ | 683]] 684command ( 'set mousescroll=ver:2' ) 685feed ( ':call inputlist(range(100))<CR>' ) 686screen : expect ( top ) 687feed ( '<Down>' ) 688screen : expect ( [[ 689| 690{1:~ }|*4 691{3: }| 6921{6: [+1]} | 6932 | 6943 | 6954 | 6965 | 6976 | 6987{6: [+92]} | 699Type number and <Enter> (q or empty cancels): ^ | 700]] ) 701feed ( '<Up>' ) 702screen : expect ( top ) 703feed ( '<PageDown>' ) 704screen : expect ( [[ 705| 706{1:~ }|*4 707{3: }| 7085{6: [+5]} | 7096 | 7107 | 7118 | 7129 | 71310 | 71411{6: [+88]} | 715Type number and <Enter> (q or empty cancels): ^ | 716]] ) 717feed ( '<PageUp>' ) 718screen : expect ( top ) 719feed ( '<End>' ) 720screen : expect ( [[ 721| 722{1:~ }|*4 723{3: }| 72493{6: [+93]} | 72594 | 72695 | 72796 | 72897 | 72998 | 73099 | 731Type number and <Enter> (q or empty cancels): ^ | 732]] ) 733-- No scrolling beyond end of buffer #36114 734feed ( '<PageDown>' ) 735screen : expect_unchanged () 736feed ( '<Home>' ) 737screen : expect ( top ) 738-- The wheel scrolls by 'mousescroll'; the arrow keys above still scrolled by one #39172 739feed ( '<ScrollWheelDown><0,0>' ) 740screen : expect ( [[ 741| 742{1:~ }|*4 743{3: }| 7442{6: [+2]} | 7453 | 7464 | 7475 | 7486 | 7497 | 7508{6: [+91]} | 751Type number and <Enter> (q or empty cancels): ^ | 752]] ) 753feed ( '<Up>' ) 754screen : expect ( [[ 755| 756{1:~ }|*4 757{3: }| 7581{6: [+1]} | 7592 | 7603 | 7614 | 7625 | 7636 | 7647{6: [+92]} | 765Type number and <Enter> (q or empty cancels): ^ | 766]] ) 767feed ( '<ScrollWheelUp><0,0>' ) 768screen : expect ( top ) 769end ) 770 771it ( 'FileType is fired after default options are set' , function () 772n . exec ( [[ 773let g:set = {} 774au FileType pager set nowrap 775au OptionSet * let g:set[expand('<amatch>')] = g:set->get(expand('<amatch>'), 0) + 1 776echom 'foo'->repeat(&columns) 777messages 778]] ) 779screen : expect ( [[ 780| 781{1:~ }|*10 782{3: }| 783^foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofo| 784| 785]] ) 786t . eq ( 5 , n . eval ( 'g:set' ). filetype ) -- still fires for 'filetype' 787end ) 788 789it ( 'Search highlights only apply to pager' , function () 790screen : add_extra_attr_ids ( { 791[ 100 ] ={ background =Screen . colors . Blue1 , foreground =Screen . colors . Red } , 792[ 101 ] ={ background =Screen . colors . Red1 , foreground =Screen . colors . Blue1 } , 793[ 102 ] ={ 794background =Screen . colors . Blue , 795foreground =Screen . colors . Red1 , 796reverse =true , 797bold =true , 798} , 799} ) 800command ( 'hi MsgArea guifg=Red guibg=Blue' ) 801command ( 'hi Search guifg=Blue guibg=Red' ) 802command ( 'set hlsearch shortmess+=s' ) 803feed ( '/foo<CR>' ) 804screen : expect ( [[ 805^ | 806{1:~ }|*12 807{9:E486: Pattern not found: foo}{100: }| 808]] ) 809set_msg_target_zero_ch () 810command ( 'echo "foo"' ) 811screen : expect ( [[ 812^ | 813{1:~ }|*12 814{1:~ }{4:foo}| 815]] ) 816feed ( 'g<lt>' ) 817screen : expect ( [[ 818| 819{1:~ }|*11 820{102: }| 821{101:^foo}{100: }| 822]] ) 823end ) 824 825it ( ':echon appends message' , function () 826command ( [[echo 1 | echon 2]] ) 827screen : expect ( [[ 828^ | 829{1:~ }|*12 83012 | 831]] ) 832feed ( 'g<lt>' ) 833screen : expect ( [[ 834| 835{1:~ }|*10 836{3: }| 837^12 | 838| 839]] ) 840feed ( [[q:echo 1 | echon 2 | echon 2 | echon 3<CR>]] ) 841screen : expect ( [[ 842^ | 843{1:~ }|*12 8441223 | 845]] ) 846feed ( 'g<lt>' ) 847screen : expect ( [[ 848| 849{1:~ }|*10 850{3: }| 851^1223 | 852| 853]] ) 854end ) 855 856it ( 'shows message from still running command' , function () 857exec_lua ( function () 858vim . schedule ( function () 859( 'foo' ) 860vim . fn . getchar () 861end ) 862end ) 863screen : expect ( [[ 864^ | 865{1:~ }|*12 866foo | 867]] ) 868feed ( '<CR>' ) 869-- Fast context is not determined by message kind #39666 870exec_lua ( function () 871vim . schedule ( function () 872vim . api . nvim_echo ( { { 'bar' } } , false , { kind ='search_cmd' } ) 873vim . fn . getchar () 874end ) 875end ) 876screen : expect ( [[ 877^ | 878{1:~ }|*12 879bar | 880]] ) 881end ) 882 883it ( 'properly formatted carriage return messages' , function () 884screen : try_resize ( screen . _width , 20 ) 885command ( [[echon "\r" | echon "Hello" | echon " " | echon "World"]] ) 886screen : expect ( [[ 887^ | 888{1:~ }|*18 889Hello World | 890]] ) 891exec_lua ( function () 892vim . api . nvim_echo ( { { 'fooo\nbarbaz\n\nlol' , 'statement' } , { '\rbar' } } , true , {} ) 893vim . api . nvim_echo ( { { 'foooooooo' , 'statement' } , { 'baz\rb' , 'error' } } , true , {} ) 894vim . api . nvim_echo ( { { 'fooobar' , 'statement' } , { '\rbaz\n' } } , true , {} ) 895vim . api . nvim_echo ( { { 'fooobar' , 'statement' } , { '\rbaz\rb' , 'error' } } , true , {} ) 896vim . api . nvim_echo ( { { 'fooo\rbar' , 'statement' } , { 'baz' , 'error' } } , true , {} ) 897end ) 898screen : expect ( [[ 899^ | 900{1:~ }|*9 901{3: }| 902{15:fooo} | 903{15:barbaz} | 904| 905bar | 906{9:b}{15:oooooooo}{9:baz} | 907baz{15:obar} | 908| 909{9:baz}{15:obar} | 910{15:bar}{9:baz} | 911]] ) 912end ) 913 914it ( 'can show message during textlock' , function () 915exec_lua ( function () 916_G . omnifunc =function () 917( 'x!' ) 918vim . cmd . sleep ( '100m' ) 919end 920vim . bo . omnifunc ='v:lua.omnifunc' 921end ) 922feed ( 'i<C-X>' ) 923screen : expect ( [[ 924^ | 925{1:~ }|*12 926{5:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)} | 927]] ) 928feed ( '<C-O>' ) 929screen : expect ( [[ 930^ | 931{1:~ }|*12 932x! | 933]] ) 934screen : expect ( [[ 935^ | 936{1:~ }|*12 937{5:-- Omni completion (^O^N^P) }{9:Pattern not found} | 938]] ) 939exec_lua ( function () 940vim . keymap . set ( 'n' , '<F1>' , function () 941( 'i hate locks so much!!!!' ) 942vim . cmd . messages () 943end , { expr =true } ) 944end ) 945feed ( '<Esc><F1>' ) 946screen : expect ( [[ 947| 948{1:~ }|*8 949{3: }| 950^x! | 951x! | 952i hate locks so much!!!! |*2 953]] ) 954end ) 955 956it ( 'replace by message ID' , function () 957exec_lua ( function () 958assert ( 1 == vim . api . nvim_echo ( { { 'foo' } } , true , {} )) 959assert ( 2 == vim . api . nvim_echo ( { { 'bar\nbaz' } } , true , {} )) 960assert ( 3 == vim . api . nvim_echo ( { { 'foo' } } , true , {} )) 961vim . keymap . set ( 'n' , 'Q' , function () 962vim . api . nvim_echo ( { { 'Syntax' , 23 } , { '\n - ' , 0 } , { 'cCommentL' , 439 } } , false , {} ) 963end ) 964end ) 965screen : expect ( [[ 966^ | 967{1:~ }|*8 968{3: }| 969foo | 970bar | 971baz | 972foo | 973]] ) 974api . nvim_echo ( { { 'foo' } } , true , { id =2 } ) 975screen : expect ( [[ 976^ | 977{1:~ }|*9 978{3: }| 979foo |*3 980]] ) 981api . nvim_echo ( { { 'bar\nbaz' } } , true , { id =1 } ) 982screen : expect ( [[ 983^ | 984{1:~ }|*8 985{3: }| 986bar | 987baz | 988foo |*2 989]] ) 990-- Pressing a key immediately dismisses an expanded cmdline, and 991-- replacing a multiline, multicolored message doesn't error due 992-- to unnecessarily inserted lines #37994. 993feed ( 'Q' ) 994screen : expect ( [[ 995^ | 996{1:~ }|*10 997{3: }| 998{100:Syntax} | 999- cCommentL | 1000]] ) 1001feed ( 'Q' ) 1002screen : expect_unchanged ( true ) 1003feed ( '<C-L>' ) -- close expanded cmdline 1004set_msg_target_zero_ch () 1005api . nvim_echo ( { { 'foo' } } , true , { id =1 } ) 1006api . nvim_echo ( { { 'bar\nbaz' } } , true , { id =2 } ) 1007api . nvim_echo ( { { 'foo' } } , true , { id =3 } ) 1008screen : expect ( [[ 1009^ | 1010{1:~ }|*9 1011{1:~ }{4:foo}| 1012{1:~ }{4:bar}| 1013{1:~ }{4:baz}| 1014{1:~ }{4:foo}| 1015]] ) 1016api . nvim_echo ( { { 'foo' } } , true , { id =2 } ) 1017screen : expect ( [[ 1018^ | 1019{1:~ }|*10 1020{1:~ }{4:foo}|*3 1021]] ) 1022api . nvim_echo ( { { 'f' , 'Conceal' } , { 'oo\nbar' } } , true , { id =3 } ) 1023screen : expect ( [[ 1024^ | 1025{1:~ }|*9 1026{1:~ }{4:foo}|*2 1027{1:~ }{14:f}{4:oo}| 1028{1:~ }{4:bar}| 1029]] ) 1030-- No error expanding the cmdline when trying to copy over message span marks #37672. 1031screen : try_resize ( screen . _width , 6 ) 1032command ( 'ls!' ) 1033screen : expect ( [[ 1034^ | 1035{1:~ }|*2 1036foo |*2 1037{14:f}oo{6: [+6]} | 1038]] ) 1039feed ( '<Esc>' ) 1040screen : expect ( [[ 1041^ | 1042{1:~ }|*5 1043]] ) 1044end ) 1045 1046it ( 'while cmdline is open' , function () 1047command ( 'cnoremap <C-A> <Cmd>lua error("foo")<CR>' ) 1048feed ( ':echo "bar"<C-A>' ) 1049screen : expect ( [[ 1050| 1051{1:~ }|*7 1052{3: }| 1053{9:E5108: Lua: [string ":lua"]:1: foo} | 1054{9:stack traceback:} | 1055{9: [C]: in function 'error'} | 1056{9: [string ":lua"]:1: in main chunk} | 1057{16::}{15:echo} {26:"bar"}^ | 1058]] ) 1059feed ( '<CR>' ) 1060screen : expect ( [[ 1061^ | 1062{1:~ }|*12 1063bar | 1064]] ) 1065set_msg_target_zero_ch () 1066feed ( [[:call confirm("foo\nbar")<C-A>]] ) 1067screen : expect ( [[ 1068| 1069{1:~ }|*8 1070{1:~ }{9:E5108: Lua: [string ":lua"]:1: foo}{4: }| 1071{1:~ }{9:stack traceback:}{4: }| 1072{1:~ }{9: [C]: in function 'error'}{4: }| 1073{1:~ }{9: [string ":lua"]:1: in main chunk}| 1074{16::}{15:call} {25:confirm}{16:(}{26:"foo\nbar"}{16:)}^ | 1075]] ) 1076feed ( '<CR>' ) 1077screen : expect ( [[ 1078| 1079{1:~ }|*8 1080{1:~ }{9:E5108: Lua: [string ":lua"]:1: foo}{4: }| 1081{3: }| 1082{6:foo} | 1083{6:bar} | 1084{6:[O]k: }^ | 1085]] ) 1086end ) 1087 1088it ( 'no search_cmd with cmdheight=0' , function () 1089set_msg_target_zero_ch () 1090feed ( 'ifoo<Esc>?foo<CR>' ) 1091screen : expect ( [[ 1092{10:^foo} | 1093{1:~ }|*13 1094]] ) 1095end ) 1096 1097it ( 'closed msg window timer removes empty lines' , function () 1098set_msg_target_zero_ch () 1099command ( 'echo "foo" | echo "bar\n"' ) 1100screen : expect ( [[ 1101^ | 1102{1:~ }|*10 1103{1:~ }{4:foo}| 1104{1:~ }{4:bar}| 1105{1:~ }{4: }| 1106]] ) 1107command ( 'fclose!' ) 1108screen : sleep ( msg_timeout + 50 ) 1109command ( 'echo "baz"' ) 1110screen : expect ( [[ 1111^ | 1112{1:~ }|*12 1113{1:~ }{4:baz}| 1114]] ) 1115-- Last message line is at bottom of window after closing it. 1116screen : try_resize ( screen . _width , 8 ) 1117command ( 'mode | echo "1\n" | echo "2\n" | echo "3\n" | echo "4\n"' ) 1118screen : expect ( [[ 1119^ | 1120{1:~ }|*3 1121{1:~ }{4:3}| 1122{1:~ }{4: }| 1123{1:~ }{4:4}| 1124{1:~ }{4: }| 1125]] ) 1126command ( 'fclose!' ) 1127screen : expect ( [[ 1128^ | 1129{1:~ }|*7 1130]] ) 1131command ( 'echo "5\n"' ) 1132screen : expect ( [[ 1133^ | 1134{1:~ }|*3 1135{1:~ }{4:4}| 1136{1:~ }{4: }| 1137{1:~ }{4:5}| 1138{1:~ }{4: }| 1139]] ) 1140end ) 1141 1142it ( 'msg window timer does not trigger ModeChanged #40780' , function () 1143exec_lua ( function () 1144vim . o . messagesopt ='hit-enter,history:500,progress:c,timeout:50' 1145require ( 'vim._core.ui2' ). enable ( { msg ={ targets ='msg' } } ) 1146end ) 1147command ( 'let g:modechanged = []' ) 1148command ( [[autocmd ModeChanged i:n call add(g:modechanged, copy(v:event))]] ) 1149command ( [[echo "a" | echo "b" | startinsert]] ) 1150screen : sleep ( 100 ) 1151t . eq ( {} , n . eval ( 'g:modechanged' )) 1152feed ( '<Esc>' ) 1153t . eq ( { { old_mode ='i' , new_mode ='n' } } , n . eval ( 'g:modechanged' )) 1154end ) 1155 1156it ( 'configured targets per kind' , function () 1157exec_lua ( function () 1158local targets ={ echo ='msg' , list_cmd ='pager' , bufwrite ='cmd' , lua_print ='cmd' } 1159require ( 'vim._core.ui2' ). enable ( { msg ={ targets =targets } } ) 1160( 'foo' ) -- "lua_print" kind goes to cmd 1161vim . cmd . echo ( '"bar"' ) -- "echo" kind goes to msg 1162vim . cmd . highlight ( 'VisualNC' ) -- "list_cmd" kind goes to pager 1163end ) 1164screen : expect ( [[ 1165^ | 1166{1:~ }|*10 1167{3: }| 1168VisualNC xxx cleared {4:bar}| 1169foo | 1170]] ) 1171command ( 'hi VisualNC' ) -- appended to the pager without focusing it 1172screen : expect ( [[ 1173^ | 1174{1:~ }|*9 1175{3: }| 1176VisualNC xxx cleared | 1177VisualNC xxx cleared {4:bar}| 1178foo | 1179]] ) 1180-- Any typed key dismisses the unfocused pager. 1181feed ( '<Esc>' ) 1182-- Duplicate indicator in msg and cmd target simultaneously 1183command ( 'echo "bar" | lua print("foo")' ) 1184command ( 'echo "bar" | lua print("foo")' ) 1185screen : expect ( [[ 1186^ | 1187{1:~ }|*11 1188{1:~ }{4:bar(2)}| 1189foo(1) | 1190]] ) 1191finally ( function () 1192os . remove ( 'Xfile' ) 1193end ) 1194-- Route bufwrite as a pattern to the message ID #39341 1195command ( 'edit Xfile | write' ) 1196screen : expect ( [[ 1197^ | 1198{1:~ }|*11 1199{1:~ }{4:bar(2)}| 1200"Xfile" [New] 0L, 0B written | 1201]] ) 1202end ) 1203 1204it ( 'message survives after closing tabpage without error #39055' , function () 1205set_msg_target_zero_ch () 1206command ( 'tabnew' ) 1207command ( 'echo "hello"' ) 1208screen : expect ( [[ 1209{24: [No Name] }{5: [No Name] }{2: }{24:X}| 1210^ | 1211{1:~ }|*11 1212{1:~ }{4:hello}| 1213]] ) 1214command ( 'quit!' ) 1215screen : expect ( [[ 1216^ | 1217{1:~ }|*12 1218{1:~ }{4:hello}| 1219]] ) 1220end ) 1221 1222it ( 'no modal/blocking prompt on exit' , function () 1223api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'one' } ) 1224feed ( ':quit<CR>' ) 1225screen : expect ( [[ 1226^one | 1227{1:~ }|*12 1228{9:E37: No write since last change}{6: [+2]} | 1229]] ) 1230end ) 1231 1232it ( 'no crash for resized grid during redraw #39075' , function () 1233exec_lua ( function () 1234vim . api . nvim_set_decoration_provider ( vim . api . nvim_create_namespace ( '' ), { 1235on_win =function () 1236( '\n' ) 1237end , 1238} ) 1239end ) 1240feed ( ':' ) 1241screen : expect ( [[ 1242| 1243{1:~ }|*12 1244{16::}^ | 1245]] ) 1246feed ( 'f' ) 1247screen : expect ( [[ 1248| 1249{1:~ }|*9 1250{3: }| 1251|*2 1252{16::}{15:f}^ | 1253]] ) 1254end ) 1255 1256it ( 'configured cmd window height prevents expanded message #39375' , function () 1257command ( 'set messagesopt+=maxheight:1' ) -- Rounds up to a single row. 1258command ( 'echo "foo\nbar"' ) 1259screen : expect ( [[ 1260^ | 1261{1:~ }|*12 1262foo{6: [+1]} | 1263]] ) 1264end ) 1265 1266it ( 'search count is cleared' , function () 1267command ( 'set ruler showcmd shortmess-=S | call setline(1, ["foo", "bar"])' ) 1268feed ( '/foo<CR>' ) 1269local search_count =[[ 1270{10:^foo} | 1271bar | 1272{1:~ }|*11 1273/foo W [1/1] 1,1 All| 1274]] 1275screen : expect ( search_count ) 1276feed ( '<C-L>j' ) 1277screen : expect ( [[ 1278{10:foo} | 1279^bar | 1280{1:~ }|*11 12812,1 All| 1282]] ) 1283feed ( 'n' ) 1284screen : expect ( search_count ) 1285command ( 'echo "-"->repeat(&columns)' ) 1286screen : expect ( [[ 1287{10:^foo} | 1288bar | 1289{1:~ }|*11 1290-----------------------------------1,1 All| 1291]] ) 1292end ) 1293 1294it ( 'search offset with semicolon #41929' , function () 1295command ( 1296'set shortmess-=S | call setline(1, ["odd line", "even line", "odd line", "even line"])' 1297) 1298feed ( '/even/;/even<CR>' ) 1299screen : expect ( [[ 1300odd line | 1301{10:even} line | 1302odd line | 1303{10:^even} line | 1304{1:~ }|*9 1305/even [2/2] | 1306]] ) 1307end ) 1308 1309it ( 'crops long messages to make place for ruler' , function () 1310command ( 'set noruler | echo "-"->repeat(&columns)' ) 1311screen : expect ( [[ 1312^ | 1313{1:~ }|*12 1314-----------------------------------------------------| 1315]] ) 1316feed ( '<C-L>' ) 1317command ( 'set ruler showcmd | echo "-"->repeat(&columns)' ) 1318screen : expect ( [[ 1319^ | 1320{1:~ }|*12 1321-----------------------------------0,0-1 All| 1322]] ) 1323feed ( '<C-L>' ) 1324-- message with multibyte characters 1325command ( 'echo "∙"->repeat(&columns)' ) 1326screen : expect ( [[ 1327^ | 1328{1:~ }|*12 1329∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙0,0-1 All| 1330]] ) 1331feed ( '<C-L>' ) 1332-- message with multicell characters 1333command ( 'echo "-".."🙂"->repeat(&columns/2-1)' ) 1334screen : expect ( [[ 1335^ | 1336{1:~ }|*12 1337-🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂0,0-1 All| 1338]] ) 1339feed ( '<C-L>' ) 1340command ( 'echo "🙂"->repeat(&columns/2)' ) 1341screen : expect ( [[ 1342^ | 1343{1:~ }|*12 1344🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂 0,0-1 All| 1345]] ) 1346feed ( '<C-L>' ) 1347-- when cmdheight>1, only the last line is cropped 1348command ( 'set cmdheight=2 | redraw | echo "-"->repeat(2*&columns)' ) 1349screen : expect ( [[ 1350^ | 1351{1:~ }|*11 1352-----------------------------------------------------| 1353-----------------------------------0,0-1 All| 1354]] ) 1355feed ( '<C-L>' ) 1356command ( 'set cmdheight=2 showbreak=> | redraw | echo "-"->repeat(2*&columns-1)' ) 1357screen : expect ( [[ 1358^ | 1359{1:~ }|*11 1360-----------------------------------------------------| 1361{1:>}----------------------------------0,0-1 All| 1362]] ) 1363command ( 'set showbreak&' ) 1364feed ( '<C-L>' ) 1365-- ruler is not shown after dismissing expanded cmdline with key press -> no need to crop 1366command ( 'set cmdheight=1 | redraw | echo "-"->repeat(2*&columns)' ) 1367feed ( 'k' ) 1368screen : expect ( [[ 1369^ | 1370{1:~ }|*12 1371-----------------------------------------------------| 1372]] ) 1373feed ( '<C-L>' ) 1374-- messages are deferred until showcmd is cleared -> no need to crop for showcmd 1375command ( 'lua vim.defer_fn(function() vim.cmd[[echo "-"->repeat(&columns)]] end, 50)' ) 1376feed ( 'g' ) 1377screen : expect ( [[ 1378^ | 1379{1:~ }|*12 1380g 0,0-1 All| 1381]] ) 1382screen : sleep ( 100 ) 1383feed ( '<Esc>' ) 1384screen : expect ( [[ 1385^ | 1386{1:~ }|*12 1387-----------------------------------0,0-1 All| 1388]] ) 1389feed ( '<C-L>' ) 1390-- message with repetition indicator keeps ruler intact 1391command ( 'echo "-"->repeat(&columns)' ) 1392command ( 'echo "-"->repeat(&columns)' ) 1393screen : expect ( [[ 1394^ | 1395{1:~ }|*12 1396--------------------------------(1)0,0-1 All| 1397]] ) 1398feed ( '<C-L>' ) 1399-- when the ruler is configured smaller, there is more space for messages 1400command ( 'set rulerformat=%l | redraw | echo "-"->repeat(&columns)' ) 1401screen : expect ( [[ 1402^ | 1403{1:~ }|*12 1404----------------------------------------------------0| 1405]] ) 1406end ) 1407 1408it ( 'pager statusline is not clobbered by DiagnosticChanged redraw #41130' , function () 1409exec_lua ( function () 1410vim . o . laststatus =3 1411vim . ( 'message' ) 1412vim . cmd . mes () 1413end ) 1414screen : expect ( [[ 1415| 1416{1:~ }|*9 1417{3: }| 1418^message | 1419{3:[Pager] }| 1420message | 1421]] ) 1422exec_lua ( function () 1423vim . diagnostic . config ( { signs =false , virtual_text =false , underline =false } ) 1424local ns =vim . api . nvim_create_namespace ( 'repro-41130' ) 1425vim . diagnostic . set ( ns , 1 , { { lnum =0 , message ='random error' } } , {} ) 1426end ) 1427screen : expect_unchanged () 1428end ) 1429 1430it ( 'correct end_row for highlights copied to pager #41419' , function () 1431command ( 'echo "a" | echo "b"' ) -- Two lines; end_row should be offset by 2 1432screen : expect ( [[ 1433^ | 1434{1:~ }|*10 1435{3: }| 1436a | 1437b | 1438]] ) 1439feed ( 'g<lt>' ) 1440screen : expect ( [[ 1441| 1442{1:~ }|*9 1443{3: }| 1444^a | 1445b | 1446| 1447]] ) 1448command ( 'echohl WarningMsg | echo "c" | echohl ErrorMsg | echo "de"' ) 1449screen : expect ( [[ 1450| 1451{1:~ }|*7 1452{3: }| 1453^a | 1454b | 1455{19:c} | 1456{9:de} | 1457| 1458]] ) 1459feed ( 'g<lt>' ) 1460screen : expect ( [[ 1461| 1462{1:~ }|*9 1463{3: }| 1464{19:^c} | 1465{9:de} | 1466| 1467]] ) 1468 1469-- A prompt with pending cmd messages moves them to the dialog (cmdline.lua). The pager is 1470-- still shown, but its line count must not offset the marks copied into the dialog. 1471exec_lua ( function () 1472local ui =require ( 'vim._core.ui2' ) 1473vim . api . nvim_buf_set_lines ( ui . bufs . cmd , 0 , - 1 , false , { 'err' } ) 1474local o ={ end_row =0 , end_col =3 , hl_group ='ErrorMsg' } 1475vim . api . nvim_buf_set_extmark ( ui . bufs . cmd , ui . ns , 0 , 0 , o ) 1476ui . msg . expand_msg ( 'cmd' , 'dialog' ) 1477end ) 1478screen : expect ( [[ 1479| 1480{1:~ }|*9 1481{3: }| 1482{3:^ }| 1483{9:err} | 1484| 1485]] ) 1486end ) 1487end )