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