tui_spec.lua 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765
  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. local t = require('test.testutil')
  7. local n = require('test.functional.testnvim')()
  8. local Screen = require('test.functional.ui.screen')
  9. local tt = require('test.functional.testterm')
  10. local eq = t.eq
  11. local feed_data = tt.feed_data
  12. local clear = n.clear
  13. local command = n.command
  14. local exec = n.exec
  15. local exec_lua = n.exec_lua
  16. local testprg = n.testprg
  17. local retry = t.retry
  18. local nvim_prog = n.nvim_prog
  19. local nvim_set = n.nvim_set
  20. local ok = t.ok
  21. local read_file = t.read_file
  22. local fn = n.fn
  23. local api = n.api
  24. local is_ci = t.is_ci
  25. local is_os = t.is_os
  26. local new_pipename = n.new_pipename
  27. local set_session = n.set_session
  28. local write_file = t.write_file
  29. local eval = n.eval
  30. local assert_log = t.assert_log
  31. local testlog = 'Xtest-tui-log'
  32. describe('TUI :detach', function()
  33. before_each(function()
  34. os.remove(testlog)
  35. end)
  36. teardown(function()
  37. os.remove(testlog)
  38. end)
  39. it('does not stop server', function()
  40. local job_opts = {
  41. env = {
  42. NVIM_LOG_FILE = testlog,
  43. },
  44. }
  45. if is_os('win') then
  46. -- TODO(justinmk): on Windows,
  47. -- - tt.setup_child_nvim() is broken.
  48. -- - session.lua is broken after the pipe closes.
  49. -- So this test currently just exercises __NVIM_DETACH + :detach, without asserting anything.
  50. -- TODO(justinmk): temporary hack for Windows.
  51. job_opts.env['__NVIM_DETACH'] = '1'
  52. n.clear(job_opts)
  53. local screen = Screen.new(50, 10)
  54. n.feed('iHello, World')
  55. screen:expect([[
  56. Hello, World^ |
  57. {1:~ }|*8
  58. {5:-- INSERT --} |
  59. ]])
  60. -- local addr = api.nvim_get_vvar('servername')
  61. eq(1, #n.api.nvim_list_uis())
  62. -- TODO(justinmk): test util should not freak out when the pipe closes.
  63. n.expect_exit(n.command, 'detach')
  64. -- n.get_session():close() -- XXX: hangs
  65. -- n.set_session(n.connect(addr)) -- XXX: hangs
  66. -- eq(0, #n.api.nvim_list_uis()) -- XXX: hangs
  67. -- Avoid a dangling process.
  68. n.get_session():close('kill')
  69. -- n.expect_exit(n.command, 'qall!')
  70. return
  71. end
  72. local server_super = n.clear()
  73. local client_super = n.new_session(true)
  74. finally(function()
  75. server_super:close()
  76. client_super:close()
  77. end)
  78. local child_server = new_pipename()
  79. local screen = tt.setup_child_nvim({
  80. '--listen',
  81. child_server,
  82. '-u',
  83. 'NONE',
  84. '-i',
  85. 'NONE',
  86. '--cmd',
  87. 'colorscheme vim',
  88. '--cmd',
  89. nvim_set .. ' notermguicolors laststatus=2 background=dark',
  90. }, job_opts)
  91. tt.feed_data('iHello, World')
  92. screen:expect {
  93. grid = [[
  94. Hello, World^ |
  95. {4:~ }|*3
  96. {MATCH:No Name}
  97. {3:-- INSERT --} |
  98. {3:-- TERMINAL --} |
  99. ]],
  100. }
  101. local child_session = n.connect(child_server)
  102. finally(function()
  103. child_session:request('nvim_command', 'qall!')
  104. end)
  105. local status, child_uis = child_session:request('nvim_list_uis')
  106. assert(status)
  107. eq(1, #child_uis)
  108. tt.feed_data('\027\027:detach\013')
  109. -- Note: "Process exited" message is misleading; tt.setup_child_nvim() sees the foreground
  110. -- process (client) exited, and doesn't know the server is still running?
  111. screen:expect {
  112. any = [[Process exited 0]],
  113. }
  114. child_uis --[[@type any[] ]] = ({ child_session:request('nvim_list_uis') })[2]
  115. eq(0, #child_uis)
  116. -- NOTE: The tt.setup_child_nvim() screen just wraps :terminal, it's not connected to the child.
  117. -- To use it again, we need to detach the old one.
  118. screen:detach()
  119. -- Edit some text on the headless server.
  120. status = (child_session:request('nvim_input', 'ddiWe did it, pooky.<Esc><Esc>'))
  121. assert(status)
  122. -- Test reattach by connecting a new TUI.
  123. local screen_reattached = tt.setup_child_nvim({
  124. '--remote-ui',
  125. '--server',
  126. child_server,
  127. }, job_opts)
  128. screen_reattached:expect {
  129. grid = [[
  130. We did it, pooky^. |
  131. {4:~ }|*3
  132. {5:[No Name] [+] }|
  133. |
  134. {3:-- TERMINAL --} |
  135. ]],
  136. }
  137. end)
  138. end)
  139. if t.skip(is_os('win')) then
  140. return
  141. end
  142. describe('TUI', function()
  143. local screen --[[@type test.functional.ui.screen]]
  144. local child_session --[[@type test.Session]]
  145. local child_exec_lua
  146. before_each(function()
  147. clear()
  148. local child_server = new_pipename()
  149. screen = tt.setup_child_nvim({
  150. '--listen',
  151. child_server,
  152. '--clean',
  153. '--cmd',
  154. nvim_set .. ' notermguicolors laststatus=2 background=dark',
  155. '--cmd',
  156. 'colorscheme vim',
  157. })
  158. screen:expect([[
  159. ^ |
  160. {4:~ }|*3
  161. {5:[No Name] }|
  162. |
  163. {3:-- TERMINAL --} |
  164. ]])
  165. child_session = n.connect(child_server)
  166. child_exec_lua = tt.make_lua_executor(child_session)
  167. end)
  168. -- Wait for mode in the child Nvim (avoid "typeahead race" #10826).
  169. local function wait_for_mode(mode)
  170. retry(nil, nil, function()
  171. local _, m = child_session:request('nvim_get_mode')
  172. eq(mode, m.mode)
  173. end)
  174. end
  175. -- Assert buffer contents in the child Nvim.
  176. local function expect_child_buf_lines(expected)
  177. assert(type({}) == type(expected))
  178. retry(nil, nil, function()
  179. local _, buflines = child_session:request('nvim_buf_get_lines', 0, 0, -1, false)
  180. eq(expected, buflines)
  181. end)
  182. end
  183. -- Ensure both child client and child server have processed pending events.
  184. local function poke_both_eventloop()
  185. child_exec_lua([[
  186. _G.termresponse = nil
  187. vim.api.nvim_create_autocmd('TermResponse', {
  188. once = true,
  189. callback = function(ev) _G.termresponse = ev.data.sequence end,
  190. })
  191. ]])
  192. feed_data('\027P0$r\027\\')
  193. retry(nil, nil, function()
  194. eq('\027P0$r', child_exec_lua('return _G.termresponse'))
  195. end)
  196. end
  197. it('rapid resize #7572 #7628', function()
  198. -- Need buffer rows to provoke the behavior.
  199. feed_data(':edit test/functional/fixtures/bigfile.txt\n')
  200. screen:expect([[
  201. ^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; |
  202. 0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; |
  203. 0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
  204. 0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
  205. {5:test/functional/fixtures/bigfile.txt }|
  206. :edit test/functional/fixtures/bigfile.txt |
  207. {3:-- TERMINAL --} |
  208. ]])
  209. command('call jobresize(b:terminal_job_id, 58, 9)')
  210. command('call jobresize(b:terminal_job_id, 62, 13)')
  211. command('call jobresize(b:terminal_job_id, 100, 42)')
  212. command('call jobresize(b:terminal_job_id, 37, 1000)')
  213. -- Resize to <5 columns.
  214. screen:try_resize(4, 44)
  215. command('call jobresize(b:terminal_job_id, 4, 1000)')
  216. -- Resize to 1 row, then to 1 column, then increase rows to 4.
  217. screen:try_resize(44, 1)
  218. command('call jobresize(b:terminal_job_id, 44, 1)')
  219. screen:try_resize(1, 1)
  220. command('call jobresize(b:terminal_job_id, 1, 1)')
  221. screen:try_resize(1, 4)
  222. command('call jobresize(b:terminal_job_id, 1, 4)')
  223. screen:try_resize(57, 17)
  224. command('call jobresize(b:terminal_job_id, 57, 17)')
  225. retry(nil, nil, function()
  226. eq({ true, 57 }, { child_session:request('nvim_win_get_width', 0) })
  227. end)
  228. end)
  229. it('accepts resize while pager is active', function()
  230. child_session:request(
  231. 'nvim_exec2',
  232. [[
  233. set more
  234. func! ManyErr()
  235. for i in range(20)
  236. echoerr "FAIL ".i
  237. endfor
  238. endfunc
  239. ]],
  240. {}
  241. )
  242. feed_data(':call ManyErr()\r')
  243. screen:expect([[
  244. {8:Error in function ManyErr:} |
  245. {11:line 2:} |
  246. {8:FAIL 0} |
  247. {8:FAIL 1} |
  248. {8:FAIL 2} |
  249. {10:-- More --}^ |
  250. {3:-- TERMINAL --} |
  251. ]])
  252. screen:try_resize(50, 10)
  253. screen:expect {
  254. grid = [[
  255. :call ManyErr() |
  256. {8:Error in function ManyErr:} |
  257. {11:line 2:} |
  258. {8:FAIL 0} |
  259. {8:FAIL 1} |
  260. {8:FAIL 2} |
  261. |*2
  262. {10:-- More --}^ |
  263. {3:-- TERMINAL --} |
  264. ]],
  265. }
  266. feed_data('j')
  267. screen:expect {
  268. grid = [[
  269. {8:Error in function ManyErr:} |
  270. {11:line 2:} |
  271. {8:FAIL 0} |
  272. {8:FAIL 1} |
  273. {8:FAIL 2} |
  274. {8:FAIL 3} |
  275. {8:FAIL 4} |
  276. {8:FAIL 5} |
  277. {10:-- More --}^ |
  278. {3:-- TERMINAL --} |
  279. ]],
  280. }
  281. screen:try_resize(50, 7)
  282. screen:expect {
  283. grid = [[
  284. {8:FAIL 1} |
  285. {8:FAIL 2} |
  286. {8:FAIL 3} |
  287. {8:FAIL 4} |
  288. {8:FAIL 5} |
  289. {10:-- More --}^ |
  290. {3:-- TERMINAL --} |
  291. ]],
  292. }
  293. screen:try_resize(50, 5)
  294. screen:expect {
  295. grid = [[
  296. {8:FAIL 3} |
  297. {8:FAIL 4} |
  298. {8:FAIL 5} |
  299. {10:-- More --}^ |
  300. {3:-- TERMINAL --} |
  301. ]],
  302. }
  303. feed_data('g')
  304. screen:expect {
  305. grid = [[
  306. :call ManyErr() |
  307. {8:Error in function ManyErr:} |
  308. {11:line 2:} |
  309. {10:-- More --}^ |
  310. {3:-- TERMINAL --} |
  311. ]],
  312. }
  313. screen:try_resize(50, 10)
  314. screen:expect {
  315. grid = [[
  316. :call ManyErr() |
  317. {8:Error in function ManyErr:} |
  318. {11:line 2:} |
  319. {8:FAIL 0} |
  320. {8:FAIL 1} |
  321. {8:FAIL 2} |
  322. {8:FAIL 3} |
  323. {8:FAIL 4} |
  324. {10:-- More --}^ |
  325. {3:-- TERMINAL --} |
  326. ]],
  327. }
  328. feed_data('\003')
  329. screen:expect {
  330. grid = [[
  331. ^ |
  332. {4:~ }|*6
  333. {5:[No Name] }|
  334. |
  335. {3:-- TERMINAL --} |
  336. ]],
  337. }
  338. end)
  339. it('accepts basic utf-8 input', function()
  340. feed_data('iabc\ntest1\ntest2')
  341. screen:expect([[
  342. abc |
  343. test1 |
  344. test2^ |
  345. {4:~ }|
  346. {5:[No Name] [+] }|
  347. {3:-- INSERT --} |
  348. {3:-- TERMINAL --} |
  349. ]])
  350. feed_data('\027')
  351. screen:expect([[
  352. abc |
  353. test1 |
  354. test^2 |
  355. {4:~ }|
  356. {5:[No Name] [+] }|
  357. |
  358. {3:-- TERMINAL --} |
  359. ]])
  360. end)
  361. it('interprets leading <Esc> byte as ALT modifier in normal-mode', function()
  362. local keys = 'dfghjkl'
  363. for c in keys:gmatch('.') do
  364. feed_data(':nnoremap <a-' .. c .. '> ialt-' .. c .. '<cr><esc>\r')
  365. feed_data('\027' .. c)
  366. end
  367. screen:expect([[
  368. alt-j |
  369. alt-k |
  370. alt-l |
  371. ^ |
  372. {5:[No Name] [+] }|
  373. |
  374. {3:-- TERMINAL --} |
  375. ]])
  376. feed_data('gg')
  377. screen:expect([[
  378. ^alt-d |
  379. alt-f |
  380. alt-g |
  381. alt-h |
  382. {5:[No Name] [+] }|
  383. |
  384. {3:-- TERMINAL --} |
  385. ]])
  386. end)
  387. it('interprets ESC+key as ALT chord in i_CTRL-V', function()
  388. -- Vim represents ALT/META by setting the "high bit" of the modified key:
  389. -- ALT+j inserts "ê". Nvim does not (#3982).
  390. feed_data('i\022\027j')
  391. screen:expect([[
  392. <M-j>^ |
  393. {4:~ }|*3
  394. {5:[No Name] [+] }|
  395. {3:-- INSERT --} |
  396. {3:-- TERMINAL --} |
  397. ]])
  398. end)
  399. it('interprets <Esc> encoded with kitty keyboard protocol', function()
  400. child_session:request(
  401. 'nvim_exec2',
  402. [[
  403. nnoremap <M-;> <Nop>
  404. nnoremap <Esc> AESC<Esc>
  405. nnoremap <C-Esc> ACtrlEsc<Esc>
  406. nnoremap <D-Esc> ASuperEsc<Esc>
  407. nnoremap ; Asemicolon<Esc>
  408. ]],
  409. {}
  410. )
  411. -- Works with no modifier
  412. feed_data('\027[27u;')
  413. expect_child_buf_lines({ 'ESCsemicolon' })
  414. -- Works with Ctrl modifier
  415. feed_data('\027[27;5u')
  416. expect_child_buf_lines({ 'ESCsemicolonCtrlEsc' })
  417. -- Works with Super modifier
  418. feed_data('\027[27;9u')
  419. expect_child_buf_lines({ 'ESCsemicolonCtrlEscSuperEsc' })
  420. -- Works with NumLock modifier (which should be the same as no modifier) #33799
  421. feed_data('\027[27;129u')
  422. expect_child_buf_lines({ 'ESCsemicolonCtrlEscSuperEscESC' })
  423. screen:expect([[
  424. ESCsemicolonCtrlEscSuperEscES^C |
  425. {4:~ }|*3
  426. {5:[No Name] [+] }|
  427. |
  428. {3:-- TERMINAL --} |
  429. ]])
  430. -- <Esc>; should be recognized as <M-;> when <M-;> is mapped
  431. feed_data('\027;')
  432. screen:expect_unchanged()
  433. expect_child_buf_lines({ 'ESCsemicolonCtrlEscSuperEscESC' })
  434. end)
  435. it('interprets <Esc><Nul> as <M-C-Space> #17198', function()
  436. feed_data('i\022\027\000')
  437. screen:expect([[
  438. <M-C-Space>^ |
  439. {4:~ }|*3
  440. {5:[No Name] [+] }|
  441. {3:-- INSERT --} |
  442. {3:-- TERMINAL --} |
  443. ]])
  444. end)
  445. it('accepts ASCII control sequences', function()
  446. feed_data('i')
  447. feed_data('\022\007') -- ctrl+g
  448. feed_data('\022\022') -- ctrl+v
  449. feed_data('\022\013') -- ctrl+m
  450. screen:expect([[
  451. {6:^G^V^M}^ |
  452. {4:~ }|*3
  453. {5:[No Name] [+] }|
  454. {3:-- INSERT --} |
  455. {3:-- TERMINAL --} |
  456. ]])
  457. child_session:request('nvim_set_keymap', 'i', '\031', '!!!', {})
  458. feed_data('\031')
  459. screen:expect([[
  460. {6:^G^V^M}!!!^ |
  461. {4:~ }|*3
  462. {5:[No Name] [+] }|
  463. {3:-- INSERT --} |
  464. {3:-- TERMINAL --} |
  465. ]])
  466. child_session:request('nvim_buf_delete', 0, { force = true })
  467. child_session:request('nvim_set_option_value', 'laststatus', 0, {})
  468. child_session:request(
  469. 'nvim_call_function',
  470. 'jobstart',
  471. { { testprg('shell-test'), 'INTERACT' }, { term = true } }
  472. )
  473. screen:expect([[
  474. interact $ ^ |
  475. |*4
  476. {3:-- TERMINAL --} |*2
  477. ]])
  478. -- mappings for C0 control codes should work in Terminal mode #33750
  479. child_session:request('nvim_set_keymap', 't', '\031', '<Cmd>new<CR>', {})
  480. feed_data('\031')
  481. screen:expect([[
  482. ^ |
  483. {4:~ }|
  484. {5:[No Name] }|
  485. interact $ |
  486. |*2
  487. {3:-- TERMINAL --} |
  488. ]])
  489. end)
  490. local function test_mouse_wheel(esc)
  491. child_session:request(
  492. 'nvim_exec2',
  493. [[
  494. set number nostartofline nowrap mousescroll=hor:1,ver:1
  495. call setline(1, repeat([join(range(10), '----')], 10))
  496. vsplit
  497. ]],
  498. {}
  499. )
  500. screen:expect([[
  501. {11: 1 }^0----1----2----3----4│{11: 1 }0----1----2----3----|
  502. {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
  503. {11: 3 }0----1----2----3----4│{11: 3 }0----1----2----3----|
  504. {11: 4 }0----1----2----3----4│{11: 4 }0----1----2----3----|
  505. {5:[No Name] [+] }{1:[No Name] [+] }|
  506. |
  507. {3:-- TERMINAL --} |
  508. ]])
  509. -- <ScrollWheelDown> in active window
  510. if esc then
  511. feed_data('\027[<65;8;1M')
  512. else
  513. api.nvim_input_mouse('wheel', 'down', '', 0, 0, 7)
  514. end
  515. screen:expect([[
  516. {11: 2 }^0----1----2----3----4│{11: 1 }0----1----2----3----|
  517. {11: 3 }0----1----2----3----4│{11: 2 }0----1----2----3----|
  518. {11: 4 }0----1----2----3----4│{11: 3 }0----1----2----3----|
  519. {11: 5 }0----1----2----3----4│{11: 4 }0----1----2----3----|
  520. {5:[No Name] [+] }{1:[No Name] [+] }|
  521. |
  522. {3:-- TERMINAL --} |
  523. ]])
  524. -- <ScrollWheelDown> in inactive window
  525. if esc then
  526. feed_data('\027[<65;48;1M')
  527. else
  528. api.nvim_input_mouse('wheel', 'down', '', 0, 0, 47)
  529. end
  530. screen:expect([[
  531. {11: 2 }^0----1----2----3----4│{11: 2 }0----1----2----3----|
  532. {11: 3 }0----1----2----3----4│{11: 3 }0----1----2----3----|
  533. {11: 4 }0----1----2----3----4│{11: 4 }0----1----2----3----|
  534. {11: 5 }0----1----2----3----4│{11: 5 }0----1----2----3----|
  535. {5:[No Name] [+] }{1:[No Name] [+] }|
  536. |
  537. {3:-- TERMINAL --} |
  538. ]])
  539. -- <ScrollWheelRight> in active window
  540. if esc then
  541. feed_data('\027[<67;8;1M')
  542. else
  543. api.nvim_input_mouse('wheel', 'right', '', 0, 0, 7)
  544. end
  545. screen:expect([[
  546. {11: 2 }^----1----2----3----4-│{11: 2 }0----1----2----3----|
  547. {11: 3 }----1----2----3----4-│{11: 3 }0----1----2----3----|
  548. {11: 4 }----1----2----3----4-│{11: 4 }0----1----2----3----|
  549. {11: 5 }----1----2----3----4-│{11: 5 }0----1----2----3----|
  550. {5:[No Name] [+] }{1:[No Name] [+] }|
  551. |
  552. {3:-- TERMINAL --} |
  553. ]])
  554. -- <ScrollWheelRight> in inactive window
  555. if esc then
  556. feed_data('\027[<67;48;1M')
  557. else
  558. api.nvim_input_mouse('wheel', 'right', '', 0, 0, 47)
  559. end
  560. screen:expect([[
  561. {11: 2 }^----1----2----3----4-│{11: 2 }----1----2----3----4|
  562. {11: 3 }----1----2----3----4-│{11: 3 }----1----2----3----4|
  563. {11: 4 }----1----2----3----4-│{11: 4 }----1----2----3----4|
  564. {11: 5 }----1----2----3----4-│{11: 5 }----1----2----3----4|
  565. {5:[No Name] [+] }{1:[No Name] [+] }|
  566. |
  567. {3:-- TERMINAL --} |
  568. ]])
  569. -- <S-ScrollWheelDown> in active window
  570. if esc then
  571. feed_data('\027[<69;8;1M')
  572. else
  573. api.nvim_input_mouse('wheel', 'down', 'S', 0, 0, 7)
  574. end
  575. screen:expect([[
  576. {11: 5 }^----1----2----3----4-│{11: 2 }----1----2----3----4|
  577. {11: 6 }----1----2----3----4-│{11: 3 }----1----2----3----4|
  578. {11: 7 }----1----2----3----4-│{11: 4 }----1----2----3----4|
  579. {11: 8 }----1----2----3----4-│{11: 5 }----1----2----3----4|
  580. {5:[No Name] [+] }{1:[No Name] [+] }|
  581. |
  582. {3:-- TERMINAL --} |
  583. ]])
  584. -- <S-ScrollWheelDown> in inactive window
  585. if esc then
  586. feed_data('\027[<69;48;1M')
  587. else
  588. api.nvim_input_mouse('wheel', 'down', 'S', 0, 0, 47)
  589. end
  590. screen:expect([[
  591. {11: 5 }^----1----2----3----4-│{11: 5 }----1----2----3----4|
  592. {11: 6 }----1----2----3----4-│{11: 6 }----1----2----3----4|
  593. {11: 7 }----1----2----3----4-│{11: 7 }----1----2----3----4|
  594. {11: 8 }----1----2----3----4-│{11: 8 }----1----2----3----4|
  595. {5:[No Name] [+] }{1:[No Name] [+] }|
  596. |
  597. {3:-- TERMINAL --} |
  598. ]])
  599. -- <S-ScrollWheelRight> in active window
  600. if esc then
  601. feed_data('\027[<71;8;1M')
  602. else
  603. api.nvim_input_mouse('wheel', 'right', 'S', 0, 0, 7)
  604. end
  605. screen:expect([[
  606. {11: 5 }^----6----7----8----9 │{11: 5 }----1----2----3----4|
  607. {11: 6 }----6----7----8----9 │{11: 6 }----1----2----3----4|
  608. {11: 7 }----6----7----8----9 │{11: 7 }----1----2----3----4|
  609. {11: 8 }----6----7----8----9 │{11: 8 }----1----2----3----4|
  610. {5:[No Name] [+] }{1:[No Name] [+] }|
  611. |
  612. {3:-- TERMINAL --} |
  613. ]])
  614. -- <S-ScrollWheelRight> in inactive window
  615. if esc then
  616. feed_data('\027[<71;48;1M')
  617. else
  618. api.nvim_input_mouse('wheel', 'right', 'S', 0, 0, 47)
  619. end
  620. screen:expect([[
  621. {11: 5 }^----6----7----8----9 │{11: 5 }5----6----7----8----|
  622. {11: 6 }----6----7----8----9 │{11: 6 }5----6----7----8----|
  623. {11: 7 }----6----7----8----9 │{11: 7 }5----6----7----8----|
  624. {11: 8 }----6----7----8----9 │{11: 8 }5----6----7----8----|
  625. {5:[No Name] [+] }{1:[No Name] [+] }|
  626. |
  627. {3:-- TERMINAL --} |
  628. ]])
  629. -- <ScrollWheelUp> in active window
  630. if esc then
  631. feed_data('\027[<64;8;1M')
  632. else
  633. api.nvim_input_mouse('wheel', 'up', '', 0, 0, 7)
  634. end
  635. screen:expect([[
  636. {11: 4 }----6----7----8----9 │{11: 5 }5----6----7----8----|
  637. {11: 5 }^----6----7----8----9 │{11: 6 }5----6----7----8----|
  638. {11: 6 }----6----7----8----9 │{11: 7 }5----6----7----8----|
  639. {11: 7 }----6----7----8----9 │{11: 8 }5----6----7----8----|
  640. {5:[No Name] [+] }{1:[No Name] [+] }|
  641. |
  642. {3:-- TERMINAL --} |
  643. ]])
  644. -- <ScrollWheelUp> in inactive window
  645. if esc then
  646. feed_data('\027[<64;48;1M')
  647. else
  648. api.nvim_input_mouse('wheel', 'up', '', 0, 0, 47)
  649. end
  650. screen:expect([[
  651. {11: 4 }----6----7----8----9 │{11: 4 }5----6----7----8----|
  652. {11: 5 }^----6----7----8----9 │{11: 5 }5----6----7----8----|
  653. {11: 6 }----6----7----8----9 │{11: 6 }5----6----7----8----|
  654. {11: 7 }----6----7----8----9 │{11: 7 }5----6----7----8----|
  655. {5:[No Name] [+] }{1:[No Name] [+] }|
  656. |
  657. {3:-- TERMINAL --} |
  658. ]])
  659. -- <ScrollWheelLeft> in active window
  660. if esc then
  661. feed_data('\027[<66;8;1M')
  662. else
  663. api.nvim_input_mouse('wheel', 'left', '', 0, 0, 7)
  664. end
  665. screen:expect([[
  666. {11: 4 }5----6----7----8----9│{11: 4 }5----6----7----8----|
  667. {11: 5 }5^----6----7----8----9│{11: 5 }5----6----7----8----|
  668. {11: 6 }5----6----7----8----9│{11: 6 }5----6----7----8----|
  669. {11: 7 }5----6----7----8----9│{11: 7 }5----6----7----8----|
  670. {5:[No Name] [+] }{1:[No Name] [+] }|
  671. |
  672. {3:-- TERMINAL --} |
  673. ]])
  674. -- <ScrollWheelLeft> in inactive window
  675. if esc then
  676. feed_data('\027[<66;48;1M')
  677. else
  678. api.nvim_input_mouse('wheel', 'left', '', 0, 0, 47)
  679. end
  680. screen:expect([[
  681. {11: 4 }5----6----7----8----9│{11: 4 }-5----6----7----8---|
  682. {11: 5 }5^----6----7----8----9│{11: 5 }-5----6----7----8---|
  683. {11: 6 }5----6----7----8----9│{11: 6 }-5----6----7----8---|
  684. {11: 7 }5----6----7----8----9│{11: 7 }-5----6----7----8---|
  685. {5:[No Name] [+] }{1:[No Name] [+] }|
  686. |
  687. {3:-- TERMINAL --} |
  688. ]])
  689. -- <S-ScrollWheelUp> in active window
  690. if esc then
  691. feed_data('\027[<68;8;1M')
  692. else
  693. api.nvim_input_mouse('wheel', 'up', 'S', 0, 0, 7)
  694. end
  695. screen:expect([[
  696. {11: 1 }5----6----7----8----9│{11: 4 }-5----6----7----8---|
  697. {11: 2 }5----6----7----8----9│{11: 5 }-5----6----7----8---|
  698. {11: 3 }5----6----7----8----9│{11: 6 }-5----6----7----8---|
  699. {11: 4 }5^----6----7----8----9│{11: 7 }-5----6----7----8---|
  700. {5:[No Name] [+] }{1:[No Name] [+] }|
  701. |
  702. {3:-- TERMINAL --} |
  703. ]])
  704. -- <S-ScrollWheelUp> in inactive window
  705. if esc then
  706. feed_data('\027[<68;48;1M')
  707. else
  708. api.nvim_input_mouse('wheel', 'up', 'S', 0, 0, 47)
  709. end
  710. screen:expect([[
  711. {11: 1 }5----6----7----8----9│{11: 1 }-5----6----7----8---|
  712. {11: 2 }5----6----7----8----9│{11: 2 }-5----6----7----8---|
  713. {11: 3 }5----6----7----8----9│{11: 3 }-5----6----7----8---|
  714. {11: 4 }5^----6----7----8----9│{11: 4 }-5----6----7----8---|
  715. {5:[No Name] [+] }{1:[No Name] [+] }|
  716. |
  717. {3:-- TERMINAL --} |
  718. ]])
  719. -- <S-ScrollWheelLeft> in active window
  720. if esc then
  721. feed_data('\027[<70;8;1M')
  722. else
  723. api.nvim_input_mouse('wheel', 'left', 'S', 0, 0, 7)
  724. end
  725. screen:expect([[
  726. {11: 1 }0----1----2----3----4│{11: 1 }-5----6----7----8---|
  727. {11: 2 }0----1----2----3----4│{11: 2 }-5----6----7----8---|
  728. {11: 3 }0----1----2----3----4│{11: 3 }-5----6----7----8---|
  729. {11: 4 }0----1----2----3----^4│{11: 4 }-5----6----7----8---|
  730. {5:[No Name] [+] }{1:[No Name] [+] }|
  731. |
  732. {3:-- TERMINAL --} |
  733. ]])
  734. -- <S-ScrollWheelLeft> in inactive window
  735. if esc then
  736. feed_data('\027[<70;48;1M')
  737. else
  738. api.nvim_input_mouse('wheel', 'left', 'S', 0, 0, 47)
  739. end
  740. screen:expect([[
  741. {11: 1 }0----1----2----3----4│{11: 1 }0----1----2----3----|
  742. {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
  743. {11: 3 }0----1----2----3----4│{11: 3 }0----1----2----3----|
  744. {11: 4 }0----1----2----3----^4│{11: 4 }0----1----2----3----|
  745. {5:[No Name] [+] }{1:[No Name] [+] }|
  746. |
  747. {3:-- TERMINAL --} |
  748. ]])
  749. end
  750. describe('accepts mouse wheel events', function()
  751. it('(mouse events sent to host)', function()
  752. test_mouse_wheel(false)
  753. end)
  754. it('(escape sequences sent to child)', function()
  755. test_mouse_wheel(true)
  756. end)
  757. end)
  758. local function test_mouse_popup(esc)
  759. child_session:request(
  760. 'nvim_exec2',
  761. [[
  762. call setline(1, 'popup menu test')
  763. set mouse=a mousemodel=popup
  764. aunmenu PopUp
  765. " Delete the default MenuPopup event handler.
  766. autocmd! nvim.popupmenu
  767. menu PopUp.foo :let g:menustr = 'foo'<CR>
  768. menu PopUp.bar :let g:menustr = 'bar'<CR>
  769. menu PopUp.baz :let g:menustr = 'baz'<CR>
  770. highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
  771. highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
  772. ]],
  773. {}
  774. )
  775. if esc then
  776. feed_data('\027[<2;5;1M')
  777. else
  778. api.nvim_input_mouse('right', 'press', '', 0, 0, 4)
  779. end
  780. screen:expect([[
  781. ^popup menu test |
  782. {4:~ }{13: foo }{4: }|
  783. {4:~ }{13: bar }{4: }|
  784. {4:~ }{13: baz }{4: }|
  785. {5:[No Name] [+] }|
  786. |
  787. {3:-- TERMINAL --} |
  788. ]])
  789. if esc then
  790. feed_data('\027[<2;5;1m')
  791. else
  792. api.nvim_input_mouse('right', 'release', '', 0, 0, 4)
  793. end
  794. screen:expect_unchanged()
  795. if esc then
  796. feed_data('\027[<64;5;1M')
  797. else
  798. api.nvim_input_mouse('wheel', 'up', '', 0, 0, 4)
  799. end
  800. screen:expect([[
  801. ^popup menu test |
  802. {4:~ }{14: foo }{4: }|
  803. {4:~ }{13: bar }{4: }|
  804. {4:~ }{13: baz }{4: }|
  805. {5:[No Name] [+] }|
  806. |
  807. {3:-- TERMINAL --} |
  808. ]])
  809. if esc then
  810. feed_data('\027[<35;7;4M')
  811. else
  812. api.nvim_input_mouse('move', '', '', 0, 3, 6)
  813. end
  814. screen:expect([[
  815. ^popup menu test |
  816. {4:~ }{13: foo }{4: }|
  817. {4:~ }{13: bar }{4: }|
  818. {4:~ }{14: baz }{4: }|
  819. {5:[No Name] [+] }|
  820. |
  821. {3:-- TERMINAL --} |
  822. ]])
  823. if esc then
  824. feed_data('\027[<65;7;4M')
  825. else
  826. api.nvim_input_mouse('wheel', 'down', '', 0, 3, 6)
  827. end
  828. screen:expect([[
  829. ^popup menu test |
  830. {4:~ }{13: foo }{4: }|
  831. {4:~ }{14: bar }{4: }|
  832. {4:~ }{13: baz }{4: }|
  833. {5:[No Name] [+] }|
  834. |
  835. {3:-- TERMINAL --} |
  836. ]])
  837. if esc then
  838. feed_data('\027[<0;7;3M')
  839. else
  840. api.nvim_input_mouse('left', 'press', '', 0, 2, 6)
  841. end
  842. screen:expect([[
  843. ^popup menu test |
  844. {4:~ }|*3
  845. {5:[No Name] [+] }|
  846. :let g:menustr = 'bar' |
  847. {3:-- TERMINAL --} |
  848. ]])
  849. if esc then
  850. feed_data('\027[<0;7;3m')
  851. else
  852. api.nvim_input_mouse('left', 'release', '', 0, 2, 6)
  853. end
  854. screen:expect_unchanged()
  855. if esc then
  856. feed_data('\027[<2;45;3M')
  857. else
  858. api.nvim_input_mouse('right', 'press', '', 0, 2, 44)
  859. end
  860. screen:expect([[
  861. ^popup menu test |
  862. {4:~ }|*2
  863. {4:~ }{13: foo }{4: }|
  864. {5:[No Name] [+] }{13: bar }{5: }|
  865. :let g:menustr = 'bar' {13: baz } |
  866. {3:-- TERMINAL --} |
  867. ]])
  868. if esc then
  869. feed_data('\027[<34;48;6M')
  870. else
  871. api.nvim_input_mouse('right', 'drag', '', 0, 5, 47)
  872. end
  873. screen:expect([[
  874. ^popup menu test |
  875. {4:~ }|*2
  876. {4:~ }{13: foo }{4: }|
  877. {5:[No Name] [+] }{13: bar }{5: }|
  878. :let g:menustr = 'bar' {14: baz } |
  879. {3:-- TERMINAL --} |
  880. ]])
  881. if esc then
  882. feed_data('\027[<2;48;6m')
  883. else
  884. api.nvim_input_mouse('right', 'release', '', 0, 5, 47)
  885. end
  886. screen:expect([[
  887. ^popup menu test |
  888. {4:~ }|*3
  889. {5:[No Name] [+] }|
  890. :let g:menustr = 'baz' |
  891. {3:-- TERMINAL --} |
  892. ]])
  893. end
  894. describe('mouse events work with right-click menu', function()
  895. it('(mouse events sent to host)', function()
  896. test_mouse_popup(false)
  897. end)
  898. it('(escape sequences sent to child)', function()
  899. test_mouse_popup(true)
  900. end)
  901. end)
  902. it('accepts keypad keys from kitty keyboard protocol #19180', function()
  903. feed_data('i')
  904. feed_data(fn.nr2char(57399)) -- KP_0
  905. feed_data(fn.nr2char(57400)) -- KP_1
  906. feed_data(fn.nr2char(57401)) -- KP_2
  907. feed_data(fn.nr2char(57402)) -- KP_3
  908. feed_data(fn.nr2char(57403)) -- KP_4
  909. feed_data(fn.nr2char(57404)) -- KP_5
  910. feed_data(fn.nr2char(57405)) -- KP_6
  911. feed_data(fn.nr2char(57406)) -- KP_7
  912. feed_data(fn.nr2char(57407)) -- KP_8
  913. feed_data(fn.nr2char(57408)) -- KP_9
  914. feed_data(fn.nr2char(57409)) -- KP_DECIMAL
  915. feed_data(fn.nr2char(57410)) -- KP_DIVIDE
  916. feed_data(fn.nr2char(57411)) -- KP_MULTIPLY
  917. feed_data(fn.nr2char(57412)) -- KP_SUBTRACT
  918. feed_data(fn.nr2char(57413)) -- KP_ADD
  919. feed_data(fn.nr2char(57414)) -- KP_ENTER
  920. feed_data(fn.nr2char(57415)) -- KP_EQUAL
  921. screen:expect([[
  922. 0123456789./*-+ |
  923. =^ |
  924. {4:~ }|*2
  925. {5:[No Name] [+] }|
  926. {3:-- INSERT --} |
  927. {3:-- TERMINAL --} |
  928. ]])
  929. feed_data(fn.nr2char(57417)) -- KP_LEFT
  930. screen:expect([[
  931. 0123456789./*-+ |
  932. ^= |
  933. {4:~ }|*2
  934. {5:[No Name] [+] }|
  935. {3:-- INSERT --} |
  936. {3:-- TERMINAL --} |
  937. ]])
  938. feed_data(fn.nr2char(57418)) -- KP_RIGHT
  939. screen:expect([[
  940. 0123456789./*-+ |
  941. =^ |
  942. {4:~ }|*2
  943. {5:[No Name] [+] }|
  944. {3:-- INSERT --} |
  945. {3:-- TERMINAL --} |
  946. ]])
  947. feed_data(fn.nr2char(57419)) -- KP_UP
  948. screen:expect([[
  949. 0^123456789./*-+ |
  950. = |
  951. {4:~ }|*2
  952. {5:[No Name] [+] }|
  953. {3:-- INSERT --} |
  954. {3:-- TERMINAL --} |
  955. ]])
  956. feed_data(fn.nr2char(57420)) -- KP_DOWN
  957. screen:expect([[
  958. 0123456789./*-+ |
  959. =^ |
  960. {4:~ }|*2
  961. {5:[No Name] [+] }|
  962. {3:-- INSERT --} |
  963. {3:-- TERMINAL --} |
  964. ]])
  965. feed_data(fn.nr2char(57425)) -- KP_INSERT
  966. screen:expect([[
  967. 0123456789./*-+ |
  968. =^ |
  969. {4:~ }|*2
  970. {5:[No Name] [+] }|
  971. {3:-- REPLACE --} |
  972. {3:-- TERMINAL --} |
  973. ]])
  974. feed_data('\027[27u') -- ESC
  975. screen:expect([[
  976. 0123456789./*-+ |
  977. ^= |
  978. {4:~ }|*2
  979. {5:[No Name] [+] }|
  980. |
  981. {3:-- TERMINAL --} |
  982. ]])
  983. feed_data('\027[57417;5u') -- CTRL + KP_LEFT
  984. screen:expect([[
  985. ^0123456789./*-+ |
  986. = |
  987. {4:~ }|*2
  988. {5:[No Name] [+] }|
  989. |
  990. {3:-- TERMINAL --} |
  991. ]])
  992. feed_data('\027[57418;2u') -- SHIFT + KP_RIGHT
  993. screen:expect([[
  994. 0123456789^./*-+ |
  995. = |
  996. {4:~ }|*2
  997. {5:[No Name] [+] }|
  998. |
  999. {3:-- TERMINAL --} |
  1000. ]])
  1001. feed_data(fn.nr2char(57426)) -- KP_DELETE
  1002. screen:expect([[
  1003. 0123456789^/*-+ |
  1004. = |
  1005. {4:~ }|*2
  1006. {5:[No Name] [+] }|
  1007. |
  1008. {3:-- TERMINAL --} |
  1009. ]])
  1010. feed_data(fn.nr2char(57423)) -- KP_HOME
  1011. screen:expect([[
  1012. ^0123456789/*-+ |
  1013. = |
  1014. {4:~ }|*2
  1015. {5:[No Name] [+] }|
  1016. |
  1017. {3:-- TERMINAL --} |
  1018. ]])
  1019. feed_data(fn.nr2char(57424)) -- KP_END
  1020. screen:expect([[
  1021. 0123456789/*-^+ |
  1022. = |
  1023. {4:~ }|*2
  1024. {5:[No Name] [+] }|
  1025. |
  1026. {3:-- TERMINAL --} |
  1027. ]])
  1028. child_session:request(
  1029. 'nvim_exec2',
  1030. [[
  1031. tab split
  1032. tabnew
  1033. highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline
  1034. ]],
  1035. {}
  1036. )
  1037. screen:expect([[
  1038. {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}|
  1039. ^ |
  1040. {4:~ }|*2
  1041. {5:[No Name] }|
  1042. |
  1043. {3:-- TERMINAL --} |
  1044. ]])
  1045. feed_data('\027[57421;5u') -- CTRL + KP_PAGE_UP
  1046. screen:expect([[
  1047. {12: + [No Name] }{3: + [No Name] }{12: [No Name] }{1: }{12:X}|
  1048. 0123456789/*-^+ |
  1049. = |
  1050. {4:~ }|
  1051. {5:[No Name] [+] }|
  1052. |
  1053. {3:-- TERMINAL --} |
  1054. ]])
  1055. feed_data('\027[57422;5u') -- CTRL + KP_PAGE_DOWN
  1056. screen:expect([[
  1057. {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}|
  1058. ^ |
  1059. {4:~ }|*2
  1060. {5:[No Name] }|
  1061. |
  1062. {3:-- TERMINAL --} |
  1063. ]])
  1064. end)
  1065. it('supports Super and Meta modifiers', function()
  1066. feed_data('i')
  1067. feed_data('\022\027[106;9u') -- Super + j
  1068. feed_data('\022\027[107;33u') -- Meta + k
  1069. feed_data('\022\027[13;41u') -- Super + Meta + Enter
  1070. feed_data('\022\027[127;48u') -- Shift + Alt + Ctrl + Super + Meta + Backspace
  1071. feed_data('\n')
  1072. feed_data('\022\027[57376;9u') -- Super + F13
  1073. feed_data('\022\027[57377;33u') -- Meta + F14
  1074. feed_data('\022\027[57378;41u') -- Super + Meta + F15
  1075. feed_data('\022\027[57379;48u') -- Shift + Alt + Ctrl + Super + Meta + F16
  1076. screen:expect([[
  1077. <D-j><T-k><T-D-CR><M-T-C-S-D-BS> |
  1078. <D-F13><T-F14><T-D-F15><M-T-C-S-D-F16>^ |
  1079. {4:~ }|*2
  1080. {5:[No Name] [+] }|
  1081. {3:-- INSERT --} |
  1082. {3:-- TERMINAL --} |
  1083. ]])
  1084. end)
  1085. it('paste: Insert mode', function()
  1086. -- "bracketed paste"
  1087. feed_data('i""\027i\027[200~')
  1088. screen:expect([[
  1089. "^" |
  1090. {4:~ }|*3
  1091. {5:[No Name] [+] }|
  1092. {3:-- INSERT --} |
  1093. {3:-- TERMINAL --} |
  1094. ]])
  1095. feed_data('pasted from terminal')
  1096. expect_child_buf_lines({ '"pasted from terminal"' })
  1097. screen:expect([[
  1098. "pasted from terminal^" |
  1099. {4:~ }|*3
  1100. {5:[No Name] [+] }|
  1101. {3:-- INSERT --} |
  1102. {3:-- TERMINAL --} |
  1103. ]])
  1104. feed_data('\027[201~') -- End paste.
  1105. poke_both_eventloop()
  1106. screen:expect_unchanged()
  1107. feed_data('\027[27u') -- ESC: go to Normal mode.
  1108. wait_for_mode('n')
  1109. screen:expect([[
  1110. "pasted from termina^l" |
  1111. {4:~ }|*3
  1112. {5:[No Name] [+] }|
  1113. |
  1114. {3:-- TERMINAL --} |
  1115. ]])
  1116. -- Dot-repeat/redo.
  1117. feed_data('2.')
  1118. expect_child_buf_lines({ '"pasted from terminapasted from terminalpasted from terminall"' })
  1119. screen:expect([[
  1120. "pasted from terminapasted from terminalpasted fro|
  1121. m termina^ll" |
  1122. {4:~ }|*2
  1123. {5:[No Name] [+] }|
  1124. |
  1125. {3:-- TERMINAL --} |
  1126. ]])
  1127. -- Undo.
  1128. feed_data('u')
  1129. expect_child_buf_lines({ '"pasted from terminal"' })
  1130. feed_data('u')
  1131. expect_child_buf_lines({ '""' })
  1132. feed_data('u')
  1133. expect_child_buf_lines({ '' })
  1134. end)
  1135. it('paste: select-mode', function()
  1136. feed_data('ithis is line 1\nthis is line 2\nline 3 is here\n\027')
  1137. wait_for_mode('n')
  1138. screen:expect([[
  1139. this is line 1 |
  1140. this is line 2 |
  1141. line 3 is here |
  1142. ^ |
  1143. {5:[No Name] [+] }|
  1144. |
  1145. {3:-- TERMINAL --} |
  1146. ]])
  1147. -- Select-mode. Use <C-n> to move down.
  1148. feed_data('gg04lgh\14\14')
  1149. screen:expect([[
  1150. this{16: is line 1} |
  1151. {16:this is line 2} |
  1152. {16:line}^ 3 is here |
  1153. |
  1154. {5:[No Name] [+] }|
  1155. {3:-- SELECT --} |
  1156. {3:-- TERMINAL --} |
  1157. ]])
  1158. feed_data('\027[200~')
  1159. feed_data('just paste it™')
  1160. feed_data('\027[201~')
  1161. screen:expect([[
  1162. thisjust paste it^™3 is here |
  1163. |
  1164. {4:~ }|*2
  1165. {5:[No Name] [+] }|
  1166. |
  1167. {3:-- TERMINAL --} |
  1168. ]])
  1169. -- Undo.
  1170. feed_data('u')
  1171. expect_child_buf_lines {
  1172. 'this is line 1',
  1173. 'this is line 2',
  1174. 'line 3 is here',
  1175. '',
  1176. }
  1177. -- Redo.
  1178. feed_data('\18') -- <C-r>
  1179. expect_child_buf_lines {
  1180. 'thisjust paste it™3 is here',
  1181. '',
  1182. }
  1183. end)
  1184. it('paste: terminal mode', function()
  1185. if is_ci('github') then
  1186. pending('tty-test complains about not owning the terminal -- actions/runner#241')
  1187. end
  1188. screen:set_default_attr_ids({
  1189. [3] = { bold = true },
  1190. [19] = { bold = true, background = 121, foreground = 0 }, -- StatusLineTerm
  1191. })
  1192. child_exec_lua('vim.o.statusline="^^^^^^^"')
  1193. child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test'))
  1194. feed_data('i')
  1195. screen:expect([[
  1196. tty ready |
  1197. ^ |
  1198. |*2
  1199. {19:^^^^^^^ }|
  1200. {3:-- TERMINAL --} |*2
  1201. ]])
  1202. feed_data('\027[200~')
  1203. feed_data('hallo')
  1204. feed_data('\027[201~')
  1205. screen:expect([[
  1206. tty ready |
  1207. hallo^ |
  1208. |*2
  1209. {19:^^^^^^^ }|
  1210. {3:-- TERMINAL --} |*2
  1211. ]])
  1212. end)
  1213. it('paste: normal-mode (+CRLF #10872)', function()
  1214. feed_data(':set ruler | echo')
  1215. wait_for_mode('c')
  1216. feed_data('\n')
  1217. wait_for_mode('n')
  1218. local expected_lf = { 'line 1', 'ESC:\027 / CR: \rx' }
  1219. local expected_crlf = { 'line 1', 'ESC:\027 / CR: ', 'x' }
  1220. local expected_grid1 = [[
  1221. line 1 |
  1222. ESC:{6:^[} / CR: |
  1223. ^x |
  1224. {4:~ }|
  1225. {5:[No Name] [+] 3,1 All}|
  1226. |
  1227. {3:-- TERMINAL --} |
  1228. ]]
  1229. -- "bracketed paste"
  1230. feed_data('\027[200~' .. table.concat(expected_lf, '\n') .. '\027[201~')
  1231. screen:expect(expected_grid1)
  1232. -- Dot-repeat/redo.
  1233. feed_data('.')
  1234. local expected_grid2 = [[
  1235. ESC:{6:^[} / CR: |
  1236. xline 1 |
  1237. ESC:{6:^[} / CR: |
  1238. ^x |
  1239. {5:[No Name] [+] 5,1 Bot}|
  1240. |
  1241. {3:-- TERMINAL --} |
  1242. ]]
  1243. screen:expect(expected_grid2)
  1244. -- Undo.
  1245. feed_data('u')
  1246. expect_child_buf_lines(expected_crlf)
  1247. feed_data('u')
  1248. expect_child_buf_lines({ '' })
  1249. feed_data(':echo')
  1250. wait_for_mode('c')
  1251. feed_data('\n')
  1252. wait_for_mode('n')
  1253. -- CRLF input
  1254. feed_data('\027[200~' .. table.concat(expected_lf, '\r\n') .. '\027[201~')
  1255. screen:expect(expected_grid1)
  1256. expect_child_buf_lines(expected_crlf)
  1257. -- Dot-repeat/redo.
  1258. feed_data('.')
  1259. screen:expect(expected_grid2)
  1260. -- Undo.
  1261. feed_data('u')
  1262. expect_child_buf_lines(expected_crlf)
  1263. feed_data('u')
  1264. expect_child_buf_lines({ '' })
  1265. end)
  1266. it('paste: cmdline-mode inserts 1 line', function()
  1267. feed_data('ifoo\n') -- Insert some text (for dot-repeat later).
  1268. feed_data('\027:""') -- Enter Cmdline-mode.
  1269. feed_data('\027[D') -- <Left> to place cursor between quotes.
  1270. wait_for_mode('c')
  1271. screen:expect([[
  1272. foo |
  1273. |
  1274. {4:~ }|*2
  1275. {5:[No Name] [+] }|
  1276. :"^" |
  1277. {3:-- TERMINAL --} |
  1278. ]])
  1279. -- "bracketed paste"
  1280. feed_data('\027[200~line 1\nline 2\n')
  1281. wait_for_mode('c')
  1282. feed_data('line 3\nline 4\n\027[201~')
  1283. poke_both_eventloop()
  1284. wait_for_mode('c')
  1285. screen:expect([[
  1286. foo |
  1287. |
  1288. {4:~ }|*2
  1289. {5:[No Name] [+] }|
  1290. :"line 1^" |
  1291. {3:-- TERMINAL --} |
  1292. ]])
  1293. -- Dot-repeat/redo.
  1294. feed_data('\027[27u')
  1295. wait_for_mode('n')
  1296. feed_data('.')
  1297. screen:expect([[
  1298. foo |*2
  1299. ^ |
  1300. {4:~ }|
  1301. {5:[No Name] [+] }|
  1302. |
  1303. {3:-- TERMINAL --} |
  1304. ]])
  1305. end)
  1306. it('paste: cmdline-mode collects chunks of unfinished line', function()
  1307. local function expect_cmdline(expected)
  1308. retry(nil, nil, function()
  1309. local _, cmdline = child_session:request('nvim_call_function', 'getcmdline', {})
  1310. eq(expected, cmdline)
  1311. local _, pos = child_session:request('nvim_call_function', 'getcmdpos', {})
  1312. eq(#expected, pos) -- Cursor is just before the last char.
  1313. end)
  1314. end
  1315. feed_data('\027:""') -- Enter Cmdline-mode.
  1316. feed_data('\027[D') -- <Left> to place cursor between quotes.
  1317. expect_cmdline('""')
  1318. feed_data('\027[200~stuff 1 ')
  1319. expect_cmdline('"stuff 1 "')
  1320. -- Discards everything after the first line.
  1321. feed_data('more\nstuff 2\nstuff 3\n')
  1322. expect_cmdline('"stuff 1 more"')
  1323. feed_data('stuff 3')
  1324. expect_cmdline('"stuff 1 more"')
  1325. -- End the paste sequence.
  1326. feed_data('\027[201~')
  1327. poke_both_eventloop()
  1328. expect_cmdline('"stuff 1 more"')
  1329. feed_data(' typed')
  1330. expect_cmdline('"stuff 1 more typed"')
  1331. end)
  1332. it('paste: recovers from vim.paste() failure', function()
  1333. child_exec_lua([[
  1334. _G.save_paste_fn = vim.paste
  1335. -- Stack traces for this test are non-deterministic, so disable them
  1336. _G.debug.traceback = function(msg) return msg end
  1337. vim.paste = function(lines, phase) error("fake fail") end
  1338. ]])
  1339. -- Prepare something for dot-repeat/redo.
  1340. feed_data('ifoo\n\027[27u')
  1341. wait_for_mode('n')
  1342. screen:expect([[
  1343. foo |
  1344. ^ |
  1345. {4:~ }|*2
  1346. {5:[No Name] [+] }|
  1347. |
  1348. {3:-- TERMINAL --} |
  1349. ]])
  1350. -- Start pasting...
  1351. feed_data('\027[200~line 1\nline 2\n')
  1352. screen:expect([[
  1353. foo |
  1354. ^ |
  1355. {4:~ }|*2
  1356. {5:[No Name] [+] }|
  1357. {8:paste: Lua: [string "<nvim>"]:4: fake fail} |
  1358. {3:-- TERMINAL --} |
  1359. ]])
  1360. -- Remaining chunks are discarded after vim.paste() failure.
  1361. feed_data('line 3\nline 4\n')
  1362. feed_data('line 5\nline 6\n')
  1363. feed_data('line 7\nline 8\n')
  1364. -- Stop paste.
  1365. feed_data('\027[201~')
  1366. screen:expect_unchanged()
  1367. feed_data('\n') -- <CR> to dismiss hit-enter prompt
  1368. expect_child_buf_lines({ 'foo', '' })
  1369. -- Dot-repeat/redo is not modified by failed paste.
  1370. feed_data('.')
  1371. screen:expect([[
  1372. foo |*2
  1373. ^ |
  1374. {4:~ }|
  1375. {5:[No Name] [+] }|
  1376. |
  1377. {3:-- TERMINAL --} |
  1378. ]])
  1379. -- Editor should still work after failed/drained paste.
  1380. feed_data('ityped input...\027[27u')
  1381. screen:expect([[
  1382. foo |*2
  1383. typed input..^. |
  1384. {4:~ }|
  1385. {5:[No Name] [+] }|
  1386. |
  1387. {3:-- TERMINAL --} |
  1388. ]])
  1389. -- Paste works if vim.paste() succeeds.
  1390. child_exec_lua([[vim.paste = _G.save_paste_fn]])
  1391. feed_data('\027[200~line A\nline B\n\027[201~')
  1392. screen:expect([[
  1393. foo |
  1394. typed input...line A |
  1395. line B |
  1396. ^ |
  1397. {5:[No Name] [+] }|
  1398. |
  1399. {3:-- TERMINAL --} |
  1400. ]])
  1401. end)
  1402. it('paste: vim.paste() cancel (retval=false) #10865', function()
  1403. -- This test only exercises the "cancel" case. Use-case would be "dangling
  1404. -- paste", but that is not implemented yet. #10865
  1405. child_exec_lua([[
  1406. vim.paste = function(lines, phase) return false end
  1407. ]])
  1408. feed_data('\027[200~line A\nline B\n\027[201~')
  1409. expect_child_buf_lines({ '' })
  1410. feed_data('ifoo\n\027[27u')
  1411. expect_child_buf_lines({ 'foo', '' })
  1412. end)
  1413. it('paste: vim.paste() cancel (retval=false) with streaming #30462', function()
  1414. child_exec_lua([[
  1415. vim.paste = (function(overridden)
  1416. return function(lines, phase)
  1417. for i, line in ipairs(lines) do
  1418. if line:find('!') then
  1419. return false
  1420. end
  1421. end
  1422. return overridden(lines, phase)
  1423. end
  1424. end)(vim.paste)
  1425. ]])
  1426. feed_data('A')
  1427. wait_for_mode('i')
  1428. feed_data('\027[200~aaa')
  1429. expect_child_buf_lines({ 'aaa' })
  1430. feed_data('bbb')
  1431. expect_child_buf_lines({ 'aaabbb' })
  1432. feed_data('ccc!') -- This chunk is cancelled.
  1433. expect_child_buf_lines({ 'aaabbb' })
  1434. feed_data('ddd\027[201~') -- This chunk is ignored.
  1435. poke_both_eventloop()
  1436. expect_child_buf_lines({ 'aaabbb' })
  1437. feed_data('\027[27u')
  1438. wait_for_mode('n')
  1439. feed_data('.') -- Dot-repeat only includes chunks actually pasted.
  1440. expect_child_buf_lines({ 'aaabbbaaabbb' })
  1441. feed_data('$\027[200~eee\027[201~') -- A following paste works normally.
  1442. expect_child_buf_lines({ 'aaabbbaaabbbeee' })
  1443. end)
  1444. it("paste: 'nomodifiable' buffer", function()
  1445. child_exec_lua([[
  1446. vim.bo.modifiable = false
  1447. -- Truncate the error message to hide the line number
  1448. _G.debug.traceback = function(msg) return msg:sub(-49) end
  1449. ]])
  1450. feed_data('\027[200~fail 1\nfail 2\n\027[201~')
  1451. screen:expect([[
  1452. |
  1453. {4:~ }|
  1454. {5: }|
  1455. {8:paste: Lua: Vim:E21: Cannot make changes, 'modifia}|
  1456. {8:ble' is off} |
  1457. {10:Press ENTER or type command to continue}^ |
  1458. {3:-- TERMINAL --} |
  1459. ]])
  1460. feed_data('\n') -- <Enter> to dismiss hit-enter prompt
  1461. child_exec_lua('vim.bo.modifiable = true')
  1462. feed_data('\027[200~success 1\nsuccess 2\n\027[201~')
  1463. screen:expect([[
  1464. success 1 |
  1465. success 2 |
  1466. ^ |
  1467. {4:~ }|
  1468. {5:[No Name] [+] }|
  1469. |
  1470. {3:-- TERMINAL --} |
  1471. ]])
  1472. end)
  1473. it('paste: exactly 64 bytes #10311', function()
  1474. local expected = string.rep('z', 64)
  1475. feed_data('i')
  1476. wait_for_mode('i')
  1477. -- "bracketed paste"
  1478. feed_data('\027[200~' .. expected .. '\027[201~')
  1479. expect_child_buf_lines({ expected })
  1480. feed_data(' end')
  1481. expected = expected .. ' end'
  1482. screen:expect([[
  1483. zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz|
  1484. zzzzzzzzzzzzzz end^ |
  1485. {4:~ }|*2
  1486. {5:[No Name] [+] }|
  1487. {3:-- INSERT --} |
  1488. {3:-- TERMINAL --} |
  1489. ]])
  1490. expect_child_buf_lines({ expected })
  1491. end)
  1492. it('paste: less-than sign in cmdline #11088', function()
  1493. local expected = '<'
  1494. feed_data(':')
  1495. wait_for_mode('c')
  1496. -- "bracketed paste"
  1497. feed_data('\027[200~' .. expected .. '\027[201~')
  1498. screen:expect([[
  1499. |
  1500. {4:~ }|*3
  1501. {5:[No Name] }|
  1502. :<^ |
  1503. {3:-- TERMINAL --} |
  1504. ]])
  1505. end)
  1506. it('paste: big burst of input', function()
  1507. feed_data(':set ruler\n')
  1508. local q = {}
  1509. for i = 1, 3000 do
  1510. q[i] = 'item ' .. tostring(i)
  1511. end
  1512. feed_data('i')
  1513. wait_for_mode('i')
  1514. -- "bracketed paste"
  1515. feed_data('\027[200~' .. table.concat(q, '\n') .. '\027[201~')
  1516. expect_child_buf_lines(q)
  1517. feed_data(' end')
  1518. screen:expect([[
  1519. item 2997 |
  1520. item 2998 |
  1521. item 2999 |
  1522. item 3000 end^ |
  1523. {5:[No Name] [+] 3000,14 Bot}|
  1524. {3:-- INSERT --} |
  1525. {3:-- TERMINAL --} |
  1526. ]])
  1527. feed_data('\027[27u') -- ESC: go to Normal mode.
  1528. wait_for_mode('n')
  1529. -- Dot-repeat/redo.
  1530. feed_data('.')
  1531. screen:expect([[
  1532. item 2997 |
  1533. item 2998 |
  1534. item 2999 |
  1535. item 3000 en^dd |
  1536. {5:[No Name] [+] 5999,13 Bot}|
  1537. |
  1538. {3:-- TERMINAL --} |
  1539. ]])
  1540. end)
  1541. it('paste: forwards spurious "start paste" code', function()
  1542. -- If multiple "start paste" sequences are sent without a corresponding
  1543. -- "stop paste" sequence, only the first occurrence should be consumed.
  1544. feed_data('i')
  1545. wait_for_mode('i')
  1546. -- Send the "start paste" sequence.
  1547. feed_data('\027[200~')
  1548. feed_data('\npasted from terminal (1)\n')
  1549. -- Send spurious "start paste" sequence.
  1550. feed_data('\027[200~')
  1551. feed_data('\n')
  1552. -- Send the "stop paste" sequence.
  1553. feed_data('\027[201~')
  1554. screen:expect([[
  1555. |
  1556. pasted from terminal (1) |
  1557. {6:^[}[200~ |
  1558. ^ |
  1559. {5:[No Name] [+] }|
  1560. {3:-- INSERT --} |
  1561. {3:-- TERMINAL --} |
  1562. ]])
  1563. end)
  1564. it('paste: ignores spurious "stop paste" code', function()
  1565. -- If "stop paste" sequence is received without a preceding "start paste"
  1566. -- sequence, it should be ignored.
  1567. feed_data('i')
  1568. wait_for_mode('i')
  1569. -- Send "stop paste" sequence.
  1570. feed_data('\027[201~')
  1571. screen:expect([[
  1572. ^ |
  1573. {4:~ }|*3
  1574. {5:[No Name] }|
  1575. {3:-- INSERT --} |
  1576. {3:-- TERMINAL --} |
  1577. ]])
  1578. end)
  1579. it('paste: split "start paste" code', function()
  1580. feed_data('i')
  1581. wait_for_mode('i')
  1582. -- Send split "start paste" sequence.
  1583. feed_data('\027[2')
  1584. feed_data('00~pasted from terminal\027[201~')
  1585. screen:expect([[
  1586. pasted from terminal^ |
  1587. {4:~ }|*3
  1588. {5:[No Name] [+] }|
  1589. {3:-- INSERT --} |
  1590. {3:-- TERMINAL --} |
  1591. ]])
  1592. end)
  1593. it('paste: split "stop paste" code', function()
  1594. feed_data('i')
  1595. wait_for_mode('i')
  1596. -- Send split "stop paste" sequence.
  1597. feed_data('\027[200~pasted from terminal\027[20')
  1598. feed_data('1~')
  1599. screen:expect([[
  1600. pasted from terminal^ |
  1601. {4:~ }|*3
  1602. {5:[No Name] [+] }|
  1603. {3:-- INSERT --} |
  1604. {3:-- TERMINAL --} |
  1605. ]])
  1606. end)
  1607. it('paste: streamed paste with isolated "stop paste" code', function()
  1608. child_exec_lua([[
  1609. _G.paste_phases = {}
  1610. vim.paste = (function(overridden)
  1611. return function(lines, phase)
  1612. table.insert(_G.paste_phases, phase)
  1613. overridden(lines, phase)
  1614. end
  1615. end)(vim.paste)
  1616. ]])
  1617. feed_data('i')
  1618. wait_for_mode('i')
  1619. feed_data('\027[200~pasted') -- phase 1
  1620. screen:expect([[
  1621. pasted^ |
  1622. {4:~ }|*3
  1623. {5:[No Name] [+] }|
  1624. {3:-- INSERT --} |
  1625. {3:-- TERMINAL --} |
  1626. ]])
  1627. feed_data(' from terminal') -- phase 2
  1628. screen:expect([[
  1629. pasted from terminal^ |
  1630. {4:~ }|*3
  1631. {5:[No Name] [+] }|
  1632. {3:-- INSERT --} |
  1633. {3:-- TERMINAL --} |
  1634. ]])
  1635. -- Send isolated "stop paste" sequence.
  1636. feed_data('\027[201~') -- phase 3
  1637. poke_both_eventloop()
  1638. screen:expect_unchanged()
  1639. local rv = child_exec_lua('return _G.paste_phases')
  1640. -- In rare cases there may be multiple chunks of phase 2 because of timing.
  1641. eq({ 1, 2, 3 }, { rv[1], rv[2], rv[#rv] })
  1642. end)
  1643. it('allows termguicolors to be set at runtime', function()
  1644. screen:set_option('rgb', true)
  1645. screen:set_default_attr_ids({
  1646. [1] = { reverse = true },
  1647. [2] = { foreground = tonumber('0x4040ff'), fg_indexed = true },
  1648. [3] = { bold = true, reverse = true },
  1649. [4] = { bold = true },
  1650. [5] = { reverse = true, foreground = tonumber('0xe0e000'), fg_indexed = true },
  1651. [6] = { foreground = tonumber('0xe0e000'), fg_indexed = true },
  1652. [7] = { reverse = true, foreground = Screen.colors.SeaGreen4 },
  1653. [8] = { foreground = Screen.colors.SeaGreen4 },
  1654. [9] = { bold = true, foreground = Screen.colors.Blue1 },
  1655. [10] = { foreground = Screen.colors.Blue },
  1656. })
  1657. feed_data(':hi SpecialKey ctermfg=3 guifg=SeaGreen\n')
  1658. feed_data('i')
  1659. feed_data('\022\007') -- ctrl+g
  1660. feed_data('\028\014') -- crtl+\ ctrl+N
  1661. feed_data(':set termguicolors?\n')
  1662. screen:expect([[
  1663. {6:^^G} |
  1664. {2:~ }|*3
  1665. {3:[No Name] [+] }|
  1666. notermguicolors |
  1667. {4:-- TERMINAL --} |
  1668. ]])
  1669. feed_data(':set termguicolors\n')
  1670. screen:expect([[
  1671. {8:^^G} |
  1672. {9:~}{10: }|*3
  1673. {3:[No Name] [+] }|
  1674. :set termguicolors |
  1675. {4:-- TERMINAL --} |
  1676. ]])
  1677. feed_data(':set notermguicolors\n')
  1678. screen:expect([[
  1679. {6:^^G} |
  1680. {2:~ }|*3
  1681. {3:[No Name] [+] }|
  1682. :set notermguicolors |
  1683. {4:-- TERMINAL --} |
  1684. ]])
  1685. end)
  1686. it('forwards :term palette colors with termguicolors', function()
  1687. if is_ci('github') then
  1688. pending('tty-test complains about not owning the terminal -- actions/runner#241')
  1689. end
  1690. screen:set_rgb_cterm(true)
  1691. screen:set_default_attr_ids({
  1692. [1] = { { reverse = true }, { reverse = true } },
  1693. [2] = {
  1694. { bold = true, background = Screen.colors.LightGreen, foreground = Screen.colors.Black },
  1695. { bold = true },
  1696. },
  1697. [3] = { { bold = true }, { bold = true } },
  1698. [4] = { { fg_indexed = true, foreground = tonumber('0xe0e000') }, { foreground = 3 } },
  1699. [5] = { { foreground = tonumber('0xff8000') }, {} },
  1700. [6] = {
  1701. {
  1702. fg_indexed = true,
  1703. bg_indexed = true,
  1704. bold = true,
  1705. background = tonumber('0x66ff99'),
  1706. foreground = Screen.colors.Black,
  1707. },
  1708. { bold = true, background = 121, foreground = 0 },
  1709. },
  1710. [7] = {
  1711. {
  1712. fg_indexed = true,
  1713. bg_indexed = true,
  1714. background = tonumber('0x66ff99'),
  1715. foreground = Screen.colors.Black,
  1716. },
  1717. { background = 121, foreground = 0 },
  1718. },
  1719. })
  1720. child_exec_lua('vim.o.statusline="^^^^^^^"')
  1721. child_exec_lua('vim.o.termguicolors=true')
  1722. child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test'))
  1723. screen:expect {
  1724. grid = [[
  1725. ^tty ready |
  1726. |*3
  1727. {2:^^^^^^^ }|
  1728. |
  1729. {3:-- TERMINAL --} |
  1730. ]],
  1731. }
  1732. feed_data(
  1733. ':call chansend(&channel, "\\033[38;5;3mtext\\033[38:2:255:128:0mcolor\\033[0;10mtext")\n'
  1734. )
  1735. screen:expect {
  1736. grid = [[
  1737. ^tty ready |
  1738. {4:text}{5:color}text |
  1739. |*2
  1740. {2:^^^^^^^ }|
  1741. |
  1742. {3:-- TERMINAL --} |
  1743. ]],
  1744. }
  1745. feed_data(':set notermguicolors\n')
  1746. screen:expect {
  1747. grid = [[
  1748. ^tty ready |
  1749. {4:text}colortext |
  1750. |*2
  1751. {6:^^^^^^^}{7: }|
  1752. :set notermguicolors |
  1753. {3:-- TERMINAL --} |
  1754. ]],
  1755. }
  1756. end)
  1757. -- Note: libvterm doesn't support colored underline or undercurl.
  1758. it('supports undercurl and underdouble when run in :terminal', function()
  1759. screen:set_default_attr_ids({
  1760. [1] = { reverse = true },
  1761. [2] = { bold = true, reverse = true },
  1762. [3] = { bold = true },
  1763. [4] = { foreground = 12 },
  1764. [5] = { undercurl = true },
  1765. [6] = { underdouble = true },
  1766. })
  1767. child_session:request('nvim_set_hl', 0, 'Visual', { undercurl = true })
  1768. feed_data('ifoobar\027V')
  1769. screen:expect([[
  1770. {5:fooba}^r |
  1771. {4:~ }|*3
  1772. {2:[No Name] [+] }|
  1773. {3:-- VISUAL LINE --} |
  1774. {3:-- TERMINAL --} |
  1775. ]])
  1776. child_session:request('nvim_set_hl', 0, 'Visual', { underdouble = true })
  1777. screen:expect([[
  1778. {6:fooba}^r |
  1779. {4:~ }|*3
  1780. {2:[No Name] [+] }|
  1781. {3:-- VISUAL LINE --} |
  1782. {3:-- TERMINAL --} |
  1783. ]])
  1784. end)
  1785. it('in nvim_list_uis(), sets nvim_set_client_info()', function()
  1786. -- $TERM in :terminal.
  1787. local exp_term = is_os('bsd') and 'builtin_xterm' or 'xterm-256color'
  1788. local ui_chan = 1
  1789. local expected = {
  1790. {
  1791. chan = ui_chan,
  1792. ext_cmdline = false,
  1793. ext_hlstate = false,
  1794. ext_linegrid = true,
  1795. ext_messages = false,
  1796. ext_multigrid = false,
  1797. ext_popupmenu = false,
  1798. ext_tabline = false,
  1799. ext_termcolors = true,
  1800. ext_wildmenu = false,
  1801. height = 6,
  1802. override = false,
  1803. rgb = false,
  1804. stdin_tty = true,
  1805. stdout_tty = true,
  1806. term_background = '',
  1807. term_colors = 256,
  1808. term_name = exp_term,
  1809. width = 50,
  1810. },
  1811. }
  1812. local _, rv = child_session:request('nvim_list_uis')
  1813. eq(expected, rv)
  1814. ---@type table
  1815. local expected_version = child_exec_lua('return vim.version()')
  1816. -- vim.version() returns `prerelease` string. Coerce it to boolean.
  1817. expected_version.prerelease = not not expected_version.prerelease
  1818. local expected_chan_info = {
  1819. client = {
  1820. attributes = {
  1821. license = 'Apache 2',
  1822. -- pid = 5371,
  1823. website = 'https://neovim.io',
  1824. },
  1825. methods = {},
  1826. name = 'nvim-tui',
  1827. type = 'ui',
  1828. version = expected_version,
  1829. },
  1830. id = ui_chan,
  1831. mode = 'rpc',
  1832. stream = 'stdio',
  1833. }
  1834. local status, chan_info = child_session:request('nvim_get_chan_info', ui_chan)
  1835. ok(status)
  1836. local info = chan_info.client
  1837. ok(info.attributes.pid and info.attributes.pid > 0, 'PID', info.attributes.pid or 'nil')
  1838. ok(info.version.major >= 0)
  1839. ok(info.version.minor >= 0)
  1840. ok(info.version.patch >= 0)
  1841. -- Delete variable fields so we can deep-compare.
  1842. info.attributes.pid = nil
  1843. eq(expected_chan_info, chan_info)
  1844. end)
  1845. it('allows grid to assume wider ambiwidth chars than host terminal', function()
  1846. child_session:request(
  1847. 'nvim_buf_set_lines',
  1848. 0,
  1849. 0,
  1850. -1,
  1851. true,
  1852. { ('℃'):rep(60), ('℃'):rep(60) }
  1853. )
  1854. child_session:request('nvim_set_option_value', 'cursorline', true, {})
  1855. child_session:request('nvim_set_option_value', 'list', true, {})
  1856. child_session:request('nvim_set_option_value', 'listchars', 'eol:$', { win = 0 })
  1857. feed_data('gg')
  1858. local singlewidth_screen = [[
  1859. {12:^℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}|
  1860. {12:℃℃℃℃℃℃℃℃℃℃}{15:$}{12: }|
  1861. ℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃|
  1862. ℃℃℃℃℃℃℃℃℃℃{4:$} |
  1863. {5:[No Name] [+] }|
  1864. |
  1865. {3:-- TERMINAL --} |
  1866. ]]
  1867. -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width,
  1868. -- the second cell of "℃" is a space and the attributes of the "℃" are applied to it.
  1869. local doublewidth_screen = [[
  1870. {12:^℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }|
  1871. {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }|
  1872. {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{15:$}{12: }|
  1873. ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ {4:@@@@}|
  1874. {5:[No Name] [+] }|
  1875. |
  1876. {3:-- TERMINAL --} |
  1877. ]]
  1878. screen:expect(singlewidth_screen)
  1879. child_session:request('nvim_set_option_value', 'ambiwidth', 'double', {})
  1880. screen:expect(doublewidth_screen)
  1881. child_session:request('nvim_set_option_value', 'ambiwidth', 'single', {})
  1882. screen:expect(singlewidth_screen)
  1883. child_session:request('nvim_call_function', 'setcellwidths', { { { 0x2103, 0x2103, 2 } } })
  1884. screen:expect(doublewidth_screen)
  1885. child_session:request('nvim_call_function', 'setcellwidths', { { { 0x2103, 0x2103, 1 } } })
  1886. screen:expect(singlewidth_screen)
  1887. end)
  1888. it('allows grid to assume wider non-ambiwidth chars than host terminal', function()
  1889. child_session:request(
  1890. 'nvim_buf_set_lines',
  1891. 0,
  1892. 0,
  1893. -1,
  1894. true,
  1895. { ('✓'):rep(60), ('✓'):rep(60) }
  1896. )
  1897. child_session:request('nvim_set_option_value', 'cursorline', true, {})
  1898. child_session:request('nvim_set_option_value', 'list', true, {})
  1899. child_session:request('nvim_set_option_value', 'listchars', 'eol:$', { win = 0 })
  1900. feed_data('gg')
  1901. local singlewidth_screen = [[
  1902. {12:^✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓}|
  1903. {12:✓✓✓✓✓✓✓✓✓✓}{15:$}{12: }|
  1904. ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓|
  1905. ✓✓✓✓✓✓✓✓✓✓{4:$} |
  1906. {5:[No Name] [+] }|
  1907. |
  1908. {3:-- TERMINAL --} |
  1909. ]]
  1910. -- When grid assumes "✓" to be double-width but host terminal assumes it to be single-width,
  1911. -- the second cell of "✓" is a space and the attributes of the "✓" are applied to it.
  1912. local doublewidth_screen = [[
  1913. {12:^✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }|
  1914. {12:✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }|
  1915. {12:✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ }{15:$}{12: }|
  1916. ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ {4:@@@@}|
  1917. {5:[No Name] [+] }|
  1918. |
  1919. {3:-- TERMINAL --} |
  1920. ]]
  1921. screen:expect(singlewidth_screen)
  1922. child_session:request('nvim_set_option_value', 'ambiwidth', 'double', {})
  1923. screen:expect_unchanged()
  1924. child_session:request('nvim_call_function', 'setcellwidths', { { { 0x2713, 0x2713, 2 } } })
  1925. screen:expect(doublewidth_screen)
  1926. child_session:request('nvim_set_option_value', 'ambiwidth', 'single', {})
  1927. screen:expect_unchanged()
  1928. child_session:request('nvim_call_function', 'setcellwidths', { { { 0x2713, 0x2713, 1 } } })
  1929. screen:expect(singlewidth_screen)
  1930. end)
  1931. it('draws correctly when cursor_address overflows #21643', function()
  1932. screen:try_resize(70, 333)
  1933. retry(nil, nil, function()
  1934. eq({ true, 330 }, { child_session:request('nvim_win_get_height', 0) })
  1935. end)
  1936. child_session:request('nvim_set_option_value', 'cursorline', true, {})
  1937. -- Use full screen message so that redrawing afterwards is more deterministic.
  1938. child_session:notify('nvim_command', 'intro')
  1939. screen:expect({ any = 'Nvim is open source and freely distributable' })
  1940. -- Going to top-left corner needs 3 bytes.
  1941. -- Setting underline attribute needs 9 bytes.
  1942. -- A Ꝩ character takes 3 bytes.
  1943. -- The whole line needs 3 + 9 + 3 * 21838 + 3 = 65529 bytes.
  1944. -- The cursor_address that comes after will overflow the 65535-byte buffer.
  1945. local line = ('Ꝩ'):rep(21838) .. '℃'
  1946. child_session:notify('nvim_buf_set_lines', 0, 0, -1, true, { line, 'b' })
  1947. -- Close the :intro message and redraw the lines.
  1948. feed_data('\n')
  1949. screen:expect([[
  1950. {12:^ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ}|
  1951. {12:ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ}|*310
  1952. {12:ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ℃ }|
  1953. b |
  1954. {4:~ }|*17
  1955. {5:[No Name] [+] }|
  1956. |
  1957. {3:-- TERMINAL --} |
  1958. ]])
  1959. end)
  1960. it('draws correctly when setting title overflows #30793', function()
  1961. screen:try_resize(67, 327)
  1962. retry(nil, nil, function()
  1963. eq({ true, 324 }, { child_session:request('nvim_win_get_height', 0) })
  1964. end)
  1965. child_exec_lua([[
  1966. vim.o.cmdheight = 0
  1967. vim.o.laststatus = 0
  1968. vim.o.ruler = false
  1969. vim.o.showcmd = false
  1970. vim.o.termsync = false
  1971. vim.o.title = true
  1972. ]])
  1973. retry(nil, nil, function()
  1974. eq('[No Name] - Nvim', api.nvim_buf_get_var(0, 'term_title'))
  1975. eq({ true, 326 }, { child_session:request('nvim_win_get_height', 0) })
  1976. end)
  1977. -- Use full screen message so that redrawing afterwards is more deterministic.
  1978. child_session:notify('nvim_command', 'intro')
  1979. screen:expect({ any = 'Nvim is open source and freely distributable' })
  1980. -- Going to top-left corner needs 3 bytes.
  1981. -- A Ꝩ character takes 3 bytes.
  1982. -- The whole line needs 3 + 3 * 21842 = 65529 bytes.
  1983. -- The title will be updated because the buffer is now modified.
  1984. -- The start of the OSC 0 sequence to set title can fit in the 65535-byte buffer,
  1985. -- but the title string cannot.
  1986. local line = ('Ꝩ'):rep(21842)
  1987. child_session:notify('nvim_buf_set_lines', 0, 0, -1, true, { line })
  1988. -- Close the :intro message and redraw the lines.
  1989. feed_data('\n')
  1990. screen:expect([[
  1991. ^ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ|
  1992. ꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨꝨ|*325
  1993. {3:-- TERMINAL --} |
  1994. ]])
  1995. retry(nil, nil, function()
  1996. eq('[No Name] + - Nvim', api.nvim_buf_get_var(0, 'term_title'))
  1997. end)
  1998. end)
  1999. it('visual bell (padding) does not crash #21610', function()
  2000. feed_data ':set visualbell\n'
  2001. screen:expect {
  2002. grid = [[
  2003. ^ |
  2004. {4:~ }|*3
  2005. {5:[No Name] }|
  2006. :set visualbell |
  2007. {3:-- TERMINAL --} |
  2008. ]],
  2009. }
  2010. -- move left is enough to invoke the bell
  2011. feed_data 'h'
  2012. -- visual change to show we process events after this
  2013. feed_data 'i'
  2014. screen:expect {
  2015. grid = [[
  2016. ^ |
  2017. {4:~ }|*3
  2018. {5:[No Name] }|
  2019. {3:-- INSERT --} |
  2020. {3:-- TERMINAL --} |
  2021. ]],
  2022. }
  2023. end)
  2024. it('no assert failure on deadly signal #21896', function()
  2025. exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]])
  2026. screen:expect {
  2027. grid = [[
  2028. Nvim: Caught deadly signal 'SIGTERM' |
  2029. |
  2030. [Process exited 1]^ |
  2031. |*3
  2032. {3:-- TERMINAL --} |
  2033. ]],
  2034. }
  2035. end)
  2036. it('no stack-use-after-scope with cursor color #22432', function()
  2037. screen:set_option('rgb', true)
  2038. command('set termguicolors')
  2039. child_session:request(
  2040. 'nvim_exec2',
  2041. [[
  2042. set tgc
  2043. hi Cursor guifg=Red guibg=Green
  2044. set guicursor=n:block-Cursor/lCursor
  2045. ]],
  2046. {}
  2047. )
  2048. screen:set_default_attr_ids({
  2049. [1] = { reverse = true },
  2050. [2] = { bold = true, foreground = Screen.colors.Blue },
  2051. [3] = { foreground = Screen.colors.Blue },
  2052. [4] = { reverse = true, bold = true },
  2053. [5] = { bold = true },
  2054. })
  2055. screen:expect([[
  2056. ^ |
  2057. {2:~}{3: }|*3
  2058. {4:[No Name] }|
  2059. |
  2060. {5:-- TERMINAL --} |
  2061. ]])
  2062. feed_data('i')
  2063. screen:expect([[
  2064. ^ |
  2065. {2:~}{3: }|*3
  2066. {4:[No Name] }|
  2067. {5:-- INSERT --} |
  2068. {5:-- TERMINAL --} |
  2069. ]])
  2070. end)
  2071. it('redraws on SIGWINCH even if terminal size is unchanged #23411', function()
  2072. child_session:request('nvim_echo', { { 'foo' } }, false, {})
  2073. screen:expect([[
  2074. ^ |
  2075. {4:~ }|*3
  2076. {5:[No Name] }|
  2077. foo |
  2078. {3:-- TERMINAL --} |
  2079. ]])
  2080. exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]])
  2081. screen:expect([[
  2082. ^ |
  2083. {4:~ }|*3
  2084. {5:[No Name] }|
  2085. |
  2086. {3:-- TERMINAL --} |
  2087. ]])
  2088. end)
  2089. it('supports hiding cursor', function()
  2090. child_session:request(
  2091. 'nvim_command',
  2092. "let g:id = jobstart([v:progpath, '--clean', '--headless'])"
  2093. )
  2094. feed_data(':call jobwait([g:id])\n')
  2095. screen:expect([[
  2096. |
  2097. {4:~ }|*3
  2098. {5:[No Name] }|
  2099. :call jobwait([g:id]) |
  2100. {3:-- TERMINAL --} |
  2101. ]])
  2102. feed_data('\003')
  2103. screen:expect([[
  2104. ^ |
  2105. {4:~ }|*3
  2106. {5:[No Name] }|
  2107. Type :qa and press <Enter> to exit Nvim |
  2108. {3:-- TERMINAL --} |
  2109. ]])
  2110. end)
  2111. it('cursor is not hidden on incsearch with no match', function()
  2112. feed_data('ifoo\027')
  2113. feed_data('/foo')
  2114. screen:expect([[
  2115. {1:foo} |
  2116. {4:~ }|*3
  2117. {5:[No Name] [+] }|
  2118. /foo^ |
  2119. {3:-- TERMINAL --} |
  2120. ]])
  2121. screen:sleep(10)
  2122. feed_data('b')
  2123. screen:expect([[
  2124. foo |
  2125. {4:~ }|*3
  2126. {5:[No Name] [+] }|
  2127. /foob^ |
  2128. {3:-- TERMINAL --} |
  2129. ]])
  2130. screen:sleep(10)
  2131. feed_data('a')
  2132. screen:expect([[
  2133. foo |
  2134. {4:~ }|*3
  2135. {5:[No Name] [+] }|
  2136. /fooba^ |
  2137. {3:-- TERMINAL --} |
  2138. ]])
  2139. end)
  2140. it('emits hyperlinks with OSC 8', function()
  2141. exec_lua([[
  2142. local buf = vim.api.nvim_get_current_buf()
  2143. _G.urls = {}
  2144. vim.api.nvim_create_autocmd('TermRequest', {
  2145. buffer = buf,
  2146. callback = function(args)
  2147. local req = args.data.sequence
  2148. if not req then
  2149. return
  2150. end
  2151. local id, url = req:match('\027]8;id=(%d+);(.*)$')
  2152. if id ~= nil and url ~= nil then
  2153. table.insert(_G.urls, { id = tonumber(id), url = url })
  2154. end
  2155. end,
  2156. })
  2157. ]])
  2158. child_exec_lua([[
  2159. vim.api.nvim_buf_set_lines(0, 0, 0, true, {'Hello'})
  2160. local ns = vim.api.nvim_create_namespace('test')
  2161. vim.api.nvim_buf_set_extmark(0, ns, 0, 1, {
  2162. end_col = 3,
  2163. url = 'https://example.com',
  2164. })
  2165. ]])
  2166. retry(nil, 1000, function()
  2167. eq({ { id = 0xE1EA0000, url = 'https://example.com' } }, exec_lua([[return _G.urls]]))
  2168. end)
  2169. end)
  2170. it('TermResponse works with vim.wait() from another autocommand #32706', function()
  2171. child_exec_lua([[
  2172. _G.termresponse = nil
  2173. vim.api.nvim_create_autocmd('TermResponse', {
  2174. callback = function(ev)
  2175. _G.sequence = ev.data.sequence
  2176. _G.v_termresponse = vim.v.termresponse
  2177. end,
  2178. })
  2179. vim.api.nvim_create_autocmd('InsertEnter', {
  2180. buffer = 0,
  2181. callback = function()
  2182. _G.result = vim.wait(3000, function()
  2183. local expected = '\027P1+r5463'
  2184. return _G.sequence == expected and _G.v_termresponse == expected
  2185. end)
  2186. end,
  2187. })
  2188. ]])
  2189. feed_data('i')
  2190. feed_data('\027P1+r5463\027\\')
  2191. retry(nil, 4000, function()
  2192. eq(true, child_exec_lua('return _G.result'))
  2193. end)
  2194. end)
  2195. end)
  2196. describe('TUI', function()
  2197. before_each(clear)
  2198. it('resize at startup #17285 #15044 #11330', function()
  2199. local screen = Screen.new(50, 10)
  2200. screen:set_default_attr_ids({
  2201. [1] = { reverse = true },
  2202. [2] = { bold = true, foreground = Screen.colors.Blue },
  2203. [3] = { bold = true },
  2204. [4] = { foreground = tonumber('0x4040ff'), fg_indexed = true },
  2205. [5] = { bold = true, reverse = true },
  2206. [6] = { foreground = Screen.colors.White, background = Screen.colors.DarkGreen },
  2207. })
  2208. fn.jobstart({
  2209. nvim_prog,
  2210. '--clean',
  2211. '--cmd',
  2212. 'colorscheme vim',
  2213. '--cmd',
  2214. 'set notermguicolors',
  2215. '--cmd',
  2216. nvim_set,
  2217. '--cmd',
  2218. 'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile',
  2219. }, {
  2220. term = true,
  2221. env = {
  2222. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  2223. },
  2224. })
  2225. exec([[
  2226. sleep 500m
  2227. vs new
  2228. ]])
  2229. screen:expect([[
  2230. ^ │ |
  2231. {2:~ }│{4:~ }|*6
  2232. {2:~ }│ |
  2233. {5:new }{6:{MATCH:<.*[/\]nvim} [-] }|
  2234. |
  2235. ]])
  2236. end)
  2237. -- #28667, #28668
  2238. for _, guicolors in ipairs({ 'notermguicolors', 'termguicolors' }) do
  2239. it('has no black flicker when clearing regions during startup with ' .. guicolors, function()
  2240. local screen = Screen.new(50, 10)
  2241. fn.jobstart({
  2242. nvim_prog,
  2243. '--clean',
  2244. '--cmd',
  2245. 'set ' .. guicolors,
  2246. '--cmd',
  2247. 'sleep 10',
  2248. }, {
  2249. term = true,
  2250. env = {
  2251. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  2252. },
  2253. })
  2254. screen:expect({
  2255. grid = [[
  2256. ^ |
  2257. |*9
  2258. ]],
  2259. intermediate = true,
  2260. })
  2261. screen:try_resize(51, 11)
  2262. screen:expect({
  2263. grid = [[
  2264. ^ |
  2265. |*10
  2266. ]],
  2267. })
  2268. end)
  2269. end
  2270. it('argv[0] can be overridden #23953', function()
  2271. if not exec_lua('return pcall(require, "ffi")') then
  2272. pending('missing LuaJIT FFI')
  2273. end
  2274. local script_file = 'Xargv0.lua'
  2275. write_file(
  2276. script_file,
  2277. [=[
  2278. local ffi = require('ffi')
  2279. ffi.cdef([[int execl(const char *, const char *, ...);]])
  2280. ffi.C.execl(vim.v.progpath, 'Xargv0nvim', '--clean', nil)
  2281. ]=]
  2282. )
  2283. finally(function()
  2284. os.remove(script_file)
  2285. end)
  2286. local screen = tt.setup_child_nvim({ '--clean', '-l', script_file })
  2287. screen:expect {
  2288. grid = [[
  2289. ^ |
  2290. ~ |*3
  2291. [No Name] 0,0-1 All|
  2292. |
  2293. {3:-- TERMINAL --} |
  2294. ]],
  2295. }
  2296. feed_data(':put =v:argv + [v:progname]\n')
  2297. screen:expect {
  2298. grid = [[
  2299. Xargv0nvim |
  2300. --embed |
  2301. --clean |
  2302. ^Xargv0nvim |
  2303. [No Name] [+] 5,1 Bot|
  2304. 4 more lines |
  2305. {3:-- TERMINAL --} |
  2306. ]],
  2307. }
  2308. end)
  2309. it('with non-tty (pipe) stdout/stderr', function()
  2310. finally(function()
  2311. os.remove('testF')
  2312. end)
  2313. local screen = tt.setup_screen(
  2314. 0,
  2315. ('"%s" --clean --cmd "set noswapfile noshowcmd noruler" --cmd "normal iabc" > /dev/null 2>&1 && cat testF && rm testF'):format(
  2316. nvim_prog
  2317. ),
  2318. nil,
  2319. { VIMRUNTIME = os.getenv('VIMRUNTIME') }
  2320. )
  2321. feed_data(':w testF\n:q\n')
  2322. screen:expect([[
  2323. :w testF |
  2324. :q |
  2325. abc |
  2326. |
  2327. [Process exited 0]^ |
  2328. |
  2329. {3:-- TERMINAL --} |
  2330. ]])
  2331. end)
  2332. it('<C-h> #10134', function()
  2333. local screen = tt.setup_child_nvim({
  2334. '--clean',
  2335. '--cmd',
  2336. 'colorscheme vim',
  2337. '--cmd',
  2338. 'set noruler notermguicolors',
  2339. '--cmd',
  2340. ':nnoremap <C-h> :echomsg "\\<C-h\\>"<CR>',
  2341. })
  2342. screen:expect {
  2343. grid = [[
  2344. ^ |
  2345. {4:~ }|*3
  2346. {5:[No Name] }|
  2347. |
  2348. {3:-- TERMINAL --} |
  2349. ]],
  2350. }
  2351. command([[call chansend(b:terminal_job_id, "\<C-h>")]])
  2352. screen:expect([[
  2353. ^ |
  2354. {4:~ }|*3
  2355. {5:[No Name] }|
  2356. <C-h> |
  2357. {3:-- TERMINAL --} |
  2358. ]])
  2359. end)
  2360. it('draws line with many trailing spaces correctly #24955', function()
  2361. local screen = tt.setup_child_nvim({
  2362. '--clean',
  2363. '--cmd',
  2364. 'set notermguicolors',
  2365. '--cmd',
  2366. 'colorscheme vim',
  2367. '--cmd',
  2368. 'call setline(1, ["1st line" .. repeat(" ", 153), "2nd line"])',
  2369. }, { cols = 80 })
  2370. screen:expect {
  2371. grid = [[
  2372. ^1st line |
  2373. |*2
  2374. 2nd line |
  2375. {5:[No Name] [+] 1,1 All}|
  2376. |
  2377. {3:-- TERMINAL --} |
  2378. ]],
  2379. }
  2380. feed_data('$')
  2381. screen:expect {
  2382. grid = [[
  2383. 1st line |
  2384. |
  2385. ^ |
  2386. 2nd line |
  2387. {5:[No Name] [+] 1,161 All}|
  2388. |
  2389. {3:-- TERMINAL --} |
  2390. ]],
  2391. }
  2392. end)
  2393. it('draws screen lines with leading spaces correctly #29711', function()
  2394. local screen = tt.setup_child_nvim({
  2395. '--clean',
  2396. '--cmd',
  2397. 'set foldcolumn=6 | call setline(1, ["", repeat("aabb", 1000)]) | echo 42',
  2398. }, { extra_rows = 10, cols = 66 })
  2399. screen:expect {
  2400. grid = [[
  2401. ^ |
  2402. aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb|*12
  2403. aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba@@@|
  2404. [No Name] [+] 1,0-1 Top|
  2405. 42 |
  2406. -- TERMINAL -- |
  2407. ]],
  2408. attr_ids = {},
  2409. }
  2410. feed_data('\12') -- Ctrl-L
  2411. -- The first line counts as 3 cells.
  2412. -- For the second line, 6 repeated spaces at the start counts as 2 cells,
  2413. -- so each screen line of the second line counts as 62 cells.
  2414. -- After drawing the first line and 8 screen lines of the second line,
  2415. -- 3 + 8 * 62 = 499 cells have been counted.
  2416. -- The 6 repeated spaces at the start of the next screen line exceeds the
  2417. -- 500-cell limit, so the buffer is flushed after these spaces.
  2418. screen:expect {
  2419. grid = [[
  2420. ^ |
  2421. aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb|*12
  2422. aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba@@@|
  2423. [No Name] [+] 1,0-1 Top|
  2424. |
  2425. -- TERMINAL -- |
  2426. ]],
  2427. attr_ids = {},
  2428. }
  2429. end)
  2430. it('no heap-buffer-overflow when changing &columns', function()
  2431. -- Set a different bg colour and change $TERM to something dumber so the `print_spaces()`
  2432. -- codepath in `clear_region()` is hit.
  2433. local screen = tt.setup_child_nvim({
  2434. '--clean',
  2435. '--cmd',
  2436. 'set notermguicolors | highlight Normal ctermbg=red',
  2437. '--cmd',
  2438. 'call setline(1, ["a"->repeat(&columns)])',
  2439. }, { env = { TERM = 'ansi' } })
  2440. screen:expect {
  2441. grid = [[
  2442. ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
  2443. ~ |*3
  2444. [No Name] [+] 1,1 All|
  2445. |
  2446. -- TERMINAL -- |
  2447. ]],
  2448. attr_ids = {},
  2449. }
  2450. feed_data(':set columns=12\n')
  2451. screen:expect {
  2452. grid = [[
  2453. ^aaaaaaaaaaaa |
  2454. aaaaaaaaaaaa |*3
  2455. < All |
  2456. |
  2457. -- TERMINAL -- |
  2458. ]],
  2459. attr_ids = {},
  2460. }
  2461. -- Wider than TUI, so screen state will look weird.
  2462. -- Wait for the statusline to redraw to confirm that the TUI lives and ASAN is happy.
  2463. feed_data(':set columns=99|set stl=redrawn%m\n')
  2464. screen:expect({ any = 'redrawn%[%+%]' })
  2465. end)
  2466. end)
  2467. describe('TUI UIEnter/UILeave', function()
  2468. it('fires exactly once, after VimEnter', function()
  2469. clear()
  2470. local screen = tt.setup_child_nvim({
  2471. '--clean',
  2472. '--cmd',
  2473. 'colorscheme vim',
  2474. '--cmd',
  2475. 'set noswapfile noshowcmd noruler notermguicolors',
  2476. '--cmd',
  2477. 'let g:evs = []',
  2478. '--cmd',
  2479. 'autocmd UIEnter * :call add(g:evs, "UIEnter")',
  2480. '--cmd',
  2481. 'autocmd UILeave * :call add(g:evs, "UILeave")',
  2482. '--cmd',
  2483. 'autocmd VimEnter * :call add(g:evs, "VimEnter")',
  2484. })
  2485. screen:expect {
  2486. grid = [[
  2487. ^ |
  2488. {4:~ }|*3
  2489. {5:[No Name] }|
  2490. |
  2491. {3:-- TERMINAL --} |
  2492. ]],
  2493. }
  2494. feed_data(':echo g:evs\n')
  2495. screen:expect {
  2496. grid = [[
  2497. ^ |
  2498. {4:~ }|*3
  2499. {5:[No Name] }|
  2500. ['VimEnter', 'UIEnter'] |
  2501. {3:-- TERMINAL --} |
  2502. ]],
  2503. }
  2504. end)
  2505. end)
  2506. describe('TUI FocusGained/FocusLost', function()
  2507. local screen
  2508. local child_session
  2509. before_each(function()
  2510. clear()
  2511. local child_server = new_pipename()
  2512. screen = tt.setup_child_nvim({
  2513. '--listen',
  2514. child_server,
  2515. '-u',
  2516. 'NONE',
  2517. '-i',
  2518. 'NONE',
  2519. '--cmd',
  2520. 'colorscheme vim',
  2521. '--cmd',
  2522. 'set noswapfile noshowcmd noruler notermguicolors background=dark',
  2523. })
  2524. screen:expect([[
  2525. ^ |
  2526. {4:~ }|*3
  2527. {5:[No Name] }|
  2528. |
  2529. {3:-- TERMINAL --} |
  2530. ]])
  2531. child_session = n.connect(child_server)
  2532. child_session:request(
  2533. 'nvim_exec2',
  2534. [[
  2535. autocmd FocusGained * echo 'gained'
  2536. autocmd FocusLost * echo 'lost'
  2537. ]],
  2538. {}
  2539. )
  2540. feed_data('\034\016') -- CTRL-\ CTRL-N
  2541. end)
  2542. it('in normal-mode', function()
  2543. retry(2, 3 * screen.timeout, function()
  2544. feed_data('\027[I')
  2545. screen:expect([[
  2546. ^ |
  2547. {4:~ }|*3
  2548. {5:[No Name] }|
  2549. gained |
  2550. {3:-- TERMINAL --} |
  2551. ]])
  2552. feed_data('\027[O')
  2553. screen:expect([[
  2554. ^ |
  2555. {4:~ }|*3
  2556. {5:[No Name] }|
  2557. lost |
  2558. {3:-- TERMINAL --} |
  2559. ]])
  2560. end)
  2561. end)
  2562. it('in insert-mode', function()
  2563. feed_data(':set noshowmode\r')
  2564. feed_data('i')
  2565. screen:expect {
  2566. grid = [[
  2567. ^ |
  2568. {4:~ }|*3
  2569. {5:[No Name] }|
  2570. :set noshowmode |
  2571. {3:-- TERMINAL --} |
  2572. ]],
  2573. }
  2574. retry(2, 3 * screen.timeout, function()
  2575. feed_data('\027[I')
  2576. screen:expect([[
  2577. ^ |
  2578. {4:~ }|*3
  2579. {5:[No Name] }|
  2580. gained |
  2581. {3:-- TERMINAL --} |
  2582. ]])
  2583. feed_data('\027[O')
  2584. screen:expect([[
  2585. ^ |
  2586. {4:~ }|*3
  2587. {5:[No Name] }|
  2588. lost |
  2589. {3:-- TERMINAL --} |
  2590. ]])
  2591. end)
  2592. end)
  2593. -- During cmdline-mode we ignore :echo invoked by timers/events.
  2594. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
  2595. it('in cmdline-mode does NOT :echo', function()
  2596. feed_data(':')
  2597. feed_data('\027[I')
  2598. screen:expect([[
  2599. |
  2600. {4:~ }|*3
  2601. {5:[No Name] }|
  2602. :^ |
  2603. {3:-- TERMINAL --} |
  2604. ]])
  2605. feed_data('\027[O')
  2606. screen:expect {
  2607. grid = [[
  2608. |
  2609. {4:~ }|*3
  2610. {5:[No Name] }|
  2611. :^ |
  2612. {3:-- TERMINAL --} |
  2613. ]],
  2614. unchanged = true,
  2615. }
  2616. end)
  2617. it('in cmdline-mode', function()
  2618. -- Set up autocmds that modify the buffer, instead of just calling :echo.
  2619. -- This is how we can test handling of focus gained/lost during cmdline-mode.
  2620. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
  2621. child_session:request(
  2622. 'nvim_exec2',
  2623. [[
  2624. autocmd!
  2625. autocmd FocusLost * call append(line('$'), 'lost')
  2626. autocmd FocusGained * call append(line('$'), 'gained')
  2627. ]],
  2628. {}
  2629. )
  2630. retry(2, 3 * screen.timeout, function()
  2631. -- Enter cmdline-mode.
  2632. feed_data(':')
  2633. screen:sleep(1)
  2634. -- Send focus lost/gained termcodes.
  2635. feed_data('\027[O')
  2636. feed_data('\027[I')
  2637. screen:sleep(1)
  2638. -- Exit cmdline-mode. Redraws from timers/events are blocked during
  2639. -- cmdline-mode, so the buffer won't be updated until we exit cmdline-mode.
  2640. feed_data('\n')
  2641. screen:expect { any = 'lost' .. (' '):rep(46) .. '|\ngained' }
  2642. end)
  2643. end)
  2644. it('in terminal-mode', function()
  2645. feed_data(':set shell=' .. testprg('shell-test') .. ' shellcmdflag=EXE\n')
  2646. feed_data(':set noshowmode laststatus=0\n')
  2647. feed_data(':terminal zia\n')
  2648. -- Wait for terminal to be ready.
  2649. screen:expect {
  2650. grid = [[
  2651. ^ready $ zia |
  2652. |
  2653. [Process exited 0] |
  2654. |*2
  2655. :terminal zia |
  2656. {3:-- TERMINAL --} |
  2657. ]],
  2658. }
  2659. feed_data('\027[I')
  2660. screen:expect {
  2661. grid = [[
  2662. ^ready $ zia |
  2663. |
  2664. [Process exited 0] |
  2665. |*2
  2666. gained |
  2667. {3:-- TERMINAL --} |
  2668. ]],
  2669. timeout = (4 * screen.timeout),
  2670. }
  2671. feed_data('\027[O')
  2672. screen:expect([[
  2673. ^ready $ zia |
  2674. |
  2675. [Process exited 0] |
  2676. |*2
  2677. lost |
  2678. {3:-- TERMINAL --} |
  2679. ]])
  2680. end)
  2681. it('in press-enter prompt', function()
  2682. feed_data(":echom 'msg1'|echom 'msg2'|echom 'msg3'|echom 'msg4'|echom 'msg5'\n")
  2683. -- Execute :messages to provoke the press-enter prompt.
  2684. feed_data(':messages\n')
  2685. screen:expect {
  2686. grid = [[
  2687. msg1 |
  2688. msg2 |
  2689. msg3 |
  2690. msg4 |
  2691. msg5 |
  2692. {10:Press ENTER or type command to continue}^ |
  2693. {3:-- TERMINAL --} |
  2694. ]],
  2695. }
  2696. feed_data('\027[I')
  2697. feed_data('\027[I')
  2698. screen:expect {
  2699. grid = [[
  2700. msg1 |
  2701. msg2 |
  2702. msg3 |
  2703. msg4 |
  2704. msg5 |
  2705. {10:Press ENTER or type command to continue}^ |
  2706. {3:-- TERMINAL --} |
  2707. ]],
  2708. unchanged = true,
  2709. }
  2710. end)
  2711. end)
  2712. -- These tests require `tt` because --headless/--embed
  2713. -- does not initialize the TUI.
  2714. describe("TUI 't_Co' (terminal colors)", function()
  2715. local screen
  2716. local function assert_term_colors(term, colorterm, maxcolors)
  2717. clear({ env = { TERM = term }, args = {} })
  2718. screen = tt.setup_child_nvim({
  2719. '--clean',
  2720. '--cmd',
  2721. 'colorscheme vim',
  2722. '--cmd',
  2723. nvim_set .. ' notermguicolors',
  2724. }, {
  2725. env = {
  2726. LANG = 'C',
  2727. TERM = term or '',
  2728. COLORTERM = colorterm or '',
  2729. },
  2730. })
  2731. local tline
  2732. if maxcolors == 8 then
  2733. tline = '{9:~ }'
  2734. elseif maxcolors == 16 then
  2735. tline = '~ '
  2736. else
  2737. tline = '{4:~ }'
  2738. end
  2739. screen:expect(string.format(
  2740. [[
  2741. ^ |
  2742. %s|*4
  2743. |
  2744. {3:-- TERMINAL --} |
  2745. ]],
  2746. tline
  2747. ))
  2748. feed_data(':echo &t_Co\n')
  2749. screen:expect(string.format(
  2750. [[
  2751. ^ |
  2752. %s|*4
  2753. %-3s |
  2754. {3:-- TERMINAL --} |
  2755. ]],
  2756. tline,
  2757. tostring(maxcolors and maxcolors or '')
  2758. ))
  2759. end
  2760. -- ansi and no terminal type at all:
  2761. it('no TERM uses 8 colors', function()
  2762. assert_term_colors(nil, nil, 8)
  2763. end)
  2764. it('TERM=ansi no COLORTERM uses 8 colors', function()
  2765. assert_term_colors('ansi', nil, 8)
  2766. end)
  2767. it('TERM=ansi with COLORTERM=anything-no-number uses 16 colors', function()
  2768. assert_term_colors('ansi', 'yet-another-term', 16)
  2769. end)
  2770. it('unknown TERM COLORTERM with 256 in name uses 256 colors', function()
  2771. assert_term_colors('ansi', 'yet-another-term-256color', 256)
  2772. end)
  2773. it('TERM=ansi-256color sets 256 colours', function()
  2774. assert_term_colors('ansi-256color', nil, 256)
  2775. end)
  2776. -- Unknown terminal types:
  2777. it('unknown TERM no COLORTERM sets 8 colours', function()
  2778. assert_term_colors('yet-another-term', nil, 8)
  2779. end)
  2780. it('unknown TERM with COLORTERM=anything-no-number uses 16 colors', function()
  2781. assert_term_colors('yet-another-term', 'yet-another-term', 16)
  2782. end)
  2783. it('unknown TERM with 256 in name sets 256 colours', function()
  2784. assert_term_colors('yet-another-term-256color', nil, 256)
  2785. end)
  2786. it('unknown TERM COLORTERM with 256 in name uses 256 colors', function()
  2787. assert_term_colors('yet-another-term', 'yet-another-term-256color', 256)
  2788. end)
  2789. -- Linux kernel terminal emulator:
  2790. it('TERM=linux uses 256 colors', function()
  2791. assert_term_colors('linux', nil, 256)
  2792. end)
  2793. it('TERM=linux-16color uses 256 colors', function()
  2794. assert_term_colors('linux-16color', nil, 256)
  2795. end)
  2796. it('TERM=linux-256color uses 256 colors', function()
  2797. assert_term_colors('linux-256color', nil, 256)
  2798. end)
  2799. -- screen:
  2800. --
  2801. -- FreeBSD falls back to the built-in screen-256colour entry.
  2802. -- Linux and MacOS have a screen entry in external terminfo with 8 colours,
  2803. -- which is raised to 16 by COLORTERM.
  2804. it('TERM=screen no COLORTERM uses 8/256 colors', function()
  2805. if is_os('freebsd') then
  2806. assert_term_colors('screen', nil, 256)
  2807. else
  2808. assert_term_colors('screen', nil, 8)
  2809. end
  2810. end)
  2811. it('TERM=screen COLORTERM=screen uses 16/256 colors', function()
  2812. if is_os('freebsd') then
  2813. assert_term_colors('screen', 'screen', 256)
  2814. else
  2815. assert_term_colors('screen', 'screen', 16)
  2816. end
  2817. end)
  2818. it('TERM=screen COLORTERM=screen-256color uses 256 colors', function()
  2819. assert_term_colors('screen', 'screen-256color', 256)
  2820. end)
  2821. it('TERM=screen-256color no COLORTERM uses 256 colors', function()
  2822. assert_term_colors('screen-256color', nil, 256)
  2823. end)
  2824. -- tmux:
  2825. --
  2826. -- FreeBSD and MacOS fall back to the built-in tmux-256colour entry.
  2827. -- Linux has a tmux entry in external terminfo with 8 colours,
  2828. -- which is raised to 256.
  2829. it('TERM=tmux no COLORTERM uses 256 colors', function()
  2830. assert_term_colors('tmux', nil, 256)
  2831. end)
  2832. it('TERM=tmux COLORTERM=tmux uses 256 colors', function()
  2833. assert_term_colors('tmux', 'tmux', 256)
  2834. end)
  2835. it('TERM=tmux COLORTERM=tmux-256color uses 256 colors', function()
  2836. assert_term_colors('tmux', 'tmux-256color', 256)
  2837. end)
  2838. it('TERM=tmux-256color no COLORTERM uses 256 colors', function()
  2839. assert_term_colors('tmux-256color', nil, 256)
  2840. end)
  2841. -- xterm and imitators:
  2842. it('TERM=xterm uses 256 colors', function()
  2843. assert_term_colors('xterm', nil, 256)
  2844. end)
  2845. it('TERM=xterm COLORTERM=gnome-terminal uses 256 colors', function()
  2846. assert_term_colors('xterm', 'gnome-terminal', 256)
  2847. end)
  2848. it('TERM=xterm COLORTERM=mate-terminal uses 256 colors', function()
  2849. assert_term_colors('xterm', 'mate-terminal', 256)
  2850. end)
  2851. it('TERM=xterm-256color uses 256 colors', function()
  2852. assert_term_colors('xterm-256color', nil, 256)
  2853. end)
  2854. -- rxvt and stterm:
  2855. --
  2856. -- FreeBSD and MacOS fall back to the built-in rxvt-256color and
  2857. -- st-256colour entries.
  2858. -- Linux has an rxvt, an st, and an st-16color entry in external terminfo
  2859. -- with 8, 8, and 16 colours respectively, which are raised to 256.
  2860. it('TERM=rxvt no COLORTERM uses 256 colors', function()
  2861. assert_term_colors('rxvt', nil, 256)
  2862. end)
  2863. it('TERM=rxvt COLORTERM=rxvt uses 256 colors', function()
  2864. assert_term_colors('rxvt', 'rxvt', 256)
  2865. end)
  2866. it('TERM=rxvt-256color uses 256 colors', function()
  2867. assert_term_colors('rxvt-256color', nil, 256)
  2868. end)
  2869. it('TERM=st no COLORTERM uses 256 colors', function()
  2870. assert_term_colors('st', nil, 256)
  2871. end)
  2872. it('TERM=st COLORTERM=st uses 256 colors', function()
  2873. assert_term_colors('st', 'st', 256)
  2874. end)
  2875. it('TERM=st COLORTERM=st-256color uses 256 colors', function()
  2876. assert_term_colors('st', 'st-256color', 256)
  2877. end)
  2878. it('TERM=st-16color no COLORTERM uses 8/256 colors', function()
  2879. assert_term_colors('st', nil, 256)
  2880. end)
  2881. it('TERM=st-16color COLORTERM=st uses 16/256 colors', function()
  2882. assert_term_colors('st', 'st', 256)
  2883. end)
  2884. it('TERM=st-16color COLORTERM=st-256color uses 256 colors', function()
  2885. assert_term_colors('st', 'st-256color', 256)
  2886. end)
  2887. it('TERM=st-256color uses 256 colors', function()
  2888. assert_term_colors('st-256color', nil, 256)
  2889. end)
  2890. -- gnome and vte:
  2891. --
  2892. -- FreeBSD and MacOS fall back to the built-in vte-256color entry.
  2893. -- Linux has a gnome, a vte, a gnome-256color, and a vte-256color entry in
  2894. -- external terminfo with 8, 8, 256, and 256 colours respectively, which are
  2895. -- raised to 256.
  2896. it('TERM=gnome no COLORTERM uses 256 colors', function()
  2897. assert_term_colors('gnome', nil, 256)
  2898. end)
  2899. it('TERM=gnome COLORTERM=gnome uses 256 colors', function()
  2900. assert_term_colors('gnome', 'gnome', 256)
  2901. end)
  2902. it('TERM=gnome COLORTERM=gnome-256color uses 256 colors', function()
  2903. assert_term_colors('gnome', 'gnome-256color', 256)
  2904. end)
  2905. it('TERM=gnome-256color uses 256 colors', function()
  2906. assert_term_colors('gnome-256color', nil, 256)
  2907. end)
  2908. it('TERM=vte no COLORTERM uses 256 colors', function()
  2909. assert_term_colors('vte', nil, 256)
  2910. end)
  2911. it('TERM=vte COLORTERM=vte uses 256 colors', function()
  2912. assert_term_colors('vte', 'vte', 256)
  2913. end)
  2914. it('TERM=vte COLORTERM=vte-256color uses 256 colors', function()
  2915. assert_term_colors('vte', 'vte-256color', 256)
  2916. end)
  2917. it('TERM=vte-256color uses 256 colors', function()
  2918. assert_term_colors('vte-256color', nil, 256)
  2919. end)
  2920. -- others:
  2921. -- TODO(blueyed): this is made pending, since it causes failure + later hang
  2922. -- when using non-compatible libvterm (#9494/#10179).
  2923. pending('TERM=interix uses 8 colors', function()
  2924. assert_term_colors('interix', nil, 8)
  2925. end)
  2926. it('TERM=iTerm.app uses 256 colors', function()
  2927. assert_term_colors('iTerm.app', nil, 256)
  2928. end)
  2929. it('TERM=iterm uses 256 colors', function()
  2930. assert_term_colors('iterm', nil, 256)
  2931. end)
  2932. end)
  2933. -- These tests require `tt` because --headless/--embed
  2934. -- does not initialize the TUI.
  2935. describe("TUI 'term' option", function()
  2936. local screen
  2937. local function assert_term(term_envvar, term_expected)
  2938. clear()
  2939. screen = tt.setup_child_nvim({
  2940. '--clean',
  2941. '--cmd',
  2942. nvim_set .. ' notermguicolors',
  2943. }, {
  2944. env = {
  2945. LANG = 'C',
  2946. TERM = term_envvar or '',
  2947. },
  2948. })
  2949. local full_timeout = screen.timeout
  2950. retry(nil, 2 * full_timeout, function() -- Wait for TUI thread to set 'term'.
  2951. feed_data(":echo 'term='.(&term)\n")
  2952. screen:expect { any = 'term=' .. term_expected, timeout = 250 }
  2953. end)
  2954. end
  2955. it('gets builtin term if $TERM is invalid', function()
  2956. assert_term('foo', 'builtin_ansi')
  2957. end)
  2958. it('gets system-provided term if $TERM is valid', function()
  2959. if is_os('openbsd') then
  2960. assert_term('xterm', 'xterm')
  2961. elseif is_os('bsd') then -- BSD lacks terminfo, builtin is always used.
  2962. assert_term('xterm', 'builtin_xterm')
  2963. elseif is_os('mac') then
  2964. local status, _ = pcall(assert_term, 'xterm', 'xterm')
  2965. if not status then
  2966. pending('macOS: unibilium could not find terminfo')
  2967. end
  2968. else
  2969. assert_term('xterm', 'xterm')
  2970. end
  2971. end)
  2972. it('builtin terms', function()
  2973. -- These non-standard terminfos are always builtin.
  2974. assert_term('win32con', 'builtin_win32con')
  2975. assert_term('conemu', 'builtin_conemu')
  2976. assert_term('vtpcon', 'builtin_vtpcon')
  2977. end)
  2978. end)
  2979. -- These tests require `tt` because --headless/--embed
  2980. -- does not initialize the TUI.
  2981. describe('TUI', function()
  2982. local screen
  2983. local logfile = 'Xtest_tui_verbose_log'
  2984. after_each(function()
  2985. os.remove(logfile)
  2986. end)
  2987. -- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI.
  2988. local function nvim_tui(extra_args)
  2989. clear()
  2990. screen = tt.setup_child_nvim({
  2991. '--clean',
  2992. '--cmd',
  2993. 'colorscheme vim',
  2994. '--cmd',
  2995. nvim_set .. ' notermguicolors',
  2996. extra_args,
  2997. }, {
  2998. env = {
  2999. LANG = 'C',
  3000. },
  3001. })
  3002. end
  3003. it('-V3log logs terminfo values', function()
  3004. nvim_tui('-V3' .. logfile)
  3005. -- Wait for TUI to start.
  3006. feed_data('Gitext')
  3007. screen:expect([[
  3008. text^ |
  3009. {4:~ }|*4
  3010. {3:-- INSERT --} |
  3011. {3:-- TERMINAL --} |
  3012. ]])
  3013. retry(nil, 3000, function() -- Wait for log file to be flushed.
  3014. local log = read_file('Xtest_tui_verbose_log') or ''
  3015. eq('--- Terminal info --- {{{\n', string.match(log, '%-%-%- Terminal.-\n')) -- }}}
  3016. ok(#log > 50)
  3017. end)
  3018. end)
  3019. it('does not crash on large inputs #26099', function()
  3020. nvim_tui()
  3021. screen:expect([[
  3022. ^ |
  3023. {4:~ }|*4
  3024. |
  3025. {3:-- TERMINAL --} |
  3026. ]])
  3027. feed_data(string.format('\027]52;c;%s\027\\', string.rep('A', 8192)))
  3028. screen:expect {
  3029. grid = [[
  3030. ^ |
  3031. {4:~ }|*4
  3032. |
  3033. {3:-- TERMINAL --} |
  3034. ]],
  3035. unchanged = true,
  3036. }
  3037. end)
  3038. it('queries the terminal for truecolor support', function()
  3039. clear()
  3040. exec_lua([[
  3041. vim.api.nvim_create_autocmd('TermRequest', {
  3042. callback = function(args)
  3043. local req = args.data.sequence
  3044. local sequence = req:match('^\027P%+q([%x;]+)$')
  3045. if sequence then
  3046. local t = {}
  3047. for cap in vim.gsplit(sequence, ';') do
  3048. local resp = string.format('\027P1+r%s\027\\', sequence)
  3049. vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
  3050. t[vim.text.hexdecode(cap)] = true
  3051. end
  3052. vim.g.xtgettcap = t
  3053. return true
  3054. end
  3055. end,
  3056. })
  3057. ]])
  3058. local child_server = new_pipename()
  3059. screen = tt.setup_child_nvim({
  3060. '--clean',
  3061. '--listen',
  3062. child_server,
  3063. }, {
  3064. env = {
  3065. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  3066. -- Force COLORTERM to be unset and use a TERM that does not contain Tc or RGB in terminfo.
  3067. -- This will force the nested nvim instance to query with XTGETTCAP
  3068. COLORTERM = '',
  3069. TERM = 'xterm-256colors',
  3070. },
  3071. })
  3072. screen:expect({ any = '%[No Name%]' })
  3073. local child_session = n.connect(child_server)
  3074. retry(nil, 1000, function()
  3075. eq({
  3076. Tc = true,
  3077. RGB = true,
  3078. setrgbf = true,
  3079. setrgbb = true,
  3080. }, eval("get(g:, 'xtgettcap', '')"))
  3081. eq({ true, 1 }, { child_session:request('nvim_eval', '&termguicolors') })
  3082. end)
  3083. end)
  3084. it('does not query the terminal for truecolor support if $COLORTERM is set', function()
  3085. clear()
  3086. exec_lua([[
  3087. vim.api.nvim_create_autocmd('TermRequest', {
  3088. callback = function(args)
  3089. local req = args.data.sequence
  3090. vim.g.termrequest = req
  3091. local xtgettcap = req:match('^\027P%+q([%x;]+)$')
  3092. if xtgettcap then
  3093. local t = {}
  3094. for cap in vim.gsplit(xtgettcap, ';') do
  3095. local resp = string.format('\027P1+r%s\027\\', xtgettcap)
  3096. vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
  3097. t[vim.text.hexdecode(cap)] = true
  3098. end
  3099. vim.g.xtgettcap = t
  3100. return true
  3101. elseif req:match('^\027P$qm\027\\$') then
  3102. vim.g.decrqss = true
  3103. end
  3104. end,
  3105. })
  3106. ]])
  3107. local child_server = new_pipename()
  3108. screen = tt.setup_child_nvim({
  3109. '--clean',
  3110. '--listen',
  3111. child_server,
  3112. }, {
  3113. env = {
  3114. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  3115. -- With COLORTERM=256, Nvim should not query the terminal and should not set 'tgc'
  3116. COLORTERM = '256',
  3117. TERM = 'xterm-256colors',
  3118. },
  3119. })
  3120. screen:expect({ any = '%[No Name%]' })
  3121. local child_session = n.connect(child_server)
  3122. retry(nil, 1000, function()
  3123. local xtgettcap = eval("get(g:, 'xtgettcap', {})")
  3124. eq(nil, xtgettcap['Tc'])
  3125. eq(nil, xtgettcap['RGB'])
  3126. eq(nil, xtgettcap['setrgbf'])
  3127. eq(nil, xtgettcap['setrgbb'])
  3128. eq(0, eval([[get(g:, 'decrqss')]]))
  3129. eq({ true, 0 }, { child_session:request('nvim_eval', '&termguicolors') })
  3130. end)
  3131. end)
  3132. it('queries the terminal for OSC 52 support', function()
  3133. clear()
  3134. exec_lua([[
  3135. vim.api.nvim_create_autocmd('TermRequest', {
  3136. callback = function(args)
  3137. local req = args.data.sequence
  3138. local sequence = req:match('^\027P%+q([%x;]+)$')
  3139. if sequence and vim.text.hexdecode(sequence) == 'Ms' then
  3140. local resp = string.format('\027P1+r%s=%s\027\\', sequence, vim.text.hexencode('\027]52;;\027\\'))
  3141. vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
  3142. return true
  3143. end
  3144. end,
  3145. })
  3146. ]])
  3147. local child_server = new_pipename()
  3148. screen = tt.setup_child_nvim({
  3149. '--listen',
  3150. child_server,
  3151. -- Use --clean instead of -u NONE to load the osc52 plugin
  3152. '--clean',
  3153. }, {
  3154. env = {
  3155. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  3156. },
  3157. })
  3158. screen:expect({ any = '%[No Name%]' })
  3159. local child_session = n.connect(child_server)
  3160. retry(nil, 1000, function()
  3161. eq({ true, { osc52 = true } }, { child_session:request('nvim_eval', 'g:termfeatures') })
  3162. end)
  3163. -- Attach another (non-TUI) UI to the child instance
  3164. local alt = Screen.new(nil, nil, nil, child_session)
  3165. -- Detach the first (primary) client so only the second UI is attached
  3166. feed_data(':detach\n')
  3167. alt:expect({ any = '%[No Name%]' })
  3168. -- osc52 should be cleared from termfeatures
  3169. eq({ true, {} }, { child_session:request('nvim_eval', 'g:termfeatures') })
  3170. alt:detach()
  3171. end)
  3172. it('does not query the terminal for OSC 52 support when disabled', function()
  3173. clear()
  3174. exec_lua([[
  3175. _G.query = false
  3176. vim.api.nvim_create_autocmd('TermRequest', {
  3177. callback = function(args)
  3178. local req = args.data.sequence
  3179. local sequence = req:match('^\027P%+q([%x;]+)$')
  3180. if sequence and vim.text.hexdecode(sequence) == 'Ms' then
  3181. _G.query = true
  3182. end
  3183. end,
  3184. })
  3185. ]])
  3186. local child_server = new_pipename()
  3187. screen = tt.setup_child_nvim({
  3188. '--listen',
  3189. child_server,
  3190. -- Use --clean instead of -u NONE to load the osc52 plugin
  3191. '--clean',
  3192. '--cmd',
  3193. 'let g:termfeatures = #{osc52: v:false}',
  3194. }, {
  3195. env = {
  3196. VIMRUNTIME = os.getenv('VIMRUNTIME'),
  3197. },
  3198. })
  3199. screen:expect({ any = '%[No Name%]' })
  3200. local child_session = n.connect(child_server)
  3201. eq({ true, { osc52 = false } }, { child_session:request('nvim_eval', 'g:termfeatures') })
  3202. eq(false, exec_lua([[return _G.query]]))
  3203. end)
  3204. end)
  3205. describe('TUI bg color', function()
  3206. before_each(clear)
  3207. it('is properly set in a nested Nvim instance when background=dark', function()
  3208. command('highlight clear Normal')
  3209. command('set background=dark') -- set outer Nvim background
  3210. local child_server = new_pipename()
  3211. local screen = tt.setup_child_nvim({
  3212. '--clean',
  3213. '--listen',
  3214. child_server,
  3215. '--cmd',
  3216. 'colorscheme vim',
  3217. '--cmd',
  3218. 'set noswapfile',
  3219. })
  3220. screen:expect({ any = '%[No Name%]' })
  3221. local child_session = n.connect(child_server)
  3222. retry(nil, nil, function()
  3223. eq({ true, 'dark' }, { child_session:request('nvim_eval', '&background') })
  3224. end)
  3225. end)
  3226. it('is properly set in a nested Nvim instance when background=light', function()
  3227. command('highlight clear Normal')
  3228. command('set background=light') -- set outer Nvim background
  3229. local child_server = new_pipename()
  3230. local screen = tt.setup_child_nvim({
  3231. '--clean',
  3232. '--listen',
  3233. child_server,
  3234. '--cmd',
  3235. 'colorscheme vim',
  3236. '--cmd',
  3237. 'set noswapfile',
  3238. })
  3239. screen:expect({ any = '%[No Name%]' })
  3240. local child_session = n.connect(child_server)
  3241. retry(nil, nil, function()
  3242. eq({ true, 'light' }, { child_session:request('nvim_eval', '&background') })
  3243. end)
  3244. end)
  3245. it('queries the terminal for background color', function()
  3246. exec_lua([[
  3247. vim.api.nvim_create_autocmd('TermRequest', {
  3248. callback = function(args)
  3249. local req = args.data.sequence
  3250. if req == '\027]11;?' then
  3251. vim.g.oscrequest = true
  3252. return true
  3253. end
  3254. end,
  3255. })
  3256. ]])
  3257. tt.setup_child_nvim({
  3258. '--clean',
  3259. '--cmd',
  3260. 'colorscheme vim',
  3261. '--cmd',
  3262. 'set noswapfile',
  3263. })
  3264. retry(nil, 1000, function()
  3265. eq(true, eval("get(g:, 'oscrequest', v:false)"))
  3266. end)
  3267. end)
  3268. it('triggers OptionSet from automatic background processing', function()
  3269. local screen = tt.setup_child_nvim({
  3270. '--clean',
  3271. '--cmd',
  3272. 'colorscheme vim',
  3273. '--cmd',
  3274. 'set noswapfile',
  3275. '-c',
  3276. 'autocmd OptionSet background echo "did OptionSet, yay!"',
  3277. })
  3278. screen:expect([[
  3279. ^ |
  3280. {3:~} |*3
  3281. {5:[No Name] 0,0-1 All}|
  3282. did OptionSet, yay! |
  3283. {3:-- TERMINAL --} |
  3284. ]])
  3285. end)
  3286. it('sends theme update notifications when background changes #31652', function()
  3287. command('set background=dark') -- set outer Nvim background
  3288. local child_server = new_pipename()
  3289. local screen = tt.setup_child_nvim({
  3290. '--clean',
  3291. '--listen',
  3292. child_server,
  3293. '--cmd',
  3294. 'colorscheme vim',
  3295. '--cmd',
  3296. 'set noswapfile',
  3297. })
  3298. screen:expect({ any = '%[No Name%]' })
  3299. local child_session = n.connect(child_server)
  3300. retry(nil, nil, function()
  3301. eq({ true, 'dark' }, { child_session:request('nvim_eval', '&background') })
  3302. end)
  3303. command('set background=light') -- set outer Nvim background
  3304. retry(nil, nil, function()
  3305. eq({ true, 'light' }, { child_session:request('nvim_eval', '&background') })
  3306. end)
  3307. end)
  3308. end)
  3309. describe('TUI client', function()
  3310. after_each(function()
  3311. os.remove(testlog)
  3312. end)
  3313. it('connects to remote instance (with its own TUI)', function()
  3314. local server_super = n.new_session(false)
  3315. local client_super = n.new_session(true)
  3316. set_session(server_super)
  3317. local server_pipe = new_pipename()
  3318. local screen_server = tt.setup_child_nvim({
  3319. '--clean',
  3320. '--listen',
  3321. server_pipe,
  3322. '--cmd',
  3323. 'colorscheme vim',
  3324. '--cmd',
  3325. nvim_set .. ' notermguicolors laststatus=2 background=dark',
  3326. })
  3327. feed_data('iHello, World')
  3328. screen_server:expect {
  3329. grid = [[
  3330. Hello, World^ |
  3331. {4:~ }|*3
  3332. {5:[No Name] [+] }|
  3333. {3:-- INSERT --} |
  3334. {3:-- TERMINAL --} |
  3335. ]],
  3336. }
  3337. feed_data('\027')
  3338. screen_server:expect {
  3339. grid = [[
  3340. Hello, Worl^d |
  3341. {4:~ }|*3
  3342. {5:[No Name] [+] }|
  3343. |
  3344. {3:-- TERMINAL --} |
  3345. ]],
  3346. }
  3347. set_session(client_super)
  3348. local screen_client = tt.setup_child_nvim({
  3349. '--remote-ui',
  3350. '--server',
  3351. server_pipe,
  3352. })
  3353. screen_client:expect {
  3354. grid = [[
  3355. Hello, Worl^d |
  3356. {4:~ }|*3
  3357. {5:[No Name] [+] }|
  3358. |
  3359. {3:-- TERMINAL --} |
  3360. ]],
  3361. }
  3362. -- grid smaller than containing terminal window is cleared properly
  3363. feed_data(":call setline(1,['a'->repeat(&columns)]->repeat(&lines))\n")
  3364. feed_data('0:set lines=3\n')
  3365. screen_server:expect {
  3366. grid = [[
  3367. ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
  3368. {5:[No Name] [+] }|
  3369. |*4
  3370. {3:-- TERMINAL --} |
  3371. ]],
  3372. }
  3373. feed_data(':q!\n')
  3374. server_super:close()
  3375. client_super:close()
  3376. end)
  3377. it('connects to remote instance (--headless)', function()
  3378. local server = n.new_session(false)
  3379. local client_super = n.new_session(true, { env = { NVIM_LOG_FILE = testlog } })
  3380. set_session(server)
  3381. local server_pipe = api.nvim_get_vvar('servername')
  3382. server:request('nvim_input', 'iHalloj!<Esc>')
  3383. server:request('nvim_command', 'set notermguicolors')
  3384. set_session(client_super)
  3385. local screen_client = tt.setup_child_nvim({
  3386. '--remote-ui',
  3387. '--server',
  3388. server_pipe,
  3389. })
  3390. screen_client:expect {
  3391. grid = [[
  3392. Halloj^! |
  3393. {4:~ }|*4
  3394. |
  3395. {3:-- TERMINAL --} |
  3396. ]],
  3397. }
  3398. -- No heap-use-after-free when receiving UI events after deadly signal #22184
  3399. server:request('nvim_input', ('a'):rep(1000))
  3400. exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]])
  3401. screen_client:expect {
  3402. grid = [[
  3403. Nvim: Caught deadly signal 'SIGTERM' |
  3404. |
  3405. [Process exited 1]^ |
  3406. |*3
  3407. {3:-- TERMINAL --} |
  3408. ]],
  3409. }
  3410. eq(0, api.nvim_get_vvar('shell_error'))
  3411. -- exits on input eof #22244
  3412. fn.system({ nvim_prog, '--remote-ui', '--server', server_pipe })
  3413. eq(1, api.nvim_get_vvar('shell_error'))
  3414. client_super:close()
  3415. server:close()
  3416. if is_os('mac') then
  3417. assert_log('uv_tty_set_mode failed: Unknown system error %-102', testlog)
  3418. end
  3419. end)
  3420. it('throws error when no server exists', function()
  3421. clear()
  3422. local screen = tt.setup_child_nvim({
  3423. '--remote-ui',
  3424. '--server',
  3425. '127.0.0.1:2436546',
  3426. }, { cols = 60 })
  3427. screen:expect([[
  3428. Remote ui failed to start: {MATCH:.*}|
  3429. |
  3430. [Process exited 1]^ |
  3431. |*3
  3432. {3:-- TERMINAL --} |
  3433. ]])
  3434. end)
  3435. local function test_remote_tui_quit(status)
  3436. local server_super = n.clear()
  3437. local client_super = n.new_session(true)
  3438. finally(function()
  3439. server_super:close()
  3440. client_super:close()
  3441. end)
  3442. local server_pipe = new_pipename()
  3443. local screen_server = tt.setup_child_nvim({
  3444. '--clean',
  3445. '--listen',
  3446. server_pipe,
  3447. '--cmd',
  3448. 'colorscheme vim',
  3449. '--cmd',
  3450. nvim_set .. ' notermguicolors laststatus=2 background=dark',
  3451. })
  3452. screen_server:expect {
  3453. grid = [[
  3454. ^ |
  3455. {4:~ }|*3
  3456. {5:[No Name] }|
  3457. |
  3458. {3:-- TERMINAL --} |
  3459. ]],
  3460. }
  3461. feed_data('iHello, World')
  3462. screen_server:expect {
  3463. grid = [[
  3464. Hello, World^ |
  3465. {4:~ }|*3
  3466. {5:[No Name] [+] }|
  3467. {3:-- INSERT --} |
  3468. {3:-- TERMINAL --} |
  3469. ]],
  3470. }
  3471. feed_data('\027')
  3472. screen_server:expect {
  3473. grid = [[
  3474. Hello, Worl^d |
  3475. {4:~ }|*3
  3476. {5:[No Name] [+] }|
  3477. |
  3478. {3:-- TERMINAL --} |
  3479. ]],
  3480. }
  3481. set_session(client_super)
  3482. local screen_client = tt.setup_child_nvim({
  3483. '--remote-ui',
  3484. '--server',
  3485. server_pipe,
  3486. })
  3487. screen_client:expect {
  3488. grid = [[
  3489. Hello, Worl^d |
  3490. {4:~ }|*3
  3491. {5:[No Name] [+] }|
  3492. |
  3493. {3:-- TERMINAL --} |
  3494. ]],
  3495. }
  3496. -- quitting the server
  3497. set_session(server_super)
  3498. feed_data(status and ':' .. status .. 'cquit!\n' or ':quit!\n')
  3499. status = status and status or 0
  3500. screen_server:expect({ any = 'Process exited ' .. status })
  3501. screen_client:expect({ any = 'Process exited ' .. status })
  3502. end
  3503. describe('exits when server quits', function()
  3504. it('with :quit', function()
  3505. test_remote_tui_quit()
  3506. end)
  3507. it('with :cquit', function()
  3508. test_remote_tui_quit(42)
  3509. end)
  3510. end)
  3511. end)