blob: 64d754b31bcdc1db4803f141438c84861a9503fe [file] [log] [blame]
Bram Moolenaar905dd902019-04-07 14:21:47 +02001" Tests for decoding escape sequences sent by the terminal.
2
3" This only works for Unix in a terminal
4if has('gui_running') || !has('unix')
5 finish
6endif
7
Bram Moolenaar564344a2019-04-28 13:00:12 +02008source shared.vim
9
Bram Moolenaard0621d82019-05-02 21:12:19 +020010" xterm2 and sgr always work, urxvt is optional.
Bram Moolenaar92fd5992019-05-02 23:00:22 +020011let s:ttymouse_values = ['xterm2', 'sgr']
Bram Moolenaard0621d82019-05-02 21:12:19 +020012if has('mouse_urxvt')
Bram Moolenaar92fd5992019-05-02 23:00:22 +020013 call add(s:ttymouse_values, 'urxvt')
14endif
15
16" dec doesn't support all the functionality
17if has('mouse_dec')
18 let s:ttymouse_dec = ['dec']
19else
20 let s:ttymouse_dec = []
Bram Moolenaard0621d82019-05-02 21:12:19 +020021endif
22
Bram Moolenaard7885432019-05-03 13:44:10 +020023" netterm only supports left click
24if has('mouse_netterm')
25 let s:ttymouse_netterm = ['netterm']
26else
27 let s:ttymouse_netterm = []
28endif
29
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020030" Helper function to emit a terminal escape code.
Bram Moolenaard0621d82019-05-02 21:12:19 +020031func TerminalEscapeCode(code, row, col, m)
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +020032 if &ttymouse ==# 'xterm2'
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020033 " need to use byte encoding here.
Bram Moolenaard0621d82019-05-02 21:12:19 +020034 let str = list2str([a:code + 0x20, a:col + 0x20, a:row + 0x20])
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020035 if has('iconv')
36 let bytes = iconv(str, 'utf-8', 'latin1')
37 else
38 " Hopefully the numbers are not too big.
39 let bytes = str
40 endif
41 call feedkeys("\<Esc>[M" .. bytes, 'Lx!')
42 elseif &ttymouse ==# 'sgr'
Bram Moolenaard0621d82019-05-02 21:12:19 +020043 call feedkeys(printf("\<Esc>[<%d;%d;%d%s", a:code, a:col, a:row, a:m), 'Lx!')
44 elseif &ttymouse ==# 'urxvt'
45 call feedkeys(printf("\<Esc>[%d;%d;%dM", a:code + 0x20, a:col, a:row), 'Lx!')
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020046 endif
47endfunc
48
Bram Moolenaar92fd5992019-05-02 23:00:22 +020049func DecEscapeCode(code, down, row, col)
50 call feedkeys(printf("\<Esc>[%d;%d;%d;%d&w", a:code, a:down, a:row, a:col), 'Lx!')
51endfunc
52
Bram Moolenaard7885432019-05-03 13:44:10 +020053func NettermEscapeCode(row, col)
54 call feedkeys(printf("\<Esc>}%d,%d\r", a:row, a:col), 'Lx!')
55endfunc
56
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020057func MouseLeftClick(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +020058 if &ttymouse ==# 'dec'
59 call DecEscapeCode(2, 4, a:row, a:col)
Bram Moolenaard7885432019-05-03 13:44:10 +020060 elseif &ttymouse ==# 'netterm'
61 call NettermEscapeCode(a:row, a:col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +020062 else
63 call TerminalEscapeCode(0, a:row, a:col, 'M')
64 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020065endfunc
66
Bram Moolenaarc1b81602019-04-27 19:11:35 +020067func MouseMiddleClick(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +020068 if &ttymouse ==# 'dec'
69 call DecEscapeCode(4, 2, a:row, a:col)
70 else
71 call TerminalEscapeCode(1, a:row, a:col, 'M')
72 endif
Bram Moolenaarc1b81602019-04-27 19:11:35 +020073endfunc
74
Bram Moolenaar1ee36d62019-05-01 23:13:56 +020075func MouseCtrlLeftClick(row, col)
76 let ctrl = 0x10
Bram Moolenaard0621d82019-05-02 21:12:19 +020077 call TerminalEscapeCode(0 + ctrl, a:row, a:col, 'M')
Bram Moolenaar1ee36d62019-05-01 23:13:56 +020078endfunc
79
80func MouseCtrlRightClick(row, col)
81 let ctrl = 0x10
Bram Moolenaard0621d82019-05-02 21:12:19 +020082 call TerminalEscapeCode(2 + ctrl, a:row, a:col, 'M')
Bram Moolenaar1ee36d62019-05-01 23:13:56 +020083endfunc
84
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020085func MouseLeftRelease(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +020086 if &ttymouse ==# 'dec'
87 call DecEscapeCode(3, 0, a:row, a:col)
Bram Moolenaard7885432019-05-03 13:44:10 +020088 elseif &ttymouse ==# 'netterm'
89 " send nothing
Bram Moolenaar92fd5992019-05-02 23:00:22 +020090 else
91 call TerminalEscapeCode(3, a:row, a:col, 'm')
92 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020093endfunc
94
Bram Moolenaarc1b81602019-04-27 19:11:35 +020095func MouseMiddleRelease(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +020096 if &ttymouse ==# 'dec'
97 call DecEscapeCode(5, 0, a:row, a:col)
98 else
99 call TerminalEscapeCode(3, a:row, a:col, 'm')
100 endif
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200101endfunc
102
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200103func MouseRightRelease(row, col)
Bram Moolenaard0621d82019-05-02 21:12:19 +0200104 call TerminalEscapeCode(3, a:row, a:col, 'm')
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200105endfunc
106
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200107func MouseLeftDrag(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200108 if &ttymouse ==# 'dec'
109 call DecEscapeCode(1, 4, a:row, a:col)
110 else
111 call TerminalEscapeCode(0x20, a:row, a:col, 'M')
112 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200113endfunc
114
115func MouseWheelUp(row, col)
Bram Moolenaard0621d82019-05-02 21:12:19 +0200116 call TerminalEscapeCode(0x40, a:row, a:col, 'M')
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200117endfunc
118
119func MouseWheelDown(row, col)
Bram Moolenaard0621d82019-05-02 21:12:19 +0200120 call TerminalEscapeCode(0x41, a:row, a:col, 'M')
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200121endfunc
122
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200123func Test_term_mouse_left_click()
Bram Moolenaar905dd902019-04-07 14:21:47 +0200124 new
125 let save_mouse = &mouse
126 let save_term = &term
127 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200128 call test_override('no_query_mouse', 1)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200129 set mouse=a term=xterm
Bram Moolenaar905dd902019-04-07 14:21:47 +0200130 call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
Bram Moolenaar905dd902019-04-07 14:21:47 +0200131
Bram Moolenaard7885432019-05-03 13:44:10 +0200132 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec + s:ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +0200133 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200134 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200135 go
Bram Moolenaar49452192019-04-17 16:27:02 +0200136 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200137 let row = 2
138 let col = 6
139 call MouseLeftClick(row, col)
140 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200141 call assert_equal([0, 2, 6, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200142 endfor
Bram Moolenaar905dd902019-04-07 14:21:47 +0200143
144 let &mouse = save_mouse
145 let &term = save_term
146 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200147 call test_override('no_query_mouse', 0)
Bram Moolenaar905dd902019-04-07 14:21:47 +0200148 bwipe!
149endfunc
150
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200151" Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back.
152func Test_xterm_mouse_ctrl_click()
153 let save_mouse = &mouse
154 let save_term = &term
155 let save_ttymouse = &ttymouse
156 set mouse=a term=xterm
157
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200158 for ttymouse_val in s:ttymouse_values
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200159 let msg = 'ttymouse=' .. ttymouse_val
160 exe 'set ttymouse=' .. ttymouse_val
161 help
162 /usr_02.txt
163 norm! zt
164 let row = 1
165 let col = 1
166 call MouseCtrlLeftClick(row, col)
167 call MouseLeftRelease(row, col)
168 call assert_match('usr_02.txt$', bufname('%'), msg)
169 call assert_equal('*usr_02.txt*', expand('<cWORD>'))
170
171 call MouseCtrlRightClick(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200172 call MouseRightRelease(row, col)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200173 call assert_match('help.txt$', bufname('%'), msg)
174 call assert_equal('|usr_02.txt|', expand('<cWORD>'))
175
176 helpclose
177 endfor
178
179 let &mouse = save_mouse
180 let &term = save_term
181 let &ttymouse = save_ttymouse
182endfunc
183
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200184func Test_term_mouse_middle_click()
Bram Moolenaar564344a2019-04-28 13:00:12 +0200185 if !WorkingClipboard()
186 throw 'Skipped: No working clipboard'
187 endif
188
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200189 new
190 let save_mouse = &mouse
191 let save_term = &term
192 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200193 call test_override('no_query_mouse', 1)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200194 let save_quotestar = @*
195 let @* = 'abc'
196 set mouse=a term=xterm
197
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200198 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200199 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200200 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200201 call setline(1, ['123456789', '123456789'])
202
203 " Middle-click in the middle of the line pastes text where clicked.
204 let row = 1
205 let col = 6
206 call MouseMiddleClick(row, col)
207 call MouseMiddleRelease(row, col)
208 call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg)
209
210 " Middle-click beyond end of the line pastes text at the end of the line.
211 let col = 20
212 call MouseMiddleClick(row, col)
213 call MouseMiddleRelease(row, col)
214 call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg)
215
216 " Middle-click beyond the last line pastes in the last line.
217 let row = 5
218 let col = 3
219 call MouseMiddleClick(row, col)
220 call MouseMiddleRelease(row, col)
221 call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg)
222 endfor
223
224 let &mouse = save_mouse
225 let &term = save_term
226 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200227 call test_override('no_query_mouse', 0)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200228 let @* = save_quotestar
229 bwipe!
230endfunc
231
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200232" TODO: for unclear reasons this test fails if it comes after
233" Test_xterm_mouse_ctrl_click()
234func Test_1xterm_mouse_wheel()
Bram Moolenaar049736f2019-04-07 21:55:07 +0200235 new
236 let save_mouse = &mouse
237 let save_term = &term
238 let save_ttymouse = &ttymouse
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200239 set mouse=a term=xterm
Bram Moolenaar049736f2019-04-07 21:55:07 +0200240 call setline(1, range(1, 100))
241
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200242 for ttymouse_val in s:ttymouse_values
Bram Moolenaar49452192019-04-17 16:27:02 +0200243 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200244 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200245 go
Bram Moolenaar49452192019-04-17 16:27:02 +0200246 call assert_equal(1, line('w0'), msg)
247 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200248
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200249 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200250 call assert_equal(4, line('w0'), msg)
251 call assert_equal([0, 4, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200252
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200253 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200254 call assert_equal(7, line('w0'), msg)
255 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200256
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200257 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200258 call assert_equal(4, line('w0'), msg)
259 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200260
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200261 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200262 call assert_equal(1, line('w0'), msg)
263 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200264 endfor
Bram Moolenaar049736f2019-04-07 21:55:07 +0200265
266 let &mouse = save_mouse
267 let &term = save_term
268 let &ttymouse = save_ttymouse
269 bwipe!
270endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200271
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200272func Test_term_mouse_drag_window_separator()
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200273 let save_mouse = &mouse
274 let save_term = &term
275 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200276 call test_override('no_query_mouse', 1)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200277 set mouse=a term=xterm
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200278
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200279 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200280 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200281 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200282
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200283 " Split horizontally and test dragging the horizontal window separator.
284 split
285 let rowseparator = winheight(0) + 1
286 let row = rowseparator
287 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200288
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200289 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
290 if ttymouse_val !=# 'xterm2' || row <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200291 call MouseLeftClick(row, col)
292 let row -= 1
293 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200294 call assert_equal(rowseparator - 1, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200295 let row += 1
296 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200297 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200298 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200299 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200300 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200301 bwipe!
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200302
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200303 " Split vertically and test dragging the vertical window separator.
304 vsplit
305 let colseparator = winwidth(0) + 1
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200306 let row = 1
307 let col = colseparator
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200308
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200309 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
310 if ttymouse_val !=# 'xterm2' || col <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200311 call MouseLeftClick(row, col)
312 let col -= 1
313 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200314 call assert_equal(colseparator - 1, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200315 let col += 1
316 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200317 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200318 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200319 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200320 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200321 bwipe!
322 endfor
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200323
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200324 let &mouse = save_mouse
325 let &term = save_term
326 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200327 call test_override('no_query_mouse', 0)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200328endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200329
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200330func Test_term_mouse_drag_statusline()
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200331 let save_mouse = &mouse
332 let save_term = &term
333 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200334 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200335 let save_laststatus = &laststatus
336 set mouse=a term=xterm laststatus=2
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200337
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200338 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200339 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200340 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200341
Bram Moolenaar49452192019-04-17 16:27:02 +0200342 call assert_equal(1, &cmdheight, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200343 let rowstatusline = winheight(0) + 1
344 let row = rowstatusline
345 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200346
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200347 if ttymouse_val ==# 'xterm2' && row > 223
348 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200349 continue
350 endif
351
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200352 call MouseLeftClick(row, col)
353 let row -= 1
354 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200355 call assert_equal(2, &cmdheight, msg)
356 call assert_equal(rowstatusline - 1, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200357 let row += 1
358 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200359 call assert_equal(1, &cmdheight, msg)
360 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200361 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200362 call assert_equal(1, &cmdheight, msg)
363 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200364 endfor
365
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200366 let &mouse = save_mouse
367 let &term = save_term
368 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200369 call test_override('no_query_mouse', 0)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200370 let &laststatus = save_laststatus
371endfunc
372
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200373func Test_term_mouse_click_tab()
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200374 let save_mouse = &mouse
375 let save_term = &term
376 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200377 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200378 set mouse=a term=xterm
379 let row = 1
380
Bram Moolenaard7885432019-05-03 13:44:10 +0200381 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec + s:ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +0200382 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200383 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200384 e Xfoo
385 tabnew Xbar
386
387 let a = split(execute(':tabs'), "\n")
388 call assert_equal(['Tab page 1',
389 \ ' Xfoo',
390 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200391 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200392
393 " Test clicking on tab names in the tabline at the top.
394 let col = 2
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200395 redraw
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200396 call MouseLeftClick(row, col)
397 call MouseLeftRelease(row, col)
398 let a = split(execute(':tabs'), "\n")
399 call assert_equal(['Tab page 1',
400 \ '> Xfoo',
401 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200402 \ ' Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200403
404 let col = 9
405 call MouseLeftClick(row, col)
406 call MouseLeftRelease(row, col)
407 let a = split(execute(':tabs'), "\n")
408 call assert_equal(['Tab page 1',
409 \ ' Xfoo',
410 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200411 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200412
413 %bwipe!
414 endfor
415
416 let &mouse = save_mouse
417 let &term = save_term
418 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200419 call test_override('no_query_mouse', 0)
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200420endfunc
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200421
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200422func Test_term_mouse_click_X_to_close_tab()
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200423 let save_mouse = &mouse
424 let save_term = &term
425 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200426 call test_override('no_query_mouse', 1)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200427 set mouse=a term=xterm
428 let row = 1
429 let col = &columns
430
Bram Moolenaard7885432019-05-03 13:44:10 +0200431 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec + s:ttymouse_netterm
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200432 if ttymouse_val ==# 'xterm2' && col > 223
433 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200434 continue
435 endif
Bram Moolenaar49452192019-04-17 16:27:02 +0200436 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200437 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200438 e Xtab1
439 tabnew Xtab2
440 tabnew Xtab3
441 tabn 2
442
443 let a = split(execute(':tabs'), "\n")
444 call assert_equal(['Tab page 1',
445 \ ' Xtab1',
446 \ 'Tab page 2',
447 \ '> Xtab2',
448 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200449 \ ' Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200450
451 " Click on "X" in tabline to close current tab i.e. Xtab2.
452 redraw
453 call MouseLeftClick(row, col)
454 call MouseLeftRelease(row, col)
455 let a = split(execute(':tabs'), "\n")
456 call assert_equal(['Tab page 1',
457 \ ' Xtab1',
458 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200459 \ '> Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200460
461 %bwipe!
462 endfor
463
464 let &mouse = save_mouse
465 let &term = save_term
466 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200467 call test_override('no_query_mouse', 0)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200468endfunc
Bram Moolenaare3e38282019-04-15 20:55:31 +0200469
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200470func Test_term_mouse_drag_to_move_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200471 let save_mouse = &mouse
472 let save_term = &term
473 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200474 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200475 " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop
476 set mouse=a term=xterm mousetime=1
477 let row = 1
478
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200479 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200480 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200481 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200482 e Xtab1
483 tabnew Xtab2
484
485 let a = split(execute(':tabs'), "\n")
486 call assert_equal(['Tab page 1',
487 \ ' Xtab1',
488 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200489 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200490 redraw
491
492 " Click in tab2 and drag it to tab1.
493 " Check getcharmod() to verify that click is not
494 " interpreted as a spurious double-click.
495 call MouseLeftClick(row, 10)
Bram Moolenaar49452192019-04-17 16:27:02 +0200496 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200497 for col in [9, 8, 7, 6]
498 call MouseLeftDrag(row, col)
499 endfor
500 call MouseLeftRelease(row, col)
501 let a = split(execute(':tabs'), "\n")
502 call assert_equal(['Tab page 1',
503 \ '> Xtab2',
504 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200505 \ ' Xtab1'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200506
Bram Moolenaar7f279762019-04-15 21:48:22 +0200507 " brief sleep to avoid causing a double-click
508 sleep 20m
Bram Moolenaare3e38282019-04-15 20:55:31 +0200509 %bwipe!
510 endfor
511
512 let &mouse = save_mouse
513 let &term = save_term
514 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200515 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200516 set mousetime&
517endfunc
518
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200519func Test_term_mouse_double_click_to_create_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200520 let save_mouse = &mouse
521 let save_term = &term
522 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200523 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200524 " Set 'mousetime' to a small value, so that double-click works but we don't
525 " have to wait long to avoid a triple-click.
526 set mouse=a term=xterm mousetime=100
527 let row = 1
528 let col = 10
529
Bram Moolenaard0621d82019-05-02 21:12:19 +0200530 let round = 0
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200531 for ttymouse_val in s:ttymouse_values + s:ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200532 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200533 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200534 e Xtab1
535 tabnew Xtab2
536
Bram Moolenaard0621d82019-05-02 21:12:19 +0200537 if round > 0
538 " We need to sleep, or else the first MouseLeftClick() will be
539 " interpreted as a spurious triple-click.
540 sleep 100m
541 endif
542 let round += 1
543
Bram Moolenaare3e38282019-04-15 20:55:31 +0200544 let a = split(execute(':tabs'), "\n")
545 call assert_equal(['Tab page 1',
546 \ ' Xtab1',
547 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200548 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200549
550 redraw
551 call MouseLeftClick(row, col)
552 " Check getcharmod() to verify that first click is not
553 " interpreted as a spurious double-click.
Bram Moolenaar49452192019-04-17 16:27:02 +0200554 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200555 call MouseLeftRelease(row, col)
556 call MouseLeftClick(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200557 call assert_equal(32, getcharmod(), msg) " double-click
Bram Moolenaare3e38282019-04-15 20:55:31 +0200558 call MouseLeftRelease(row, col)
559 let a = split(execute(':tabs'), "\n")
560 call assert_equal(['Tab page 1',
561 \ ' Xtab1',
562 \ 'Tab page 2',
563 \ '> [No Name]',
564 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200565 \ ' Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200566
Bram Moolenaare3e38282019-04-15 20:55:31 +0200567 %bwipe!
568 endfor
569
570 let &mouse = save_mouse
571 let &term = save_term
572 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200573 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200574 set mousetime&
575endfunc
Bram Moolenaar696d6372019-04-17 16:33:46 +0200576
577func Test_xterm_mouse_click_in_fold_columns()
578 new
579 let save_mouse = &mouse
580 let save_term = &term
581 let save_ttymouse = &ttymouse
582 let save_foldcolumn = &foldcolumn
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200583 set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2
Bram Moolenaar696d6372019-04-17 16:33:46 +0200584
585 " Create 2 nested folds.
586 call setline(1, range(1, 7))
587 2,6fold
588 norm! zR
589 4,5fold
590 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
591 \ map(range(1, 7), 'foldclosed(v:val)'))
592
593 " Click in "+" of inner fold in foldcolumn should open it.
594 redraw
595 let row = 4
596 let col = 2
597 call MouseLeftClick(row, col)
598 call MouseLeftRelease(row, col)
599 call assert_equal([-1, -1, -1, -1, -1, -1, -1],
600 \ map(range(1, 7), 'foldclosed(v:val)'))
601
602 " Click in "-" of outer fold in foldcolumn should close it.
603 redraw
604 let row = 2
605 let col = 1
606 call MouseLeftClick(row, col)
607 call MouseLeftRelease(row, col)
608 call assert_equal([-1, 2, 2, 2, 2, 2, -1],
609 \ map(range(1, 7), 'foldclosed(v:val)'))
610 norm! zR
611
612 " Click in "|" of inner fold in foldcolumn should close it.
613 redraw
614 let row = 5
615 let col = 2
616 call MouseLeftClick(row, col)
617 call MouseLeftRelease(row, col)
618 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
619 \ map(range(1, 7), 'foldclosed(v:val)'))
620
621 let &foldcolumn = save_foldcolumn
622 let &ttymouse = save_ttymouse
623 let &term = save_term
624 let &mouse = save_mouse
625 bwipe!
626endfunc
Bram Moolenaar66761db2019-06-05 22:07:51 +0200627
628" This only checks if the sequence is recognized.
629" TODO: check that the values were parsed properly
630func Test_term_rgb_response()
631 set t_RF=x
632 set t_RB=y
633
634 " response to t_RF, 4 digits
635 let red = 0x12
636 let green = 0x34
637 let blue = 0x56
638 let seq = printf("\<Esc>]10;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
639 call feedkeys(seq, 'Lx!')
640 call assert_equal(seq, v:termrfgresp)
641
642 " response to t_RF, 2 digits
643 let red = 0x78
644 let green = 0x9a
645 let blue = 0xbc
646 let seq = printf("\<Esc>]10;rgb:%02x/%02x/%02x\x07", red, green, blue)
647 call feedkeys(seq, 'Lx!')
648 call assert_equal(seq, v:termrfgresp)
649
650 " response to t_RB, 4 digits
651 let red = 0x21
652 let green = 0x43
653 let blue = 0x65
654 let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
655 call feedkeys(seq, 'Lx!')
656 call assert_equal(seq, v:termrbgresp)
657
658 " response to t_RB, 2 digits
659 let red = 0x87
660 let green = 0xa9
661 let blue = 0xcb
662 let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue)
663 call feedkeys(seq, 'Lx!')
664 call assert_equal(seq, v:termrbgresp)
665
666 set t_RF= t_RB=
667endfunc
668
669" This only checks if the sequence is recognized.
670" This must be last, because it has side effects to xterm properties.
671" TODO: check that the values were parsed properly
672func Test_xx_term_style_response()
673 " Termresponse is only parsed when t_RV is not empty.
674 set t_RV=x
675
676 " send the termresponse to trigger requesting the XT codes
677 let seq = "\<Esc>[>41;337;0c"
678 call feedkeys(seq, 'Lx!')
679 call assert_equal(seq, v:termresponse)
680
681 let seq = "\<Esc>P1$r2 q\<Esc>\\"
682 call feedkeys(seq, 'Lx!')
683 call assert_equal(seq, v:termstyleresp)
684
685 set t_RV=
686endfunc