@letta-ai/letta-code 0.19.2 → 0.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/protocol.d.ts +3 -1
- package/dist/types/protocol.d.ts.map +1 -1
- package/letta.js +496 -189
- package/package.json +2 -2
- package/vendor/ink/build/hooks/use-input.js +13 -2
- package/vendor/ink/build/package/build/parse-keypress.js +225 -0
- package/vendor/ink/build/parse-keypress.js +225 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letta-ai/letta-code",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"description": "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"test:update-chain:manual": "bun run src/tests/update-chain-smoke.ts --mode manual",
|
|
74
74
|
"test:update-chain:startup": "bun run src/tests/update-chain-smoke.ts --mode startup",
|
|
75
75
|
"prepublishOnly": "bun run build",
|
|
76
|
-
"postinstall": "node scripts/postinstall-patches.js || echo letta: vendor patches skipped"
|
|
76
|
+
"postinstall": "node scripts/postinstall-patches.js || echo letta: vendor patches skipped && node -e \"try{require('fs').chmodSync(require('path').join(require.resolve('node-pty/package.json'),'../prebuilds/darwin-arm64/spawn-helper'),0o755)}catch(e){}\" || true"
|
|
77
77
|
},
|
|
78
78
|
"lint-staged": {
|
|
79
79
|
"*.{ts,tsx,js,jsx,json}": [
|
|
@@ -147,21 +147,32 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
// Map keycodes to names
|
|
150
|
+
// Map keycodes to names and actual character sequences
|
|
151
151
|
const csiUKeyMap = {
|
|
152
152
|
9: 'tab',
|
|
153
153
|
13: 'return',
|
|
154
154
|
27: 'escape',
|
|
155
|
+
32: 'space',
|
|
155
156
|
127: 'backspace',
|
|
156
157
|
};
|
|
158
|
+
const csiUSeqMap = {
|
|
159
|
+
9: '\t',
|
|
160
|
+
13: '\r',
|
|
161
|
+
27: '\x1b',
|
|
162
|
+
32: ' ',
|
|
163
|
+
127: '\x7f',
|
|
164
|
+
};
|
|
157
165
|
|
|
158
166
|
let name = csiUKeyMap[keycode] || '';
|
|
167
|
+
let seq = csiUSeqMap[keycode] || data;
|
|
159
168
|
|
|
160
169
|
// Handle letter keycodes (a-z: 97-122, A-Z: 65-90)
|
|
161
170
|
if (!name && keycode >= 97 && keycode <= 122) {
|
|
162
171
|
name = String.fromCharCode(keycode); // lowercase letter
|
|
172
|
+
seq = String.fromCharCode(keycode);
|
|
163
173
|
} else if (!name && keycode >= 65 && keycode <= 90) {
|
|
164
174
|
name = String.fromCharCode(keycode + 32); // convert to lowercase
|
|
175
|
+
seq = String.fromCharCode(keycode + 32);
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
if (name) {
|
|
@@ -171,7 +182,7 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
171
182
|
meta: !!(modifier & 10),
|
|
172
183
|
shift: !!(modifier & 1),
|
|
173
184
|
option: false,
|
|
174
|
-
sequence:
|
|
185
|
+
sequence: seq,
|
|
175
186
|
raw: data,
|
|
176
187
|
};
|
|
177
188
|
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// Copied from https://github.com/enquirer/enquirer/blob/36785f3399a41cd61e9d28d1eb9c2fcd73d69b4c/lib/keypress.js
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
const metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
|
4
|
+
const fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
|
5
|
+
const keyName = {
|
|
6
|
+
/* xterm/gnome ESC O letter */
|
|
7
|
+
OP: 'f1',
|
|
8
|
+
OQ: 'f2',
|
|
9
|
+
OR: 'f3',
|
|
10
|
+
OS: 'f4',
|
|
11
|
+
/* xterm/rxvt ESC [ number ~ */
|
|
12
|
+
'[11~': 'f1',
|
|
13
|
+
'[12~': 'f2',
|
|
14
|
+
'[13~': 'f3',
|
|
15
|
+
'[14~': 'f4',
|
|
16
|
+
/* from Cygwin and used in libuv */
|
|
17
|
+
'[[A': 'f1',
|
|
18
|
+
'[[B': 'f2',
|
|
19
|
+
'[[C': 'f3',
|
|
20
|
+
'[[D': 'f4',
|
|
21
|
+
'[[E': 'f5',
|
|
22
|
+
/* common */
|
|
23
|
+
'[15~': 'f5',
|
|
24
|
+
'[17~': 'f6',
|
|
25
|
+
'[18~': 'f7',
|
|
26
|
+
'[19~': 'f8',
|
|
27
|
+
'[20~': 'f9',
|
|
28
|
+
'[21~': 'f10',
|
|
29
|
+
'[23~': 'f11',
|
|
30
|
+
'[24~': 'f12',
|
|
31
|
+
/* xterm ESC [ letter */
|
|
32
|
+
'[A': 'up',
|
|
33
|
+
'[B': 'down',
|
|
34
|
+
'[C': 'right',
|
|
35
|
+
'[D': 'left',
|
|
36
|
+
'[E': 'clear',
|
|
37
|
+
'[F': 'end',
|
|
38
|
+
'[H': 'home',
|
|
39
|
+
/* xterm/gnome ESC O letter */
|
|
40
|
+
OA: 'up',
|
|
41
|
+
OB: 'down',
|
|
42
|
+
OC: 'right',
|
|
43
|
+
OD: 'left',
|
|
44
|
+
OE: 'clear',
|
|
45
|
+
OF: 'end',
|
|
46
|
+
OH: 'home',
|
|
47
|
+
/* xterm/rxvt ESC [ number ~ */
|
|
48
|
+
'[1~': 'home',
|
|
49
|
+
'[2~': 'insert',
|
|
50
|
+
'[3~': 'delete',
|
|
51
|
+
'[4~': 'end',
|
|
52
|
+
'[5~': 'pageup',
|
|
53
|
+
'[6~': 'pagedown',
|
|
54
|
+
/* putty */
|
|
55
|
+
'[[5~': 'pageup',
|
|
56
|
+
'[[6~': 'pagedown',
|
|
57
|
+
/* rxvt */
|
|
58
|
+
'[7~': 'home',
|
|
59
|
+
'[8~': 'end',
|
|
60
|
+
/* rxvt keys with modifiers */
|
|
61
|
+
'[a': 'up',
|
|
62
|
+
'[b': 'down',
|
|
63
|
+
'[c': 'right',
|
|
64
|
+
'[d': 'left',
|
|
65
|
+
'[e': 'clear',
|
|
66
|
+
'[2$': 'insert',
|
|
67
|
+
'[3$': 'delete',
|
|
68
|
+
'[5$': 'pageup',
|
|
69
|
+
'[6$': 'pagedown',
|
|
70
|
+
'[7$': 'home',
|
|
71
|
+
'[8$': 'end',
|
|
72
|
+
Oa: 'up',
|
|
73
|
+
Ob: 'down',
|
|
74
|
+
Oc: 'right',
|
|
75
|
+
Od: 'left',
|
|
76
|
+
Oe: 'clear',
|
|
77
|
+
'[2^': 'insert',
|
|
78
|
+
'[3^': 'delete',
|
|
79
|
+
'[5^': 'pageup',
|
|
80
|
+
'[6^': 'pagedown',
|
|
81
|
+
'[7^': 'home',
|
|
82
|
+
'[8^': 'end',
|
|
83
|
+
/* misc. */
|
|
84
|
+
'[Z': 'tab',
|
|
85
|
+
};
|
|
86
|
+
export const nonAlphanumericKeys = [...Object.values(keyName), 'backspace'];
|
|
87
|
+
const isShiftKey = (code) => {
|
|
88
|
+
return [
|
|
89
|
+
'[a',
|
|
90
|
+
'[b',
|
|
91
|
+
'[c',
|
|
92
|
+
'[d',
|
|
93
|
+
'[e',
|
|
94
|
+
'[2$',
|
|
95
|
+
'[3$',
|
|
96
|
+
'[5$',
|
|
97
|
+
'[6$',
|
|
98
|
+
'[7$',
|
|
99
|
+
'[8$',
|
|
100
|
+
'[Z',
|
|
101
|
+
].includes(code);
|
|
102
|
+
};
|
|
103
|
+
const isCtrlKey = (code) => {
|
|
104
|
+
return [
|
|
105
|
+
'Oa',
|
|
106
|
+
'Ob',
|
|
107
|
+
'Oc',
|
|
108
|
+
'Od',
|
|
109
|
+
'Oe',
|
|
110
|
+
'[2^',
|
|
111
|
+
'[3^',
|
|
112
|
+
'[5^',
|
|
113
|
+
'[6^',
|
|
114
|
+
'[7^',
|
|
115
|
+
'[8^',
|
|
116
|
+
].includes(code);
|
|
117
|
+
};
|
|
118
|
+
const parseKeypress = (s = '') => {
|
|
119
|
+
let parts;
|
|
120
|
+
if (Buffer.isBuffer(s)) {
|
|
121
|
+
if (s[0] > 127 && s[1] === undefined) {
|
|
122
|
+
s[0] -= 128;
|
|
123
|
+
s = '\x1b' + String(s);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
s = String(s);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (s !== undefined && typeof s !== 'string') {
|
|
130
|
+
s = String(s);
|
|
131
|
+
}
|
|
132
|
+
else if (!s) {
|
|
133
|
+
s = '';
|
|
134
|
+
}
|
|
135
|
+
const key = {
|
|
136
|
+
name: '',
|
|
137
|
+
ctrl: false,
|
|
138
|
+
meta: false,
|
|
139
|
+
shift: false,
|
|
140
|
+
option: false,
|
|
141
|
+
sequence: s,
|
|
142
|
+
raw: s,
|
|
143
|
+
};
|
|
144
|
+
key.sequence = key.sequence || s || key.name;
|
|
145
|
+
if (s === '\r') {
|
|
146
|
+
// carriage return
|
|
147
|
+
key.raw = undefined;
|
|
148
|
+
key.name = 'return';
|
|
149
|
+
}
|
|
150
|
+
else if (s === '\n') {
|
|
151
|
+
// enter, should have been called linefeed
|
|
152
|
+
key.name = 'enter';
|
|
153
|
+
}
|
|
154
|
+
else if (s === '\t') {
|
|
155
|
+
// tab
|
|
156
|
+
key.name = 'tab';
|
|
157
|
+
}
|
|
158
|
+
else if (s === '\b' || s === '\x1b\b') {
|
|
159
|
+
// backspace or ctrl+h
|
|
160
|
+
key.name = 'backspace';
|
|
161
|
+
key.meta = s.charAt(0) === '\x1b';
|
|
162
|
+
}
|
|
163
|
+
else if (s === '\x7f' || s === '\x1b\x7f') {
|
|
164
|
+
// TODO(vadimdemedes): `enquirer` detects delete key as backspace, but I had to split them up to avoid breaking changes in Ink. Merge them back together in the next major version.
|
|
165
|
+
// delete
|
|
166
|
+
key.name = 'delete';
|
|
167
|
+
key.meta = s.charAt(0) === '\x1b';
|
|
168
|
+
}
|
|
169
|
+
else if (s === '\x1b' || s === '\x1b\x1b') {
|
|
170
|
+
// escape key
|
|
171
|
+
key.name = 'escape';
|
|
172
|
+
key.meta = s.length === 2;
|
|
173
|
+
}
|
|
174
|
+
else if (s === ' ' || s === '\x1b ') {
|
|
175
|
+
key.name = 'space';
|
|
176
|
+
key.meta = s.length === 2;
|
|
177
|
+
}
|
|
178
|
+
else if (s <= '\x1a') {
|
|
179
|
+
// ctrl+letter
|
|
180
|
+
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
|
|
181
|
+
key.ctrl = true;
|
|
182
|
+
}
|
|
183
|
+
else if (s.length === 1 && s >= '0' && s <= '9') {
|
|
184
|
+
// number
|
|
185
|
+
key.name = 'number';
|
|
186
|
+
}
|
|
187
|
+
else if (s.length === 1 && s >= 'a' && s <= 'z') {
|
|
188
|
+
// lowercase letter
|
|
189
|
+
key.name = s;
|
|
190
|
+
}
|
|
191
|
+
else if (s.length === 1 && s >= 'A' && s <= 'Z') {
|
|
192
|
+
// shift+letter
|
|
193
|
+
key.name = s.toLowerCase();
|
|
194
|
+
key.shift = true;
|
|
195
|
+
}
|
|
196
|
+
else if ((parts = metaKeyCodeRe.exec(s))) {
|
|
197
|
+
// meta+character key
|
|
198
|
+
key.meta = true;
|
|
199
|
+
key.shift = /^[A-Z]$/.test(parts[1]);
|
|
200
|
+
}
|
|
201
|
+
else if ((parts = fnKeyRe.exec(s))) {
|
|
202
|
+
const segs = [...s];
|
|
203
|
+
if (segs[0] === '\u001b' && segs[1] === '\u001b') {
|
|
204
|
+
key.option = true;
|
|
205
|
+
}
|
|
206
|
+
// ansi escape sequence
|
|
207
|
+
// reassemble the key code leaving out leading \x1b's,
|
|
208
|
+
// the modifier key bitflag and any meaningless "1;" sequence
|
|
209
|
+
const code = [parts[1], parts[2], parts[4], parts[6]]
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.join('');
|
|
212
|
+
const modifier = (parts[3] || parts[5] || 1) - 1;
|
|
213
|
+
// Parse the key modifier
|
|
214
|
+
key.ctrl = !!(modifier & 4);
|
|
215
|
+
key.meta = !!(modifier & 10);
|
|
216
|
+
key.shift = !!(modifier & 1);
|
|
217
|
+
key.code = code;
|
|
218
|
+
key.name = keyName[code];
|
|
219
|
+
key.shift = isShiftKey(code) || key.shift;
|
|
220
|
+
key.ctrl = isCtrlKey(code) || key.ctrl;
|
|
221
|
+
}
|
|
222
|
+
return key;
|
|
223
|
+
};
|
|
224
|
+
export default parseKeypress;
|
|
225
|
+
//# sourceMappingURL=parse-keypress.js.map
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// Copied from https://github.com/enquirer/enquirer/blob/36785f3399a41cd61e9d28d1eb9c2fcd73d69b4c/lib/keypress.js
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
const metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
|
|
4
|
+
const fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
|
|
5
|
+
const keyName = {
|
|
6
|
+
/* xterm/gnome ESC O letter */
|
|
7
|
+
OP: 'f1',
|
|
8
|
+
OQ: 'f2',
|
|
9
|
+
OR: 'f3',
|
|
10
|
+
OS: 'f4',
|
|
11
|
+
/* xterm/rxvt ESC [ number ~ */
|
|
12
|
+
'[11~': 'f1',
|
|
13
|
+
'[12~': 'f2',
|
|
14
|
+
'[13~': 'f3',
|
|
15
|
+
'[14~': 'f4',
|
|
16
|
+
/* from Cygwin and used in libuv */
|
|
17
|
+
'[[A': 'f1',
|
|
18
|
+
'[[B': 'f2',
|
|
19
|
+
'[[C': 'f3',
|
|
20
|
+
'[[D': 'f4',
|
|
21
|
+
'[[E': 'f5',
|
|
22
|
+
/* common */
|
|
23
|
+
'[15~': 'f5',
|
|
24
|
+
'[17~': 'f6',
|
|
25
|
+
'[18~': 'f7',
|
|
26
|
+
'[19~': 'f8',
|
|
27
|
+
'[20~': 'f9',
|
|
28
|
+
'[21~': 'f10',
|
|
29
|
+
'[23~': 'f11',
|
|
30
|
+
'[24~': 'f12',
|
|
31
|
+
/* xterm ESC [ letter */
|
|
32
|
+
'[A': 'up',
|
|
33
|
+
'[B': 'down',
|
|
34
|
+
'[C': 'right',
|
|
35
|
+
'[D': 'left',
|
|
36
|
+
'[E': 'clear',
|
|
37
|
+
'[F': 'end',
|
|
38
|
+
'[H': 'home',
|
|
39
|
+
/* xterm/gnome ESC O letter */
|
|
40
|
+
OA: 'up',
|
|
41
|
+
OB: 'down',
|
|
42
|
+
OC: 'right',
|
|
43
|
+
OD: 'left',
|
|
44
|
+
OE: 'clear',
|
|
45
|
+
OF: 'end',
|
|
46
|
+
OH: 'home',
|
|
47
|
+
/* xterm/rxvt ESC [ number ~ */
|
|
48
|
+
'[1~': 'home',
|
|
49
|
+
'[2~': 'insert',
|
|
50
|
+
'[3~': 'delete',
|
|
51
|
+
'[4~': 'end',
|
|
52
|
+
'[5~': 'pageup',
|
|
53
|
+
'[6~': 'pagedown',
|
|
54
|
+
/* putty */
|
|
55
|
+
'[[5~': 'pageup',
|
|
56
|
+
'[[6~': 'pagedown',
|
|
57
|
+
/* rxvt */
|
|
58
|
+
'[7~': 'home',
|
|
59
|
+
'[8~': 'end',
|
|
60
|
+
/* rxvt keys with modifiers */
|
|
61
|
+
'[a': 'up',
|
|
62
|
+
'[b': 'down',
|
|
63
|
+
'[c': 'right',
|
|
64
|
+
'[d': 'left',
|
|
65
|
+
'[e': 'clear',
|
|
66
|
+
'[2$': 'insert',
|
|
67
|
+
'[3$': 'delete',
|
|
68
|
+
'[5$': 'pageup',
|
|
69
|
+
'[6$': 'pagedown',
|
|
70
|
+
'[7$': 'home',
|
|
71
|
+
'[8$': 'end',
|
|
72
|
+
Oa: 'up',
|
|
73
|
+
Ob: 'down',
|
|
74
|
+
Oc: 'right',
|
|
75
|
+
Od: 'left',
|
|
76
|
+
Oe: 'clear',
|
|
77
|
+
'[2^': 'insert',
|
|
78
|
+
'[3^': 'delete',
|
|
79
|
+
'[5^': 'pageup',
|
|
80
|
+
'[6^': 'pagedown',
|
|
81
|
+
'[7^': 'home',
|
|
82
|
+
'[8^': 'end',
|
|
83
|
+
/* misc. */
|
|
84
|
+
'[Z': 'tab',
|
|
85
|
+
};
|
|
86
|
+
export const nonAlphanumericKeys = [...Object.values(keyName), 'backspace'];
|
|
87
|
+
const isShiftKey = (code) => {
|
|
88
|
+
return [
|
|
89
|
+
'[a',
|
|
90
|
+
'[b',
|
|
91
|
+
'[c',
|
|
92
|
+
'[d',
|
|
93
|
+
'[e',
|
|
94
|
+
'[2$',
|
|
95
|
+
'[3$',
|
|
96
|
+
'[5$',
|
|
97
|
+
'[6$',
|
|
98
|
+
'[7$',
|
|
99
|
+
'[8$',
|
|
100
|
+
'[Z',
|
|
101
|
+
].includes(code);
|
|
102
|
+
};
|
|
103
|
+
const isCtrlKey = (code) => {
|
|
104
|
+
return [
|
|
105
|
+
'Oa',
|
|
106
|
+
'Ob',
|
|
107
|
+
'Oc',
|
|
108
|
+
'Od',
|
|
109
|
+
'Oe',
|
|
110
|
+
'[2^',
|
|
111
|
+
'[3^',
|
|
112
|
+
'[5^',
|
|
113
|
+
'[6^',
|
|
114
|
+
'[7^',
|
|
115
|
+
'[8^',
|
|
116
|
+
].includes(code);
|
|
117
|
+
};
|
|
118
|
+
const parseKeypress = (s = '') => {
|
|
119
|
+
let parts;
|
|
120
|
+
if (Buffer.isBuffer(s)) {
|
|
121
|
+
if (s[0] > 127 && s[1] === undefined) {
|
|
122
|
+
s[0] -= 128;
|
|
123
|
+
s = '\x1b' + String(s);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
s = String(s);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (s !== undefined && typeof s !== 'string') {
|
|
130
|
+
s = String(s);
|
|
131
|
+
}
|
|
132
|
+
else if (!s) {
|
|
133
|
+
s = '';
|
|
134
|
+
}
|
|
135
|
+
const key = {
|
|
136
|
+
name: '',
|
|
137
|
+
ctrl: false,
|
|
138
|
+
meta: false,
|
|
139
|
+
shift: false,
|
|
140
|
+
option: false,
|
|
141
|
+
sequence: s,
|
|
142
|
+
raw: s,
|
|
143
|
+
};
|
|
144
|
+
key.sequence = key.sequence || s || key.name;
|
|
145
|
+
if (s === '\r') {
|
|
146
|
+
// carriage return
|
|
147
|
+
key.raw = undefined;
|
|
148
|
+
key.name = 'return';
|
|
149
|
+
}
|
|
150
|
+
else if (s === '\n') {
|
|
151
|
+
// enter, should have been called linefeed
|
|
152
|
+
key.name = 'enter';
|
|
153
|
+
}
|
|
154
|
+
else if (s === '\t') {
|
|
155
|
+
// tab
|
|
156
|
+
key.name = 'tab';
|
|
157
|
+
}
|
|
158
|
+
else if (s === '\b' || s === '\x1b\b') {
|
|
159
|
+
// backspace or ctrl+h
|
|
160
|
+
key.name = 'backspace';
|
|
161
|
+
key.meta = s.charAt(0) === '\x1b';
|
|
162
|
+
}
|
|
163
|
+
else if (s === '\x7f' || s === '\x1b\x7f') {
|
|
164
|
+
// TODO(vadimdemedes): `enquirer` detects delete key as backspace, but I had to split them up to avoid breaking changes in Ink. Merge them back together in the next major version.
|
|
165
|
+
// delete
|
|
166
|
+
key.name = 'delete';
|
|
167
|
+
key.meta = s.charAt(0) === '\x1b';
|
|
168
|
+
}
|
|
169
|
+
else if (s === '\x1b' || s === '\x1b\x1b') {
|
|
170
|
+
// escape key
|
|
171
|
+
key.name = 'escape';
|
|
172
|
+
key.meta = s.length === 2;
|
|
173
|
+
}
|
|
174
|
+
else if (s === ' ' || s === '\x1b ') {
|
|
175
|
+
key.name = 'space';
|
|
176
|
+
key.meta = s.length === 2;
|
|
177
|
+
}
|
|
178
|
+
else if (s <= '\x1a') {
|
|
179
|
+
// ctrl+letter
|
|
180
|
+
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
|
|
181
|
+
key.ctrl = true;
|
|
182
|
+
}
|
|
183
|
+
else if (s.length === 1 && s >= '0' && s <= '9') {
|
|
184
|
+
// number
|
|
185
|
+
key.name = 'number';
|
|
186
|
+
}
|
|
187
|
+
else if (s.length === 1 && s >= 'a' && s <= 'z') {
|
|
188
|
+
// lowercase letter
|
|
189
|
+
key.name = s;
|
|
190
|
+
}
|
|
191
|
+
else if (s.length === 1 && s >= 'A' && s <= 'Z') {
|
|
192
|
+
// shift+letter
|
|
193
|
+
key.name = s.toLowerCase();
|
|
194
|
+
key.shift = true;
|
|
195
|
+
}
|
|
196
|
+
else if ((parts = metaKeyCodeRe.exec(s))) {
|
|
197
|
+
// meta+character key
|
|
198
|
+
key.meta = true;
|
|
199
|
+
key.shift = /^[A-Z]$/.test(parts[1]);
|
|
200
|
+
}
|
|
201
|
+
else if ((parts = fnKeyRe.exec(s))) {
|
|
202
|
+
const segs = [...s];
|
|
203
|
+
if (segs[0] === '\u001b' && segs[1] === '\u001b') {
|
|
204
|
+
key.option = true;
|
|
205
|
+
}
|
|
206
|
+
// ansi escape sequence
|
|
207
|
+
// reassemble the key code leaving out leading \x1b's,
|
|
208
|
+
// the modifier key bitflag and any meaningless "1;" sequence
|
|
209
|
+
const code = [parts[1], parts[2], parts[4], parts[6]]
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.join('');
|
|
212
|
+
const modifier = (parts[3] || parts[5] || 1) - 1;
|
|
213
|
+
// Parse the key modifier
|
|
214
|
+
key.ctrl = !!(modifier & 4);
|
|
215
|
+
key.meta = !!(modifier & 10);
|
|
216
|
+
key.shift = !!(modifier & 1);
|
|
217
|
+
key.code = code;
|
|
218
|
+
key.name = keyName[code];
|
|
219
|
+
key.shift = isShiftKey(code) || key.shift;
|
|
220
|
+
key.ctrl = isCtrlKey(code) || key.ctrl;
|
|
221
|
+
}
|
|
222
|
+
return key;
|
|
223
|
+
};
|
|
224
|
+
export default parseKeypress;
|
|
225
|
+
//# sourceMappingURL=parse-keypress.js.map
|