@celljs/ta-workspace 4.7.0 → 4.8.0
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/README.md +5 -5
- package/README.zh-cn.md +6 -6
- package/package.json +3 -3
- package/web/index.js +1911 -634
- package/web-src/browser-agent.ts +440 -0
- package/web-src/browser-common.tsx +278 -0
- package/web-src/browser-import.tsx +126 -0
- package/web-src/browser-webview.tsx +270 -0
- package/web-src/browser.tsx +25 -220
- package/web-src/explorer.tsx +241 -3
- package/web-src/i18n.ts +77 -2
- package/web-src/index.tsx +7 -1
- package/web-src/style.ts +35 -6
- package/web-src/terminal.tsx +53 -134
- package/web-src/util/browser-snapshot.spec.ts +96 -0
- package/web-src/util/browser-snapshot.ts +225 -0
- package/web-src/util/upload.spec.ts +66 -0
- package/web-src/util/upload.ts +123 -0
- package/web-src/util/workspace.spec.ts +32 -13
- package/web-src/util/workspace.ts +42 -0
- package/web-src/util/zip.spec.ts +60 -0
- package/web-src/util/zip.ts +137 -0
- package/web-src/workspace-client.ts +103 -1
- package/web-src/util/ansi.spec.ts +0 -66
- package/web-src/util/ansi.ts +0 -438
- package/web-src/util/keys.ts +0 -56
package/web-src/util/ansi.ts
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
/** How a run of characters looks: SGR of a terminal. Colors are 0–255 of the xterm palette, or `#rrggbb`. */
|
|
2
|
-
export interface AnsiStyle {
|
|
3
|
-
fg?: number | string;
|
|
4
|
-
bg?: number | string;
|
|
5
|
-
bold?: boolean;
|
|
6
|
-
dim?: boolean;
|
|
7
|
-
italic?: boolean;
|
|
8
|
-
underline?: boolean;
|
|
9
|
-
inverse?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface AnsiSpan {
|
|
13
|
-
text: string;
|
|
14
|
-
style: AnsiStyle;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Cell {
|
|
18
|
-
char: string;
|
|
19
|
-
style: AnsiStyle;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const PLAIN: AnsiStyle = Object.freeze({});
|
|
23
|
-
/** A control sequence: parameters, intermediates and the final byte. */
|
|
24
|
-
const ESC = '\x1b';
|
|
25
|
-
const CSI = new RegExp(`^${ESC}\\[([0-?]*)([ -/]*)([@-~])`);
|
|
26
|
-
const DEFAULT_MAX_LINES = 2000;
|
|
27
|
-
const TAB = 8;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The smallest screen a shell needs: lines of styled characters and a cursor. It follows SGR colors,
|
|
31
|
-
* `\r`, `\b`, `\t`, moving the cursor, erasing and clearing; titles and modes it reads and drops.
|
|
32
|
-
* Lines that scroll off stay, up to `maxLines`.
|
|
33
|
-
*/
|
|
34
|
-
export class AnsiScreen {
|
|
35
|
-
protected lines: Cell[][] = [[]];
|
|
36
|
-
/** The line of the cursor, an index of `lines`. */
|
|
37
|
-
protected row = 0;
|
|
38
|
-
protected col = 0;
|
|
39
|
-
protected style: AnsiStyle = PLAIN;
|
|
40
|
-
/** The end of the last `feed`, when it stopped inside a sequence. */
|
|
41
|
-
protected rest = '';
|
|
42
|
-
protected savedCursor?: { row: number; col: number };
|
|
43
|
-
/** Bumped by each change: a view draws again when it changed. */
|
|
44
|
-
version = 0;
|
|
45
|
-
|
|
46
|
-
constructor(
|
|
47
|
-
protected cols = 80,
|
|
48
|
-
protected rows = 24,
|
|
49
|
-
protected readonly maxLines = DEFAULT_MAX_LINES,
|
|
50
|
-
) {}
|
|
51
|
-
|
|
52
|
-
resize(cols: number, rows: number): void {
|
|
53
|
-
this.cols = Math.max(1, cols);
|
|
54
|
-
this.rows = Math.max(1, rows);
|
|
55
|
-
this.version++;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
feed(input: string): void {
|
|
59
|
-
const text = this.rest + input;
|
|
60
|
-
this.rest = '';
|
|
61
|
-
let i = 0;
|
|
62
|
-
while (i < text.length) {
|
|
63
|
-
const char = text[i];
|
|
64
|
-
if (char === '\x1b') {
|
|
65
|
-
const used = this.escape(text, i);
|
|
66
|
-
if (used < 0) {
|
|
67
|
-
this.rest = text.slice(i);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
i += used;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
i++;
|
|
74
|
-
if (char === '\r') {
|
|
75
|
-
this.col = 0;
|
|
76
|
-
} else if (char === '\n') {
|
|
77
|
-
this.lineFeed();
|
|
78
|
-
} else if (char === '\b') {
|
|
79
|
-
this.col = Math.max(0, this.col - 1);
|
|
80
|
-
} else if (char === '\t') {
|
|
81
|
-
this.col = Math.min(this.cols - 1, (Math.floor(this.col / TAB) + 1) * TAB);
|
|
82
|
-
} else if (char >= ' ' && char !== '\x7f') {
|
|
83
|
-
const code = char.charCodeAt(0);
|
|
84
|
-
// A pair of surrogates is one character.
|
|
85
|
-
if (code >= 0xd800 && code < 0xdc00 && i < text.length) {
|
|
86
|
-
this.put(char + text[i]);
|
|
87
|
-
i++;
|
|
88
|
-
} else {
|
|
89
|
-
this.put(char);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
this.version++;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
clear(): void {
|
|
97
|
-
this.lines = [[]];
|
|
98
|
-
this.row = 0;
|
|
99
|
-
this.col = 0;
|
|
100
|
-
this.version++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The lines, each a list of runs of one style. */
|
|
104
|
-
spans(): AnsiSpan[][] {
|
|
105
|
-
return this.lines.map(line => {
|
|
106
|
-
const spans: AnsiSpan[] = [];
|
|
107
|
-
for (const cell of line) {
|
|
108
|
-
const last = spans[spans.length - 1];
|
|
109
|
-
if (last && last.style === cell.style) {
|
|
110
|
-
last.text += cell.char;
|
|
111
|
-
} else {
|
|
112
|
-
spans.push({ text: cell.char, style: cell.style });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return spans;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** The text, without styles; for tests and copying. */
|
|
120
|
-
text(): string {
|
|
121
|
-
return this.lines
|
|
122
|
-
.map(line =>
|
|
123
|
-
line
|
|
124
|
-
.map(cell => cell.char)
|
|
125
|
-
.join('')
|
|
126
|
-
.trimEnd(),
|
|
127
|
-
)
|
|
128
|
-
.join('\n');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
cursor(): { row: number; col: number } {
|
|
132
|
-
return { row: this.row, col: this.col };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
protected put(char: string): void {
|
|
136
|
-
if (this.col >= this.cols) {
|
|
137
|
-
this.col = 0;
|
|
138
|
-
this.lineFeed();
|
|
139
|
-
}
|
|
140
|
-
const line = this.lines[this.row];
|
|
141
|
-
while (line.length < this.col) {
|
|
142
|
-
line.push({ char: ' ', style: PLAIN });
|
|
143
|
-
}
|
|
144
|
-
line[this.col] = { char, style: this.style };
|
|
145
|
-
this.col++;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
protected lineFeed(): void {
|
|
149
|
-
this.row++;
|
|
150
|
-
if (this.row === this.lines.length) {
|
|
151
|
-
this.lines.push([]);
|
|
152
|
-
}
|
|
153
|
-
if (this.lines.length > this.maxLines) {
|
|
154
|
-
const drop = this.lines.length - this.maxLines;
|
|
155
|
-
this.lines.splice(0, drop);
|
|
156
|
-
this.row -= drop;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** The first line of the screen: the last `rows` lines are the screen. */
|
|
161
|
-
protected top(): number {
|
|
162
|
-
return Math.max(0, this.lines.length - this.rows);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** How many characters the sequence at `start` takes; -1 when it is not complete yet. */
|
|
166
|
-
protected escape(text: string, start: number): number {
|
|
167
|
-
const kind = text[start + 1];
|
|
168
|
-
if (kind === undefined) {
|
|
169
|
-
return -1;
|
|
170
|
-
}
|
|
171
|
-
if (kind === '[') {
|
|
172
|
-
const found = CSI.exec(text.slice(start, start + 64));
|
|
173
|
-
if (!found) {
|
|
174
|
-
return text.length - start < 64 ? -1 : 2;
|
|
175
|
-
}
|
|
176
|
-
this.csi(found[1], found[3]);
|
|
177
|
-
return found[0].length;
|
|
178
|
-
}
|
|
179
|
-
if (kind === ']' || kind === 'P' || kind === '_' || kind === '^') {
|
|
180
|
-
// A title, a link or a device string: up to BEL or ST.
|
|
181
|
-
const bel = text.indexOf('\x07', start + 2);
|
|
182
|
-
const st = text.indexOf('\x1b\\', start + 2);
|
|
183
|
-
const end = bel < 0 ? st : st < 0 ? bel : Math.min(bel, st);
|
|
184
|
-
if (end < 0) {
|
|
185
|
-
return -1;
|
|
186
|
-
}
|
|
187
|
-
return end - start + (end === bel ? 1 : 2);
|
|
188
|
-
}
|
|
189
|
-
if (kind === '(' || kind === ')' || kind === '#') {
|
|
190
|
-
return text.length - start < 3 ? -1 : 3;
|
|
191
|
-
}
|
|
192
|
-
if (kind === '7') {
|
|
193
|
-
this.savedCursor = { row: this.row, col: this.col };
|
|
194
|
-
} else if (kind === '8' && this.savedCursor) {
|
|
195
|
-
({ row: this.row, col: this.col } = this.savedCursor);
|
|
196
|
-
} else if (kind === 'M') {
|
|
197
|
-
this.row = Math.max(this.top(), this.row - 1);
|
|
198
|
-
} else if (kind === 'c') {
|
|
199
|
-
this.clear();
|
|
200
|
-
this.style = PLAIN;
|
|
201
|
-
}
|
|
202
|
-
return 2;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
protected csi(params: string, final: string): void {
|
|
206
|
-
if (params.startsWith('?') || params.startsWith('>') || params.startsWith('=')) {
|
|
207
|
-
// Private modes: bracketed paste, the cursor, the alternate screen.
|
|
208
|
-
if (/^\?(1049|47|1047)$/.test(params) && (final === 'h' || final === 'l')) {
|
|
209
|
-
this.eraseScreen(2);
|
|
210
|
-
}
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const values = params.split(';').map(value => (value === '' ? undefined : Number(value)));
|
|
214
|
-
const n = values[0] ?? 1;
|
|
215
|
-
switch (final) {
|
|
216
|
-
case 'm':
|
|
217
|
-
this.sgr(values.map(value => value ?? 0));
|
|
218
|
-
break;
|
|
219
|
-
case 'A':
|
|
220
|
-
this.row = Math.max(this.top(), this.row - n);
|
|
221
|
-
break;
|
|
222
|
-
case 'B':
|
|
223
|
-
this.moveRow(this.row + n);
|
|
224
|
-
break;
|
|
225
|
-
case 'C':
|
|
226
|
-
this.col = Math.min(this.cols - 1, this.col + n);
|
|
227
|
-
break;
|
|
228
|
-
case 'D':
|
|
229
|
-
this.col = Math.max(0, this.col - n);
|
|
230
|
-
break;
|
|
231
|
-
case 'E':
|
|
232
|
-
this.moveRow(this.row + n);
|
|
233
|
-
this.col = 0;
|
|
234
|
-
break;
|
|
235
|
-
case 'F':
|
|
236
|
-
this.row = Math.max(this.top(), this.row - n);
|
|
237
|
-
this.col = 0;
|
|
238
|
-
break;
|
|
239
|
-
case 'G':
|
|
240
|
-
this.col = Math.min(this.cols - 1, Math.max(0, n - 1));
|
|
241
|
-
break;
|
|
242
|
-
case 'H':
|
|
243
|
-
case 'f':
|
|
244
|
-
this.moveRow(this.top() + Math.max(0, (values[0] ?? 1) - 1));
|
|
245
|
-
this.col = Math.min(this.cols - 1, Math.max(0, (values[1] ?? 1) - 1));
|
|
246
|
-
break;
|
|
247
|
-
case 'J':
|
|
248
|
-
this.eraseScreen(values[0] ?? 0);
|
|
249
|
-
break;
|
|
250
|
-
case 'K':
|
|
251
|
-
this.eraseLine(values[0] ?? 0);
|
|
252
|
-
break;
|
|
253
|
-
case 'P':
|
|
254
|
-
this.lines[this.row].splice(this.col, n);
|
|
255
|
-
break;
|
|
256
|
-
case 'X':
|
|
257
|
-
for (let i = this.col; i < Math.min(this.col + n, this.lines[this.row].length); i++) {
|
|
258
|
-
this.lines[this.row][i] = { char: ' ', style: PLAIN };
|
|
259
|
-
}
|
|
260
|
-
break;
|
|
261
|
-
case '@':
|
|
262
|
-
if (this.col < this.lines[this.row].length) {
|
|
263
|
-
this.lines[this.row].splice(this.col, 0, ...Array.from({ length: n }, () => ({ char: ' ', style: PLAIN })));
|
|
264
|
-
}
|
|
265
|
-
break;
|
|
266
|
-
case 's':
|
|
267
|
-
this.savedCursor = { row: this.row, col: this.col };
|
|
268
|
-
break;
|
|
269
|
-
case 'u':
|
|
270
|
-
if (this.savedCursor) {
|
|
271
|
-
({ row: this.row, col: this.col } = this.savedCursor);
|
|
272
|
-
}
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
protected moveRow(row: number): void {
|
|
278
|
-
while (this.lines.length <= row) {
|
|
279
|
-
this.lines.push([]);
|
|
280
|
-
}
|
|
281
|
-
this.row = row;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
protected eraseLine(mode: number): void {
|
|
285
|
-
const line = this.lines[this.row];
|
|
286
|
-
if (mode === 0) {
|
|
287
|
-
line.length = Math.min(line.length, this.col);
|
|
288
|
-
} else if (mode === 1) {
|
|
289
|
-
for (let i = 0; i <= Math.min(this.col, line.length - 1); i++) {
|
|
290
|
-
line[i] = { char: ' ', style: PLAIN };
|
|
291
|
-
}
|
|
292
|
-
} else {
|
|
293
|
-
line.length = 0;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
protected eraseScreen(mode: number): void {
|
|
298
|
-
if (mode === 0) {
|
|
299
|
-
this.eraseLine(0);
|
|
300
|
-
this.lines.length = this.row + 1;
|
|
301
|
-
} else if (mode === 1) {
|
|
302
|
-
for (let i = this.top(); i < this.row; i++) {
|
|
303
|
-
this.lines[i] = [];
|
|
304
|
-
}
|
|
305
|
-
this.eraseLine(1);
|
|
306
|
-
} else {
|
|
307
|
-
// The screen scrolls away and stays above, as in xterm; 3 also drops what is above.
|
|
308
|
-
if (mode === 3) {
|
|
309
|
-
this.lines = [[]];
|
|
310
|
-
} else {
|
|
311
|
-
const used = this.lines.length > 1 || this.lines[0].length > 0;
|
|
312
|
-
for (let i = 0; used && i < this.rows; i++) {
|
|
313
|
-
this.lines.push([]);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
this.row = this.top();
|
|
317
|
-
this.col = 0;
|
|
318
|
-
if (this.lines.length > this.maxLines) {
|
|
319
|
-
const drop = this.lines.length - this.maxLines;
|
|
320
|
-
this.lines.splice(0, drop);
|
|
321
|
-
this.row -= drop;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
protected sgr(values: number[]): void {
|
|
327
|
-
const style: AnsiStyle = { ...this.style };
|
|
328
|
-
for (let i = 0; i < values.length; i++) {
|
|
329
|
-
const value = values[i];
|
|
330
|
-
if (value === 0) {
|
|
331
|
-
for (const key of Object.keys(style) as (keyof AnsiStyle)[]) {
|
|
332
|
-
delete style[key];
|
|
333
|
-
}
|
|
334
|
-
} else if (value === 1) {
|
|
335
|
-
style.bold = true;
|
|
336
|
-
} else if (value === 2) {
|
|
337
|
-
style.dim = true;
|
|
338
|
-
} else if (value === 3) {
|
|
339
|
-
style.italic = true;
|
|
340
|
-
} else if (value === 4) {
|
|
341
|
-
style.underline = true;
|
|
342
|
-
} else if (value === 7) {
|
|
343
|
-
style.inverse = true;
|
|
344
|
-
} else if (value === 22) {
|
|
345
|
-
delete style.bold;
|
|
346
|
-
delete style.dim;
|
|
347
|
-
} else if (value === 23) {
|
|
348
|
-
delete style.italic;
|
|
349
|
-
} else if (value === 24) {
|
|
350
|
-
delete style.underline;
|
|
351
|
-
} else if (value === 27) {
|
|
352
|
-
delete style.inverse;
|
|
353
|
-
} else if (value >= 30 && value <= 37) {
|
|
354
|
-
style.fg = value - 30;
|
|
355
|
-
} else if (value >= 90 && value <= 97) {
|
|
356
|
-
style.fg = value - 90 + 8;
|
|
357
|
-
} else if (value === 39) {
|
|
358
|
-
delete style.fg;
|
|
359
|
-
} else if (value >= 40 && value <= 47) {
|
|
360
|
-
style.bg = value - 40;
|
|
361
|
-
} else if (value >= 100 && value <= 107) {
|
|
362
|
-
style.bg = value - 100 + 8;
|
|
363
|
-
} else if (value === 49) {
|
|
364
|
-
delete style.bg;
|
|
365
|
-
} else if (value === 38 || value === 48) {
|
|
366
|
-
const key = value === 38 ? 'fg' : 'bg';
|
|
367
|
-
if (values[i + 1] === 5 && values[i + 2] !== undefined) {
|
|
368
|
-
style[key] = values[i + 2];
|
|
369
|
-
i += 2;
|
|
370
|
-
} else if (values[i + 1] === 2 && values[i + 4] !== undefined) {
|
|
371
|
-
style[key] = `#${values
|
|
372
|
-
.slice(i + 2, i + 5)
|
|
373
|
-
.map(part => Math.min(255, part).toString(16).padStart(2, '0'))
|
|
374
|
-
.join('')}`;
|
|
375
|
-
i += 4;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
this.style = Object.keys(style).length ? style : PLAIN;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/** The colors of the xterm palette as CSS: the first 16 follow the theme of the page. */
|
|
384
|
-
export namespace AnsiUtil {
|
|
385
|
-
const BASIC = ['--ta-text', '--ta-red', '--ta-green', '--ta-yellow', '--ta-blue', '#c084fc', '#22d3ee', '--ta-secondary'];
|
|
386
|
-
const STEPS = [0, 95, 135, 175, 215, 255];
|
|
387
|
-
|
|
388
|
-
export function color(value: number | string | undefined): string | undefined {
|
|
389
|
-
if (value === undefined || typeof value === 'string') {
|
|
390
|
-
return value;
|
|
391
|
-
}
|
|
392
|
-
if (value < 16) {
|
|
393
|
-
if (value % 8 === 0) {
|
|
394
|
-
return 'var(--ta-muted)';
|
|
395
|
-
}
|
|
396
|
-
const name = value === 15 ? '--ta-text' : BASIC[value % 8];
|
|
397
|
-
return name.startsWith('--') ? `var(${name})` : name;
|
|
398
|
-
}
|
|
399
|
-
if (value < 232) {
|
|
400
|
-
const n = value - 16;
|
|
401
|
-
return `rgb(${STEPS[Math.floor(n / 36)]}, ${STEPS[Math.floor(n / 6) % 6]}, ${STEPS[n % 6]})`;
|
|
402
|
-
}
|
|
403
|
-
const gray = 8 + (value - 232) * 10;
|
|
404
|
-
return `rgb(${gray}, ${gray}, ${gray})`;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/** Inline CSS of a style. */
|
|
408
|
-
export function css(style: AnsiStyle): Record<string, string> | undefined {
|
|
409
|
-
if (style === PLAIN || !Object.keys(style).length) {
|
|
410
|
-
return undefined;
|
|
411
|
-
}
|
|
412
|
-
let fg = color(style.fg);
|
|
413
|
-
let bg = color(style.bg);
|
|
414
|
-
if (style.inverse) {
|
|
415
|
-
[fg, bg] = [bg ?? 'var(--ta-main)', fg ?? 'var(--ta-text)'];
|
|
416
|
-
}
|
|
417
|
-
const css: Record<string, string> = {};
|
|
418
|
-
if (fg) {
|
|
419
|
-
css.color = fg;
|
|
420
|
-
}
|
|
421
|
-
if (bg) {
|
|
422
|
-
css.background = bg;
|
|
423
|
-
}
|
|
424
|
-
if (style.bold) {
|
|
425
|
-
css.fontWeight = '600';
|
|
426
|
-
}
|
|
427
|
-
if (style.dim) {
|
|
428
|
-
css.opacity = '0.65';
|
|
429
|
-
}
|
|
430
|
-
if (style.italic) {
|
|
431
|
-
css.fontStyle = 'italic';
|
|
432
|
-
}
|
|
433
|
-
if (style.underline) {
|
|
434
|
-
css.textDecoration = 'underline';
|
|
435
|
-
}
|
|
436
|
-
return css;
|
|
437
|
-
}
|
|
438
|
-
}
|
package/web-src/util/keys.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** What a key press sends to a terminal; undefined for keys the text input handles (letters, IME). */
|
|
2
|
-
export interface KeyPress {
|
|
3
|
-
key: string;
|
|
4
|
-
ctrlKey?: boolean;
|
|
5
|
-
altKey?: boolean;
|
|
6
|
-
metaKey?: boolean;
|
|
7
|
-
shiftKey?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const KEYS: Record<string, string> = {
|
|
11
|
-
Enter: '\r',
|
|
12
|
-
Backspace: '\x7f',
|
|
13
|
-
Tab: '\t',
|
|
14
|
-
Escape: '\x1b',
|
|
15
|
-
ArrowUp: '\x1b[A',
|
|
16
|
-
ArrowDown: '\x1b[B',
|
|
17
|
-
ArrowRight: '\x1b[C',
|
|
18
|
-
ArrowLeft: '\x1b[D',
|
|
19
|
-
Home: '\x1b[H',
|
|
20
|
-
End: '\x1b[F',
|
|
21
|
-
Delete: '\x1b[3~',
|
|
22
|
-
Insert: '\x1b[2~',
|
|
23
|
-
PageUp: '\x1b[5~',
|
|
24
|
-
PageDown: '\x1b[6~',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export namespace TerminalKeys {
|
|
28
|
-
export function sequence(event: KeyPress): string | undefined {
|
|
29
|
-
if (event.metaKey) {
|
|
30
|
-
// The browser's: copy, paste, close the tab.
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
if (event.key === 'Tab' && event.shiftKey) {
|
|
34
|
-
return '\x1b[Z';
|
|
35
|
-
}
|
|
36
|
-
const special = KEYS[event.key];
|
|
37
|
-
if (special) {
|
|
38
|
-
return event.altKey ? `\x1b${special}` : special;
|
|
39
|
-
}
|
|
40
|
-
if (event.ctrlKey && event.key.length === 1) {
|
|
41
|
-
const code = event.key.toUpperCase().charCodeAt(0);
|
|
42
|
-
if (code >= 64 && code <= 95) {
|
|
43
|
-
return String.fromCharCode(code - 64);
|
|
44
|
-
}
|
|
45
|
-
if (event.key === ' ') {
|
|
46
|
-
return '\x00';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Pasted text as the shell takes it: lines end with `\r`. */
|
|
53
|
-
export function paste(text: string): string {
|
|
54
|
-
return text.replace(/\r?\n/g, '\r');
|
|
55
|
-
}
|
|
56
|
-
}
|