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