Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
| 2 | " This is split in two, because it can take a lot of time. |
| 3 | " See test_terminal.vim and test_terminal2.vim for further tests. |
| 4 | |
| 5 | source check.vim |
| 6 | CheckFeature terminal |
| 7 | |
| 8 | source shared.vim |
| 9 | source screendump.vim |
| 10 | source mouse.vim |
| 11 | source term_util.vim |
| 12 | |
| 13 | let $PROMPT_COMMAND='' |
| 14 | |
| 15 | func Test_terminal_altscreen() |
| 16 | " somehow doesn't work on MS-Windows |
| 17 | CheckUnix |
| 18 | let cmd = "cat Xtext\<CR>" |
| 19 | |
| 20 | let buf = term_start(&shell, {}) |
| 21 | call writefile(["\<Esc>[?1047h"], 'Xtext') |
| 22 | call term_sendkeys(buf, cmd) |
| 23 | call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) |
| 24 | |
| 25 | call writefile(["\<Esc>[?1047l"], 'Xtext') |
| 26 | call term_sendkeys(buf, cmd) |
| 27 | call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) |
| 28 | |
| 29 | call term_sendkeys(buf, "exit\r") |
| 30 | exe buf . "bwipe!" |
| 31 | call delete('Xtext') |
| 32 | endfunc |
| 33 | |
| 34 | func Test_terminal_shell_option() |
| 35 | if has('unix') |
| 36 | " exec is a shell builtin command, should fail without a shell. |
| 37 | term exec ls runtest.vim |
| 38 | call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))}) |
| 39 | bwipe! |
| 40 | |
| 41 | term ++shell exec ls runtest.vim |
| 42 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 43 | bwipe! |
| 44 | elseif has('win32') |
| 45 | " dir is a shell builtin command, should fail without a shell. |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 46 | " However, if dir.exe (which might be provided by Cygwin/MSYS2) exists in |
| 47 | " the %PATH%, "term dir" succeeds unintentionally. Use dir.com instead. |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 48 | try |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 49 | term dir.com /b runtest.vim |
| 50 | call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))}) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 51 | catch /CreateProcess/ |
| 52 | " ignore |
| 53 | endtry |
| 54 | bwipe! |
| 55 | |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 56 | " This should execute the dir builtin command even with ".com". |
| 57 | term ++shell dir.com /b runtest.vim |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 58 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 59 | bwipe! |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 60 | else |
| 61 | throw 'Skipped: does not work on this platform' |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 62 | endif |
| 63 | endfunc |
| 64 | |
| 65 | func Test_terminal_invalid_arg() |
| 66 | call assert_fails('terminal ++xyz', 'E181:') |
| 67 | endfunc |
| 68 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 69 | " Check a terminal with different colors |
| 70 | func Terminal_color(group_name, highlight_cmds, highlight_opt, open_cmds) |
| 71 | CheckRunVimInTerminal |
| 72 | CheckUnix |
| 73 | |
| 74 | let lines = [ |
| 75 | \ 'call setline(1, range(20))', |
| 76 | \ 'func OpenTerm()', |
| 77 | \ ' set noruler', |
| 78 | \ " call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})", |
| 79 | \ ] + a:open_cmds + [ |
| 80 | \ 'endfunc', |
| 81 | \ ] + a:highlight_cmds |
| 82 | call writefile(lines, 'XtermStart') |
| 83 | let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
| 84 | call TermWait(buf, 100) |
| 85 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 86 | call TermWait(buf, 50) |
| 87 | call term_sendkeys(buf, "hello\<CR>") |
| 88 | call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {}) |
| 89 | |
| 90 | call term_sendkeys(buf, "\<C-D>") |
| 91 | call TermWait(buf, 50) |
| 92 | call StopVimInTerminal(buf) |
| 93 | call delete('XtermStart') |
| 94 | endfunc |
| 95 | |
| 96 | func Test_terminal_color_Terminal() |
| 97 | call Terminal_color("Terminal", [ |
| 98 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 99 | \ ], "", []) |
| 100 | endfunc |
| 101 | |
| 102 | func Test_terminal_color_group() |
| 103 | call Terminal_color("MyTermCol", [ |
| 104 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 105 | \ ], "term_highlight: 'MyTermCol',", []) |
| 106 | endfunc |
| 107 | |
| 108 | func Test_terminal_color_wincolor() |
| 109 | call Terminal_color("MyWinCol", [ |
| 110 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 111 | \ ], "", [ |
| 112 | \ 'set wincolor=MyWinCol', |
| 113 | \ ]) |
| 114 | endfunc |
| 115 | |
| 116 | func Test_terminal_color_group_over_Terminal() |
| 117 | call Terminal_color("MyTermCol_over_Terminal", [ |
| 118 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 119 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 120 | \ ], "term_highlight: 'MyTermCol',", []) |
| 121 | endfunc |
| 122 | |
| 123 | func Test_terminal_color_wincolor_over_group() |
| 124 | call Terminal_color("MyWinCol_over_group", [ |
| 125 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 126 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 127 | \ ], "term_highlight: 'MyTermCol',", [ |
| 128 | \ 'set wincolor=MyWinCol', |
| 129 | \ ]) |
| 130 | endfunc |
| 131 | |
| 132 | func Test_terminal_color_wincolor_split() |
| 133 | CheckRunVimInTerminal |
| 134 | CheckUnix |
| 135 | |
| 136 | let lines = [ |
| 137 | \ 'call setline(1, range(20))', |
| 138 | \ 'func OpenTerm()', |
| 139 | \ ' set noruler', |
| 140 | \ " call term_start('cat', #{vertical: 1, term_highlight: 'MyTermCol'})", |
| 141 | \ 'endfunc', |
| 142 | \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue', |
| 143 | \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow', |
| 144 | \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue', |
| 145 | \ ] |
| 146 | call writefile(lines, 'XtermStart') |
| 147 | let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
| 148 | call TermWait(buf, 100) |
| 149 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 150 | call TermWait(buf, 50) |
| 151 | call term_sendkeys(buf, "hello\<CR>") |
| 152 | call TermWait(buf, 50) |
| 153 | |
| 154 | call term_sendkeys(buf, "\<C-W>:split\<CR>") |
| 155 | call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol\<CR>") |
| 156 | call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol', {}) |
| 157 | |
| 158 | call term_sendkeys(buf, "\<C-W>b:2sb\<CR>") |
| 159 | call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol2\<CR>") |
| 160 | call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {}) |
| 161 | |
| 162 | call term_sendkeys(buf, "\<C-D>") |
| 163 | call TermWait(buf, 50) |
| 164 | call StopVimInTerminal(buf) |
| 165 | call delete('XtermStart') |
| 166 | endfunc |
| 167 | |
| 168 | func Test_terminal_color_transp_Terminal() |
| 169 | call Terminal_color("transp_Terminal", [ |
| 170 | \ "highlight Terminal ctermfg=blue", |
| 171 | \ ], "", []) |
| 172 | endfunc |
| 173 | |
| 174 | func Test_terminal_color_transp_group() |
| 175 | call Terminal_color("transp_MyTermCol", [ |
| 176 | \ "highlight MyTermCol ctermfg=darkgreen", |
| 177 | \ ], "term_highlight: 'MyTermCol',", []) |
| 178 | endfunc |
| 179 | |
| 180 | func Test_terminal_color_transp_wincolor() |
| 181 | call Terminal_color("transp_MyWinCol", [ |
| 182 | \ "highlight MyWinCol ctermfg=red", |
| 183 | \ ], "", [ |
| 184 | \ 'set wincolor=MyWinCol', |
| 185 | \ ]) |
| 186 | endfunc |
| 187 | |
| 188 | func Test_terminal_color_gui_Terminal() |
| 189 | CheckFeature termguicolors |
| 190 | call Terminal_color("gui_Terminal", [ |
| 191 | \ "set termguicolors", |
| 192 | \ "highlight Terminal guifg=#3344ff guibg=#b0a700", |
| 193 | \ ], "", []) |
| 194 | endfunc |
| 195 | |
| 196 | func Test_terminal_color_gui_group() |
| 197 | CheckFeature termguicolors |
| 198 | call Terminal_color("gui_MyTermCol", [ |
| 199 | \ "set termguicolors", |
| 200 | \ "highlight MyTermCol guifg=#007800 guibg=#6789ff", |
| 201 | \ ], "term_highlight: 'MyTermCol',", []) |
| 202 | endfunc |
| 203 | |
| 204 | func Test_terminal_color_gui_wincolor() |
| 205 | CheckFeature termguicolors |
| 206 | call Terminal_color("gui_MyWinCol", [ |
| 207 | \ "set termguicolors", |
| 208 | \ "highlight MyWinCol guifg=#fe1122 guibg=#818100", |
| 209 | \ ], "", [ |
| 210 | \ 'set wincolor=MyWinCol', |
| 211 | \ ]) |
| 212 | endfunc |
| 213 | |
| 214 | func Test_terminal_color_gui_transp_Terminal() |
| 215 | CheckFeature termguicolors |
| 216 | call Terminal_color("gui_transp_Terminal", [ |
| 217 | \ "set termguicolors", |
| 218 | \ "highlight Terminal guifg=#3344ff", |
| 219 | \ ], "", []) |
| 220 | endfunc |
| 221 | |
| 222 | func Test_terminal_color_gui_transp_group() |
| 223 | CheckFeature termguicolors |
| 224 | call Terminal_color("gui_transp_MyTermCol", [ |
| 225 | \ "set termguicolors", |
| 226 | \ "highlight MyTermCol guifg=#007800", |
| 227 | \ ], "term_highlight: 'MyTermCol',", []) |
| 228 | endfunc |
| 229 | |
| 230 | func Test_terminal_color_gui_transp_wincolor() |
| 231 | CheckFeature termguicolors |
| 232 | call Terminal_color("gui_transp_MyWinCol", [ |
| 233 | \ "set termguicolors", |
| 234 | \ "highlight MyWinCol guifg=#fe1122", |
| 235 | \ ], "", [ |
| 236 | \ 'set wincolor=MyWinCol', |
| 237 | \ ]) |
| 238 | endfunc |
| 239 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 240 | func Test_terminal_in_popup() |
| 241 | CheckRunVimInTerminal |
| 242 | |
| 243 | let text =<< trim END |
| 244 | some text |
| 245 | to edit |
| 246 | in a popup window |
| 247 | END |
| 248 | call writefile(text, 'Xtext') |
| 249 | let cmd = GetVimCommandCleanTerm() |
| 250 | let lines = [ |
| 251 | \ 'call setline(1, range(20))', |
| 252 | \ 'hi PopTerm ctermbg=grey', |
| 253 | \ 'func OpenTerm(setColor)', |
| 254 | \ " set noruler", |
| 255 | \ " let s:buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})", |
| 256 | \ ' let g:winid = popup_create(s:buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})', |
| 257 | \ ' if a:setColor', |
| 258 | \ ' call win_execute(g:winid, "set wincolor=PopTerm")', |
| 259 | \ ' endif', |
| 260 | \ 'endfunc', |
| 261 | \ 'func HidePopup()', |
| 262 | \ ' call popup_hide(g:winid)', |
| 263 | \ 'endfunc', |
| 264 | \ 'func ClosePopup()', |
| 265 | \ ' call popup_close(g:winid)', |
| 266 | \ 'endfunc', |
| 267 | \ 'func ReopenPopup()', |
| 268 | \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})', |
| 269 | \ 'endfunc', |
| 270 | \ ] |
| 271 | call writefile(lines, 'XtermPopup') |
| 272 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
| 273 | call TermWait(buf, 100) |
| 274 | call term_sendkeys(buf, ":call OpenTerm(0)\<CR>") |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 275 | call TermWait(buf, 500) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 276 | call term_sendkeys(buf, ":\<CR>") |
| 277 | call TermWait(buf, 100) |
| 278 | call term_sendkeys(buf, "\<C-W>:echo getwinvar(g:winid, \"&buftype\") win_gettype(g:winid)\<CR>") |
| 279 | call VerifyScreenDump(buf, 'Test_terminal_popup_1', {}) |
| 280 | |
| 281 | call term_sendkeys(buf, ":q\<CR>") |
| 282 | call VerifyScreenDump(buf, 'Test_terminal_popup_2', {}) |
| 283 | |
| 284 | call term_sendkeys(buf, ":call OpenTerm(1)\<CR>") |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 285 | call TermWait(buf, 500) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 286 | call term_sendkeys(buf, ":set hlsearch\<CR>") |
| 287 | call TermWait(buf, 100) |
| 288 | call term_sendkeys(buf, "/edit\<CR>") |
| 289 | call VerifyScreenDump(buf, 'Test_terminal_popup_3', {}) |
| 290 | |
| 291 | call term_sendkeys(buf, "\<C-W>:call HidePopup()\<CR>") |
| 292 | call VerifyScreenDump(buf, 'Test_terminal_popup_4', {}) |
| 293 | call term_sendkeys(buf, "\<CR>") |
| 294 | call TermWait(buf, 50) |
| 295 | |
| 296 | call term_sendkeys(buf, "\<C-W>:call ClosePopup()\<CR>") |
| 297 | call VerifyScreenDump(buf, 'Test_terminal_popup_5', {}) |
| 298 | |
| 299 | call term_sendkeys(buf, "\<C-W>:call ReopenPopup()\<CR>") |
| 300 | call VerifyScreenDump(buf, 'Test_terminal_popup_6', {}) |
| 301 | |
| 302 | " Go to terminal-Normal mode and visually select text. |
| 303 | call term_sendkeys(buf, "\<C-W>Ngg/in\<CR>vww") |
| 304 | call VerifyScreenDump(buf, 'Test_terminal_popup_7', {}) |
| 305 | |
| 306 | " Back to job mode, redraws |
| 307 | call term_sendkeys(buf, "A") |
| 308 | call VerifyScreenDump(buf, 'Test_terminal_popup_8', {}) |
| 309 | |
| 310 | call TermWait(buf, 50) |
| 311 | call term_sendkeys(buf, ":q\<CR>") |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 312 | call TermWait(buf, 250) " wait for terminal to vanish |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 313 | |
| 314 | call StopVimInTerminal(buf) |
| 315 | call delete('Xtext') |
| 316 | call delete('XtermPopup') |
| 317 | endfunc |
| 318 | |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 319 | " Check a terminal in popup window uses the default minimum size. |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 320 | func Test_terminal_in_popup_min_size() |
| 321 | CheckRunVimInTerminal |
| 322 | |
| 323 | let text =<< trim END |
| 324 | another text |
| 325 | to show |
| 326 | in a popup window |
| 327 | END |
| 328 | call writefile(text, 'Xtext') |
| 329 | let lines = [ |
| 330 | \ 'call setline(1, range(20))', |
| 331 | \ 'func OpenTerm()', |
| 332 | \ " let s:buf = term_start('cat Xtext', #{hidden: 1})", |
| 333 | \ ' let g:winid = popup_create(s:buf, #{ border: []})', |
| 334 | \ 'endfunc', |
| 335 | \ ] |
| 336 | call writefile(lines, 'XtermPopup') |
| 337 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
| 338 | call TermWait(buf, 100) |
| 339 | call term_sendkeys(buf, ":set noruler\<CR>") |
| 340 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 341 | call TermWait(buf, 50) |
| 342 | call term_sendkeys(buf, ":\<CR>") |
| 343 | call VerifyScreenDump(buf, 'Test_terminal_popup_m1', {}) |
| 344 | |
| 345 | call TermWait(buf, 50) |
| 346 | call term_sendkeys(buf, ":q\<CR>") |
| 347 | call TermWait(buf, 50) " wait for terminal to vanish |
| 348 | call StopVimInTerminal(buf) |
| 349 | call delete('Xtext') |
| 350 | call delete('XtermPopup') |
| 351 | endfunc |
| 352 | |
| 353 | " Check a terminal in popup window with different colors |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 354 | func Terminal_in_popup_color(group_name, highlight_cmds, highlight_opt, popup_cmds, popup_opt) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 355 | CheckRunVimInTerminal |
| 356 | CheckUnix |
| 357 | |
| 358 | let lines = [ |
| 359 | \ 'call setline(1, range(20))', |
| 360 | \ 'func OpenTerm()', |
| 361 | \ " let s:buf = term_start('cat', #{hidden: 1, " |
| 362 | \ .. a:highlight_opt .. "})", |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 363 | \ ' let g:winid = popup_create(s:buf, #{border: [], ' |
| 364 | \ .. a:popup_opt .. '})', |
| 365 | \ ] + a:popup_cmds + [ |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 366 | \ 'endfunc', |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 367 | \ ] + a:highlight_cmds |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 368 | call writefile(lines, 'XtermPopup') |
| 369 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
| 370 | call TermWait(buf, 100) |
| 371 | call term_sendkeys(buf, ":set noruler\<CR>") |
| 372 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 373 | call TermWait(buf, 50) |
| 374 | call term_sendkeys(buf, "hello\<CR>") |
| 375 | call VerifyScreenDump(buf, 'Test_terminal_popup_' .. a:group_name, {}) |
| 376 | |
| 377 | call term_sendkeys(buf, "\<C-D>") |
| 378 | call TermWait(buf, 50) |
| 379 | call term_sendkeys(buf, ":q\<CR>") |
| 380 | call TermWait(buf, 50) " wait for terminal to vanish |
| 381 | call StopVimInTerminal(buf) |
| 382 | call delete('XtermPopup') |
| 383 | endfunc |
| 384 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 385 | func Test_terminal_in_popup_color_Terminal() |
| 386 | call Terminal_in_popup_color("Terminal", [ |
| 387 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 388 | \ ], "", [], "") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 389 | endfunc |
| 390 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 391 | func Test_terminal_in_popup_color_group() |
| 392 | call Terminal_in_popup_color("MyTermCol", [ |
| 393 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 394 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 395 | endfunc |
| 396 | |
| 397 | func Test_terminal_in_popup_color_wincolor() |
| 398 | call Terminal_in_popup_color("MyWinCol", [ |
| 399 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 400 | \ ], "", [ |
| 401 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 402 | \ ], "") |
| 403 | endfunc |
| 404 | |
| 405 | func Test_terminal_in_popup_color_popup_highlight() |
| 406 | call Terminal_in_popup_color("MyPopupHlCol", [ |
| 407 | \ "highlight MyPopupHlCol ctermfg=cyan ctermbg=green", |
| 408 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 409 | endfunc |
| 410 | |
| 411 | func Test_terminal_in_popup_color_group_over_Terminal() |
| 412 | call Terminal_in_popup_color("MyTermCol_over_Terminal", [ |
| 413 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 414 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 415 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 416 | endfunc |
| 417 | |
| 418 | func Test_terminal_in_popup_color_wincolor_over_group() |
| 419 | call Terminal_in_popup_color("MyWinCol_over_group", [ |
| 420 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 421 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 422 | \ ], "term_highlight: 'MyTermCol',", [ |
| 423 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 424 | \ ], "") |
| 425 | endfunc |
| 426 | |
| 427 | func Test_terminal_in_popup_color_transp_Terminal() |
| 428 | call Terminal_in_popup_color("transp_Terminal", [ |
| 429 | \ "highlight Terminal ctermfg=blue", |
| 430 | \ ], "", [], "") |
| 431 | endfunc |
| 432 | |
| 433 | func Test_terminal_in_popup_color_transp_group() |
| 434 | call Terminal_in_popup_color("transp_MyTermCol", [ |
| 435 | \ "highlight MyTermCol ctermfg=darkgreen", |
| 436 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 437 | endfunc |
| 438 | |
| 439 | func Test_terminal_in_popup_color_transp_wincolor() |
| 440 | call Terminal_in_popup_color("transp_MyWinCol", [ |
| 441 | \ "highlight MyWinCol ctermfg=red", |
| 442 | \ ], "", [ |
| 443 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 444 | \ ], "") |
| 445 | endfunc |
| 446 | |
| 447 | func Test_terminal_in_popup_color_transp_popup_highlight() |
| 448 | call Terminal_in_popup_color("transp_MyPopupHlCol", [ |
| 449 | \ "highlight MyPopupHlCol ctermfg=cyan", |
| 450 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 451 | endfunc |
| 452 | |
| 453 | func Test_terminal_in_popup_color_gui_Terminal() |
| 454 | CheckFeature termguicolors |
| 455 | call Terminal_in_popup_color("gui_Terminal", [ |
| 456 | \ "set termguicolors", |
| 457 | \ "highlight Terminal guifg=#3344ff guibg=#b0a700", |
| 458 | \ ], "", [], "") |
| 459 | endfunc |
| 460 | |
| 461 | func Test_terminal_in_popup_color_gui_group() |
| 462 | CheckFeature termguicolors |
| 463 | call Terminal_in_popup_color("gui_MyTermCol", [ |
| 464 | \ "set termguicolors", |
| 465 | \ "highlight MyTermCol guifg=#007800 guibg=#6789ff", |
| 466 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 467 | endfunc |
| 468 | |
| 469 | func Test_terminal_in_popup_color_gui_wincolor() |
| 470 | CheckFeature termguicolors |
| 471 | call Terminal_in_popup_color("gui_MyWinCol", [ |
| 472 | \ "set termguicolors", |
| 473 | \ "highlight MyWinCol guifg=#fe1122 guibg=#818100", |
| 474 | \ ], "", [ |
| 475 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 476 | \ ], "") |
| 477 | endfunc |
| 478 | |
| 479 | func Test_terminal_in_popup_color_gui_popup_highlight() |
| 480 | CheckFeature termguicolors |
| 481 | call Terminal_in_popup_color("gui_MyPopupHlCol", [ |
| 482 | \ "set termguicolors", |
| 483 | \ "highlight MyPopupHlCol guifg=#00e8f0 guibg=#126521", |
| 484 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 485 | endfunc |
| 486 | |
| 487 | func Test_terminal_in_popup_color_gui_transp_Terminal() |
| 488 | CheckFeature termguicolors |
| 489 | call Terminal_in_popup_color("gui_transp_Terminal", [ |
| 490 | \ "set termguicolors", |
| 491 | \ "highlight Terminal guifg=#3344ff", |
| 492 | \ ], "", [], "") |
| 493 | endfunc |
| 494 | |
| 495 | func Test_terminal_in_popup_color_gui_transp_group() |
| 496 | CheckFeature termguicolors |
| 497 | call Terminal_in_popup_color("gui_transp_MyTermCol", [ |
| 498 | \ "set termguicolors", |
| 499 | \ "highlight MyTermCol guifg=#007800", |
| 500 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 501 | endfunc |
| 502 | |
| 503 | func Test_terminal_in_popup_color_gui_transp_wincolor() |
| 504 | CheckFeature termguicolors |
| 505 | call Terminal_in_popup_color("gui_transp_MyWinCol", [ |
| 506 | \ "set termguicolors", |
| 507 | \ "highlight MyWinCol guifg=#fe1122", |
| 508 | \ ], "", [ |
| 509 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 510 | \ ], "") |
| 511 | endfunc |
| 512 | |
| 513 | func Test_terminal_in_popup_color_gui_transp_popup_highlight() |
| 514 | CheckFeature termguicolors |
| 515 | call Terminal_in_popup_color("gui_transp_MyPopupHlCol", [ |
| 516 | \ "set termguicolors", |
| 517 | \ "highlight MyPopupHlCol guifg=#00e8f0", |
| 518 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 519 | endfunc |
| 520 | |
| 521 | func Test_double_popup_terminal() |
| 522 | let buf1 = term_start(&shell, #{hidden: 1}) |
| 523 | let win1 = popup_create(buf1, {}) |
| 524 | let buf2 = term_start(&shell, #{hidden: 1}) |
| 525 | call assert_fails('call popup_create(buf2, {})', 'E861:') |
| 526 | call popup_close(win1) |
| 527 | exe buf1 .. 'bwipe!' |
| 528 | exe buf2 .. 'bwipe!' |
| 529 | endfunc |
| 530 | |
LemonBoy | 4a392d2 | 2022-04-23 14:07:56 +0100 | [diff] [blame] | 531 | func Test_escape_popup_terminal() |
| 532 | set hidden |
| 533 | |
| 534 | " Cannot escape a terminal popup window using win_gotoid |
| 535 | let prev_win = win_getid() |
| 536 | eval term_start('sh', #{hidden: 1, term_finish: 'close'})->popup_create({}) |
| 537 | call assert_fails("call win_gotoid(" .. prev_win .. ")", 'E863:') |
| 538 | |
| 539 | call popup_clear(1) |
| 540 | set hidden& |
| 541 | endfunc |
| 542 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 543 | func Test_issue_5607() |
| 544 | let wincount = winnr('$') |
| 545 | exe 'terminal' &shell &shellcmdflag 'exit' |
| 546 | let job = term_getjob(bufnr()) |
| 547 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 548 | |
| 549 | let old_wincolor = &wincolor |
| 550 | try |
| 551 | set wincolor= |
| 552 | finally |
| 553 | let &wincolor = old_wincolor |
| 554 | bw! |
| 555 | endtry |
| 556 | endfunc |
| 557 | |
| 558 | func Test_hidden_terminal() |
| 559 | let buf = term_start(&shell, #{hidden: 1}) |
| 560 | call assert_equal('', bufname('^$')) |
| 561 | call StopShellInTerminal(buf) |
| 562 | endfunc |
| 563 | |
| 564 | func Test_term_nasty_callback() |
| 565 | CheckExecutable sh |
| 566 | |
| 567 | set hidden |
| 568 | let g:buf0 = term_start('sh', #{hidden: 1, term_finish: 'close'}) |
| 569 | call popup_create(g:buf0, {}) |
| 570 | call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:') |
| 571 | |
| 572 | call popup_clear(1) |
| 573 | set hidden& |
| 574 | endfunc |
| 575 | |
| 576 | func Test_term_and_startinsert() |
| 577 | CheckRunVimInTerminal |
| 578 | CheckUnix |
| 579 | |
| 580 | let lines =<< trim EOL |
| 581 | put='some text' |
| 582 | term |
| 583 | startinsert |
| 584 | EOL |
| 585 | call writefile(lines, 'XTest_startinsert') |
| 586 | let buf = RunVimInTerminal('-S XTest_startinsert', {}) |
| 587 | |
| 588 | call term_sendkeys(buf, "exit\r") |
| 589 | call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))}) |
| 590 | call term_sendkeys(buf, "0l") |
| 591 | call term_sendkeys(buf, "A<\<Esc>") |
| 592 | call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))}) |
| 593 | |
| 594 | call StopVimInTerminal(buf) |
| 595 | call delete('XTest_startinsert') |
| 596 | endfunc |
| 597 | |
| 598 | " Test for passing invalid arguments to terminal functions |
| 599 | func Test_term_func_invalid_arg() |
| 600 | call assert_fails('let b = term_getaltscreen([])', 'E745:') |
| 601 | call assert_fails('let a = term_getattr(1, [])', 'E730:') |
| 602 | call assert_fails('let c = term_getcursor([])', 'E745:') |
| 603 | call assert_fails('let l = term_getline([], 1)', 'E745:') |
| 604 | call assert_fails('let l = term_getscrolled([])', 'E745:') |
| 605 | call assert_fails('let s = term_getsize([])', 'E745:') |
| 606 | call assert_fails('let s = term_getstatus([])', 'E745:') |
| 607 | call assert_fails('let s = term_scrape([], 1)', 'E745:') |
| 608 | call assert_fails('call term_sendkeys([], "a")', 'E745:') |
| 609 | call assert_fails('call term_setapi([], "")', 'E745:') |
| 610 | call assert_fails('call term_setrestore([], "")', 'E745:') |
| 611 | call assert_fails('call term_setkill([], "")', 'E745:') |
| 612 | if has('gui') || has('termguicolors') |
| 613 | call assert_fails('let p = term_getansicolors([])', 'E745:') |
| 614 | call assert_fails('call term_setansicolors([], [])', 'E745:') |
| 615 | endif |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 616 | let buf = term_start('echo') |
| 617 | call assert_fails('call term_setapi(' .. buf .. ', {})', 'E731:') |
| 618 | call assert_fails('call term_setkill(' .. buf .. ', {})', 'E731:') |
| 619 | call assert_fails('call term_setrestore(' .. buf .. ', {})', 'E731:') |
| 620 | exe buf . "bwipe!" |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 621 | endfunc |
| 622 | |
| 623 | " Test for sending various special keycodes to a terminal |
| 624 | func Test_term_keycode_translation() |
| 625 | CheckRunVimInTerminal |
| 626 | |
| 627 | let buf = RunVimInTerminal('', {}) |
| 628 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 629 | call term_sendkeys(buf, ":set timeoutlen=20\<CR>") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 630 | |
| 631 | let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>", |
| 632 | \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>", |
| 633 | \ "\<S-Home>", "\<C-Home>", "\<End>", "\<S-End>", "\<C-End>", |
| 634 | \ "\<Ins>", "\<Del>", "\<Left>", "\<S-Left>", "\<C-Left>", "\<Right>", |
| 635 | \ "\<S-Right>", "\<C-Right>", "\<Up>", "\<S-Up>", "\<Down>", |
| 636 | \ "\<S-Down>"] |
| 637 | let output = ['<F1>', '<F2>', '<F3>', '<F4>', '<F5>', '<F6>', '<F7>', |
| 638 | \ '<F8>', '<F9>', '<F10>', '<F11>', '<F12>', '<Home>', '<S-Home>', |
| 639 | \ '<C-Home>', '<End>', '<S-End>', '<C-End>', '<Insert>', '<Del>', |
| 640 | \ '<Left>', '<S-Left>', '<C-Left>', '<Right>', '<S-Right>', |
| 641 | \ '<C-Right>', '<Up>', '<S-Up>', '<Down>', '<S-Down>'] |
| 642 | |
| 643 | call term_sendkeys(buf, "i") |
| 644 | for i in range(len(keys)) |
| 645 | call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i]) |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 646 | call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))}, 200) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 647 | endfor |
| 648 | |
| 649 | let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>", |
| 650 | \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>", |
| 651 | \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"] |
| 652 | let keypad_output = ['0', '1', '2', '3', '4', '5', |
| 653 | \ '6', '7', '8', '9', '.', '+', |
| 654 | \ '-', '*', '/'] |
| 655 | for i in range(len(keypad_keys)) |
| 656 | " TODO: Mysteriously keypad 3 and 9 do not work on some systems. |
| 657 | if keypad_output[i] == '3' || keypad_output[i] == '9' |
| 658 | continue |
| 659 | endif |
| 660 | call term_sendkeys(buf, "\<C-U>" .. keypad_keys[i]) |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 661 | call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))}, 100) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 662 | endfor |
| 663 | |
| 664 | call feedkeys("\<C-U>\<kEnter>\<BS>one\<C-W>.two", 'xt') |
| 665 | call WaitForAssert({-> assert_equal('two', term_getline(buf, 1))}) |
| 666 | |
| 667 | call StopVimInTerminal(buf) |
| 668 | endfunc |
| 669 | |
| 670 | " Test for using the mouse in a terminal |
| 671 | func Test_term_mouse() |
| 672 | CheckNotGui |
| 673 | CheckRunVimInTerminal |
| 674 | |
| 675 | let save_mouse = &mouse |
| 676 | let save_term = &term |
| 677 | let save_ttymouse = &ttymouse |
| 678 | let save_clipboard = &clipboard |
| 679 | set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= |
| 680 | |
| 681 | let lines =<< trim END |
| 682 | one two three four five |
| 683 | red green yellow red blue |
| 684 | vim emacs sublime nano |
| 685 | END |
| 686 | call writefile(lines, 'Xtest_mouse') |
| 687 | |
| 688 | " Create a terminal window running Vim for the test with mouse enabled |
| 689 | let prev_win = win_getid() |
| 690 | let buf = RunVimInTerminal('Xtest_mouse -n', {}) |
| 691 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
| 692 | call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>") |
| 693 | call term_sendkeys(buf, ":set clipboard=\<CR>") |
| 694 | call term_sendkeys(buf, ":set mousemodel=extend\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 695 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 696 | redraw! |
| 697 | |
| 698 | " Use the mouse to enter the terminal window |
| 699 | call win_gotoid(prev_win) |
| 700 | call feedkeys(MouseLeftClickCode(1, 1), 'x') |
| 701 | call feedkeys(MouseLeftReleaseCode(1, 1), 'x') |
| 702 | call assert_equal(1, getwininfo(win_getid())[0].terminal) |
| 703 | |
| 704 | " Test for <LeftMouse> click/release |
| 705 | call test_setmouse(2, 5) |
| 706 | call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt') |
| 707 | call test_setmouse(3, 8) |
| 708 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 709 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 710 | call term_sendkeys(buf, ":call writefile([json_encode(getpos('.'))], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 711 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 712 | let pos = json_decode(readfile('Xbuf')[0]) |
| 713 | call assert_equal([3, 8], pos[1:2]) |
| 714 | |
| 715 | " Test for selecting text using mouse |
| 716 | call delete('Xbuf') |
| 717 | call test_setmouse(2, 11) |
| 718 | call term_sendkeys(buf, "\<LeftMouse>") |
| 719 | call test_setmouse(2, 16) |
| 720 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 721 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 722 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 723 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 724 | call assert_equal('yellow', readfile('Xbuf')[0]) |
| 725 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 726 | " Test for selecting text using double click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 727 | call delete('Xbuf') |
| 728 | call test_setmouse(1, 11) |
| 729 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>") |
| 730 | call test_setmouse(1, 17) |
| 731 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 732 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 733 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 734 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 735 | call assert_equal('three four', readfile('Xbuf')[0]) |
| 736 | |
| 737 | " Test for selecting a line using triple click |
| 738 | call delete('Xbuf') |
| 739 | call test_setmouse(3, 2) |
| 740 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 741 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 742 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 743 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 744 | call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0]) |
| 745 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 746 | " Test for selecting a block using quadruple click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 747 | call delete('Xbuf') |
| 748 | call test_setmouse(1, 11) |
| 749 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>") |
| 750 | call test_setmouse(3, 13) |
| 751 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 752 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 753 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 754 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 755 | call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0]) |
| 756 | |
| 757 | " Test for extending a selection using right click |
| 758 | call delete('Xbuf') |
| 759 | call test_setmouse(2, 9) |
| 760 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>") |
| 761 | call test_setmouse(2, 16) |
| 762 | call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 763 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 764 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 765 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 766 | call assert_equal("n yellow", readfile('Xbuf')[0]) |
| 767 | |
| 768 | " Test for pasting text using middle click |
| 769 | call delete('Xbuf') |
| 770 | call term_sendkeys(buf, ":let @r='bright '\<CR>") |
| 771 | call test_setmouse(2, 22) |
| 772 | call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 773 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 774 | call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 775 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 776 | call assert_equal("red bright blue", readfile('Xbuf')[0][-15:]) |
| 777 | |
| 778 | " cleanup |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 779 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 780 | call StopVimInTerminal(buf) |
| 781 | let &mouse = save_mouse |
| 782 | let &term = save_term |
| 783 | let &ttymouse = save_ttymouse |
| 784 | let &clipboard = save_clipboard |
| 785 | set mousetime& |
| 786 | call delete('Xtest_mouse') |
| 787 | call delete('Xbuf') |
| 788 | endfunc |
| 789 | |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 790 | " Test for sync buffer cwd with shell's pwd |
| 791 | func Test_terminal_sync_shell_dir() |
| 792 | CheckUnix |
| 793 | " The test always use sh (see src/testdir/unix.vim). |
Bram Moolenaar | 7bfa6d6 | 2022-01-14 12:06:47 +0000 | [diff] [blame] | 794 | " BSD's sh doesn't seem to play well with the OSC 7 escape sequence. |
| 795 | CheckNotBSD |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 796 | |
| 797 | set asd |
| 798 | " , is |
| 799 | " 1. a valid character for directory names |
| 800 | " 2. a reserved character in url-encoding |
| 801 | let chars = ",a" |
| 802 | " "," is url-encoded as '%2C' |
| 803 | let chars_url = "%2Ca" |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 804 | let tmpfolder = fnamemodify(tempname(),':h') .. '/' .. chars |
| 805 | let tmpfolder_url = fnamemodify(tempname(),':h') .. '/' .. chars_url |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 806 | call mkdir(tmpfolder, "p") |
| 807 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 808 | call term_sendkeys(buf, "echo $'\\e\]7;file://" .. tmpfolder_url .. "\\a'\<CR>") |
| 809 | "call term_sendkeys(buf, "cd " .. tmpfolder .. "\<CR>") |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 810 | call TermWait(buf) |
| 811 | if has("mac") |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 812 | let expected = "/private" .. tmpfolder |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 813 | else |
| 814 | let expected = tmpfolder |
| 815 | endif |
| 816 | call assert_equal(expected, getcwd(winnr())) |
Bram Moolenaar | 82820d9 | 2021-03-30 20:54:28 +0200 | [diff] [blame] | 817 | |
| 818 | set noasd |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 819 | endfunc |
| 820 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 821 | " Test for modeless selection in a terminal |
| 822 | func Test_term_modeless_selection() |
| 823 | CheckUnix |
| 824 | CheckNotGui |
| 825 | CheckRunVimInTerminal |
| 826 | CheckFeature clipboard_working |
| 827 | |
| 828 | let save_mouse = &mouse |
| 829 | let save_term = &term |
| 830 | let save_ttymouse = &ttymouse |
| 831 | set mouse=a term=xterm ttymouse=sgr mousetime=200 |
| 832 | set clipboard=autoselectml |
| 833 | |
| 834 | let lines =<< trim END |
| 835 | one two three four five |
| 836 | red green yellow red blue |
| 837 | vim emacs sublime nano |
| 838 | END |
| 839 | call writefile(lines, 'Xtest_modeless') |
| 840 | |
| 841 | " Create a terminal window running Vim for the test with mouse disabled |
| 842 | let prev_win = win_getid() |
| 843 | let buf = RunVimInTerminal('Xtest_modeless -n', {}) |
| 844 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
| 845 | call term_sendkeys(buf, ":set mouse=\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 846 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 847 | redraw! |
| 848 | |
| 849 | " Use the mouse to enter the terminal window |
| 850 | call win_gotoid(prev_win) |
| 851 | call feedkeys(MouseLeftClickCode(1, 1), 'x') |
| 852 | call feedkeys(MouseLeftReleaseCode(1, 1), 'x') |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 853 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 854 | call assert_equal(1, getwininfo(win_getid())[0].terminal) |
| 855 | |
| 856 | " Test for copying a modeless selection to clipboard |
| 857 | let @* = 'clean' |
| 858 | " communicating with X server may take a little time |
| 859 | sleep 100m |
| 860 | call feedkeys(MouseLeftClickCode(2, 3), 'x') |
| 861 | call feedkeys(MouseLeftDragCode(2, 11), 'x') |
| 862 | call feedkeys(MouseLeftReleaseCode(2, 11), 'x') |
| 863 | call assert_equal("d green y", @*) |
| 864 | |
| 865 | " cleanup |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 866 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 867 | call StopVimInTerminal(buf) |
| 868 | let &mouse = save_mouse |
| 869 | let &term = save_term |
| 870 | let &ttymouse = save_ttymouse |
| 871 | set mousetime& clipboard& |
| 872 | call delete('Xtest_modeless') |
| 873 | new | only! |
| 874 | endfunc |
| 875 | |
Bram Moolenaar | a4b4426 | 2020-07-12 21:38:29 +0200 | [diff] [blame] | 876 | func Test_terminal_getwinpos() |
| 877 | CheckRunVimInTerminal |
| 878 | |
| 879 | " split, go to the bottom-right window |
| 880 | split |
| 881 | wincmd j |
| 882 | set splitright |
| 883 | |
Bram Moolenaar | 4209521 | 2020-07-21 21:48:58 +0200 | [diff] [blame] | 884 | let buf = RunVimInTerminal('', {'cols': 60}) |
| 885 | call TermWait(buf, 100) |
| 886 | call term_sendkeys(buf, ":echo getwinpos(500)\<CR>") |
Bram Moolenaar | a4b4426 | 2020-07-12 21:38:29 +0200 | [diff] [blame] | 887 | |
| 888 | " Find the output of getwinpos() in the bottom line. |
| 889 | let rows = term_getsize(buf)[0] |
| 890 | call WaitForAssert({-> assert_match('\[\d\+, \d\+\]', term_getline(buf, rows))}) |
| 891 | let line = term_getline(buf, rows) |
| 892 | let xpos = str2nr(substitute(line, '\[\(\d\+\), \d\+\]', '\1', '')) |
| 893 | let ypos = str2nr(substitute(line, '\[\d\+, \(\d\+\)\]', '\1', '')) |
| 894 | |
| 895 | " Position must be bigger than the getwinpos() result of Vim itself. |
| 896 | " The calculation in the console assumes a 10 x 7 character cell. |
| 897 | " In the GUI it can be more, let's assume a 20 x 14 cell. |
| 898 | " And then add 100 / 200 tolerance. |
| 899 | let [xroot, yroot] = getwinpos() |
| 900 | let winpos = 50->getwinpos() |
| 901 | call assert_equal(xroot, winpos[0]) |
| 902 | call assert_equal(yroot, winpos[1]) |
Bram Moolenaar | 7dfc5ce | 2020-09-05 15:05:30 +0200 | [diff] [blame] | 903 | let [winrow, wincol] = win_screenpos(0) |
Bram Moolenaar | a4b4426 | 2020-07-12 21:38:29 +0200 | [diff] [blame] | 904 | let xoff = wincol * (has('gui_running') ? 14 : 7) + 100 |
| 905 | let yoff = winrow * (has('gui_running') ? 20 : 10) + 200 |
| 906 | call assert_inrange(xroot + 2, xroot + xoff, xpos) |
| 907 | call assert_inrange(yroot + 2, yroot + yoff, ypos) |
| 908 | |
| 909 | call TermWait(buf) |
| 910 | call term_sendkeys(buf, ":q\<CR>") |
| 911 | call StopVimInTerminal(buf) |
Bram Moolenaar | a4b4426 | 2020-07-12 21:38:29 +0200 | [diff] [blame] | 912 | set splitright& |
| 913 | only! |
| 914 | endfunc |
| 915 | |
ichizok | c3f91c0 | 2021-12-17 09:44:33 +0000 | [diff] [blame] | 916 | func Test_terminal_term_start_error() |
| 917 | func s:term_start_error() abort |
| 918 | try |
| 919 | return term_start([[]]) |
| 920 | catch |
| 921 | return v:exception |
| 922 | finally |
| 923 | " |
| 924 | endtry |
| 925 | endfunc |
| 926 | autocmd WinEnter * call type(0) |
| 927 | |
| 928 | " Must not crash in s:term_start_error, nor the exception thrown. |
| 929 | let result = s:term_start_error() |
| 930 | call assert_match('^Vim(return):E730:', result) |
| 931 | |
| 932 | autocmd! WinEnter |
| 933 | delfunc s:term_start_error |
| 934 | endfunc |
| 935 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 936 | |
| 937 | " vim: shiftwidth=2 sts=2 expandtab |