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