annotate src/testdir/keycode_check.vim @ 31156:0ecb16d5f86f v9.0.0912

patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm Commit: https://github.com/vim/vim/commit/c896adbcdee8b2296433a61c1f009aae9f68a594 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 19 19:02:40 2022 +0000 patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm Problem: libvterm with modifyOtherKeys level 2 does not match xterm. Solution: Adjust key code escape sequences to be the same as what xterm sends in modifyOtherKeys level 2 mode. Check the value of no_reduce_keys before using it.
author Bram Moolenaar <Bram@vim.org>
date Sat, 19 Nov 2022 20:15:03 +0100
parents 548241980a27
children ee50174810ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 vim9script
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 # Script to get various codes that keys send, depending on the protocol used.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 #
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
5 # Usage: vim -u NONE -S keycode_check.vim
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 #
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 # Author: Bram Moolenaar
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 # Last Update: 2022 Nov 15
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 #
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 # The codes are stored in the file "keycode_check.json", so that you can
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 # compare the results of various terminals.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 #
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 # You can select what protocol to enable:
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 # - None
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 # - modifyOtherKeys level 2
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 # - kitty keyboard protocol
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 # Change directory to where this script is, so that the json file is found
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 # there.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 exe 'cd ' .. expand('<sfile>:h')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 echo 'working in directory: ' .. getcwd()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 const filename = 'keycode_check.json'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 # Dictionary of dictionaries with the results in the form:
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 # {'xterm': {protocol: 'none', 'Tab': '09', 'S-Tab': '09'},
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 # 'xterm2': {protocol: 'mok2', 'Tab': '09', 'S-Tab': '09'},
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 # 'kitty': {protocol: 'kitty', 'Tab': '09', 'S-Tab': '09'},
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 # }
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 # The values are in hex form.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 var keycodes = {}
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 if filereadable(filename)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 keycodes = readfile(filename)->join()->json_decode()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 else
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 # Use some dummy entries to try out with
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 keycodes = {
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 'xterm': {protocol: 'none', 'Tab': '09', 'S-Tab': '09'},
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 'kitty': {protocol: 'kitty', 'Tab': '09', 'S-Tab': '1b5b393b3275'},
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 }
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 var orig_keycodes = deepcopy(keycodes) # used to detect something changed
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 # Write the "keycodes" variable in JSON form to "filename".
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 def WriteKeycodes()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 # If the file already exists move it to become the backup file.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 if filereadable(filename)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 if rename(filename, filename .. '~')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 echoerr $'Renaming {filename} to {filename}~ failed!'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 if writefile([json_encode(keycodes)], filename) != 0
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 echoerr $'Writing {filename} failed!'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 # The key entries that we want to list, in this order.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 # The first item is displayed in the prompt, the second is the key in
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 # the keycodes dictionary.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 var key_entries = [
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 ['Tab', 'Tab'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 ['Shift-Tab', 'S-Tab'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 ['Ctrl-Tab', 'C-Tab'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 ['Alt-Tab', 'A-Tab'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 ['Ctrl-I', 'C-I'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 ['Shift-Ctrl-I', 'S-C-I'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 ['Esc', 'Esc'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 ['Shift-Esc', 'S-Esc'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 ['Ctrl-Esc', 'C-Esc'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 ['Alt-Esc', 'A-Esc'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 ['Space', 'Space'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 ['Shift-Space', 'S-Space'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 ['Ctrl-Space', 'C-Space'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 ['Alt-Space', 'A-Space'],
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 ]
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
79 # Given a terminal name and a item name, return the text to display.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
80 def GetItemDisplay(term: string, item: string): string
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
81 var val = get(keycodes[term], item, '')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
82
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
83 # see if we can pretty-print this one
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
84 var pretty = val
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
85 if val[0 : 1] == '1b'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
86 pretty = 'ESC'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
87 var idx = 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
88
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
89 if val[0 : 3] == '1b5b'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
90 pretty = 'CSI'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
91 idx = 4
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
92 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
93
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
94 var digits = false
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
95 while idx < len(val)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
96 var cc = val[idx : idx + 1]
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
97 var nr = str2nr('0x' .. cc, 16)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
98 idx += 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
99 if nr >= char2nr('0') && nr <= char2nr('9')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
100 if !digits
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
101 pretty ..= ' '
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
102 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
103 digits = true
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
104 pretty ..= cc[1]
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
105 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
106 if nr == char2nr(';') && digits
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
107 # don't use space between semicolon and digits to keep it short
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
108 pretty ..= ';'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
109 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
110 digits = false
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
111 if nr >= char2nr(' ') && nr <= char2nr('~')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
112 # printable character
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
113 pretty ..= ' ' .. printf('%c', nr)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
114 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
115 # non-printable, use hex code
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
116 pretty = val
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
117 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
118 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
119 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
120 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
121 endwhile
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
122 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
123
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
124 return pretty
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
125 enddef
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
126
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 # Action: list the information in "keycodes" in a more or less nice way.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 def ActionList()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 var terms = keys(keycodes)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if len(terms) == 0
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 echo 'No terminal results yet'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 endif
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
135 sort(terms)
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
137 var items = ['protocol', 'version', 'status', 'resource']
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
138 + key_entries->copy()->map((_, v) => v[1])
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
139
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
140 # For each terminal compute the needed width, add two.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
141 # You may need to increase the terminal width to avoid wrapping.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
142 var widths = []
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
143 for [idx, term] in items(terms)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
144 widths[idx] = len(term) + 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
145 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
146
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
147 for item in items
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
148 for [idx, term] in items(terms)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
149 var l = len(GetItemDisplay(term, item))
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
150 if widths[idx] < l + 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
151 widths[idx] = l + 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
152 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
153 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
154 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
155
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
156 # Use one column of width 10 for the item name.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
157 echo "\n"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
158 echon ' '
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
159 for [idx, term] in items(terms)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
160 echon printf('%-' .. widths[idx] .. 's', term)
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 for item in items
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 echon printf('%8s ', item)
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
166 for [idx, term] in items(terms)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
167 echon printf('%-' .. widths[idx] .. 's', GetItemDisplay(term, item))
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 echo ''
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
174 # Convert the literal string after "raw key input" into hex form.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
175 def Literal2hex(code: string): string
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
176 var hex = ''
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
177 for i in range(len(code))
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
178 hex ..= printf('%02x', char2nr(code[i]))
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
179 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
180 return hex
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
181 enddef
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
182
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 def GetTermName(): string
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 var name = input('Enter the name of the terminal: ')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 return name
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 # Gather key codes for terminal "name".
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 def DoTerm(name: string)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 var proto = inputlist([$'What protocol to enable for {name}:',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 '1. None',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 '2. modifyOtherKeys level 2',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 '3. kitty',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 ])
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 &t_TE = "\<Esc>[>4;m"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 var proto_name = 'none'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if proto == 1
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 &t_TI = ""
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 elseif proto == 2
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
201 # Enable modifyOtherKeys level 2
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
202 # Request the resource value: DCS + Q modifyOtherKeys ST
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
203 &t_TI = "\<Esc>[>4;2m" .. "\<Esc>P+Q6d6f646966794f746865724b657973\<Esc>\\"
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 proto_name = 'mok2'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 elseif proto == 3
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
206 # Enable Kitty keyboard protocol and request the status
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
207 &t_TI = "\<Esc>[>1u" .. "\<Esc>[?u"
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 proto_name = 'kitty'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 else
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 echoerr 'invalid protocol choice'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
214 # Append the request for the version response, this is used to check we have
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
215 # the results.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
216 &t_TI ..= "\<Esc>[>c"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
217
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
218 # Pattern that matches the line with the version response.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
219 const version_pattern = "\<Esc>\\[>\\d\\+;\\d\\+;\\d*c"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
220
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
221 # Pattern that matches the resource value response:
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
222 # DCS 1 + R Pt ST valid
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
223 # DCS 0 + R Pt ST invalid
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
224 const resource_pattern = "\<Esc>P[01]+R.*\<Esc>\\\\"
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
225
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
226 # Pattern that matches the line with the status. Currently what terminals
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
227 # return for the Kitty keyboard protocol.
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
228 const kitty_status_pattern = "\<Esc>\\[?\\d\\+u"
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
229
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
230 ch_logfile('keylog', 'w')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
231
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 # executing a dummy shell command will output t_TI
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 !echo >/dev/null
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
235 # Wait until the log file has the version response.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
236 var startTime = reltime()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
237 var seenVersion = false
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
238 while !seenVersion
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
239 var log = readfile('keylog')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
240 if len(log) > 2
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
241 for line in log
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
242 if line =~ 'raw key input'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
243 var code = substitute(line, '.*raw key input: "\([^"]*\).*', '\1', '')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
244 if code =~ version_pattern
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
245 seenVersion = true
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
246 echo 'Found the version response'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
247 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
248 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
249 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
250 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
251 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
252 if reltime(startTime)->reltimefloat() > 3
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
253 # break out after three seconds
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
254 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
255 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
256 endwhile
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
257
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
258 echo 'seenVersion: ' seenVersion
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
259
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
260 # Prepare the terminal entry, set protocol and clear status and version.
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 if !has_key(keycodes, name)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 keycodes[name] = {}
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 keycodes[name]['protocol'] = proto_name
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
265 keycodes[name]['version'] = ''
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
266 keycodes[name]['status'] = ''
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
267 keycodes[name]['resource'] = ''
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
269 # Check the log file for a status and the version response
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
270 ch_logfile('', '')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
271 var log = readfile('keylog')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
272 delete('keylog')
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
273
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
274 for line in log
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
275 if line =~ 'raw key input'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
276 var code = substitute(line, '.*raw key input: "\([^"]*\).*', '\1', '')
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
277
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
278 # Check for resource value response
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
279 if code =~ resource_pattern
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
280 var resource = substitute(code, '.*\(' .. resource_pattern .. '\).*', '\1', '')
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
281 # use the value as the resource, "=30" means zero
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
282 resource = substitute(resource, '.*\(=\p\+\).*', '\1', '')
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
283
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
284 if keycodes[name]['resource'] != ''
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
285 echomsg 'Another resource found after ' .. keycodes[name]['resource']
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
286 endif
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
287 keycodes[name]['resource'] = resource
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
288 endif
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
289
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
290 # Check for kitty keyboard protocol status
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
291 if code =~ kitty_status_pattern
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
292 var status = substitute(code, '.*\(' .. kitty_status_pattern .. '\).*', '\1', '')
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
293 # use the response itself as the status
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
294 status = Literal2hex(status)
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
295
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
296 if keycodes[name]['status'] != ''
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
297 echomsg 'Another status found after ' .. keycodes[name]['status']
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
298 endif
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
299 keycodes[name]['status'] = status
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
300 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
301
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
302 if code =~ version_pattern
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
303 var version = substitute(code, '.*\(' .. version_pattern .. '\).*', '\1', '')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
304 keycodes[name]['version'] = Literal2hex(version)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
305 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
306 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
307 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
308 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
309
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
310 echo "For Alt to work you may need to press the Windows/Super key as well"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
311 echo "When a key press doesn't get to Vim (e.g. when using Alt) press x"
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
313 # The log of ignored typeahead is left around for debugging, start with an
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
314 # empty file here.
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
315 delete('keylog-ignore')
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
316
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 for entry in key_entries
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
318 # Consume any typeahead. Wait a bit for any responses to arrive.
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
319 ch_logfile('keylog-ignore', 'a')
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
320 while 1
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
321 sleep 100m
31156
0ecb16d5f86f patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents: 31137
diff changeset
322 if getchar(1) == 0
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
323 break
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
324 endif
31156
0ecb16d5f86f patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents: 31137
diff changeset
325 while getchar(1) != 0
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
326 getchar()
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
327 endwhile
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
328 endwhile
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
329 ch_logfile('', '')
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
330
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 ch_logfile('keylog', 'w')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 echo $'Press the {entry[0]} key (q to quit):'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 var r = getcharstr()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 ch_logfile('', '')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 if r == 'q'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 break
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 endif
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
338
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
339 log = readfile('keylog')
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
340 delete('keylog')
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 if len(log) < 2
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 echoerr 'failed to read result'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 var done = false
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 for line in log
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 if line =~ 'raw key input'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 var code = substitute(line, '.*raw key input: "\([^"]*\).*', '\1', '')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
350 # Remove any version termresponse
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
351 code = substitute(code, version_pattern, '', 'g')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
352
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
353 # Remove any XTGETTCAP replies.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
354 const cappat = "\<Esc>P[01]+\\k\\+=\\x*\<Esc>\\\\"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
355 code = substitute(code, cappat, '', 'g')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
356
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
357 # Remove any kitty status reply
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
358 code = substitute(code, kitty_status_pattern, '', 'g')
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
359 if code == ''
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
360 continue
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
361 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
362
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
363 # Convert the literal bytes into hex. If 'x' was pressed then clear
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
364 # the entry.
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 var hex = ''
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
366 if code != 'x'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
367 hex = Literal2hex(code)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
368 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
369
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 keycodes[name][entry[1]] = hex
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 done = true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 break
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 if !done
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 echo 'Code not found in log'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 # Action: Add key codes for a new terminal.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 def ActionAdd()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 var name = input('Enter name of the terminal: ')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 if index(keys(keycodes), name) >= 0
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 echoerr $'Terminal {name} already exists'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 DoTerm(name)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 # Action: Replace key codes for an already known terminal.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 def ActionReplace()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 var terms = keys(keycodes)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 if len(terms) == 0
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 echo 'No terminal results yet'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 var choice = inputlist(['Select:'] + terms->copy()->map((idx, arg) => (idx + 1) .. ': ' .. arg))
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if choice > 0 && choice <= len(terms)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 DoTerm(terms[choice - 1])
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
405 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
406 echo 'invalid index'
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 endif
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
408 enddef
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
409
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
410 # Action: Clear key codes for an already known terminal.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
411 def ActionClear()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
412 var terms = keys(keycodes)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
413 if len(terms) == 0
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
414 echo 'No terminal results yet'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
415 return
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
416 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
417
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
418 var choice = inputlist(['Select:'] + terms->copy()->map((idx, arg) => (idx + 1) .. ': ' .. arg))
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
419 echo "\n"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
420 if choice > 0 && choice <= len(terms)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
421 remove(keycodes, terms[choice - 1])
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
422 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
423 echo 'invalid index'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
424 endif
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 # Action: Quit, possibly after saving the results first.
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 def ActionQuit()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 # If nothing was changed just quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 if keycodes == orig_keycodes
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 while true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 var res = input("Save the changed key codes (y/n)? ")
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if res == 'n'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 if res == 'y'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 WriteKeycodes()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 echo 'invalid reply'
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 endwhile
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 # The main loop
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 while true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 var action = inputlist(['Select operation:',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 '1. List results',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 '2. Add results for a new terminal',
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 '3. Replace results',
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
453 '4. Clear results',
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
454 '5. Quit',
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 ])
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 if action == 1
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 ActionList()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 elseif action == 2
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 ActionAdd()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 elseif action == 3
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 ActionReplace()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 elseif action == 4
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
464 ActionClear()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
465 elseif action == 5
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 ActionQuit()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 endwhile