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