robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- TUI acceptance tests. 2-- Uses :terminal as a way to send keys and assert screen state. 3-- 4-- "bracketed paste" terminal feature: 5-- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode 6 7local t =require ( 'test.testutil' ) 8local n =require ( 'test.functional.testnvim' )() 9local Screen =require ( 'test.functional.ui.screen' ) 10local tt =require ( 'test.functional.testterm' ) 11 12local describe , it , before_each , after_each , pending , finally = 13t . describe , t . it , t . before_each , t . after_each , t . pending , t . finally 14local eq =t . eq 15local feed_data =tt . feed_data 16local clear =n . clear 17local command =n . command 18local exec =n . exec 19local exec_lua =n . exec_lua 20local testprg =n . testprg 21local retry =t . retry 22local nvim_prog =n . nvim_prog 23local nvim_set =n . nvim_set 24local ok =t . ok 25local read_file =t . read_file 26local fn =n . fn 27local api =n . api 28local is_os =t . is_os 29local new_pipename =n . new_pipename 30local set_session =n . set_session 31local write_file =t . write_file 32local eval =n . eval 33local assert_log =t . assert_log 34 35local testlog ='Xtest-tui-log' 36 37-- Using this to have 'notermguicolors' in Nvim instances without starting a timer 38-- that causes delay on exit with ASAN/TSAN. 39local env_notermguicolors ={ COLORTERM ='xterm-256color' } 40 41describe ( 'TUI' , function () 42it ( 'exit status 1 and error message with server --listen error #34365' , function () 43clear () 44local addr_in_use =api . nvim_get_vvar ( 'servername' ) 45local screen =tt . setup_child_nvim ( 46{ '--listen' , addr_in_use , '-u' , 'NONE' , '-i' , 'NONE' } , 47{ extra_rows =10 , cols =60 , env ={ NVIM_LOG_FILE =testlog } } 48) 49finally ( function () 50os . remove ( testlog ) 51end ) 52 53screen : expect ( { any =vim . pesc ( '[Process exited 1]' ) } ) 54 55-- When the address is very long, the error message may be only partly visible. 56if # addr_in_use <= 600 then 57screen : expect ( { 58any =vim . pesc ( 59( '%s: Failed to --listen: address already in use:' ): format ( 60fn . fnamemodify ( nvim_prog , ':t' ) 61) 62), 63unchanged =true , 64} ) 65end 66 67-- Always assert the log for the error message. 68assert_log ( 69vim . pesc ( 'Failed to start server: address already in use: ' .. addr_in_use ), 70testlog , 71100 72) 73end ) 74 75it ( 'suspending does not crash or hang' , function () 76clear () 77local screen =tt . setup_child_nvim ( { '--clean' } , { env =env_notermguicolors } ) 78local s0 =[[ 79^ | 80~ |*3 81{2:[No Name] 0,0-1 All}| 82| 83{5:-- TERMINAL --} | 84]] 85screen : expect ( s0 ) 86feed_data ( ':' ) 87local s1 =[[ 88| 89~ |*3 90{2:[No Name] 0,0-1 All}| 91:^ | 92{5:-- TERMINAL --} | 93]] 94screen : expect ( s1 ) 95feed_data ( 'suspend\r' ) 96if is_os ( 'win' ) then -- no-op on Windows 97screen : expect ( [[ 98^ | 99~ |*3 100{2:[No Name] 0,0-1 All}| 101:suspend | 102{5:-- TERMINAL --} | 103]] ) 104else -- resuming works on other platforms 105screen : expect ( [[ 106|*5 107^[Process suspended] | 108{5:-- TERMINAL --} | 109]] ) 110n . feed ( '<Space>' ) 111screen : expect ( s0 ) 112end 113feed_data ( ':' ) 114screen : expect ( s1 ) 115end ) 116 117it ( 'jobstart child writing to CON does not leak to screen' , function () 118-- A child job that writes to CON must not leak onto the TUI screen. The 119-- embedded server AttachConsole()'s the parent terminal (so server io.stdout 120-- e.g. SIXEL works), but jobs must get their own (windowless) console so 121-- writes to CON go nowhere visible. 122t . skip ( not is_os ( 'win' ), 'N/A Windows only' ) 123n . clear () 124finally ( function () 125n . check_close () 126end ) 127 128local screen =tt . setup_child_nvim ( { 129'--clean' , 130'--cmd' , 131'colorscheme vim' , 132'--cmd' , 133nvim_set .. ' laststatus=2 background=dark' , 134} , { env =env_notermguicolors } ) 135tt . override_screen_expect_for_conpty ( screen ) 136 137feed_data ( 'iZZZSENTINEL' ) 138 139-- Leave insert mode and run a job that writes directly to CON, blocking 140-- until it finishes. The CON output must not appear anywhere on screen. 141feed_data ( "\027\027:call jobwait([jobstart(['cmd', '/c', 'echo LEAKEDXYZ > CON'])])\013" ) 142 143screen : expect ( [[ 144ZZZSENTINE^L | 145{100:~ }|*3 146{3:[No Name] [+] }| 147| 148{5:-- TERMINAL --} | 149]] ) 150end ) 151end ) 152 153describe ( 'TUI :detach' , function () 154local child_server , screen 155 156local function setup_detach_child ( opts ) 157opts =opts or {} 158n . clear () 159finally ( function () 160n . check_close () 161end ) 162 163child_server =new_pipename () 164screen =tt . setup_child_nvim ( { 165'--listen' , 166child_server , 167'-u' , 168'NONE' , 169'-i' , 170'NONE' , 171'--cmd' , 172'colorscheme vim' , 173'--cmd' , 174nvim_set .. ' laststatus=2 background=dark' , 175} , { env =env_notermguicolors , cols =opts . cols } ) 176tt . override_screen_expect_for_conpty ( screen ) 177-- The child's `--listen` socket is created asynchronously wrt its PTY output. 178t . retry ( nil , 2000 , function () 179assert ( vim . uv . fs_stat ( child_server )) 180end ) 181end 182 183it ( 'does not stop server' , function () 184setup_detach_child () 185 186tt . feed_data ( 'iHello, World' ) 187screen : expect ( [[ 188Hello, World^ | 189{100:~ }|*3 190{3:[No Name] [+] }| 191{5:-- INSERT --} | 192{5:-- TERMINAL --} | 193]] ) 194 195local child_session =n . connect ( child_server ) 196finally ( function () 197-- Avoid a dangling process after :detach. 198child_session : request ( 'nvim_command' , 'qall!' ) 199end ) 200local status , child_uis =child_session : request ( 'nvim_list_uis' ) 201assert ( status ) 202eq ( 1 , # child_uis ) 203 204eq ( 205{ false , { 0 , 'Vim(detach):E16: Invalid range' } } , 206{ child_session : request ( 'nvim_command' , '2detach' ) } 207) 208eq ( 209{ false , { 0 , 'Vim(detach):E488: Trailing characters: foo: detach foo' } } , 210{ child_session : request ( 'nvim_command' , 'detach foo' ) } 211) 212 213tt . feed_data ( '\027\027:detach\013' ) 214-- Note: "Process exited" message is misleading; tt.setup_child_nvim() sees the foreground 215-- process (client) exited, and doesn't know the server is still running? 216screen : expect { 217any =[[Process exited 0]] , 218} 219 220child_uis --[[@type any[] ]] =( { child_session : request ( 'nvim_list_uis' ) } )[ 2 ] 221eq ( 0 , # child_uis ) 222 223-- NOTE: The tt.setup_child_nvim() screen just wraps :terminal, it's not connected to the child. 224-- To use it again, we need to detach the old one. 225screen : detach () 226 227-- Edit some text on the headless server. 228status =( child_session : request ( 'nvim_input' , 'ddiWe did it, pooky.<Esc><Esc>' )) 229assert ( status ) 230 231-- Test reattach by connecting a new TUI. 232local screen_reattached =tt . setup_child_nvim ( { 233'--remote-ui' , 234'--server' , 235child_server , 236} , { env =env_notermguicolors } ) 237 238screen_reattached : expect ( [[ 239We did it, pooky^. | 240{100:~ }|*3 241{3:[No Name] [+] }| 242| 243{5:-- TERMINAL --} | 244]] ) 245end ) 246 247it ( 'detach! keeps the UI attached but survives client disconnect' , function () 248-- Wide enough that the confirmation message doesn't trigger a |hit-enter| prompt. 249setup_detach_child ( { cols =80 } ) 250-- Capture the client (foreground TUI) job so we can kill it below. 251local term_job =n . api . nvim_buf_get_var ( 0 , 'terminal_job_id' ) 252 253-- Wait for the child server to come up (its socket to exist), then connect. 254local child_session ---@type test.Session 255retry ( nil , nil , function () 256child_session =n . connect ( child_server ) 257end ) 258finally ( function () 259-- Stop the (surviving) server so it doesn't dangle. 260pcall ( function () 261n . connect ( child_server ): request ( 'nvim_command' , 'qall!' ) 262end ) 263end ) 264 265feed_data ( '\027\027:detach!\013' ) 266screen : expect ( { any =vim . pesc ( 'Nvim will continue running' ) } ) 267 268-- Unlike ":detach", the UI is still attached. 269eq ( 1 , # ( { child_session : request ( 'nvim_list_uis' ) } )[ 2 ]) 270 271-- Simulate the host terminal disconnecting: SIGKILL the client so it can't shut down cleanly. 272-- On Windows this also exercises the console hand-off in rpc_close_event(). 273n . exec_lua ( function ( pid ) 274vim . uv . kill ( pid , 'sigkill' ) 275end , n . fn . jobpid ( term_job )) 276 277retry ( nil , 4000 , function () 278eq ( 2 , ( { child_session : request ( 'nvim_eval' , '1+1' ) } )[ 2 ]) 279end ) 280end ) 281 282it ( '% detaches other UIs' , function () 283setup_detach_child () 284finally ( function () 285pcall ( function () 286local s =n . connect ( child_server ) 287s : request ( 'nvim_command' , 'qall!' ) 288end ) 289end ) 290 291tt . feed_data ( 'iHello from detach!' ) 292screen : expect ( { any =vim . pesc ( 'Hello from detach!^' ) } ) 293tt . feed_data ( '\027' ) 294 295local child_session =n . connect ( child_server ) 296local _ , uis_before =child_session : request ( 'nvim_list_uis' ) 297eq ( 1 , # uis_before ) 298local tui_chan_id =uis_before [ 1 ]. chan 299 300-- :%detach with only 1 UI is a no-op. 301tt . feed_data ( ':%detach\013' ) 302screen : expect ( { any =vim . pesc ( 'No other UIs are attached' ) } ) 303local _ , uis_noop =child_session : request ( 'nvim_list_uis' ) 304eq ( 1 , # uis_noop ) 305 306child_session : request ( 'nvim_ui_attach' , 50 , 7 , {} ) 307local _ , uis_attached =child_session : request ( 'nvim_list_uis' ) 308eq ( 2 , # uis_attached ) 309 310-- Send the command in two steps, to avoid "Screen test succeeded immediately" warning. 311tt . feed_data ( ':%detach' ) 312screen : expect ( { any =vim . pesc ( ':%detach^' ) } ) 313tt . feed_data ( '\013' ) 314screen : expect ( [[ 315Hello from detach^! | 316{100:~ }|*3 317{3:[No Name] [+] }| 318| 319{5:-- TERMINAL --} | 320]] ) 321 322local verify_session =n . connect ( child_server ) 323local _ , uis_after =verify_session : request ( 'nvim_list_uis' ) 324eq ( 1 , # uis_after ) 325eq ( tui_chan_id , uis_after [ 1 ]. chan ) 326end ) 327 328it ( '% detaches the original UI when invoked from a later UI' , function () 329setup_detach_child () 330finally ( function () 331pcall ( function () 332local s =n . connect ( child_server ) 333s : request ( 'nvim_command' , 'qall!' ) 334end ) 335end ) 336 337screen : expect ( { any =vim . pesc ( '[No Name]' ) } ) 338local child_session =n . connect ( child_server ) 339child_session : request ( 'nvim_ui_attach' , 50 , 7 , {} ) 340local _ , uis_before =child_session : request ( 'nvim_list_uis' ) 341eq ( 2 , # uis_before ) 342 343eq ( { true , vim . NIL } , { child_session : request ( 'nvim_command' , '%detach' ) } ) 344screen : expect ( { any =[[Process exited 0]] } ) 345 346local status , uis_after =child_session : request ( 'nvim_list_uis' ) 347ok ( status ) 348eq ( 1 , # uis_after ) 349end ) 350end ) 351 352describe ( 'TUI :restart' , function () 353before_each ( n . clear ) 354after_each ( n . check_close ) 355 356--- Asserts that the server at `addr` has (or has not) restarted since `starttime`. 357---@param starttime integer v:starttime of the server before restart 358---@param sess table Session 359---@param addr string 360---@return integer starttime 361---@return table session 362local function assert_restarted ( starttime , sess , addr ) 363sess : close () 364local new_starttime 365-- Retry: old server may still be alive (connect succeeds but yields stale starttime), 366-- or on Windows the --listen address is restored async. 367retry ( nil , 5000 , function () 368local candidate =n . connect ( addr ) 369local status , t =candidate : request ( 'nvim_eval' , 'v:starttime' ) 370if not status then 371candidate : close () 372error ( type ( t ) == 'table' and t [ 2 ] or t ) 373end 374if t <= starttime then 375candidate : close () 376end 377ok ( t > starttime , ( 'v:starttime (%d) > old starttime (%d)' ): format ( t , starttime ), t ) 378sess =candidate 379new_starttime =t 380end ) 381return new_starttime , sess 382end 383 384it ( 'validation' , function () 385eq ( 'Vim(restart):E481: No range allowed: :1restart!' , t . pcall_err ( n . command , ':1restart!' )) 386end ) 387 388it ( ':restart (no bang) restores session, window layout' , function () 389local file ='Xtest-restart-file' 390write_file ( file , 'foobar' ) 391finally ( function () 392os . remove ( file ) 393end ) 394 395local server_pipe =new_pipename () 396local server_session 397finally ( function () 398if server_session then 399server_session : close () 400end 401end ) 402local screen =tt . setup_child_nvim ( { 403'--clean' , 404'--listen' , 405server_pipe , 406'--cmd' , 407'set notermguicolors laststatus=0 noruler noshowcmd' , 408} , { 409env =vim . tbl_extend ( 'force' , env_notermguicolors , { 410-- Ignore logs, because assert_restarted may log "connection refused" while it retries. 411NVIM_LOG_FILE =testlog , 412} ), 413} ) 414finally ( function () 415os . remove ( testlog ) 416end ) 417 418feed_data ( ':edit ' .. file .. '\r' ) 419feed_data ( ':wincmd v\r' ) 420screen : expect ( [[ 421^foobar │foobar | 422~ │~ | 423~ │~ | 424~ │~ | 425~ │~ | 426:wincmd v | 427{5:-- TERMINAL --} | 428]] ) 429server_session =n . connect ( server_pipe ) 430local _ , starttime =server_session : request ( 'nvim_eval' , 'v:starttime' ) 431eq ( { true , '' } , { server_session : request ( 'nvim_get_vvar' , 'this_session' ) } ) 432 433-- :restart 434feed_data ( ':restart\r' ) 435screen : expect ( [[ 436^foobar │foobar | 437~ │~ | 438~ │~ | 439~ │~ | 440~ │~ | 441| 442{5:-- TERMINAL --} | 443]] ) 444starttime , server_session =assert_restarted ( starttime , server_session , server_pipe ) 445eq ( { true , 'restart' } , { server_session : request ( 'nvim_get_vvar' , 'startreason' ) } ) 446eq ( { true , '' } , { server_session : request ( 'nvim_get_vvar' , 'this_session' ) } ) 447 448-- :restart! 449feed_data ( ':restart!\r' ) 450screen : expect ( [[ 451^ | 452~ |*4 453| 454{5:-- TERMINAL --} | 455]] ) 456starttime , server_session =assert_restarted ( starttime , server_session , server_pipe ) 457eq ( { true , 'restart!' } , { server_session : request ( 'nvim_get_vvar' , 'startreason' ) } ) 458 459feed_data ( ':qall!\r' ) 460screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 461end ) 462 463it ( 'ZR' , function () 464-- Just exercise ZR, don't need to test all :restart functionality here. 465local file ='Xtest-restart-file' 466write_file ( file , 'foo' ) 467finally ( function () 468os . remove ( file ) 469end ) 470local server_pipe =new_pipename () 471local server_session 472finally ( function () 473if server_session then 474server_session : close () 475end 476end ) 477local screen =tt . setup_child_nvim ( { 478'--clean' , 479'--listen' , 480server_pipe , 481'--cmd' , 482'set notermguicolors' , 483} , { 484env =vim . tbl_extend ( 'force' , env_notermguicolors , { 485-- Ignore logs, because assert_restarted may log "connection refused" while it retries. 486NVIM_LOG_FILE =testlog , 487} ), 488} ) 489finally ( function () 490os . remove ( testlog ) 491end ) 492feed_data ( ':edit ' .. file .. '\r' ) 493screen : expect ( { any ='foo' } ) 494 495server_session =n . connect ( server_pipe ) 496local _ , starttime =server_session : request ( 'nvim_eval' , 'v:starttime' ) 497 498-- ZR preserves screen state 499tt . feed_data ( 'ZR' ) 500starttime , server_session =assert_restarted ( starttime , server_session , server_pipe ) 501-- Match the full restored screen, to avoid "Screen test succeeded immediately" warning. 502screen : expect ( [[ 503^foo | 504~ |*3 505{2:Xtest-restart-file 1,1 All}| 506| 507{5:-- TERMINAL --} | 508]] ) 509 510-- [1-8]ZR does not preserve screen state 511tt . feed_data ( '1ZR' ) 512screen : expect ( { any =vim . pesc ( '[No Name]' ), none ='foo' } ) 513 514-- ZR on modified buffer fails with E37. 515tt . feed_data ( 'ifoo\027' ) 516tt . feed_data ( 'ZR' ) 517screen : expect ( { any ='E37:' } ) 518-- Overwrite the message so the next "E37" is a real transition, not a stale immediate match. 519tt . feed_data ( ':echo "cleared"\r' ) 520screen : expect ( { any ='cleared' , none ='E37:' } ) 521tt . feed_data ( '1ZR' ) 522screen : expect ( { any ='E37:' } ) 523 524-- [9]ZR discards unsaved changes. 525tt . feed_data ( '9ZR' ) 526screen : expect ( { any =vim . pesc ( '[No Name]' ) } ) 527starttime , server_session =assert_restarted ( starttime , server_session , server_pipe ) 528 529-- The server is now detached and needs to be quit explicitly. 530tt . feed_data ( ':qall!\r' ) 531end ) 532 533it ( 'works' , function () 534-- Log exit events + v:exitreason. 535local eventlog =t . tmpname () 536local initfile =t . tmpname () .. '.lua' 537local init =[[ 538local f = %q 539vim.api.nvim_create_autocmd({ 'QuitPre', 'ExitPre', 'VimLeavePre', 'VimLeave' }, { 540callback = function(ev) 541vim.fn.writefile({ ('%%s:%%s'):format(ev.event, vim.v.exitreason) }, f, 'a') 542end, 543}) 544]] 545write_file ( initfile , init : format ( eventlog )) 546finally ( function () 547os . remove ( eventlog ) 548os . remove ( initfile ) 549end ) 550 551local function assert_exitreason ( expected ) 552local default = 553'QuitPre:restart!\nExitPre:restart!\nVimLeavePre:restart!\nVimLeave:restart!\n' 554eq ( expected or default , t . read_file ( eventlog )) 555os . remove ( eventlog ) 556end 557 558local server_pipe =new_pipename () 559local screen =tt . setup_child_nvim ( { 560'--clean' , 561'-u' , 562initfile , 563'--listen' , 564server_pipe , 565'--cmd' , 566'colorscheme vim' , 567'--cmd' , 568'set laststatus=2 background=dark noruler noshowcmd' , 569} , { env ={ COLORTERM ='truecolor' } } ) 570screen : set_option ( 'rgb' , true ) 571screen : add_extra_attr_ids ( { 572[ 101 ] ={ bold =true , foreground =Screen . colors . WebGreen } , 573} ) 574 575-- 'termguicolors' support should be detected properly after :restart! 576-- The value of has("gui_running") should be 0 before and after :restart! 577local function assert_termguicolors_and_no_gui_running () 578tt . feed_data ( ':echo "&termguicolors: " .. &termguicolors\013' ) 579screen : expect ( { any ='&termguicolors: 1' } ) 580tt . feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 581screen : expect ( { any ='GUI Running: 0' } ) 582end 583 584local s0 =[[ 585^ | 586{1:~}{18: }|*3 587{3:[No Name] }| 588| 589{5:-- TERMINAL --} | 590]] 591screen : expect ( s0 ) 592assert_termguicolors_and_no_gui_running () 593 594local server_session =n . connect ( server_pipe ) 595local _ , server_pid =server_session : request ( 'nvim_call_function' , 'getpid' , {} ) 596local function assert_new_pid () 597server_session : close () 598-- On Windows, --listen address is restored async (after old server exits). 599if is_os ( 'win' ) then 600retry ( nil , 5000 , function () 601server_session =n . connect ( server_pipe ) 602end ) 603else 604server_session =n . connect ( server_pipe ) 605end 606local _ , new_pid =server_session : request ( 'nvim_call_function' , 'getpid' , {} ) 607t . neq ( server_pid , new_pid ) 608server_pid =new_pid 609end 610 611local s1 =[[ 612| 613^Hello1 | 614{1:~}{18: }|*2 615{3:[No Name] [+] }| 616| 617{5:-- TERMINAL --} | 618]] 619 620tt . feed_data ( ':set nomodified\013' ) 621tt . feed_data ( ':restart\013' ) 622screen : expect ( s0 ) 623assert_new_pid () 624assert_exitreason ( 'QuitPre:restart\nExitPre:restart\nVimLeavePre:restart\nVimLeave:restart\n' ) 625assert_termguicolors_and_no_gui_running () 626 627tt . feed_data ( ':set nomodified\013' ) 628-- Command is run on new server. 629tt . feed_data ( ":restart! put ='Hello1'\013" ) 630screen : expect ( s1 ) 631assert_new_pid () 632assert_exitreason () 633assert_termguicolors_and_no_gui_running () 634 635-- Complex command following +cmd. 636tt . feed_data ( ":restart! +qall! put ='Hello2' | put ='World2'\013" ) 637screen : expect ( [[ 638| 639Hello2 | 640^World2 | 641{1:~}{18: }| 642{3:[No Name] [+] }| 643| 644{5:-- TERMINAL --} | 645]] ) 646assert_new_pid () 647assert_exitreason () 648assert_termguicolors_and_no_gui_running () 649 650-- Check ":restart!" on an unmodified buffer. 651tt . feed_data ( ':set nomodified\013' ) 652tt . feed_data ( ':restart!\013' ) 653screen : expect ( s0 ) 654assert_new_pid () 655assert_exitreason () 656assert_termguicolors_and_no_gui_running () 657 658-- Check ":restart! +qall!" on an unmodified buffer. 659tt . feed_data ( ':restart! +qall!\013' ) 660screen : expect ( s0 ) 661assert_new_pid () 662assert_exitreason () 663assert_termguicolors_and_no_gui_running () 664 665-- Check ":restart[!] +echo" cannot restart server. 666-- Check the full screen state to ensure this doesn't pollute the current UI. 667for _ , cmd in ipairs ( { ':restart' , ':restart!' } ) do 668tt . feed_data ( cmd .. ' +echo\013' ) 669screen : expect ( [[ 670| 671{1:~}{18: }| 672{3: }| 673{9:E5201: Restart failed: +cmd did not quit server: e}| 674{9:cho} | 675{101:Press ENTER or type command to continue}^ | 676{5:-- TERMINAL --} | 677]] ) 678tt . feed_data ( '\013' ) 679-- Return to a distinct state so the next screen:expect() doesn't "succeed immediately". 680screen : expect ( { any =vim . pesc ( '[No Name]' ) } ) 681end 682 683tt . feed_data ( 'ithis will be removed\027' ) 684screen : expect ( { any =vim . pesc ( 'this will be remove^d' ) } ) 685 686-- Check ":confirm restart!" on a modified buffer. 687tt . feed_data ( ':confirm restart!\013' ) 688screen : expect ( { any =vim . pesc ( 'Save changes to "Untitled"?' ) } ) 689 690-- Cancel the operation (abandons restart). 691tt . feed_data ( 'C\013' ) 692screen : expect ( { any =vim . pesc ( '[No Name]' ) } ) 693-- Failed/cancelled restarts still fire QuitPre/ExitPre (but not VimLeave[Pre]). 694assert_exitreason ( 'QuitPre:restart!\nExitPre:restart!\n' ) 695 696-- Check :restart! respects 'confirm' option. 697tt . feed_data ( ':set confirm\013' ) 698tt . feed_data ( ':restart!\013' ) 699screen : expect ( { any =vim . pesc ( 'Save changes to "Untitled"?' ) } ) 700tt . feed_data ( 'C\013' ) 701screen : expect ( { any =vim . pesc ( '[No Name]' ) } ) 702tt . feed_data ( ':set noconfirm\013' ) 703-- Failed/cancelled restarts still fire QuitPre/ExitPre (but not VimLeave[Pre]). 704assert_exitreason ( 'QuitPre:restart!\nExitPre:restart!\n' ) 705 706-- Check ":confirm restart! <cmd>" on a modified buffer. 707tt . feed_data ( ":confirm restart! put ='Hello3'\013" ) 708screen : expect ( { any =vim . pesc ( 'Save changes to "Untitled"?' ) } ) 709tt . feed_data ( 'N\013' ) 710screen : expect ( { any ='%^Hello3' } ) 711assert_new_pid () 712assert_exitreason () 713assert_termguicolors_and_no_gui_running () 714 715-- Check ":confirm restart! +echo" correctly ignores ":confirm" 716tt . feed_data ( ':confirm restart! +echo\013' ) 717screen : expect ( { any =vim . pesc ( 'E5201: Restart failed: +cmd did not quit server' ) } ) 718 719-- Check ":restart[!]" on a modified buffer. 720tt . feed_data ( 'ithis will be removed\027' ) 721for cmd , exitreason in pairs ( { 722[ ':restart' ] ='restart' , 723[ ':restart!' ] ='restart!' , 724} ) do 725tt . feed_data ( cmd ) 726-- Assert the command-line echo so the E37 assertion below doesn't "succeed immediately". 727screen : expect ( { any =vim . pesc ( cmd ) } ) 728tt . feed_data ( '\013' ) 729screen : expect ( { any =vim . pesc ( 'E37: No write since last change' ) } ) 730assert_exitreason (( 'QuitPre:%s\nExitPre:%s\n' ): format ( exitreason , exitreason )) 731end 732 733-- Check ":restart! +qall!" on a modified buffer. 734tt . feed_data ( 'ithis will be removed\027' ) 735tt . feed_data ( ':restart! +qall!\013' ) 736screen : expect ( s0 ) 737assert_new_pid () 738assert_exitreason () 739assert_termguicolors_and_no_gui_running () 740 741if not is_os ( 'win' ) then 742-- No --listen conflict when server exit is delayed. 743feed_data ( ':lua vim.schedule(function() vim.wait(100) end); vim.cmd("restart!")\n' ) 744screen : expect ( s0 ) 745assert_new_pid () 746assert_exitreason () 747assert_termguicolors_and_no_gui_running () 748end 749 750screen : try_resize ( 60 , 6 ) 751screen : expect ( [[ 752^ | 753{1:~}{18: }|*2 754{3:[No Name] }| 755| 756{5:-- TERMINAL --} | 757]] ) 758 759--- Check that ":restart!" uses the updated size after terminal resize. 760tt . feed_data ( ':restart! echo "restarted"\013' ) 761screen : expect ( [[ 762^ | 763{1:~}{18: }|*2 764{3:[No Name] }| 765restarted | 766{5:-- TERMINAL --} | 767]] ) 768assert_new_pid () 769assert_exitreason () 770assert_termguicolors_and_no_gui_running () 771 772-- The server is now detached and needs to be quit explicitly. 773feed_data ( ':qall!\r' ) 774screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 775end ) 776 777it ( 'drops "-" and "-- [files…]" from v:argv #34417' , function () 778t . skip ( is_os ( 'win' ), 'stdin behavior differs on Windows' ) 779local file ='file.lua' 780write_file ( file , "print('-S works')\n" ) 781finally ( function () 782os . remove ( file ) 783end ) 784local server_session 785finally ( function () 786if server_session then 787server_session : close () 788end 789end ) 790local server_pipe =new_pipename () 791local screen =tt . setup_child_nvim ( { 792'-u' , 793'NONE' , 794'-i' , 795'NONE' , 796'--listen' , 797server_pipe , 798'--cmd' , 799'set notermguicolors' , 800'-S' , 801file , 802'-s' , 803'-' , 804'-' , 805'--' , 806'Xtest-file1' , 807'Xtest-file2' , 808} , { env =env_notermguicolors } ) 809screen : expect ( [[ 810^ | 811~ |*3 812{2:Xtest-file1 0,0-1 All}| 813-S works | 814{5:-- TERMINAL --} | 815]] ) 816server_session =n . connect ( server_pipe ) 817local expr ='index(v:argv, "-") >= 0 || index(v:argv, "--") >= 0 ? v:true : v:false' 818local has_s ='index(v:argv, "-s") >= 0 ? v:true : v:false' 819local has_S ='index(v:argv, "-S") >= 0 ? v:true : v:false' 820eq ( { true , true } , { server_session : request ( 'nvim_eval' , expr ) } ) 821eq ( { true , true } , { server_session : request ( 'nvim_eval' , has_s ) } ) 822eq ( { true , true } , { server_session : request ( 'nvim_eval' , has_S ) } ) 823 824tt . feed_data ( ":restart! put='foo'\013" ) 825screen : expect ( [[ 826| 827^foo | 828~ |*2 829{2:[No Name] [+] 2,1 All}| 830| 831{5:-- TERMINAL --} | 832]] ) 833server_session : close () 834server_session =n . connect ( server_pipe ) 835 836eq ( { true , false } , { server_session : request ( 'nvim_eval' , expr ) } ) 837eq ( { true , false } , { server_session : request ( 'nvim_eval' , has_s ) } ) 838eq ( { true , false } , { server_session : request ( 'nvim_eval' , has_S ) } ) 839 840-- local argv = ({ server_session:request('nvim_eval', 'v:argv') })[2] --[[@type table]] 841-- eq(13, #argv) 842-- eq("-c put='foo'", table.concat(argv, ' ', #argv - 1, #argv)) 843 844-- The server is now detached and needs to be quit explicitly. 845feed_data ( ':qall!\r' ) 846screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 847end ) 848 849it ( '[command] triggers autocommands properly #38549' , function () 850local screen =tt . setup_child_nvim ( { 851'--clean' , 852'--cmd' , 853'autocmd FileType text echomsg "TRIGGERED: " .. bufnr()' , 854'--cmd' , 855'set notermguicolors noswapfile laststatus=0' , 856} , { env =env_notermguicolors } ) 857screen : expect ( [[ 858^ | 859~ |*4 8600,0-1 All| 861{5:-- TERMINAL --} | 862]] ) 863 864-- 'laststatus' should be 0 in the new Nvim and FileType event should be triggered. 865feed_data ( ':restart! set nowrap | edit test/functional/fixtures/bigfile.txt\r' ) 866screen : expect ( [[ 867^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; | 8680001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; | 8690002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; | 8700003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; | 8710004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;| 872TRIGGERED: 1 1,1 Top| 873{5:-- TERMINAL --} | 874]] ) 875 876-- The server is now detached and needs to be quit explicitly. 877feed_data ( ':qall!\r' ) 878screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 879end ) 880 881it ( 'new server loads user config after old server exits #38569' , function () 882local config_file ='Xrestart_session_config.lua' 883local session_file ='Xrestart_session.vim' 884write_file ( 885config_file , 886( [[ 887vim.api.nvim_create_autocmd("VimLeavePre", { 888callback = function() 889vim.cmd('mksession! %s') 890end, 891}) 892 893if vim.v.vim_did_enter and vim.uv.fs_stat('%s') then 894vim.cmd('source %s') 895end 896]] ): format ( session_file , session_file , session_file ) 897) 898finally ( function () 899os . remove ( config_file ) 900os . remove ( session_file ) 901end ) 902 903local screen =tt . setup_child_nvim ( { 904'--clean' , 905'-u' , 906config_file , 907'--cmd' , 908'set notermguicolors noswapfile laststatus=0 nowrap noruler noshowcmd' , 909} , { env =env_notermguicolors } ) 910screen : expect ( [[ 911^ | 912~ |*4 913| 914{5:-- TERMINAL --} | 915]] ) 916 917feed_data ( ':rightbelow 28vsplit test/functional/fixtures/bigfile.txt\r' ) 918screen : expect ( [[ 919│^0000;<control>;Cc;0;BN;;;;;N| 920~ │0001;<control>;Cc;0;BN;;;;;N| 921~ │0002;<control>;Cc;0;BN;;;;;N| 922~ │0003;<control>;Cc;0;BN;;;;;N| 923~ │0004;<control>;Cc;0;BN;;;;;N| 924| 925{5:-- TERMINAL --} | 926]] ) 927 928feed_data ( ':restart! echo "restarted"\r' ) 929screen : expect ( [[ 930│^0000;<control>;Cc;0;BN;;;;;N| 931~ │0001;<control>;Cc;0;BN;;;;;N| 932~ │0002;<control>;Cc;0;BN;;;;;N| 933~ │0003;<control>;Cc;0;BN;;;;;N| 934~ │0004;<control>;Cc;0;BN;;;;;N| 935restarted | 936{5:-- TERMINAL --} | 937]] ) 938 939feed_data ( ':set sessionoptions-=winsize | restart!\r' ) 940screen : expect ( [[ 941│^0000;<control>;Cc;0;BN;;;| 942~ │0001;<control>;Cc;0;BN;;;| 943~ │0002;<control>;Cc;0;BN;;;| 944~ │0003;<control>;Cc;0;BN;;;| 945~ │0004;<control>;Cc;0;BN;;;| 946| 947{5:-- TERMINAL --} | 948]] ) 949 950-- The server is now detached and needs to be quit explicitly. 951feed_data ( ':qall!\r' ) 952screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 953end ) 954end ) 955 956describe ( 'TUI :connect' , function () 957before_each ( n . clear ) 958after_each ( n . check_close ) 959 960local screen_empty =[[ 961^ | 962{100:~ }|*5 963| 964]] 965 966it ( 'leaves the current server running' , function () 967local server1 =new_pipename () 968local screen1 =tt . setup_child_nvim ( { '--listen' , server1 , '--clean' } ) 969screen1 : expect ( { any =vim . pesc ( '[No Name]' ) } ) 970 971tt . feed_data ( ':connect\013' ) 972screen1 : expect ( { any ='E471: Argument required' } ) 973 974tt . feed_data ( 'iThis is server 1.\027' ) 975screen1 : expect ( { any =vim . pesc ( 'This is server 1^.' ) } ) 976 977-- Prevent screen2 from receiving the old terminal state. 978command ( 'enew' ) 979screen1 : expect ( screen_empty ) 980screen1 : detach () 981 982local server2 =new_pipename () 983local screen2 =tt . setup_child_nvim ( { '--listen' , server2 , '--clean' } ) 984screen2 : expect ( { any =vim . pesc ( '[No Name]' ) } ) 985 986tt . feed_data ( 'iThis is server 2.\027' ) 987screen2 : expect ( { any =vim . pesc ( 'This is server 2^.' ) } ) 988 989if is_os ( 'win' ) then 990-- still supports backslashes 991server1 =server1 : gsub ( '/' , '\\' ) 992end 993tt . feed_data ( ':connect ' .. server1 .. '\013' ) 994screen2 : expect ( { any =vim . pesc ( 'This is server 1^.' ) } ) 995 996local server1_session =n . connect ( server1 ) 997server1_session : request ( 'nvim_command' , 'qall!' ) 998screen2 : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 999 1000screen2 : detach () 1001 1002local server2_session =n . connect ( server2 ) 1003 1004local screen3 =tt . setup_child_nvim ( { '--remote-ui' , '--server' , server2 } ) 1005screen3 : expect ( { any =vim . pesc ( 'This is server 2^.' ) } ) 1006 1007screen3 : detach () 1008server2_session : request ( 'nvim_command' , 'qall!' ) 1009end ) 1010 1011it ( '! stops the current server' , function () 1012local server1 =new_pipename () 1013local screen1 =tt . setup_child_nvim ( { '--listen' , server1 , '--clean' } ) 1014screen1 : expect ( { any =vim . pesc ( '[No Name]' ) } ) 1015 1016tt . feed_data ( 'iThis is server 1.\027' ) 1017screen1 : expect ( { any =vim . pesc ( 'This is server 1^.' ) } ) 1018 1019-- Prevent screen2 from receiving the old terminal state. 1020command ( 'enew' ) 1021screen1 : expect ( screen_empty ) 1022screen1 : detach () 1023 1024local server2 =new_pipename () 1025local screen2 =tt . setup_child_nvim ( { '--listen' , server2 , '--clean' } ) 1026screen2 : expect ( { any =vim . pesc ( '[No Name]' ) } ) 1027 1028tt . feed_data ( ':connect! ' .. server1 .. '\013' ) 1029screen2 : expect ( { any =vim . pesc ( 'This is server 1^.' ) } ) 1030 1031retry ( nil , nil , function () 1032eq ( nil , vim . uv . fs_stat ( server2 )) 1033end ) 1034 1035local server1_session =n . connect ( server1 ) 1036server1_session : request ( 'nvim_command' , 'qall!' ) 1037screen2 : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 1038 1039screen2 : detach () 1040end ) 1041end ) 1042 1043describe ( 'TUI' , function () 1044local screen --[[@type test.functional.ui.screen]] 1045local child_session --[[@type test.Session]] 1046local child_exec_lua --[[@type fun(code: string, ...):any]] 1047 1048before_each ( function () 1049clear () 1050local child_server =new_pipename () 1051screen =tt . setup_child_nvim ( { 1052'--listen' , 1053child_server , 1054'--clean' , 1055'--cmd' , 1056nvim_set .. ' laststatus=2 background=dark' , 1057'--cmd' , 1058'colorscheme vim' , 1059} , { env =env_notermguicolors } ) 1060screen : expect ( [[ 1061^ | 1062{100:~ }|*3 1063{3:[No Name] }| 1064| 1065{5:-- TERMINAL --} | 1066]] ) 1067child_session =n . connect ( child_server ) 1068child_exec_lua =tt . make_lua_executor ( child_session ) 1069end ) 1070 1071-- Wait for mode in the child Nvim (avoid "typeahead race" #10826). 1072local function wait_for_mode ( mode ) 1073retry ( nil , nil , function () 1074local _ , m =child_session : request ( 'nvim_get_mode' ) 1075eq ( mode , m . mode ) 1076end ) 1077end 1078 1079-- Assert buffer contents in the child Nvim. 1080local function expect_child_buf_lines ( expected ) 1081assert ( type ( {} ) == type ( expected )) 1082retry ( nil , nil , function () 1083local _ , buflines =child_session : request ( 'nvim_buf_get_lines' , 0 , 0 , - 1 , false ) 1084eq ( expected , buflines ) 1085end ) 1086end 1087 1088-- Ensure both child client and child server have processed pending events. 1089local function poke_both_eventloop () 1090child_exec_lua ( [[ 1091_G.termresponse = nil 1092vim.api.nvim_create_autocmd('TermResponse', { 1093once = true, 1094callback = function(ev) _G.termresponse = ev.data.sequence end, 1095}) 1096]] ) 1097feed_data ( '\027P0$r\027\\' ) 1098retry ( nil , nil , function () 1099eq ( '\027P0$r' , child_exec_lua ( 'return _G.termresponse' )) 1100end ) 1101end 1102 1103it ( 'rapid resize #7572 #7628' , function () 1104-- Need buffer rows to provoke the behavior. 1105feed_data ( ':edit test/functional/fixtures/bigfile.txt\n' ) 1106screen : expect ( [[ 1107^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; | 11080001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; | 11090002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; | 11100003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; | 1111{3:test/functional/fixtures/bigfile.txt }| 1112:edit test/functional/fixtures/bigfile.txt | 1113{5:-- TERMINAL --} | 1114]] ) 1115command ( 'call jobresize(b:terminal_job_id, 58, 9)' ) 1116command ( 'call jobresize(b:terminal_job_id, 62, 13)' ) 1117command ( 'call jobresize(b:terminal_job_id, 100, 42)' ) 1118command ( 'call jobresize(b:terminal_job_id, 37, 1000)' ) 1119-- Resize to <5 columns. 1120screen : try_resize ( 4 , 44 ) 1121command ( 'call jobresize(b:terminal_job_id, 4, 1000)' ) 1122-- Resize to 1 row, then to 1 column, then increase rows to 4. 1123screen : try_resize ( 44 , 1 ) 1124command ( 'call jobresize(b:terminal_job_id, 44, 1)' ) 1125screen : try_resize ( 1 , 1 ) 1126command ( 'call jobresize(b:terminal_job_id, 1, 1)' ) 1127screen : try_resize ( 1 , 4 ) 1128command ( 'call jobresize(b:terminal_job_id, 1, 4)' ) 1129screen : try_resize ( 57 , 17 ) 1130command ( 'call jobresize(b:terminal_job_id, 57, 17)' ) 1131retry ( nil , nil , function () 1132eq ( { true , 57 } , { child_session : request ( 'nvim_win_get_width' , 0 ) } ) 1133end ) 1134end ) 1135 1136it ( 'accepts resize while pager is active' , function () 1137tt . override_screen_expect_for_conpty ( screen ) 1138child_session : request ( 1139'nvim_exec2' , 1140[[ 1141set more 1142func! ManyErr() 1143for i in range(20) 1144echoerr "FAIL ".i 1145endfor 1146endfunc 1147]] , 1148{} 1149) 1150feed_data ( ':call ManyErr()\r' ) 1151screen : expect ( [[ 1152{101:Error in function ManyErr:} | 1153{103:line 2:} | 1154{101:FAIL 0} | 1155{101:FAIL 1} | 1156{101:FAIL 2} | 1157{102:-- More --}^ | 1158{5:-- TERMINAL --} | 1159]] ) 1160 1161screen : try_resize ( 50 , 10 ) 1162screen : expect ( [[ 1163:call ManyErr() | 1164{101:Error in function ManyErr:} | 1165{103:line 2:} | 1166{101:FAIL 0} | 1167{101:FAIL 1} | 1168{101:FAIL 2} | 1169|*2 1170{102:-- More --}^ | 1171{5:-- TERMINAL --} | 1172]] ) 1173 1174feed_data ( 'j' ) 1175screen : expect ( [[ 1176{101:Error in function ManyErr:} | 1177{103:line 2:} | 1178{101:FAIL 0} | 1179{101:FAIL 1} | 1180{101:FAIL 2} | 1181{101:FAIL 3} | 1182{101:FAIL 4} | 1183{101:FAIL 5} | 1184{102:-- More --}^ | 1185{5:-- TERMINAL --} | 1186]] ) 1187 1188screen : try_resize ( 50 , 7 ) 1189screen : expect ( [[ 1190{101:FAIL 1} | 1191{101:FAIL 2} | 1192{101:FAIL 3} | 1193{101:FAIL 4} | 1194{101:FAIL 5} | 1195{102:-- More --}^ | 1196{5:-- TERMINAL --} | 1197]] ) 1198 1199screen : try_resize ( 50 , 5 ) 1200screen : expect ( [[ 1201{101:FAIL 3} | 1202{101:FAIL 4} | 1203{101:FAIL 5} | 1204{102:-- More --}^ | 1205{5:-- TERMINAL --} | 1206]] ) 1207 1208feed_data ( 'g' ) 1209screen : expect ( [[ 1210:call ManyErr() | 1211{101:Error in function ManyErr:} | 1212{103:line 2:} | 1213{102:-- More --}^ | 1214{5:-- TERMINAL --} | 1215]] ) 1216 1217screen : try_resize ( 50 , 10 ) 1218screen : expect ( [[ 1219:call ManyErr() | 1220{101:Error in function ManyErr:} | 1221{103:line 2:} | 1222{101:FAIL 0} | 1223{101:FAIL 1} | 1224{101:FAIL 2} | 1225{101:FAIL 3} | 1226{101:FAIL 4} | 1227{102:-- More --}^ | 1228{5:-- TERMINAL --} | 1229]] ) 1230 1231feed_data ( '\003' ) 1232screen : expect ( [[ 1233^ | 1234{100:~ }|*6 1235{3:[No Name] }| 1236| 1237{5:-- TERMINAL --} | 1238]] ) 1239end ) 1240 1241it ( 'accepts basic utf-8 input' , function () 1242feed_data ( 'iabc\ntest1\ntest2' ) 1243screen : expect ( [[ 1244abc | 1245test1 | 1246test2^ | 1247{100:~ }| 1248{3:[No Name] [+] }| 1249{5:-- INSERT --} | 1250{5:-- TERMINAL --} | 1251]] ) 1252feed_data ( '\027' ) 1253screen : expect ( [[ 1254abc | 1255test1 | 1256test^2 | 1257{100:~ }| 1258{3:[No Name] [+] }| 1259| 1260{5:-- TERMINAL --} | 1261]] ) 1262end ) 1263 1264it ( 'interprets leading ESC byte as ALT modifier in normal-mode' , function () 1265local keys ='dfghjkl' 1266for c in keys : gmatch ( '.' ) do 1267feed_data ( ':nnoremap <a-' .. c .. '> ialt-' .. c .. '<cr><esc>\r' ) 1268feed_data ( '\027' .. c ) 1269end 1270feed_data ( ':nnoremap <a-esc> ialt-esc<esc>\r' ) 1271feed_data ( '\027\027' ) 1272screen : expect ( [[ 1273alt-j | 1274alt-k | 1275alt-l | 1276alt-es^c | 1277{3:[No Name] [+] }| 1278| 1279{5:-- TERMINAL --} | 1280]] ) 1281feed_data ( 'gg' ) 1282screen : expect ( [[ 1283^alt-d | 1284alt-f | 1285alt-g | 1286alt-h | 1287{3:[No Name] [+] }| 1288| 1289{5:-- TERMINAL --} | 1290]] ) 1291end ) 1292 1293it ( 'interprets ESC+key as ALT chord in i_CTRL-V' , function () 1294-- Vim represents ALT/META by setting the "high bit" of the modified key: 1295-- ALT+j inserts "ê". Nvim does not (#3982). 1296feed_data ( 'i\022\027j' ) 1297screen : expect ( [[ 1298<M-j>^ | 1299{100:~ }|*3 1300{3:[No Name] [+] }| 1301{5:-- INSERT --} | 1302{5:-- TERMINAL --} | 1303]] ) 1304end ) 1305 1306it ( 'interprets ESC encoded with kitty keyboard protocol' , function () 1307child_session : request ( 1308'nvim_exec2' , 1309[[ 1310nnoremap <M-;> <Nop> 1311nnoremap <Esc> AESC<Esc> 1312nnoremap <C-Esc> ACtrlEsc<Esc> 1313nnoremap <D-Esc> ASuperEsc<Esc> 1314nnoremap ; Asemicolon<Esc> 1315]] , 1316{} 1317) 1318-- Works with no modifier 1319feed_data ( '\027[27u;' ) 1320expect_child_buf_lines ( { 'ESCsemicolon' } ) 1321-- Works with Ctrl modifier 1322feed_data ( '\027[27;5u' ) 1323expect_child_buf_lines ( { 'ESCsemicolonCtrlEsc' } ) 1324-- Works with Super modifier 1325feed_data ( '\027[27;9u' ) 1326expect_child_buf_lines ( { 'ESCsemicolonCtrlEscSuperEsc' } ) 1327-- Works with NumLock modifier (which should be the same as no modifier) #33799 1328feed_data ( '\027[27;129u' ) 1329expect_child_buf_lines ( { 'ESCsemicolonCtrlEscSuperEscESC' } ) 1330screen : expect ( [[ 1331ESCsemicolonCtrlEscSuperEscES^C | 1332{100:~ }|*3 1333{3:[No Name] [+] }| 1334| 1335{5:-- TERMINAL --} | 1336]] ) 1337-- ESC+; should be recognized as <M-;> when <M-;> is mapped 1338feed_data ( '\027;' ) 1339screen : expect_unchanged () 1340expect_child_buf_lines ( { 'ESCsemicolonCtrlEscSuperEscESC' } ) 1341end ) 1342 1343it ( 'interprets ESC NUL as <M-C-Space> #17198' , function () 1344t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 1345feed_data ( 'i\022\027\000' ) 1346screen : expect ( [[ 1347<M-C-Space>^ | 1348{100:~ }|*3 1349{3:[No Name] [+] }| 1350{5:-- INSERT --} | 1351{5:-- TERMINAL --} | 1352]] ) 1353end ) 1354 1355it ( 'does not interpret ESC preceding repeat/release event as ALT #41763' , function () 1356child_session : request ( 'nvim_command' , 'noremap <M-Esc> <Nop>' ) 1357child_session : request ( 'nvim_command' , 'noremap! <M-Esc> <Nop>' ) 1358feed_data ( 'i\015' ) 1359wait_for_mode ( 'niI' ) 1360feed_data ( '\027\027[27;1:3u' ) -- ESC, ESC release 1361wait_for_mode ( 'i' ) 1362feed_data ( '\015' ) 1363wait_for_mode ( 'niI' ) 1364feed_data ( '\027\027[27;1:2u\027[27;1:3u' ) -- ESC, ESC repeat, ESC release 1365wait_for_mode ( 'n' ) 1366end ) 1367 1368it ( "split sequences work within 'ttimeoutlen' time" , function () 1369poke_both_eventloop () -- Make sure startup requests have finished. 1370-- The split sequences below are always completed, so this timeout never actually fires; it only 1371-- needs to exceed the inter-byte gap, which balloons on slow CI. 1372child_session : request ( 'nvim_set_option_value' , 'ttimeoutlen' , n . load_adjust ( 1000 ), {} ) 1373feed_data ( 'i' ) 1374screen : expect ( [[ 1375^ | 1376{100:~ }|*3 1377{3:[No Name] }| 1378{5:-- INSERT --} | 1379{5:-- TERMINAL --} | 1380]] ) 1381-- Split UTF-8 '⌂' character 1382feed_data ( '\226' ) 1383screen : expect_unchanged ( false , 25 ) 1384feed_data ( '\140' ) 1385screen : expect_unchanged ( false , 25 ) 1386feed_data ( '\130' ) 1387screen : expect ( [[ 1388⌂^ | 1389{100:~ }|*3 1390{3:[No Name] [+] }| 1391{5:-- INSERT --} | 1392{5:-- TERMINAL --} | 1393]] ) 1394-- Split CSI u escape sequence for Ctrl-X 1395feed_data ( '\027' ) 1396screen : expect_unchanged ( false , 25 ) 1397feed_data ( '[' ) 1398screen : expect_unchanged ( false , 25 ) 1399feed_data ( '120;' ) 1400screen : expect_unchanged ( false , 25 ) 1401feed_data ( '5u' ) 1402screen : expect ( [[ 1403⌂^ | 1404{100:~ }|*3 1405{3:[No Name] [+] }| 1406{5:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)} | 1407{5:-- TERMINAL --} | 1408]] ) 1409 1410-- <Esc> is sent after 'ttimeoutlen' exceeds. Use a small value so the sleep below reliably exceeds it. 1411child_session : request ( 'nvim_set_option_value' , 'ttimeoutlen' , 250 , {} ) 1412poke_both_eventloop () 1413 1414feed_data ( '\027' ) 1415screen : expect_unchanged ( false , 25 ) 1416vim . uv . sleep ( 225 ) 1417screen : expect ( [[ 1418^⌂ | 1419{100:~ }|*3 1420{3:[No Name] [+] }| 1421| 1422{5:-- TERMINAL --} | 1423]] ) 1424end ) 1425 1426it ( 'accepts ASCII control sequences' , function () 1427feed_data ( 'i' ) 1428feed_data ( '\022\007' ) -- ctrl+g 1429feed_data ( '\022\022' ) -- ctrl+v 1430feed_data ( '\022\013' ) -- ctrl+m 1431screen : expect ( [[ 1432{104:^G^V^M}^ | 1433{100:~ }|*3 1434{3:[No Name] [+] }| 1435{5:-- INSERT --} | 1436{5:-- TERMINAL --} | 1437]] ) 1438child_session : request ( 'nvim_set_keymap' , 'i' , '\031' , '!!!' , {} ) 1439feed_data ( '\031' ) 1440screen : expect ( [[ 1441{104:^G^V^M}!!!^ | 1442{100:~ }|*3 1443{3:[No Name] [+] }| 1444{5:-- INSERT --} | 1445{5:-- TERMINAL --} | 1446]] ) 1447child_session : request ( 'nvim_buf_delete' , 0 , { force =true } ) 1448child_session : request ( 'nvim_set_option_value' , 'laststatus' , 0 , {} ) 1449child_session : request ( 1450'nvim_call_function' , 1451'jobstart' , 1452{ { testprg ( 'shell-test' ), 'INTERACT' } , { term =true } } 1453) 1454screen : expect ( [[ 1455interact $ ^ | 1456|*4 1457{5:-- TERMINAL --} |*2 1458]] ) 1459-- mappings for C0 control codes should work in Terminal mode #33750 1460child_session : request ( 'nvim_set_keymap' , 't' , '\031' , '<Cmd>new<CR>' , {} ) 1461feed_data ( '\031' ) 1462screen : expect ( [[ 1463^ | 1464{100:~ }| 1465{3:[No Name] }| 1466interact $ | 1467|*2 1468{5:-- TERMINAL --} | 1469]] ) 1470end ) 1471 1472local function test_mouse_wheel ( esc ) 1473t . skip ( is_os ( 'win' ), 'FIXME: some spaces have wrong attrs on Windows' ) 1474child_session : request ( 1475'nvim_exec2' , 1476[[ 1477set number nostartofline nowrap mousescroll=hor:1,ver:1 1478call setline(1, repeat([join(range(10), '----')], 10)) 1479vsplit 1480]] , 1481{} 1482) 1483screen : expect ( [[ 1484{103: 1 }^0----1----2----3----4│{103: 1 }0----1----2----3----| 1485{103: 2 }0----1----2----3----4│{103: 2 }0----1----2----3----| 1486{103: 3 }0----1----2----3----4│{103: 3 }0----1----2----3----| 1487{103: 4 }0----1----2----3----4│{103: 4 }0----1----2----3----| 1488{3:[No Name] [+] }{2:[No Name] [+] }| 1489| 1490{5:-- TERMINAL --} | 1491]] ) 1492-- <ScrollWheelDown> in active window 1493if esc then 1494feed_data ( '\027[<65;8;1M' ) 1495else 1496api . nvim_input_mouse ( 'wheel' , 'down' , '' , 0 , 0 , 7 ) 1497end 1498screen : expect ( [[ 1499{103: 2 }^0----1----2----3----4│{103: 1 }0----1----2----3----| 1500{103: 3 }0----1----2----3----4│{103: 2 }0----1----2----3----| 1501{103: 4 }0----1----2----3----4│{103: 3 }0----1----2----3----| 1502{103: 5 }0----1----2----3----4│{103: 4 }0----1----2----3----| 1503{3:[No Name] [+] }{2:[No Name] [+] }| 1504| 1505{5:-- TERMINAL --} | 1506]] ) 1507-- <ScrollWheelDown> in inactive window 1508if esc then 1509feed_data ( '\027[<65;48;1M' ) 1510else 1511api . nvim_input_mouse ( 'wheel' , 'down' , '' , 0 , 0 , 47 ) 1512end 1513screen : expect ( [[ 1514{103: 2 }^0----1----2----3----4│{103: 2 }0----1----2----3----| 1515{103: 3 }0----1----2----3----4│{103: 3 }0----1----2----3----| 1516{103: 4 }0----1----2----3----4│{103: 4 }0----1----2----3----| 1517{103: 5 }0----1----2----3----4│{103: 5 }0----1----2----3----| 1518{3:[No Name] [+] }{2:[No Name] [+] }| 1519| 1520{5:-- TERMINAL --} | 1521]] ) 1522-- <ScrollWheelRight> in active window 1523if esc then 1524feed_data ( '\027[<67;8;1M' ) 1525else 1526api . nvim_input_mouse ( 'wheel' , 'right' , '' , 0 , 0 , 7 ) 1527end 1528screen : expect ( [[ 1529{103: 2 }^----1----2----3----4-│{103: 2 }0----1----2----3----| 1530{103: 3 }----1----2----3----4-│{103: 3 }0----1----2----3----| 1531{103: 4 }----1----2----3----4-│{103: 4 }0----1----2----3----| 1532{103: 5 }----1----2----3----4-│{103: 5 }0----1----2----3----| 1533{3:[No Name] [+] }{2:[No Name] [+] }| 1534| 1535{5:-- TERMINAL --} | 1536]] ) 1537-- <ScrollWheelRight> in inactive window 1538if esc then 1539feed_data ( '\027[<67;48;1M' ) 1540else 1541api . nvim_input_mouse ( 'wheel' , 'right' , '' , 0 , 0 , 47 ) 1542end 1543screen : expect ( [[ 1544{103: 2 }^----1----2----3----4-│{103: 2 }----1----2----3----4| 1545{103: 3 }----1----2----3----4-│{103: 3 }----1----2----3----4| 1546{103: 4 }----1----2----3----4-│{103: 4 }----1----2----3----4| 1547{103: 5 }----1----2----3----4-│{103: 5 }----1----2----3----4| 1548{3:[No Name] [+] }{2:[No Name] [+] }| 1549| 1550{5:-- TERMINAL --} | 1551]] ) 1552-- <S-ScrollWheelDown> in active window 1553if esc then 1554feed_data ( '\027[<69;8;1M' ) 1555else 1556api . nvim_input_mouse ( 'wheel' , 'down' , 'S' , 0 , 0 , 7 ) 1557end 1558screen : expect ( [[ 1559{103: 5 }^----1----2----3----4-│{103: 2 }----1----2----3----4| 1560{103: 6 }----1----2----3----4-│{103: 3 }----1----2----3----4| 1561{103: 7 }----1----2----3----4-│{103: 4 }----1----2----3----4| 1562{103: 8 }----1----2----3----4-│{103: 5 }----1----2----3----4| 1563{3:[No Name] [+] }{2:[No Name] [+] }| 1564| 1565{5:-- TERMINAL --} | 1566]] ) 1567-- <S-ScrollWheelDown> in inactive window 1568if esc then 1569feed_data ( '\027[<69;48;1M' ) 1570else 1571api . nvim_input_mouse ( 'wheel' , 'down' , 'S' , 0 , 0 , 47 ) 1572end 1573screen : expect ( [[ 1574{103: 5 }^----1----2----3----4-│{103: 5 }----1----2----3----4| 1575{103: 6 }----1----2----3----4-│{103: 6 }----1----2----3----4| 1576{103: 7 }----1----2----3----4-│{103: 7 }----1----2----3----4| 1577{103: 8 }----1----2----3----4-│{103: 8 }----1----2----3----4| 1578{3:[No Name] [+] }{2:[No Name] [+] }| 1579| 1580{5:-- TERMINAL --} | 1581]] ) 1582-- <S-ScrollWheelRight> in active window 1583if esc then 1584feed_data ( '\027[<71;8;1M' ) 1585else 1586api . nvim_input_mouse ( 'wheel' , 'right' , 'S' , 0 , 0 , 7 ) 1587end 1588screen : expect ( [[ 1589{103: 5 }^----6----7----8----9 │{103: 5 }----1----2----3----4| 1590{103: 6 }----6----7----8----9 │{103: 6 }----1----2----3----4| 1591{103: 7 }----6----7----8----9 │{103: 7 }----1----2----3----4| 1592{103: 8 }----6----7----8----9 │{103: 8 }----1----2----3----4| 1593{3:[No Name] [+] }{2:[No Name] [+] }| 1594| 1595{5:-- TERMINAL --} | 1596]] ) 1597-- <S-ScrollWheelRight> in inactive window 1598if esc then 1599feed_data ( '\027[<71;48;1M' ) 1600else 1601api . nvim_input_mouse ( 'wheel' , 'right' , 'S' , 0 , 0 , 47 ) 1602end 1603screen : expect ( [[ 1604{103: 5 }^----6----7----8----9 │{103: 5 }5----6----7----8----| 1605{103: 6 }----6----7----8----9 │{103: 6 }5----6----7----8----| 1606{103: 7 }----6----7----8----9 │{103: 7 }5----6----7----8----| 1607{103: 8 }----6----7----8----9 │{103: 8 }5----6----7----8----| 1608{3:[No Name] [+] }{2:[No Name] [+] }| 1609| 1610{5:-- TERMINAL --} | 1611]] ) 1612-- <ScrollWheelUp> in active window 1613if esc then 1614feed_data ( '\027[<64;8;1M' ) 1615else 1616api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 7 ) 1617end 1618screen : expect ( [[ 1619{103: 4 }----6----7----8----9 │{103: 5 }5----6----7----8----| 1620{103: 5 }^----6----7----8----9 │{103: 6 }5----6----7----8----| 1621{103: 6 }----6----7----8----9 │{103: 7 }5----6----7----8----| 1622{103: 7 }----6----7----8----9 │{103: 8 }5----6----7----8----| 1623{3:[No Name] [+] }{2:[No Name] [+] }| 1624| 1625{5:-- TERMINAL --} | 1626]] ) 1627-- <ScrollWheelUp> in inactive window 1628if esc then 1629feed_data ( '\027[<64;48;1M' ) 1630else 1631api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 47 ) 1632end 1633screen : expect ( [[ 1634{103: 4 }----6----7----8----9 │{103: 4 }5----6----7----8----| 1635{103: 5 }^----6----7----8----9 │{103: 5 }5----6----7----8----| 1636{103: 6 }----6----7----8----9 │{103: 6 }5----6----7----8----| 1637{103: 7 }----6----7----8----9 │{103: 7 }5----6----7----8----| 1638{3:[No Name] [+] }{2:[No Name] [+] }| 1639| 1640{5:-- TERMINAL --} | 1641]] ) 1642-- <ScrollWheelLeft> in active window 1643if esc then 1644feed_data ( '\027[<66;8;1M' ) 1645else 1646api . nvim_input_mouse ( 'wheel' , 'left' , '' , 0 , 0 , 7 ) 1647end 1648screen : expect ( [[ 1649{103: 4 }5----6----7----8----9│{103: 4 }5----6----7----8----| 1650{103: 5 }5^----6----7----8----9│{103: 5 }5----6----7----8----| 1651{103: 6 }5----6----7----8----9│{103: 6 }5----6----7----8----| 1652{103: 7 }5----6----7----8----9│{103: 7 }5----6----7----8----| 1653{3:[No Name] [+] }{2:[No Name] [+] }| 1654| 1655{5:-- TERMINAL --} | 1656]] ) 1657-- <ScrollWheelLeft> in inactive window 1658if esc then 1659feed_data ( '\027[<66;48;1M' ) 1660else 1661api . nvim_input_mouse ( 'wheel' , 'left' , '' , 0 , 0 , 47 ) 1662end 1663screen : expect ( [[ 1664{103: 4 }5----6----7----8----9│{103: 4 }-5----6----7----8---| 1665{103: 5 }5^----6----7----8----9│{103: 5 }-5----6----7----8---| 1666{103: 6 }5----6----7----8----9│{103: 6 }-5----6----7----8---| 1667{103: 7 }5----6----7----8----9│{103: 7 }-5----6----7----8---| 1668{3:[No Name] [+] }{2:[No Name] [+] }| 1669| 1670{5:-- TERMINAL --} | 1671]] ) 1672-- <S-ScrollWheelUp> in active window 1673if esc then 1674feed_data ( '\027[<68;8;1M' ) 1675else 1676api . nvim_input_mouse ( 'wheel' , 'up' , 'S' , 0 , 0 , 7 ) 1677end 1678screen : expect ( [[ 1679{103: 1 }5----6----7----8----9│{103: 4 }-5----6----7----8---| 1680{103: 2 }5----6----7----8----9│{103: 5 }-5----6----7----8---| 1681{103: 3 }5----6----7----8----9│{103: 6 }-5----6----7----8---| 1682{103: 4 }5^----6----7----8----9│{103: 7 }-5----6----7----8---| 1683{3:[No Name] [+] }{2:[No Name] [+] }| 1684| 1685{5:-- TERMINAL --} | 1686]] ) 1687-- <S-ScrollWheelUp> in inactive window 1688if esc then 1689feed_data ( '\027[<68;48;1M' ) 1690else 1691api . nvim_input_mouse ( 'wheel' , 'up' , 'S' , 0 , 0 , 47 ) 1692end 1693screen : expect ( [[ 1694{103: 1 }5----6----7----8----9│{103: 1 }-5----6----7----8---| 1695{103: 2 }5----6----7----8----9│{103: 2 }-5----6----7----8---| 1696{103: 3 }5----6----7----8----9│{103: 3 }-5----6----7----8---| 1697{103: 4 }5^----6----7----8----9│{103: 4 }-5----6----7----8---| 1698{3:[No Name] [+] }{2:[No Name] [+] }| 1699| 1700{5:-- TERMINAL --} | 1701]] ) 1702-- <S-ScrollWheelLeft> in active window 1703if esc then 1704feed_data ( '\027[<70;8;1M' ) 1705else 1706api . nvim_input_mouse ( 'wheel' , 'left' , 'S' , 0 , 0 , 7 ) 1707end 1708screen : expect ( [[ 1709{103: 1 }0----1----2----3----4│{103: 1 }-5----6----7----8---| 1710{103: 2 }0----1----2----3----4│{103: 2 }-5----6----7----8---| 1711{103: 3 }0----1----2----3----4│{103: 3 }-5----6----7----8---| 1712{103: 4 }0----1----2----3----^4│{103: 4 }-5----6----7----8---| 1713{3:[No Name] [+] }{2:[No Name] [+] }| 1714| 1715{5:-- TERMINAL --} | 1716]] ) 1717-- <S-ScrollWheelLeft> in inactive window 1718if esc then 1719feed_data ( '\027[<70;48;1M' ) 1720else 1721api . nvim_input_mouse ( 'wheel' , 'left' , 'S' , 0 , 0 , 47 ) 1722end 1723screen : expect ( [[ 1724{103: 1 }0----1----2----3----4│{103: 1 }0----1----2----3----| 1725{103: 2 }0----1----2----3----4│{103: 2 }0----1----2----3----| 1726{103: 3 }0----1----2----3----4│{103: 3 }0----1----2----3----| 1727{103: 4 }0----1----2----3----^4│{103: 4 }0----1----2----3----| 1728{3:[No Name] [+] }{2:[No Name] [+] }| 1729| 1730{5:-- TERMINAL --} | 1731]] ) 1732end 1733 1734describe ( 'accepts mouse wheel events' , function () 1735it ( '(mouse events sent to host)' , function () 1736test_mouse_wheel ( false ) 1737end ) 1738 1739it ( '(escape sequences sent to child)' , function () 1740test_mouse_wheel ( true ) 1741end ) 1742end ) 1743 1744local function test_mouse_popup ( esc ) 1745child_session : request ( 1746'nvim_exec2' , 1747[[ 1748call setline(1, 'popup menu test') 1749set mouse=a mousemodel=popup 1750 1751aunmenu PopUp 1752" Delete the default MenuPopup event handler. 1753autocmd! nvim.popupmenu 1754menu PopUp.foo :let g:menustr = 'foo'<CR> 1755menu PopUp.bar :let g:menustr = 'bar'<CR> 1756menu PopUp.baz :let g:menustr = 'baz'<CR> 1757highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse 1758highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold 1759]] , 1760{} 1761) 1762if esc then 1763feed_data ( '\027[<2;5;1M' ) 1764else 1765api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 0 , 4 ) 1766end 1767screen : expect ( [[ 1768^popup menu test | 1769{100:~ }{105: foo }{100: }| 1770{100:~ }{105: bar }{100: }| 1771{100:~ }{105: baz }{100: }| 1772{3:[No Name] [+] }| 1773| 1774{5:-- TERMINAL --} | 1775]] ) 1776if esc then 1777feed_data ( '\027[<2;5;1m' ) 1778else 1779api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 0 , 4 ) 1780end 1781screen : expect_unchanged () 1782if esc then 1783feed_data ( '\027[<64;5;1M' ) 1784else 1785api . nvim_input_mouse ( 'wheel' , 'up' , '' , 0 , 0 , 4 ) 1786end 1787screen : expect ( [[ 1788^popup menu test | 1789{100:~ }{106: foo }{100: }| 1790{100:~ }{105: bar }{100: }| 1791{100:~ }{105: baz }{100: }| 1792{3:[No Name] [+] }| 1793| 1794{5:-- TERMINAL --} | 1795]] ) 1796if esc then 1797feed_data ( '\027[<35;7;4M' ) 1798else 1799api . nvim_input_mouse ( 'move' , '' , '' , 0 , 3 , 6 ) 1800end 1801screen : expect ( [[ 1802^popup menu test | 1803{100:~ }{105: foo }{100: }| 1804{100:~ }{105: bar }{100: }| 1805{100:~ }{106: baz }{100: }| 1806{3:[No Name] [+] }| 1807| 1808{5:-- TERMINAL --} | 1809]] ) 1810if esc then 1811feed_data ( '\027[<65;7;4M' ) 1812else 1813api . nvim_input_mouse ( 'wheel' , 'down' , '' , 0 , 3 , 6 ) 1814end 1815screen : expect ( [[ 1816^popup menu test | 1817{100:~ }{105: foo }{100: }| 1818{100:~ }{106: bar }{100: }| 1819{100:~ }{105: baz }{100: }| 1820{3:[No Name] [+] }| 1821| 1822{5:-- TERMINAL --} | 1823]] ) 1824if esc then 1825feed_data ( '\027[<0;7;3M' ) 1826else 1827api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 2 , 6 ) 1828end 1829screen : expect ( [[ 1830^popup menu test | 1831{100:~ }|*3 1832{3:[No Name] [+] }| 1833:let g:menustr = 'bar' | 1834{5:-- TERMINAL --} | 1835]] ) 1836if esc then 1837feed_data ( '\027[<0;7;3m' ) 1838else 1839api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 2 , 6 ) 1840end 1841screen : expect_unchanged () 1842if esc then 1843feed_data ( '\027[<2;45;3M' ) 1844else 1845api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 2 , 44 ) 1846end 1847screen : expect ( [[ 1848^popup menu test | 1849{100:~ }|*2 1850{100:~ }{105: foo }{100: }| 1851{3:[No Name] [+] }{105: bar }{3: }| 1852:let g:menustr = 'bar' {105: baz } | 1853{5:-- TERMINAL --} | 1854]] ) 1855if esc then 1856feed_data ( '\027[<34;48;6M' ) 1857else 1858api . nvim_input_mouse ( 'right' , 'drag' , '' , 0 , 5 , 47 ) 1859end 1860screen : expect ( [[ 1861^popup menu test | 1862{100:~ }|*2 1863{100:~ }{105: foo }{100: }| 1864{3:[No Name] [+] }{105: bar }{3: }| 1865:let g:menustr = 'bar' {106: baz } | 1866{5:-- TERMINAL --} | 1867]] ) 1868if esc then 1869feed_data ( '\027[<2;48;6m' ) 1870else 1871api . nvim_input_mouse ( 'right' , 'release' , '' , 0 , 5 , 47 ) 1872end 1873screen : expect ( [[ 1874^popup menu test | 1875{100:~ }|*3 1876{3:[No Name] [+] }| 1877:let g:menustr = 'baz' | 1878{5:-- TERMINAL --} | 1879]] ) 1880end 1881 1882describe ( 'mouse events work with right-click menu' , function () 1883it ( '(mouse events sent to host)' , function () 1884test_mouse_popup ( false ) 1885end ) 1886 1887it ( '(escape sequences sent to child)' , function () 1888test_mouse_popup ( true ) 1889end ) 1890end ) 1891 1892it ( 'accepts keypad keys from kitty keyboard protocol #19180' , function () 1893feed_data ( 'i' ) 1894feed_data ( fn . nr2char ( 57399 )) -- KP_0 1895feed_data ( fn . nr2char ( 57400 )) -- KP_1 1896feed_data ( fn . nr2char ( 57401 )) -- KP_2 1897feed_data ( fn . nr2char ( 57402 )) -- KP_3 1898feed_data ( fn . nr2char ( 57403 )) -- KP_4 1899feed_data ( fn . nr2char ( 57404 )) -- KP_5 1900feed_data ( fn . nr2char ( 57405 )) -- KP_6 1901feed_data ( fn . nr2char ( 57406 )) -- KP_7 1902feed_data ( fn . nr2char ( 57407 )) -- KP_8 1903feed_data ( fn . nr2char ( 57408 )) -- KP_9 1904feed_data ( fn . nr2char ( 57409 )) -- KP_DECIMAL 1905feed_data ( fn . nr2char ( 57410 )) -- KP_DIVIDE 1906feed_data ( fn . nr2char ( 57411 )) -- KP_MULTIPLY 1907feed_data ( fn . nr2char ( 57412 )) -- KP_SUBTRACT 1908feed_data ( fn . nr2char ( 57413 )) -- KP_ADD 1909feed_data ( fn . nr2char ( 57414 )) -- KP_ENTER 1910feed_data ( fn . nr2char ( 57415 )) -- KP_EQUAL 1911screen : expect ( [[ 19120123456789./*-+ | 1913=^ | 1914{100:~ }|*2 1915{3:[No Name] [+] }| 1916{5:-- INSERT --} | 1917{5:-- TERMINAL --} | 1918]] ) 1919feed_data ( fn . nr2char ( 57417 )) -- KP_LEFT 1920screen : expect ( [[ 19210123456789./*-+ | 1922^= | 1923{100:~ }|*2 1924{3:[No Name] [+] }| 1925{5:-- INSERT --} | 1926{5:-- TERMINAL --} | 1927]] ) 1928feed_data ( fn . nr2char ( 57418 )) -- KP_RIGHT 1929screen : expect ( [[ 19300123456789./*-+ | 1931=^ | 1932{100:~ }|*2 1933{3:[No Name] [+] }| 1934{5:-- INSERT --} | 1935{5:-- TERMINAL --} | 1936]] ) 1937feed_data ( fn . nr2char ( 57419 )) -- KP_UP 1938screen : expect ( [[ 19390^123456789./*-+ | 1940= | 1941{100:~ }|*2 1942{3:[No Name] [+] }| 1943{5:-- INSERT --} | 1944{5:-- TERMINAL --} | 1945]] ) 1946feed_data ( fn . nr2char ( 57420 )) -- KP_DOWN 1947screen : expect ( [[ 19480123456789./*-+ | 1949=^ | 1950{100:~ }|*2 1951{3:[No Name] [+] }| 1952{5:-- INSERT --} | 1953{5:-- TERMINAL --} | 1954]] ) 1955feed_data ( fn . nr2char ( 57425 )) -- KP_INSERT 1956screen : expect ( [[ 19570123456789./*-+ | 1958=^ | 1959{100:~ }|*2 1960{3:[No Name] [+] }| 1961{5:-- REPLACE --} | 1962{5:-- TERMINAL --} | 1963]] ) 1964feed_data ( '\027[27u' ) -- ESC 1965screen : expect ( [[ 19660123456789./*-+ | 1967^= | 1968{100:~ }|*2 1969{3:[No Name] [+] }| 1970| 1971{5:-- TERMINAL --} | 1972]] ) 1973feed_data ( '\027[57417;5u' ) -- CTRL + KP_LEFT 1974screen : expect ( [[ 1975^0123456789./*-+ | 1976= | 1977{100:~ }|*2 1978{3:[No Name] [+] }| 1979| 1980{5:-- TERMINAL --} | 1981]] ) 1982feed_data ( '\027[57418;2u' ) -- SHIFT + KP_RIGHT 1983screen : expect ( [[ 19840123456789^./*-+ | 1985= | 1986{100:~ }|*2 1987{3:[No Name] [+] }| 1988| 1989{5:-- TERMINAL --} | 1990]] ) 1991feed_data ( fn . nr2char ( 57426 )) -- KP_DELETE 1992screen : expect ( [[ 19930123456789^/*-+ | 1994= | 1995{100:~ }|*2 1996{3:[No Name] [+] }| 1997| 1998{5:-- TERMINAL --} | 1999]] ) 2000feed_data ( fn . nr2char ( 57423 )) -- KP_HOME 2001screen : expect ( [[ 2002^0123456789/*-+ | 2003= | 2004{100:~ }|*2 2005{3:[No Name] [+] }| 2006| 2007{5:-- TERMINAL --} | 2008]] ) 2009feed_data ( fn . nr2char ( 57424 )) -- KP_END 2010screen : expect ( [[ 20110123456789/*-^+ | 2012= | 2013{100:~ }|*2 2014{3:[No Name] [+] }| 2015| 2016{5:-- TERMINAL --} | 2017]] ) 2018child_session : request ( 2019'nvim_exec2' , 2020[[ 2021tab split 2022tabnew 2023highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline 2024]] , 2025{} 2026) 2027screen : expect ( [[ 2028{107: + [No Name] + [No Name] }{5: [No Name] }{2: }{107:X}| 2029^ | 2030{100:~ }|*2 2031{3:[No Name] }| 2032| 2033{5:-- TERMINAL --} | 2034]] ) 2035feed_data ( '\027[57421;5u' ) -- CTRL + KP_PAGE_UP 2036screen : expect ( [[ 2037{107: + [No Name] }{5: + [No Name] }{107: [No Name] }{2: }{107:X}| 20380123456789/*-^+ | 2039= | 2040{100:~ }| 2041{3:[No Name] [+] }| 2042| 2043{5:-- TERMINAL --} | 2044]] ) 2045feed_data ( '\027[57422;5u' ) -- CTRL + KP_PAGE_DOWN 2046screen : expect ( [[ 2047{107: + [No Name] + [No Name] }{5: [No Name] }{2: }{107:X}| 2048^ | 2049{100:~ }|*2 2050{3:[No Name] }| 2051| 2052{5:-- TERMINAL --} | 2053]] ) 2054end ) 2055 2056it ( 'supports Super and Meta modifiers' , function () 2057feed_data ( 'i' ) 2058feed_data ( '\022\027[106;9u' ) -- Super + j 2059feed_data ( '\022\027[107;33u' ) -- Meta + k 2060feed_data ( '\022\027[13;41u' ) -- Super + Meta + Enter 2061feed_data ( '\022\027[127;48u' ) -- Shift + Alt + Ctrl + Super + Meta + Backspace 2062feed_data ( '\n' ) 2063feed_data ( '\022\027[57376;9u' ) -- Super + F13 2064feed_data ( '\022\027[57377;33u' ) -- Meta + F14 2065feed_data ( '\022\027[57378;41u' ) -- Super + Meta + F15 2066feed_data ( '\022\027[57379;48u' ) -- Shift + Alt + Ctrl + Super + Meta + F16 2067screen : expect ( [[ 2068<D-j><T-k><T-D-CR><M-T-C-S-D-BS> | 2069<D-F13><T-F14><T-D-F15><M-T-C-S-D-F16>^ | 2070{100:~ }|*2 2071{3:[No Name] [+] }| 2072{5:-- INSERT --} | 2073{5:-- TERMINAL --} | 2074]] ) 2075end ) 2076 2077it ( 'paste: Insert mode' , function () 2078-- "bracketed paste" 2079feed_data ( 'i""\027i\027[200~' ) 2080screen : expect ( [[ 2081"^" | 2082{100:~ }|*3 2083{3:[No Name] [+] }| 2084{5:-- INSERT --} | 2085{5:-- TERMINAL --} | 2086]] ) 2087feed_data ( 'pasted from terminal' ) 2088expect_child_buf_lines ( { '"pasted from terminal"' } ) 2089screen : expect ( [[ 2090"pasted from terminal^" | 2091{100:~ }|*3 2092{3:[No Name] [+] }| 2093{5:-- INSERT --} | 2094{5:-- TERMINAL --} | 2095]] ) 2096feed_data ( '\027[201~' ) -- End paste. 2097poke_both_eventloop () 2098screen : expect_unchanged () 2099feed_data ( '\027[27u' ) -- ESC: go to Normal mode. 2100wait_for_mode ( 'n' ) 2101screen : expect ( [[ 2102"pasted from termina^l" | 2103{100:~ }|*3 2104{3:[No Name] [+] }| 2105| 2106{5:-- TERMINAL --} | 2107]] ) 2108-- Dot-repeat/redo. 2109feed_data ( '2.' ) 2110expect_child_buf_lines ( { '"pasted from terminapasted from terminalpasted from terminall"' } ) 2111screen : expect ( [[ 2112"pasted from terminapasted from terminalpasted fro| 2113m termina^ll" | 2114{100:~ }|*2 2115{3:[No Name] [+] }| 2116| 2117{5:-- TERMINAL --} | 2118]] ) 2119-- Undo. 2120feed_data ( 'u' ) 2121expect_child_buf_lines ( { '"pasted from terminal"' } ) 2122feed_data ( 'u' ) 2123expect_child_buf_lines ( { '""' } ) 2124feed_data ( 'u' ) 2125expect_child_buf_lines ( { '' } ) 2126end ) 2127 2128it ( 'paste: select-mode' , function () 2129feed_data ( 'ithis is line 1\nthis is line 2\nline 3 is here\n\027' ) 2130wait_for_mode ( 'n' ) 2131screen : expect ( [[ 2132this is line 1 | 2133this is line 2 | 2134line 3 is here | 2135^ | 2136{3:[No Name] [+] }| 2137| 2138{5:-- TERMINAL --} | 2139]] ) 2140-- Select-mode. Use <C-n> to move down. 2141feed_data ( 'gg04lgh\14\14' ) 2142screen : expect ( [[ 2143this{108: is line 1} | 2144{108:this is line 2} | 2145{108:line^ }3 is here | 2146| 2147{3:[No Name] [+] }| 2148{5:-- SELECT --} | 2149{5:-- TERMINAL --} | 2150]] ) 2151feed_data ( '\027[200~' ) 2152feed_data ( 'just paste it™' ) 2153feed_data ( '\027[201~' ) 2154screen : expect ( [[ 2155thisjust paste it^™3 is here | 2156| 2157{100:~ }|*2 2158{3:[No Name] [+] }| 2159| 2160{5:-- TERMINAL --} | 2161]] ) 2162-- Undo. 2163feed_data ( 'u' ) 2164expect_child_buf_lines { 2165'this is line 1' , 2166'this is line 2' , 2167'line 3 is here' , 2168'' , 2169} 2170-- Redo. 2171feed_data ( '\18' ) -- <C-r> 2172expect_child_buf_lines { 2173'thisjust paste it™3 is here' , 2174'' , 2175} 2176end ) 2177 2178it ( 'paste: terminal mode' , function () 2179child_exec_lua ( 'vim.o.statusline="^^^^^^^"' ) 2180child_exec_lua ( 'vim.fn.jobstart({ ... }, { term = true })' , testprg ( 'tty-test' )) 2181feed_data ( 'i' ) 2182screen : expect ( [[ 2183tty ready | 2184^ | 2185|*2 2186{109:^^^^^^^ }| 2187{5:-- TERMINAL --} |*2 2188]] ) 2189feed_data ( '\027[200~' ) 2190feed_data ( 'hallo' ) 2191feed_data ( '\027[201~' ) 2192screen : expect ( [[ 2193tty ready | 2194hallo^ | 2195|*2 2196{109:^^^^^^^ }| 2197{5:-- TERMINAL --} |*2 2198]] ) 2199end ) 2200 2201it ( 'paste: normal-mode (+CRLF #10872)' , function () 2202t . skip ( is_os ( 'win' ), 'FIXME: some spaces have wrong attrs on Windows' ) 2203feed_data ( ':set ruler | echo' ) 2204wait_for_mode ( 'c' ) 2205feed_data ( '\n' ) 2206wait_for_mode ( 'n' ) 2207local expected_lf ={ 'line 1' , 'ESC:\027 / CR: \rx' } 2208local expected_crlf ={ 'line 1' , 'ESC:\027 / CR: ' , 'x' } 2209local expected_grid1 =[[ 2210line 1 | 2211ESC:{104:^[} / CR: | 2212^x | 2213{100:~ }| 2214{3:[No Name] [+] 3,1 All}| 2215| 2216{5:-- TERMINAL --} | 2217]] 2218-- "bracketed paste" 2219feed_data ( '\027[200~' .. table . concat ( expected_lf , '\n' ) .. '\027[201~' ) 2220screen : expect ( expected_grid1 ) 2221-- Dot-repeat/redo. 2222feed_data ( '.' ) 2223local expected_grid2 =[[ 2224ESC:{104:^[} / CR: | 2225xline 1 | 2226ESC:{104:^[} / CR: | 2227^x | 2228{3:[No Name] [+] 5,1 Bot}| 2229| 2230{5:-- TERMINAL --} | 2231]] 2232screen : expect ( expected_grid2 ) 2233-- Undo. 2234feed_data ( 'u' ) 2235expect_child_buf_lines ( expected_crlf ) 2236feed_data ( 'u' ) 2237expect_child_buf_lines ( { '' } ) 2238feed_data ( ':echo' ) 2239wait_for_mode ( 'c' ) 2240feed_data ( '\n' ) 2241wait_for_mode ( 'n' ) 2242-- CRLF input 2243feed_data ( '\027[200~' .. table . concat ( expected_lf , '\r\n' ) .. '\027[201~' ) 2244screen : expect ( expected_grid1 ) 2245expect_child_buf_lines ( expected_crlf ) 2246-- Dot-repeat/redo. 2247feed_data ( '.' ) 2248screen : expect ( expected_grid2 ) 2249-- Undo. 2250feed_data ( 'u' ) 2251expect_child_buf_lines ( expected_crlf ) 2252feed_data ( 'u' ) 2253expect_child_buf_lines ( { '' } ) 2254end ) 2255 2256it ( 'paste: cmdline-mode inserts 1 line' , function () 2257feed_data ( 'ifoo\n' ) -- Insert some text (for dot-repeat later). 2258feed_data ( '\027:""' ) -- Enter Cmdline-mode. 2259feed_data ( '\027[D' ) -- <Left> to place cursor between quotes. 2260wait_for_mode ( 'c' ) 2261screen : expect ( [[ 2262foo | 2263| 2264{100:~ }|*2 2265{3:[No Name] [+] }| 2266:"^" | 2267{5:-- TERMINAL --} | 2268]] ) 2269-- "bracketed paste" 2270feed_data ( '\027[200~line 1\nline 2\n' ) 2271wait_for_mode ( 'c' ) 2272feed_data ( 'line 3\nline 4\n\027[201~' ) 2273poke_both_eventloop () 2274wait_for_mode ( 'c' ) 2275screen : expect ( [[ 2276foo | 2277| 2278{100:~ }|*2 2279{3:[No Name] [+] }| 2280:"line 1^" | 2281{5:-- TERMINAL --} | 2282]] ) 2283-- Dot-repeat/redo. 2284feed_data ( '\027[27u' ) 2285wait_for_mode ( 'n' ) 2286feed_data ( '.' ) 2287screen : expect ( [[ 2288foo |*2 2289^ | 2290{100:~ }| 2291{3:[No Name] [+] }| 2292| 2293{5:-- TERMINAL --} | 2294]] ) 2295end ) 2296 2297it ( 'paste: cmdline-mode collects chunks of unfinished line' , function () 2298local function expect_cmdline ( expected ) 2299retry ( nil , nil , function () 2300local _ , cmdline =child_session : request ( 'nvim_call_function' , 'getcmdline' , {} ) 2301eq ( expected , cmdline ) 2302local _ , pos =child_session : request ( 'nvim_call_function' , 'getcmdpos' , {} ) 2303eq ( # expected , pos ) -- Cursor is just before the last char. 2304end ) 2305end 2306feed_data ( '\027:""' ) -- Enter Cmdline-mode. 2307feed_data ( '\027[D' ) -- <Left> to place cursor between quotes. 2308expect_cmdline ( '""' ) 2309feed_data ( '\027[200~stuff 1 ' ) 2310expect_cmdline ( '"stuff 1 "' ) 2311-- Discards everything after the first line. 2312feed_data ( 'more\nstuff 2\nstuff 3\n' ) 2313expect_cmdline ( '"stuff 1 more"' ) 2314feed_data ( 'stuff 3' ) 2315expect_cmdline ( '"stuff 1 more"' ) 2316-- End the paste sequence. 2317feed_data ( '\027[201~' ) 2318poke_both_eventloop () 2319expect_cmdline ( '"stuff 1 more"' ) 2320feed_data ( ' typed' ) 2321expect_cmdline ( '"stuff 1 more typed"' ) 2322end ) 2323 2324it ( 'paste: recovers from vim.paste() failure' , function () 2325child_exec_lua ( [[ 2326_G.save_paste_fn = vim.paste 2327-- Stack traces for this test are non-deterministic, so disable them 2328_G.debug.traceback = function(msg) return msg end 2329vim.paste = function(lines, phase) error("fake fail") end 2330]] ) 2331-- Prepare something for dot-repeat/redo. 2332feed_data ( 'ifoo\n\027[27u' ) 2333wait_for_mode ( 'n' ) 2334screen : expect ( [[ 2335foo | 2336^ | 2337{100:~ }|*2 2338{3:[No Name] [+] }| 2339| 2340{5:-- TERMINAL --} | 2341]] ) 2342-- Start pasting... 2343feed_data ( '\027[200~line 1\nline 2\n' ) 2344screen : expect ( [[ 2345foo | 2346^ | 2347{100:~ }|*2 2348{3:[No Name] [+] }| 2349{101:paste: Lua: [string "<nvim>"]:4: fake fail} | 2350{5:-- TERMINAL --} | 2351]] ) 2352-- Remaining chunks are discarded after vim.paste() failure. 2353feed_data ( 'line 3\nline 4\n' ) 2354feed_data ( 'line 5\nline 6\n' ) 2355feed_data ( 'line 7\nline 8\n' ) 2356-- Stop paste. 2357feed_data ( '\027[201~' ) 2358screen : expect_unchanged () 2359feed_data ( '\n' ) -- <CR> to dismiss hit-enter prompt 2360expect_child_buf_lines ( { 'foo' , '' } ) 2361-- Dot-repeat/redo is not modified by failed paste. 2362feed_data ( '.' ) 2363screen : expect ( [[ 2364foo |*2 2365^ | 2366{100:~ }| 2367{3:[No Name] [+] }| 2368| 2369{5:-- TERMINAL --} | 2370]] ) 2371-- Editor should still work after failed/drained paste. 2372feed_data ( 'ityped input...\027[27u' ) 2373screen : expect ( [[ 2374foo |*2 2375typed input..^. | 2376{100:~ }| 2377{3:[No Name] [+] }| 2378| 2379{5:-- TERMINAL --} | 2380]] ) 2381-- Paste works if vim.paste() succeeds. 2382child_exec_lua ( [[vim.paste = _G.save_paste_fn]] ) 2383feed_data ( '\027[200~line A\nline B\n\027[201~' ) 2384screen : expect ( [[ 2385foo | 2386typed input...line A | 2387line B | 2388^ | 2389{3:[No Name] [+] }| 2390| 2391{5:-- TERMINAL --} | 2392]] ) 2393end ) 2394 2395it ( 'paste: vim.paste() cancel (retval=false) #10865' , function () 2396-- This test only exercises the "cancel" case. Use-case would be "dangling 2397-- paste", but that is not implemented yet. #10865 2398child_exec_lua ( [[ 2399vim.paste = function(lines, phase) return false end 2400]] ) 2401feed_data ( '\027[200~line A\nline B\n\027[201~' ) 2402expect_child_buf_lines ( { '' } ) 2403feed_data ( 'ifoo\n\027[27u' ) 2404expect_child_buf_lines ( { 'foo' , '' } ) 2405end ) 2406 2407it ( 'paste: vim.paste() cancel (retval=false) with streaming #30462' , function () 2408child_exec_lua ( [[ 2409vim.paste = (function(overridden) 2410return function(lines, phase) 2411for i, line in ipairs(lines) do 2412if line:find('!') then 2413return false 2414end 2415end 2416return overridden(lines, phase) 2417end 2418end)(vim.paste) 2419]] ) 2420feed_data ( 'A' ) 2421wait_for_mode ( 'i' ) 2422feed_data ( '\027[200~aaa' ) 2423expect_child_buf_lines ( { 'aaa' } ) 2424feed_data ( 'bbb' ) 2425expect_child_buf_lines ( { 'aaabbb' } ) 2426feed_data ( 'ccc!' ) -- This chunk is cancelled. 2427expect_child_buf_lines ( { 'aaabbb' } ) 2428feed_data ( 'ddd\027[201~' ) -- This chunk is ignored. 2429poke_both_eventloop () 2430expect_child_buf_lines ( { 'aaabbb' } ) 2431feed_data ( '\027[27u' ) 2432wait_for_mode ( 'n' ) 2433feed_data ( '.' ) -- Dot-repeat only includes chunks actually pasted. 2434expect_child_buf_lines ( { 'aaabbbaaabbb' } ) 2435feed_data ( '$\027[200~eee\027[201~' ) -- A following paste works normally. 2436expect_child_buf_lines ( { 'aaabbbaaabbbeee' } ) 2437end ) 2438 2439it ( "paste: 'nomodifiable' buffer" , function () 2440tt . override_screen_expect_for_conpty ( screen ) 2441child_exec_lua ( [[ 2442vim.bo.modifiable = false 2443-- Truncate the error message to hide the line number 2444_G.debug.traceback = function(msg) return msg:sub(-49) end 2445]] ) 2446feed_data ( '\027[200~fail 1\nfail 2\n\027[201~' ) 2447screen : expect ( [[ 2448| 2449{100:~ }| 2450{3: }| 2451{101:paste: Lua: Vim:E21: Cannot make changes, 'modifia}| 2452{101:ble' is off} | 2453{102:Press ENTER or type command to continue}^ | 2454{5:-- TERMINAL --} | 2455]] ) 2456feed_data ( '\n' ) -- <Enter> to dismiss hit-enter prompt 2457child_exec_lua ( 'vim.bo.modifiable = true' ) 2458feed_data ( '\027[200~success 1\nsuccess 2\n\027[201~' ) 2459screen : expect ( [[ 2460success 1 | 2461success 2 | 2462^ | 2463{100:~ }| 2464{3:[No Name] [+] }| 2465| 2466{5:-- TERMINAL --} | 2467]] ) 2468end ) 2469 2470it ( 'paste: exactly 64 bytes #10311' , function () 2471local expected =string . rep ( 'z' , 64 ) 2472feed_data ( 'i' ) 2473wait_for_mode ( 'i' ) 2474-- "bracketed paste" 2475feed_data ( '\027[200~' .. expected .. '\027[201~' ) 2476expect_child_buf_lines ( { expected } ) 2477feed_data ( ' end' ) 2478expected =expected .. ' end' 2479screen : expect ( [[ 2480zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz| 2481zzzzzzzzzzzzzz end^ | 2482{100:~ }|*2 2483{3:[No Name] [+] }| 2484{5:-- INSERT --} | 2485{5:-- TERMINAL --} | 2486]] ) 2487expect_child_buf_lines ( { expected } ) 2488end ) 2489 2490it ( 'paste: less-than sign in cmdline #11088' , function () 2491local expected ='<' 2492feed_data ( ':' ) 2493wait_for_mode ( 'c' ) 2494-- "bracketed paste" 2495feed_data ( '\027[200~' .. expected .. '\027[201~' ) 2496screen : expect ( [[ 2497| 2498{100:~ }|*3 2499{3:[No Name] }| 2500:<^ | 2501{5:-- TERMINAL --} | 2502]] ) 2503end ) 2504 2505it ( 'paste: big burst of input' , function () 2506feed_data ( ':set ruler\n' ) 2507local q ={} 2508for i =1 , 3000 do 2509q [ i ] ='item ' .. tostring ( i ) 2510end 2511feed_data ( 'i' ) 2512wait_for_mode ( 'i' ) 2513-- "bracketed paste" 2514feed_data ( '\027[200~' .. table . concat ( q , '\n' ) .. '\027[201~' ) 2515expect_child_buf_lines ( q ) 2516feed_data ( ' end' ) 2517screen : expect ( [[ 2518item 2997 | 2519item 2998 | 2520item 2999 | 2521item 3000 end^ | 2522{3:[No Name] [+] 3000,14 Bot}| 2523{5:-- INSERT --} | 2524{5:-- TERMINAL --} | 2525]] ) 2526feed_data ( '\027[27u' ) -- ESC: go to Normal mode. 2527wait_for_mode ( 'n' ) 2528-- Dot-repeat/redo. 2529feed_data ( '.' ) 2530screen : expect ( [[ 2531item 2997 | 2532item 2998 | 2533item 2999 | 2534item 3000 en^dd | 2535{3:[No Name] [+] 5999,13 Bot}| 2536| 2537{5:-- TERMINAL --} | 2538]] ) 2539end ) 2540 2541it ( 'paste: forwards spurious "start paste" code' , function () 2542-- If multiple "start paste" sequences are sent without a corresponding 2543-- "stop paste" sequence, only the first occurrence should be consumed. 2544feed_data ( 'i' ) 2545wait_for_mode ( 'i' ) 2546-- Send the "start paste" sequence. 2547feed_data ( '\027[200~' ) 2548feed_data ( '\npasted from terminal (1)\n' ) 2549-- Send spurious "start paste" sequence. 2550feed_data ( '\027[200~' ) 2551feed_data ( '\n' ) 2552-- Send the "stop paste" sequence. 2553feed_data ( '\027[201~' ) 2554screen : expect ( [[ 2555| 2556pasted from terminal (1) | 2557{104:^[}[200~ | 2558^ | 2559{3:[No Name] [+] }| 2560{5:-- INSERT --} | 2561{5:-- TERMINAL --} | 2562]] ) 2563end ) 2564 2565it ( 'paste: ignores spurious "stop paste" code' , function () 2566-- If "stop paste" sequence is received without a preceding "start paste" 2567-- sequence, it should be ignored. 2568feed_data ( 'i' ) 2569wait_for_mode ( 'i' ) 2570-- Send "stop paste" sequence. 2571feed_data ( '\027[201~' ) 2572screen : expect ( [[ 2573^ | 2574{100:~ }|*3 2575{3:[No Name] }| 2576{5:-- INSERT --} | 2577{5:-- TERMINAL --} | 2578]] ) 2579end ) 2580 2581it ( 'paste: split "start paste" code' , function () 2582t . skip ( is_os ( 'win' ), 'FIXME: wrong behavior on Windows' ) 2583feed_data ( 'i' ) 2584wait_for_mode ( 'i' ) 2585-- Send split "start paste" sequence. 2586feed_data ( '\027[2' ) 2587feed_data ( '00~pasted from terminal\027[201~' ) 2588screen : expect ( [[ 2589pasted from terminal^ | 2590{100:~ }|*3 2591{3:[No Name] [+] }| 2592{5:-- INSERT --} | 2593{5:-- TERMINAL --} | 2594]] ) 2595end ) 2596 2597it ( 'paste: split "stop paste" code' , function () 2598t . skip ( is_os ( 'win' ), 'FIXME: wrong behavior on Windows' ) 2599feed_data ( 'i' ) 2600wait_for_mode ( 'i' ) 2601-- Send split "stop paste" sequence. 2602feed_data ( '\027[200~pasted from terminal\027[20' ) 2603feed_data ( '1~' ) 2604screen : expect ( [[ 2605pasted from terminal^ | 2606{100:~ }|*3 2607{3:[No Name] [+] }| 2608{5:-- INSERT --} | 2609{5:-- TERMINAL --} | 2610]] ) 2611end ) 2612 2613it ( 'paste: streamed paste with isolated "stop paste" code' , function () 2614child_exec_lua ( [[ 2615_G.paste_phases = {} 2616vim.paste = (function(overridden) 2617return function(lines, phase) 2618table.insert(_G.paste_phases, phase) 2619overridden(lines, phase) 2620end 2621end)(vim.paste) 2622]] ) 2623feed_data ( 'i' ) 2624wait_for_mode ( 'i' ) 2625feed_data ( '\027[200~pasted' ) -- phase 1 2626screen : expect ( [[ 2627pasted^ | 2628{100:~ }|*3 2629{3:[No Name] [+] }| 2630{5:-- INSERT --} | 2631{5:-- TERMINAL --} | 2632]] ) 2633feed_data ( ' from terminal' ) -- phase 2 2634screen : expect ( [[ 2635pasted from terminal^ | 2636{100:~ }|*3 2637{3:[No Name] [+] }| 2638{5:-- INSERT --} | 2639{5:-- TERMINAL --} | 2640]] ) 2641-- Send isolated "stop paste" sequence. 2642feed_data ( '\027[201~' ) -- phase 3 2643poke_both_eventloop () 2644screen : expect_unchanged () 2645local rv =child_exec_lua ( 'return _G.paste_phases' ) 2646-- In rare cases there may be multiple chunks of phase 2 because of timing. 2647eq ( { 1 , 2 , 3 } , { rv [ 1 ], rv [ 2 ], rv [ # rv ] } ) 2648end ) 2649 2650it ( 'allows termguicolors to be set at runtime' , function () 2651tt . override_screen_expect_for_conpty ( screen ) 2652screen : set_option ( 'rgb' , true ) 2653feed_data ( ':hi SpecialKey ctermfg=3 guifg=SeaGreen\n' ) 2654feed_data ( 'i' ) 2655feed_data ( '\022\007' ) -- ctrl+g 2656feed_data ( '\028\014' ) -- crtl+\ ctrl+N 2657feed_data ( ':set termguicolors?\n' ) 2658screen : expect ( [[ 2659{110:^^G} | 2660{111:~ }|*3 2661{3:[No Name] [+] }| 2662notermguicolors | 2663{5:-- TERMINAL --} | 2664]] ) 2665 2666feed_data ( ':set termguicolors\n' ) 2667screen : expect ( [[ 2668{113:^^G} | 2669{1:~}{18: }|*3 2670{3:[No Name] [+] }| 2671:set termguicolors | 2672{5:-- TERMINAL --} | 2673]] ) 2674 2675feed_data ( ':set notermguicolors\n' ) 2676screen : expect ( [[ 2677{110:^^G} | 2678{111:~ }|*3 2679{3:[No Name] [+] }| 2680:set notermguicolors | 2681{5:-- TERMINAL --} | 2682]] ) 2683end ) 2684 2685it ( 'forwards :term palette colors with termguicolors' , function () 2686t . skip ( is_os ( 'win' ), 'FIXME: wrong behavior on Windows' ) 2687screen : set_rgb_cterm ( true ) 2688screen : set_default_attr_ids ( { 2689[ 1 ] ={ { reverse =true } , { reverse =true } } , 2690[ 2 ] ={ 2691{ bold =true , background =Screen . colors . LightGreen , foreground =Screen . colors . Black } , 2692{ bold =true } , 2693} , 2694[ 3 ] ={ { bold =true } , { bold =true } } , 2695[ 4 ] ={ { fg_indexed =true , foreground =tonumber ( '0xe0e000' ) } , { foreground =3 } } , 2696[ 5 ] ={ { foreground =tonumber ( '0xff8000' ) } , {} } , 2697[ 6 ] ={ 2698{ 2699fg_indexed =true , 2700bg_indexed =true , 2701bold =true , 2702background =tonumber ( '0x66ff99' ), 2703foreground =Screen . colors . Black , 2704} , 2705{ bold =true , background =121 , foreground =0 } , 2706} , 2707[ 7 ] ={ 2708{ 2709fg_indexed =true , 2710bg_indexed =true , 2711background =tonumber ( '0x66ff99' ), 2712foreground =Screen . colors . Black , 2713} , 2714{ background =121 , foreground =0 } , 2715} , 2716} ) 2717 2718child_exec_lua ( 'vim.o.statusline="^^^^^^^"' ) 2719child_exec_lua ( 'vim.o.termguicolors=true' ) 2720child_exec_lua ( 'vim.fn.jobstart({ ... }, { term = true })' , testprg ( 'tty-test' )) 2721screen : expect ( [[ 2722^tty ready | 2723|*3 2724{2:^^^^^^^ }| 2725| 2726{3:-- TERMINAL --} | 2727]] ) 2728feed_data ( 2729':call chansend(&channel, "\\033[38;5;3mtext\\033[38:2:255:128:0mcolor\\033[0;10mtext")\n' 2730) 2731screen : expect ( [[ 2732^tty ready | 2733{4:text}{5:color}text | 2734|*2 2735{2:^^^^^^^ }| 2736| 2737{3:-- TERMINAL --} | 2738]] ) 2739 2740feed_data ( ':set notermguicolors\n' ) 2741screen : expect ( [[ 2742^tty ready | 2743{4:text}colortext | 2744|*2 2745{6:^^^^^^^}{7: }| 2746:set notermguicolors | 2747{3:-- TERMINAL --} | 2748]] ) 2749end ) 2750 2751-- Note: libvterm doesn't support colored underline or undercurl. 2752it ( 'supports undercurl and underdouble when run in :terminal' , function () 2753child_session : request ( 'nvim_set_hl' , 0 , 'Visual' , { undercurl =true } ) 2754feed_data ( 'ifoobar\027V' ) 2755screen : expect ( [[ 2756{114:fooba^r} | 2757{100:~ }|*3 2758{3:[No Name] [+] }| 2759{5:-- VISUAL LINE --} | 2760{5:-- TERMINAL --} | 2761]] ) 2762child_session : request ( 'nvim_set_hl' , 0 , 'Visual' , { underdouble =true } ) 2763screen : expect ( [[ 2764{115:fooba^r} | 2765{100:~ }|*3 2766{3:[No Name] [+] }| 2767{5:-- VISUAL LINE --} | 2768{5:-- TERMINAL --} | 2769]] ) 2770end ) 2771 2772it ( 'in nvim_list_uis(), sets nvim_set_client_info()' , function () 2773-- $TERM in :terminal. 2774local exp_term =( is_os ( 'bsd' ) or is_os ( 'win' ) or fn . has ( 'terminfo' ) == 0 ) and 'xterm' 2775or 'xterm-256color' 2776local ui_chan =1 2777local expected ={ 2778{ 2779chan =ui_chan , 2780ext_cmdline =false , 2781ext_hlstate =false , 2782ext_linegrid =true , 2783ext_messages =false , 2784ext_multigrid =false , 2785ext_popupmenu =false , 2786ext_tabline =false , 2787ext_termcolors =true , 2788ext_wildmenu =false , 2789height =6 , 2790override =false , 2791rgb =false , 2792stdin_tty =true , 2793stdout_tty =true , 2794term_background ='' , 2795term_colors =256 , 2796term_name =exp_term , 2797width =50 , 2798} , 2799} 2800local _ , rv =child_session : request ( 'nvim_list_uis' ) 2801eq ( expected , rv ) 2802 2803---@type table 2804local expected_version =child_exec_lua ( 'return vim.version()' ) 2805-- vim.version() returns `prerelease` string. Coerce it to boolean. 2806expected_version . prerelease =not not expected_version . prerelease 2807 2808local expected_chan_info ={ 2809client ={ 2810attributes ={ 2811license ='Apache 2' , 2812-- pid = 5371, 2813website ='https://neovim.io' , 2814} , 2815methods ={} , 2816name ='nvim-tui' , 2817type ='ui' , 2818version =expected_version , 2819} , 2820id =ui_chan , 2821mode ='rpc' , 2822stream ='stdio' , 2823} 2824 2825local status , chan_info =child_session : request ( 'nvim_get_chan_info' , ui_chan ) 2826ok ( status ) 2827local info =chan_info . client 2828ok ( info . attributes . pid and info . attributes . pid > 0 , 'PID' , info . attributes . pid or 'nil' ) 2829ok ( info . version . major >= 0 ) 2830ok ( info . version . minor >= 0 ) 2831ok ( info . version . patch >= 0 ) 2832 2833-- Delete variable fields so we can deep-compare. 2834info . attributes . pid =nil 2835 2836eq ( expected_chan_info , chan_info ) 2837end ) 2838 2839it ( 'allows grid to assume wider ambiwidth chars than host terminal' , function () 2840tt . override_screen_expect_for_conpty ( screen ) 2841child_session : request ( 2842'nvim_buf_set_lines' , 28430 , 28440 , 2845- 1 , 2846true , 2847{ ( '℃' ): rep ( 60 ), ( '℃' ): rep ( 60 ) } 2848) 2849child_session : request ( 'nvim_set_option_value' , 'cursorline' , true , {} ) 2850child_session : request ( 'nvim_set_option_value' , 'list' , true , {} ) 2851child_session : request ( 'nvim_set_option_value' , 'listchars' , 'eol:$' , { win =0 } ) 2852feed_data ( 'gg' ) 2853local singlewidth_screen =[[ 2854{107:^℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}| 2855{107:℃℃℃℃℃℃℃℃℃℃}{116:$}{107: }| 2856℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃| 2857℃℃℃℃℃℃℃℃℃℃{100:$} | 2858{3:[No Name] [+] }| 2859| 2860{5:-- TERMINAL --} | 2861]] 2862-- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width, 2863-- the second cell of "℃" is a space and the attributes of the "℃" are applied to it. 2864local doublewidth_screen =[[ 2865{107:^℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| 2866{107:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| 2867{107:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{116:$}{107: }| 2868℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ {100:@@@@}| 2869{3:[No Name] [+] }| 2870| 2871{5:-- TERMINAL --} | 2872]] 2873screen : expect ( singlewidth_screen ) 2874child_session : request ( 'nvim_set_option_value' , 'ambiwidth' , 'double' , {} ) 2875screen : expect ( doublewidth_screen ) 2876child_session : request ( 'nvim_set_option_value' , 'ambiwidth' , 'single' , {} ) 2877screen : expect ( singlewidth_screen ) 2878child_session : request ( 'nvim_call_function' , 'setcellwidths' , { { { 0x2103 , 0x2103 , 2 } } } ) 2879screen : expect ( doublewidth_screen ) 2880child_session : request ( 'nvim_call_function' , 'setcellwidths' , { { { 0x2103 , 0x2103 , 1 } } } ) 2881screen : expect ( singlewidth_screen ) 2882end ) 2883 2884it ( 'allows grid to assume wider non-ambiwidth chars than host terminal' , function () 2885tt . override_screen_expect_for_conpty ( screen ) 2886child_session : request ( 2887'nvim_buf_set_lines' , 28880 , 28890 , 2890- 1 , 2891true , 2892{ ( '✓' ): rep ( 60 ), ( '✓' ): rep ( 60 ) } 2893) 2894child_session : request ( 'nvim_set_option_value' , 'cursorline' , true , {} ) 2895child_session : request ( 'nvim_set_option_value' , 'list' , true , {} ) 2896child_session : request ( 'nvim_set_option_value' , 'listchars' , 'eol:$' , { win =0 } ) 2897feed_data ( 'gg' ) 2898local singlewidth_screen =[[ 2899{107:^✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓}| 2900{107:✓✓✓✓✓✓✓✓✓✓}{116:$}{107: }| 2901✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓| 2902✓✓✓✓✓✓✓✓✓✓{100:$} | 2903{3:[No Name] [+] }| 2904| 2905{5:-- TERMINAL --} | 2906]] 2907-- When grid assumes "✓" to be double-width but host terminal assumes it to be single-width, 2908-- the second cell of "✓" is a space and the attributes of the "✓" are applied to it. 2909local doublewidth_screen =[[ 2910{107:^✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }| 2911{107:✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }| 2912{107:✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }{116:$}{107: }| 2913✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ {100:@@@@}| 2914{3:[No Name] [+] }| 2915| 2916{5:-- TERMINAL --} | 2917]] 2918screen : expect ( singlewidth_screen ) 2919child_session : request ( 'nvim_set_option_value' , 'ambiwidth' , 'double' , {} ) 2920screen : expect_unchanged () 2921child_session : request ( 'nvim_call_function' , 'setcellwidths' , { { { 0x2713 , 0x2713 , 2 } } } ) 2922screen : expect ( doublewidth_screen ) 2923child_session : request ( 'nvim_set_option_value' , 'ambiwidth' , 'single' , {} ) 2924screen : expect_unchanged () 2925child_session : request ( 'nvim_call_function' , 'setcellwidths' , { { { 0x2713 , 0x2713 , 1 } } } ) 2926screen : expect ( singlewidth_screen ) 2927end ) 2928 2929it ( 'draws correctly when cursor_address overflows #21643' , function () 2930screen : try_resize ( 70 , 333 ) 2931retry ( nil , nil , function () 2932eq ( { true , 330 } , { child_session : request ( 'nvim_win_get_height' , 0 ) } ) 2933end ) 2934child_session : request ( 'nvim_set_option_value' , 'cursorline' , true , {} ) 2935-- Use full screen message so that redrawing afterwards is more deterministic. 2936child_session : notify ( 'nvim_command' , 'intro' ) 2937screen : expect ( { any ='Nvim is open source and freely distributable' } ) 2938-- Going to top-left corner needs 3 bytes. 2939-- Setting underline attribute needs 9 bytes. 2940-- A Ꝩ character takes 3 bytes. 2941-- The whole line needs 3 + 9 + 3 * 21838 + 3 = 65529 bytes. 2942-- The cursor_address that comes after will overflow the 65535-byte buffer. 2943local line =( 'Ꝩ' ): rep ( 21838 ) .. '℃' 2944child_session : notify ( 'nvim_buf_set_lines' , 0 , 0 , - 1 , true , { line , 'b' } ) 2945-- Close the :intro message and redraw the lines. 2946feed_data ( '\n' ) 2947screen : expect ( [[ 2948{107:^ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ}| 2949{107:ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ}|*310 2950{107:ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ℃ }| 2951b | 2952{100:~ }|*17 2953{3:[No Name] [+] }| 2954| 2955{5:-- TERMINAL --} | 2956]] ) 2957end ) 2958 2959it ( 'does not split large synchronized TUI output' , function () 2960screen : try_resize ( 70 , 333 ) 2961retry ( nil , 1000 , function () 2962eq ( { true , 330 } , { child_session : request ( 'nvim_win_get_height' , 0 ) } ) 2963end ) 2964 2965local dump =t . tmpname () 2966finally ( function () 2967os . remove ( dump ) 2968end ) 2969 2970-- Inform the TUI that synchronized output is supported. 2971feed_data ( '\027[?2026;2$y' ) 2972poke_both_eventloop () 2973child_session : request ( 'nvim_set_option_value' , 'termsync' , true , {} ) 2974child_session : request ( 'nvim_buf_set_lines' , 0 , 0 , - 1 , true , { ( 'Ꝩ' ): rep ( 21844 ), 'b' } ) 2975 2976child_session : request ( 'nvim__screenshot' , dump ) 2977poke_both_eventloop () 2978local raw =assert ( read_file ( dump )) 2979 2980local _ , starts =raw : gsub ( '\027%[%?2026h' , '' ) 2981local _ , ends =raw : gsub ( '\027%[%?2026l' , '' ) 2982eq ( { 1 , 1 } , { starts , ends } ) 2983end ) 2984 2985it ( 'draws correctly when setting title overflows #30793' , function () 2986screen : try_resize ( 67 , 327 ) 2987retry ( nil , nil , function () 2988eq ( { true , 324 } , { child_session : request ( 'nvim_win_get_height' , 0 ) } ) 2989end ) 2990child_exec_lua ( [[ 2991vim.o.cmdheight = 0 2992vim.o.laststatus = 0 2993vim.o.ruler = false 2994vim.o.showcmd = false 2995vim.o.termsync = false 2996vim.o.titlestring = '%t%( %M%) - Nvim' 2997vim.o.title = true 2998]] ) 2999retry ( nil , nil , function () 3000eq ( '[No Name] - Nvim' , api . nvim_buf_get_var ( 0 , 'term_title' )) 3001eq ( { true , 326 } , { child_session : request ( 'nvim_win_get_height' , 0 ) } ) 3002end ) 3003-- Use full screen message so that redrawing afterwards is more deterministic. 3004child_session : notify ( 'nvim_command' , 'intro' ) 3005screen : expect ( { any ='Nvim is open source and freely distributable' } ) 3006-- Going to top-left corner needs 3 bytes. 3007-- A Ꝩ character takes 3 bytes. 3008-- The whole line needs 3 + 3 * 21842 = 65529 bytes. 3009-- The title will be updated because the buffer is now modified. 3010-- The start of the OSC 0 sequence to set title can fit in the 65535-byte buffer, 3011-- but the title string cannot. 3012local line =( 'Ꝩ' ): rep ( 21842 ) 3013child_session : notify ( 'nvim_buf_set_lines' , 0 , 0 , - 1 , true , { line } ) 3014-- Close the :intro message and redraw the lines. 3015feed_data ( '\n' ) 3016screen : expect ( [[ 3017^ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ| 3018ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ|*325 3019{5:-- TERMINAL --} | 3020]] ) 3021retry ( nil , nil , function () 3022eq ( '[No Name] + - Nvim' , api . nvim_buf_get_var ( 0 , 'term_title' )) 3023end ) 3024end ) 3025 3026it ( 'visual bell (padding) does not crash #21610' , function () 3027feed_data ':set visualbell\n' 3028screen : expect ( [[ 3029^ | 3030{100:~ }|*3 3031{3:[No Name] }| 3032:set visualbell | 3033{5:-- TERMINAL --} | 3034]] ) 3035 3036-- move left is enough to invoke the bell 3037feed_data 'h' 3038-- visual change to show we process events after this 3039feed_data 'i' 3040screen : expect ( [[ 3041^ | 3042{100:~ }|*3 3043{3:[No Name] }| 3044{5:-- INSERT --} | 3045{5:-- TERMINAL --} | 3046]] ) 3047end ) 3048 3049it ( 'no assert failure on deadly signal #21896' , function () 3050exec_lua ( [[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]] ) 3051screen : expect ( is_os ( 'win' ) and { any ='%[Process exited 1%]' } or [[ 3052Nvim: Caught deadly signal 'SIGTERM' | 3053^ | 3054[Process exited 1] | 3055|*3 3056{5:-- TERMINAL --} | 3057]] ) 3058end ) 3059 3060it ( 'exit status 1 and error message with deadly signal sent to server' , function () 3061local _ , server_pid =child_session : request ( 'nvim_call_function' , 'getpid' , {} ) 3062exec_lua ( [[vim.uv.kill(..., 'sigterm')]] , server_pid ) 3063if not is_os ( 'win' ) then 3064screen : expect ( { any =vim . pesc ( [[Nvim: Caught deadly signal 'SIGTERM']] ) } ) 3065end 3066screen : expect ( { any =vim . pesc ( '[Process exited 1]' ) } ) 3067end ) 3068 3069it ( 'exits properly when :quit non-last window in event handler #14379' , function () 3070local code =[[ 3071vim.defer_fn(function() 3072vim.cmd('vsplit | quit') 3073end, 0) 3074vim.cmd('quit') 3075]] 3076child_session : notify ( 'nvim_exec_lua' , code , {} ) 3077screen : expect ( [[ 3078^ | 3079[Process exited 0] | 3080|*4 3081{5:-- TERMINAL --} | 3082]] ) 3083end ) 3084 3085it ( 'no stack-use-after-scope with cursor color #22432' , function () 3086screen : set_option ( 'rgb' , true ) 3087command ( 'set termguicolors' ) 3088child_session : request ( 3089'nvim_exec2' , 3090[[ 3091set tgc 3092hi Cursor guifg=Red guibg=Green 3093set guicursor=n:block-Cursor/lCursor 3094]] , 3095{} 3096) 3097screen : expect ( [[ 3098^ | 3099{1:~}{18: }|*3 3100{3:[No Name] }| 3101| 3102{5:-- TERMINAL --} | 3103]] ) 3104feed_data ( 'i' ) 3105screen : expect ( [[ 3106^ | 3107{1:~}{18: }|*3 3108{3:[No Name] }| 3109{5:-- INSERT --} | 3110{5:-- TERMINAL --} | 3111]] ) 3112end ) 3113 3114it ( 'redraws on SIGWINCH even if terminal size is unchanged #23411' , function () 3115-- On Windows, SIGWINCH cannot be sent as a signal with uv_kill(), while 3116-- SIGWINCH handlers are only called on terminal resize. 3117t . skip ( is_os ( 'win' ), 'N/A for Windows' ) 3118child_session : request ( 'nvim_echo' , { { 'foo' } } , false , {} ) 3119screen : expect ( [[ 3120^ | 3121{100:~ }|*3 3122{3:[No Name] }| 3123foo | 3124{5:-- TERMINAL --} | 3125]] ) 3126exec_lua ( [[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]] ) 3127screen : expect ( [[ 3128^ | 3129{100:~ }|*3 3130{3:[No Name] }| 3131| 3132{5:-- TERMINAL --} | 3133]] ) 3134end ) 3135 3136it ( 'supports hiding cursor' , function () 3137child_session : request ( 3138'nvim_command' , 3139"let g:id = jobstart([v:progpath, '--clean', '--headless'])" 3140) 3141feed_data ( ':call jobwait([g:id])\n' ) 3142screen : expect ( [[ 3143| 3144{100:~ }|*3 3145{3:[No Name] }| 3146:call jobwait([g:id]) | 3147{5:-- TERMINAL --} | 3148]] ) 3149feed_data ( '\003' ) 3150screen : expect ( [[ 3151^ | 3152{100:~ }|*3 3153{3:[No Name] }| 3154Type :qa and press <Enter> to exit Nvim | 3155{5:-- TERMINAL --} | 3156]] ) 3157end ) 3158 3159it ( 'cursor is not hidden on incsearch with no match' , function () 3160feed_data ( 'ifoo\027' ) 3161feed_data ( '/foo' ) 3162screen : expect ( [[ 3163{2:foo} | 3164{100:~ }|*3 3165{3:[No Name] [+] }| 3166/foo^ | 3167{5:-- TERMINAL --} | 3168]] ) 3169screen : sleep ( 10 ) 3170feed_data ( 'b' ) 3171screen : expect ( [[ 3172foo | 3173{100:~ }|*3 3174{3:[No Name] [+] }| 3175/foob^ | 3176{5:-- TERMINAL --} | 3177]] ) 3178screen : sleep ( 10 ) 3179feed_data ( 'a' ) 3180screen : expect ( [[ 3181foo | 3182{100:~ }|*3 3183{3:[No Name] [+] }| 3184/fooba^ | 3185{5:-- TERMINAL --} | 3186]] ) 3187end ) 3188 3189it ( 'emits hyperlinks with OSC 8' , function () 3190t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 3191exec_lua ( [[ 3192local buf = vim.api.nvim_get_current_buf() 3193_G.urls = {} 3194vim.api.nvim_create_autocmd('TermRequest', { 3195buf = buf, 3196callback = function(ev) 3197local req = ev.data.sequence 3198if not req then 3199return 3200end 3201local id, url = req:match('\027]8;id=(%d+);(.*)$') 3202if id ~= nil and url ~= nil then 3203table.insert(_G.urls, { id = tonumber(id), url = url }) 3204end 3205end, 3206}) 3207]] ) 3208child_exec_lua ( [[ 3209vim.api.nvim_buf_set_lines(0, 0, 0, true, {'Hello'}) 3210_G.NS = vim.api.nvim_create_namespace('test') 3211vim.api.nvim_buf_set_extmark(0, _G.NS, 0, 1, { 3212end_col = 3, 3213url = 'https://example.com', 3214}) 3215]] ) 3216retry ( nil , 1000 , function () 3217eq ( { { id =0xE1EA0000 , url ='https://example.com' } } , exec_lua ( [[return _G.urls]] )) 3218end ) 3219-- No crash with very long URL #30794 3220child_exec_lua ( [[ 3221vim.api.nvim_buf_set_extmark(0, _G.NS, 0, 3, { 3222end_col = 5, 3223url = 'https://example.com/' .. ('a'):rep(65536), 3224}) 3225]] ) 3226retry ( nil , nil , function () 3227eq ( { 3228{ id =0xE1EA0000 , url ='https://example.com' } , 3229{ id =0xE1EA0001 , url ='https://example.com/' .. ( 'a' ): rep ( 65536 ) } , 3230} , exec_lua ( [[return _G.urls]] )) 3231end ) 3232end ) 3233 3234it ( 'TermResponse on kitty-multiple-cursors protocol query' , function () 3235child_exec_lua ( [[ 3236_G.termresponse = nil 3237vim.api.nvim_create_autocmd('TermResponse', { 3238once = true, 3239callback = function(ev) 3240_G.termresponse = ev.data.sequence 3241end, 3242}) 3243]] ) 3244feed_data ( '\027[>1;2;3;29;30;40;100;101 q' ) 3245retry ( nil , nil , function () 3246eq ( '\027[>1;2;3;29;30;40;100;101 q' , child_exec_lua ( 'return _G.termresponse' )) 3247end ) 3248end ) 3249 3250it ( 'TermResponse works with vim.wait() from another autocommand #32706' , function () 3251child_exec_lua ( [[ 3252_G.termresponse = nil 3253vim.api.nvim_create_autocmd('TermResponse', { 3254callback = function(ev) 3255_G.sequence = ev.data.sequence 3256_G.v_termresponse = vim.v.termresponse 3257end, 3258}) 3259vim.api.nvim_create_autocmd('InsertEnter', { 3260buf = 0, 3261callback = function() 3262_G.result = vim.wait(3000, function() 3263local expected = '\027P1+r5463' 3264return _G.sequence == expected and _G.v_termresponse == expected 3265end) 3266end, 3267}) 3268]] ) 3269feed_data ( 'i' ) 3270feed_data ( '\027P1+r5463\027\\' ) 3271retry ( nil , 4000 , function () 3272eq ( true , child_exec_lua ( 'return _G.result' )) 3273end ) 3274end ) 3275 3276it ( 'TermResponse from unblock_autocmds() sets "data"' , function () 3277if not child_exec_lua ( 'return pcall(require, "ffi")' ) then 3278pending ( 'N/A: missing LuaJIT FFI' ) 3279end 3280child_exec_lua ( [[ 3281local ffi = require('ffi') 3282ffi.cdef[=[ 3283void block_autocmds(void); 3284void unblock_autocmds(void); 3285]=] 3286ffi.C.block_autocmds() 3287vim.api.nvim_create_autocmd('TermResponse', { 3288once = true, 3289callback = function(ev) 3290_G.data = ev.data 3291end, 3292}) 3293]] ) 3294local chan =child_exec_lua ( 'return vim.api.nvim_list_uis()[1].chan' ) 3295feed_data ( '\027P0$r\027\\' ) 3296retry ( nil , 4000 , function () 3297eq ( '\027P0$r' , child_exec_lua ( 'return vim.v.termresponse' )) 3298end ) 3299eq ( vim . NIL , child_exec_lua ( 'return _G.data' )) 3300child_exec_lua ( 'require("ffi").C.unblock_autocmds()' ) 3301eq ( { sequence ='\027P0$r' , chan =chan } , child_exec_lua ( 'return _G.data' )) 3302 3303-- If TermResponse during TermResponse changes v:termresponse, data.sequence contains the actual 3304-- response that triggered the autocommand. 3305-- The second autocommand below forces a use-after-free when v:termresponse's value changes 3306-- during TermResponse if data.sequence didn't allocate its own copy. 3307child_exec_lua ( [[ 3308require('ffi').C.block_autocmds() 3309vim.api.nvim_create_autocmd('TermResponse', { 3310once = true, 3311callback = function(ev) 3312_G.au1_termresponse1 = vim.v.termresponse 3313_G.au1_sequence1 = ev.data.sequence 3314local chan = vim.fn.sockconnect('pipe', vim.v.servername, { rpc = true }) 3315vim.rpcrequest(chan, 'nvim_ui_term_event', 'termresponse', 'baz') 3316_G.au1_termresponse2 = vim.v.termresponse 3317_G.au1_sequence2 = ev.data.sequence 3318end, 3319}) 3320_G.au2_sequences = {} 3321vim.api.nvim_create_autocmd('TermResponse', { 3322callback = function(ev) 3323table.insert(_G.au2_sequences, ev.data.sequence) 3324end, 3325}) 3326]] ) 3327child_session : request ( 'nvim_ui_term_event' , 'termresponse' , 'foobar' ) 3328eq ( 'foobar' , child_exec_lua ( 'return vim.v.termresponse' )) 3329-- For good measure, check deferred TermResponse doesn't try to fire if autocmds are still 3330-- blocked after unblock_autocmds. 3331child_exec_lua ( 'require("ffi").C.block_autocmds() require("ffi").C.unblock_autocmds()' ) 3332eq ( vim . NIL , child_exec_lua ( 'return _G.au1_termresponse1' )) 3333child_exec_lua ( 'require("ffi").C.unblock_autocmds()' ) 3334eq ( 'foobar' , child_exec_lua ( 'return _G.au1_termresponse1' )) 3335eq ( 'foobar' , child_exec_lua ( 'return _G.au1_sequence1' )) 3336eq ( 'baz' , child_exec_lua ( 'return _G.au1_termresponse2' )) 3337eq ( 'foobar' , child_exec_lua ( 'return _G.au1_sequence2' )) -- unchanged 3338-- Second autocmd triggers due to "baz" (via the nested TermResponse), then from "foobar". 3339eq ( { 'baz' , 'foobar' } , child_exec_lua ( 'return _G.au2_sequences' )) 3340end ) 3341 3342it ( 'nvim_ui_send works' , function () 3343child_session : request ( 'nvim_ui_send' , '\027]2;TEST_TITLE\027\\' ) 3344retry ( nil , nil , function () 3345eq ( 'TEST_TITLE' , api . nvim_buf_get_var ( 0 , 'term_title' )) 3346end ) 3347end ) 3348 3349it ( 'stdin and stdout are tty fds in embedded server #38172' , function () 3350eq ( 3351{ 'tty' , 'tty' } , 3352child_exec_lua ( 'return { vim.uv.guess_handle(0), vim.uv.guess_handle(1) }' ) 3353) 3354-- Also works after :restart! #38745 3355feed_data ( ':restart! lua ={ vim.uv.guess_handle(0), vim.uv.guess_handle(1) }\r' ) 3356screen : expect ( [[ 3357^ | 3358{100:~ }|*3 3359{3:[No Name] }| 3360{ "tty", "tty" } | 3361{5:-- TERMINAL --} | 3362]] ) 3363-- The server is now detached and needs to be quit explicitly. 3364feed_data ( ':qall!\r' ) 3365screen : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 3366end ) 3367end ) 3368 3369describe ( 'TUI' , function () 3370before_each ( clear ) 3371 3372it ( 'resize at startup #17285 #15044 #11330' , function () 3373local screen =Screen . new ( 50 , 10 ) 3374screen : add_extra_attr_ids ( { 3375[ 100 ] ={ foreground =tonumber ( '0x4040ff' ), fg_indexed =true } , 3376[ 101 ] ={ foreground =Screen . colors . Gray100 , background =Screen . colors . DarkGreen } , 3377} ) 3378fn . jobstart ( { 3379nvim_prog , 3380'--clean' , 3381'--cmd' , 3382'colorscheme vim' , 3383'--cmd' , 3384'set notermguicolors' , 3385'--cmd' , 3386nvim_set , 3387'--cmd' , 3388'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile' , 3389} , { 3390term =true , 3391env ={ 3392VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 3393} , 3394} ) 3395exec ( [[ 3396sleep 500m 3397vs new 3398]] ) 3399screen : expect (( [[ 3400^ │ | 3401{1:~ }│{100:~ }|*6 3402{1:~ }│ | 3403{3:new }{101:{MATCH:<.*%s} [-] }| 3404| 3405]] ): format ( is_os ( 'win' ) and '[/\\]nvim%.exe' or '/nvim' )) 3406end ) 3407 3408-- #28667, #28668 3409for _ , guicolors in ipairs ( { 'notermguicolors' , 'termguicolors' } ) do 3410it ( 'has no black flicker when clearing regions during startup with ' .. guicolors , function () 3411local screen =Screen . new ( 50 , 10 ) 3412-- Colorscheme is automatically detected as light in _core/defaults.lua, so fg 3413-- should be dark except on Windows, where it doesn't respond to the OSC11 query, 3414-- so bg is dark. 3415local fg =is_os ( 'win' ) and Screen . colors . NvimLightGrey2 or Screen . colors . NvimDarkGrey2 3416local bg =is_os ( 'win' ) and Screen . colors . NvimDarkGrey2 or Screen . colors . NvimLightGrey2 3417screen : add_extra_attr_ids ( { 3418[ 100 ] ={ 3419foreground =fg , 3420background =bg , 3421} , 3422} ) 3423fn . jobstart ( { 3424nvim_prog , 3425'--clean' , 3426'--cmd' , 3427'set ' .. guicolors , 3428'--cmd' , 3429'echo "foo"' , 3430'--cmd' , 3431'sleep 10' , 3432} , { 3433term =true , 3434env ={ VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ) } , 3435} ) 3436if guicolors == 'termguicolors' then 3437screen : expect ( [[ 3438{100:^ }| 3439{100: }|*7 3440{100:foo }| 3441| 3442]] ) 3443else 3444screen : expect ( [[ 3445^ | 3446|*7 3447foo | 3448| 3449]] ) 3450end 3451end ) 3452end 3453 3454it ( 'argv[0] can be overridden #23953' , function () 3455t . skip ( is_os ( 'win' ), 'N/A for Windows' ) 3456t . skip ( t . is_arch ( 's390x' ), 'FIXME s390x' ) 3457local screen =Screen . new ( 50 , 7 , { rgb =false } ) 3458fn . jobstart ( 3459{ testprg ( 'shell-test' ), 'EXECVP' , nvim_prog , 'Xargv0nvim' , '--clean' } , 3460{ term =true , env ={ VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ) } } 3461) 3462command ( 'startinsert' ) 3463screen : expect ( [[ 3464^ | 3465~ |*3 3466[No Name] 0,0-1 All| 3467| 3468{5:-- TERMINAL --} | 3469]] ) 3470feed_data ( ':put =v:argv + [v:progname]\n' ) 3471screen : expect ( [[ 3472Xargv0nvim | 3473--embed | 3474--clean | 3475^Xargv0nvim | 3476[No Name] [+] 5,1 Bot| 34774 more lines | 3478{5:-- TERMINAL --} | 3479]] ) 3480end ) 3481 3482it ( "float is still highlighted with 'winblend' over uninitialized cells #34360" , function () 3483write_file ( 3484'Xblend.lua' , 3485[[ 3486local win = vim.api.nvim_open_win(0, false, { relative = 'editor', width = 3, height = 1, row = 1000, col = 0, zindex = 400 }) 3487vim.api.nvim_set_option_value('winblend', 30, { win = win }) 3488vim.fn.setline(1, "foo") 3489vim.api.nvim_buf_set_extmark(0, vim.api.nvim_create_namespace(''), 0, 0, { end_col = 3, hl_group = 'Title' }) 3490]] 3491) 3492finally ( function () 3493os . remove ( 'Xblend.lua' ) 3494end ) 3495local screen =tt . setup_child_nvim ( { '--clean' , '-u' , 'Xblend.lua' } ) 3496screen : expect ( [[ 3497{5:^foo} | 3498~ |*3 3499[No Name] [+] 1,1 All| 3500{5:foo} | 3501{5:-- TERMINAL --} | 3502]] ) 3503end ) 3504 3505it ( 'with non-tty (pipe) stdout/stderr' , function () 3506t . skip ( is_os ( 'win' ), 'N/A for Windows' ) 3507finally ( function () 3508os . remove ( 'testF' ) 3509os . remove ( testlog ) 3510end ) 3511local screen =tt . setup_screen ( 35120 , 3513( '"%s" --clean --cmd "set noswapfile noshowcmd noruler" --cmd "normal iabc" > /dev/null 2>&1 && cat testF && rm testF' ): format ( 3514nvim_prog 3515), 3516nil , 3517{ VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), NVIM_LOG_FILE =testlog } 3518) 3519feed_data ( ':w testF\n:q\n' ) 3520screen : expect ( [[ 3521:w testF | 3522:q | 3523abc | 3524^ | 3525[Process exited 0] | 3526| 3527{5:-- TERMINAL --} | 3528]] ) 3529assert_log ( 'TUI: timed out waiting for DA1 response' , testlog ) 3530end ) 3531 3532it ( '<C-h> #10134' , function () 3533local screen =tt . setup_child_nvim ( { 3534'--clean' , 3535'--cmd' , 3536'colorscheme vim' , 3537'--cmd' , 3538'set noruler' , 3539'--cmd' , 3540':nnoremap <C-h> :echomsg "\\<C-h\\>"<CR>' , 3541} , { env =env_notermguicolors } ) 3542screen : expect ( [[ 3543^ | 3544{100:~ }|*3 3545{3:[No Name] }| 3546| 3547{5:-- TERMINAL --} | 3548]] ) 3549 3550command ( [[call chansend(b:terminal_job_id, "\<C-h>")]] ) 3551screen : expect ( [[ 3552^ | 3553{100:~ }|*3 3554{3:[No Name] }| 3555<C-h> | 3556{5:-- TERMINAL --} | 3557]] ) 3558end ) 3559 3560it ( 'draws line with many trailing spaces correctly #24955' , function () 3561local screen =tt . setup_child_nvim ( { 3562'--clean' , 3563'--cmd' , 3564'colorscheme vim' , 3565'--cmd' , 3566'call setline(1, ["1st line" .. repeat(" ", 153), "2nd line"])' , 3567} , { cols =80 , env =env_notermguicolors } ) 3568screen : expect ( [[ 3569^1st line | 3570|*2 35712nd line | 3572{3:[No Name] [+] 1,1 All}| 3573| 3574{5:-- TERMINAL --} | 3575]] ) 3576feed_data ( '$' ) 3577screen : expect ( [[ 35781st line | 3579| 3580^ | 35812nd line | 3582{3:[No Name] [+] 1,161 All}| 3583| 3584{5:-- TERMINAL --} | 3585]] ) 3586end ) 3587 3588it ( 'draws screen lines with leading spaces correctly #29711' , function () 3589local screen =tt . setup_child_nvim ( { 3590'--clean' , 3591'--cmd' , 3592'set foldcolumn=6 | call setline(1, ["", repeat("aabb", 1000)]) | echo 42' , 3593} , { extra_rows =10 , cols =66 } ) 3594screen : expect ( [[ 3595^ | 3596aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb|*12 3597aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba@@@| 3598[No Name] [+] 1,0-1 Top| 359942 | 3600{5:-- TERMINAL --} | 3601]] ) 3602feed_data ( '\12' ) -- Ctrl-L 3603-- The first line counts as 3 cells. 3604-- For the second line, 6 repeated spaces at the start counts as 2 cells, 3605-- so each screen line of the second line counts as 62 cells. 3606-- After drawing the first line and 8 screen lines of the second line, 3607-- 3 + 8 * 62 = 499 cells have been counted. 3608-- The 6 repeated spaces at the start of the next screen line exceeds the 3609-- 500-cell limit, so the buffer is flushed after these spaces. 3610screen : expect ( [[ 3611^ | 3612aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb|*12 3613aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba@@@| 3614[No Name] [+] 1,0-1 Top| 3615| 3616{5:-- TERMINAL --} | 3617]] ) 3618end ) 3619 3620it ( 'no heap-buffer-overflow when changing &columns' , function () 3621t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 3622-- Set a different bg colour and change $TERM to something dumber so the `print_spaces()` 3623-- codepath in `clear_region()` is hit. 3624local screen =tt . setup_child_nvim ( { 3625'--clean' , 3626'--cmd' , 3627'set notermguicolors | highlight Normal ctermbg=red' , 3628'--cmd' , 3629'call setline(1, ["a"->repeat(&columns)])' , 3630} , { env ={ TERM ='ansi' } } ) 3631 3632screen : expect ( [[ 3633{117:^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| 3634{117:~ }|*3 3635{118:[No Name] [+] 1,1 All}| 3636{117: }| 3637{5:-- TERMINAL --} | 3638]] ) 3639 3640feed_data ( ':set columns=12\n' ) 3641screen : expect ( [[ 3642{117:^aaaaaaaaaaaa }| 3643{117:aaaaaaaaaaaa }|*3 3644{118:< All}{117: }| 3645{117: }| 3646{5:-- TERMINAL --} | 3647]] ) 3648 3649-- Wider than TUI, so screen state will look weird. 3650-- Wait for the statusline to redraw to confirm that the TUI lives and ASAN is happy. 3651feed_data ( ':set columns=99|set stl=redrawn%m\n' ) 3652screen : expect ( { any ='redrawn%[%+%]' } ) 3653end ) 3654 3655it ( 'missing DSR response does not lead to hit-enter prompt #38877' , function () 3656local child_server =n . new_pipename () 3657exec_lua ( 'vim.uv.os_unsetenv("NVIM_TEST")' ) 3658local job =fn . jobstart ( { nvim_prog , '--clean' , '--listen' , child_server } , { 3659-- Use pty = true for a PTY without a terminal, so that there is no DSR response. 3660pty =true , 3661env ={ 3662VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 3663COLORTERM ='xterm-256color' , 3664NVIM_LOG_FILE =testlog , 3665} , 3666} ) 3667finally ( function () 3668exec_lua ( function () 3669vim . fn . jobstop ( job ) 3670vim . fn . jobwait ( { job } , 5000 ) 3671end ) 3672os . remove ( testlog ) 3673end ) 3674retry ( nil , nil , function () 3675t . neq ( nil , vim . uv . fs_stat ( child_server )) 3676end ) 3677local child_session =n . connect ( child_server ) 3678local expected_msg = 3679"E1568: Terminal did not respond to DSR request for 'background' color. Startup may be slower. :help 'ttyfast'" 3680retry ( nil , 4000 , function () 3681eq ( { true , { mode ='n' , blocking =false } } , { child_session : request ( 'nvim_get_mode' ) } ) 3682if not is_os ( 'win' ) then -- ConPTY provides DSR response on Windows? 3683eq ( 3684{ true , { output =expected_msg } } , 3685{ child_session : request ( 'nvim_exec2' , 'messages' , { output =true } ) } 3686) 3687end 3688end ) 3689end ) 3690 3691it ( 'exits immediately when stdin is closed #35744' , function () 3692local screen =tt . setup_child_nvim ( 3693{ '--clean' , '--cmd' , 'set laststatus=2' } , 3694{ env =vim . tbl_extend ( 'force' , env_notermguicolors , { NVIM_LOG_FILE =testlog } ) } 3695) 3696finally ( function () 3697os . remove ( testlog ) 3698end ) 3699screen : expect ( { any ='%[No Name%]' } ) 3700 3701local chan =api . nvim_get_option_value ( 'channel' , { buf =0 } ) 3702local pid =fn . jobpid ( chan ) 3703fn . chanclose ( chan ) 3704-- On Windows the console terminates the child with STATUS_CONTROL_C_EXIT (-1073741510). 3705screen : expect ( { 3706any =is_os ( 'win' ) and '%[Process exited %-?%d+%]' or '%[Process exited 1%]' , 3707} ) 3708-- Closing stdin must skip the DA1 wait. 3709t . assert_nolog ( 'timed out waiting for DA1 response' , testlog , 100 ) 3710eq ( vim . NIL , api . nvim_get_proc ( pid )) 3711end ) 3712end ) 3713 3714describe ( 'TUI UIEnter/UILeave' , function () 3715it ( 'fires exactly once, after VimEnter' , function () 3716clear () 3717local screen =tt . setup_child_nvim ( { 3718'--clean' , 3719'--cmd' , 3720'colorscheme vim' , 3721'--cmd' , 3722'set noswapfile noshowcmd noruler' , 3723'--cmd' , 3724'let g:evs = []' , 3725'--cmd' , 3726'autocmd UIEnter * :call add(g:evs, "UIEnter")' , 3727'--cmd' , 3728'autocmd UILeave * :call add(g:evs, "UILeave")' , 3729'--cmd' , 3730'autocmd VimEnter * :call add(g:evs, "VimEnter")' , 3731} , { env =env_notermguicolors } ) 3732screen : expect ( [[ 3733^ | 3734{100:~ }|*3 3735{3:[No Name] }| 3736| 3737{5:-- TERMINAL --} | 3738]] ) 3739feed_data ( ':echo g:evs\n' ) 3740screen : expect ( [[ 3741^ | 3742{100:~ }|*3 3743{3:[No Name] }| 3744['VimEnter', 'UIEnter'] | 3745{5:-- TERMINAL --} | 3746]] ) 3747end ) 3748end ) 3749 3750describe ( 'TUI FocusGained/FocusLost' , function () 3751local screen --[[@type test.functional.ui.screen]] 3752local child_session --[[@type test.Session]] 3753 3754before_each ( function () 3755clear () 3756local child_server =new_pipename () 3757screen =tt . setup_child_nvim ( { 3758'--listen' , 3759child_server , 3760'-u' , 3761'NONE' , 3762'-i' , 3763'NONE' , 3764'--cmd' , 3765'colorscheme vim' , 3766'--cmd' , 3767'set noswapfile noshowcmd noruler background=dark' , 3768} , { env =env_notermguicolors } ) 3769 3770screen : expect ( [[ 3771^ | 3772{100:~ }|*3 3773{3:[No Name] }| 3774| 3775{5:-- TERMINAL --} | 3776]] ) 3777child_session =n . connect ( child_server ) 3778child_session : request ( 3779'nvim_exec2' , 3780[[ 3781autocmd FocusGained * echo 'gained' 3782autocmd FocusLost * echo 'lost' 3783]] , 3784{} 3785) 3786feed_data ( '\034\016' ) -- CTRL-\ CTRL-N 3787end ) 3788 3789it ( 'in normal-mode' , function () 3790retry ( 2 , 3 * screen . timeout , function () 3791feed_data ( '\027[I' ) 3792screen : expect ( [[ 3793^ | 3794{100:~ }|*3 3795{3:[No Name] }| 3796gained | 3797{5:-- TERMINAL --} | 3798]] ) 3799 3800feed_data ( '\027[O' ) 3801screen : expect ( [[ 3802^ | 3803{100:~ }|*3 3804{3:[No Name] }| 3805lost | 3806{5:-- TERMINAL --} | 3807]] ) 3808end ) 3809end ) 3810 3811it ( 'in insert-mode' , function () 3812feed_data ( ':set noshowmode\r' ) 3813feed_data ( 'i' ) 3814screen : expect ( [[ 3815^ | 3816{100:~ }|*3 3817{3:[No Name] }| 3818:set noshowmode | 3819{5:-- TERMINAL --} | 3820]] ) 3821retry ( 2 , 3 * screen . timeout , function () 3822feed_data ( '\027[I' ) 3823screen : expect ( [[ 3824^ | 3825{100:~ }|*3 3826{3:[No Name] }| 3827gained | 3828{5:-- TERMINAL --} | 3829]] ) 3830feed_data ( '\027[O' ) 3831screen : expect ( [[ 3832^ | 3833{100:~ }|*3 3834{3:[No Name] }| 3835lost | 3836{5:-- TERMINAL --} | 3837]] ) 3838end ) 3839end ) 3840 3841-- During cmdline-mode we ignore :echo invoked by timers/events. 3842-- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. 3843it ( 'in cmdline-mode does NOT :echo' , function () 3844feed_data ( ':' ) 3845feed_data ( '\027[I' ) 3846screen : expect ( [[ 3847| 3848{100:~ }|*3 3849{3:[No Name] }| 3850:^ | 3851{5:-- TERMINAL --} | 3852]] ) 3853feed_data ( '\027[O' ) 3854screen : expect_unchanged () 3855end ) 3856 3857it ( 'in cmdline-mode' , function () 3858-- Set up autocmds that modify the buffer, instead of just calling :echo. 3859-- This is how we can test handling of focus gained/lost during cmdline-mode. 3860-- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. 3861child_session : request ( 3862'nvim_exec2' , 3863[[ 3864autocmd! 3865autocmd FocusLost * call append(line('$'), 'lost') 3866autocmd FocusGained * call append(line('$'), 'gained') 3867]] , 3868{} 3869) 3870retry ( 2 , 3 * screen . timeout , function () 3871-- Enter cmdline-mode. 3872feed_data ( ':' ) 3873screen : sleep ( 1 ) 3874-- Send focus lost/gained termcodes. 3875feed_data ( '\027[O' ) 3876feed_data ( '\027[I' ) 3877screen : sleep ( 1 ) 3878-- Exit cmdline-mode. Redraws from timers/events are blocked during 3879-- cmdline-mode, so the buffer won't be updated until we exit cmdline-mode. 3880feed_data ( '\n' ) 3881screen : expect { any ='lost' .. ( ' ' ): rep ( 46 ) .. '|\ngained' } 3882end ) 3883end ) 3884 3885it ( 'in terminal-mode' , function () 3886feed_data ( ':set shell=' .. testprg ( 'shell-test' ) .. ' shellcmdflag=EXE\n' ) 3887feed_data ( ':set shellxquote=\n' ) -- win: avoid extra quotes 3888feed_data ( ':set noshowmode laststatus=0\n' ) 3889 3890feed_data ( ':terminal zia\n' ) 3891-- Wait for terminal to be ready. 3892screen : expect ( [[ 3893^ready $ zia | 3894| 3895[Process exited 0] | 3896|*2 3897:terminal zia | 3898{5:-- TERMINAL --} | 3899]] ) 3900 3901feed_data ( '\027[I' ) 3902screen : expect { 3903grid =[[ 3904^ready $ zia | 3905| 3906[Process exited 0] | 3907|*2 3908gained | 3909{5:-- TERMINAL --} | 3910]] , 3911timeout =( 4 * screen . timeout ), 3912} 3913 3914feed_data ( '\027[O' ) 3915screen : expect ( [[ 3916^ready $ zia | 3917| 3918[Process exited 0] | 3919|*2 3920lost | 3921{5:-- TERMINAL --} | 3922]] ) 3923end ) 3924 3925it ( 'in hit-enter prompt' , function () 3926tt . override_screen_expect_for_conpty ( screen ) 3927feed_data ( ":echom 'msg1'|echom 'msg2'|echom 'msg3'|echom 'msg4'|echom 'msg5'\n" ) 3928screen : expect ( [[ 3929msg1 | 3930msg2 | 3931msg3 | 3932msg4 | 3933msg5 | 3934{102:Press ENTER or type command to continue}^ | 3935{5:-- TERMINAL --} | 3936]] ) 3937feed_data ( '\027[I' ) 3938feed_data ( '\027[I' ) 3939screen : expect_unchanged () 3940end ) 3941end ) 3942 3943-- These tests require `tt` because --headless/--embed does not initialize the TUI. 3944describe ( "TUI 't_Co' (terminal colors)" , function () 3945local screen --[[@type test.functional.ui.screen]] 3946 3947local function assert_term_colors ( term , colorterm , maxcolors , builtin_maxcolors ) 3948clear ( { env ={ TERM =term } , args ={} } ) 3949if builtin_maxcolors and ( is_os ( 'freebsd' ) or is_os ( 'win' ) or fn . has ( 'terminfo' ) == 0 ) then 3950maxcolors =builtin_maxcolors 3951end 3952screen =tt . setup_child_nvim ( { 3953'--clean' , 3954'--cmd' , 3955'colorscheme vim' , 3956'--cmd' , 3957nvim_set .. ' notermguicolors' , 3958} , { 3959env ={ 3960LANG ='C' , 3961TERM =term or '' , 3962COLORTERM =colorterm or '' , 3963} , 3964} ) 3965 3966local tline --[[@type string]] 3967if maxcolors == 8 then 3968tline ='{112:~ }' 3969elseif maxcolors == 16 then 3970tline ='~ ' 3971else 3972tline ='{100:~ }' 3973end 3974 3975screen : expect ( string . format ( 3976[[ 3977^ | 3978%s|*4 3979| 3980{5:-- TERMINAL --} | 3981]] , 3982tline 3983)) 3984 3985feed_data ( ':echo &t_Co\n' ) 3986screen : expect ( string . format ( 3987[[ 3988^ | 3989%s|*4 3990%-3s | 3991{5:-- TERMINAL --} | 3992]] , 3993tline , 3994tostring ( maxcolors and maxcolors or '' ) 3995)) 3996end 3997 3998-- ansi and no terminal type at all: 3999 4000if is_os ( 'win' ) then 4001it ( 'guessed vtpcon with no TERM uses 256 colors' , function () 4002assert_term_colors ( nil , nil , 256 ) 4003end ) 4004else 4005it ( 'no TERM uses 8 colors' , function () 4006assert_term_colors ( nil , nil , 8 ) 4007end ) 4008end 4009 4010it ( 'TERM=ansi no COLORTERM uses 8 colors' , function () 4011assert_term_colors ( 'ansi' , nil , 8 ) 4012end ) 4013 4014it ( 'TERM=ansi with COLORTERM=anything-no-number uses 16 colors' , function () 4015assert_term_colors ( 'ansi' , 'yet-another-term' , 16 ) 4016end ) 4017 4018it ( 'unknown TERM COLORTERM with 256 in name uses 256 colors' , function () 4019assert_term_colors ( 'ansi' , 'yet-another-term-256color' , 256 ) 4020end ) 4021 4022it ( 'TERM=ansi-256color sets 256 colours' , function () 4023assert_term_colors ( 'ansi-256color' , nil , 256 ) 4024end ) 4025 4026-- Unknown terminal types: 4027 4028it ( 'unknown TERM no COLORTERM sets 8 colours' , function () 4029assert_term_colors ( 'yet-another-term' , nil , 8 ) 4030end ) 4031 4032it ( 'unknown TERM with COLORTERM=anything-no-number uses 16 colors' , function () 4033assert_term_colors ( 'yet-another-term' , 'yet-another-term' , 16 ) 4034end ) 4035 4036it ( 'unknown TERM with 256 in name sets 256 colours' , function () 4037assert_term_colors ( 'yet-another-term-256color' , nil , 256 ) 4038end ) 4039 4040it ( 'unknown TERM COLORTERM with 256 in name uses 256 colors' , function () 4041assert_term_colors ( 'yet-another-term' , 'yet-another-term-256color' , 256 ) 4042end ) 4043 4044-- Linux kernel terminal emulator: 4045 4046it ( 'TERM=linux uses 256 colors' , function () 4047assert_term_colors ( 'linux' , nil , 256 ) 4048end ) 4049 4050it ( 'TERM=linux-16color uses 256 colors' , function () 4051assert_term_colors ( 'linux-16color' , nil , 256 ) 4052end ) 4053 4054it ( 'TERM=linux-256color uses 256 colors' , function () 4055assert_term_colors ( 'linux-256color' , nil , 256 ) 4056end ) 4057 4058-- screen: 4059-- 4060-- FreeBSD/Windows (any build without terminfo) fall back to built-in "screen-256colour". 4061-- Linux/MacOS have a screen entry in external terminfo with 8 colours, raised to 16 by COLORTERM. 4062 4063it ( 'TERM=screen no COLORTERM uses 8/256 colors' , function () 4064assert_term_colors ( 'screen' , nil , 8 , 256 ) 4065end ) 4066 4067it ( 'TERM=screen COLORTERM=screen uses 16/256 colors' , function () 4068assert_term_colors ( 'screen' , 'screen' , 16 , 256 ) 4069end ) 4070 4071it ( 'TERM=screen COLORTERM=screen-256color uses 256 colors' , function () 4072assert_term_colors ( 'screen' , 'screen-256color' , 256 ) 4073end ) 4074 4075it ( 'TERM=screen-256color no COLORTERM uses 256 colors' , function () 4076assert_term_colors ( 'screen-256color' , nil , 256 ) 4077end ) 4078 4079-- tmux: 4080-- 4081-- FreeBSD and MacOS fall back to the built-in tmux-256colour entry. 4082-- Linux has a tmux entry in external terminfo with 8 colours, 4083-- which is raised to 256. 4084 4085it ( 'TERM=tmux no COLORTERM uses 256 colors' , function () 4086assert_term_colors ( 'tmux' , nil , 256 ) 4087end ) 4088 4089it ( 'TERM=tmux COLORTERM=tmux uses 256 colors' , function () 4090assert_term_colors ( 'tmux' , 'tmux' , 256 ) 4091end ) 4092 4093it ( 'TERM=tmux COLORTERM=tmux-256color uses 256 colors' , function () 4094assert_term_colors ( 'tmux' , 'tmux-256color' , 256 ) 4095end ) 4096 4097it ( 'TERM=tmux-256color no COLORTERM uses 256 colors' , function () 4098assert_term_colors ( 'tmux-256color' , nil , 256 ) 4099end ) 4100 4101-- xterm and imitators: 4102 4103it ( 'TERM=xterm uses 256 colors' , function () 4104assert_term_colors ( 'xterm' , nil , 256 ) 4105end ) 4106 4107it ( 'TERM=xterm COLORTERM=gnome-terminal uses 256 colors' , function () 4108assert_term_colors ( 'xterm' , 'gnome-terminal' , 256 ) 4109end ) 4110 4111it ( 'TERM=xterm COLORTERM=mate-terminal uses 256 colors' , function () 4112assert_term_colors ( 'xterm' , 'mate-terminal' , 256 ) 4113end ) 4114 4115it ( 'TERM=xterm-256color uses 256 colors' , function () 4116assert_term_colors ( 'xterm-256color' , nil , 256 ) 4117end ) 4118 4119-- rxvt and stterm: 4120-- 4121-- FreeBSD and MacOS fall back to the built-in rxvt-256color and 4122-- st-256colour entries. 4123-- Linux has an rxvt, an st, and an st-16color entry in external terminfo 4124-- with 8, 8, and 16 colours respectively, which are raised to 256. 4125 4126it ( 'TERM=rxvt no COLORTERM uses 256 colors' , function () 4127assert_term_colors ( 'rxvt' , nil , 256 ) 4128end ) 4129 4130it ( 'TERM=rxvt COLORTERM=rxvt uses 256 colors' , function () 4131assert_term_colors ( 'rxvt' , 'rxvt' , 256 ) 4132end ) 4133 4134it ( 'TERM=rxvt-256color uses 256 colors' , function () 4135assert_term_colors ( 'rxvt-256color' , nil , 256 ) 4136end ) 4137 4138it ( 'TERM=st no COLORTERM uses 256 colors' , function () 4139assert_term_colors ( 'st' , nil , 256 ) 4140end ) 4141 4142it ( 'TERM=st COLORTERM=st uses 256 colors' , function () 4143assert_term_colors ( 'st' , 'st' , 256 ) 4144end ) 4145 4146it ( 'TERM=st COLORTERM=st-256color uses 256 colors' , function () 4147assert_term_colors ( 'st' , 'st-256color' , 256 ) 4148end ) 4149 4150it ( 'TERM=st-16color no COLORTERM uses 8/256 colors' , function () 4151assert_term_colors ( 'st' , nil , 256 ) 4152end ) 4153 4154it ( 'TERM=st-16color COLORTERM=st uses 16/256 colors' , function () 4155assert_term_colors ( 'st' , 'st' , 256 ) 4156end ) 4157 4158it ( 'TERM=st-16color COLORTERM=st-256color uses 256 colors' , function () 4159assert_term_colors ( 'st' , 'st-256color' , 256 ) 4160end ) 4161 4162it ( 'TERM=st-256color uses 256 colors' , function () 4163assert_term_colors ( 'st-256color' , nil , 256 ) 4164end ) 4165 4166-- gnome and vte: 4167-- 4168-- FreeBSD and MacOS fall back to the built-in vte-256color entry. 4169-- Linux has a gnome, a vte, a gnome-256color, and a vte-256color entry in 4170-- external terminfo with 8, 8, 256, and 256 colours respectively, which are 4171-- raised to 256. 4172 4173it ( 'TERM=gnome no COLORTERM uses 256 colors' , function () 4174assert_term_colors ( 'gnome' , nil , 256 ) 4175end ) 4176 4177it ( 'TERM=gnome COLORTERM=gnome uses 256 colors' , function () 4178assert_term_colors ( 'gnome' , 'gnome' , 256 ) 4179end ) 4180 4181it ( 'TERM=gnome COLORTERM=gnome-256color uses 256 colors' , function () 4182assert_term_colors ( 'gnome' , 'gnome-256color' , 256 ) 4183end ) 4184 4185it ( 'TERM=gnome-256color uses 256 colors' , function () 4186assert_term_colors ( 'gnome-256color' , nil , 256 ) 4187end ) 4188 4189it ( 'TERM=vte no COLORTERM uses 256 colors' , function () 4190assert_term_colors ( 'vte' , nil , 256 ) 4191end ) 4192 4193it ( 'TERM=vte COLORTERM=vte uses 256 colors' , function () 4194assert_term_colors ( 'vte' , 'vte' , 256 ) 4195end ) 4196 4197it ( 'TERM=vte COLORTERM=vte-256color uses 256 colors' , function () 4198assert_term_colors ( 'vte' , 'vte-256color' , 256 ) 4199end ) 4200 4201it ( 'TERM=vte-256color uses 256 colors' , function () 4202assert_term_colors ( 'vte-256color' , nil , 256 ) 4203end ) 4204 4205-- others: 4206 4207-- TODO(blueyed): this is made pending, since it causes failure + later hang 4208-- when using non-compatible libvterm (#9494/#10179). 4209pending ( 'TERM=interix uses 8 colors' , function () 4210assert_term_colors ( 'interix' , nil , 8 ) 4211end ) 4212 4213it ( 'TERM=iTerm.app uses 256 colors' , function () 4214assert_term_colors ( 'iTerm.app' , nil , 256 ) 4215end ) 4216 4217it ( 'TERM=iterm uses 256 colors' , function () 4218assert_term_colors ( 'iterm' , nil , 256 ) 4219end ) 4220end ) 4221 4222-- These tests require `tt` because --headless/--embed does not initialize the TUI. 4223describe ( "TUI 'term' option" , function () 4224local screen --[[@type test.functional.ui.screen]] 4225 4226local function assert_term ( term_envvar , term_expected ) 4227clear () 4228screen =tt . setup_child_nvim ( { 4229'--clean' , 4230'--cmd' , 4231nvim_set .. ' notermguicolors' , 4232} , { 4233env ={ 4234LANG ='C' , 4235TERM =term_envvar or '' , 4236} , 4237} ) 4238 4239local full_timeout =screen . timeout 4240retry ( nil , 2 * full_timeout , function () -- Wait for TUI thread to set 'term'. 4241feed_data ( ":echo 'term='.(&term)\n" ) 4242screen : expect { any ='term=' .. term_expected , timeout =250 } 4243end ) 4244end 4245 4246it ( 'gets builtin term if $TERM is invalid' , function () 4247assert_term ( 'foo' , 'ansi' ) 4248end ) 4249 4250it ( 'gets system-provided term if $TERM is valid' , function () 4251if is_os ( 'openbsd' ) then 4252assert_term ( 'xterm' , 'xterm' ) 4253elseif is_os ( 'bsd' ) then -- BSD lacks terminfo, builtin is always used. 4254assert_term ( 'xterm' , 'xterm' ) 4255elseif is_os ( 'mac' ) then 4256local status , _ =pcall ( assert_term , 'xterm' , 'xterm' ) 4257if not status then 4258pending ( 'macOS: unibilium could not find terminfo' ) 4259end 4260else 4261assert_term ( 'xterm' , 'xterm' ) 4262end 4263end ) 4264 4265it ( 'builtin terms' , function () 4266-- These non-standard terminfos are always builtin. 4267assert_term ( 'win32con' , 'win32con' ) 4268assert_term ( 'conemu' , 'conemu' ) 4269assert_term ( 'vtpcon' , 'vtpcon' ) 4270end ) 4271end ) 4272 4273-- These tests require `tt` because --headless/--embed does not initialize the TUI. 4274describe ( 'TUI' , function () 4275local screen --[[@type test.functional.ui.screen]] 4276 4277-- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI. 4278local function nvim_tui ( extra_args , extra_env ) 4279clear () 4280extra_env =extra_env or {} 4281local env =vim . tbl_extend ( 'force' , { LANG ='C' } , extra_env ) 4282 4283screen =tt . setup_child_nvim ( { 4284'--clean' , 4285'--cmd' , 4286'colorscheme vim' , 4287'--cmd' , 4288nvim_set .. ' notermguicolors' , 4289extra_args , 4290} , { 4291env =env , 4292} ) 4293end 4294 4295it ( '-V3log logs terminfo values' , function () 4296local logfile ='Xtest_tui_verbose_log' 4297nvim_tui ( '-V3' .. logfile ) 4298finally ( function () 4299os . remove ( logfile ) 4300end ) 4301 4302-- Wait for TUI to start. 4303feed_data ( 'Gitext' ) 4304screen : expect ( [[ 4305text^ | 4306{100:~ }|*4 4307{5:-- INSERT --} | 4308{5:-- TERMINAL --} | 4309]] ) 4310 4311retry ( nil , 3000 , function () -- Wait for log file to be flushed. 4312local log =read_file ( logfile ) or '' 4313eq ( '--- Terminal info --- {{{\n' , string . match ( log , '%-%-%- Terminal.-\n' )) -- }}} 4314ok ( # log > 50 ) 4315end ) 4316end ) 4317 4318it ( 'uses $NVIM_TERMDEFS to override terminfo' , function () 4319local logfile ='Xtest_terminfo_override_verbose_log' 4320finally ( function () 4321os . remove ( logfile ) 4322end ) 4323 4324local terminfo ={ 4325enter_ca_mode ='ENTER_CA_MODE' , 4326reset_cursor_style ='\027[0 q' , 4327key_home ={ 'ABC' , 'DEF' } , 4328key_npage ='npage' , 4329key_end ={ 'GHI' } , 4330key_f1 ='JKL' , 4331key_f63 ='MNO' , 4332Su =true , 4333max_colors =999 , 4334} 4335 4336nvim_tui ( '-V3' .. logfile , { NVIM_TERMDEFS =vim . json . encode ( terminfo ) } ) 4337 4338assert_log ( 'enter_ca_mode[^\n]*= ' .. terminfo . enter_ca_mode , logfile , 9999 ) 4339assert_log ( 4340'reset_cursor_style[^\n]*= ' .. vim . pesc ( terminfo . reset_cursor_style : gsub ( '\027' , '^[' )), 4341logfile , 43429999 4343) 4344assert_log ( 4345string . format ( 'key_home%%s*= %s, key_shome = %s' , terminfo . key_home [ 1 ], terminfo . key_home [ 2 ]), 4346logfile , 43479999 4348) 4349assert_log ( 'key_npage%s*= ' .. terminfo . key_npage , logfile , 9999 ) 4350assert_log ( 'key_end%s*= ' .. terminfo . key_end [ 1 ] .. '\n' , logfile , 9999 ) 4351assert_log ( 'key_f1%s*= ' .. terminfo . key_f1 , logfile , 9999 ) 4352assert_log ( 'key_f63%s*= ' .. terminfo . key_f63 , logfile , 9999 ) 4353assert_log ( 'extended underline[^\n]*: ' .. tostring ( terminfo . Su ), logfile , 9999 ) 4354assert_log ( 'max_colors: ' .. terminfo . max_colors , logfile , 9999 ) 4355end ) 4356 4357it ( 'does not crash on large inputs #26099' , function () 4358nvim_tui () 4359 4360screen : expect ( [[ 4361^ | 4362{100:~ }|*4 4363| 4364{5:-- TERMINAL --} | 4365]] ) 4366 4367feed_data ( string . format ( '\027]52;c;%s\027\\' , string . rep ( 'A' , 8192 ))) 4368 4369screen : expect_unchanged () 4370end ) 4371 4372it ( 'queries the terminal for truecolor support' , function () 4373t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 4374clear () 4375exec_lua ( [[ 4376vim.api.nvim_create_autocmd('TermRequest', { 4377callback = function(ev) 4378local req = ev.data.sequence 4379local sequence = req:match('^\027P%+q([%x;]+)$') 4380if sequence then 4381local t = {} 4382for cap in vim.gsplit(sequence, ';') do 4383local resp = string.format('\027P1+r%s\027\\', sequence) 4384vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp) 4385t[vim.text.hexdecode(cap)] = true 4386end 4387vim.g.xtgettcap = t 4388return true 4389end 4390end, 4391}) 4392]] ) 4393 4394local child_server =new_pipename () 4395screen =tt . setup_child_nvim ( { 4396'--clean' , 4397'--listen' , 4398child_server , 4399} , { 4400env ={ 4401VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 4402 4403-- Force COLORTERM to be unset and use a TERM that does not contain Tc or RGB in terminfo. 4404-- This will force the nested nvim instance to query with XTGETTCAP 4405COLORTERM ='' , 4406TERM ='xterm-256colors' , 4407} , 4408} ) 4409 4410screen : expect ( { any ='%[No Name%]' } ) 4411 4412local child_session =n . connect ( child_server ) 4413retry ( nil , 1000 , function () 4414eq ( { 4415Tc =true , 4416RGB =true , 4417setrgbf =true , 4418setrgbb =true , 4419} , eval ( "get(g:, 'xtgettcap', '')" )) 4420eq ( { true , 1 } , { child_session : request ( 'nvim_eval' , '&termguicolors' ) } ) 4421end ) 4422end ) 4423 4424it ( 'does not query the terminal for truecolor support if $COLORTERM is set' , function () 4425clear () 4426exec_lua ( [[ 4427vim.api.nvim_create_autocmd('TermRequest', { 4428callback = function(ev) 4429local req = ev.data.sequence 4430vim.g.termrequest = req 4431local xtgettcap = req:match('^\027P%+q([%x;]+)$') 4432if xtgettcap then 4433local t = {} 4434for cap in vim.gsplit(xtgettcap, ';') do 4435local resp = string.format('\027P1+r%s\027\\', xtgettcap) 4436vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp) 4437t[vim.text.hexdecode(cap)] = true 4438end 4439vim.g.xtgettcap = t 4440return true 4441elseif req:match('^\027P$qm\027\\$') then 4442vim.g.decrqss = true 4443end 4444end, 4445}) 4446]] ) 4447 4448local child_server =new_pipename () 4449screen =tt . setup_child_nvim ( { 4450'--clean' , 4451'--listen' , 4452child_server , 4453} , { 4454env ={ 4455VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 4456-- With COLORTERM=256, Nvim should not query the terminal and should not set 'tgc' 4457COLORTERM ='256' , 4458TERM ='xterm-256colors' , 4459} , 4460} ) 4461 4462screen : expect ( { any ='%[No Name%]' } ) 4463 4464local child_session =n . connect ( child_server ) 4465retry ( nil , 1000 , function () 4466local xtgettcap =eval ( "get(g:, 'xtgettcap', {})" ) 4467eq ( nil , xtgettcap [ 'Tc' ]) 4468eq ( nil , xtgettcap [ 'RGB' ]) 4469eq ( nil , xtgettcap [ 'setrgbf' ]) 4470eq ( nil , xtgettcap [ 'setrgbb' ]) 4471eq ( 0 , eval ( [[get(g:, 'decrqss')]] )) 4472eq ( { true , 0 } , { child_session : request ( 'nvim_eval' , '&termguicolors' ) } ) 4473end ) 4474end ) 4475 4476it ( 'queries the terminal for OSC 52 support with XTGETTCAP' , function () 4477t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 4478clear () 4479if not exec_lua ( 'return pcall(require, "ffi")' ) then 4480pending ( 'N/A: missing LuaJIT FFI' ) 4481end 4482 4483-- Change vterm's DA1 response so that it doesn't include 52 4484exec_lua ( function () 4485local ffi =require ( 'ffi' ) 4486ffi . cdef [[ 4487extern char vterm_primary_device_attr [] 4488]] 4489 4490ffi . copy ( ffi . C . vterm_primary_device_attr , '61;22' ) 4491end ) 4492 4493exec_lua ( [[ 4494_G.query = false 4495vim.api.nvim_create_autocmd('TermRequest', { 4496callback = function(ev) 4497local req = ev.data.sequence 4498local sequence = req:match('^\027P%+q([%x;]+)$') 4499if sequence and vim.text.hexdecode(sequence) == 'Ms' then 4500local resp = string.format('\027P1+r%s=%s\027\\', sequence, vim.text.hexencode('\027]52;;\027\\')) 4501vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp) 4502_G.query = true 4503return true 4504end 4505end, 4506}) 4507]] ) 4508 4509local child_server =new_pipename () 4510screen =tt . setup_child_nvim ( { 4511'--listen' , 4512child_server , 4513'--clean' , 4514} , { 4515env ={ 4516VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 4517} , 4518} ) 4519 4520screen : expect ( { any ='%[No Name%]' } ) 4521 4522local child_session =n . connect ( child_server ) 4523retry ( nil , 1000 , function () 4524eq ( { true , { osc52 =true } } , { child_session : request ( 'nvim_eval' , 'g:termfeatures' ) } ) 4525end ) 4526eq ( true , exec_lua ( [[return _G.query]] )) 4527 4528-- Attach another (non-TUI) UI to the child instance 4529local alt =Screen . new ( nil , nil , nil , child_session ) 4530finally ( function () 4531alt : detach () 4532-- Avoid a dangling process after :detach. 4533child_session : request ( 'nvim_command' , 'qall!' ) 4534end ) 4535 4536-- Detach the first (primary) client so only the second UI is attached 4537feed_data ( ':detach\n' ) 4538 4539alt : expect ( { any ='%[No Name%]' } ) 4540 4541-- osc52 should be cleared from termfeatures 4542eq ( { true , {} } , { child_session : request ( 'nvim_eval' , 'g:termfeatures' ) } ) 4543end ) 4544 4545it ( 'determines OSC 52 support from DA1 response' , function () 4546t . skip ( is_os ( 'win' ), 'FIXME: does not work on Windows' ) 4547clear () 4548exec_lua ( [[ 4549-- Check that we do not emit an XTGETTCAP request when DA1 indicates support 4550_G.query = false 4551vim.api.nvim_create_autocmd('TermRequest', { 4552callback = function(ev) 4553local req = ev.data.sequence 4554local sequence = req:match('^\027P%+q([%x;]+)$') 4555if sequence and vim.text.hexdecode(sequence) == 'Ms' then 4556_G.query = true 4557return true 4558end 4559end, 4560}) 4561]] ) 4562 4563local child_server =new_pipename () 4564screen =tt . setup_child_nvim ( { 4565'--listen' , 4566child_server , 4567'--clean' , 4568} , { 4569env ={ 4570VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 4571} , 4572} ) 4573 4574screen : expect ( { any ='%[No Name%]' } ) 4575 4576local child_session =n . connect ( child_server ) 4577retry ( nil , 1000 , function () 4578eq ( { true , { osc52 =true } } , { child_session : request ( 'nvim_eval' , 'g:termfeatures' ) } ) 4579end ) 4580eq ( false , exec_lua ( [[return _G.query]] )) 4581end ) 4582 4583it ( 'does not query the terminal for OSC 52 support when disabled' , function () 4584clear () 4585exec_lua ( [[ 4586_G.query = false 4587vim.api.nvim_create_autocmd('TermRequest', { 4588callback = function(ev) 4589local req = ev.data.sequence 4590local sequence = req:match('^\027P%+q([%x;]+)$') 4591if sequence and vim.text.hexdecode(sequence) == 'Ms' then 4592_G.query = true 4593return true 4594end 4595end, 4596}) 4597]] ) 4598 4599local child_server =new_pipename () 4600screen =tt . setup_child_nvim ( { 4601'--listen' , 4602child_server , 4603'--clean' , 4604'--cmd' , 4605'let g:termfeatures = #{osc52: v:false}' , 4606} , { 4607env ={ 4608VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ), 4609} , 4610} ) 4611 4612screen : expect ( { any ='%[No Name%]' } ) 4613 4614local child_session =n . connect ( child_server ) 4615eq ( { true , { osc52 =false } } , { child_session : request ( 'nvim_eval' , 'g:termfeatures' ) } ) 4616eq ( false , exec_lua ( [[return _G.query]] )) 4617end ) 4618end ) 4619 4620describe ( 'TUI bg color' , function () 4621if t . skip ( is_os ( 'win' )) then 4622return 4623end 4624 4625before_each ( clear ) 4626 4627it ( 'is properly set in a nested Nvim instance when background=dark' , function () 4628command ( 'highlight clear Normal' ) 4629command ( 'set background=dark' ) -- set outer Nvim background 4630local child_server =new_pipename () 4631local screen =tt . setup_child_nvim ( { 4632'--clean' , 4633'--listen' , 4634child_server , 4635'--cmd' , 4636'colorscheme vim' , 4637'--cmd' , 4638'set noswapfile' , 4639} ) 4640screen : expect ( { any ='%[No Name%]' } ) 4641local child_session =n . connect ( child_server ) 4642retry ( nil , nil , function () 4643eq ( { true , 'dark' } , { child_session : request ( 'nvim_eval' , '&background' ) } ) 4644end ) 4645end ) 4646 4647it ( 'is properly set in a nested Nvim instance when background=light' , function () 4648command ( 'highlight clear Normal' ) 4649command ( 'set background=light' ) -- set outer Nvim background 4650local child_server =new_pipename () 4651local screen =tt . setup_child_nvim ( { 4652'--clean' , 4653'--listen' , 4654child_server , 4655'--cmd' , 4656'colorscheme vim' , 4657'--cmd' , 4658'set noswapfile' , 4659} ) 4660screen : expect ( { any ='%[No Name%]' } ) 4661local child_session =n . connect ( child_server ) 4662retry ( nil , nil , function () 4663eq ( { true , 'light' } , { child_session : request ( 'nvim_eval' , '&background' ) } ) 4664end ) 4665end ) 4666 4667it ( 'queries the terminal for background color' , function () 4668exec_lua ( [[ 4669vim.api.nvim_create_autocmd('TermRequest', { 4670callback = function(ev) 4671local req = ev.data.sequence 4672if req == '\027]11;?' then 4673vim.g.oscrequest = true 4674return true 4675end 4676end, 4677}) 4678]] ) 4679tt . setup_child_nvim ( { 4680'--clean' , 4681'--cmd' , 4682'colorscheme vim' , 4683'--cmd' , 4684'set noswapfile' , 4685} ) 4686retry ( nil , 1000 , function () 4687eq ( true , eval ( "get(g:, 'oscrequest', v:false)" )) 4688end ) 4689end ) 4690 4691it ( 'sends theme update notifications when background changes #31652' , function () 4692command ( 'set background=dark' ) -- set outer Nvim background 4693local child_server =new_pipename () 4694local screen =tt . setup_child_nvim ( { 4695'--clean' , 4696'--listen' , 4697child_server , 4698'--cmd' , 4699'colorscheme vim' , 4700'--cmd' , 4701'set noswapfile' , 4702'-c' , 4703[[autocmd OptionSet background let g:background_option_old = v:option_old]] , 4704'-c' , 4705[[autocmd OptionSet background let g:background_option_new = v:option_new]] , 4706} ) 4707screen : expect ( { any ='%[No Name%]' } ) 4708local child_session =n . connect ( child_server ) 4709retry ( nil , nil , function () 4710eq ( { true , 'dark' } , { child_session : request ( 'nvim_eval' , '&background' ) } ) 4711end ) 4712command ( 'set background=light' ) -- set outer Nvim background 4713retry ( nil , nil , function () 4714eq ( { true , 'light' } , { child_session : request ( 'nvim_eval' , '&background' ) } ) 4715end ) 4716-- Make sure it triggered OptionSet with v:option_* values #38551 #41146 4717eq ( { true , 'dark' } , { child_session : request ( 'nvim_eval' , 'g:background_option_old' ) } ) 4718eq ( { true , 'light' } , { child_session : request ( 'nvim_eval' , 'g:background_option_new' ) } ) 4719end ) 4720 4721-- Start a headless server (the outer Nvim is its OSC-11-answering terminal), 4722-- cleaned up when the test ends, and return its address and a client session. 4723local function start_headless ( extra ) 4724local server =new_pipename () 4725local argv ={ nvim_prog , '--clean' , '--headless' , '--listen' , server } 4726local job =fn . jobstart ( vim . list_extend ( argv , extra or {} )) 4727finally ( function () 4728pcall ( fn . jobstop , job ) 4729end ) 4730local session 4731retry ( nil , nil , function () 4732session =n . connect ( server ) 4733end ) 4734return server , session 4735end 4736 4737it ( 'is detected on remote-ui attach to a headless server #30320' , function () 4738command ( 'highlight clear Normal' ) 4739command ( 'set background=light' ) -- outer Nvim acts as a light terminal 4740local server , session = 4741start_headless ( { '--cmd' , 'colorscheme vim' , '--cmd' , 'set noswapfile' } ) 4742local screen =tt . setup_child_nvim ( { '--remote-ui' , '--server' , server } ) 4743screen : expect ( { any ='%[No Name%]' } ) 4744retry ( nil , nil , function () 4745eq ( { true , 'light' } , { session : request ( 'nvim_eval' , '&background' ) } ) 4746end ) 4747end ) 4748 4749it ( 'enables termguicolors on remote-ui attach to a headless server #30320' , function () 4750command ( 'set background=light' ) 4751local server , session = 4752start_headless ( { '--cmd' , 'colorscheme vim' , '--cmd' , 'set noswapfile' } ) 4753eq ( { true , 0 } , { session : request ( 'nvim_eval' , '&termguicolors' ) } ) 4754-- A truecolor terminal so the attaching client reports rgb=true. 4755local screen =tt . setup_child_nvim ( 4756{ '--remote-ui' , '--server' , server } , 4757{ env ={ COLORTERM ='truecolor' } } 4758) 4759screen : expect ( { any ='%[No Name%]' } ) 4760retry ( nil , nil , function () 4761eq ( { true , 1 } , { session : request ( 'nvim_eval' , '&termguicolors' ) } ) 4762end ) 4763end ) 4764 4765it ( 'does not override an explicit user background on remote-ui attach' , function () 4766command ( 'highlight clear Normal' ) 4767command ( 'set background=light' ) -- light terminal 4768local server , session =start_headless ( { 4769'--cmd' , 4770'set background=dark' , -- user pins dark 4771'--cmd' , 4772'colorscheme vim' , 4773'--cmd' , 4774'set noswapfile' , 4775} ) 4776-- Count OSC 11 responses so we can wait for the attach round-trip to finish 4777-- (a deterministic barrier) before asserting the user's value held. 4778session : request ( 4779'nvim_exec_lua' , 4780[[ 4781_G.osc11 = 0 4782vim.api.nvim_create_autocmd('TermResponse', { callback = function(ev) 4783if ev.data.sequence:find(']11;rgb', 1, true) then 4784_G.osc11 = _G.osc11 + 1 4785end 4786end }) 4787]] , 4788{} 4789) 4790local screen =tt . setup_child_nvim ( { '--remote-ui' , '--server' , server } ) 4791screen : expect ( { any ='%[No Name%]' } ) 4792retry ( nil , nil , function () 4793eq ( { true , true } , { session : request ( 'nvim_exec_lua' , 'return _G.osc11 > 0' , {} ) } ) 4794end ) 4795eq ( { true , 'dark' } , { session : request ( 'nvim_eval' , '&background' ) } ) 4796end ) 4797 4798it ( 'reacts to a runtime theme change over remote-ui' , function () 4799command ( 'highlight clear Normal' ) 4800command ( 'set background=light' ) -- start light 4801local server , session = 4802start_headless ( { '--cmd' , 'colorscheme vim' , '--cmd' , 'set noswapfile' } ) 4803local screen =tt . setup_child_nvim ( { '--remote-ui' , '--server' , server } ) 4804screen : expect ( { any ='%[No Name%]' } ) 4805retry ( nil , nil , function () 4806eq ( { true , 'light' } , { session : request ( 'nvim_eval' , '&background' ) } ) 4807end ) 4808command ( 'highlight clear Normal' ) 4809command ( 'set background=dark' ) -- flip the outer terminal at runtime 4810retry ( nil , nil , function () 4811eq ( { true , 'dark' } , { session : request ( 'nvim_eval' , '&background' ) } ) 4812end ) 4813end ) 4814end ) 4815 4816describe ( 'TUI client' , function () 4817local function start_tui_and_remote_client () 4818local server_super =n . clear () 4819local client_super =n . new_session ( true ) 4820finally ( function () 4821client_super : close () 4822server_super : close () 4823end ) 4824 4825local server_pipe =new_pipename () 4826local screen_server =tt . setup_child_nvim ( { 4827'--clean' , 4828'--listen' , 4829server_pipe , 4830'--cmd' , 4831'colorscheme vim' , 4832'--cmd' , 4833nvim_set .. ' laststatus=2 background=dark' , 4834} , { env =env_notermguicolors } ) 4835screen_server : expect ( [[ 4836^ | 4837{100:~ }|*3 4838{3:[No Name] }| 4839| 4840{5:-- TERMINAL --} | 4841]] ) 4842 4843feed_data ( 'iHello, World' ) 4844screen_server : expect ( [[ 4845Hello, World^ | 4846{100:~ }|*3 4847{3:[No Name] [+] }| 4848{5:-- INSERT --} | 4849{5:-- TERMINAL --} | 4850]] ) 4851feed_data ( '\027' ) 4852local s0 =[[ 4853Hello, Worl^d | 4854{100:~ }|*3 4855{3:[No Name] [+] }| 4856| 4857{5:-- TERMINAL --} | 4858]] 4859screen_server : expect ( s0 ) 4860 4861feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 4862screen_server : expect ( { any ='GUI Running: 0' } ) 4863 4864set_session ( client_super ) 4865local screen_client =tt . setup_child_nvim ( { 4866'--remote-ui' , 4867'--server' , 4868server_pipe , 4869} , { env =env_notermguicolors } ) 4870screen_client : expect ( s0 ) 4871 4872return server_super , screen_server , screen_client 4873end 4874 4875it ( 'connects to remote instance (with its own TUI)' , function () 4876local _ , screen_server , screen_client =start_tui_and_remote_client () 4877 4878feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 4879screen_client : expect ( { any ='GUI Running: 0' } ) 4880 4881-- grid smaller than containing terminal window is cleared properly 4882feed_data ( ":call setline(1,['a'->repeat(&columns)]->repeat(&lines))\n" ) 4883feed_data ( '0:set lines=3\n' ) 4884local s1 =[[ 4885^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 4886{3:[No Name] [+] }| 4887|*4 4888{5:-- TERMINAL --} | 4889]] 4890screen_client : expect ( s1 ) 4891screen_server : expect ( s1 ) 4892end ) 4893 4894it ( ':restart! works when connecting to remote instance (with its own TUI)' , function () 4895local _ , screen_server , screen_client =start_tui_and_remote_client () 4896 4897-- Both clients should attach to the new server. 4898feed_data ( ':restart! +qall!\n' ) 4899local screen_restarted =[[ 4900^ | 4901{100:~ }|*3 4902{3:[No Name] }| 4903| 4904{5:-- TERMINAL --} | 4905]] 4906screen_client : expect ( screen_restarted ) 4907screen_server : expect ( screen_restarted ) 4908 4909feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 4910screen_client : expect ( { any ='GUI Running: 0' } ) 4911 4912-- The :vsplit command should only be executed once. 4913feed_data ( ':restart! vsplit\r' ) 4914screen_restarted =[[ 4915^ │ | 4916{100:~ }│{100:~ }|*3 4917{3:[No Name] }{2:[No Name] }| 4918| 4919{5:-- TERMINAL --} | 4920]] 4921screen_client : expect ( screen_restarted ) 4922screen_server : expect ( screen_restarted ) 4923 4924feed_data ( ':qall!\r' ) 4925screen_client : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 4926screen_server : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 4927end ) 4928 4929local function start_headless_server_and_client ( use_testlog ) 4930local server =n . new_session ( false , { 4931args_rm ={ '--cmd' } , 4932args ={ 4933'--cmd' , 4934'colorscheme vim' , 4935'--cmd' , 4936nvim_set .. ' notermguicolors background=dark' , 4937} , 4938} ) 4939local client_super = 4940n . new_session ( true , use_testlog and { env ={ NVIM_LOG_FILE =testlog } } or {} ) 4941finally ( function () 4942client_super : close () 4943server : close () 4944os . remove ( testlog ) 4945end ) 4946 4947set_session ( server ) 4948--- @type string 4949local server_pipe =api . nvim_get_vvar ( 'servername' ) 4950server : request ( 'nvim_input' , 'iHalloj!<Esc>' ) 4951 4952set_session ( client_super ) 4953local screen_client =tt . setup_child_nvim ( { 4954'--remote-ui' , 4955'--server' , 4956server_pipe , 4957} , { env =env_notermguicolors } ) 4958screen_client : expect ( [[ 4959Halloj^! | 4960{100:~ }|*4 4961| 4962{5:-- TERMINAL --} | 4963]] ) 4964 4965return server , server_pipe , screen_client 4966end 4967 4968it ( 'connects to remote instance (--headless)' , function () 4969local server , server_pipe , screen_client =start_headless_server_and_client ( false ) 4970 4971-- No heap-use-after-free when receiving UI events after deadly signal #22184 4972server : request ( 'nvim_input' , ( 'a' ): rep ( 1000 )) 4973exec_lua ( [[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]] ) 4974screen_client : expect ( is_os ( 'win' ) and { any ='%[Process exited 1%]' } or [[ 4975Nvim: Caught deadly signal 'SIGTERM' | 4976^ | 4977[Process exited 1] | 4978|*3 4979{5:-- TERMINAL --} | 4980]] ) 4981 4982eq ( 0 , api . nvim_get_vvar ( 'shell_error' )) 4983-- exits on input eof #22244 4984-- Use system() without input so that stdin is closed. 4985fn . system ( { nvim_prog , '--remote-ui' , '--server' , server_pipe } ) 4986eq ( 1 , api . nvim_get_vvar ( 'shell_error' )) 4987 4988command ( 'bwipe!' ) 4989-- Start another remote client to attach to the same server. 4990fn . jobstart ( { nvim_prog , '--remote-ui' , '--server' , server_pipe } , { term =true } ) 4991command ( 'startinsert' ) 4992screen_client : expect ( [[ 4993{100:<<<}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 4994aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|*3 4995aaaaaa^ | 4996{5:-- INSERT --} | 4997{5:-- TERMINAL --} | 4998]] ) 4999feed_data ( '\027' ) 5000 5001feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 5002screen_client : expect ( { any ='GUI Running: 0' } ) 5003end ) 5004 5005it ( ':restart! works when connecting to remote instance (--headless)' , function () 5006local _ , server_pipe , screen_client =start_headless_server_and_client ( false ) 5007 5008-- The client should attach to the new server and the original server should exit. 5009feed_data ( ':restart! +qall!\n' ) 5010screen_client : expect ( [[ 5011^ | 5012{100:~ }|*4 5013| 5014{5:-- TERMINAL --} | 5015]] ) 5016retry ( nil , nil , function () 5017eq ( nil , vim . uv . fs_stat ( server_pipe )) 5018end ) 5019 5020feed_data ( ':echo "GUI Running: " .. has("gui_running")\013' ) 5021screen_client : expect ( { any ='GUI Running: 0' } ) 5022 5023feed_data ( ':q!\r' ) 5024screen_client : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 5025end ) 5026 5027local ffi_str_defs =[[ 5028local ffi = require('ffi') 5029local cstr = ffi.typeof('char[?]') 5030ffi.cdef('typedef struct { char *data; size_t size; } String;') 5031local function to_api_string(str) 5032return ffi.new('String', { data = cstr(#str + 1, str), size = #str }) 5033end 5034]] 5035 5036it ( 'does not crash or hang with a very long title' , function () 5037local server , _ , screen_client =start_headless_server_and_client ( true ) 5038local server_exec_lua =tt . make_lua_executor ( server ) 5039if not server_exec_lua ( 'return pcall(require, "ffi")' ) then 5040pending ( 'N/A: missing LuaJIT FFI' ) 5041end 5042 5043server : request ( 'nvim_set_option_value' , 'titlestring' , '%t%( %M%) - Nvim' , {} ) 5044local bufname =api . nvim_buf_get_name ( 0 ) 5045local old_title =api . nvim_buf_get_var ( 0 , 'term_title' ) 5046if not is_os ( 'win' ) then 5047eq ( bufname , old_title ) 5048end 5049-- Normally a title cannot be longer than the 65535-byte buffer as maketitle() 5050-- limits it length. Use FFI to send a very long title directly. 5051server_exec_lua ( ffi_str_defs .. [[ 5052ffi.cdef('void ui_call_set_title(String title);') 5053ffi.C.ui_call_set_title(to_api_string(('a'):rep(65536))) 5054]] ) 5055screen_client : expect_unchanged () 5056assert_log ( 'set_title: title string too long!' , testlog ) 5057eq ( old_title , api . nvim_buf_get_var ( 0 , 'term_title' )) 5058 5059-- Following escape sequences are not affected. 5060server : request ( 'nvim_set_option_value' , 'title' , true , {} ) 5061retry ( nil , nil , function () 5062eq ( '[No Name] + - Nvim' , api . nvim_buf_get_var ( 0 , 'term_title' )) 5063end ) 5064end ) 5065 5066it ( 'logs chdir failure properly' , function () 5067t . skip ( is_os ( 'win' ), 'N/A for Windows' ) 5068local server , _ , screen_client =start_headless_server_and_client ( true ) 5069local server_exec_lua =tt . make_lua_executor ( server ) 5070if not server_exec_lua ( 'return pcall(require, "ffi")' ) then 5071pending ( 'N/A: missing LuaJIT FFI' ) 5072end 5073 5074-- Use FFI to send a chdir event to a non-directory path. 5075server_exec_lua ( ffi_str_defs .. [[ 5076ffi.cdef('void ui_call_chdir(String path);') 5077ffi.C.ui_call_chdir(to_api_string('README.md')) 5078]] ) 5079screen_client : expect_unchanged () 5080assert_log ( 'Failed to chdir to README%.md: not a directory' , testlog ) 5081end ) 5082 5083it ( 'nvim_ui_send works with remote client #36317' , function () 5084local server , _ , _ =start_headless_server_and_client ( false ) 5085server : request ( 'nvim_ui_send' , '\027]2;TEST_TITLE\027\\' ) 5086retry ( nil , nil , function () 5087eq ( 'TEST_TITLE' , api . nvim_buf_get_var ( 0 , 'term_title' )) 5088end ) 5089end ) 5090 5091it ( 'throws error when no server exists' , function () 5092clear () 5093local screen =tt . setup_child_nvim ( { 5094'--remote-ui' , 5095'--server' , 5096'127.0.0.1:2436546' , 5097} , { cols =60 } ) 5098 5099screen : expect ( [[ 5100Remote ui failed to start: {MATCH:.*}| 5101^ | 5102[Process exited 1] | 5103|*3 5104{5:-- TERMINAL --} | 5105]] ) 5106end ) 5107 5108local function test_remote_tui_quit ( status ) 5109local server_super , screen_server , screen_client =start_tui_and_remote_client () 5110 5111-- quitting the server 5112set_session ( server_super ) 5113feed_data ( status and ':' .. status .. 'cquit!\n' or ':quit!\n' ) 5114status =status and status or 0 5115screen_server : expect ( { any ='Process exited ' .. status } ) 5116screen_client : expect ( { any ='Process exited ' .. status } ) 5117end 5118 5119describe ( 'exits when server quits' , function () 5120it ( 'with :quit' , function () 5121test_remote_tui_quit () 5122end ) 5123 5124it ( 'with :cquit' , function () 5125test_remote_tui_quit ( 42 ) 5126end ) 5127end ) 5128 5129it ( 'suspend/resume works with multiple clients' , function () 5130t . skip ( is_os ( 'win' ), 'N/A for Windows' ) 5131local server_super , screen_server , screen_client =start_tui_and_remote_client () 5132 5133local screen_normal =[[ 5134Hello, Worl^d | 5135{100:~ }|*3 5136{3:[No Name] [+] }| 5137| 5138{5:-- TERMINAL --} | 5139]] 5140local screen_suspended =[[ 5141|*5 5142^[Process suspended] | 5143{5:-- TERMINAL --} | 5144]] 5145 5146screen_client : expect ( { grid =screen_normal , unchanged =true } ) 5147screen_server : expect ( { grid =screen_normal , unchanged =true } ) 5148 5149-- Suspend both clients. 5150feed_data ( ':suspend\r' ) 5151screen_client : expect ( { grid =screen_suspended } ) 5152screen_server : expect ( { grid =screen_suspended } ) 5153 5154-- Resume the remote client. 5155n . feed ( '<Space>' ) 5156screen_client : expect ( { grid =screen_normal } ) 5157screen_server : expect ( { grid =screen_suspended , unchanged =true } ) 5158 5159-- Resume the embedding client. 5160server_super : request ( 'nvim_input' , '<Space>' ) 5161screen_server : expect ( { grid =screen_normal } ) 5162screen_client : expect ( { grid =screen_normal , unchanged =true } ) 5163 5164-- Suspend both clients again. 5165feed_data ( ':suspend\r' ) 5166screen_client : expect ( { grid =screen_suspended } ) 5167screen_server : expect ( { grid =screen_suspended } ) 5168 5169-- Resume the remote client. 5170n . feed ( '<Space>' ) 5171screen_client : expect ( { grid =screen_normal } ) 5172screen_server : expect ( { grid =screen_suspended , unchanged =true } ) 5173 5174-- Suspend the remote client again. 5175feed_data ( ':suspend\r' ) 5176screen_client : expect ( { grid =screen_suspended } ) 5177screen_server : expect ( { grid =screen_suspended , unchanged =true } ) 5178 5179-- Resume the embedding client. 5180server_super : request ( 'nvim_input' , '<Space>' ) 5181screen_server : expect ( { grid =screen_normal } ) 5182screen_client : expect ( { grid =screen_suspended , unchanged =true } ) 5183 5184-- Resume the remote client. 5185n . feed ( '<Space>' ) 5186screen_client : expect ( { grid =screen_normal } ) 5187screen_server : expect ( { grid =screen_normal , unchanged =true } ) 5188 5189feed_data ( ':quit!\r' ) 5190screen_server : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 5191screen_client : expect ( { any =vim . pesc ( '[Process exited 0]' ) } ) 5192end ) 5193end )