restty 0.1.17 → 0.1.18
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 +4 -9
- package/dist/{app/index.js → chunk-53vdvhe3.js} +23781 -23698
- package/dist/fonts/manager.d.ts +1 -2
- package/dist/internal.js +105 -56357
- package/dist/renderer/shapes.d.ts +1 -3
- package/dist/restty.js +20 -0
- package/dist/unicode/ghostty-symbol-ranges.d.ts +1 -0
- package/dist/unicode/symbols.d.ts +6 -0
- package/package.json +8 -61
- package/dist/fonts/index.js +0 -5333
- package/dist/grid/index.js +0 -71
- package/dist/ime/index.js +0 -84
- package/dist/index.js +0 -56354
- package/dist/input/index.js +0 -1051
- package/dist/pty/index.js +0 -338
- package/dist/renderer/index.js +0 -1715
- package/dist/selection/index.js +0 -226
- package/dist/theme/index.js +0 -11218
- package/dist/wasm/index.js +0 -6003
package/dist/input/index.js
DELETED
|
@@ -1,1051 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, {
|
|
5
|
-
get: all[name],
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
set: (newValue) => all[name] = () => newValue
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/input/keymap.ts
|
|
13
|
-
var sequences = {
|
|
14
|
-
enter: "\r",
|
|
15
|
-
backspace: "",
|
|
16
|
-
delete: "\x1B[3~",
|
|
17
|
-
tab: "\t",
|
|
18
|
-
shiftTab: "\x1B[Z",
|
|
19
|
-
escape: "\x1B"
|
|
20
|
-
};
|
|
21
|
-
var DEFAULT_CONFIG = {
|
|
22
|
-
enableCtrlCombos: true
|
|
23
|
-
};
|
|
24
|
-
var KITTY_FLAG_DISAMBIGUATE = 1 << 0;
|
|
25
|
-
var KITTY_FLAG_REPORT_EVENTS = 1 << 1;
|
|
26
|
-
var KITTY_FLAG_REPORT_ALTERNATE = 1 << 2;
|
|
27
|
-
var KITTY_FLAG_REPORT_ALL = 1 << 3;
|
|
28
|
-
var KITTY_FLAG_REPORT_ASSOCIATED_TEXT = 1 << 4;
|
|
29
|
-
var KITTY_SPECIAL_KEYS = {
|
|
30
|
-
Escape: { code: 27, final: "u" },
|
|
31
|
-
Enter: { code: 13, final: "u" },
|
|
32
|
-
Tab: { code: 9, final: "u" },
|
|
33
|
-
Backspace: { code: 127, final: "u" },
|
|
34
|
-
Insert: { code: 2, final: "~" },
|
|
35
|
-
Delete: { code: 3, final: "~" },
|
|
36
|
-
Del: { code: 3, final: "~" },
|
|
37
|
-
ArrowLeft: { code: 1, final: "D" },
|
|
38
|
-
ArrowRight: { code: 1, final: "C" },
|
|
39
|
-
ArrowUp: { code: 1, final: "A" },
|
|
40
|
-
ArrowDown: { code: 1, final: "B" },
|
|
41
|
-
PageUp: { code: 5, final: "~" },
|
|
42
|
-
PageDown: { code: 6, final: "~" },
|
|
43
|
-
Home: { code: 1, final: "H" },
|
|
44
|
-
End: { code: 1, final: "F" },
|
|
45
|
-
CapsLock: { code: 57358, final: "u" },
|
|
46
|
-
ScrollLock: { code: 57359, final: "u" },
|
|
47
|
-
NumLock: { code: 57360, final: "u" },
|
|
48
|
-
PrintScreen: { code: 57361, final: "u" },
|
|
49
|
-
Pause: { code: 57362, final: "u" },
|
|
50
|
-
ContextMenu: { code: 57363, final: "u" },
|
|
51
|
-
Menu: { code: 57363, final: "u" },
|
|
52
|
-
F1: { code: 1, final: "P" },
|
|
53
|
-
F2: { code: 1, final: "Q" },
|
|
54
|
-
F3: { code: 13, final: "~" },
|
|
55
|
-
F4: { code: 1, final: "S" },
|
|
56
|
-
F5: { code: 15, final: "~" },
|
|
57
|
-
F6: { code: 17, final: "~" },
|
|
58
|
-
F7: { code: 18, final: "~" },
|
|
59
|
-
F8: { code: 19, final: "~" },
|
|
60
|
-
F9: { code: 20, final: "~" },
|
|
61
|
-
F10: { code: 21, final: "~" },
|
|
62
|
-
F11: { code: 23, final: "~" },
|
|
63
|
-
F12: { code: 24, final: "~" },
|
|
64
|
-
F13: { code: 57376, final: "u" },
|
|
65
|
-
F14: { code: 57377, final: "u" },
|
|
66
|
-
F15: { code: 57378, final: "u" },
|
|
67
|
-
F16: { code: 57379, final: "u" },
|
|
68
|
-
F17: { code: 57380, final: "u" },
|
|
69
|
-
F18: { code: 57381, final: "u" },
|
|
70
|
-
F19: { code: 57382, final: "u" },
|
|
71
|
-
F20: { code: 57383, final: "u" },
|
|
72
|
-
F21: { code: 57384, final: "u" },
|
|
73
|
-
F22: { code: 57385, final: "u" },
|
|
74
|
-
F23: { code: 57386, final: "u" },
|
|
75
|
-
F24: { code: 57387, final: "u" }
|
|
76
|
-
};
|
|
77
|
-
var KITTY_KEYPAD_BY_CODE = {
|
|
78
|
-
Numpad0: { code: 57399, final: "u" },
|
|
79
|
-
Numpad1: { code: 57400, final: "u" },
|
|
80
|
-
Numpad2: { code: 57401, final: "u" },
|
|
81
|
-
Numpad3: { code: 57402, final: "u" },
|
|
82
|
-
Numpad4: { code: 57403, final: "u" },
|
|
83
|
-
Numpad5: { code: 57404, final: "u" },
|
|
84
|
-
Numpad6: { code: 57405, final: "u" },
|
|
85
|
-
Numpad7: { code: 57406, final: "u" },
|
|
86
|
-
Numpad8: { code: 57407, final: "u" },
|
|
87
|
-
Numpad9: { code: 57408, final: "u" },
|
|
88
|
-
NumpadDecimal: { code: 57409, final: "u" },
|
|
89
|
-
NumpadDivide: { code: 57410, final: "u" },
|
|
90
|
-
NumpadMultiply: { code: 57411, final: "u" },
|
|
91
|
-
NumpadSubtract: { code: 57412, final: "u" },
|
|
92
|
-
NumpadAdd: { code: 57413, final: "u" },
|
|
93
|
-
NumpadEnter: { code: 57414, final: "u" },
|
|
94
|
-
NumpadEqual: { code: 57415, final: "u" }
|
|
95
|
-
};
|
|
96
|
-
var KITTY_LOCK_KEYS = new Set(["CapsLock", "NumLock", "ScrollLock"]);
|
|
97
|
-
var UN_SHIFTED_CODE_BY_CODE = {
|
|
98
|
-
Backquote: "`",
|
|
99
|
-
Minus: "-",
|
|
100
|
-
Equal: "=",
|
|
101
|
-
BracketLeft: "[",
|
|
102
|
-
BracketRight: "]",
|
|
103
|
-
Backslash: "\\",
|
|
104
|
-
Semicolon: ";",
|
|
105
|
-
Quote: "'",
|
|
106
|
-
Comma: ",",
|
|
107
|
-
Period: ".",
|
|
108
|
-
Slash: "/"
|
|
109
|
-
};
|
|
110
|
-
var SHIFTED_CODE_BY_CODE = {
|
|
111
|
-
Backquote: "~",
|
|
112
|
-
Digit1: "!",
|
|
113
|
-
Digit2: "@",
|
|
114
|
-
Digit3: "#",
|
|
115
|
-
Digit4: "$",
|
|
116
|
-
Digit5: "%",
|
|
117
|
-
Digit6: "^",
|
|
118
|
-
Digit7: "&",
|
|
119
|
-
Digit8: "*",
|
|
120
|
-
Digit9: "(",
|
|
121
|
-
Digit0: ")",
|
|
122
|
-
Minus: "_",
|
|
123
|
-
Equal: "+",
|
|
124
|
-
BracketLeft: "{",
|
|
125
|
-
BracketRight: "}",
|
|
126
|
-
Backslash: "|",
|
|
127
|
-
Semicolon: ":",
|
|
128
|
-
Quote: '"',
|
|
129
|
-
Comma: "<",
|
|
130
|
-
Period: ">",
|
|
131
|
-
Slash: "?"
|
|
132
|
-
};
|
|
133
|
-
function ctrlCharForKey(key) {
|
|
134
|
-
if (key === " ")
|
|
135
|
-
return "\x00";
|
|
136
|
-
if (key === "@")
|
|
137
|
-
return "\x00";
|
|
138
|
-
if (key === "[")
|
|
139
|
-
return "\x1B";
|
|
140
|
-
if (key === "\\")
|
|
141
|
-
return "\x1C";
|
|
142
|
-
if (key === "]")
|
|
143
|
-
return "\x1D";
|
|
144
|
-
if (key === "^")
|
|
145
|
-
return "\x1E";
|
|
146
|
-
if (key === "_")
|
|
147
|
-
return "\x1F";
|
|
148
|
-
if (key === "?")
|
|
149
|
-
return "";
|
|
150
|
-
if (key.length === 1) {
|
|
151
|
-
const code = key.toUpperCase().charCodeAt(0);
|
|
152
|
-
if (code >= 64 && code <= 95) {
|
|
153
|
-
return String.fromCharCode(code & 31);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return "";
|
|
157
|
-
}
|
|
158
|
-
function modifierCode(event) {
|
|
159
|
-
let mod = 1;
|
|
160
|
-
if (event.shiftKey)
|
|
161
|
-
mod += 1;
|
|
162
|
-
if (event.altKey)
|
|
163
|
-
mod += 2;
|
|
164
|
-
if (event.ctrlKey)
|
|
165
|
-
mod += 4;
|
|
166
|
-
return mod;
|
|
167
|
-
}
|
|
168
|
-
function encodeKeyEvent(event, config = DEFAULT_CONFIG, kittyFlags = 0) {
|
|
169
|
-
if (!event)
|
|
170
|
-
return "";
|
|
171
|
-
if (event.isComposing)
|
|
172
|
-
return "";
|
|
173
|
-
if (kittyFlags !== 0) {
|
|
174
|
-
return encodeKittyKeyEvent(event, kittyFlags);
|
|
175
|
-
}
|
|
176
|
-
if (event.metaKey)
|
|
177
|
-
return "";
|
|
178
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
179
|
-
let seq = "";
|
|
180
|
-
if (cfg.enableCtrlCombos && event.ctrlKey) {
|
|
181
|
-
seq = ctrlCharForKey(event.key);
|
|
182
|
-
if (event.altKey && seq)
|
|
183
|
-
seq = `\x1B${seq}`;
|
|
184
|
-
}
|
|
185
|
-
if (!seq) {
|
|
186
|
-
switch (event.key) {
|
|
187
|
-
case "Enter":
|
|
188
|
-
seq = sequences.enter;
|
|
189
|
-
break;
|
|
190
|
-
case "Backspace":
|
|
191
|
-
seq = sequences.backspace;
|
|
192
|
-
break;
|
|
193
|
-
case "Delete":
|
|
194
|
-
case "Del":
|
|
195
|
-
seq = sequences.delete;
|
|
196
|
-
break;
|
|
197
|
-
case "Tab":
|
|
198
|
-
seq = event.shiftKey ? sequences.shiftTab : sequences.tab;
|
|
199
|
-
break;
|
|
200
|
-
case "Escape":
|
|
201
|
-
seq = sequences.escape;
|
|
202
|
-
break;
|
|
203
|
-
case "ArrowUp":
|
|
204
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}A` : "\x1B[A";
|
|
205
|
-
break;
|
|
206
|
-
case "ArrowDown":
|
|
207
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}B` : "\x1B[B";
|
|
208
|
-
break;
|
|
209
|
-
case "ArrowRight":
|
|
210
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}C` : "\x1B[C";
|
|
211
|
-
break;
|
|
212
|
-
case "ArrowLeft":
|
|
213
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}D` : "\x1B[D";
|
|
214
|
-
break;
|
|
215
|
-
case "Home":
|
|
216
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}H` : "\x1B[H";
|
|
217
|
-
break;
|
|
218
|
-
case "End":
|
|
219
|
-
seq = event.shiftKey || event.altKey || event.ctrlKey ? `\x1B[1;${modifierCode(event)}F` : "\x1B[F";
|
|
220
|
-
break;
|
|
221
|
-
case "PageUp":
|
|
222
|
-
seq = "\x1B[5~";
|
|
223
|
-
break;
|
|
224
|
-
case "PageDown":
|
|
225
|
-
seq = "\x1B[6~";
|
|
226
|
-
break;
|
|
227
|
-
case "Insert":
|
|
228
|
-
seq = "\x1B[2~";
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
if (event.key?.startsWith("F")) {
|
|
232
|
-
const fn = Number(event.key.slice(1));
|
|
233
|
-
const map = {
|
|
234
|
-
1: "\x1BOP",
|
|
235
|
-
2: "\x1BOQ",
|
|
236
|
-
3: "\x1BOR",
|
|
237
|
-
4: "\x1BOS",
|
|
238
|
-
5: "\x1B[15~",
|
|
239
|
-
6: "\x1B[17~",
|
|
240
|
-
7: "\x1B[18~",
|
|
241
|
-
8: "\x1B[19~",
|
|
242
|
-
9: "\x1B[20~",
|
|
243
|
-
10: "\x1B[21~",
|
|
244
|
-
11: "\x1B[23~",
|
|
245
|
-
12: "\x1B[24~"
|
|
246
|
-
};
|
|
247
|
-
seq = map[fn] ?? "";
|
|
248
|
-
} else if (event.key?.length === 1) {
|
|
249
|
-
seq = event.altKey ? `\x1B${event.key}` : event.key;
|
|
250
|
-
}
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return seq;
|
|
255
|
-
}
|
|
256
|
-
function kittyModifierCode(event, includeLockModifiers) {
|
|
257
|
-
let code = 1;
|
|
258
|
-
if (event.shiftKey)
|
|
259
|
-
code += 1;
|
|
260
|
-
if (event.altKey)
|
|
261
|
-
code += 2;
|
|
262
|
-
if (event.ctrlKey)
|
|
263
|
-
code += 4;
|
|
264
|
-
if (event.metaKey)
|
|
265
|
-
code += 8;
|
|
266
|
-
if (includeLockModifiers) {
|
|
267
|
-
if (event.getModifierState?.("CapsLock"))
|
|
268
|
-
code += 64;
|
|
269
|
-
if (event.getModifierState?.("NumLock"))
|
|
270
|
-
code += 128;
|
|
271
|
-
}
|
|
272
|
-
return code;
|
|
273
|
-
}
|
|
274
|
-
function deriveUnshiftedCodepoint(event) {
|
|
275
|
-
const code = event.code || "";
|
|
276
|
-
if (code.startsWith("Key") && code.length === 4) {
|
|
277
|
-
return code.slice(3).toLowerCase().codePointAt(0) ?? 0;
|
|
278
|
-
}
|
|
279
|
-
if (code.startsWith("Digit") && code.length === 6) {
|
|
280
|
-
return code.slice(5).codePointAt(0) ?? 0;
|
|
281
|
-
}
|
|
282
|
-
const punctuation = UN_SHIFTED_CODE_BY_CODE[code];
|
|
283
|
-
if (punctuation)
|
|
284
|
-
return punctuation.codePointAt(0) ?? 0;
|
|
285
|
-
if (event.key?.length === 1)
|
|
286
|
-
return event.key.codePointAt(0) ?? 0;
|
|
287
|
-
return 0;
|
|
288
|
-
}
|
|
289
|
-
function deriveShiftedCodepoint(event, unshiftedCodepoint) {
|
|
290
|
-
if (!event.shiftKey)
|
|
291
|
-
return 0;
|
|
292
|
-
if (event.key?.length === 1) {
|
|
293
|
-
const cp2 = event.key.codePointAt(0) ?? 0;
|
|
294
|
-
if (cp2 > 0 && cp2 !== unshiftedCodepoint)
|
|
295
|
-
return cp2;
|
|
296
|
-
}
|
|
297
|
-
const shifted = SHIFTED_CODE_BY_CODE[event.code || ""];
|
|
298
|
-
if (!shifted)
|
|
299
|
-
return 0;
|
|
300
|
-
const cp = shifted.codePointAt(0) ?? 0;
|
|
301
|
-
return cp !== unshiftedCodepoint ? cp : 0;
|
|
302
|
-
}
|
|
303
|
-
function deriveBaseLayoutCodepoint(event) {
|
|
304
|
-
const code = event.code || "";
|
|
305
|
-
if (code.startsWith("Key") && code.length === 4) {
|
|
306
|
-
return code.slice(3).toLowerCase().codePointAt(0) ?? 0;
|
|
307
|
-
}
|
|
308
|
-
if (code.startsWith("Digit") && code.length === 6) {
|
|
309
|
-
return code.slice(5).codePointAt(0) ?? 0;
|
|
310
|
-
}
|
|
311
|
-
const punctuation = UN_SHIFTED_CODE_BY_CODE[code];
|
|
312
|
-
if (punctuation)
|
|
313
|
-
return punctuation.codePointAt(0) ?? 0;
|
|
314
|
-
return 0;
|
|
315
|
-
}
|
|
316
|
-
function toCodepoints(text) {
|
|
317
|
-
const points = [];
|
|
318
|
-
for (const ch of text) {
|
|
319
|
-
points.push(ch.codePointAt(0) ?? 0);
|
|
320
|
-
}
|
|
321
|
-
return points.filter((cp) => cp > 0);
|
|
322
|
-
}
|
|
323
|
-
function kittyEventType(event, reportEvents) {
|
|
324
|
-
if (!reportEvents)
|
|
325
|
-
return 0;
|
|
326
|
-
if (event.type === "keyup")
|
|
327
|
-
return 3;
|
|
328
|
-
if (event.repeat)
|
|
329
|
-
return 2;
|
|
330
|
-
return 1;
|
|
331
|
-
}
|
|
332
|
-
function encodeKittySequence(code, final, modifiers, eventType, alternates, associatedText) {
|
|
333
|
-
if (final !== "u" && final !== "~") {
|
|
334
|
-
if (eventType !== 0)
|
|
335
|
-
return `\x1B[1;${modifiers}:${eventType}${final}`;
|
|
336
|
-
if (modifiers > 1)
|
|
337
|
-
return `\x1B[1;${modifiers}${final}`;
|
|
338
|
-
return `\x1B[${final}`;
|
|
339
|
-
}
|
|
340
|
-
let keyPart = `${code}`;
|
|
341
|
-
if (final === "u" && alternates && (alternates.shifted || alternates.base)) {
|
|
342
|
-
const shifted = alternates.shifted ? `${alternates.shifted}` : "";
|
|
343
|
-
const base = alternates.base ? `${alternates.base}` : "";
|
|
344
|
-
keyPart += `:${shifted}`;
|
|
345
|
-
if (base)
|
|
346
|
-
keyPart += `:${base}`;
|
|
347
|
-
}
|
|
348
|
-
const hasAssocText = Boolean(associatedText?.length);
|
|
349
|
-
if (eventType === 0 && modifiers <= 1 && !hasAssocText) {
|
|
350
|
-
return `\x1B[${keyPart}${final}`;
|
|
351
|
-
}
|
|
352
|
-
let seq = `\x1B[${keyPart};${modifiers}`;
|
|
353
|
-
if (eventType !== 0)
|
|
354
|
-
seq += `:${eventType}`;
|
|
355
|
-
if (hasAssocText)
|
|
356
|
-
seq += `;${associatedText.join(":")}`;
|
|
357
|
-
seq += final;
|
|
358
|
-
return seq;
|
|
359
|
-
}
|
|
360
|
-
function encodeKittyKeyEvent(event, kittyFlags) {
|
|
361
|
-
const reportEvents = (kittyFlags & KITTY_FLAG_REPORT_EVENTS) !== 0;
|
|
362
|
-
const reportAlternate = (kittyFlags & KITTY_FLAG_REPORT_ALTERNATE) !== 0;
|
|
363
|
-
const reportAll = (kittyFlags & KITTY_FLAG_REPORT_ALL) !== 0;
|
|
364
|
-
const reportAssociatedText = (kittyFlags & KITTY_FLAG_REPORT_ASSOCIATED_TEXT) !== 0;
|
|
365
|
-
const disambiguate = (kittyFlags & KITTY_FLAG_DISAMBIGUATE) !== 0;
|
|
366
|
-
const key = event.key ?? "";
|
|
367
|
-
const special = KITTY_KEYPAD_BY_CODE[event.code || ""] ?? KITTY_SPECIAL_KEYS[key];
|
|
368
|
-
const isLockKey = KITTY_LOCK_KEYS.has(key);
|
|
369
|
-
const hasText = key.length === 1;
|
|
370
|
-
const hasTextModifiers = event.altKey || event.ctrlKey || event.metaKey;
|
|
371
|
-
const eventType = kittyEventType(event, reportEvents);
|
|
372
|
-
const isRelease = event.type === "keyup";
|
|
373
|
-
const isLegacyTextKey = !special && hasText && !reportAll && !hasTextModifiers;
|
|
374
|
-
const isLegacyControlKey = (key === "Enter" || key === "Tab" || key === "Backspace") && !reportAll && !hasTextModifiers && !disambiguate;
|
|
375
|
-
if (isRelease && !reportEvents)
|
|
376
|
-
return "";
|
|
377
|
-
if (isRelease && isLegacyTextKey)
|
|
378
|
-
return "";
|
|
379
|
-
if (isRelease && isLegacyControlKey)
|
|
380
|
-
return "";
|
|
381
|
-
if (isLockKey && !reportAll)
|
|
382
|
-
return "";
|
|
383
|
-
if (isLegacyTextKey) {
|
|
384
|
-
return key;
|
|
385
|
-
}
|
|
386
|
-
if (isLegacyControlKey) {
|
|
387
|
-
switch (key) {
|
|
388
|
-
case "Enter":
|
|
389
|
-
return sequences.enter;
|
|
390
|
-
case "Tab":
|
|
391
|
-
return sequences.tab;
|
|
392
|
-
case "Backspace":
|
|
393
|
-
return sequences.backspace;
|
|
394
|
-
default:
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
const mods = kittyModifierCode(event, reportAll);
|
|
399
|
-
if (special) {
|
|
400
|
-
return encodeKittySequence(special.code, special.final, mods, eventType);
|
|
401
|
-
}
|
|
402
|
-
const unshifted = deriveUnshiftedCodepoint(event);
|
|
403
|
-
if (unshifted > 0 && (reportAll || disambiguate || hasTextModifiers || eventType !== 0)) {
|
|
404
|
-
const alternates = reportAlternate && reportAll ? {
|
|
405
|
-
shifted: deriveShiftedCodepoint(event, unshifted) || undefined,
|
|
406
|
-
base: (() => {
|
|
407
|
-
const base = deriveBaseLayoutCodepoint(event);
|
|
408
|
-
return base > 0 && base !== unshifted ? base : undefined;
|
|
409
|
-
})()
|
|
410
|
-
} : undefined;
|
|
411
|
-
const associated = reportAll && reportAssociatedText && hasText ? toCodepoints(key) : undefined;
|
|
412
|
-
return encodeKittySequence(unshifted, "u", mods, eventType, alternates, associated);
|
|
413
|
-
}
|
|
414
|
-
if (hasText) {
|
|
415
|
-
return event.altKey ? `\x1B${key}` : key;
|
|
416
|
-
}
|
|
417
|
-
return "";
|
|
418
|
-
}
|
|
419
|
-
function encodeBeforeInput(event) {
|
|
420
|
-
if (!event)
|
|
421
|
-
return "";
|
|
422
|
-
const type = event.inputType;
|
|
423
|
-
if (type === "insertText")
|
|
424
|
-
return event.data || "";
|
|
425
|
-
if (type === "insertLineBreak")
|
|
426
|
-
return sequences.enter;
|
|
427
|
-
if (type === "deleteContentBackward")
|
|
428
|
-
return sequences.backspace;
|
|
429
|
-
if (type === "deleteContentForward")
|
|
430
|
-
return sequences.delete;
|
|
431
|
-
if (type === "insertFromPaste") {
|
|
432
|
-
return event.dataTransfer?.getData("text/plain") || "";
|
|
433
|
-
}
|
|
434
|
-
return "";
|
|
435
|
-
}
|
|
436
|
-
function mapKeyForPty(seq) {
|
|
437
|
-
const csi = "\x1B[";
|
|
438
|
-
if (seq.startsWith(csi) && seq.endsWith("u")) {
|
|
439
|
-
const body = seq.slice(csi.length, -1);
|
|
440
|
-
const [codeText] = body.split(";");
|
|
441
|
-
if (codeText && /^[0-9]+$/.test(codeText)) {
|
|
442
|
-
const code = Number(codeText);
|
|
443
|
-
if (code === 127)
|
|
444
|
-
return "";
|
|
445
|
-
if (code === 13)
|
|
446
|
-
return "\r";
|
|
447
|
-
if (code === 9)
|
|
448
|
-
return "\t";
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (seq.startsWith(csi) && seq.endsWith("~")) {
|
|
452
|
-
const body = seq.slice(csi.length, -1);
|
|
453
|
-
if (body === "3" || body.startsWith("3;"))
|
|
454
|
-
return "\x1B[3~";
|
|
455
|
-
}
|
|
456
|
-
if (seq === sequences.backspace || seq === "\b" || seq === "\b\x1B[P")
|
|
457
|
-
return "";
|
|
458
|
-
if (seq === sequences.delete || seq === "\x1B[P")
|
|
459
|
-
return "\x1B[3~";
|
|
460
|
-
if (seq === sequences.enter || seq === `\r
|
|
461
|
-
`)
|
|
462
|
-
return "\r";
|
|
463
|
-
return seq;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/input/ansi.ts
|
|
467
|
-
var ESC = "\x1B";
|
|
468
|
-
function parsePrivateModeSeq(seq) {
|
|
469
|
-
if (!seq.startsWith(`${ESC}[?`) || seq.length < 5)
|
|
470
|
-
return null;
|
|
471
|
-
const final = seq[seq.length - 1];
|
|
472
|
-
if (final !== "h" && final !== "l")
|
|
473
|
-
return null;
|
|
474
|
-
const body = seq.slice(3, -1);
|
|
475
|
-
if (!body || /[^0-9;]/.test(body))
|
|
476
|
-
return null;
|
|
477
|
-
const parts = body.split(";");
|
|
478
|
-
const codes = [];
|
|
479
|
-
for (let i = 0;i < parts.length; i += 1) {
|
|
480
|
-
const part = parts[i];
|
|
481
|
-
if (!part)
|
|
482
|
-
return null;
|
|
483
|
-
const code = Number(part);
|
|
484
|
-
if (!Number.isFinite(code))
|
|
485
|
-
return null;
|
|
486
|
-
codes.push(code);
|
|
487
|
-
}
|
|
488
|
-
return { codes, enabled: final === "h" };
|
|
489
|
-
}
|
|
490
|
-
function parseWindowOpSeq(seq) {
|
|
491
|
-
if (!seq.startsWith(`${ESC}[`) || !seq.endsWith("t"))
|
|
492
|
-
return null;
|
|
493
|
-
const body = seq.slice(2, -1);
|
|
494
|
-
if (/[^0-9;]/.test(body))
|
|
495
|
-
return null;
|
|
496
|
-
return body ? body.split(";").map((part) => Number(part)) : [];
|
|
497
|
-
}
|
|
498
|
-
function isDeviceAttributesQuery(seq) {
|
|
499
|
-
if (!seq.startsWith(`${ESC}[`) || !seq.endsWith("c"))
|
|
500
|
-
return false;
|
|
501
|
-
const body = seq.slice(2, -1);
|
|
502
|
-
let i = 0;
|
|
503
|
-
while (i < body.length && (body[i] === "?" || body[i] === ">"))
|
|
504
|
-
i += 1;
|
|
505
|
-
while (i < body.length && body.charCodeAt(i) >= 48 && body.charCodeAt(i) <= 57)
|
|
506
|
-
i += 1;
|
|
507
|
-
if (i < body.length && body[i] === ";") {
|
|
508
|
-
i += 1;
|
|
509
|
-
while (i < body.length && body.charCodeAt(i) >= 48 && body.charCodeAt(i) <= 57)
|
|
510
|
-
i += 1;
|
|
511
|
-
}
|
|
512
|
-
return i === body.length;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// src/input/mouse.ts
|
|
516
|
-
class MouseController {
|
|
517
|
-
mode = "auto";
|
|
518
|
-
enabled = false;
|
|
519
|
-
format = "x10";
|
|
520
|
-
motion = "none";
|
|
521
|
-
pressed = false;
|
|
522
|
-
button = 0;
|
|
523
|
-
flags = { 1000: false, 1002: false, 1003: false };
|
|
524
|
-
x10Event = false;
|
|
525
|
-
sendReply;
|
|
526
|
-
positionToCell;
|
|
527
|
-
positionToPixel;
|
|
528
|
-
constructor(options) {
|
|
529
|
-
this.sendReply = options.sendReply;
|
|
530
|
-
this.positionToCell = options.positionToCell;
|
|
531
|
-
this.positionToPixel = options.positionToPixel;
|
|
532
|
-
}
|
|
533
|
-
setReplySink(fn) {
|
|
534
|
-
this.sendReply = fn;
|
|
535
|
-
}
|
|
536
|
-
setPositionToCell(fn) {
|
|
537
|
-
this.positionToCell = fn;
|
|
538
|
-
}
|
|
539
|
-
setPositionToPixel(fn) {
|
|
540
|
-
this.positionToPixel = fn;
|
|
541
|
-
}
|
|
542
|
-
setMode(mode) {
|
|
543
|
-
this.mode = mode;
|
|
544
|
-
if (mode === "on") {
|
|
545
|
-
this.enabled = true;
|
|
546
|
-
this.format = "sgr";
|
|
547
|
-
this.motion = "drag";
|
|
548
|
-
} else if (mode === "off") {
|
|
549
|
-
this.enabled = false;
|
|
550
|
-
this.format = "x10";
|
|
551
|
-
this.motion = "none";
|
|
552
|
-
} else {
|
|
553
|
-
this.enabled = this.x10Event || this.flags[1000] || this.flags[1002] || this.flags[1003];
|
|
554
|
-
if (this.flags[1003])
|
|
555
|
-
this.motion = "any";
|
|
556
|
-
else if (this.flags[1002])
|
|
557
|
-
this.motion = "drag";
|
|
558
|
-
else
|
|
559
|
-
this.motion = "none";
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
handleModeSeq(seq) {
|
|
563
|
-
const mode = parsePrivateModeSeq(seq);
|
|
564
|
-
if (!mode)
|
|
565
|
-
return false;
|
|
566
|
-
const { enabled, codes } = mode;
|
|
567
|
-
let handled = false;
|
|
568
|
-
for (const code of codes) {
|
|
569
|
-
if (code === 9) {
|
|
570
|
-
this.x10Event = enabled;
|
|
571
|
-
handled = true;
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
if (code === 1006) {
|
|
575
|
-
this.format = enabled ? "sgr" : "x10";
|
|
576
|
-
handled = true;
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
if (code === 1016) {
|
|
580
|
-
this.format = enabled ? "sgr_pixels" : "x10";
|
|
581
|
-
handled = true;
|
|
582
|
-
continue;
|
|
583
|
-
}
|
|
584
|
-
if (code === 1005) {
|
|
585
|
-
this.format = enabled ? "utf8" : "x10";
|
|
586
|
-
handled = true;
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
if (code === 1015) {
|
|
590
|
-
this.format = enabled ? "urxvt" : "x10";
|
|
591
|
-
handled = true;
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
if (code === 1000 || code === 1002 || code === 1003) {
|
|
595
|
-
this.updateFlags(code, enabled);
|
|
596
|
-
handled = true;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return handled;
|
|
600
|
-
}
|
|
601
|
-
isActive() {
|
|
602
|
-
if (this.mode === "off")
|
|
603
|
-
return false;
|
|
604
|
-
if (this.mode === "on")
|
|
605
|
-
return true;
|
|
606
|
-
return this.enabled;
|
|
607
|
-
}
|
|
608
|
-
getStatus() {
|
|
609
|
-
return { mode: this.mode, active: this.isActive(), detail: this.format, enabled: this.enabled };
|
|
610
|
-
}
|
|
611
|
-
sendMouseEvent(kind, event) {
|
|
612
|
-
if (!this.isActive())
|
|
613
|
-
return false;
|
|
614
|
-
if (!this.positionToCell)
|
|
615
|
-
return false;
|
|
616
|
-
if (this.isX10EventMode() && kind !== "down")
|
|
617
|
-
return false;
|
|
618
|
-
const cell = this.positionToCell(event);
|
|
619
|
-
const col = cell.col + 1;
|
|
620
|
-
const row = cell.row + 1;
|
|
621
|
-
const pixel = this.positionToPixel ? this.positionToPixel(event) : null;
|
|
622
|
-
const isSgr = this.format === "sgr" || this.format === "sgr_pixels";
|
|
623
|
-
const base = "button" in event && event.button === 1 ? 1 : ("button" in event) && event.button === 2 ? 2 : 0;
|
|
624
|
-
const mods = this.modifiers(event, !this.isX10EventMode());
|
|
625
|
-
if (kind === "down") {
|
|
626
|
-
this.pressed = true;
|
|
627
|
-
this.button = base;
|
|
628
|
-
const code = base + mods;
|
|
629
|
-
return this.sendMouse(code, col, row, pixel, false);
|
|
630
|
-
}
|
|
631
|
-
if (kind === "up") {
|
|
632
|
-
const btn = this.pressed ? this.button : base;
|
|
633
|
-
this.pressed = false;
|
|
634
|
-
const code = isSgr ? btn + mods : 3 + mods;
|
|
635
|
-
return this.sendMouse(code, col, row, pixel, true);
|
|
636
|
-
}
|
|
637
|
-
if (kind === "move") {
|
|
638
|
-
if (this.motion === "none")
|
|
639
|
-
return false;
|
|
640
|
-
if (this.motion === "drag" && !this.pressed)
|
|
641
|
-
return false;
|
|
642
|
-
const btn = this.pressed ? this.button : 3;
|
|
643
|
-
const code = btn + mods + 32;
|
|
644
|
-
return this.sendMouse(code, col, row, pixel, false);
|
|
645
|
-
}
|
|
646
|
-
if (kind === "wheel") {
|
|
647
|
-
const delta = Math.sign(event.deltaY);
|
|
648
|
-
if (!delta)
|
|
649
|
-
return false;
|
|
650
|
-
const code = (delta < 0 ? 64 : 65) + mods;
|
|
651
|
-
return this.sendMouse(code, col, row, pixel, false);
|
|
652
|
-
}
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
updateFlags(code, enabled) {
|
|
656
|
-
if (!(code in this.flags))
|
|
657
|
-
return;
|
|
658
|
-
this.flags[code] = enabled;
|
|
659
|
-
this.enabled = this.x10Event || this.flags[1000] || this.flags[1002] || this.flags[1003];
|
|
660
|
-
if (this.flags[1003])
|
|
661
|
-
this.motion = "any";
|
|
662
|
-
else if (this.flags[1002])
|
|
663
|
-
this.motion = "drag";
|
|
664
|
-
else
|
|
665
|
-
this.motion = "none";
|
|
666
|
-
}
|
|
667
|
-
isX10EventMode() {
|
|
668
|
-
if (!this.x10Event)
|
|
669
|
-
return false;
|
|
670
|
-
return !(this.flags[1000] || this.flags[1002] || this.flags[1003]);
|
|
671
|
-
}
|
|
672
|
-
modifiers(event, enabled) {
|
|
673
|
-
if (!enabled)
|
|
674
|
-
return 0;
|
|
675
|
-
let mod = 0;
|
|
676
|
-
if (event.shiftKey)
|
|
677
|
-
mod |= 4;
|
|
678
|
-
if (event.altKey)
|
|
679
|
-
mod |= 8;
|
|
680
|
-
if (event.ctrlKey)
|
|
681
|
-
mod |= 16;
|
|
682
|
-
return mod;
|
|
683
|
-
}
|
|
684
|
-
sendMouse(code, col, row, pixel, release) {
|
|
685
|
-
if (this.format === "x10") {
|
|
686
|
-
if (col > 223 || row > 223)
|
|
687
|
-
return false;
|
|
688
|
-
const cb = 32 + code;
|
|
689
|
-
const cx = 32 + col;
|
|
690
|
-
const cy = 32 + row;
|
|
691
|
-
this.sendReply(`\x1B[M${String.fromCharCode(cb, cx, cy)}`);
|
|
692
|
-
return true;
|
|
693
|
-
}
|
|
694
|
-
if (this.format === "utf8") {
|
|
695
|
-
const cb = String.fromCharCode(32 + code);
|
|
696
|
-
const cx = String.fromCodePoint(32 + col);
|
|
697
|
-
const cy = String.fromCodePoint(32 + row);
|
|
698
|
-
this.sendReply(`\x1B[M${cb}${cx}${cy}`);
|
|
699
|
-
return true;
|
|
700
|
-
}
|
|
701
|
-
if (this.format === "urxvt") {
|
|
702
|
-
this.sendReply(`\x1B[${32 + code};${col};${row}M`);
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
const suffix = release ? "m" : "M";
|
|
706
|
-
if (this.format === "sgr_pixels" && pixel) {
|
|
707
|
-
this.sendReply(`\x1B[<${code};${pixel.x};${pixel.y}${suffix}`);
|
|
708
|
-
return true;
|
|
709
|
-
}
|
|
710
|
-
this.sendReply(`\x1B[<${code};${col};${row}${suffix}`);
|
|
711
|
-
return true;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// src/input/output.ts
|
|
716
|
-
var textDecoder = new TextDecoder;
|
|
717
|
-
var textEncoder = new TextEncoder;
|
|
718
|
-
function decodeBase64(data) {
|
|
719
|
-
if (!data)
|
|
720
|
-
return new Uint8Array;
|
|
721
|
-
const cleaned = data.replace(/\s+/g, "");
|
|
722
|
-
if (typeof atob === "function") {
|
|
723
|
-
const binary = atob(cleaned);
|
|
724
|
-
const bytes = new Uint8Array(binary.length);
|
|
725
|
-
for (let i = 0;i < binary.length; i += 1) {
|
|
726
|
-
bytes[i] = binary.charCodeAt(i) & 255;
|
|
727
|
-
}
|
|
728
|
-
return bytes;
|
|
729
|
-
}
|
|
730
|
-
if (typeof Buffer !== "undefined") {
|
|
731
|
-
return new Uint8Array(Buffer.from(cleaned, "base64"));
|
|
732
|
-
}
|
|
733
|
-
return new Uint8Array;
|
|
734
|
-
}
|
|
735
|
-
function encodeBase64(bytes) {
|
|
736
|
-
if (typeof btoa === "function") {
|
|
737
|
-
let binary = "";
|
|
738
|
-
const chunk = 32768;
|
|
739
|
-
for (let i = 0;i < bytes.length; i += chunk) {
|
|
740
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
741
|
-
}
|
|
742
|
-
return btoa(binary);
|
|
743
|
-
}
|
|
744
|
-
if (typeof Buffer !== "undefined") {
|
|
745
|
-
return Buffer.from(bytes).toString("base64");
|
|
746
|
-
}
|
|
747
|
-
return "";
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
class OutputFilter {
|
|
751
|
-
remainder = "";
|
|
752
|
-
getCursorPosition;
|
|
753
|
-
sendReply;
|
|
754
|
-
mouse;
|
|
755
|
-
altScreen = false;
|
|
756
|
-
bracketedPaste = false;
|
|
757
|
-
focusReporting = false;
|
|
758
|
-
synchronizedOutput = false;
|
|
759
|
-
windowOpHandler;
|
|
760
|
-
getWindowMetrics;
|
|
761
|
-
clipboardWrite;
|
|
762
|
-
clipboardRead;
|
|
763
|
-
getDefaultColors;
|
|
764
|
-
constructor(options) {
|
|
765
|
-
this.getCursorPosition = options.getCursorPosition;
|
|
766
|
-
this.sendReply = options.sendReply;
|
|
767
|
-
this.mouse = options.mouse;
|
|
768
|
-
this.getDefaultColors = options.getDefaultColors;
|
|
769
|
-
this.clipboardWrite = options.onClipboardWrite;
|
|
770
|
-
this.clipboardRead = options.onClipboardRead;
|
|
771
|
-
this.windowOpHandler = options.onWindowOp;
|
|
772
|
-
this.getWindowMetrics = options.getWindowMetrics;
|
|
773
|
-
}
|
|
774
|
-
setCursorProvider(fn) {
|
|
775
|
-
this.getCursorPosition = fn;
|
|
776
|
-
}
|
|
777
|
-
setReplySink(fn) {
|
|
778
|
-
this.sendReply = fn;
|
|
779
|
-
}
|
|
780
|
-
setWindowOpHandler(fn) {
|
|
781
|
-
this.windowOpHandler = fn;
|
|
782
|
-
}
|
|
783
|
-
isAltScreen() {
|
|
784
|
-
return this.altScreen;
|
|
785
|
-
}
|
|
786
|
-
isBracketedPaste() {
|
|
787
|
-
return this.bracketedPaste;
|
|
788
|
-
}
|
|
789
|
-
isFocusReporting() {
|
|
790
|
-
return this.focusReporting;
|
|
791
|
-
}
|
|
792
|
-
isSynchronizedOutput() {
|
|
793
|
-
return this.synchronizedOutput;
|
|
794
|
-
}
|
|
795
|
-
replyOscColor(code, rgb) {
|
|
796
|
-
const toHex4 = (value) => Math.round(Math.max(0, Math.min(255, value)) * 257).toString(16).padStart(4, "0");
|
|
797
|
-
const r = toHex4(rgb[0]);
|
|
798
|
-
const g = toHex4(rgb[1]);
|
|
799
|
-
const b = toHex4(rgb[2]);
|
|
800
|
-
this.sendReply(`\x1B]${code};rgb:${r}/${g}/${b}\x07`);
|
|
801
|
-
}
|
|
802
|
-
handleOsc(seq) {
|
|
803
|
-
const content = seq.slice(2);
|
|
804
|
-
const parts = content.split(";");
|
|
805
|
-
const code = parts[0] ?? "";
|
|
806
|
-
if (code === "52") {
|
|
807
|
-
const target = parts[1] ?? "c";
|
|
808
|
-
const payload = parts.slice(2).join(";");
|
|
809
|
-
if (payload === "?") {
|
|
810
|
-
if (!this.clipboardRead)
|
|
811
|
-
return true;
|
|
812
|
-
Promise.resolve(this.clipboardRead()).then((text2) => {
|
|
813
|
-
const safeText = text2 ?? "";
|
|
814
|
-
const bytes2 = textEncoder.encode(safeText);
|
|
815
|
-
const encoded = encodeBase64(bytes2);
|
|
816
|
-
this.sendReply(`\x1B]52;${target};${encoded}\x07`);
|
|
817
|
-
}).catch(() => {});
|
|
818
|
-
return true;
|
|
819
|
-
}
|
|
820
|
-
if (!this.clipboardWrite)
|
|
821
|
-
return true;
|
|
822
|
-
const bytes = decodeBase64(payload);
|
|
823
|
-
const text = textDecoder.decode(bytes);
|
|
824
|
-
Promise.resolve(this.clipboardWrite(text)).catch(() => {});
|
|
825
|
-
return true;
|
|
826
|
-
}
|
|
827
|
-
const param = parts[1];
|
|
828
|
-
if (param !== "?")
|
|
829
|
-
return false;
|
|
830
|
-
const colors = this.getDefaultColors?.();
|
|
831
|
-
if (!colors)
|
|
832
|
-
return false;
|
|
833
|
-
if (code === "10" && colors.fg) {
|
|
834
|
-
this.replyOscColor(code, colors.fg);
|
|
835
|
-
return true;
|
|
836
|
-
}
|
|
837
|
-
if (code === "11" && colors.bg) {
|
|
838
|
-
this.replyOscColor(code, colors.bg);
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
if (code === "12" && colors.cursor) {
|
|
842
|
-
this.replyOscColor(code, colors.cursor);
|
|
843
|
-
return true;
|
|
844
|
-
}
|
|
845
|
-
return false;
|
|
846
|
-
}
|
|
847
|
-
handleModeSeq(seq) {
|
|
848
|
-
const mode = parsePrivateModeSeq(seq);
|
|
849
|
-
if (!mode)
|
|
850
|
-
return false;
|
|
851
|
-
const { enabled, codes } = mode;
|
|
852
|
-
let handled = false;
|
|
853
|
-
for (const code of codes) {
|
|
854
|
-
if (code === 2004) {
|
|
855
|
-
this.bracketedPaste = enabled;
|
|
856
|
-
handled = true;
|
|
857
|
-
} else if (code === 1004) {
|
|
858
|
-
this.focusReporting = enabled;
|
|
859
|
-
handled = true;
|
|
860
|
-
} else if (code === 2026) {
|
|
861
|
-
this.synchronizedOutput = enabled;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
return handled;
|
|
865
|
-
}
|
|
866
|
-
handleWindowOp(seq) {
|
|
867
|
-
const params = parseWindowOpSeq(seq);
|
|
868
|
-
if (!params)
|
|
869
|
-
return false;
|
|
870
|
-
const op = params[0] ?? 0;
|
|
871
|
-
const metrics = this.getWindowMetrics?.();
|
|
872
|
-
if (metrics && op === 14 && params.length === 1) {
|
|
873
|
-
this.sendReply(`\x1B[4;${metrics.heightPx};${metrics.widthPx}t`);
|
|
874
|
-
return true;
|
|
875
|
-
}
|
|
876
|
-
if (metrics && op === 16 && params.length === 1) {
|
|
877
|
-
this.sendReply(`\x1B[6;${metrics.cellHeightPx};${metrics.cellWidthPx}t`);
|
|
878
|
-
return true;
|
|
879
|
-
}
|
|
880
|
-
if (metrics && op === 18 && params.length === 1) {
|
|
881
|
-
this.sendReply(`\x1B[8;${metrics.rows};${metrics.cols}t`);
|
|
882
|
-
return true;
|
|
883
|
-
}
|
|
884
|
-
if (!this.windowOpHandler)
|
|
885
|
-
return false;
|
|
886
|
-
if (params[0] === 8 && params.length >= 3) {
|
|
887
|
-
this.windowOpHandler({
|
|
888
|
-
type: "resize",
|
|
889
|
-
rows: params[1] ?? 0,
|
|
890
|
-
cols: params[2] ?? 0,
|
|
891
|
-
params,
|
|
892
|
-
raw: seq
|
|
893
|
-
});
|
|
894
|
-
} else {
|
|
895
|
-
this.windowOpHandler({ type: "unknown", params, raw: seq });
|
|
896
|
-
}
|
|
897
|
-
return true;
|
|
898
|
-
}
|
|
899
|
-
filter(output) {
|
|
900
|
-
if (!output)
|
|
901
|
-
return output;
|
|
902
|
-
let data = this.remainder + output;
|
|
903
|
-
this.remainder = "";
|
|
904
|
-
let result = "";
|
|
905
|
-
let i = 0;
|
|
906
|
-
while (i < data.length) {
|
|
907
|
-
const ch = data[i];
|
|
908
|
-
if (ch !== "\x1B") {
|
|
909
|
-
result += ch;
|
|
910
|
-
i += 1;
|
|
911
|
-
continue;
|
|
912
|
-
}
|
|
913
|
-
if (i + 1 >= data.length) {
|
|
914
|
-
this.remainder = data.slice(i);
|
|
915
|
-
break;
|
|
916
|
-
}
|
|
917
|
-
if (data[i + 1] === "]") {
|
|
918
|
-
let j2 = i + 2;
|
|
919
|
-
let terminatorLen = 0;
|
|
920
|
-
while (j2 < data.length) {
|
|
921
|
-
const code = data.charCodeAt(j2);
|
|
922
|
-
if (code === 7) {
|
|
923
|
-
terminatorLen = 1;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
if (code === 27 && j2 + 1 < data.length && data[j2 + 1] === "\\") {
|
|
927
|
-
terminatorLen = 2;
|
|
928
|
-
break;
|
|
929
|
-
}
|
|
930
|
-
j2 += 1;
|
|
931
|
-
}
|
|
932
|
-
if (!terminatorLen) {
|
|
933
|
-
this.remainder = data.slice(i);
|
|
934
|
-
break;
|
|
935
|
-
}
|
|
936
|
-
const seq2 = data.slice(i, j2);
|
|
937
|
-
if (!this.handleOsc(seq2)) {
|
|
938
|
-
result += data.slice(i, j2 + terminatorLen);
|
|
939
|
-
}
|
|
940
|
-
i = j2 + terminatorLen;
|
|
941
|
-
continue;
|
|
942
|
-
}
|
|
943
|
-
if (data[i + 1] !== "[") {
|
|
944
|
-
result += ch;
|
|
945
|
-
i += 1;
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
let j = i + 2;
|
|
949
|
-
while (j < data.length) {
|
|
950
|
-
const code = data.charCodeAt(j);
|
|
951
|
-
if (code >= 64 && code <= 126)
|
|
952
|
-
break;
|
|
953
|
-
j += 1;
|
|
954
|
-
}
|
|
955
|
-
if (j >= data.length) {
|
|
956
|
-
this.remainder = data.slice(i);
|
|
957
|
-
break;
|
|
958
|
-
}
|
|
959
|
-
const seq = data.slice(i, j + 1);
|
|
960
|
-
const altMode = parsePrivateModeSeq(seq);
|
|
961
|
-
if (altMode) {
|
|
962
|
-
const { enabled, codes } = altMode;
|
|
963
|
-
if (codes.some((code) => code === 47 || code === 1047 || code === 1049)) {
|
|
964
|
-
this.altScreen = enabled;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
const mouseHandled = this.mouse.handleModeSeq(seq);
|
|
968
|
-
const modeHandled = this.handleModeSeq(seq);
|
|
969
|
-
if (mouseHandled || modeHandled) {
|
|
970
|
-
i = j + 1;
|
|
971
|
-
continue;
|
|
972
|
-
}
|
|
973
|
-
if (seq.endsWith("t") && this.handleWindowOp(seq)) {
|
|
974
|
-
i = j + 1;
|
|
975
|
-
continue;
|
|
976
|
-
}
|
|
977
|
-
if (seq === "\x1B[6n") {
|
|
978
|
-
const { row, col } = this.getCursorPosition();
|
|
979
|
-
this.sendReply(`\x1B[${row};${col}R`);
|
|
980
|
-
} else if (seq === "\x1B[>q") {
|
|
981
|
-
this.sendReply("\x1BP>|ghostty 1.0\x1B\\");
|
|
982
|
-
} else if (isDeviceAttributesQuery(seq)) {
|
|
983
|
-
this.sendReply("\x1B[?1;2c");
|
|
984
|
-
} else {
|
|
985
|
-
result += seq;
|
|
986
|
-
}
|
|
987
|
-
i = j + 1;
|
|
988
|
-
}
|
|
989
|
-
return result;
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
// src/input/index.ts
|
|
994
|
-
function createInputHandler(options = {}) {
|
|
995
|
-
const config = options.config || {};
|
|
996
|
-
const cursorProvider = options.getCursorPosition || (() => ({ row: 1, col: 1 }));
|
|
997
|
-
const replySink = options.sendReply || (() => {});
|
|
998
|
-
const positionToCell = options.positionToCell || (() => ({ row: 0, col: 0 }));
|
|
999
|
-
const positionToPixel = options.positionToPixel || null;
|
|
1000
|
-
const mouse = new MouseController({
|
|
1001
|
-
sendReply: replySink,
|
|
1002
|
-
positionToCell,
|
|
1003
|
-
positionToPixel: positionToPixel ?? undefined
|
|
1004
|
-
});
|
|
1005
|
-
const filter = new OutputFilter({
|
|
1006
|
-
getCursorPosition: cursorProvider,
|
|
1007
|
-
sendReply: replySink,
|
|
1008
|
-
mouse,
|
|
1009
|
-
getDefaultColors: options.getDefaultColors,
|
|
1010
|
-
onClipboardRead: options.onClipboardRead,
|
|
1011
|
-
onClipboardWrite: options.onClipboardWrite,
|
|
1012
|
-
onWindowOp: options.onWindowOp,
|
|
1013
|
-
getWindowMetrics: options.getWindowMetrics
|
|
1014
|
-
});
|
|
1015
|
-
return {
|
|
1016
|
-
sequences,
|
|
1017
|
-
encodeKeyEvent: (event) => encodeKeyEvent(event, config, options.getKittyKeyboardFlags?.() ?? 0),
|
|
1018
|
-
encodeBeforeInput,
|
|
1019
|
-
mapKeyForPty,
|
|
1020
|
-
filterOutput: (output) => filter.filter(output),
|
|
1021
|
-
setReplySink: (fn) => {
|
|
1022
|
-
mouse.setReplySink(fn);
|
|
1023
|
-
filter.setReplySink(fn);
|
|
1024
|
-
},
|
|
1025
|
-
setCursorProvider: (fn) => {
|
|
1026
|
-
filter.setCursorProvider(fn);
|
|
1027
|
-
},
|
|
1028
|
-
setPositionToCell: (fn) => {
|
|
1029
|
-
mouse.setPositionToCell(fn);
|
|
1030
|
-
},
|
|
1031
|
-
setPositionToPixel: (fn) => {
|
|
1032
|
-
mouse.setPositionToPixel(fn);
|
|
1033
|
-
},
|
|
1034
|
-
setWindowOpHandler: (fn) => {
|
|
1035
|
-
filter.setWindowOpHandler(fn);
|
|
1036
|
-
},
|
|
1037
|
-
setMouseMode: (mode) => {
|
|
1038
|
-
mouse.setMode(mode);
|
|
1039
|
-
},
|
|
1040
|
-
getMouseStatus: () => mouse.getStatus(),
|
|
1041
|
-
isMouseActive: () => mouse.isActive(),
|
|
1042
|
-
isBracketedPaste: () => filter.isBracketedPaste(),
|
|
1043
|
-
isFocusReporting: () => filter.isFocusReporting(),
|
|
1044
|
-
isAltScreen: () => filter.isAltScreen(),
|
|
1045
|
-
isSynchronizedOutput: () => filter.isSynchronizedOutput(),
|
|
1046
|
-
sendMouseEvent: (kind, event) => mouse.sendMouseEvent(kind, event)
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
export {
|
|
1050
|
-
createInputHandler
|
|
1051
|
-
};
|