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