annotate src/testdir/keycode_check.vim @ 33933:aceaf677dd92 v9.0.2163

patch 9.0.2163: Vim9: type can be assigned to list/dict Commit: https://github.com/vim/vim/commit/fa831102c38c9192edf3aaf0cbcaff9ee5e006ac Author: Ernie Rael <errael@raelity.com> Date: Thu Dec 14 20:06:39 2023 +0100 patch 9.0.2163: Vim9: type can be assigned to list/dict Problem: Vim9: type can be assigned to list/dict Solution: Prevent assigning a `type` to a `list` or `dict` closes: #13683 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 14 Dec 2023 20:15:08 +0100
parents dbec60b8c253
children
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 #
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31243
diff changeset
7 # Author: Bram Moolenaar
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31243
diff changeset
8 # Last Update: 2022 Nov 15
31105
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
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
137 var items = ['protocol', 'version', 'kitty', 'modkeys']
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"
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
197 var proto_name = 'unknown'
31105
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
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
199 # Request the XTQMODKEYS value and request the kitty keyboard protocol status.
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
200 &t_TI = "\<Esc>[?4m" .. "\<Esc>[?u"
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
201 proto_name = 'none'
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 elseif proto == 2
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
203 # Enable modifyOtherKeys level 2 and request the XTQMODKEYS value.
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
204 &t_TI = "\<Esc>[>4;2m" .. "\<Esc>[?4m"
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 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
206 elseif proto == 3
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
207 # Enable Kitty keyboard protocol and request the status.
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
208 &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
209 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
210 else
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
215 # 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
216 # the results.
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
217 &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
218
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
219 # 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
220 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
221
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
222 # Pattern that matches the XTQMODKEYS response:
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
223 # CSI > 4;Pv m
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
224 # where Pv indicates the modifyOtherKeys level
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
225 const modkeys_pattern = "\<Esc>\\[>4;\\dm"
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
226
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
227 # 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
228 # 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
229 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
230
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
231 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
232
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 # 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
234 !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
235
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
236 # 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
237 var startTime = reltime()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
238 var seenVersion = false
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
239 while !seenVersion
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
240 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
241 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
242 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
243 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
244 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
245 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
246 seenVersion = true
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
247 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
248 break
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 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
251 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
252 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
253 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
254 # 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
255 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
256 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
257 endwhile
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
258
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
259 echo 'seenVersion: ' seenVersion
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
260
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
261 # 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
262 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
263 keycodes[name] = {}
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 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
266 keycodes[name]['version'] = ''
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
267 keycodes[name]['kitty'] = ''
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
268 keycodes[name]['modkeys'] = ''
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
270 # 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
271 ch_logfile('', '')
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
272 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
273 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
274
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
275 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
276 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
277 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
278
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
279 # Check for the XTQMODKEYS response.
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
280 if code =~ modkeys_pattern
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
281 var modkeys = substitute(code, '.*\(' .. modkeys_pattern .. '\).*', '\1', '')
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
282 # We could get the level out of the response, but showing the response
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
283 # itself provides more information.
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
284 # modkeys = substitute(modkeys, '.*4;\(\d\)m', '\1', '')
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
285
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
286 if keycodes[name]['modkeys'] != ''
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
287 echomsg 'Another modkeys found after ' .. keycodes[name]['modkeys']
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
288 endif
31241
ee50174810ac patch 9.0.0954: cannot detect whether modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 31156
diff changeset
289 keycodes[name]['modkeys'] = modkeys
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
290 endif
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
291
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
292 # 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
293 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
294 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
295 # 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
296 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
297
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
298 if keycodes[name]['kitty'] != ''
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
299 echomsg 'Another status found after ' .. keycodes[name]['kitty']
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
300 endif
31243
984ebd1f6605 patch 9.0.0955: libvterm does not support the XTQMODKEYS request
Bram Moolenaar <Bram@vim.org>
parents: 31241
diff changeset
301 keycodes[name]['kitty'] = status
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
302 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
303
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
304 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
305 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
306 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
307 break
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
308 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
309 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
310 endfor
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
311
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
312 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
313 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
314
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
315 # 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
316 # 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
317 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
318
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 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
320 # 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
321 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
322 while 1
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
323 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
324 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
325 break
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
326 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
327 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
328 getchar()
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
329 endwhile
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
330 endwhile
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
331 ch_logfile('', '')
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
332
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 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
334 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
335 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
336 ch_logfile('', '')
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 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
338 break
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 endif
31137
548241980a27 patch 9.0.0903: key code checker doesn't check modifyOtherKeys resource
Bram Moolenaar <Bram@vim.org>
parents: 31109
diff changeset
340
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
341 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
342 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
343 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
344 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
345 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 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
348 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
349 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
350 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
351
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
352 # 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
353 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
354
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
355 # 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
356 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
357 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
358
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
359 # 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
360 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
361 if code == ''
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
362 continue
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
363 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
364
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
365 # 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
366 # 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
367 var hex = ''
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
368 if code != 'x'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
369 hex = Literal2hex(code)
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
370 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
371
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 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
373 done = true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 break
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 if !done
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 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
379 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 endfor
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 # 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
384 def ActionAdd()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 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
386 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 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
388 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
389 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 DoTerm(name)
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 # 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
396 def ActionReplace()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 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
398 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
399 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
400 return
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 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
404 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 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
406 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
407 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
408 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
409 endif
31109
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
410 enddef
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
411
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
412 # 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
413 def ActionClear()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
414 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
415 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
416 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
417 return
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
418 endif
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
419
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
420 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
421 echo "\n"
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
422 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
423 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
424 else
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
425 echo 'invalid index'
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
426 endif
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 # 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
430 def ActionQuit()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 # 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
432 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
433 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 while true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 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
438 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
439 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 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
442 WriteKeycodes()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 quit
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 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
446 endwhile
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 enddef
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 # 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
450 while true
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 var action = inputlist(['Select operation:',
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31243
diff changeset
452 '1. List results',
31105
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 '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
454 '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
455 '4. Clear results',
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
456 '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
457 ])
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 echo "\n"
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 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
460 ActionList()
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 == 2
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 ActionAdd()
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 == 3
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 ActionReplace()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 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
466 ActionClear()
17e171cf2cca patch 9.0.0889: keycode check script has a few flaws
Bram Moolenaar <Bram@vim.org>
parents: 31105
diff changeset
467 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
468 ActionQuit()
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 endif
46d1a434784b patch 9.0.0887: cannot easily try out what codes various keys produce
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 endwhile