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 | |
Yegappan Lakshmanan | d603e95 | 2024-06-10 18:16:34 +0200 | [diff] [blame] | 13 | import './vim9.vim' as v9 |
| 14 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 15 | let $PROMPT_COMMAND='' |
| 16 | |
| 17 | func Test_terminal_altscreen() |
| 18 | " somehow doesn't work on MS-Windows |
| 19 | CheckUnix |
| 20 | let cmd = "cat Xtext\<CR>" |
| 21 | |
| 22 | let buf = term_start(&shell, {}) |
Yegappan Lakshmanan | e446a01 | 2023-01-19 17:49:58 +0000 | [diff] [blame] | 23 | call TermWait(buf) |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 24 | call writefile(["\<Esc>[?1047h"], 'Xtext', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 25 | call term_sendkeys(buf, cmd) |
| 26 | call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) |
| 27 | |
| 28 | call writefile(["\<Esc>[?1047l"], 'Xtext') |
| 29 | call term_sendkeys(buf, cmd) |
| 30 | call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) |
| 31 | |
| 32 | call term_sendkeys(buf, "exit\r") |
| 33 | exe buf . "bwipe!" |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 34 | endfunc |
| 35 | |
| 36 | func Test_terminal_shell_option() |
| 37 | if has('unix') |
| 38 | " exec is a shell builtin command, should fail without a shell. |
| 39 | term exec ls runtest.vim |
| 40 | call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))}) |
| 41 | bwipe! |
| 42 | |
| 43 | term ++shell exec ls runtest.vim |
| 44 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 45 | bwipe! |
| 46 | elseif has('win32') |
| 47 | " dir is a shell builtin command, should fail without a shell. |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 48 | " However, if dir.exe (which might be provided by Cygwin/MSYS2) exists in |
| 49 | " the %PATH%, "term dir" succeeds unintentionally. Use dir.com instead. |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 50 | try |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 51 | term dir.com /b runtest.vim |
| 52 | call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))}) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 53 | catch /CreateProcess/ |
| 54 | " ignore |
| 55 | endtry |
| 56 | bwipe! |
| 57 | |
Bram Moolenaar | 066b12e | 2020-07-28 21:40:27 +0200 | [diff] [blame] | 58 | " This should execute the dir builtin command even with ".com". |
| 59 | term ++shell dir.com /b runtest.vim |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 60 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 61 | bwipe! |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 62 | else |
| 63 | throw 'Skipped: does not work on this platform' |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 64 | endif |
| 65 | endfunc |
| 66 | |
| 67 | func Test_terminal_invalid_arg() |
| 68 | call assert_fails('terminal ++xyz', 'E181:') |
| 69 | endfunc |
| 70 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 71 | " Check a terminal with different colors |
| 72 | func Terminal_color(group_name, highlight_cmds, highlight_opt, open_cmds) |
| 73 | CheckRunVimInTerminal |
| 74 | CheckUnix |
| 75 | |
| 76 | let lines = [ |
| 77 | \ 'call setline(1, range(20))', |
| 78 | \ 'func OpenTerm()', |
| 79 | \ ' set noruler', |
| 80 | \ " call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})", |
| 81 | \ ] + a:open_cmds + [ |
| 82 | \ 'endfunc', |
| 83 | \ ] + a:highlight_cmds |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 84 | call writefile(lines, 'XtermStart', 'D') |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 85 | let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
| 86 | call TermWait(buf, 100) |
| 87 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 88 | call TermWait(buf, 50) |
| 89 | call term_sendkeys(buf, "hello\<CR>") |
| 90 | call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {}) |
| 91 | |
| 92 | call term_sendkeys(buf, "\<C-D>") |
| 93 | call TermWait(buf, 50) |
| 94 | call StopVimInTerminal(buf) |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 95 | endfunc |
| 96 | |
| 97 | func Test_terminal_color_Terminal() |
| 98 | call Terminal_color("Terminal", [ |
| 99 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 100 | \ ], "", []) |
| 101 | endfunc |
| 102 | |
| 103 | func Test_terminal_color_group() |
| 104 | call Terminal_color("MyTermCol", [ |
| 105 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 106 | \ ], "term_highlight: 'MyTermCol',", []) |
| 107 | endfunc |
| 108 | |
| 109 | func Test_terminal_color_wincolor() |
| 110 | call Terminal_color("MyWinCol", [ |
| 111 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 112 | \ ], "", [ |
| 113 | \ 'set wincolor=MyWinCol', |
| 114 | \ ]) |
| 115 | endfunc |
| 116 | |
| 117 | func Test_terminal_color_group_over_Terminal() |
| 118 | call Terminal_color("MyTermCol_over_Terminal", [ |
| 119 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 120 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 121 | \ ], "term_highlight: 'MyTermCol',", []) |
| 122 | endfunc |
| 123 | |
| 124 | func Test_terminal_color_wincolor_over_group() |
| 125 | call Terminal_color("MyWinCol_over_group", [ |
| 126 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 127 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 128 | \ ], "term_highlight: 'MyTermCol',", [ |
| 129 | \ 'set wincolor=MyWinCol', |
| 130 | \ ]) |
| 131 | endfunc |
| 132 | |
| 133 | func Test_terminal_color_wincolor_split() |
| 134 | CheckRunVimInTerminal |
| 135 | CheckUnix |
| 136 | |
| 137 | let lines = [ |
| 138 | \ 'call setline(1, range(20))', |
| 139 | \ 'func OpenTerm()', |
| 140 | \ ' set noruler', |
| 141 | \ " call term_start('cat', #{vertical: 1, term_highlight: 'MyTermCol'})", |
| 142 | \ 'endfunc', |
| 143 | \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue', |
| 144 | \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow', |
| 145 | \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue', |
| 146 | \ ] |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 147 | call writefile(lines, 'XtermStart', 'D') |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 148 | let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
| 149 | call TermWait(buf, 100) |
| 150 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 151 | call TermWait(buf, 50) |
| 152 | call term_sendkeys(buf, "hello\<CR>") |
| 153 | call TermWait(buf, 50) |
| 154 | |
| 155 | call term_sendkeys(buf, "\<C-W>:split\<CR>") |
| 156 | call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol\<CR>") |
| 157 | call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol', {}) |
| 158 | |
| 159 | call term_sendkeys(buf, "\<C-W>b:2sb\<CR>") |
| 160 | call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol2\<CR>") |
| 161 | call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {}) |
| 162 | |
| 163 | call term_sendkeys(buf, "\<C-D>") |
| 164 | call TermWait(buf, 50) |
| 165 | call StopVimInTerminal(buf) |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 248 | call writefile(text, 'Xtext', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 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 | \ ] |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 271 | call writefile(lines, 'XtermPopup', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 272 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 273 | call TermWait(buf, 200) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 274 | call term_sendkeys(buf, ":call OpenTerm(0)\<CR>") |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 275 | call TermWait(buf, 800) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 276 | call term_sendkeys(buf, ":\<CR>") |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 277 | call TermWait(buf, 500) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 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>") |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 285 | call TermWait(buf, 800) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 286 | call term_sendkeys(buf, ":set hlsearch\<CR>") |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 287 | call TermWait(buf, 500) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 315 | endfunc |
| 316 | |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 317 | " Check a terminal in popup window uses the default minimum size. |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 318 | func Test_terminal_in_popup_min_size() |
| 319 | CheckRunVimInTerminal |
| 320 | |
| 321 | let text =<< trim END |
| 322 | another text |
| 323 | to show |
| 324 | in a popup window |
| 325 | END |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 326 | call writefile(text, 'Xtext', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 327 | let lines = [ |
| 328 | \ 'call setline(1, range(20))', |
| 329 | \ 'func OpenTerm()', |
| 330 | \ " let s:buf = term_start('cat Xtext', #{hidden: 1})", |
| 331 | \ ' let g:winid = popup_create(s:buf, #{ border: []})', |
| 332 | \ 'endfunc', |
| 333 | \ ] |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 334 | call writefile(lines, 'XtermPopup', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 335 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
| 336 | call TermWait(buf, 100) |
| 337 | call term_sendkeys(buf, ":set noruler\<CR>") |
| 338 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 339 | call TermWait(buf, 50) |
| 340 | call term_sendkeys(buf, ":\<CR>") |
| 341 | call VerifyScreenDump(buf, 'Test_terminal_popup_m1', {}) |
| 342 | |
| 343 | call TermWait(buf, 50) |
| 344 | call term_sendkeys(buf, ":q\<CR>") |
| 345 | call TermWait(buf, 50) " wait for terminal to vanish |
| 346 | call StopVimInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 347 | endfunc |
| 348 | |
| 349 | " Check a terminal in popup window with different colors |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 350 | 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] | 351 | CheckRunVimInTerminal |
| 352 | CheckUnix |
| 353 | |
| 354 | let lines = [ |
| 355 | \ 'call setline(1, range(20))', |
| 356 | \ 'func OpenTerm()', |
| 357 | \ " let s:buf = term_start('cat', #{hidden: 1, " |
| 358 | \ .. a:highlight_opt .. "})", |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 359 | \ ' let g:winid = popup_create(s:buf, #{border: [], ' |
| 360 | \ .. a:popup_opt .. '})', |
| 361 | \ ] + a:popup_cmds + [ |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 362 | \ 'endfunc', |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 363 | \ ] + a:highlight_cmds |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 364 | call writefile(lines, 'XtermPopup', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 365 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
| 366 | call TermWait(buf, 100) |
| 367 | call term_sendkeys(buf, ":set noruler\<CR>") |
| 368 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 369 | call TermWait(buf, 50) |
| 370 | call term_sendkeys(buf, "hello\<CR>") |
| 371 | call VerifyScreenDump(buf, 'Test_terminal_popup_' .. a:group_name, {}) |
| 372 | |
| 373 | call term_sendkeys(buf, "\<C-D>") |
| 374 | call TermWait(buf, 50) |
| 375 | call term_sendkeys(buf, ":q\<CR>") |
| 376 | call TermWait(buf, 50) " wait for terminal to vanish |
| 377 | call StopVimInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 378 | endfunc |
| 379 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 380 | func Test_terminal_in_popup_color_Terminal() |
| 381 | call Terminal_in_popup_color("Terminal", [ |
| 382 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 383 | \ ], "", [], "") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 384 | endfunc |
| 385 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 386 | func Test_terminal_in_popup_color_group() |
| 387 | call Terminal_in_popup_color("MyTermCol", [ |
| 388 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 389 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 390 | endfunc |
| 391 | |
| 392 | func Test_terminal_in_popup_color_wincolor() |
| 393 | call Terminal_in_popup_color("MyWinCol", [ |
| 394 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 395 | \ ], "", [ |
| 396 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 397 | \ ], "") |
| 398 | endfunc |
| 399 | |
| 400 | func Test_terminal_in_popup_color_popup_highlight() |
| 401 | call Terminal_in_popup_color("MyPopupHlCol", [ |
| 402 | \ "highlight MyPopupHlCol ctermfg=cyan ctermbg=green", |
| 403 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 404 | endfunc |
| 405 | |
| 406 | func Test_terminal_in_popup_color_group_over_Terminal() |
| 407 | call Terminal_in_popup_color("MyTermCol_over_Terminal", [ |
| 408 | \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
| 409 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 410 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 411 | endfunc |
| 412 | |
| 413 | func Test_terminal_in_popup_color_wincolor_over_group() |
| 414 | call Terminal_in_popup_color("MyWinCol_over_group", [ |
| 415 | \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue", |
| 416 | \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow", |
| 417 | \ ], "term_highlight: 'MyTermCol',", [ |
| 418 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 419 | \ ], "") |
| 420 | endfunc |
| 421 | |
| 422 | func Test_terminal_in_popup_color_transp_Terminal() |
| 423 | call Terminal_in_popup_color("transp_Terminal", [ |
| 424 | \ "highlight Terminal ctermfg=blue", |
| 425 | \ ], "", [], "") |
| 426 | endfunc |
| 427 | |
| 428 | func Test_terminal_in_popup_color_transp_group() |
| 429 | call Terminal_in_popup_color("transp_MyTermCol", [ |
| 430 | \ "highlight MyTermCol ctermfg=darkgreen", |
| 431 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 432 | endfunc |
| 433 | |
| 434 | func Test_terminal_in_popup_color_transp_wincolor() |
| 435 | call Terminal_in_popup_color("transp_MyWinCol", [ |
| 436 | \ "highlight MyWinCol ctermfg=red", |
| 437 | \ ], "", [ |
| 438 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 439 | \ ], "") |
| 440 | endfunc |
| 441 | |
| 442 | func Test_terminal_in_popup_color_transp_popup_highlight() |
| 443 | call Terminal_in_popup_color("transp_MyPopupHlCol", [ |
| 444 | \ "highlight MyPopupHlCol ctermfg=cyan", |
| 445 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 446 | endfunc |
| 447 | |
| 448 | func Test_terminal_in_popup_color_gui_Terminal() |
| 449 | CheckFeature termguicolors |
| 450 | call Terminal_in_popup_color("gui_Terminal", [ |
| 451 | \ "set termguicolors", |
| 452 | \ "highlight Terminal guifg=#3344ff guibg=#b0a700", |
| 453 | \ ], "", [], "") |
| 454 | endfunc |
| 455 | |
| 456 | func Test_terminal_in_popup_color_gui_group() |
| 457 | CheckFeature termguicolors |
| 458 | call Terminal_in_popup_color("gui_MyTermCol", [ |
| 459 | \ "set termguicolors", |
| 460 | \ "highlight MyTermCol guifg=#007800 guibg=#6789ff", |
| 461 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 462 | endfunc |
| 463 | |
| 464 | func Test_terminal_in_popup_color_gui_wincolor() |
| 465 | CheckFeature termguicolors |
| 466 | call Terminal_in_popup_color("gui_MyWinCol", [ |
| 467 | \ "set termguicolors", |
| 468 | \ "highlight MyWinCol guifg=#fe1122 guibg=#818100", |
| 469 | \ ], "", [ |
| 470 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 471 | \ ], "") |
| 472 | endfunc |
| 473 | |
| 474 | func Test_terminal_in_popup_color_gui_popup_highlight() |
| 475 | CheckFeature termguicolors |
| 476 | call Terminal_in_popup_color("gui_MyPopupHlCol", [ |
| 477 | \ "set termguicolors", |
| 478 | \ "highlight MyPopupHlCol guifg=#00e8f0 guibg=#126521", |
| 479 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
| 480 | endfunc |
| 481 | |
| 482 | func Test_terminal_in_popup_color_gui_transp_Terminal() |
| 483 | CheckFeature termguicolors |
| 484 | call Terminal_in_popup_color("gui_transp_Terminal", [ |
| 485 | \ "set termguicolors", |
| 486 | \ "highlight Terminal guifg=#3344ff", |
| 487 | \ ], "", [], "") |
| 488 | endfunc |
| 489 | |
| 490 | func Test_terminal_in_popup_color_gui_transp_group() |
| 491 | CheckFeature termguicolors |
| 492 | call Terminal_in_popup_color("gui_transp_MyTermCol", [ |
| 493 | \ "set termguicolors", |
| 494 | \ "highlight MyTermCol guifg=#007800", |
| 495 | \ ], "term_highlight: 'MyTermCol',", [], "") |
| 496 | endfunc |
| 497 | |
| 498 | func Test_terminal_in_popup_color_gui_transp_wincolor() |
| 499 | CheckFeature termguicolors |
| 500 | call Terminal_in_popup_color("gui_transp_MyWinCol", [ |
| 501 | \ "set termguicolors", |
| 502 | \ "highlight MyWinCol guifg=#fe1122", |
| 503 | \ ], "", [ |
| 504 | \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")', |
| 505 | \ ], "") |
| 506 | endfunc |
| 507 | |
| 508 | func Test_terminal_in_popup_color_gui_transp_popup_highlight() |
| 509 | CheckFeature termguicolors |
| 510 | call Terminal_in_popup_color("gui_transp_MyPopupHlCol", [ |
| 511 | \ "set termguicolors", |
| 512 | \ "highlight MyPopupHlCol guifg=#00e8f0", |
| 513 | \ ], "", [], "highlight: 'MyPopupHlCol'") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 514 | endfunc |
| 515 | |
| 516 | func Test_double_popup_terminal() |
| 517 | let buf1 = term_start(&shell, #{hidden: 1}) |
| 518 | let win1 = popup_create(buf1, {}) |
| 519 | let buf2 = term_start(&shell, #{hidden: 1}) |
| 520 | call assert_fails('call popup_create(buf2, {})', 'E861:') |
| 521 | call popup_close(win1) |
| 522 | exe buf1 .. 'bwipe!' |
| 523 | exe buf2 .. 'bwipe!' |
| 524 | endfunc |
| 525 | |
LemonBoy | 4a392d2 | 2022-04-23 14:07:56 +0100 | [diff] [blame] | 526 | func Test_escape_popup_terminal() |
| 527 | set hidden |
| 528 | |
| 529 | " Cannot escape a terminal popup window using win_gotoid |
| 530 | let prev_win = win_getid() |
| 531 | eval term_start('sh', #{hidden: 1, term_finish: 'close'})->popup_create({}) |
| 532 | call assert_fails("call win_gotoid(" .. prev_win .. ")", 'E863:') |
| 533 | |
| 534 | call popup_clear(1) |
| 535 | set hidden& |
| 536 | endfunc |
| 537 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 538 | func Test_issue_5607() |
| 539 | let wincount = winnr('$') |
| 540 | exe 'terminal' &shell &shellcmdflag 'exit' |
| 541 | let job = term_getjob(bufnr()) |
| 542 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 543 | |
| 544 | let old_wincolor = &wincolor |
| 545 | try |
| 546 | set wincolor= |
| 547 | finally |
| 548 | let &wincolor = old_wincolor |
| 549 | bw! |
| 550 | endtry |
| 551 | endfunc |
| 552 | |
| 553 | func Test_hidden_terminal() |
| 554 | let buf = term_start(&shell, #{hidden: 1}) |
| 555 | call assert_equal('', bufname('^$')) |
| 556 | call StopShellInTerminal(buf) |
| 557 | endfunc |
| 558 | |
| 559 | func Test_term_nasty_callback() |
| 560 | CheckExecutable sh |
| 561 | |
| 562 | set hidden |
| 563 | let g:buf0 = term_start('sh', #{hidden: 1, term_finish: 'close'}) |
| 564 | call popup_create(g:buf0, {}) |
| 565 | call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:') |
| 566 | |
| 567 | call popup_clear(1) |
| 568 | set hidden& |
| 569 | endfunc |
| 570 | |
| 571 | func Test_term_and_startinsert() |
| 572 | CheckRunVimInTerminal |
| 573 | CheckUnix |
| 574 | |
| 575 | let lines =<< trim EOL |
| 576 | put='some text' |
| 577 | term |
| 578 | startinsert |
| 579 | EOL |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 580 | call writefile(lines, 'XTest_startinsert', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 581 | let buf = RunVimInTerminal('-S XTest_startinsert', {}) |
| 582 | |
| 583 | call term_sendkeys(buf, "exit\r") |
| 584 | call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))}) |
| 585 | call term_sendkeys(buf, "0l") |
| 586 | call term_sendkeys(buf, "A<\<Esc>") |
| 587 | call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))}) |
| 588 | |
| 589 | call StopVimInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 590 | endfunc |
| 591 | |
| 592 | " Test for passing invalid arguments to terminal functions |
| 593 | func Test_term_func_invalid_arg() |
| 594 | call assert_fails('let b = term_getaltscreen([])', 'E745:') |
| 595 | call assert_fails('let a = term_getattr(1, [])', 'E730:') |
| 596 | call assert_fails('let c = term_getcursor([])', 'E745:') |
| 597 | call assert_fails('let l = term_getline([], 1)', 'E745:') |
| 598 | call assert_fails('let l = term_getscrolled([])', 'E745:') |
| 599 | call assert_fails('let s = term_getsize([])', 'E745:') |
| 600 | call assert_fails('let s = term_getstatus([])', 'E745:') |
| 601 | call assert_fails('let s = term_scrape([], 1)', 'E745:') |
| 602 | call assert_fails('call term_sendkeys([], "a")', 'E745:') |
| 603 | call assert_fails('call term_setapi([], "")', 'E745:') |
| 604 | call assert_fails('call term_setrestore([], "")', 'E745:') |
| 605 | call assert_fails('call term_setkill([], "")', 'E745:') |
| 606 | if has('gui') || has('termguicolors') |
| 607 | call assert_fails('let p = term_getansicolors([])', 'E745:') |
| 608 | call assert_fails('call term_setansicolors([], [])', 'E745:') |
| 609 | endif |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 610 | let buf = term_start('echo') |
| 611 | call assert_fails('call term_setapi(' .. buf .. ', {})', 'E731:') |
| 612 | call assert_fails('call term_setkill(' .. buf .. ', {})', 'E731:') |
| 613 | call assert_fails('call term_setrestore(' .. buf .. ', {})', 'E731:') |
| 614 | exe buf . "bwipe!" |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 615 | endfunc |
| 616 | |
| 617 | " Test for sending various special keycodes to a terminal |
| 618 | func Test_term_keycode_translation() |
| 619 | CheckRunVimInTerminal |
| 620 | |
| 621 | let buf = RunVimInTerminal('', {}) |
| 622 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 623 | call term_sendkeys(buf, ":set timeoutlen=20\<CR>") |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 624 | |
| 625 | let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>", |
| 626 | \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>", |
| 627 | \ "\<S-Home>", "\<C-Home>", "\<End>", "\<S-End>", "\<C-End>", |
| 628 | \ "\<Ins>", "\<Del>", "\<Left>", "\<S-Left>", "\<C-Left>", "\<Right>", |
| 629 | \ "\<S-Right>", "\<C-Right>", "\<Up>", "\<S-Up>", "\<Down>", |
| 630 | \ "\<S-Down>"] |
| 631 | let output = ['<F1>', '<F2>', '<F3>', '<F4>', '<F5>', '<F6>', '<F7>', |
| 632 | \ '<F8>', '<F9>', '<F10>', '<F11>', '<F12>', '<Home>', '<S-Home>', |
| 633 | \ '<C-Home>', '<End>', '<S-End>', '<C-End>', '<Insert>', '<Del>', |
| 634 | \ '<Left>', '<S-Left>', '<C-Left>', '<Right>', '<S-Right>', |
| 635 | \ '<C-Right>', '<Up>', '<S-Up>', '<Down>', '<S-Down>'] |
| 636 | |
| 637 | call term_sendkeys(buf, "i") |
| 638 | for i in range(len(keys)) |
| 639 | call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i]) |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 640 | call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))}, 200) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 641 | endfor |
| 642 | |
| 643 | let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>", |
| 644 | \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>", |
| 645 | \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"] |
| 646 | let keypad_output = ['0', '1', '2', '3', '4', '5', |
| 647 | \ '6', '7', '8', '9', '.', '+', |
| 648 | \ '-', '*', '/'] |
| 649 | for i in range(len(keypad_keys)) |
| 650 | " TODO: Mysteriously keypad 3 and 9 do not work on some systems. |
| 651 | if keypad_output[i] == '3' || keypad_output[i] == '9' |
| 652 | continue |
| 653 | endif |
| 654 | call term_sendkeys(buf, "\<C-U>" .. keypad_keys[i]) |
Bram Moolenaar | 4d8c96d | 2020-12-29 20:53:33 +0100 | [diff] [blame] | 655 | call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))}, 100) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 656 | endfor |
| 657 | |
| 658 | call feedkeys("\<C-U>\<kEnter>\<BS>one\<C-W>.two", 'xt') |
| 659 | call WaitForAssert({-> assert_equal('two', term_getline(buf, 1))}) |
| 660 | |
| 661 | call StopVimInTerminal(buf) |
| 662 | endfunc |
| 663 | |
| 664 | " Test for using the mouse in a terminal |
| 665 | func Test_term_mouse() |
| 666 | CheckNotGui |
| 667 | CheckRunVimInTerminal |
| 668 | |
| 669 | let save_mouse = &mouse |
| 670 | let save_term = &term |
| 671 | let save_ttymouse = &ttymouse |
| 672 | let save_clipboard = &clipboard |
| 673 | set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= |
| 674 | |
| 675 | let lines =<< trim END |
| 676 | one two three four five |
| 677 | red green yellow red blue |
| 678 | vim emacs sublime nano |
| 679 | END |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 680 | call writefile(lines, 'Xtest_mouse', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 681 | |
| 682 | " Create a terminal window running Vim for the test with mouse enabled |
| 683 | let prev_win = win_getid() |
| 684 | let buf = RunVimInTerminal('Xtest_mouse -n', {}) |
| 685 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
| 686 | call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>") |
| 687 | call term_sendkeys(buf, ":set clipboard=\<CR>") |
| 688 | call term_sendkeys(buf, ":set mousemodel=extend\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 689 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 690 | redraw! |
| 691 | |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 692 | " Funcref used in WaitFor() to check that the "Xbuf" file is readable and |
| 693 | " has some contents. This avoids a "List index out of range" error when the |
| 694 | " file hasn't been written yet. |
| 695 | let XbufNotEmpty = {-> filereadable('Xbuf') && len(readfile('Xbuf')) > 0} |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 696 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 697 | " Use the mouse to enter the terminal window |
| 698 | call win_gotoid(prev_win) |
| 699 | call feedkeys(MouseLeftClickCode(1, 1), 'x') |
| 700 | call feedkeys(MouseLeftReleaseCode(1, 1), 'x') |
| 701 | call assert_equal(1, getwininfo(win_getid())[0].terminal) |
| 702 | |
| 703 | " Test for <LeftMouse> click/release |
| 704 | call test_setmouse(2, 5) |
| 705 | call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt') |
| 706 | call test_setmouse(3, 8) |
| 707 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 708 | call TermWait(buf, 50) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 709 | call delete('Xbuf') |
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 | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 712 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 713 | let pos = json_decode(readfile('Xbuf')[0]) |
| 714 | call assert_equal([3, 8], pos[1:2]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 715 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 716 | |
| 717 | " Test for selecting text using mouse |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 718 | call test_setmouse(2, 11) |
| 719 | call term_sendkeys(buf, "\<LeftMouse>") |
| 720 | call test_setmouse(2, 16) |
| 721 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 722 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 723 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 724 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 1d139a0 | 2022-11-10 00:09:22 +0000 | [diff] [blame] | 725 | call WaitForAssert({-> assert_equal('yellow', readfile('Xbuf')[0])}) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 726 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 727 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 728 | " Test for selecting text using double click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 729 | call test_setmouse(1, 11) |
| 730 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>") |
| 731 | call test_setmouse(1, 17) |
| 732 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 733 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 734 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 735 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 736 | call assert_equal('three four', readfile('Xbuf')[0]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 737 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 738 | |
| 739 | " Test for selecting a line using triple click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 740 | call test_setmouse(3, 2) |
| 741 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 742 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 743 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 744 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 745 | call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 746 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 747 | |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 748 | " Test for selecting a block using quadruple click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 749 | call test_setmouse(1, 11) |
| 750 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>") |
| 751 | call test_setmouse(3, 13) |
| 752 | call term_sendkeys(buf, "\<LeftRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 753 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 754 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 755 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 756 | call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 757 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 758 | |
| 759 | " Test for extending a selection using right click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 760 | call test_setmouse(2, 9) |
| 761 | call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>") |
| 762 | call test_setmouse(2, 16) |
| 763 | call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 764 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 765 | call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 766 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 767 | call assert_equal("n yellow", readfile('Xbuf')[0]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 768 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 769 | |
| 770 | " Test for pasting text using middle click |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 771 | call term_sendkeys(buf, ":let @r='bright '\<CR>") |
| 772 | call test_setmouse(2, 22) |
| 773 | call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 774 | call TermWait(buf, 50) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 775 | call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>") |
Bram Moolenaar | 98aebcc | 2022-11-10 12:38:16 +0000 | [diff] [blame] | 776 | call WaitFor(XbufNotEmpty) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 777 | call assert_equal("red bright blue", readfile('Xbuf')[0][-15:]) |
James McCoy | 157241e | 2022-11-09 23:29:14 +0000 | [diff] [blame] | 778 | call delete('Xbuf') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 779 | |
| 780 | " cleanup |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 781 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 782 | call StopVimInTerminal(buf) |
| 783 | let &mouse = save_mouse |
| 784 | let &term = save_term |
| 785 | let &ttymouse = save_ttymouse |
| 786 | let &clipboard = save_clipboard |
| 787 | set mousetime& |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 788 | call delete('Xbuf') |
| 789 | endfunc |
| 790 | |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 791 | " Test for sync buffer cwd with shell's pwd |
| 792 | func Test_terminal_sync_shell_dir() |
| 793 | CheckUnix |
| 794 | " The test always use sh (see src/testdir/unix.vim). |
Bram Moolenaar | 7bfa6d6 | 2022-01-14 12:06:47 +0000 | [diff] [blame] | 795 | " BSD's sh doesn't seem to play well with the OSC 7 escape sequence. |
| 796 | CheckNotBSD |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 797 | |
| 798 | set asd |
| 799 | " , is |
| 800 | " 1. a valid character for directory names |
| 801 | " 2. a reserved character in url-encoding |
| 802 | let chars = ",a" |
| 803 | " "," is url-encoded as '%2C' |
| 804 | let chars_url = "%2Ca" |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 805 | let tmpfolder = fnamemodify(tempname(),':h') .. '/' .. chars |
| 806 | let tmpfolder_url = fnamemodify(tempname(),':h') .. '/' .. chars_url |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 807 | call mkdir(tmpfolder, "p") |
| 808 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 809 | call term_sendkeys(buf, "echo $'\\e\]7;file://" .. tmpfolder_url .. "\\a'\<CR>") |
| 810 | "call term_sendkeys(buf, "cd " .. tmpfolder .. "\<CR>") |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 811 | call TermWait(buf) |
| 812 | if has("mac") |
Bram Moolenaar | ced2b38 | 2022-01-13 15:25:32 +0000 | [diff] [blame] | 813 | let expected = "/private" .. tmpfolder |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 814 | else |
| 815 | let expected = tmpfolder |
| 816 | endif |
| 817 | call assert_equal(expected, getcwd(winnr())) |
Bram Moolenaar | 82820d9 | 2021-03-30 20:54:28 +0200 | [diff] [blame] | 818 | |
| 819 | set noasd |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 820 | endfunc |
| 821 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 822 | " Test for modeless selection in a terminal |
| 823 | func Test_term_modeless_selection() |
| 824 | CheckUnix |
| 825 | CheckNotGui |
| 826 | CheckRunVimInTerminal |
| 827 | CheckFeature clipboard_working |
| 828 | |
| 829 | let save_mouse = &mouse |
| 830 | let save_term = &term |
| 831 | let save_ttymouse = &ttymouse |
| 832 | set mouse=a term=xterm ttymouse=sgr mousetime=200 |
| 833 | set clipboard=autoselectml |
| 834 | |
| 835 | let lines =<< trim END |
| 836 | one two three four five |
| 837 | red green yellow red blue |
| 838 | vim emacs sublime nano |
| 839 | END |
Bram Moolenaar | c4860bd | 2022-10-15 20:52:26 +0100 | [diff] [blame] | 840 | call writefile(lines, 'Xtest_modeless', 'D') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 841 | |
| 842 | " Create a terminal window running Vim for the test with mouse disabled |
| 843 | let prev_win = win_getid() |
| 844 | let buf = RunVimInTerminal('Xtest_modeless -n', {}) |
| 845 | call term_sendkeys(buf, ":set nocompatible\<CR>") |
| 846 | call term_sendkeys(buf, ":set mouse=\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 847 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 848 | redraw! |
| 849 | |
| 850 | " Use the mouse to enter the terminal window |
| 851 | call win_gotoid(prev_win) |
| 852 | call feedkeys(MouseLeftClickCode(1, 1), 'x') |
| 853 | call feedkeys(MouseLeftReleaseCode(1, 1), 'x') |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 854 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 855 | call assert_equal(1, getwininfo(win_getid())[0].terminal) |
| 856 | |
| 857 | " Test for copying a modeless selection to clipboard |
| 858 | let @* = 'clean' |
| 859 | " communicating with X server may take a little time |
| 860 | sleep 100m |
| 861 | call feedkeys(MouseLeftClickCode(2, 3), 'x') |
| 862 | call feedkeys(MouseLeftDragCode(2, 11), 'x') |
| 863 | call feedkeys(MouseLeftReleaseCode(2, 11), 'x') |
| 864 | call assert_equal("d green y", @*) |
| 865 | |
| 866 | " cleanup |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 867 | call TermWait(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 868 | call StopVimInTerminal(buf) |
| 869 | let &mouse = save_mouse |
| 870 | let &term = save_term |
| 871 | let &ttymouse = save_ttymouse |
| 872 | set mousetime& clipboard& |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 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 | |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 936 | func Test_terminal_vt420() |
| 937 | CheckRunVimInTerminal |
| 938 | " For Termcap |
| 939 | CheckUnix |
Christian Brabandt | 83d3b3b | 2024-04-30 20:45:09 +0200 | [diff] [blame] | 940 | CheckExecutable infocmp |
| 941 | let a = system('infocmp vt420') |
| 942 | if v:shell_error |
| 943 | " reset v:shell_error |
| 944 | let a = system('true') |
| 945 | throw 'Skipped: vt420 terminfo not available' |
| 946 | endif |
| 947 | let rows = 15 |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 948 | call writefile([':set term=vt420'], 'Xterm420', 'D') |
| 949 | |
| 950 | let buf = RunVimInTerminal('-S Xterm420', #{rows: rows}) |
| 951 | call TermWait(buf, 100) |
| 952 | call term_sendkeys(buf, ":set t_xo?\<CR>") |
| 953 | call WaitForAssert({-> assert_match('t_xo=y', term_getline(buf, rows))}) |
| 954 | call StopVimInTerminal(buf) |
| 955 | |
| 956 | call writefile([''], 'Xterm420') |
| 957 | let buf = RunVimInTerminal('-S Xterm420', #{rows: rows}) |
| 958 | call TermWait(buf, 100) |
| 959 | call term_sendkeys(buf, ":set t_xo?\<CR>") |
| 960 | call WaitForAssert({-> assert_match('t_xo=\s\+', term_getline(buf, rows))}) |
| 961 | call StopVimInTerminal(buf) |
| 962 | endfunc |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 963 | |
Yegappan Lakshmanan | d603e95 | 2024-06-10 18:16:34 +0200 | [diff] [blame] | 964 | " Test for using 'vertical' with term_start(). If a following term_start(), |
| 965 | " doesn't have the 'vertical' attribute, then it should be split horizontally. |
| 966 | func Test_terminal_vertical() |
| 967 | let lines =<< trim END |
| 968 | call term_start("NONE", {'vertical': 1}) |
| 969 | call term_start("NONE") |
| 970 | VAR layout = winlayout() |
| 971 | call assert_equal('row', layout[0], string(layout)) |
| 972 | call assert_equal('col', layout[1][0][0], string(layout)) |
| 973 | :%bw! |
| 974 | END |
| 975 | call v9.CheckLegacyAndVim9Success(lines) |
| 976 | endfunc |
| 977 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 978 | " vim: shiftwidth=2 sts=2 expandtab |