Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature terminal |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 5 | |
| 6 | source shared.vim |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 7 | source screendump.vim |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 8 | |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 9 | let s:python = PythonProg() |
Bram Moolenaar | ddd3308 | 2019-06-03 23:07:25 +0200 | [diff] [blame] | 10 | let $PROMPT_COMMAND='' |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 11 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 12 | " Open a terminal with a shell, assign the job to g:job and return the buffer |
| 13 | " number. |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 14 | func Run_shell_in_terminal(options) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 15 | if has('win32') |
| 16 | let buf = term_start([&shell,'/k'], a:options) |
| 17 | else |
| 18 | let buf = term_start(&shell, a:options) |
| 19 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 20 | |
| 21 | let termlist = term_list() |
| 22 | call assert_equal(1, len(termlist)) |
| 23 | call assert_equal(buf, termlist[0]) |
| 24 | |
| 25 | let g:job = term_getjob(buf) |
| 26 | call assert_equal(v:t_job, type(g:job)) |
| 27 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 28 | let string = string({'job': buf->term_getjob()}) |
Bram Moolenaar | 35422f4 | 2017-08-05 16:33:56 +0200 | [diff] [blame] | 29 | call assert_match("{'job': 'process \\d\\+ run'}", string) |
| 30 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 31 | return buf |
| 32 | endfunc |
| 33 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 34 | func Test_terminal_basic() |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 35 | au TerminalOpen * let b:done = 'yes' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 36 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 38 | if has("unix") |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 39 | call assert_match('^/dev/', job_info(g:job).tty_out) |
| 40 | call assert_match('^/dev/', term_gettty('')) |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 41 | else |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 42 | " ConPTY works on anonymous pipe. |
| 43 | if !has('conpty') |
| 44 | call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 45 | call assert_match('^\\\\.\\pipe\\', ''->term_gettty()) |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 46 | endif |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 47 | endif |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 48 | call assert_equal('t', mode()) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 49 | call assert_equal('yes', b:done) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 50 | call assert_match('%aR[^\n]*running]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 51 | call assert_match('%aR[^\n]*running]', execute('ls R')) |
| 52 | call assert_notmatch('%[^\n]*running]', execute('ls F')) |
| 53 | call assert_notmatch('%[^\n]*running]', execute('ls ?')) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 55 | call StopShellInTerminal(buf) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 56 | call term_wait(buf) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 57 | call assert_equal('n', mode()) |
| 58 | call assert_match('%aF[^\n]*finished]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 59 | call assert_match('%aF[^\n]*finished]', execute('ls F')) |
| 60 | call assert_notmatch('%[^\n]*finished]', execute('ls R')) |
| 61 | call assert_notmatch('%[^\n]*finished]', execute('ls ?')) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 62 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 63 | " closing window wipes out the terminal buffer a with finished job |
| 64 | close |
| 65 | call assert_equal("", bufname(buf)) |
| 66 | |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 67 | au! TerminalOpen |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 68 | unlet g:job |
| 69 | endfunc |
| 70 | |
| 71 | func Test_terminal_make_change() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 72 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 73 | call StopShellInTerminal(buf) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 74 | call term_wait(buf) |
| 75 | |
| 76 | setlocal modifiable |
| 77 | exe "normal Axxx\<Esc>" |
| 78 | call assert_fails(buf . 'bwipe', 'E517') |
| 79 | undo |
| 80 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 81 | exe buf . 'bwipe' |
| 82 | unlet g:job |
| 83 | endfunc |
| 84 | |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 85 | func Test_terminal_paste_register() |
| 86 | let @" = "text to paste" |
| 87 | |
| 88 | let buf = Run_shell_in_terminal({}) |
| 89 | " Wait for the shell to display a prompt |
| 90 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 91 | |
| 92 | call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt') |
| 93 | call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 94 | call WaitForAssert({-> assert_equal('text to paste 42', 2->getline())}) |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 95 | |
| 96 | exe buf . 'bwipe!' |
| 97 | unlet g:job |
| 98 | endfunc |
| 99 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 100 | func Test_terminal_wipe_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 101 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 102 | call assert_fails(buf . 'bwipe', 'E517') |
| 103 | exe buf . 'bwipe!' |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 104 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 105 | call assert_equal("", bufname(buf)) |
| 106 | |
| 107 | unlet g:job |
| 108 | endfunc |
| 109 | |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 110 | func Test_terminal_split_quit() |
| 111 | let buf = Run_shell_in_terminal({}) |
| 112 | call term_wait(buf) |
| 113 | split |
| 114 | quit! |
| 115 | call term_wait(buf) |
| 116 | sleep 50m |
| 117 | call assert_equal('run', job_status(g:job)) |
| 118 | |
| 119 | quit! |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 120 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 121 | |
| 122 | exe buf . 'bwipe' |
| 123 | unlet g:job |
| 124 | endfunc |
| 125 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 126 | func Test_terminal_hide_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 127 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 128 | setlocal bufhidden=hide |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 129 | quit |
| 130 | for nr in range(1, winnr('$')) |
| 131 | call assert_notequal(winbufnr(nr), buf) |
| 132 | endfor |
| 133 | call assert_true(bufloaded(buf)) |
| 134 | call assert_true(buflisted(buf)) |
| 135 | |
| 136 | exe 'split ' . buf . 'buf' |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 137 | call StopShellInTerminal(buf) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 138 | exe buf . 'bwipe' |
| 139 | |
| 140 | unlet g:job |
| 141 | endfunc |
| 142 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 143 | func s:Nasty_exit_cb(job, st) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 144 | exe g:buf . 'bwipe!' |
| 145 | let g:buf = 0 |
| 146 | endfunc |
| 147 | |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 148 | func Get_cat_123_cmd() |
| 149 | if has('win32') |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 150 | if !has('conpty') |
| 151 | return 'cmd /c "cls && color 2 && echo 123"' |
| 152 | else |
| 153 | " When clearing twice, extra sequence is not output. |
| 154 | return 'cmd /c "cls && cls && color 2 && echo 123"' |
| 155 | endif |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 156 | else |
| 157 | call writefile(["\<Esc>[32m123"], 'Xtext') |
| 158 | return "cat Xtext" |
| 159 | endif |
| 160 | endfunc |
| 161 | |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 162 | func Test_terminal_nasty_cb() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 163 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 164 | let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) |
| 165 | let g:job = term_getjob(g:buf) |
| 166 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 167 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 168 | call WaitForAssert({-> assert_equal(0, g:buf)}) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 169 | unlet g:job |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 170 | unlet g:buf |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 171 | call delete('Xtext') |
| 172 | endfunc |
| 173 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 174 | func Check_123(buf) |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 175 | let l = term_scrape(a:buf, 0) |
| 176 | call assert_true(len(l) == 0) |
| 177 | let l = term_scrape(a:buf, 999) |
| 178 | call assert_true(len(l) == 0) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 179 | let l = a:buf->term_scrape(1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 180 | call assert_true(len(l) > 0) |
| 181 | call assert_equal('1', l[0].chars) |
| 182 | call assert_equal('2', l[1].chars) |
| 183 | call assert_equal('3', l[2].chars) |
| 184 | call assert_equal('#00e000', l[0].fg) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 185 | call assert_equal(0, term_getattr(l[0].attr, 'bold')) |
| 186 | call assert_equal(0, l[0].attr->term_getattr('italic')) |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 187 | if has('win32') |
| 188 | " On Windows 'background' always defaults to dark, even though the terminal |
| 189 | " may use a light background. Therefore accept both white and black. |
| 190 | call assert_match('#ffffff\|#000000', l[0].bg) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 191 | else |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 192 | if &background == 'light' |
| 193 | call assert_equal('#ffffff', l[0].bg) |
| 194 | else |
| 195 | call assert_equal('#000000', l[0].bg) |
| 196 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 197 | endif |
| 198 | |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 199 | let l = term_getline(a:buf, -1) |
| 200 | call assert_equal('', l) |
| 201 | let l = term_getline(a:buf, 0) |
| 202 | call assert_equal('', l) |
| 203 | let l = term_getline(a:buf, 999) |
| 204 | call assert_equal('', l) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 205 | let l = term_getline(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 206 | call assert_equal('123', l) |
| 207 | endfunc |
| 208 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 209 | func Test_terminal_scrape_123() |
| 210 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 211 | let buf = term_start(cmd) |
| 212 | |
| 213 | let termlist = term_list() |
| 214 | call assert_equal(1, len(termlist)) |
| 215 | call assert_equal(buf, termlist[0]) |
| 216 | |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 217 | " Nothing happens with invalid buffer number |
| 218 | call term_wait(1234) |
| 219 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 220 | call term_wait(buf) |
Bram Moolenaar | 1783337 | 2017-09-04 22:23:19 +0200 | [diff] [blame] | 221 | " On MS-Windows we first get a startup message of two lines, wait for the |
Bram Moolenaar | 1bfdc07 | 2017-09-05 20:19:42 +0200 | [diff] [blame] | 222 | " "cls" to happen, after that we have one line with three characters. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 223 | call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 224 | call Check_123(buf) |
| 225 | |
| 226 | " Must still work after the job ended. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 227 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 228 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 229 | call term_wait(buf) |
| 230 | call Check_123(buf) |
| 231 | |
| 232 | exe buf . 'bwipe' |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 233 | call delete('Xtext') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 234 | endfunc |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 235 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 236 | func Test_terminal_scrape_multibyte() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 237 | call writefile(["léttまrs"], 'Xtext') |
| 238 | if has('win32') |
Bram Moolenaar | 3678393 | 2017-08-14 23:07:30 +0200 | [diff] [blame] | 239 | " Run cmd with UTF-8 codepage to make the type command print the expected |
| 240 | " multibyte characters. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 241 | let buf = term_start("cmd /K chcp 65001") |
| 242 | call term_sendkeys(buf, "type Xtext\<CR>") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 243 | eval buf->term_sendkeys("exit\<CR>") |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 244 | let line = 4 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 245 | else |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 246 | let buf = term_start("cat Xtext") |
| 247 | let line = 1 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 248 | endif |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 249 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 250 | call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"}) |
| 251 | let l = term_scrape(buf, line) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 252 | call assert_true(len(l) >= 7) |
| 253 | call assert_equal('l', l[0].chars) |
| 254 | call assert_equal('é', l[1].chars) |
| 255 | call assert_equal(1, l[1].width) |
| 256 | call assert_equal('t', l[2].chars) |
| 257 | call assert_equal('t', l[3].chars) |
| 258 | call assert_equal('ま', l[4].chars) |
| 259 | call assert_equal(2, l[4].width) |
| 260 | call assert_equal('r', l[5].chars) |
| 261 | call assert_equal('s', l[6].chars) |
| 262 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 263 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 264 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 265 | call term_wait(buf) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 266 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 267 | exe buf . 'bwipe' |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 268 | call delete('Xtext') |
| 269 | endfunc |
| 270 | |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 271 | func Test_terminal_scroll() |
| 272 | call writefile(range(1, 200), 'Xtext') |
| 273 | if has('win32') |
| 274 | let cmd = 'cmd /c "type Xtext"' |
| 275 | else |
| 276 | let cmd = "cat Xtext" |
| 277 | endif |
| 278 | let buf = term_start(cmd) |
| 279 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 280 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 281 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 282 | call term_wait(buf) |
| 283 | if has('win32') |
| 284 | " TODO: this should not be needed |
| 285 | sleep 100m |
| 286 | endif |
| 287 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 288 | let scrolled = buf->term_getscrolled() |
| 289 | call assert_equal(scrolled, term_getscrolled(buf)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 290 | call assert_equal('1', getline(1)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 291 | call assert_equal('1', term_getline(buf, 1 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 292 | call assert_equal('49', getline(49)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 293 | call assert_equal('49', term_getline(buf, 49 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 294 | call assert_equal('200', getline(200)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 295 | call assert_equal('200', term_getline(buf, 200 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 296 | |
| 297 | exe buf . 'bwipe' |
| 298 | call delete('Xtext') |
| 299 | endfunc |
| 300 | |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 301 | func Test_terminal_scrollback() |
Bram Moolenaar | 33c5e9f | 2018-05-26 18:58:51 +0200 | [diff] [blame] | 302 | let buf = Run_shell_in_terminal({'term_rows': 15}) |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 303 | set termwinscroll=100 |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 304 | call writefile(range(150), 'Xtext') |
| 305 | if has('win32') |
| 306 | call term_sendkeys(buf, "type Xtext\<CR>") |
| 307 | else |
| 308 | call term_sendkeys(buf, "cat Xtext\<CR>") |
| 309 | endif |
| 310 | let rows = term_getsize(buf)[0] |
Bram Moolenaar | 6c67219 | 2018-04-15 13:28:42 +0200 | [diff] [blame] | 311 | " On MS-Windows there is an empty line, check both last line and above it. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 312 | call WaitForAssert({-> assert_match( '149', term_getline(buf, rows - 1) . term_getline(buf, rows - 2))}) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 313 | let lines = line('$') |
Bram Moolenaar | ac3e830 | 2018-04-15 13:10:44 +0200 | [diff] [blame] | 314 | call assert_inrange(91, 100, lines) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 315 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 316 | call StopShellInTerminal(buf) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 317 | call term_wait(buf) |
| 318 | exe buf . 'bwipe' |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 319 | set termwinscroll& |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 320 | call delete('Xtext') |
| 321 | endfunc |
| 322 | |
| 323 | func Test_terminal_postponed_scrollback() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 324 | " tail -f only works on Unix |
| 325 | CheckUnix |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 326 | |
| 327 | call writefile(range(50), 'Xtext') |
| 328 | call writefile([ |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 329 | \ 'set shell=/bin/sh noruler', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 330 | \ 'terminal', |
Bram Moolenaar | 7e841e3 | 2019-02-15 00:26:14 +0100 | [diff] [blame] | 331 | \ 'sleep 200m', |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 332 | \ 'call feedkeys("tail -n 100 -f Xtext\<CR>", "xt")', |
| 333 | \ 'sleep 100m', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 334 | \ 'call feedkeys("\<C-W>N", "xt")', |
| 335 | \ ], 'XTest_postponed') |
| 336 | let buf = RunVimInTerminal('-S XTest_postponed', {}) |
| 337 | " Check that the Xtext lines are displayed and in Terminal-Normal mode |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 338 | call VerifyScreenDump(buf, 'Test_terminal_01', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 339 | |
| 340 | silent !echo 'one more line' >>Xtext |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 341 | " Screen will not change, move cursor to get a different dump |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 342 | call term_sendkeys(buf, "k") |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 343 | call VerifyScreenDump(buf, 'Test_terminal_02', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 344 | |
| 345 | " Back to Terminal-Job mode, text will scroll and show the extra line. |
| 346 | call term_sendkeys(buf, "a") |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 347 | call VerifyScreenDump(buf, 'Test_terminal_03', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 348 | |
| 349 | call term_wait(buf) |
| 350 | call term_sendkeys(buf, "\<C-C>") |
| 351 | call term_wait(buf) |
| 352 | call term_sendkeys(buf, "exit\<CR>") |
| 353 | call term_wait(buf) |
| 354 | call term_sendkeys(buf, ":q\<CR>") |
| 355 | call StopVimInTerminal(buf) |
| 356 | call delete('XTest_postponed') |
| 357 | call delete('Xtext') |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 358 | endfunc |
| 359 | |
Bram Moolenaar | 81aa0f5 | 2019-02-14 23:23:19 +0100 | [diff] [blame] | 360 | " Run diff on two dumps with different size. |
| 361 | func Test_terminal_dumpdiff_size() |
| 362 | call assert_equal(1, winnr('$')) |
| 363 | call term_dumpdiff('dumps/Test_incsearch_search_01.dump', 'dumps/Test_popup_command_01.dump') |
| 364 | call assert_equal(2, winnr('$')) |
| 365 | call assert_match('Test_incsearch_search_01.dump', getline(10)) |
| 366 | call assert_match(' +++++$', getline(11)) |
| 367 | call assert_match('Test_popup_command_01.dump', getline(31)) |
| 368 | call assert_equal(repeat('+', 75), getline(30)) |
| 369 | quit |
| 370 | endfunc |
| 371 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 372 | func Test_terminal_size() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 373 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 374 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 375 | exe 'terminal ++rows=5 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 376 | let size = term_getsize('') |
| 377 | bwipe! |
| 378 | call assert_equal(5, size[0]) |
| 379 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 380 | call term_start(cmd, {'term_rows': 6}) |
| 381 | let size = term_getsize('') |
| 382 | bwipe! |
| 383 | call assert_equal(6, size[0]) |
| 384 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 385 | vsplit |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 386 | exe 'terminal ++rows=5 ++cols=33 ' . cmd |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 387 | call assert_equal([5, 33], ''->term_getsize()) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 388 | |
| 389 | call term_setsize('', 6, 0) |
| 390 | call assert_equal([6, 33], term_getsize('')) |
| 391 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 392 | eval ''->term_setsize(0, 35) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 393 | call assert_equal([6, 35], term_getsize('')) |
| 394 | |
| 395 | call term_setsize('', 7, 30) |
| 396 | call assert_equal([7, 30], term_getsize('')) |
| 397 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 398 | bwipe! |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 399 | call assert_fails("call term_setsize('', 7, 30)", "E955:") |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 400 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 401 | call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) |
| 402 | let size = term_getsize('') |
| 403 | bwipe! |
| 404 | call assert_equal([6, 36], size) |
| 405 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 406 | exe 'vertical terminal ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 407 | let size = term_getsize('') |
| 408 | bwipe! |
| 409 | call assert_equal(20, size[1]) |
| 410 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 411 | eval cmd->term_start({'vertical': 1, 'term_cols': 26}) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 412 | let size = term_getsize('') |
| 413 | bwipe! |
| 414 | call assert_equal(26, size[1]) |
| 415 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 416 | split |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 417 | exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 418 | let size = term_getsize('') |
| 419 | bwipe! |
| 420 | call assert_equal([6, 20], size) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 421 | |
| 422 | call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27}) |
| 423 | let size = term_getsize('') |
| 424 | bwipe! |
| 425 | call assert_equal([7, 27], size) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 426 | |
| 427 | call delete('Xtext') |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 428 | endfunc |
| 429 | |
| 430 | func Test_terminal_curwin() |
| 431 | let cmd = Get_cat_123_cmd() |
| 432 | call assert_equal(1, winnr('$')) |
| 433 | |
| 434 | split dummy |
| 435 | exe 'terminal ++curwin ' . cmd |
| 436 | call assert_equal(2, winnr('$')) |
| 437 | bwipe! |
| 438 | |
| 439 | split dummy |
| 440 | call term_start(cmd, {'curwin': 1}) |
| 441 | call assert_equal(2, winnr('$')) |
| 442 | bwipe! |
| 443 | |
| 444 | split dummy |
| 445 | call setline(1, 'change') |
| 446 | call assert_fails('terminal ++curwin ' . cmd, 'E37:') |
| 447 | call assert_equal(2, winnr('$')) |
| 448 | exe 'terminal! ++curwin ' . cmd |
| 449 | call assert_equal(2, winnr('$')) |
| 450 | bwipe! |
| 451 | |
| 452 | split dummy |
| 453 | call setline(1, 'change') |
| 454 | call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') |
| 455 | call assert_equal(2, winnr('$')) |
| 456 | bwipe! |
| 457 | |
| 458 | split dummy |
| 459 | bwipe! |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 460 | call delete('Xtext') |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 461 | endfunc |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 462 | |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 463 | func s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 464 | if s:python != '' |
| 465 | let cmd = s:python . " test_short_sleep.py" |
Bram Moolenaar | c8523e2 | 2018-06-03 18:22:02 +0200 | [diff] [blame] | 466 | " 500 was not enough for Travis |
| 467 | let waittime = 900 |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 468 | else |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 469 | echo 'This will take five seconds...' |
| 470 | let waittime = 2000 |
| 471 | if has('win32') |
| 472 | let cmd = $windir . '\system32\timeout.exe 1' |
| 473 | else |
| 474 | let cmd = 'sleep 1' |
| 475 | endif |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 476 | endif |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 477 | return [cmd, waittime] |
| 478 | endfunc |
| 479 | |
| 480 | func Test_terminal_finish_open_close() |
| 481 | call assert_equal(1, winnr('$')) |
| 482 | |
| 483 | let [cmd, waittime] = s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 484 | |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 485 | " shell terminal closes automatically |
| 486 | terminal |
| 487 | let buf = bufnr('%') |
| 488 | call assert_equal(2, winnr('$')) |
| 489 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 490 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 491 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 492 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 493 | |
| 494 | " shell terminal that does not close automatically |
| 495 | terminal ++noclose |
| 496 | let buf = bufnr('%') |
| 497 | call assert_equal(2, winnr('$')) |
| 498 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 499 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 500 | call StopShellInTerminal(buf) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 501 | call assert_equal(2, winnr('$')) |
| 502 | quit |
| 503 | call assert_equal(1, winnr('$')) |
| 504 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 505 | exe 'terminal ++close ' . cmd |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 506 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 507 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 508 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 509 | |
| 510 | call term_start(cmd, {'term_finish': 'close'}) |
| 511 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 512 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 513 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 514 | call assert_equal(1, winnr('$')) |
| 515 | |
| 516 | exe 'terminal ++open ' . cmd |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 517 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 518 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 519 | bwipe |
| 520 | |
| 521 | call term_start(cmd, {'term_finish': 'open'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 522 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 523 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 524 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 525 | |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 526 | exe 'terminal ++hidden ++open ' . cmd |
| 527 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 528 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 529 | bwipe |
| 530 | |
| 531 | call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) |
| 532 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 533 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 534 | bwipe |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 535 | |
| 536 | call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') |
| 537 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:') |
| 538 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') |
| 539 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') |
| 540 | |
| 541 | call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 542 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 543 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 544 | call assert_equal(4, winheight(0)) |
| 545 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 546 | endfunc |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 547 | |
| 548 | func Test_terminal_cwd() |
Bram Moolenaar | e9f6fd2 | 2017-09-10 14:25:49 +0200 | [diff] [blame] | 549 | if !executable('pwd') |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 550 | return |
| 551 | endif |
| 552 | call mkdir('Xdir') |
| 553 | let buf = term_start('pwd', {'cwd': 'Xdir'}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 554 | call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 555 | |
| 556 | exe buf . 'bwipe' |
| 557 | call delete('Xdir', 'rf') |
| 558 | endfunc |
| 559 | |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 560 | func Test_terminal_cwd_failure() |
| 561 | " Case 1: Provided directory is not actually a directory. Attempt to make |
| 562 | " the file executable as well. |
| 563 | call writefile([], 'Xfile') |
| 564 | call setfperm('Xfile', 'rwx------') |
| 565 | call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:') |
| 566 | call delete('Xfile') |
| 567 | |
| 568 | " Case 2: Directory does not exist. |
| 569 | call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:') |
| 570 | |
| 571 | " Case 3: Directory exists but is not accessible. |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 572 | " Skip this for root, it will be accessible anyway. |
| 573 | if $USER != 'root' |
| 574 | call mkdir('XdirNoAccess', '', '0600') |
| 575 | " return early if the directory permissions could not be set properly |
| 576 | if getfperm('XdirNoAccess')[2] == 'x' |
| 577 | call delete('XdirNoAccess', 'rf') |
| 578 | return |
| 579 | endif |
| 580 | call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:') |
| 581 | call delete('XdirNoAccess', 'rf') |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 582 | endif |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 583 | endfunc |
| 584 | |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 585 | func Test_terminal_servername() |
| 586 | if !has('clientserver') |
| 587 | return |
| 588 | endif |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 589 | call s:test_environment("VIM_SERVERNAME", v:servername) |
| 590 | endfunc |
| 591 | |
| 592 | func Test_terminal_version() |
| 593 | call s:test_environment("VIM_TERMINAL", string(v:version)) |
| 594 | endfunc |
| 595 | |
| 596 | func s:test_environment(name, value) |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 597 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 598 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 599 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 600 | if has('win32') |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 601 | call term_sendkeys(buf, "echo %" . a:name . "%\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 602 | else |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 603 | call term_sendkeys(buf, "echo $" . a:name . "\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 604 | endif |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 605 | call term_wait(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 606 | call StopShellInTerminal(buf) |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 607 | call WaitForAssert({-> assert_equal(a:value, getline(2))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 608 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 609 | exe buf . 'bwipe' |
| 610 | unlet buf |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 611 | endfunc |
| 612 | |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 613 | func Test_terminal_env() |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 614 | let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) |
Bram Moolenaar | 51c2368 | 2017-08-14 21:45:00 +0200 | [diff] [blame] | 615 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 616 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 617 | if has('win32') |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 618 | call term_sendkeys(buf, "echo %TESTENV%\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 619 | else |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 620 | call term_sendkeys(buf, "echo $TESTENV\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 621 | endif |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 622 | eval buf->term_wait() |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 623 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 624 | call WaitForAssert({-> assert_equal('correct', getline(2))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 625 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 626 | exe buf . 'bwipe' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 627 | endfunc |
Bram Moolenaar | 679653e | 2017-08-13 14:13:19 +0200 | [diff] [blame] | 628 | |
Bram Moolenaar | dcaa613 | 2017-08-13 17:13:09 +0200 | [diff] [blame] | 629 | func Test_terminal_list_args() |
| 630 | let buf = term_start([&shell, &shellcmdflag, 'echo "123"']) |
| 631 | call assert_fails(buf . 'bwipe', 'E517') |
| 632 | exe buf . 'bwipe!' |
| 633 | call assert_equal("", bufname(buf)) |
| 634 | endfunction |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 635 | |
| 636 | func Test_terminal_noblock() |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 637 | let buf = term_start(&shell) |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 638 | if has('bsd') || has('mac') || has('sun') |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 639 | " The shell or something else has a problem dealing with more than 1000 |
| 640 | " characters at the same time. |
| 641 | let len = 1000 |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 642 | " NPFS is used in Windows, nonblocking mode does not work properly. |
| 643 | elseif has('win32') |
| 644 | let len = 1 |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 645 | else |
| 646 | let len = 5000 |
| 647 | endif |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 648 | |
| 649 | for c in ['a','b','c','d','e','f','g','h','i','j','k'] |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 650 | call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>") |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 651 | endfor |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 652 | call term_sendkeys(buf, "echo done\<cr>") |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 653 | |
| 654 | " On MS-Windows there is an extra empty line below "done". Find "done" in |
| 655 | " the last-but-one or the last-but-two line. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 656 | let lnum = term_getsize(buf)[0] - 1 |
Bram Moolenaar | 2181014 | 2018-02-02 18:30:36 +0100 | [diff] [blame] | 657 | call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 10000) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 658 | let line = term_getline(buf, lnum) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 659 | if line !~ 'done' |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 660 | let line = term_getline(buf, lnum - 1) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 661 | endif |
| 662 | call assert_match('done', line) |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 663 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 664 | let g:job = term_getjob(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 665 | call StopShellInTerminal(buf) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 666 | call term_wait(buf) |
Bram Moolenaar | d21f8b5 | 2017-08-19 15:40:01 +0200 | [diff] [blame] | 667 | unlet g:job |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 668 | bwipe |
| 669 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 670 | |
| 671 | func Test_terminal_write_stdin() |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 672 | if !executable('wc') |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 673 | throw 'skipped: wc command not available' |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 674 | endif |
Bram Moolenaar | 1580f75 | 2018-06-03 15:26:36 +0200 | [diff] [blame] | 675 | if has('win32') |
| 676 | " TODO: enable once writing to stdin works on MS-Windows |
| 677 | return |
| 678 | endif |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 679 | new |
| 680 | call setline(1, ['one', 'two', 'three']) |
| 681 | %term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 682 | call WaitForAssert({-> assert_match('3', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 683 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 684 | call assert_equal(['3', '3', '14'], nrs) |
| 685 | bwipe |
| 686 | |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 687 | new |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 688 | call setline(1, ['one', 'two', 'three', 'four']) |
| 689 | 2,3term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 690 | call WaitForAssert({-> assert_match('2', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 691 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 692 | call assert_equal(['2', '2', '10'], nrs) |
| 693 | bwipe |
| 694 | |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 695 | if executable('python') |
| 696 | new |
| 697 | call setline(1, ['print("hello")']) |
| 698 | 1term ++eof=exit() python |
| 699 | " MS-Windows echoes the input, Unix doesn't. |
| 700 | call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"') |
| 701 | if getline(1) =~ 'hello' |
| 702 | call assert_equal('hello', getline(1)) |
| 703 | else |
| 704 | call assert_equal('hello', getline(line('$') - 1)) |
| 705 | endif |
| 706 | bwipe |
| 707 | |
| 708 | if has('win32') |
| 709 | new |
| 710 | call setline(1, ['print("hello")']) |
| 711 | 1term ++eof=<C-Z> python |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 712 | call WaitForAssert({-> assert_match('Z', getline("$"))}) |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 713 | call assert_equal('hello', getline(line('$') - 1)) |
| 714 | bwipe |
| 715 | endif |
| 716 | endif |
| 717 | |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 718 | bwipe! |
| 719 | endfunc |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 720 | |
| 721 | func Test_terminal_no_cmd() |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 722 | let buf = term_start('NONE', {}) |
| 723 | call assert_notequal(0, buf) |
| 724 | |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 725 | let pty = job_info(term_getjob(buf))['tty_out'] |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 726 | call assert_notequal('', pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 727 | if has('gui_running') && !has('win32') |
| 728 | " In the GUI job_start() doesn't work, it does not read from the pty. |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 729 | call system('echo "look here" > ' . pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 730 | else |
| 731 | " Otherwise using a job works on all systems. |
| 732 | call job_start([&shell, &shellcmdflag, 'echo "look here" > ' . pty]) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 733 | endif |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 734 | call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 735 | |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 736 | bwipe! |
| 737 | endfunc |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 738 | |
| 739 | func Test_terminal_special_chars() |
| 740 | " this file name only works on Unix |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 741 | CheckUnix |
| 742 | |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 743 | call mkdir('Xdir with spaces') |
| 744 | call writefile(['x'], 'Xdir with spaces/quoted"file') |
| 745 | term ls Xdir\ with\ spaces/quoted\"file |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 746 | call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 747 | call term_wait('') |
| 748 | |
| 749 | call delete('Xdir with spaces', 'rf') |
| 750 | bwipe |
| 751 | endfunc |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 752 | |
| 753 | func Test_terminal_wrong_options() |
| 754 | call assert_fails('call term_start(&shell, { |
| 755 | \ "in_io": "file", |
| 756 | \ "in_name": "xxx", |
| 757 | \ "out_io": "file", |
| 758 | \ "out_name": "xxx", |
| 759 | \ "err_io": "file", |
| 760 | \ "err_name": "xxx" |
| 761 | \ })', 'E474:') |
| 762 | call assert_fails('call term_start(&shell, { |
| 763 | \ "out_buf": bufnr("%") |
| 764 | \ })', 'E474:') |
| 765 | call assert_fails('call term_start(&shell, { |
| 766 | \ "err_buf": bufnr("%") |
| 767 | \ })', 'E474:') |
| 768 | endfunc |
| 769 | |
| 770 | func Test_terminal_redir_file() |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 771 | let cmd = Get_cat_123_cmd() |
| 772 | let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) |
| 773 | call term_wait(buf) |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 774 | " ConPTY may precede escape sequence. There are things that are not so. |
| 775 | if !has('conpty') |
| 776 | call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) |
| 777 | call assert_match('123', readfile('Xfile')[0]) |
| 778 | endif |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 779 | let g:job = term_getjob(buf) |
| 780 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 781 | call delete('Xfile') |
| 782 | bwipe |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 783 | |
| 784 | if has('unix') |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 785 | call writefile(['one line'], 'Xfile') |
| 786 | let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) |
| 787 | call term_wait(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 788 | call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) |
Bram Moolenaar | 8b53b79 | 2017-09-05 20:29:25 +0200 | [diff] [blame] | 789 | let g:job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 790 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 791 | bwipe |
| 792 | call delete('Xfile') |
| 793 | endif |
| 794 | endfunc |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 795 | |
| 796 | func TerminalTmap(remap) |
| 797 | let buf = Run_shell_in_terminal({}) |
| 798 | call assert_equal('t', mode()) |
| 799 | |
| 800 | if a:remap |
| 801 | tmap 123 456 |
| 802 | else |
| 803 | tnoremap 123 456 |
| 804 | endif |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 805 | " don't use abcde, it's an existing command |
| 806 | tmap 456 abxde |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 807 | call assert_equal('456', maparg('123', 't')) |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 808 | call assert_equal('abxde', maparg('456', 't')) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 809 | call feedkeys("123", 'tx') |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 810 | call WaitForAssert({-> assert_match('abxde\|456', term_getline(buf, term_getcursor(buf)[0]))}) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 811 | let lnum = term_getcursor(buf)[0] |
| 812 | if a:remap |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 813 | call assert_match('abxde', term_getline(buf, lnum)) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 814 | else |
| 815 | call assert_match('456', term_getline(buf, lnum)) |
| 816 | endif |
| 817 | |
| 818 | call term_sendkeys(buf, "\r") |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 819 | call StopShellInTerminal(buf) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 820 | call term_wait(buf) |
| 821 | |
| 822 | tunmap 123 |
| 823 | tunmap 456 |
| 824 | call assert_equal('', maparg('123', 't')) |
| 825 | close |
| 826 | unlet g:job |
| 827 | endfunc |
| 828 | |
| 829 | func Test_terminal_tmap() |
| 830 | call TerminalTmap(1) |
| 831 | call TerminalTmap(0) |
| 832 | endfunc |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 833 | |
| 834 | func Test_terminal_wall() |
| 835 | let buf = Run_shell_in_terminal({}) |
| 836 | wall |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 837 | call StopShellInTerminal(buf) |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 838 | call term_wait(buf) |
| 839 | exe buf . 'bwipe' |
| 840 | unlet g:job |
| 841 | endfunc |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 842 | |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 843 | func Test_terminal_wqall() |
| 844 | let buf = Run_shell_in_terminal({}) |
| 845 | call assert_fails('wqall', 'E948') |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 846 | call StopShellInTerminal(buf) |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 847 | call term_wait(buf) |
| 848 | exe buf . 'bwipe' |
| 849 | unlet g:job |
| 850 | endfunc |
| 851 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 852 | func Test_terminal_composing_unicode() |
| 853 | let save_enc = &encoding |
| 854 | set encoding=utf-8 |
| 855 | |
| 856 | if has('win32') |
| 857 | let cmd = "cmd /K chcp 65001" |
| 858 | let lnum = [3, 6, 9] |
| 859 | else |
| 860 | let cmd = &shell |
| 861 | let lnum = [1, 3, 5] |
| 862 | endif |
| 863 | |
| 864 | enew |
| 865 | let buf = term_start(cmd, {'curwin': bufnr('')}) |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 866 | let g:job = term_getjob(buf) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 867 | call term_wait(buf, 50) |
| 868 | |
Bram Moolenaar | ebe74b7 | 2018-04-21 23:34:43 +0200 | [diff] [blame] | 869 | if has('win32') |
| 870 | call assert_equal('cmd', job_info(g:job).cmd[0]) |
| 871 | else |
| 872 | call assert_equal(&shell, job_info(g:job).cmd[0]) |
| 873 | endif |
| 874 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 875 | " ascii + composing |
| 876 | let txt = "a\u0308bc" |
| 877 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 878 | call term_wait(buf, 50) |
| 879 | call assert_match("echo " . txt, term_getline(buf, lnum[0])) |
| 880 | call assert_equal(txt, term_getline(buf, lnum[0] + 1)) |
| 881 | let l = term_scrape(buf, lnum[0] + 1) |
| 882 | call assert_equal("a\u0308", l[0].chars) |
| 883 | call assert_equal("b", l[1].chars) |
| 884 | call assert_equal("c", l[2].chars) |
| 885 | |
| 886 | " multibyte + composing |
| 887 | let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099" |
| 888 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 889 | call term_wait(buf, 50) |
| 890 | call assert_match("echo " . txt, term_getline(buf, lnum[1])) |
| 891 | call assert_equal(txt, term_getline(buf, lnum[1] + 1)) |
| 892 | let l = term_scrape(buf, lnum[1] + 1) |
| 893 | call assert_equal("\u304b\u3099", l[0].chars) |
| 894 | call assert_equal("\u304e", l[1].chars) |
| 895 | call assert_equal("\u304f\u3099", l[2].chars) |
| 896 | call assert_equal("\u3052", l[3].chars) |
| 897 | call assert_equal("\u3053\u3099", l[4].chars) |
| 898 | |
| 899 | " \u00a0 + composing |
| 900 | let txt = "abc\u00a0\u0308" |
| 901 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 902 | call term_wait(buf, 50) |
| 903 | call assert_match("echo " . txt, term_getline(buf, lnum[2])) |
| 904 | call assert_equal(txt, term_getline(buf, lnum[2] + 1)) |
| 905 | let l = term_scrape(buf, lnum[2] + 1) |
| 906 | call assert_equal("\u00a0\u0308", l[3].chars) |
| 907 | |
| 908 | call term_sendkeys(buf, "exit\r") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 909 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 910 | bwipe! |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 911 | unlet g:job |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 912 | let &encoding = save_enc |
| 913 | endfunc |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 914 | |
| 915 | func Test_terminal_aucmd_on_close() |
| 916 | fun Nop() |
| 917 | let s:called = 1 |
| 918 | endfun |
| 919 | |
| 920 | aug repro |
| 921 | au! |
| 922 | au BufWinLeave * call Nop() |
| 923 | aug END |
| 924 | |
| 925 | let [cmd, waittime] = s:get_sleep_cmd() |
| 926 | |
| 927 | call assert_equal(1, winnr('$')) |
| 928 | new |
| 929 | call setline(1, ['one', 'two']) |
| 930 | exe 'term ++close ' . cmd |
| 931 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 932 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 933 | call assert_equal(1, s:called) |
| 934 | bwipe! |
| 935 | |
| 936 | unlet s:called |
| 937 | au! repro |
| 938 | delfunc Nop |
| 939 | endfunc |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 940 | |
| 941 | func Test_terminal_term_start_empty_command() |
| 942 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 943 | call assert_fails(cmd, 'E474') |
| 944 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 945 | call assert_fails(cmd, 'E474') |
| 946 | let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})" |
| 947 | call assert_fails(cmd, 'E474') |
| 948 | let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})" |
| 949 | call assert_fails(cmd, 'E474') |
| 950 | endfunc |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 951 | |
| 952 | func Test_terminal_response_to_control_sequence() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 953 | CheckUnix |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 954 | |
| 955 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 956 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 957 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 958 | call term_sendkeys(buf, "cat\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 959 | call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 960 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 961 | " Request the cursor position. |
| 962 | call term_sendkeys(buf, "\x1b[6n\<CR>") |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 963 | |
| 964 | " Wait for output from tty to display, below an empty line. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 965 | call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 966 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 967 | " End "cat" gently. |
| 968 | call term_sendkeys(buf, "\<CR>\<C-D>") |
| 969 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 970 | call StopShellInTerminal(buf) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 971 | exe buf . 'bwipe' |
| 972 | unlet g:job |
| 973 | endfunc |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 974 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 975 | " Run Vim, start a terminal in that Vim with the kill argument, |
| 976 | " :qall works. |
| 977 | func Run_terminal_qall_kill(line1, line2) |
| 978 | " 1. Open a terminal window and wait for the prompt to appear |
| 979 | " 2. set kill using term_setkill() |
| 980 | " 3. make Vim exit, it will kill the shell |
| 981 | let after = [ |
| 982 | \ a:line1, |
| 983 | \ 'let buf = bufnr("%")', |
| 984 | \ 'while term_getline(buf, 1) =~ "^\\s*$"', |
| 985 | \ ' sleep 10m', |
| 986 | \ 'endwhile', |
| 987 | \ a:line2, |
| 988 | \ 'au VimLeavePre * call writefile(["done"], "Xdone")', |
| 989 | \ 'qall', |
| 990 | \ ] |
| 991 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 992 | return |
| 993 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 994 | call assert_equal("done", readfile("Xdone")[0]) |
| 995 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 996 | endfunc |
| 997 | |
| 998 | " Run Vim in a terminal, then start a terminal in that Vim with a kill |
| 999 | " argument, check that :qall works. |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1000 | func Test_terminal_qall_kill_arg() |
| 1001 | call Run_terminal_qall_kill('term ++kill=kill', '') |
| 1002 | endfunc |
| 1003 | |
| 1004 | " Run Vim, start a terminal in that Vim, set the kill argument with |
| 1005 | " term_setkill(), check that :qall works. |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1006 | func Test_terminal_qall_kill_func() |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1007 | call Run_terminal_qall_kill('term', 'eval buf->term_setkill("kill")') |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1008 | endfunc |
| 1009 | |
| 1010 | " Run Vim, start a terminal in that Vim without the kill argument, |
| 1011 | " check that :qall does not exit, :qall! does. |
| 1012 | func Test_terminal_qall_exit() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1013 | let after =<< trim [CODE] |
| 1014 | term |
| 1015 | let buf = bufnr("%") |
| 1016 | while term_getline(buf, 1) =~ "^\\s*$" |
| 1017 | sleep 10m |
| 1018 | endwhile |
| 1019 | set nomore |
| 1020 | au VimLeavePre * call writefile(["too early"], "Xdone") |
| 1021 | qall |
| 1022 | au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone") |
| 1023 | cquit |
| 1024 | [CODE] |
| 1025 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1026 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1027 | return |
| 1028 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1029 | call assert_equal("done", readfile("Xdone")[0]) |
| 1030 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1031 | endfunc |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1032 | |
| 1033 | " Run Vim in a terminal, then start a terminal in that Vim without a kill |
| 1034 | " argument, check that :confirm qall works. |
| 1035 | func Test_terminal_qall_prompt() |
| 1036 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1037 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1038 | endif |
| 1039 | let buf = RunVimInTerminal('', {}) |
| 1040 | |
| 1041 | " Open a terminal window and wait for the prompt to appear |
| 1042 | call term_sendkeys(buf, ":term\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1043 | call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) |
| 1044 | call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1045 | |
| 1046 | " make Vim exit, it will prompt to kill the shell |
| 1047 | call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1048 | call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1049 | call term_sendkeys(buf, "y") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1050 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1051 | |
| 1052 | " close the terminal window where Vim was running |
| 1053 | quit |
| 1054 | endfunc |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1055 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 1056 | func Test_terminal_open_autocmd() |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1057 | augroup repro |
| 1058 | au! |
| 1059 | au TerminalOpen * let s:called += 1 |
| 1060 | augroup END |
| 1061 | |
| 1062 | let s:called = 0 |
| 1063 | |
| 1064 | " Open a terminal window with :terminal |
| 1065 | terminal |
| 1066 | call assert_equal(1, s:called) |
| 1067 | bwipe! |
| 1068 | |
| 1069 | " Open a terminal window with term_start() |
| 1070 | call term_start(&shell) |
| 1071 | call assert_equal(2, s:called) |
| 1072 | bwipe! |
| 1073 | |
| 1074 | " Open a hidden terminal buffer with :terminal |
| 1075 | terminal ++hidden |
| 1076 | call assert_equal(3, s:called) |
| 1077 | for buf in term_list() |
| 1078 | exe buf . "bwipe!" |
| 1079 | endfor |
| 1080 | |
| 1081 | " Open a hidden terminal buffer with term_start() |
| 1082 | let buf = term_start(&shell, {'hidden': 1}) |
| 1083 | call assert_equal(4, s:called) |
| 1084 | exe buf . "bwipe!" |
| 1085 | |
| 1086 | unlet s:called |
| 1087 | au! repro |
| 1088 | endfunction |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1089 | |
| 1090 | func Check_dump01(off) |
| 1091 | call assert_equal('one two three four five', trim(getline(a:off + 1))) |
| 1092 | call assert_equal('~ Select Word', trim(getline(a:off + 7))) |
Bram Moolenaar | 1834d37 | 2018-03-29 17:40:46 +0200 | [diff] [blame] | 1093 | call assert_equal(':popup PopUp', trim(getline(a:off + 20))) |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1094 | endfunc |
| 1095 | |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1096 | func Test_terminal_dumpwrite_composing() |
| 1097 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1098 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1099 | endif |
| 1100 | let save_enc = &encoding |
| 1101 | set encoding=utf-8 |
| 1102 | call assert_equal(1, winnr('$')) |
| 1103 | |
| 1104 | let text = " a\u0300 e\u0302 o\u0308" |
| 1105 | call writefile([text], 'Xcomposing') |
Bram Moolenaar | 77bfd75 | 2018-04-30 18:03:10 +0200 | [diff] [blame] | 1106 | let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1107 | call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1108 | eval 'Xdump'->term_dumpwrite(buf) |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1109 | let dumpline = readfile('Xdump')[0] |
| 1110 | call assert_match('|à| |ê| |ö', dumpline) |
| 1111 | |
| 1112 | call StopVimInTerminal(buf) |
| 1113 | call delete('Xcomposing') |
| 1114 | call delete('Xdump') |
| 1115 | let &encoding = save_enc |
| 1116 | endfunc |
| 1117 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1118 | " just testing basic functionality. |
| 1119 | func Test_terminal_dumpload() |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1120 | let curbuf = winbufnr('') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1121 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1122 | let buf = term_dumpload('dumps/Test_popup_command_01.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1123 | call assert_equal(2, winnr('$')) |
| 1124 | call assert_equal(20, line('$')) |
| 1125 | call Check_dump01(0) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1126 | |
| 1127 | " Load another dump in the same window |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1128 | let buf2 = 'dumps/Test_diff_01.dump'->term_dumpload({'bufnr': buf}) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1129 | call assert_equal(buf, buf2) |
| 1130 | call assert_notequal('one two three four five', trim(getline(1))) |
| 1131 | |
| 1132 | " Load the first dump again in the same window |
| 1133 | let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf}) |
| 1134 | call assert_equal(buf, buf2) |
| 1135 | call Check_dump01(0) |
| 1136 | |
| 1137 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': curbuf})", 'E475:') |
| 1138 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:') |
| 1139 | new |
| 1140 | let closedbuf = winbufnr('') |
| 1141 | quit |
| 1142 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:') |
| 1143 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1144 | quit |
| 1145 | endfunc |
| 1146 | |
| 1147 | func Test_terminal_dumpdiff() |
| 1148 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1149 | eval 'dumps/Test_popup_command_01.dump'->term_dumpdiff('dumps/Test_popup_command_02.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1150 | call assert_equal(2, winnr('$')) |
| 1151 | call assert_equal(62, line('$')) |
| 1152 | call Check_dump01(0) |
| 1153 | call Check_dump01(42) |
| 1154 | call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) |
| 1155 | quit |
| 1156 | endfunc |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1157 | |
Bram Moolenaar | c3ef896 | 2019-02-15 00:16:13 +0100 | [diff] [blame] | 1158 | func Test_terminal_dumpdiff_swap() |
| 1159 | call assert_equal(1, winnr('$')) |
| 1160 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump') |
| 1161 | call assert_equal(2, winnr('$')) |
| 1162 | call assert_equal(62, line('$')) |
| 1163 | call assert_match('Test_popup_command_01.dump', getline(21)) |
| 1164 | call assert_match('Test_popup_command_03.dump', getline(42)) |
| 1165 | call assert_match('Undo', getline(3)) |
| 1166 | call assert_match('three four five', getline(45)) |
| 1167 | |
| 1168 | normal s |
| 1169 | call assert_match('Test_popup_command_03.dump', getline(21)) |
| 1170 | call assert_match('Test_popup_command_01.dump', getline(42)) |
| 1171 | call assert_match('three four five', getline(3)) |
| 1172 | call assert_match('Undo', getline(45)) |
| 1173 | quit |
| 1174 | endfunc |
| 1175 | |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1176 | func Test_terminal_dumpdiff_options() |
| 1177 | set laststatus=0 |
| 1178 | call assert_equal(1, winnr('$')) |
| 1179 | let height = winheight(0) |
| 1180 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33}) |
| 1181 | call assert_equal(2, winnr('$')) |
| 1182 | call assert_equal(height, winheight(winnr())) |
| 1183 | call assert_equal(33, winwidth(winnr())) |
| 1184 | call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%')) |
| 1185 | quit |
| 1186 | |
| 1187 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1188 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'}) |
| 1189 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | e809a4e | 2019-07-04 17:35:05 +0200 | [diff] [blame] | 1190 | call assert_equal(&columns, winwidth(0)) |
| 1191 | call assert_equal(13, winheight(0)) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1192 | call assert_equal('something else', bufname('%')) |
| 1193 | quit |
| 1194 | |
| 1195 | call assert_equal(1, winnr('$')) |
| 1196 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1}) |
| 1197 | call assert_equal(1, winnr('$')) |
| 1198 | bwipe |
| 1199 | |
| 1200 | set laststatus& |
| 1201 | endfunc |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1202 | |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1203 | func Api_drop_common(options) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1204 | call assert_equal(1, winnr('$')) |
| 1205 | |
| 1206 | " Use the title termcap entries to output the escape sequence. |
| 1207 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1208 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1209 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1210 | \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1211 | \ 'redraw', |
| 1212 | \ "set t_ts=", |
| 1213 | \ ], 'Xscript') |
| 1214 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 769e9d2 | 2018-04-11 20:53:49 +0200 | [diff] [blame] | 1215 | call WaitFor({-> bufnr('Xtextfile') > 0}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1216 | call assert_equal('Xtextfile', expand('%:t')) |
| 1217 | call assert_true(winnr('$') >= 3) |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1218 | return buf |
| 1219 | endfunc |
| 1220 | |
| 1221 | func Test_terminal_api_drop_newwin() |
| 1222 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1223 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1224 | endif |
| 1225 | let buf = Api_drop_common('') |
| 1226 | call assert_equal(0, &bin) |
| 1227 | call assert_equal('', &fenc) |
| 1228 | |
| 1229 | call StopVimInTerminal(buf) |
| 1230 | call delete('Xscript') |
| 1231 | bwipe Xtextfile |
| 1232 | endfunc |
| 1233 | |
| 1234 | func Test_terminal_api_drop_newwin_bin() |
| 1235 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1236 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1237 | endif |
| 1238 | let buf = Api_drop_common(',{"bin":1}') |
| 1239 | call assert_equal(1, &bin) |
| 1240 | |
| 1241 | call StopVimInTerminal(buf) |
| 1242 | call delete('Xscript') |
| 1243 | bwipe Xtextfile |
| 1244 | endfunc |
| 1245 | |
| 1246 | func Test_terminal_api_drop_newwin_binary() |
| 1247 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1248 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1249 | endif |
| 1250 | let buf = Api_drop_common(',{"binary":1}') |
| 1251 | call assert_equal(1, &bin) |
| 1252 | |
| 1253 | call StopVimInTerminal(buf) |
| 1254 | call delete('Xscript') |
| 1255 | bwipe Xtextfile |
| 1256 | endfunc |
| 1257 | |
| 1258 | func Test_terminal_api_drop_newwin_nobin() |
| 1259 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1260 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1261 | endif |
| 1262 | set binary |
| 1263 | let buf = Api_drop_common(',{"nobin":1}') |
| 1264 | call assert_equal(0, &bin) |
| 1265 | |
| 1266 | call StopVimInTerminal(buf) |
| 1267 | call delete('Xscript') |
| 1268 | bwipe Xtextfile |
| 1269 | set nobinary |
| 1270 | endfunc |
| 1271 | |
| 1272 | func Test_terminal_api_drop_newwin_nobinary() |
| 1273 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1274 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1275 | endif |
| 1276 | set binary |
| 1277 | let buf = Api_drop_common(',{"nobinary":1}') |
| 1278 | call assert_equal(0, &bin) |
| 1279 | |
| 1280 | call StopVimInTerminal(buf) |
| 1281 | call delete('Xscript') |
| 1282 | bwipe Xtextfile |
| 1283 | set nobinary |
| 1284 | endfunc |
| 1285 | |
| 1286 | func Test_terminal_api_drop_newwin_ff() |
| 1287 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1288 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1289 | endif |
| 1290 | let buf = Api_drop_common(',{"ff":"dos"}') |
| 1291 | call assert_equal("dos", &ff) |
| 1292 | |
| 1293 | call StopVimInTerminal(buf) |
| 1294 | call delete('Xscript') |
| 1295 | bwipe Xtextfile |
| 1296 | endfunc |
| 1297 | |
| 1298 | func Test_terminal_api_drop_newwin_fileformat() |
| 1299 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1300 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1301 | endif |
| 1302 | let buf = Api_drop_common(',{"fileformat":"dos"}') |
| 1303 | call assert_equal("dos", &ff) |
| 1304 | |
| 1305 | call StopVimInTerminal(buf) |
| 1306 | call delete('Xscript') |
| 1307 | bwipe Xtextfile |
| 1308 | endfunc |
| 1309 | |
| 1310 | func Test_terminal_api_drop_newwin_enc() |
| 1311 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1312 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1313 | endif |
| 1314 | let buf = Api_drop_common(',{"enc":"utf-16"}') |
| 1315 | call assert_equal("utf-16", &fenc) |
| 1316 | |
| 1317 | call StopVimInTerminal(buf) |
| 1318 | call delete('Xscript') |
| 1319 | bwipe Xtextfile |
| 1320 | endfunc |
| 1321 | |
| 1322 | func Test_terminal_api_drop_newwin_encoding() |
| 1323 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1324 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1325 | endif |
| 1326 | let buf = Api_drop_common(',{"encoding":"utf-16"}') |
| 1327 | call assert_equal("utf-16", &fenc) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1328 | |
| 1329 | call StopVimInTerminal(buf) |
| 1330 | call delete('Xscript') |
| 1331 | bwipe Xtextfile |
| 1332 | endfunc |
| 1333 | |
| 1334 | func Test_terminal_api_drop_oldwin() |
| 1335 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1336 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1337 | endif |
| 1338 | let firstwinid = win_getid() |
| 1339 | split Xtextfile |
| 1340 | let textfile_winid = win_getid() |
| 1341 | call assert_equal(2, winnr('$')) |
| 1342 | call win_gotoid(firstwinid) |
| 1343 | |
| 1344 | " Use the title termcap entries to output the escape sequence. |
| 1345 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1346 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1347 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1348 | \ 'let &titlestring = ''["drop","Xtextfile"]''', |
| 1349 | \ 'redraw', |
| 1350 | \ "set t_ts=", |
| 1351 | \ ], 'Xscript') |
Bram Moolenaar | 15a1c3f | 2018-03-25 18:56:25 +0200 | [diff] [blame] | 1352 | let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1353 | call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1354 | call assert_equal(textfile_winid, win_getid()) |
| 1355 | |
| 1356 | call StopVimInTerminal(buf) |
| 1357 | call delete('Xscript') |
| 1358 | bwipe Xtextfile |
| 1359 | endfunc |
| 1360 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1361 | func Tapi_TryThis(bufnum, arg) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1362 | let g:called_bufnum = a:bufnum |
| 1363 | let g:called_arg = a:arg |
| 1364 | endfunc |
| 1365 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1366 | func WriteApiCall(funcname) |
| 1367 | " Use the title termcap entries to output the escape sequence. |
| 1368 | call writefile([ |
| 1369 | \ 'set title', |
| 1370 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1371 | \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', |
| 1372 | \ 'redraw', |
| 1373 | \ "set t_ts=", |
| 1374 | \ ], 'Xscript') |
| 1375 | endfunc |
| 1376 | |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1377 | func Test_terminal_api_call() |
| 1378 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1379 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1380 | endif |
Bram Moolenaar | 2de50f8 | 2018-03-25 19:09:56 +0200 | [diff] [blame] | 1381 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1382 | call WriteApiCall('Tapi_TryThis') |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1383 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1384 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1385 | call assert_equal(buf, g:called_bufnum) |
| 1386 | call assert_equal(['hello', 123], g:called_arg) |
| 1387 | |
| 1388 | call StopVimInTerminal(buf) |
| 1389 | call delete('Xscript') |
| 1390 | unlet g:called_bufnum |
| 1391 | unlet g:called_arg |
| 1392 | endfunc |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1393 | |
| 1394 | func Test_terminal_api_call_fails() |
| 1395 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1396 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1397 | endif |
| 1398 | |
| 1399 | call WriteApiCall('TryThis') |
| 1400 | call ch_logfile('Xlog', 'w') |
| 1401 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1402 | call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1403 | |
| 1404 | call StopVimInTerminal(buf) |
| 1405 | call delete('Xscript') |
| 1406 | call ch_logfile('', '') |
| 1407 | call delete('Xlog') |
| 1408 | endfunc |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1409 | |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1410 | let s:caught_e937 = 0 |
| 1411 | |
| 1412 | func Tapi_Delete(bufnum, arg) |
| 1413 | try |
| 1414 | execute 'bdelete!' a:bufnum |
| 1415 | catch /E937:/ |
| 1416 | let s:caught_e937 = 1 |
| 1417 | endtry |
| 1418 | endfunc |
| 1419 | |
| 1420 | func Test_terminal_api_call_fail_delete() |
| 1421 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1422 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1423 | endif |
| 1424 | |
| 1425 | call WriteApiCall('Tapi_Delete') |
| 1426 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1427 | call WaitForAssert({-> assert_equal(1, s:caught_e937)}) |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1428 | |
| 1429 | call StopVimInTerminal(buf) |
| 1430 | call delete('Xscript') |
| 1431 | call ch_logfile('', '') |
| 1432 | endfunc |
| 1433 | |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1434 | func Test_terminal_ansicolors_default() |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1435 | if !exists('*term_getansicolors') |
| 1436 | throw 'Skipped: term_getansicolors() not supported' |
| 1437 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1438 | let colors = [ |
| 1439 | \ '#000000', '#e00000', |
| 1440 | \ '#00e000', '#e0e000', |
| 1441 | \ '#0000e0', '#e000e0', |
| 1442 | \ '#00e0e0', '#e0e0e0', |
| 1443 | \ '#808080', '#ff4040', |
| 1444 | \ '#40ff40', '#ffff40', |
| 1445 | \ '#4040ff', '#ff40ff', |
| 1446 | \ '#40ffff', '#ffffff', |
| 1447 | \] |
| 1448 | |
| 1449 | let buf = Run_shell_in_terminal({}) |
| 1450 | call assert_equal(colors, term_getansicolors(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1451 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1452 | call term_wait(buf) |
| 1453 | |
| 1454 | exe buf . 'bwipe' |
| 1455 | endfunc |
| 1456 | |
| 1457 | let s:test_colors = [ |
| 1458 | \ '#616e64', '#0d0a79', |
| 1459 | \ '#6d610d', '#0a7373', |
| 1460 | \ '#690d0a', '#6d696e', |
| 1461 | \ '#0d0a6f', '#616e0d', |
| 1462 | \ '#0a6479', '#6d0d0a', |
| 1463 | \ '#617373', '#0d0a69', |
| 1464 | \ '#6d690d', '#0a6e6f', |
| 1465 | \ '#610d0a', '#6e6479', |
| 1466 | \] |
| 1467 | |
| 1468 | func Test_terminal_ansicolors_global() |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1469 | if !exists('*term_getansicolors') |
| 1470 | throw 'Skipped: term_getansicolors() not supported' |
| 1471 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1472 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1473 | let buf = Run_shell_in_terminal({}) |
| 1474 | call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1475 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1476 | call term_wait(buf) |
| 1477 | |
| 1478 | exe buf . 'bwipe' |
| 1479 | unlet g:terminal_ansi_colors |
| 1480 | endfunc |
| 1481 | |
| 1482 | func Test_terminal_ansicolors_func() |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1483 | if !exists('*term_getansicolors') |
| 1484 | throw 'Skipped: term_getansicolors() not supported' |
| 1485 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1486 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1487 | let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) |
| 1488 | call assert_equal(s:test_colors, term_getansicolors(buf)) |
| 1489 | |
| 1490 | call term_setansicolors(buf, g:terminal_ansi_colors) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1491 | call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors()) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1492 | |
| 1493 | let colors = [ |
| 1494 | \ 'ivory', 'AliceBlue', |
| 1495 | \ 'grey67', 'dark goldenrod', |
| 1496 | \ 'SteelBlue3', 'PaleVioletRed4', |
| 1497 | \ 'MediumPurple2', 'yellow2', |
| 1498 | \ 'RosyBrown3', 'OrangeRed2', |
| 1499 | \ 'white smoke', 'navy blue', |
| 1500 | \ 'grey47', 'gray97', |
| 1501 | \ 'MistyRose2', 'DodgerBlue4', |
| 1502 | \] |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1503 | eval buf->term_setansicolors(colors) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1504 | |
| 1505 | let colors[4] = 'Invalid' |
| 1506 | call assert_fails('call term_setansicolors(buf, colors)', 'E474:') |
| 1507 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1508 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1509 | call term_wait(buf) |
| 1510 | exe buf . 'bwipe' |
| 1511 | endfunc |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1512 | |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1513 | func Test_terminal_all_ansi_colors() |
| 1514 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1515 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1516 | endif |
| 1517 | |
| 1518 | " Use all the ANSI colors. |
| 1519 | call writefile([ |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1520 | \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")', |
Bram Moolenaar | a0aaf3c | 2019-04-13 23:18:21 +0200 | [diff] [blame] | 1521 | \ 'hi Tblack ctermfg=0 ctermbg=8', |
| 1522 | \ 'hi Tdarkred ctermfg=1 ctermbg=9', |
| 1523 | \ 'hi Tdarkgreen ctermfg=2 ctermbg=10', |
| 1524 | \ 'hi Tbrown ctermfg=3 ctermbg=11', |
| 1525 | \ 'hi Tdarkblue ctermfg=4 ctermbg=12', |
| 1526 | \ 'hi Tdarkmagenta ctermfg=5 ctermbg=13', |
| 1527 | \ 'hi Tdarkcyan ctermfg=6 ctermbg=14', |
| 1528 | \ 'hi Tlightgrey ctermfg=7 ctermbg=15', |
| 1529 | \ 'hi Tdarkgrey ctermfg=8 ctermbg=0', |
| 1530 | \ 'hi Tred ctermfg=9 ctermbg=1', |
| 1531 | \ 'hi Tgreen ctermfg=10 ctermbg=2', |
| 1532 | \ 'hi Tyellow ctermfg=11 ctermbg=3', |
| 1533 | \ 'hi Tblue ctermfg=12 ctermbg=4', |
| 1534 | \ 'hi Tmagenta ctermfg=13 ctermbg=5', |
| 1535 | \ 'hi Tcyan ctermfg=14 ctermbg=6', |
| 1536 | \ 'hi Twhite ctermfg=15 ctermbg=7', |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1537 | \ 'hi TdarkredBold ctermfg=1 cterm=bold', |
| 1538 | \ 'hi TgreenBold ctermfg=10 cterm=bold', |
| 1539 | \ 'hi TmagentaBold ctermfg=13 cterm=bold ctermbg=5', |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1540 | \ '', |
| 1541 | \ 'call matchadd("Tblack", "A")', |
| 1542 | \ 'call matchadd("Tdarkred", "B")', |
| 1543 | \ 'call matchadd("Tdarkgreen", "C")', |
| 1544 | \ 'call matchadd("Tbrown", "D")', |
| 1545 | \ 'call matchadd("Tdarkblue", "E")', |
| 1546 | \ 'call matchadd("Tdarkmagenta", "F")', |
| 1547 | \ 'call matchadd("Tdarkcyan", "G")', |
| 1548 | \ 'call matchadd("Tlightgrey", "H")', |
| 1549 | \ 'call matchadd("Tdarkgrey", "I")', |
| 1550 | \ 'call matchadd("Tred", "J")', |
| 1551 | \ 'call matchadd("Tgreen", "K")', |
| 1552 | \ 'call matchadd("Tyellow", "L")', |
| 1553 | \ 'call matchadd("Tblue", "M")', |
| 1554 | \ 'call matchadd("Tmagenta", "N")', |
| 1555 | \ 'call matchadd("Tcyan", "O")', |
| 1556 | \ 'call matchadd("Twhite", "P")', |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1557 | \ 'call matchadd("TdarkredBold", "X")', |
| 1558 | \ 'call matchadd("TgreenBold", "Y")', |
| 1559 | \ 'call matchadd("TmagentaBold", "Z")', |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1560 | \ 'redraw', |
| 1561 | \ ], 'Xcolorscript') |
| 1562 | let buf = RunVimInTerminal('-S Xcolorscript', {'rows': 10}) |
| 1563 | call VerifyScreenDump(buf, 'Test_terminal_all_ansi_colors', {}) |
| 1564 | |
| 1565 | call term_sendkeys(buf, ":q\<CR>") |
| 1566 | call StopVimInTerminal(buf) |
| 1567 | call delete('Xcolorscript') |
| 1568 | endfunc |
| 1569 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1570 | func Test_terminal_termwinsize_option_fixed() |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1571 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 1572 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1573 | endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1574 | set termwinsize=6x40 |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1575 | let text = [] |
| 1576 | for n in range(10) |
| 1577 | call add(text, repeat(n, 50)) |
| 1578 | endfor |
| 1579 | call writefile(text, 'Xwinsize') |
| 1580 | let buf = RunVimInTerminal('Xwinsize', {}) |
| 1581 | let win = bufwinid(buf) |
| 1582 | call assert_equal([6, 40], term_getsize(buf)) |
| 1583 | call assert_equal(6, winheight(win)) |
| 1584 | call assert_equal(40, winwidth(win)) |
| 1585 | |
| 1586 | " resizing the window doesn't resize the terminal. |
| 1587 | resize 10 |
| 1588 | vertical resize 60 |
| 1589 | call assert_equal([6, 40], term_getsize(buf)) |
| 1590 | call assert_equal(10, winheight(win)) |
| 1591 | call assert_equal(60, winwidth(win)) |
| 1592 | |
| 1593 | call StopVimInTerminal(buf) |
| 1594 | call delete('Xwinsize') |
| 1595 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1596 | call assert_fails('set termwinsize=40', 'E474') |
| 1597 | call assert_fails('set termwinsize=10+40', 'E474') |
| 1598 | call assert_fails('set termwinsize=abc', 'E474') |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1599 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1600 | set termwinsize= |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1601 | endfunc |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1602 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1603 | func Test_terminal_termwinsize_option_zero() |
| 1604 | set termwinsize=0x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1605 | let buf = Run_shell_in_terminal({}) |
| 1606 | let win = bufwinid(buf) |
| 1607 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1608 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1609 | call term_wait(buf) |
| 1610 | exe buf . 'bwipe' |
| 1611 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1612 | set termwinsize=7x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1613 | let buf = Run_shell_in_terminal({}) |
| 1614 | let win = bufwinid(buf) |
| 1615 | call assert_equal([7, winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1616 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1617 | call term_wait(buf) |
| 1618 | exe buf . 'bwipe' |
| 1619 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1620 | set termwinsize=0x33 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1621 | let buf = Run_shell_in_terminal({}) |
| 1622 | let win = bufwinid(buf) |
| 1623 | call assert_equal([winheight(win), 33], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1624 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1625 | call term_wait(buf) |
| 1626 | exe buf . 'bwipe' |
| 1627 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1628 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1629 | endfunc |
| 1630 | |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 1631 | func Test_terminal_termwinsize_minimum() |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1632 | set termwinsize=10*50 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1633 | vsplit |
| 1634 | let buf = Run_shell_in_terminal({}) |
| 1635 | let win = bufwinid(buf) |
| 1636 | call assert_inrange(10, 1000, winheight(win)) |
| 1637 | call assert_inrange(50, 1000, winwidth(win)) |
| 1638 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
| 1639 | |
| 1640 | resize 15 |
| 1641 | vertical resize 60 |
| 1642 | redraw |
| 1643 | call assert_equal([15, 60], term_getsize(buf)) |
| 1644 | call assert_equal(15, winheight(win)) |
| 1645 | call assert_equal(60, winwidth(win)) |
| 1646 | |
| 1647 | resize 7 |
| 1648 | vertical resize 30 |
| 1649 | redraw |
| 1650 | call assert_equal([10, 50], term_getsize(buf)) |
| 1651 | call assert_equal(7, winheight(win)) |
| 1652 | call assert_equal(30, winwidth(win)) |
| 1653 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1654 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1655 | call term_wait(buf) |
| 1656 | exe buf . 'bwipe' |
| 1657 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1658 | set termwinsize=0*0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1659 | let buf = Run_shell_in_terminal({}) |
| 1660 | let win = bufwinid(buf) |
| 1661 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1662 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1663 | call term_wait(buf) |
| 1664 | exe buf . 'bwipe' |
| 1665 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1666 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1667 | endfunc |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1668 | |
| 1669 | func Test_terminal_termwinkey() |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1670 | " make three tabpages, terminal in the middle |
| 1671 | 0tabnew |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1672 | tabnext |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1673 | tabnew |
| 1674 | tabprev |
| 1675 | call assert_equal(1, winnr('$')) |
| 1676 | call assert_equal(2, tabpagenr()) |
| 1677 | let thiswin = win_getid() |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1678 | |
| 1679 | let buf = Run_shell_in_terminal({}) |
| 1680 | let termwin = bufwinid(buf) |
| 1681 | set termwinkey=<C-L> |
| 1682 | call feedkeys("\<C-L>w", 'tx') |
| 1683 | call assert_equal(thiswin, win_getid()) |
| 1684 | call feedkeys("\<C-W>w", 'tx') |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1685 | call assert_equal(termwin, win_getid()) |
| 1686 | |
Bram Moolenaar | a4b2699 | 2019-08-15 20:58:54 +0200 | [diff] [blame] | 1687 | set langmap=xjyk |
| 1688 | call feedkeys("\<C-L>x", 'tx') |
| 1689 | call assert_equal(thiswin, win_getid()) |
| 1690 | call feedkeys("\<C-W>y", 'tx') |
| 1691 | call assert_equal(termwin, win_getid()) |
| 1692 | set langmap= |
| 1693 | |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1694 | call feedkeys("\<C-L>gt", "xt") |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1695 | call assert_equal(3, tabpagenr()) |
| 1696 | tabprev |
| 1697 | call assert_equal(2, tabpagenr()) |
| 1698 | call assert_equal(termwin, win_getid()) |
| 1699 | |
| 1700 | call feedkeys("\<C-L>gT", "xt") |
| 1701 | call assert_equal(1, tabpagenr()) |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1702 | tabnext |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1703 | call assert_equal(2, tabpagenr()) |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1704 | call assert_equal(termwin, win_getid()) |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1705 | |
| 1706 | let job = term_getjob(buf) |
| 1707 | call feedkeys("\<C-L>\<C-C>", 'tx') |
| 1708 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 1709 | |
| 1710 | set termwinkey& |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1711 | tabnext |
| 1712 | tabclose |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1713 | tabprev |
| 1714 | tabclose |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1715 | endfunc |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1716 | |
| 1717 | func Test_terminal_out_err() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1718 | CheckUnix |
| 1719 | |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1720 | call writefile([ |
| 1721 | \ '#!/bin/sh', |
| 1722 | \ 'echo "this is standard error" >&2', |
| 1723 | \ 'echo "this is standard out" >&1', |
| 1724 | \ ], 'Xechoerrout.sh') |
| 1725 | call setfperm('Xechoerrout.sh', 'rwxrwx---') |
| 1726 | |
| 1727 | let outfile = 'Xtermstdout' |
| 1728 | let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) |
Bram Moolenaar | 5319191 | 2018-06-19 20:08:14 +0200 | [diff] [blame] | 1729 | |
| 1730 | call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))}) |
| 1731 | call assert_equal(['this is standard out'], readfile(outfile)) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1732 | call assert_equal('this is standard error', term_getline(buf, 1)) |
| 1733 | |
Bram Moolenaar | 54c6baf | 2018-05-12 21:12:12 +0200 | [diff] [blame] | 1734 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1735 | exe buf . 'bwipe' |
| 1736 | call delete('Xechoerrout.sh') |
| 1737 | call delete(outfile) |
| 1738 | endfunc |
Bram Moolenaar | 4d6cd29 | 2018-05-15 23:53:26 +0200 | [diff] [blame] | 1739 | |
| 1740 | func Test_terminwinscroll() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1741 | CheckUnix |
Bram Moolenaar | 4d6cd29 | 2018-05-15 23:53:26 +0200 | [diff] [blame] | 1742 | |
| 1743 | " Let the terminal output more than 'termwinscroll' lines, some at the start |
| 1744 | " will be dropped. |
| 1745 | exe 'set termwinscroll=' . &lines |
| 1746 | let buf = term_start('/bin/sh') |
| 1747 | for i in range(1, &lines) |
| 1748 | call feedkeys("echo " . i . "\<CR>", 'xt') |
| 1749 | call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))}) |
| 1750 | endfor |
| 1751 | " Go to Terminal-Normal mode to update the buffer. |
| 1752 | call feedkeys("\<C-W>N", 'xt') |
| 1753 | call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$')) |
| 1754 | |
| 1755 | " Every "echo nr" must only appear once |
| 1756 | let lines = getline(1, line('$')) |
| 1757 | for i in range(&lines - len(lines) / 2 + 2, &lines) |
| 1758 | let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'}) |
| 1759 | call assert_equal(1, len(filtered), 'for "echo ' . i . '"') |
| 1760 | endfor |
| 1761 | |
| 1762 | exe buf . 'bwipe!' |
| 1763 | endfunc |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1764 | |
Bram Moolenaar | 875cf87 | 2018-07-08 20:49:07 +0200 | [diff] [blame] | 1765 | " Resizing the terminal window caused an ml_get error. |
| 1766 | " TODO: This does not reproduce the original problem. |
| 1767 | func Test_terminal_resize() |
| 1768 | set statusline=x |
| 1769 | terminal |
| 1770 | call assert_equal(2, winnr('$')) |
| 1771 | |
| 1772 | " Fill the terminal with text. |
| 1773 | if has('win32') |
| 1774 | call feedkeys("dir\<CR>", 'xt') |
| 1775 | else |
| 1776 | call feedkeys("ls\<CR>", 'xt') |
| 1777 | endif |
| 1778 | " Go to Terminal-Normal mode for a moment. |
| 1779 | call feedkeys("\<C-W>N", 'xt') |
| 1780 | " Open a new window |
| 1781 | call feedkeys("i\<C-W>n", 'xt') |
| 1782 | call assert_equal(3, winnr('$')) |
| 1783 | redraw |
| 1784 | |
| 1785 | close |
| 1786 | call assert_equal(2, winnr('$')) |
| 1787 | call feedkeys("exit\<CR>", 'xt') |
| 1788 | set statusline& |
| 1789 | endfunc |
| 1790 | |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1791 | " must be nearly the last, we can't go back from GUI to terminal |
| 1792 | func Test_zz1_terminal_in_gui() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1793 | CheckCanRunGui |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1794 | |
| 1795 | " Ignore the "failed to create input context" error. |
| 1796 | call test_ignore_error('E285:') |
| 1797 | |
| 1798 | gui -f |
| 1799 | |
| 1800 | call assert_equal(1, winnr('$')) |
| 1801 | let buf = Run_shell_in_terminal({'term_finish': 'close'}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1802 | call StopShellInTerminal(buf) |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1803 | call term_wait(buf) |
| 1804 | |
| 1805 | " closing window wipes out the terminal buffer a with finished job |
| 1806 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 1807 | call assert_equal("", bufname(buf)) |
| 1808 | |
| 1809 | unlet g:job |
| 1810 | endfunc |
| 1811 | |
| 1812 | func Test_zz2_terminal_guioptions_bang() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1813 | CheckGui |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1814 | set guioptions+=! |
| 1815 | |
| 1816 | let filename = 'Xtestscript' |
| 1817 | if has('win32') |
| 1818 | let filename .= '.bat' |
| 1819 | let prefix = '' |
| 1820 | let contents = ['@echo off', 'exit %1'] |
| 1821 | else |
| 1822 | let filename .= '.sh' |
| 1823 | let prefix = './' |
| 1824 | let contents = ['#!/bin/sh', 'exit $1'] |
| 1825 | endif |
| 1826 | call writefile(contents, filename) |
| 1827 | call setfperm(filename, 'rwxrwx---') |
| 1828 | |
| 1829 | " Check if v:shell_error is equal to the exit status. |
| 1830 | let exitval = 0 |
| 1831 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1832 | call assert_equal(exitval, v:shell_error) |
| 1833 | |
| 1834 | let exitval = 9 |
| 1835 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1836 | call assert_equal(exitval, v:shell_error) |
| 1837 | |
| 1838 | set guioptions& |
| 1839 | call delete(filename) |
| 1840 | endfunc |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1841 | |
| 1842 | func Test_terminal_hidden() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1843 | CheckUnix |
| 1844 | |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1845 | term ++hidden cat |
| 1846 | let bnr = bufnr('$') |
| 1847 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1848 | exe 'sbuf ' . bnr |
| 1849 | call assert_equal('terminal', &buftype) |
| 1850 | call term_sendkeys(bnr, "asdf\<CR>") |
| 1851 | call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))}) |
| 1852 | call term_sendkeys(bnr, "\<C-D>") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1853 | call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())}) |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1854 | bwipe! |
| 1855 | endfunc |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 1856 | |
Bram Moolenaar | a4c2a24 | 2019-03-25 23:01:38 +0100 | [diff] [blame] | 1857 | func Test_terminal_switch_mode() |
| 1858 | term |
| 1859 | let bnr = bufnr('$') |
| 1860 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1861 | call feedkeys("\<C-W>N", 'xt') |
| 1862 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1863 | call feedkeys("A", 'xt') |
| 1864 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1865 | call feedkeys("\<C-W>N", 'xt') |
| 1866 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1867 | call feedkeys("I", 'xt') |
| 1868 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1869 | call feedkeys("\<C-W>Nv", 'xt') |
| 1870 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1871 | call feedkeys("I", 'xt') |
| 1872 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1873 | call feedkeys("\<C-W>Nv", 'xt') |
| 1874 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1875 | call feedkeys("A", 'xt') |
| 1876 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1877 | bwipe! |
| 1878 | endfunc |
| 1879 | |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 1880 | func Test_terminal_hidden_and_close() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1881 | CheckUnix |
| 1882 | |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 1883 | call assert_equal(1, winnr('$')) |
| 1884 | term ++hidden ++close ls |
| 1885 | let bnr = bufnr('$') |
| 1886 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1887 | call WaitForAssert({-> assert_false(bufexists(bnr))}) |
| 1888 | call assert_equal(1, winnr('$')) |
| 1889 | endfunc |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1890 | |
| 1891 | func Test_terminal_does_not_truncate_last_newlines() |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 1892 | " This test does not pass through ConPTY. |
| 1893 | if has('conpty') |
| 1894 | return |
| 1895 | endif |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1896 | let contents = [ |
| 1897 | \ [ 'One', '', 'X' ], |
| 1898 | \ [ 'Two', '', '' ], |
| 1899 | \ [ 'Three' ] + repeat([''], 30) |
| 1900 | \ ] |
| 1901 | |
| 1902 | for c in contents |
| 1903 | call writefile(c, 'Xfile') |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 1904 | if has('win32') |
| 1905 | term cmd /c type Xfile |
| 1906 | else |
| 1907 | term cat Xfile |
| 1908 | endif |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1909 | let bnr = bufnr('$') |
| 1910 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1911 | call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 1912 | sleep 100m |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1913 | call assert_equal(c, getline(1, line('$'))) |
| 1914 | quit |
| 1915 | endfor |
| 1916 | |
| 1917 | call delete('Xfile') |
| 1918 | endfunc |
Bram Moolenaar | e751a5f | 2018-12-16 16:16:10 +0100 | [diff] [blame] | 1919 | |
Bram Moolenaar | 528ccfb | 2018-12-21 20:55:22 +0100 | [diff] [blame] | 1920 | func Test_terminal_no_job() |
| 1921 | let term = term_start('false', {'term_finish': 'close'}) |
| 1922 | call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) }) |
| 1923 | endfunc |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1924 | |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 1925 | func Test_term_getcursor() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1926 | CheckUnix |
| 1927 | |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 1928 | let buf = Run_shell_in_terminal({}) |
| 1929 | |
| 1930 | " Wait for the shell to display a prompt. |
| 1931 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 1932 | |
| 1933 | " Hide the cursor. |
| 1934 | call term_sendkeys(buf, "echo -e '\\033[?25l'\r") |
| 1935 | call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)}) |
| 1936 | |
| 1937 | " Show the cursor. |
| 1938 | call term_sendkeys(buf, "echo -e '\\033[?25h'\r") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1939 | call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)}) |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 1940 | |
| 1941 | " Change color of cursor. |
| 1942 | call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)}) |
| 1943 | call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r") |
| 1944 | call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)}) |
| 1945 | call term_sendkeys(buf, "echo -e '\\033]12;green\\007'\r") |
| 1946 | call WaitForAssert({-> assert_equal('green', term_getcursor(buf)[2].color)}) |
| 1947 | |
| 1948 | " Make cursor a blinking block. |
| 1949 | call term_sendkeys(buf, "echo -e '\\033[1 q'\r") |
| 1950 | call WaitForAssert({-> assert_equal([1, 1], |
| 1951 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1952 | |
| 1953 | " Make cursor a steady block. |
| 1954 | call term_sendkeys(buf, "echo -e '\\033[2 q'\r") |
| 1955 | call WaitForAssert({-> assert_equal([0, 1], |
| 1956 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1957 | |
| 1958 | " Make cursor a blinking underline. |
| 1959 | call term_sendkeys(buf, "echo -e '\\033[3 q'\r") |
| 1960 | call WaitForAssert({-> assert_equal([1, 2], |
| 1961 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1962 | |
| 1963 | " Make cursor a steady underline. |
| 1964 | call term_sendkeys(buf, "echo -e '\\033[4 q'\r") |
| 1965 | call WaitForAssert({-> assert_equal([0, 2], |
| 1966 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1967 | |
| 1968 | " Make cursor a blinking vertical bar. |
| 1969 | call term_sendkeys(buf, "echo -e '\\033[5 q'\r") |
| 1970 | call WaitForAssert({-> assert_equal([1, 3], |
| 1971 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1972 | |
| 1973 | " Make cursor a steady vertical bar. |
| 1974 | call term_sendkeys(buf, "echo -e '\\033[6 q'\r") |
| 1975 | call WaitForAssert({-> assert_equal([0, 3], |
| 1976 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 1977 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1978 | call StopShellInTerminal(buf) |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 1979 | endfunc |
| 1980 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1981 | func Test_term_gettitle() |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1982 | " term_gettitle() returns an empty string for a non-terminal buffer |
Bram Moolenaar | 4a5711b | 2019-04-06 12:39:55 +0200 | [diff] [blame] | 1983 | " and for a non-existing buffer. |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1984 | call assert_equal('', bufnr('%')->term_gettitle()) |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1985 | call assert_equal('', term_gettitle(bufnr('$') + 1)) |
| 1986 | |
Bram Moolenaar | 4a5711b | 2019-04-06 12:39:55 +0200 | [diff] [blame] | 1987 | if !has('title') || &title == 0 || empty(&t_ts) |
| 1988 | throw "Skipped: can't get/set title" |
| 1989 | endif |
| 1990 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1991 | let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile']) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 1992 | if has('autoservername') |
Bram Moolenaar | 9c35d05 | 2019-04-13 20:39:15 +0200 | [diff] [blame] | 1993 | call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d\+$', term_gettitle(term)) }) |
| 1994 | call term_sendkeys(term, ":e Xfoo\r") |
| 1995 | call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d\+$', term_gettitle(term)) }) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 1996 | else |
| 1997 | call WaitForAssert({-> assert_equal('[No Name] - VIM', term_gettitle(term)) }) |
Bram Moolenaar | 9c35d05 | 2019-04-13 20:39:15 +0200 | [diff] [blame] | 1998 | call term_sendkeys(term, ":e Xfoo\r") |
| 1999 | call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM$', term_gettitle(term)) }) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2000 | endif |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2001 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2002 | call term_sendkeys(term, ":set titlestring=foo\r") |
| 2003 | call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) }) |
| 2004 | |
| 2005 | exe term . 'bwipe!' |
| 2006 | endfunc |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 2007 | |
| 2008 | " When drawing the statusline the cursor position may not have been updated |
| 2009 | " yet. |
| 2010 | " 1. create a terminal, make it show 2 lines |
| 2011 | " 2. 0.5 sec later: leave terminal window, execute "i" |
| 2012 | " 3. 0.5 sec later: clear terminal window, now it's 1 line |
| 2013 | " 4. 0.5 sec later: redraw, including statusline (used to trigger bug) |
| 2014 | " 4. 0.5 sec later: should be done, clean up |
| 2015 | func Test_terminal_statusline() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2016 | CheckUnix |
| 2017 | |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 2018 | set statusline=x |
| 2019 | terminal |
| 2020 | let tbuf = bufnr('') |
| 2021 | call term_sendkeys(tbuf, "clear; echo a; echo b; sleep 1; clear\n") |
| 2022 | call timer_start(500, { tid -> feedkeys("\<C-w>j", 'tx') }) |
| 2023 | call timer_start(1500, { tid -> feedkeys("\<C-l>", 'tx') }) |
| 2024 | au BufLeave * if &buftype == 'terminal' | silent! normal i | endif |
| 2025 | |
| 2026 | sleep 2 |
| 2027 | exe tbuf . 'bwipe!' |
| 2028 | au! BufLeave |
| 2029 | set statusline= |
| 2030 | endfunc |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2031 | |
| 2032 | func Test_terminal_getwinpos() |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2033 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 2034 | throw 'Skipped: cannot run Vim in a terminal window' |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2035 | endif |
| 2036 | |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2037 | " split, go to the bottom-right window |
| 2038 | split |
| 2039 | wincmd j |
| 2040 | set splitright |
| 2041 | |
| 2042 | call writefile([ |
| 2043 | \ 'echo getwinpos()', |
| 2044 | \ ], 'XTest_getwinpos') |
| 2045 | let buf = RunVimInTerminal('-S XTest_getwinpos', {'cols': 60}) |
| 2046 | call term_wait(buf) |
| 2047 | |
| 2048 | " Find the output of getwinpos() in the bottom line. |
| 2049 | let rows = term_getsize(buf)[0] |
| 2050 | call WaitForAssert({-> assert_match('\[\d\+, \d\+\]', term_getline(buf, rows))}) |
| 2051 | let line = term_getline(buf, rows) |
| 2052 | let xpos = str2nr(substitute(line, '\[\(\d\+\), \d\+\]', '\1', '')) |
| 2053 | let ypos = str2nr(substitute(line, '\[\d\+, \(\d\+\)\]', '\1', '')) |
| 2054 | |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2055 | " Position must be bigger than the getwinpos() result of Vim itself. |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2056 | " The calculation in the console assumes a 10 x 7 character cell. |
Bram Moolenaar | 1b55797 | 2019-04-09 21:17:32 +0200 | [diff] [blame] | 2057 | " In the GUI it can be more, let's assume a 20 x 14 cell. |
| 2058 | " And then add 100 / 200 tolerance. |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2059 | let [xroot, yroot] = getwinpos() |
Bram Moolenaar | 5d69fdb | 2019-08-31 19:13:58 +0200 | [diff] [blame] | 2060 | let winpos = 50->getwinpos() |
| 2061 | call assert_equal(xroot, winpos[0]) |
| 2062 | call assert_equal(yroot, winpos[1]) |
Bram Moolenaar | 1b55797 | 2019-04-09 21:17:32 +0200 | [diff] [blame] | 2063 | let [winrow, wincol] = win_screenpos('.') |
| 2064 | let xoff = wincol * (has('gui_running') ? 14 : 7) + 100 |
| 2065 | let yoff = winrow * (has('gui_running') ? 20 : 10) + 200 |
| 2066 | call assert_inrange(xroot + 2, xroot + xoff, xpos) |
| 2067 | call assert_inrange(yroot + 2, yroot + yoff, ypos) |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2068 | |
| 2069 | call term_wait(buf) |
| 2070 | call term_sendkeys(buf, ":q\<CR>") |
| 2071 | call StopVimInTerminal(buf) |
| 2072 | call delete('XTest_getwinpos') |
| 2073 | exe buf . 'bwipe!' |
| 2074 | set splitright& |
| 2075 | only! |
| 2076 | endfunc |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2077 | |
| 2078 | func Test_terminal_altscreen() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2079 | " somehow doesn't work on MS-Windows |
| 2080 | CheckUnix |
| 2081 | let cmd = "cat Xtext\<CR>" |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2082 | |
| 2083 | let buf = term_start(&shell, {}) |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2084 | call writefile(["\<Esc>[?1047h"], 'Xtext') |
| 2085 | call term_sendkeys(buf, cmd) |
Bram Moolenaar | b9c79cf | 2019-09-08 22:09:52 +0200 | [diff] [blame] | 2086 | call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) |
| 2087 | |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2088 | call writefile(["\<Esc>[?1047l"], 'Xtext') |
| 2089 | call term_sendkeys(buf, cmd) |
Bram Moolenaar | b9c79cf | 2019-09-08 22:09:52 +0200 | [diff] [blame] | 2090 | call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2091 | |
| 2092 | call term_sendkeys(buf, "exit\r") |
| 2093 | exe buf . "bwipe!" |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2094 | call delete('Xtext') |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2095 | endfunc |