Mercurial > vim
comparison src/testdir/keycode_check.vim @ 31137:548241980a27 v9.0.0903
patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Commit: https://github.com/vim/vim/commit/236dffab43f919bdbc565e6edc38eb27e7a5b657
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 18 21:20:25 2022 +0000
patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Problem: Key code checker doesn't check modifyOtherKeys resource.
Solution: Request the modifyOtherKeys resource value. Drop resource DCS
responses.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 18 Nov 2022 22:30:04 +0100 |
parents | 17e171cf2cca |
children | 0ecb16d5f86f |
comparison
equal
deleted
inserted
replaced
31136:9423dacd1538 | 31137:548241980a27 |
---|---|
132 echo 'No terminal results yet' | 132 echo 'No terminal results yet' |
133 return | 133 return |
134 endif | 134 endif |
135 sort(terms) | 135 sort(terms) |
136 | 136 |
137 var items = ['protocol', 'version', 'status'] | 137 var items = ['protocol', 'version', 'status', 'resource'] |
138 + key_entries->copy()->map((_, v) => v[1]) | 138 + key_entries->copy()->map((_, v) => v[1]) |
139 | 139 |
140 # For each terminal compute the needed width, add two. | 140 # For each terminal compute the needed width, add two. |
141 # You may need to increase the terminal width to avoid wrapping. | 141 # You may need to increase the terminal width to avoid wrapping. |
142 var widths = [] | 142 var widths = [] |
196 &t_TE = "\<Esc>[>4;m" | 196 &t_TE = "\<Esc>[>4;m" |
197 var proto_name = 'none' | 197 var proto_name = 'none' |
198 if proto == 1 | 198 if proto == 1 |
199 &t_TI = "" | 199 &t_TI = "" |
200 elseif proto == 2 | 200 elseif proto == 2 |
201 # Enable modifyOtherKeys level 2 - no status is reported | 201 # Enable modifyOtherKeys level 2 |
202 &t_TI = "\<Esc>[>4;2m" | 202 # Request the resource value: DCS + Q modifyOtherKeys ST |
203 &t_TI = "\<Esc>[>4;2m" .. "\<Esc>P+Q6d6f646966794f746865724b657973\<Esc>\\" | |
203 proto_name = 'mok2' | 204 proto_name = 'mok2' |
204 elseif proto == 3 | 205 elseif proto == 3 |
205 # Enable Kitty keyboard protocol and request the status | 206 # Enable Kitty keyboard protocol and request the status |
206 &t_TI = "\<Esc>[>1u" .. "\<Esc>[?u" | 207 &t_TI = "\<Esc>[>1u" .. "\<Esc>[?u" |
207 proto_name = 'kitty' | 208 proto_name = 'kitty' |
215 &t_TI ..= "\<Esc>[>c" | 216 &t_TI ..= "\<Esc>[>c" |
216 | 217 |
217 # Pattern that matches the line with the version response. | 218 # Pattern that matches the line with the version response. |
218 const version_pattern = "\<Esc>\\[>\\d\\+;\\d\\+;\\d*c" | 219 const version_pattern = "\<Esc>\\[>\\d\\+;\\d\\+;\\d*c" |
219 | 220 |
221 # Pattern that matches the resource value response: | |
222 # DCS 1 + R Pt ST valid | |
223 # DCS 0 + R Pt ST invalid | |
224 const resource_pattern = "\<Esc>P[01]+R.*\<Esc>\\\\" | |
225 | |
220 # Pattern that matches the line with the status. Currently what terminals | 226 # Pattern that matches the line with the status. Currently what terminals |
221 # return for the Kitty keyboard protocol. | 227 # return for the Kitty keyboard protocol. |
222 const status_pattern = "\<Esc>\\[?\\d\\+u" | 228 const kitty_status_pattern = "\<Esc>\\[?\\d\\+u" |
223 | 229 |
224 ch_logfile('keylog', 'w') | 230 ch_logfile('keylog', 'w') |
225 | 231 |
226 # executing a dummy shell command will output t_TI | 232 # executing a dummy shell command will output t_TI |
227 !echo >/dev/null | 233 !echo >/dev/null |
242 endif | 248 endif |
243 endif | 249 endif |
244 endfor | 250 endfor |
245 endif | 251 endif |
246 if reltime(startTime)->reltimefloat() > 3 | 252 if reltime(startTime)->reltimefloat() > 3 |
253 # break out after three seconds | |
247 break | 254 break |
248 endif | 255 endif |
249 endwhile | 256 endwhile |
250 | 257 |
251 echo 'seenVersion: ' seenVersion | 258 echo 'seenVersion: ' seenVersion |
255 keycodes[name] = {} | 262 keycodes[name] = {} |
256 endif | 263 endif |
257 keycodes[name]['protocol'] = proto_name | 264 keycodes[name]['protocol'] = proto_name |
258 keycodes[name]['version'] = '' | 265 keycodes[name]['version'] = '' |
259 keycodes[name]['status'] = '' | 266 keycodes[name]['status'] = '' |
267 keycodes[name]['resource'] = '' | |
260 | 268 |
261 # Check the log file for a status and the version response | 269 # Check the log file for a status and the version response |
262 ch_logfile('', '') | 270 ch_logfile('', '') |
263 var log = readfile('keylog') | 271 var log = readfile('keylog') |
264 delete('keylog') | 272 delete('keylog') |
273 | |
265 for line in log | 274 for line in log |
266 if line =~ 'raw key input' | 275 if line =~ 'raw key input' |
267 var code = substitute(line, '.*raw key input: "\([^"]*\).*', '\1', '') | 276 var code = substitute(line, '.*raw key input: "\([^"]*\).*', '\1', '') |
277 | |
278 # Check for resource value response | |
279 if code =~ resource_pattern | |
280 var resource = substitute(code, '.*\(' .. resource_pattern .. '\).*', '\1', '') | |
281 # use the value as the resource, "=30" means zero | |
282 resource = substitute(resource, '.*\(=\p\+\).*', '\1', '') | |
283 | |
284 if keycodes[name]['resource'] != '' | |
285 echomsg 'Another resource found after ' .. keycodes[name]['resource'] | |
286 endif | |
287 keycodes[name]['resource'] = resource | |
288 endif | |
289 | |
268 # Check for kitty keyboard protocol status | 290 # Check for kitty keyboard protocol status |
269 if code =~ status_pattern | 291 if code =~ kitty_status_pattern |
270 var status = substitute(code, '.*\(' .. status_pattern .. '\).*', '\1', '') | 292 var status = substitute(code, '.*\(' .. kitty_status_pattern .. '\).*', '\1', '') |
271 keycodes[name]['status'] = Literal2hex(status) | 293 # use the response itself as the status |
294 status = Literal2hex(status) | |
295 | |
296 if keycodes[name]['status'] != '' | |
297 echomsg 'Another status found after ' .. keycodes[name]['status'] | |
298 endif | |
299 keycodes[name]['status'] = status | |
272 endif | 300 endif |
273 | 301 |
274 if code =~ version_pattern | 302 if code =~ version_pattern |
275 var version = substitute(code, '.*\(' .. version_pattern .. '\).*', '\1', '') | 303 var version = substitute(code, '.*\(' .. version_pattern .. '\).*', '\1', '') |
276 keycodes[name]['version'] = Literal2hex(version) | 304 keycodes[name]['version'] = Literal2hex(version) |
280 endfor | 308 endfor |
281 | 309 |
282 echo "For Alt to work you may need to press the Windows/Super key as well" | 310 echo "For Alt to work you may need to press the Windows/Super key as well" |
283 echo "When a key press doesn't get to Vim (e.g. when using Alt) press x" | 311 echo "When a key press doesn't get to Vim (e.g. when using Alt) press x" |
284 | 312 |
313 # The log of ignored typeahead is left around for debugging, start with an | |
314 # empty file here. | |
315 delete('keylog-ignore') | |
316 | |
285 for entry in key_entries | 317 for entry in key_entries |
286 # Consume any typeahead. Wait a bit for any responses to arrive. | 318 # Consume any typeahead. Wait a bit for any responses to arrive. |
287 sleep 100m | 319 ch_logfile('keylog-ignore', 'a') |
288 while getchar(1) | 320 while 1 |
289 getchar() | |
290 sleep 100m | 321 sleep 100m |
322 if !getchar(1) | |
323 break | |
324 endif | |
325 while getchar(1) | |
326 getchar() | |
327 endwhile | |
291 endwhile | 328 endwhile |
329 ch_logfile('', '') | |
292 | 330 |
293 ch_logfile('keylog', 'w') | 331 ch_logfile('keylog', 'w') |
294 echo $'Press the {entry[0]} key (q to quit):' | 332 echo $'Press the {entry[0]} key (q to quit):' |
295 var r = getcharstr() | 333 var r = getcharstr() |
296 ch_logfile('', '') | 334 ch_logfile('', '') |
297 if r == 'q' | 335 if r == 'q' |
298 break | 336 break |
299 endif | 337 endif |
338 | |
300 log = readfile('keylog') | 339 log = readfile('keylog') |
301 if entry[1] == 'Tab' | 340 delete('keylog') |
302 # keep a copy | |
303 rename('keylog', 'keylog-tab') | |
304 else | |
305 delete('keylog') | |
306 endif | |
307 if len(log) < 2 | 341 if len(log) < 2 |
308 echoerr 'failed to read result' | 342 echoerr 'failed to read result' |
309 return | 343 return |
310 endif | 344 endif |
311 var done = false | 345 var done = false |
319 # Remove any XTGETTCAP replies. | 353 # Remove any XTGETTCAP replies. |
320 const cappat = "\<Esc>P[01]+\\k\\+=\\x*\<Esc>\\\\" | 354 const cappat = "\<Esc>P[01]+\\k\\+=\\x*\<Esc>\\\\" |
321 code = substitute(code, cappat, '', 'g') | 355 code = substitute(code, cappat, '', 'g') |
322 | 356 |
323 # Remove any kitty status reply | 357 # Remove any kitty status reply |
324 code = substitute(code, status_pattern, '', 'g') | 358 code = substitute(code, kitty_status_pattern, '', 'g') |
325 if code == '' | 359 if code == '' |
326 continue | 360 continue |
327 endif | 361 endif |
328 | 362 |
329 # Convert the literal bytes into hex. If 'x' was pressed then clear | 363 # Convert the literal bytes into hex. If 'x' was pressed then clear |