screen_basic_spec.lua 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.clear
  4. local feed, command = helpers.feed, helpers.command
  5. local insert = helpers.insert
  6. local eq = helpers.eq
  7. local eval = helpers.eval
  8. local iswin = helpers.iswin
  9. local funcs, meths, exec_lua = helpers.funcs, helpers.meths, helpers.exec_lua
  10. describe('screen', function()
  11. local screen
  12. local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
  13. '--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
  14. '--embed'}
  15. before_each(function()
  16. local screen_nvim = spawn(nvim_argv)
  17. set_session(screen_nvim)
  18. screen = Screen.new()
  19. screen:attach()
  20. screen:set_default_attr_ids( {
  21. [0] = {bold=true, foreground=255},
  22. [1] = {bold=true, reverse=true},
  23. } )
  24. end)
  25. it('default initial screen', function()
  26. screen:expect([[
  27. ^ |
  28. {0:~ }|
  29. {0:~ }|
  30. {0:~ }|
  31. {0:~ }|
  32. {0:~ }|
  33. {0:~ }|
  34. {0:~ }|
  35. {0:~ }|
  36. {0:~ }|
  37. {0:~ }|
  38. {0:~ }|
  39. {1:[No Name] }|
  40. |
  41. ]])
  42. end)
  43. end)
  44. local function screen_tests(linegrid)
  45. local screen
  46. before_each(function()
  47. clear()
  48. screen = Screen.new()
  49. screen:attach({rgb=true,ext_linegrid=linegrid})
  50. screen:set_default_attr_ids( {
  51. [0] = {bold=true, foreground=255},
  52. [1] = {bold=true, reverse=true},
  53. [2] = {bold=true},
  54. [3] = {reverse=true},
  55. [4] = {background = Screen.colors.LightGrey, underline = true},
  56. [5] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Fuchsia},
  57. [6] = {bold = true, foreground = Screen.colors.Fuchsia},
  58. [7] = {bold = true, foreground = Screen.colors.SeaGreen},
  59. } )
  60. end)
  61. describe(':suspend', function()
  62. it('is forwarded to the UI', function()
  63. local function check()
  64. eq(true, screen.suspended)
  65. end
  66. command('let g:ev = []')
  67. command('autocmd VimResume * :call add(g:ev, "r")')
  68. command('autocmd VimSuspend * :call add(g:ev, "s")')
  69. eq(false, screen.suspended)
  70. command('suspend')
  71. eq({ 's', 'r' }, eval('g:ev'))
  72. screen:expect(check)
  73. screen.suspended = false
  74. feed('<c-z>')
  75. eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
  76. screen:expect(check)
  77. screen.suspended = false
  78. command('suspend')
  79. eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
  80. end)
  81. end)
  82. describe('bell/visual bell', function()
  83. it('is forwarded to the UI', function()
  84. feed('<left>')
  85. screen:expect(function()
  86. eq(true, screen.bell)
  87. eq(false, screen.visual_bell)
  88. end)
  89. screen.bell = false
  90. command('set visualbell')
  91. feed('<left>')
  92. screen:expect(function()
  93. eq(true, screen.visual_bell)
  94. eq(false, screen.bell)
  95. end)
  96. end)
  97. end)
  98. describe(':set title', function()
  99. it('is forwarded to the UI', function()
  100. local expected = 'test-title'
  101. command('set titlestring='..expected)
  102. command('set title')
  103. screen:expect(function()
  104. eq(expected, screen.title)
  105. end)
  106. end)
  107. it('has correct default title with unnamed file', function()
  108. local expected = '[No Name] - NVIM'
  109. command('set title')
  110. screen:expect(function()
  111. eq(expected, screen.title)
  112. end)
  113. end)
  114. it('has correct default title with named file', function()
  115. local expected = (iswin() and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM')
  116. command('set title')
  117. command(iswin() and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
  118. screen:expect(function()
  119. eq(expected, screen.title)
  120. end)
  121. end)
  122. describe('is not changed by', function()
  123. local file1 = iswin() and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
  124. local file2 = iswin() and 'C:\\mydir\\myfile2' or '/mydir/myfile2'
  125. local expected = (iswin() and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM')
  126. local buf2
  127. before_each(function()
  128. command('edit '..file1)
  129. buf2 = funcs.bufadd(file2)
  130. command('set title')
  131. end)
  132. it('calling setbufvar() to set an option in a hidden buffer from i_CTRL-R', function()
  133. command([[inoremap <F2> <C-R>=setbufvar(]]..buf2..[[, '&autoindent', 1) ? '' : ''<CR>]])
  134. feed('i<F2><Esc>')
  135. command('redraw!')
  136. screen:expect(function()
  137. eq(expected, screen.title)
  138. end)
  139. end)
  140. it('an RPC call to nvim_buf_set_option in a hidden buffer', function()
  141. meths.buf_set_option(buf2, 'autoindent', true)
  142. command('redraw!')
  143. screen:expect(function()
  144. eq(expected, screen.title)
  145. end)
  146. end)
  147. it('a Lua callback calling nvim_buf_set_option in a hidden buffer', function()
  148. exec_lua(string.format([[
  149. vim.schedule(function()
  150. vim.api.nvim_buf_set_option(%d, 'autoindent', true)
  151. end)
  152. ]], buf2))
  153. command('redraw!')
  154. screen:expect(function()
  155. eq(expected, screen.title)
  156. end)
  157. end)
  158. it('a Lua callback calling nvim_buf_call in a hidden buffer', function()
  159. exec_lua(string.format([[
  160. vim.schedule(function()
  161. vim.api.nvim_buf_call(%d, function() end)
  162. end)
  163. ]], buf2))
  164. command('redraw!')
  165. screen:expect(function()
  166. eq(expected, screen.title)
  167. end)
  168. end)
  169. end)
  170. end)
  171. describe(':set icon', function()
  172. it('is forwarded to the UI', function()
  173. local expected = 'test-icon'
  174. command('set iconstring='..expected)
  175. command('set icon')
  176. screen:expect(function()
  177. eq(expected, screen.icon)
  178. end)
  179. end)
  180. end)
  181. describe('statusline', function()
  182. it('is redrawn after <c-l>', function()
  183. command('set laststatus=2')
  184. screen:expect([[
  185. ^ |
  186. {0:~ }|
  187. {0:~ }|
  188. {0:~ }|
  189. {0:~ }|
  190. {0:~ }|
  191. {0:~ }|
  192. {0:~ }|
  193. {0:~ }|
  194. {0:~ }|
  195. {0:~ }|
  196. {0:~ }|
  197. {1:[No Name] }|
  198. |
  199. ]])
  200. feed('<c-l>')
  201. screen:expect{grid=[[
  202. ^ |
  203. {0:~ }|
  204. {0:~ }|
  205. {0:~ }|
  206. {0:~ }|
  207. {0:~ }|
  208. {0:~ }|
  209. {0:~ }|
  210. {0:~ }|
  211. {0:~ }|
  212. {0:~ }|
  213. {0:~ }|
  214. {1:[No Name] }|
  215. |
  216. ]], reset=true}
  217. command('split')
  218. screen:expect([[
  219. ^ |
  220. {0:~ }|
  221. {0:~ }|
  222. {0:~ }|
  223. {0:~ }|
  224. {0:~ }|
  225. {1:[No Name] }|
  226. |
  227. {0:~ }|
  228. {0:~ }|
  229. {0:~ }|
  230. {0:~ }|
  231. {3:[No Name] }|
  232. |
  233. ]])
  234. feed('<c-l>')
  235. screen:expect{grid=[[
  236. ^ |
  237. {0:~ }|
  238. {0:~ }|
  239. {0:~ }|
  240. {0:~ }|
  241. {0:~ }|
  242. {1:[No Name] }|
  243. |
  244. {0:~ }|
  245. {0:~ }|
  246. {0:~ }|
  247. {0:~ }|
  248. {3:[No Name] }|
  249. |
  250. ]], reset=true}
  251. end)
  252. end)
  253. describe('window', function()
  254. describe('split', function()
  255. it('horizontal', function()
  256. command('sp')
  257. screen:expect([[
  258. ^ |
  259. {0:~ }|
  260. {0:~ }|
  261. {0:~ }|
  262. {0:~ }|
  263. {0:~ }|
  264. {1:[No Name] }|
  265. |
  266. {0:~ }|
  267. {0:~ }|
  268. {0:~ }|
  269. {0:~ }|
  270. {3:[No Name] }|
  271. |
  272. ]])
  273. end)
  274. it('horizontal and resize', function()
  275. command('sp')
  276. command('resize 8')
  277. screen:expect([[
  278. ^ |
  279. {0:~ }|
  280. {0:~ }|
  281. {0:~ }|
  282. {0:~ }|
  283. {0:~ }|
  284. {0:~ }|
  285. {0:~ }|
  286. {1:[No Name] }|
  287. |
  288. {0:~ }|
  289. {0:~ }|
  290. {3:[No Name] }|
  291. |
  292. ]])
  293. end)
  294. it('horizontal and vertical', function()
  295. command('sp')
  296. command('vsp')
  297. command('vsp')
  298. screen:expect([[
  299. ^ {3:│} {3:│} |
  300. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  301. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  302. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  303. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  304. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  305. {1:[No Name] }{3:[No Name] [No Name] }|
  306. |
  307. {0:~ }|
  308. {0:~ }|
  309. {0:~ }|
  310. {0:~ }|
  311. {3:[No Name] }|
  312. |
  313. ]])
  314. insert('hello')
  315. screen:expect([[
  316. hell^o {3:│}hello {3:│}hello |
  317. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  318. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  319. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  320. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  321. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  322. {1:[No Name] [+] }{3:[No Name] [+] [No Name] [+] }|
  323. hello |
  324. {0:~ }|
  325. {0:~ }|
  326. {0:~ }|
  327. {0:~ }|
  328. {3:[No Name] [+] }|
  329. |
  330. ]])
  331. end)
  332. end)
  333. end)
  334. describe('tabs', function()
  335. it('tabnew creates a new buffer', function()
  336. command('sp')
  337. command('vsp')
  338. command('vsp')
  339. insert('hello')
  340. screen:expect([[
  341. hell^o {3:│}hello {3:│}hello |
  342. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  343. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  344. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  345. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  346. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  347. {1:[No Name] [+] }{3:[No Name] [+] [No Name] [+] }|
  348. hello |
  349. {0:~ }|
  350. {0:~ }|
  351. {0:~ }|
  352. {0:~ }|
  353. {3:[No Name] [+] }|
  354. |
  355. ]])
  356. command('tabnew')
  357. insert('hello2')
  358. feed('h')
  359. screen:expect([[
  360. {4: }{5:4}{4:+ [No Name] }{2: + [No Name] }{3: }{4:X}|
  361. hell^o2 |
  362. {0:~ }|
  363. {0:~ }|
  364. {0:~ }|
  365. {0:~ }|
  366. {0:~ }|
  367. {0:~ }|
  368. {0:~ }|
  369. {0:~ }|
  370. {0:~ }|
  371. {0:~ }|
  372. {0:~ }|
  373. |
  374. ]])
  375. command('tabprevious')
  376. screen:expect([[
  377. {2: }{6:4}{2:+ [No Name] }{4: + [No Name] }{3: }{4:X}|
  378. hell^o {3:│}hello {3:│}hello |
  379. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  380. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  381. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  382. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  383. {0:~ }{3:│}{0:~ }{3:│}{0:~ }|
  384. {1:[No Name] [+] }{3:[No Name] [+] [No Name] [+] }|
  385. hello |
  386. {0:~ }|
  387. {0:~ }|
  388. {0:~ }|
  389. {3:[No Name] [+] }|
  390. |
  391. ]])
  392. end)
  393. it('tabline is redrawn after messages', function()
  394. command('tabnew')
  395. screen:expect([[
  396. {4: [No Name] }{2: [No Name] }{3: }{4:X}|
  397. ^ |
  398. {0:~ }|
  399. {0:~ }|
  400. {0:~ }|
  401. {0:~ }|
  402. {0:~ }|
  403. {0:~ }|
  404. {0:~ }|
  405. {0:~ }|
  406. {0:~ }|
  407. {0:~ }|
  408. {0:~ }|
  409. |
  410. ]])
  411. feed(':echo "'..string.rep('x\\n', 11)..'"<cr>')
  412. screen:expect([[
  413. {1: }|
  414. x |
  415. x |
  416. x |
  417. x |
  418. x |
  419. x |
  420. x |
  421. x |
  422. x |
  423. x |
  424. x |
  425. |
  426. {7:Press ENTER or type command to continue}^ |
  427. ]])
  428. feed('<cr>')
  429. screen:expect([[
  430. {4: [No Name] }{2: [No Name] }{3: }{4:X}|
  431. ^ |
  432. {0:~ }|
  433. {0:~ }|
  434. {0:~ }|
  435. {0:~ }|
  436. {0:~ }|
  437. {0:~ }|
  438. {0:~ }|
  439. {0:~ }|
  440. {0:~ }|
  441. {0:~ }|
  442. {0:~ }|
  443. |
  444. ]])
  445. feed(':echo "'..string.rep('x\\n', 12)..'"<cr>')
  446. screen:expect([[
  447. x |
  448. x |
  449. x |
  450. x |
  451. x |
  452. x |
  453. x |
  454. x |
  455. x |
  456. x |
  457. x |
  458. x |
  459. |
  460. {7:Press ENTER or type command to continue}^ |
  461. ]])
  462. feed('<cr>')
  463. screen:expect([[
  464. {4: [No Name] }{2: [No Name] }{3: }{4:X}|
  465. ^ |
  466. {0:~ }|
  467. {0:~ }|
  468. {0:~ }|
  469. {0:~ }|
  470. {0:~ }|
  471. {0:~ }|
  472. {0:~ }|
  473. {0:~ }|
  474. {0:~ }|
  475. {0:~ }|
  476. {0:~ }|
  477. |
  478. ]])
  479. end)
  480. it('redraws properly with :tab split right after scroll', function()
  481. feed('15Ofoo<esc>15Obar<esc>gg')
  482. command('vsplit')
  483. screen:expect([[
  484. ^foo {3:│}foo |
  485. foo {3:│}foo |
  486. foo {3:│}foo |
  487. foo {3:│}foo |
  488. foo {3:│}foo |
  489. foo {3:│}foo |
  490. foo {3:│}foo |
  491. foo {3:│}foo |
  492. foo {3:│}foo |
  493. foo {3:│}foo |
  494. foo {3:│}foo |
  495. foo {3:│}foo |
  496. {1:[No Name] [+] }{3:[No Name] [+] }|
  497. |
  498. ]])
  499. feed('<PageDown>')
  500. screen:expect([[
  501. ^foo {3:│}foo |
  502. foo {3:│}foo |
  503. foo {3:│}foo |
  504. foo {3:│}foo |
  505. bar {3:│}foo |
  506. bar {3:│}foo |
  507. bar {3:│}foo |
  508. bar {3:│}foo |
  509. bar {3:│}foo |
  510. bar {3:│}foo |
  511. bar {3:│}foo |
  512. bar {3:│}foo |
  513. {1:[No Name] [+] }{3:[No Name] [+] }|
  514. |
  515. ]])
  516. command('tab split')
  517. screen:expect([[
  518. {4: }{5:2}{4:+ [No Name] }{2: + [No Name] }{3: }{4:X}|
  519. ^foo |
  520. foo |
  521. foo |
  522. foo |
  523. bar |
  524. bar |
  525. bar |
  526. bar |
  527. bar |
  528. bar |
  529. bar |
  530. bar |
  531. |
  532. ]])
  533. end)
  534. it('redraws unvisited tab #9152', function()
  535. insert('hello')
  536. -- create a tab without visiting it
  537. command('tabnew|tabnext')
  538. screen:expect([[
  539. {2: + [No Name] }{4: [No Name] }{3: }{4:X}|
  540. hell^o |
  541. {0:~ }|
  542. {0:~ }|
  543. {0:~ }|
  544. {0:~ }|
  545. {0:~ }|
  546. {0:~ }|
  547. {0:~ }|
  548. {0:~ }|
  549. {0:~ }|
  550. {0:~ }|
  551. {0:~ }|
  552. |
  553. ]])
  554. feed('gT')
  555. screen:expect([[
  556. {4: + [No Name] }{2: [No Name] }{3: }{4:X}|
  557. ^ |
  558. {0:~ }|
  559. {0:~ }|
  560. {0:~ }|
  561. {0:~ }|
  562. {0:~ }|
  563. {0:~ }|
  564. {0:~ }|
  565. {0:~ }|
  566. {0:~ }|
  567. {0:~ }|
  568. {0:~ }|
  569. |
  570. ]])
  571. end)
  572. end)
  573. describe('insert mode', function()
  574. it('move to next line with <cr>', function()
  575. feed('iline 1<cr>line 2<cr>')
  576. screen:expect([[
  577. line 1 |
  578. line 2 |
  579. ^ |
  580. {0:~ }|
  581. {0:~ }|
  582. {0:~ }|
  583. {0:~ }|
  584. {0:~ }|
  585. {0:~ }|
  586. {0:~ }|
  587. {0:~ }|
  588. {0:~ }|
  589. {0:~ }|
  590. {2:-- INSERT --} |
  591. ]])
  592. end)
  593. end)
  594. describe('normal mode', function()
  595. -- https://code.google.com/p/vim/issues/detail?id=339
  596. it("setting 'ruler' doesn't reset the preferred column", function()
  597. command('set virtualedit=')
  598. feed('i0123456<cr>789<esc>kllj')
  599. command('set ruler')
  600. feed('k')
  601. screen:expect([[
  602. 0123^456 |
  603. 789 |
  604. {0:~ }|
  605. {0:~ }|
  606. {0:~ }|
  607. {0:~ }|
  608. {0:~ }|
  609. {0:~ }|
  610. {0:~ }|
  611. {0:~ }|
  612. {0:~ }|
  613. {0:~ }|
  614. {0:~ }|
  615. 1,5 All |
  616. ]])
  617. end)
  618. end)
  619. describe('command mode', function()
  620. it('typing commands', function()
  621. feed(':ls')
  622. screen:expect([[
  623. |
  624. {0:~ }|
  625. {0:~ }|
  626. {0:~ }|
  627. {0:~ }|
  628. {0:~ }|
  629. {0:~ }|
  630. {0:~ }|
  631. {0:~ }|
  632. {0:~ }|
  633. {0:~ }|
  634. {0:~ }|
  635. {0:~ }|
  636. :ls^ |
  637. ]])
  638. end)
  639. it('execute command with multi-line output without msgsep', function()
  640. command("set display-=msgsep")
  641. feed(':ls<cr>')
  642. screen:expect([[
  643. {0:~ }|
  644. {0:~ }|
  645. {0:~ }|
  646. {0:~ }|
  647. {0:~ }|
  648. {0:~ }|
  649. {0:~ }|
  650. {0:~ }|
  651. {0:~ }|
  652. {0:~ }|
  653. {0:~ }|
  654. :ls |
  655. 1 %a "[No Name]" line 1 |
  656. {7:Press ENTER or type command to continue}^ |
  657. ]])
  658. feed('<cr>') -- skip the "Press ENTER..." state or tests will hang
  659. end)
  660. it('execute command with multi-line output and with msgsep', function()
  661. command("set display+=msgsep")
  662. feed(':ls<cr>')
  663. screen:expect([[
  664. |
  665. {0:~ }|
  666. {0:~ }|
  667. {0:~ }|
  668. {0:~ }|
  669. {0:~ }|
  670. {0:~ }|
  671. {0:~ }|
  672. {0:~ }|
  673. {0:~ }|
  674. {1: }|
  675. :ls |
  676. 1 %a "[No Name]" line 1 |
  677. {7:Press ENTER or type command to continue}^ |
  678. ]])
  679. feed('<cr>') -- skip the "Press ENTER..." state or tests will hang
  680. end)
  681. end)
  682. describe('scrolling and clearing', function()
  683. before_each(function()
  684. insert([[
  685. Inserting
  686. text
  687. with
  688. many
  689. lines
  690. to
  691. test
  692. scrolling
  693. and
  694. clearing
  695. in
  696. split
  697. windows
  698. ]])
  699. command('sp')
  700. command('vsp')
  701. command('vsp')
  702. screen:expect([[
  703. and {3:│}and {3:│}and |
  704. clearing {3:│}clearing {3:│}clearing |
  705. in {3:│}in {3:│}in |
  706. split {3:│}split {3:│}split |
  707. windows {3:│}windows {3:│}windows |
  708. ^ {3:│} {3:│} |
  709. {1:[No Name] [+] }{3:[No Name] [+] [No Name] [+] }|
  710. clearing |
  711. in |
  712. split |
  713. windows |
  714. |
  715. {3:[No Name] [+] }|
  716. |
  717. ]])
  718. end)
  719. it('only affects the current scroll region', function()
  720. feed('6k')
  721. screen:expect([[
  722. ^scrolling {3:│}and {3:│}and |
  723. and {3:│}clearing {3:│}clearing |
  724. clearing {3:│}in {3:│}in |
  725. in {3:│}split {3:│}split |
  726. split {3:│}windows {3:│}windows |
  727. windows {3:│} {3:│} |
  728. {1:[No Name] [+] }{3:[No Name] [+] [No Name] [+] }|
  729. clearing |
  730. in |
  731. split |
  732. windows |
  733. |
  734. {3:[No Name] [+] }|
  735. |
  736. ]])
  737. feed('<c-w>l')
  738. screen:expect([[
  739. scrolling {3:│}and {3:│}and |
  740. and {3:│}clearing {3:│}clearing |
  741. clearing {3:│}in {3:│}in |
  742. in {3:│}split {3:│}split |
  743. split {3:│}windows {3:│}windows |
  744. windows {3:│}^ {3:│} |
  745. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  746. clearing |
  747. in |
  748. split |
  749. windows |
  750. |
  751. {3:[No Name] [+] }|
  752. |
  753. ]])
  754. feed('gg')
  755. screen:expect([[
  756. scrolling {3:│}^Inserting {3:│}and |
  757. and {3:│}text {3:│}clearing |
  758. clearing {3:│}with {3:│}in |
  759. in {3:│}many {3:│}split |
  760. split {3:│}lines {3:│}windows |
  761. windows {3:│}to {3:│} |
  762. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  763. clearing |
  764. in |
  765. split |
  766. windows |
  767. |
  768. {3:[No Name] [+] }|
  769. |
  770. ]])
  771. feed('7j')
  772. screen:expect([[
  773. scrolling {3:│}with {3:│}and |
  774. and {3:│}many {3:│}clearing |
  775. clearing {3:│}lines {3:│}in |
  776. in {3:│}to {3:│}split |
  777. split {3:│}test {3:│}windows |
  778. windows {3:│}^scrolling {3:│} |
  779. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  780. clearing |
  781. in |
  782. split |
  783. windows |
  784. |
  785. {3:[No Name] [+] }|
  786. |
  787. ]])
  788. feed('2j')
  789. screen:expect([[
  790. scrolling {3:│}lines {3:│}and |
  791. and {3:│}to {3:│}clearing |
  792. clearing {3:│}test {3:│}in |
  793. in {3:│}scrolling {3:│}split |
  794. split {3:│}and {3:│}windows |
  795. windows {3:│}^clearing {3:│} |
  796. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  797. clearing |
  798. in |
  799. split |
  800. windows |
  801. |
  802. {3:[No Name] [+] }|
  803. |
  804. ]])
  805. feed('5k')
  806. screen:expect([[
  807. scrolling {3:│}^lines {3:│}and |
  808. and {3:│}to {3:│}clearing |
  809. clearing {3:│}test {3:│}in |
  810. in {3:│}scrolling {3:│}split |
  811. split {3:│}and {3:│}windows |
  812. windows {3:│}clearing {3:│} |
  813. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  814. clearing |
  815. in |
  816. split |
  817. windows |
  818. |
  819. {3:[No Name] [+] }|
  820. |
  821. ]])
  822. feed('k')
  823. screen:expect([[
  824. scrolling {3:│}^many {3:│}and |
  825. and {3:│}lines {3:│}clearing |
  826. clearing {3:│}to {3:│}in |
  827. in {3:│}test {3:│}split |
  828. split {3:│}scrolling {3:│}windows |
  829. windows {3:│}and {3:│} |
  830. {3:[No Name] [+] }{1:[No Name] [+] }{3:<Name] [+] }|
  831. clearing |
  832. in |
  833. split |
  834. windows |
  835. |
  836. {3:[No Name] [+] }|
  837. |
  838. ]])
  839. end)
  840. end)
  841. describe('resize', function()
  842. before_each(function()
  843. screen:try_resize(25, 5)
  844. feed('iresize')
  845. end)
  846. it('rebuilds the whole screen', function()
  847. screen:expect([[
  848. resize^ |
  849. {0:~ }|
  850. {0:~ }|
  851. {0:~ }|
  852. {2:-- INSERT --} |
  853. ]])
  854. end)
  855. it('has minimum width/height values', function()
  856. screen:try_resize(1, 1)
  857. screen:expect([[
  858. resize^ |
  859. {2:-- INSERT -} |
  860. ]])
  861. feed('<esc>:ls')
  862. screen:expect([[
  863. resize |
  864. :ls^ |
  865. ]])
  866. end)
  867. end)
  868. describe('press enter', function()
  869. it('does not crash on <F1> at “Press ENTER”', function()
  870. command('nnoremap <F1> :echo "TEST"<CR>')
  871. feed(':ls<CR>')
  872. screen:expect([[
  873. |
  874. {0:~ }|
  875. {0:~ }|
  876. {0:~ }|
  877. {0:~ }|
  878. {0:~ }|
  879. {0:~ }|
  880. {0:~ }|
  881. {0:~ }|
  882. {0:~ }|
  883. {1: }|
  884. :ls |
  885. 1 %a "[No Name]" line 1 |
  886. {7:Press ENTER or type command to continue}^ |
  887. ]])
  888. feed('<F1>')
  889. screen:expect([[
  890. ^ |
  891. {0:~ }|
  892. {0:~ }|
  893. {0:~ }|
  894. {0:~ }|
  895. {0:~ }|
  896. {0:~ }|
  897. {0:~ }|
  898. {0:~ }|
  899. {0:~ }|
  900. {0:~ }|
  901. {0:~ }|
  902. {0:~ }|
  903. TEST |
  904. ]])
  905. end)
  906. end)
  907. -- Regression test for #8357
  908. it('does not have artifacts after temporary chars in insert mode', function()
  909. command('set timeoutlen=10000')
  910. command('inoremap jk <esc>')
  911. feed('ifooj')
  912. screen:expect([[
  913. foo^j |
  914. {0:~ }|
  915. {0:~ }|
  916. {0:~ }|
  917. {0:~ }|
  918. {0:~ }|
  919. {0:~ }|
  920. {0:~ }|
  921. {0:~ }|
  922. {0:~ }|
  923. {0:~ }|
  924. {0:~ }|
  925. {0:~ }|
  926. {2:-- INSERT --} |
  927. ]])
  928. feed('k')
  929. screen:expect([[
  930. fo^o |
  931. {0:~ }|
  932. {0:~ }|
  933. {0:~ }|
  934. {0:~ }|
  935. {0:~ }|
  936. {0:~ }|
  937. {0:~ }|
  938. {0:~ }|
  939. {0:~ }|
  940. {0:~ }|
  941. {0:~ }|
  942. {0:~ }|
  943. |
  944. ]])
  945. end)
  946. end
  947. describe("Screen (char-based)", function()
  948. screen_tests(false)
  949. end)
  950. describe("Screen (line-based)", function()
  951. screen_tests(true)
  952. end)
  953. describe('Screen default colors', function()
  954. local screen
  955. local function startup(light, termcolors)
  956. local extra = (light and ' background=light') or ''
  957. local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
  958. '--cmd', 'set shortmess+=I noswapfile belloff= noshowcmd noruler'..extra,
  959. '--embed'}
  960. local screen_nvim = spawn(nvim_argv)
  961. set_session(screen_nvim)
  962. screen = Screen.new()
  963. screen:attach(termcolors and {rgb=true,ext_termcolors=true} or {rgb=true})
  964. end
  965. it('are dark per default', function()
  966. startup(false, false)
  967. screen:expect{condition=function()
  968. eq({rgb_bg=0, rgb_fg=Screen.colors.White, rgb_sp=Screen.colors.Red,
  969. cterm_bg=0, cterm_fg=0}, screen.default_colors)
  970. end}
  971. end)
  972. it('can be set to light', function()
  973. startup(true, false)
  974. screen:expect{condition=function()
  975. eq({rgb_fg=Screen.colors.White, rgb_bg=0, rgb_sp=Screen.colors.Red,
  976. cterm_bg=0, cterm_fg=0}, screen.default_colors)
  977. end}
  978. end)
  979. it('can be handled by external terminal', function()
  980. startup(false, true)
  981. screen:expect{condition=function()
  982. eq({rgb_bg=-1, rgb_fg=-1, rgb_sp=-1, cterm_bg=0, cterm_fg=0}, screen.default_colors)
  983. end}
  984. startup(true, true)
  985. screen:expect{condition=function()
  986. eq({rgb_bg=-1, rgb_fg=-1, rgb_sp=-1, cterm_bg=0, cterm_fg=0}, screen.default_colors)
  987. end}
  988. end)
  989. end)
  990. describe('screen with msgsep deactivated on startup', function()
  991. local screen
  992. before_each(function()
  993. clear('--cmd', 'set display-=msgsep')
  994. screen = Screen.new()
  995. screen:attach()
  996. screen:set_default_attr_ids {
  997. [0] = {bold=true, foreground=255};
  998. [7] = {bold = true, foreground = Screen.colors.SeaGreen};
  999. }
  1000. end)
  1001. it('execute command with multi-line output', function()
  1002. feed ':ls<cr>'
  1003. screen:expect([[
  1004. {0:~ }|
  1005. {0:~ }|
  1006. {0:~ }|
  1007. {0:~ }|
  1008. {0:~ }|
  1009. {0:~ }|
  1010. {0:~ }|
  1011. {0:~ }|
  1012. {0:~ }|
  1013. {0:~ }|
  1014. {0:~ }|
  1015. :ls |
  1016. 1 %a "[No Name]" line 1 |
  1017. {7:Press ENTER or type command to continue}^ |
  1018. ]])
  1019. feed '<cr>' -- skip the "Press ENTER..." state or tests will hang
  1020. end)
  1021. end)