@boba-cli/tea 0.1.0-alpha.1
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 +260 -0
- package/dist/index.cjs +1125 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +337 -0
- package/dist/index.d.ts +337 -0
- package/dist/index.js +1085 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var machine = require('@boba-cli/machine');
|
|
4
|
+
|
|
5
|
+
// src/input.ts
|
|
6
|
+
|
|
7
|
+
// src/messages.ts
|
|
8
|
+
var QuitMsg = class {
|
|
9
|
+
_tag = "quit";
|
|
10
|
+
};
|
|
11
|
+
var InterruptMsg = class {
|
|
12
|
+
_tag = "interrupt";
|
|
13
|
+
};
|
|
14
|
+
var SuspendMsg = class {
|
|
15
|
+
_tag = "suspend";
|
|
16
|
+
};
|
|
17
|
+
var ResumeMsg = class {
|
|
18
|
+
_tag = "resume";
|
|
19
|
+
};
|
|
20
|
+
var WindowSizeMsg = class {
|
|
21
|
+
constructor(width, height) {
|
|
22
|
+
this.width = width;
|
|
23
|
+
this.height = height;
|
|
24
|
+
}
|
|
25
|
+
_tag = "window-size";
|
|
26
|
+
};
|
|
27
|
+
var FocusMsg = class {
|
|
28
|
+
_tag = "focus";
|
|
29
|
+
};
|
|
30
|
+
var BlurMsg = class {
|
|
31
|
+
_tag = "blur";
|
|
32
|
+
};
|
|
33
|
+
var ClearScreenMsg = class {
|
|
34
|
+
_tag = "clear-screen";
|
|
35
|
+
};
|
|
36
|
+
var EnterAltScreenMsg = class {
|
|
37
|
+
_tag = "enter-alt-screen";
|
|
38
|
+
};
|
|
39
|
+
var ExitAltScreenMsg = class {
|
|
40
|
+
_tag = "exit-alt-screen";
|
|
41
|
+
};
|
|
42
|
+
var EnableMouseCellMotionMsg = class {
|
|
43
|
+
_tag = "enable-mouse-cell-motion";
|
|
44
|
+
};
|
|
45
|
+
var EnableMouseAllMotionMsg = class {
|
|
46
|
+
_tag = "enable-mouse-all-motion";
|
|
47
|
+
};
|
|
48
|
+
var DisableMouseMsg = class {
|
|
49
|
+
_tag = "disable-mouse";
|
|
50
|
+
};
|
|
51
|
+
var ShowCursorMsg = class {
|
|
52
|
+
_tag = "show-cursor";
|
|
53
|
+
};
|
|
54
|
+
var HideCursorMsg = class {
|
|
55
|
+
_tag = "hide-cursor";
|
|
56
|
+
};
|
|
57
|
+
var EnableReportFocusMsg = class {
|
|
58
|
+
_tag = "enable-report-focus";
|
|
59
|
+
};
|
|
60
|
+
var DisableReportFocusMsg = class {
|
|
61
|
+
_tag = "disable-report-focus";
|
|
62
|
+
};
|
|
63
|
+
var SetWindowTitleMsg = class {
|
|
64
|
+
constructor(title) {
|
|
65
|
+
this.title = title;
|
|
66
|
+
}
|
|
67
|
+
_tag = "set-window-title";
|
|
68
|
+
};
|
|
69
|
+
var KeyType = /* @__PURE__ */ ((KeyType2) => {
|
|
70
|
+
KeyType2["Null"] = "null";
|
|
71
|
+
KeyType2["Break"] = "break";
|
|
72
|
+
KeyType2["Enter"] = "enter";
|
|
73
|
+
KeyType2["Backspace"] = "backspace";
|
|
74
|
+
KeyType2["Tab"] = "tab";
|
|
75
|
+
KeyType2["Esc"] = "esc";
|
|
76
|
+
KeyType2["Space"] = "space";
|
|
77
|
+
KeyType2["Runes"] = "runes";
|
|
78
|
+
KeyType2["Up"] = "up";
|
|
79
|
+
KeyType2["Down"] = "down";
|
|
80
|
+
KeyType2["Right"] = "right";
|
|
81
|
+
KeyType2["Left"] = "left";
|
|
82
|
+
KeyType2["ShiftTab"] = "shift+tab";
|
|
83
|
+
KeyType2["Home"] = "home";
|
|
84
|
+
KeyType2["End"] = "end";
|
|
85
|
+
KeyType2["PgUp"] = "pgup";
|
|
86
|
+
KeyType2["PgDown"] = "pgdown";
|
|
87
|
+
KeyType2["CtrlPgUp"] = "ctrl+pgup";
|
|
88
|
+
KeyType2["CtrlPgDown"] = "ctrl+pgdown";
|
|
89
|
+
KeyType2["Delete"] = "delete";
|
|
90
|
+
KeyType2["Insert"] = "insert";
|
|
91
|
+
KeyType2["CtrlUp"] = "ctrl+up";
|
|
92
|
+
KeyType2["CtrlDown"] = "ctrl+down";
|
|
93
|
+
KeyType2["CtrlRight"] = "ctrl+right";
|
|
94
|
+
KeyType2["CtrlLeft"] = "ctrl+left";
|
|
95
|
+
KeyType2["CtrlHome"] = "ctrl+home";
|
|
96
|
+
KeyType2["CtrlEnd"] = "ctrl+end";
|
|
97
|
+
KeyType2["ShiftUp"] = "shift+up";
|
|
98
|
+
KeyType2["ShiftDown"] = "shift+down";
|
|
99
|
+
KeyType2["ShiftRight"] = "shift+right";
|
|
100
|
+
KeyType2["ShiftLeft"] = "shift+left";
|
|
101
|
+
KeyType2["ShiftHome"] = "shift+home";
|
|
102
|
+
KeyType2["ShiftEnd"] = "shift+end";
|
|
103
|
+
KeyType2["CtrlShiftUp"] = "ctrl+shift+up";
|
|
104
|
+
KeyType2["CtrlShiftDown"] = "ctrl+shift+down";
|
|
105
|
+
KeyType2["CtrlShiftLeft"] = "ctrl+shift+left";
|
|
106
|
+
KeyType2["CtrlShiftRight"] = "ctrl+shift+right";
|
|
107
|
+
KeyType2["CtrlShiftHome"] = "ctrl+shift+home";
|
|
108
|
+
KeyType2["CtrlShiftEnd"] = "ctrl+shift+end";
|
|
109
|
+
KeyType2["F1"] = "f1";
|
|
110
|
+
KeyType2["F2"] = "f2";
|
|
111
|
+
KeyType2["F3"] = "f3";
|
|
112
|
+
KeyType2["F4"] = "f4";
|
|
113
|
+
KeyType2["F5"] = "f5";
|
|
114
|
+
KeyType2["F6"] = "f6";
|
|
115
|
+
KeyType2["F7"] = "f7";
|
|
116
|
+
KeyType2["F8"] = "f8";
|
|
117
|
+
KeyType2["F9"] = "f9";
|
|
118
|
+
KeyType2["F10"] = "f10";
|
|
119
|
+
KeyType2["F11"] = "f11";
|
|
120
|
+
KeyType2["F12"] = "f12";
|
|
121
|
+
KeyType2["F13"] = "f13";
|
|
122
|
+
KeyType2["F14"] = "f14";
|
|
123
|
+
KeyType2["F15"] = "f15";
|
|
124
|
+
KeyType2["F16"] = "f16";
|
|
125
|
+
KeyType2["F17"] = "f17";
|
|
126
|
+
KeyType2["F18"] = "f18";
|
|
127
|
+
KeyType2["F19"] = "f19";
|
|
128
|
+
KeyType2["F20"] = "f20";
|
|
129
|
+
return KeyType2;
|
|
130
|
+
})(KeyType || {});
|
|
131
|
+
var keyNames = {
|
|
132
|
+
["null" /* Null */]: "ctrl+@",
|
|
133
|
+
["break" /* Break */]: "ctrl+c",
|
|
134
|
+
["enter" /* Enter */]: "enter",
|
|
135
|
+
["backspace" /* Backspace */]: "backspace",
|
|
136
|
+
["tab" /* Tab */]: "tab",
|
|
137
|
+
["esc" /* Esc */]: "esc",
|
|
138
|
+
["space" /* Space */]: " ",
|
|
139
|
+
["runes" /* Runes */]: "runes",
|
|
140
|
+
["up" /* Up */]: "up",
|
|
141
|
+
["down" /* Down */]: "down",
|
|
142
|
+
["right" /* Right */]: "right",
|
|
143
|
+
["left" /* Left */]: "left",
|
|
144
|
+
["shift+tab" /* ShiftTab */]: "shift+tab",
|
|
145
|
+
["home" /* Home */]: "home",
|
|
146
|
+
["end" /* End */]: "end",
|
|
147
|
+
["pgup" /* PgUp */]: "pgup",
|
|
148
|
+
["pgdown" /* PgDown */]: "pgdown",
|
|
149
|
+
["ctrl+pgup" /* CtrlPgUp */]: "ctrl+pgup",
|
|
150
|
+
["ctrl+pgdown" /* CtrlPgDown */]: "ctrl+pgdown",
|
|
151
|
+
["delete" /* Delete */]: "delete",
|
|
152
|
+
["insert" /* Insert */]: "insert",
|
|
153
|
+
["ctrl+up" /* CtrlUp */]: "ctrl+up",
|
|
154
|
+
["ctrl+down" /* CtrlDown */]: "ctrl+down",
|
|
155
|
+
["ctrl+right" /* CtrlRight */]: "ctrl+right",
|
|
156
|
+
["ctrl+left" /* CtrlLeft */]: "ctrl+left",
|
|
157
|
+
["ctrl+home" /* CtrlHome */]: "ctrl+home",
|
|
158
|
+
["ctrl+end" /* CtrlEnd */]: "ctrl+end",
|
|
159
|
+
["shift+up" /* ShiftUp */]: "shift+up",
|
|
160
|
+
["shift+down" /* ShiftDown */]: "shift+down",
|
|
161
|
+
["shift+right" /* ShiftRight */]: "shift+right",
|
|
162
|
+
["shift+left" /* ShiftLeft */]: "shift+left",
|
|
163
|
+
["shift+home" /* ShiftHome */]: "shift+home",
|
|
164
|
+
["shift+end" /* ShiftEnd */]: "shift+end",
|
|
165
|
+
["ctrl+shift+up" /* CtrlShiftUp */]: "ctrl+shift+up",
|
|
166
|
+
["ctrl+shift+down" /* CtrlShiftDown */]: "ctrl+shift+down",
|
|
167
|
+
["ctrl+shift+left" /* CtrlShiftLeft */]: "ctrl+shift+left",
|
|
168
|
+
["ctrl+shift+right" /* CtrlShiftRight */]: "ctrl+shift+right",
|
|
169
|
+
["ctrl+shift+home" /* CtrlShiftHome */]: "ctrl+shift+home",
|
|
170
|
+
["ctrl+shift+end" /* CtrlShiftEnd */]: "ctrl+shift+end",
|
|
171
|
+
["f1" /* F1 */]: "f1",
|
|
172
|
+
["f2" /* F2 */]: "f2",
|
|
173
|
+
["f3" /* F3 */]: "f3",
|
|
174
|
+
["f4" /* F4 */]: "f4",
|
|
175
|
+
["f5" /* F5 */]: "f5",
|
|
176
|
+
["f6" /* F6 */]: "f6",
|
|
177
|
+
["f7" /* F7 */]: "f7",
|
|
178
|
+
["f8" /* F8 */]: "f8",
|
|
179
|
+
["f9" /* F9 */]: "f9",
|
|
180
|
+
["f10" /* F10 */]: "f10",
|
|
181
|
+
["f11" /* F11 */]: "f11",
|
|
182
|
+
["f12" /* F12 */]: "f12",
|
|
183
|
+
["f13" /* F13 */]: "f13",
|
|
184
|
+
["f14" /* F14 */]: "f14",
|
|
185
|
+
["f15" /* F15 */]: "f15",
|
|
186
|
+
["f16" /* F16 */]: "f16",
|
|
187
|
+
["f17" /* F17 */]: "f17",
|
|
188
|
+
["f18" /* F18 */]: "f18",
|
|
189
|
+
["f19" /* F19 */]: "f19",
|
|
190
|
+
["f20" /* F20 */]: "f20"
|
|
191
|
+
};
|
|
192
|
+
var controlKeyMap = {
|
|
193
|
+
0: "null" /* Null */,
|
|
194
|
+
3: "break" /* Break */,
|
|
195
|
+
9: "tab" /* Tab */,
|
|
196
|
+
10: "enter" /* Enter */,
|
|
197
|
+
13: "enter" /* Enter */,
|
|
198
|
+
27: "esc" /* Esc */,
|
|
199
|
+
127: "backspace" /* Backspace */
|
|
200
|
+
};
|
|
201
|
+
var sequences = [
|
|
202
|
+
["\x1B[A", { type: "up" /* Up */, runes: "", alt: false, paste: false }],
|
|
203
|
+
["\x1B[B", { type: "down" /* Down */, runes: "", alt: false, paste: false }],
|
|
204
|
+
["\x1B[C", { type: "right" /* Right */, runes: "", alt: false, paste: false }],
|
|
205
|
+
["\x1B[D", { type: "left" /* Left */, runes: "", alt: false, paste: false }],
|
|
206
|
+
["\x1B[Z", { type: "shift+tab" /* ShiftTab */, runes: "", alt: false, paste: false }],
|
|
207
|
+
["\x1B[2~", { type: "insert" /* Insert */, runes: "", alt: false, paste: false }],
|
|
208
|
+
["\x1B[3~", { type: "delete" /* Delete */, runes: "", alt: false, paste: false }],
|
|
209
|
+
["\x1B[5~", { type: "pgup" /* PgUp */, runes: "", alt: false, paste: false }],
|
|
210
|
+
["\x1B[6~", { type: "pgdown" /* PgDown */, runes: "", alt: false, paste: false }],
|
|
211
|
+
["\x1B[1~", { type: "home" /* Home */, runes: "", alt: false, paste: false }],
|
|
212
|
+
["\x1B[4~", { type: "end" /* End */, runes: "", alt: false, paste: false }],
|
|
213
|
+
["\x1B[H", { type: "home" /* Home */, runes: "", alt: false, paste: false }],
|
|
214
|
+
["\x1B[F", { type: "end" /* End */, runes: "", alt: false, paste: false }],
|
|
215
|
+
["\x1BOP", { type: "f1" /* F1 */, runes: "", alt: false, paste: false }],
|
|
216
|
+
["\x1BOQ", { type: "f2" /* F2 */, runes: "", alt: false, paste: false }],
|
|
217
|
+
["\x1BOR", { type: "f3" /* F3 */, runes: "", alt: false, paste: false }],
|
|
218
|
+
["\x1BOS", { type: "f4" /* F4 */, runes: "", alt: false, paste: false }],
|
|
219
|
+
["\x1B[15~", { type: "f5" /* F5 */, runes: "", alt: false, paste: false }],
|
|
220
|
+
["\x1B[17~", { type: "f6" /* F6 */, runes: "", alt: false, paste: false }],
|
|
221
|
+
["\x1B[18~", { type: "f7" /* F7 */, runes: "", alt: false, paste: false }],
|
|
222
|
+
["\x1B[19~", { type: "f8" /* F8 */, runes: "", alt: false, paste: false }],
|
|
223
|
+
["\x1B[20~", { type: "f9" /* F9 */, runes: "", alt: false, paste: false }],
|
|
224
|
+
["\x1B[21~", { type: "f10" /* F10 */, runes: "", alt: false, paste: false }],
|
|
225
|
+
["\x1B[23~", { type: "f11" /* F11 */, runes: "", alt: false, paste: false }],
|
|
226
|
+
["\x1B[24~", { type: "f12" /* F12 */, runes: "", alt: false, paste: false }],
|
|
227
|
+
[
|
|
228
|
+
"\x1B[1;2A",
|
|
229
|
+
{ type: "shift+up" /* ShiftUp */, runes: "", alt: false, paste: false }
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
"\x1B[1;2B",
|
|
233
|
+
{ type: "shift+down" /* ShiftDown */, runes: "", alt: false, paste: false }
|
|
234
|
+
],
|
|
235
|
+
[
|
|
236
|
+
"\x1B[1;2C",
|
|
237
|
+
{ type: "shift+right" /* ShiftRight */, runes: "", alt: false, paste: false }
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
"\x1B[1;2D",
|
|
241
|
+
{ type: "shift+left" /* ShiftLeft */, runes: "", alt: false, paste: false }
|
|
242
|
+
],
|
|
243
|
+
[
|
|
244
|
+
"\x1B[1;5A",
|
|
245
|
+
{ type: "ctrl+up" /* CtrlUp */, runes: "", alt: false, paste: false }
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
"\x1B[1;5B",
|
|
249
|
+
{ type: "ctrl+down" /* CtrlDown */, runes: "", alt: false, paste: false }
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"\x1B[1;5C",
|
|
253
|
+
{ type: "ctrl+right" /* CtrlRight */, runes: "", alt: false, paste: false }
|
|
254
|
+
],
|
|
255
|
+
[
|
|
256
|
+
"\x1B[1;5D",
|
|
257
|
+
{ type: "ctrl+left" /* CtrlLeft */, runes: "", alt: false, paste: false }
|
|
258
|
+
],
|
|
259
|
+
[
|
|
260
|
+
"\x1B[1;6A",
|
|
261
|
+
{ type: "ctrl+shift+up" /* CtrlShiftUp */, runes: "", alt: false, paste: false }
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
"\x1B[1;6B",
|
|
265
|
+
{ type: "ctrl+shift+down" /* CtrlShiftDown */, runes: "", alt: false, paste: false }
|
|
266
|
+
],
|
|
267
|
+
[
|
|
268
|
+
"\x1B[1;6C",
|
|
269
|
+
{ type: "ctrl+shift+right" /* CtrlShiftRight */, runes: "", alt: false, paste: false }
|
|
270
|
+
],
|
|
271
|
+
[
|
|
272
|
+
"\x1B[1;6D",
|
|
273
|
+
{ type: "ctrl+shift+left" /* CtrlShiftLeft */, runes: "", alt: false, paste: false }
|
|
274
|
+
],
|
|
275
|
+
["\x1B[1;3A", { type: "up" /* Up */, runes: "", alt: true, paste: false }],
|
|
276
|
+
["\x1B[1;3B", { type: "down" /* Down */, runes: "", alt: true, paste: false }],
|
|
277
|
+
["\x1B[1;3C", { type: "right" /* Right */, runes: "", alt: true, paste: false }],
|
|
278
|
+
["\x1B[1;3D", { type: "left" /* Left */, runes: "", alt: true, paste: false }],
|
|
279
|
+
[
|
|
280
|
+
"\x1B[5;5~",
|
|
281
|
+
{ type: "ctrl+pgup" /* CtrlPgUp */, runes: "", alt: false, paste: false }
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
"\x1B[6;5~",
|
|
285
|
+
{ type: "ctrl+pgdown" /* CtrlPgDown */, runes: "", alt: false, paste: false }
|
|
286
|
+
],
|
|
287
|
+
["\x1B[5;3~", { type: "pgup" /* PgUp */, runes: "", alt: true, paste: false }],
|
|
288
|
+
["\x1B[6;3~", { type: "pgdown" /* PgDown */, runes: "", alt: true, paste: false }],
|
|
289
|
+
["\x1B[3;2~", { type: "insert" /* Insert */, runes: "", alt: true, paste: false }],
|
|
290
|
+
["\x1B[3;3~", { type: "delete" /* Delete */, runes: "", alt: true, paste: false }],
|
|
291
|
+
["\x1B[[A", { type: "f1" /* F1 */, runes: "", alt: false, paste: false }],
|
|
292
|
+
["\x1B[[B", { type: "f2" /* F2 */, runes: "", alt: false, paste: false }],
|
|
293
|
+
["\x1B[[C", { type: "f3" /* F3 */, runes: "", alt: false, paste: false }],
|
|
294
|
+
["\x1B[[D", { type: "f4" /* F4 */, runes: "", alt: false, paste: false }],
|
|
295
|
+
["\x1B[[E", { type: "f5" /* F5 */, runes: "", alt: false, paste: false }]
|
|
296
|
+
];
|
|
297
|
+
var KeyMsg = class {
|
|
298
|
+
constructor(key) {
|
|
299
|
+
this.key = key;
|
|
300
|
+
}
|
|
301
|
+
_tag = "key";
|
|
302
|
+
toString() {
|
|
303
|
+
return keyToString(this.key);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
function keyToString(key) {
|
|
307
|
+
if (key.type === "runes" /* Runes */) {
|
|
308
|
+
const value = key.paste ? `[${key.runes}]` : key.runes;
|
|
309
|
+
return key.alt ? `alt+${value}` : value;
|
|
310
|
+
}
|
|
311
|
+
const base = keyNames[key.type] ?? "";
|
|
312
|
+
return key.alt ? `alt+${base}` : base;
|
|
313
|
+
}
|
|
314
|
+
function parseKey(buffer, allowMoreData) {
|
|
315
|
+
if (buffer.length === 0) {
|
|
316
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
317
|
+
}
|
|
318
|
+
const input = machine.decodeString(buffer);
|
|
319
|
+
for (const [seq, key] of sequences) {
|
|
320
|
+
if (input.startsWith(seq)) {
|
|
321
|
+
return { key, length: machine.byteLength(seq) };
|
|
322
|
+
}
|
|
323
|
+
if (allowMoreData && seq.startsWith(input)) {
|
|
324
|
+
return { needMore: true };
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (buffer[0] === 27 && buffer.length > 1) {
|
|
328
|
+
const [rune2, altLength] = machine.decodeFirstRune(buffer, 1);
|
|
329
|
+
if (altLength > 0 && rune2 !== null) {
|
|
330
|
+
return {
|
|
331
|
+
key: { type: "runes" /* Runes */, runes: rune2, alt: true, paste: false },
|
|
332
|
+
length: 1 + altLength
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const code = buffer[0] ?? 0;
|
|
337
|
+
const mapped = Object.prototype.hasOwnProperty.call(
|
|
338
|
+
controlKeyMap,
|
|
339
|
+
code
|
|
340
|
+
) ? controlKeyMap[code] : void 0;
|
|
341
|
+
if (mapped !== void 0) {
|
|
342
|
+
return {
|
|
343
|
+
key: { type: mapped, runes: "", alt: false, paste: false },
|
|
344
|
+
length: 1
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const [rune, runeLength] = machine.decodeFirstRune(buffer);
|
|
348
|
+
if (runeLength === 0 || rune === null) {
|
|
349
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
350
|
+
}
|
|
351
|
+
if (rune === " ") {
|
|
352
|
+
return {
|
|
353
|
+
key: { type: "space" /* Space */, runes: rune, alt: false, paste: false },
|
|
354
|
+
length: runeLength
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
key: { type: "runes" /* Runes */, runes: rune, alt: false, paste: false },
|
|
359
|
+
length: runeLength
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
var MouseAction = /* @__PURE__ */ ((MouseAction2) => {
|
|
363
|
+
MouseAction2["Press"] = "press";
|
|
364
|
+
MouseAction2["Release"] = "release";
|
|
365
|
+
MouseAction2["Motion"] = "motion";
|
|
366
|
+
return MouseAction2;
|
|
367
|
+
})(MouseAction || {});
|
|
368
|
+
var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
|
|
369
|
+
MouseButton2["None"] = "none";
|
|
370
|
+
MouseButton2["Left"] = "left";
|
|
371
|
+
MouseButton2["Middle"] = "middle";
|
|
372
|
+
MouseButton2["Right"] = "right";
|
|
373
|
+
MouseButton2["WheelUp"] = "wheel-up";
|
|
374
|
+
MouseButton2["WheelDown"] = "wheel-down";
|
|
375
|
+
MouseButton2["WheelLeft"] = "wheel-left";
|
|
376
|
+
MouseButton2["WheelRight"] = "wheel-right";
|
|
377
|
+
MouseButton2["Backward"] = "backward";
|
|
378
|
+
MouseButton2["Forward"] = "forward";
|
|
379
|
+
MouseButton2["Button10"] = "button-10";
|
|
380
|
+
MouseButton2["Button11"] = "button-11";
|
|
381
|
+
return MouseButton2;
|
|
382
|
+
})(MouseButton || {});
|
|
383
|
+
var MouseMsg = class {
|
|
384
|
+
constructor(event) {
|
|
385
|
+
this.event = event;
|
|
386
|
+
}
|
|
387
|
+
_tag = "mouse";
|
|
388
|
+
toString() {
|
|
389
|
+
const parts = [
|
|
390
|
+
this.event.ctrl ? "ctrl" : "",
|
|
391
|
+
this.event.alt ? "alt" : "",
|
|
392
|
+
this.event.shift ? "shift" : ""
|
|
393
|
+
].filter(Boolean);
|
|
394
|
+
const mods = parts.length > 0 ? `${parts.join("+")}+` : "";
|
|
395
|
+
return `${mods}${this.event.button} ${this.event.action} @${this.event.x},${this.event.y}`;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
var mouseSGRRegex = /(\d+);(\d+);(\d+)([Mm])/;
|
|
399
|
+
var mouseEventX10Len = 6;
|
|
400
|
+
var x10MouseByteOffset = 32;
|
|
401
|
+
function parseMouse(buffer, allowMoreData) {
|
|
402
|
+
if (buffer.length < 3 || buffer[0] !== 27 || buffer[1] !== 91) {
|
|
403
|
+
return void 0;
|
|
404
|
+
}
|
|
405
|
+
if (buffer[2] === 77) {
|
|
406
|
+
if (buffer.length < mouseEventX10Len) {
|
|
407
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
408
|
+
}
|
|
409
|
+
const event = parseX10MouseEvent(buffer.subarray(0, mouseEventX10Len));
|
|
410
|
+
return { msg: new MouseMsg(event), length: mouseEventX10Len };
|
|
411
|
+
}
|
|
412
|
+
if (buffer[2] === 60) {
|
|
413
|
+
const slice = machine.decodeString(buffer);
|
|
414
|
+
const match = mouseSGRRegex.exec(slice.slice(3));
|
|
415
|
+
if (!match) {
|
|
416
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
417
|
+
}
|
|
418
|
+
const event = parseSGRMouseEvent(slice);
|
|
419
|
+
const matchedLength = match[0]?.length ?? 0;
|
|
420
|
+
return { msg: new MouseMsg(event), length: matchedLength + 3 };
|
|
421
|
+
}
|
|
422
|
+
return void 0;
|
|
423
|
+
}
|
|
424
|
+
function parseSGRMouseEvent(seq) {
|
|
425
|
+
const match = mouseSGRRegex.exec(seq.slice(3));
|
|
426
|
+
if (!match) {
|
|
427
|
+
return defaultMouseEvent();
|
|
428
|
+
}
|
|
429
|
+
const buttonCode = Number.parseInt(match[1] ?? "0", 10);
|
|
430
|
+
const px = Number.parseInt(match[2] ?? "0", 10);
|
|
431
|
+
const py = Number.parseInt(match[3] ?? "0", 10);
|
|
432
|
+
const release = match[4] === "m";
|
|
433
|
+
const event = parseMouseButton(buttonCode, true);
|
|
434
|
+
if (event.action !== "motion" /* Motion */ && !eventIsWheel(event) && release) {
|
|
435
|
+
event.action = "release" /* Release */;
|
|
436
|
+
}
|
|
437
|
+
event.x = px - 1;
|
|
438
|
+
event.y = py - 1;
|
|
439
|
+
return event;
|
|
440
|
+
}
|
|
441
|
+
function parseX10MouseEvent(buf) {
|
|
442
|
+
const buttonByte = buf[3] ?? 0;
|
|
443
|
+
const c1 = buf[4] ?? 0;
|
|
444
|
+
const c2 = buf[5] ?? 0;
|
|
445
|
+
const event = parseMouseButton(buttonByte, false);
|
|
446
|
+
event.x = c1 - x10MouseByteOffset - 1;
|
|
447
|
+
event.y = c2 - x10MouseByteOffset - 1;
|
|
448
|
+
return event;
|
|
449
|
+
}
|
|
450
|
+
function parseMouseButton(code, isSGR) {
|
|
451
|
+
let e = code;
|
|
452
|
+
if (!isSGR) {
|
|
453
|
+
e -= x10MouseByteOffset;
|
|
454
|
+
}
|
|
455
|
+
const bitShift = 4;
|
|
456
|
+
const bitAlt = 8;
|
|
457
|
+
const bitCtrl = 16;
|
|
458
|
+
const bitMotion = 32;
|
|
459
|
+
const bitWheel = 64;
|
|
460
|
+
const bitAdd = 128;
|
|
461
|
+
const bitsMask = 3;
|
|
462
|
+
const event = defaultMouseEvent();
|
|
463
|
+
if ((e & bitAdd) !== 0) {
|
|
464
|
+
const extraButtons = {
|
|
465
|
+
0: "backward" /* Backward */,
|
|
466
|
+
1: "forward" /* Forward */,
|
|
467
|
+
2: "button-10" /* Button10 */,
|
|
468
|
+
3: "button-11" /* Button11 */
|
|
469
|
+
};
|
|
470
|
+
event.button = extraButtons[e & bitsMask] ?? "none" /* None */;
|
|
471
|
+
} else if ((e & bitWheel) !== 0) {
|
|
472
|
+
const wheelButtons = {
|
|
473
|
+
0: "wheel-up" /* WheelUp */,
|
|
474
|
+
1: "wheel-down" /* WheelDown */,
|
|
475
|
+
2: "wheel-left" /* WheelLeft */,
|
|
476
|
+
3: "wheel-right" /* WheelRight */
|
|
477
|
+
};
|
|
478
|
+
event.button = wheelButtons[e & bitsMask] ?? "none" /* None */;
|
|
479
|
+
} else {
|
|
480
|
+
const baseButtons = {
|
|
481
|
+
0: "left" /* Left */,
|
|
482
|
+
1: "middle" /* Middle */,
|
|
483
|
+
2: "right" /* Right */,
|
|
484
|
+
3: "none" /* None */
|
|
485
|
+
};
|
|
486
|
+
event.button = baseButtons[e & bitsMask] ?? "none" /* None */;
|
|
487
|
+
if ((e & bitsMask) === bitsMask) {
|
|
488
|
+
event.action = "release" /* Release */;
|
|
489
|
+
event.button = "none" /* None */;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if ((e & bitMotion) !== 0 && !eventIsWheel(event)) {
|
|
493
|
+
event.action = "motion" /* Motion */;
|
|
494
|
+
}
|
|
495
|
+
event.alt = (e & bitAlt) !== 0;
|
|
496
|
+
event.ctrl = (e & bitCtrl) !== 0;
|
|
497
|
+
event.shift = (e & bitShift) !== 0;
|
|
498
|
+
return event;
|
|
499
|
+
}
|
|
500
|
+
function eventIsWheel(event) {
|
|
501
|
+
return event.button === "wheel-up" /* WheelUp */ || event.button === "wheel-down" /* WheelDown */ || event.button === "wheel-left" /* WheelLeft */ || event.button === "wheel-right" /* WheelRight */;
|
|
502
|
+
}
|
|
503
|
+
function defaultMouseEvent() {
|
|
504
|
+
return {
|
|
505
|
+
x: 0,
|
|
506
|
+
y: 0,
|
|
507
|
+
shift: false,
|
|
508
|
+
alt: false,
|
|
509
|
+
ctrl: false,
|
|
510
|
+
action: "press" /* Press */,
|
|
511
|
+
button: "none" /* None */
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/input.ts
|
|
516
|
+
var BRACKET_PASTE_START = "\x1B[200~";
|
|
517
|
+
var BRACKET_PASTE_END = "\x1B[201~";
|
|
518
|
+
function startInput(options) {
|
|
519
|
+
if (!options.platform) {
|
|
520
|
+
return () => {
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
let buffer = machine.allocBytes(0);
|
|
524
|
+
let disposable = null;
|
|
525
|
+
const onData = (data) => {
|
|
526
|
+
buffer = machine.concatBytes(buffer, data);
|
|
527
|
+
buffer = consumeBuffer(buffer, options.onMessage);
|
|
528
|
+
};
|
|
529
|
+
disposable = options.platform.terminal.onInput(onData);
|
|
530
|
+
return () => {
|
|
531
|
+
if (disposable) {
|
|
532
|
+
disposable.dispose();
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function consumeBuffer(buffer, push) {
|
|
537
|
+
let offset = 0;
|
|
538
|
+
while (offset < buffer.length) {
|
|
539
|
+
const slice = buffer.subarray(offset);
|
|
540
|
+
const result = detectOne(slice, offset + slice.length === buffer.length);
|
|
541
|
+
if (!result || "needMore" in result) {
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
offset += result.length;
|
|
545
|
+
if (result.msg) {
|
|
546
|
+
push(result.msg);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return buffer.subarray(offset);
|
|
550
|
+
}
|
|
551
|
+
function detectOne(buffer, allowMoreData) {
|
|
552
|
+
if (buffer.length === 0) {
|
|
553
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
554
|
+
}
|
|
555
|
+
const mouse = parseMouse(buffer, allowMoreData);
|
|
556
|
+
if (mouse) {
|
|
557
|
+
if ("needMore" in mouse) {
|
|
558
|
+
return mouse;
|
|
559
|
+
}
|
|
560
|
+
return { msg: mouse.msg, length: mouse.length };
|
|
561
|
+
}
|
|
562
|
+
const focus = detectFocus(buffer);
|
|
563
|
+
if (focus) {
|
|
564
|
+
return focus;
|
|
565
|
+
}
|
|
566
|
+
const paste = detectBracketedPaste(buffer, allowMoreData);
|
|
567
|
+
if (paste) {
|
|
568
|
+
return paste;
|
|
569
|
+
}
|
|
570
|
+
const key = parseKey(buffer, allowMoreData);
|
|
571
|
+
if (!key) {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
if ("needMore" in key) {
|
|
575
|
+
return key;
|
|
576
|
+
}
|
|
577
|
+
return { msg: new KeyMsg(key.key), length: key.length };
|
|
578
|
+
}
|
|
579
|
+
function detectFocus(buffer) {
|
|
580
|
+
if (buffer.length === 3 && buffer[0] === 27 && buffer[1] === 91) {
|
|
581
|
+
if (buffer[2] === 73) {
|
|
582
|
+
return { msg: new FocusMsg(), length: 3 };
|
|
583
|
+
}
|
|
584
|
+
if (buffer[2] === 79) {
|
|
585
|
+
return { msg: new BlurMsg(), length: 3 };
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return void 0;
|
|
589
|
+
}
|
|
590
|
+
function detectBracketedPaste(buffer, allowMoreData) {
|
|
591
|
+
const decoder = new TextDecoder("utf-8", { fatal: false });
|
|
592
|
+
const asString = decoder.decode(buffer);
|
|
593
|
+
if (!asString.startsWith(BRACKET_PASTE_START)) {
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
const endIndex = asString.indexOf(
|
|
597
|
+
BRACKET_PASTE_END,
|
|
598
|
+
BRACKET_PASTE_START.length
|
|
599
|
+
);
|
|
600
|
+
if (endIndex === -1) {
|
|
601
|
+
return allowMoreData ? { needMore: true } : void 0;
|
|
602
|
+
}
|
|
603
|
+
const content = asString.slice(BRACKET_PASTE_START.length, endIndex);
|
|
604
|
+
const fullString = BRACKET_PASTE_START + content + BRACKET_PASTE_END;
|
|
605
|
+
const length = machine.encodeString(fullString).length;
|
|
606
|
+
const key = new KeyMsg({
|
|
607
|
+
type: "runes" /* Runes */,
|
|
608
|
+
runes: content,
|
|
609
|
+
alt: false,
|
|
610
|
+
paste: true
|
|
611
|
+
});
|
|
612
|
+
return { msg: key, length };
|
|
613
|
+
}
|
|
614
|
+
var StandardRenderer = class {
|
|
615
|
+
nextFrame = null;
|
|
616
|
+
lastFrame = "";
|
|
617
|
+
ticker = null;
|
|
618
|
+
terminal;
|
|
619
|
+
frameInterval;
|
|
620
|
+
constructor(options = {}) {
|
|
621
|
+
this.terminal = options.platform?.terminal ?? null;
|
|
622
|
+
const fps = Math.min(Math.max(options.fps ?? 60, 1), 120);
|
|
623
|
+
this.frameInterval = Math.round(1e3 / fps);
|
|
624
|
+
}
|
|
625
|
+
start() {
|
|
626
|
+
if (this.ticker) {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
this.ticker = setInterval(() => this.flush(), this.frameInterval);
|
|
630
|
+
}
|
|
631
|
+
stop() {
|
|
632
|
+
this.flush();
|
|
633
|
+
if (this.ticker) {
|
|
634
|
+
clearInterval(this.ticker);
|
|
635
|
+
this.ticker = null;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
write(view) {
|
|
639
|
+
this.nextFrame = view ?? "";
|
|
640
|
+
}
|
|
641
|
+
repaint() {
|
|
642
|
+
this.lastFrame = "";
|
|
643
|
+
}
|
|
644
|
+
flush() {
|
|
645
|
+
if (this.nextFrame === null) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const frame = this.nextFrame;
|
|
649
|
+
if (frame === this.lastFrame) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
this.lastFrame = frame;
|
|
653
|
+
if (this.terminal) {
|
|
654
|
+
this.terminal.write(`${machine.CLEAR_SCREEN}${machine.CURSOR_HOME}${frame}`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
var TerminalController = class {
|
|
659
|
+
rawMode = false;
|
|
660
|
+
altScreen = false;
|
|
661
|
+
bracketedPaste = false;
|
|
662
|
+
focusReporting = false;
|
|
663
|
+
terminal;
|
|
664
|
+
constructor(platform) {
|
|
665
|
+
this.terminal = platform?.terminal ?? null;
|
|
666
|
+
}
|
|
667
|
+
enableRawMode() {
|
|
668
|
+
if (this.terminal && !this.rawMode) {
|
|
669
|
+
this.terminal.enableRawMode();
|
|
670
|
+
this.rawMode = true;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
disableRawMode() {
|
|
674
|
+
if (this.terminal && this.rawMode) {
|
|
675
|
+
this.terminal.disableRawMode();
|
|
676
|
+
this.rawMode = false;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
enterAltScreen() {
|
|
680
|
+
this.write(machine.ALT_SCREEN_ON);
|
|
681
|
+
this.altScreen = true;
|
|
682
|
+
}
|
|
683
|
+
exitAltScreen() {
|
|
684
|
+
this.write(machine.ALT_SCREEN_OFF);
|
|
685
|
+
this.altScreen = false;
|
|
686
|
+
}
|
|
687
|
+
clearScreen() {
|
|
688
|
+
this.write(`${machine.CLEAR_SCREEN}${machine.CURSOR_HOME}`);
|
|
689
|
+
}
|
|
690
|
+
showCursor() {
|
|
691
|
+
this.write(machine.CURSOR_SHOW);
|
|
692
|
+
}
|
|
693
|
+
hideCursor() {
|
|
694
|
+
this.write(machine.CURSOR_HIDE);
|
|
695
|
+
}
|
|
696
|
+
enableMouseCellMotion() {
|
|
697
|
+
this.write(machine.MOUSE_CELL_ON);
|
|
698
|
+
this.write(machine.MOUSE_SGR_ON);
|
|
699
|
+
}
|
|
700
|
+
enableMouseAllMotion() {
|
|
701
|
+
this.write(machine.MOUSE_ALL_ON);
|
|
702
|
+
this.write(machine.MOUSE_SGR_ON);
|
|
703
|
+
}
|
|
704
|
+
disableMouse() {
|
|
705
|
+
this.write(machine.MOUSE_CELL_OFF);
|
|
706
|
+
this.write(machine.MOUSE_ALL_OFF);
|
|
707
|
+
this.write(machine.MOUSE_SGR_OFF);
|
|
708
|
+
}
|
|
709
|
+
enableBracketedPaste() {
|
|
710
|
+
this.write(machine.BRACKETED_PASTE_ON);
|
|
711
|
+
this.bracketedPaste = true;
|
|
712
|
+
}
|
|
713
|
+
disableBracketedPaste() {
|
|
714
|
+
this.write(machine.BRACKETED_PASTE_OFF);
|
|
715
|
+
this.bracketedPaste = false;
|
|
716
|
+
}
|
|
717
|
+
enableReportFocus() {
|
|
718
|
+
this.write(machine.REPORT_FOCUS_ON);
|
|
719
|
+
this.focusReporting = true;
|
|
720
|
+
}
|
|
721
|
+
disableReportFocus() {
|
|
722
|
+
this.write(machine.REPORT_FOCUS_OFF);
|
|
723
|
+
this.focusReporting = false;
|
|
724
|
+
}
|
|
725
|
+
setWindowTitle(title) {
|
|
726
|
+
this.write(`\x1B]0;${title}\x07`);
|
|
727
|
+
}
|
|
728
|
+
cleanup() {
|
|
729
|
+
this.disableMouse();
|
|
730
|
+
if (this.focusReporting) {
|
|
731
|
+
this.disableReportFocus();
|
|
732
|
+
}
|
|
733
|
+
if (this.bracketedPaste) {
|
|
734
|
+
this.disableBracketedPaste();
|
|
735
|
+
}
|
|
736
|
+
this.showCursor();
|
|
737
|
+
if (this.altScreen) {
|
|
738
|
+
this.exitAltScreen();
|
|
739
|
+
}
|
|
740
|
+
this.disableRawMode();
|
|
741
|
+
}
|
|
742
|
+
write(data) {
|
|
743
|
+
if (data.length === 0) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (this.terminal) {
|
|
747
|
+
this.terminal.write(data);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
// src/program.ts
|
|
753
|
+
var Program = class {
|
|
754
|
+
model;
|
|
755
|
+
terminal;
|
|
756
|
+
renderer;
|
|
757
|
+
opts;
|
|
758
|
+
platform;
|
|
759
|
+
stopInput;
|
|
760
|
+
running = false;
|
|
761
|
+
queue = [];
|
|
762
|
+
draining = false;
|
|
763
|
+
result = null;
|
|
764
|
+
resolveWait;
|
|
765
|
+
constructor(model, options = {}) {
|
|
766
|
+
this.model = model;
|
|
767
|
+
this.opts = options;
|
|
768
|
+
this.platform = options.platform;
|
|
769
|
+
this.terminal = new TerminalController(options.platform);
|
|
770
|
+
this.renderer = new StandardRenderer({
|
|
771
|
+
platform: options.platform,
|
|
772
|
+
fps: options.fps
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
async run() {
|
|
776
|
+
this.running = true;
|
|
777
|
+
this.setupTerminal();
|
|
778
|
+
this.setupSignals();
|
|
779
|
+
this.renderer.start();
|
|
780
|
+
try {
|
|
781
|
+
this.runCmd(this.model.init());
|
|
782
|
+
this.renderer.write(this.model.view());
|
|
783
|
+
this.startInputLoop();
|
|
784
|
+
await this.waitUntilDone();
|
|
785
|
+
this.result = { model: this.model };
|
|
786
|
+
} catch (err) {
|
|
787
|
+
this.result = { model: this.model, error: err };
|
|
788
|
+
} finally {
|
|
789
|
+
this.shutdown();
|
|
790
|
+
}
|
|
791
|
+
return this.result ?? { model: this.model };
|
|
792
|
+
}
|
|
793
|
+
waitUntilDone() {
|
|
794
|
+
return new Promise((resolve) => {
|
|
795
|
+
this.resolveWait = resolve;
|
|
796
|
+
if (!this.running) {
|
|
797
|
+
resolve();
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
send(msg2) {
|
|
802
|
+
if (!msg2) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
this.queue.push(msg2);
|
|
806
|
+
if (!this.draining) {
|
|
807
|
+
void this.drainQueue();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
quit() {
|
|
811
|
+
this.send(new QuitMsg());
|
|
812
|
+
}
|
|
813
|
+
kill() {
|
|
814
|
+
this.running = false;
|
|
815
|
+
this.shutdown();
|
|
816
|
+
}
|
|
817
|
+
drainQueue() {
|
|
818
|
+
if (this.draining) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
this.draining = true;
|
|
822
|
+
while (this.running && this.queue.length > 0) {
|
|
823
|
+
const msg2 = this.queue.shift();
|
|
824
|
+
if (msg2 === void 0) {
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
const consumed = this.handleInternal(msg2);
|
|
828
|
+
if (consumed) {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
const [nextModel, cmd] = this.model.update(msg2);
|
|
832
|
+
this.model = nextModel;
|
|
833
|
+
this.runCmd(cmd);
|
|
834
|
+
this.renderer.write(this.model.view());
|
|
835
|
+
}
|
|
836
|
+
this.draining = false;
|
|
837
|
+
}
|
|
838
|
+
handleInternal(msg2) {
|
|
839
|
+
if (msg2 instanceof QuitMsg || msg2 instanceof InterruptMsg) {
|
|
840
|
+
this.running = false;
|
|
841
|
+
if (this.resolveWait) {
|
|
842
|
+
this.resolveWait();
|
|
843
|
+
}
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
if (msg2 instanceof ClearScreenMsg) {
|
|
847
|
+
this.terminal.clearScreen();
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
if (msg2 instanceof EnterAltScreenMsg) {
|
|
851
|
+
this.terminal.enterAltScreen();
|
|
852
|
+
this.renderer.repaint();
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
if (msg2 instanceof ExitAltScreenMsg) {
|
|
856
|
+
this.terminal.exitAltScreen();
|
|
857
|
+
this.renderer.repaint();
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
if (msg2 instanceof EnableMouseCellMotionMsg) {
|
|
861
|
+
this.terminal.enableMouseCellMotion();
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
if (msg2 instanceof EnableMouseAllMotionMsg) {
|
|
865
|
+
this.terminal.enableMouseAllMotion();
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
if (msg2 instanceof DisableMouseMsg) {
|
|
869
|
+
this.terminal.disableMouse();
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
if (msg2 instanceof ShowCursorMsg) {
|
|
873
|
+
this.terminal.showCursor();
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
if (msg2 instanceof HideCursorMsg) {
|
|
877
|
+
this.terminal.hideCursor();
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
if (msg2 instanceof SetWindowTitleMsg) {
|
|
881
|
+
this.terminal.setWindowTitle(msg2.title);
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
if (msg2 instanceof ResumeMsg) {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
runCmd(cmd) {
|
|
890
|
+
if (!cmd) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const handleResult = (result) => {
|
|
894
|
+
if (result === null || result === void 0) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (Array.isArray(result)) {
|
|
898
|
+
for (const msg2 of result) {
|
|
899
|
+
this.send(msg2);
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
this.send(result);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
try {
|
|
906
|
+
const effect = cmd();
|
|
907
|
+
if (effect instanceof Promise) {
|
|
908
|
+
effect.then(handleResult).catch((err) => {
|
|
909
|
+
console.error(err);
|
|
910
|
+
});
|
|
911
|
+
} else {
|
|
912
|
+
handleResult(effect);
|
|
913
|
+
}
|
|
914
|
+
} catch (err) {
|
|
915
|
+
console.error(err);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
setupTerminal() {
|
|
919
|
+
this.terminal.enableRawMode();
|
|
920
|
+
this.terminal.hideCursor();
|
|
921
|
+
if (this.opts.altScreen) {
|
|
922
|
+
this.terminal.enterAltScreen();
|
|
923
|
+
this.terminal.clearScreen();
|
|
924
|
+
}
|
|
925
|
+
if (this.opts.mouseMode === "cell") {
|
|
926
|
+
this.terminal.enableMouseCellMotion();
|
|
927
|
+
} else if (this.opts.mouseMode === "all") {
|
|
928
|
+
this.terminal.enableMouseAllMotion();
|
|
929
|
+
}
|
|
930
|
+
if (this.opts.bracketedPaste !== false) {
|
|
931
|
+
this.terminal.enableBracketedPaste();
|
|
932
|
+
}
|
|
933
|
+
if (this.opts.reportFocus) {
|
|
934
|
+
this.terminal.enableReportFocus();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
startInputLoop() {
|
|
938
|
+
this.stopInput = startInput({
|
|
939
|
+
platform: this.platform,
|
|
940
|
+
onMessage: (msg2) => this.send(msg2)
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
setupSignals() {
|
|
944
|
+
const disposables = [];
|
|
945
|
+
if (this.platform) {
|
|
946
|
+
const intDisposable = this.platform.signals.onInterrupt(this.onSigInt);
|
|
947
|
+
const termDisposable = this.platform.signals.onTerminate(this.onSigTerm);
|
|
948
|
+
disposables.push(
|
|
949
|
+
() => intDisposable.dispose(),
|
|
950
|
+
() => termDisposable.dispose()
|
|
951
|
+
);
|
|
952
|
+
const handleResize = (size) => {
|
|
953
|
+
this.send(new WindowSizeMsg(size.columns, size.rows));
|
|
954
|
+
};
|
|
955
|
+
const resizeDisposable = this.platform.terminal.onResize(handleResize);
|
|
956
|
+
disposables.push(() => resizeDisposable.dispose());
|
|
957
|
+
const initialSize = this.platform.terminal.getSize();
|
|
958
|
+
this.send(new WindowSizeMsg(initialSize.columns, initialSize.rows));
|
|
959
|
+
}
|
|
960
|
+
this.disposeSignals = () => {
|
|
961
|
+
for (const dispose of disposables) {
|
|
962
|
+
dispose();
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
disposeSignals = null;
|
|
967
|
+
onSigInt = () => {
|
|
968
|
+
this.send(new InterruptMsg());
|
|
969
|
+
};
|
|
970
|
+
onSigTerm = () => {
|
|
971
|
+
this.send(new QuitMsg());
|
|
972
|
+
};
|
|
973
|
+
shutdown() {
|
|
974
|
+
if (this.disposeSignals) {
|
|
975
|
+
this.disposeSignals();
|
|
976
|
+
this.disposeSignals = null;
|
|
977
|
+
}
|
|
978
|
+
if (this.stopInput) {
|
|
979
|
+
this.stopInput();
|
|
980
|
+
this.stopInput = void 0;
|
|
981
|
+
}
|
|
982
|
+
this.renderer.stop();
|
|
983
|
+
this.terminal.cleanup();
|
|
984
|
+
if (this.platform) {
|
|
985
|
+
this.platform.dispose();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
// src/commands.ts
|
|
991
|
+
var now = () => /* @__PURE__ */ new Date();
|
|
992
|
+
function batch(...cmds) {
|
|
993
|
+
const valid = cmds.filter((cmd) => Boolean(cmd));
|
|
994
|
+
if (valid.length === 0) {
|
|
995
|
+
return null;
|
|
996
|
+
}
|
|
997
|
+
if (valid.length === 1) {
|
|
998
|
+
const [only] = valid;
|
|
999
|
+
return only ?? null;
|
|
1000
|
+
}
|
|
1001
|
+
return async () => {
|
|
1002
|
+
const results = await Promise.all(
|
|
1003
|
+
valid.map((cmd) => Promise.resolve(cmd?.()))
|
|
1004
|
+
);
|
|
1005
|
+
return flatten(results);
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
function sequence(...cmds) {
|
|
1009
|
+
const valid = cmds.filter((cmd) => Boolean(cmd));
|
|
1010
|
+
if (valid.length === 0) {
|
|
1011
|
+
return null;
|
|
1012
|
+
}
|
|
1013
|
+
if (valid.length === 1) {
|
|
1014
|
+
const [only] = valid;
|
|
1015
|
+
return only ?? null;
|
|
1016
|
+
}
|
|
1017
|
+
return async () => {
|
|
1018
|
+
const messages = [];
|
|
1019
|
+
for (const cmd of valid) {
|
|
1020
|
+
const result = await Promise.resolve(cmd?.());
|
|
1021
|
+
if (result !== null && result !== void 0) {
|
|
1022
|
+
messages.push(result);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return flatten(messages);
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function tick(ms, fn) {
|
|
1029
|
+
return () => new Promise((resolve) => {
|
|
1030
|
+
setTimeout(() => resolve(fn(now())), ms);
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
function every(ms, fn) {
|
|
1034
|
+
return () => new Promise((resolve) => {
|
|
1035
|
+
const current = now();
|
|
1036
|
+
const delay = alignToInterval(current, ms);
|
|
1037
|
+
setTimeout(() => resolve(fn(now())), delay);
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
var msg = (value) => () => value;
|
|
1041
|
+
var quit = () => msg(new QuitMsg());
|
|
1042
|
+
function flatten(values) {
|
|
1043
|
+
const results = [];
|
|
1044
|
+
for (const value of values) {
|
|
1045
|
+
if (value === null || value === void 0) {
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
if (Array.isArray(value)) {
|
|
1049
|
+
results.push(...value);
|
|
1050
|
+
} else {
|
|
1051
|
+
results.push(value);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (results.length === 0) {
|
|
1055
|
+
return null;
|
|
1056
|
+
}
|
|
1057
|
+
if (results.length === 1) {
|
|
1058
|
+
return results[0];
|
|
1059
|
+
}
|
|
1060
|
+
return results;
|
|
1061
|
+
}
|
|
1062
|
+
function alignToInterval(date, ms) {
|
|
1063
|
+
const next = new Date(date);
|
|
1064
|
+
next.setMilliseconds(0);
|
|
1065
|
+
const remainder = date.getTime() % ms;
|
|
1066
|
+
return remainder === 0 ? ms : ms - remainder;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// src/screen.ts
|
|
1070
|
+
var clearScreen = () => () => new ClearScreenMsg();
|
|
1071
|
+
var enableMouseCellMotion = () => () => new EnableMouseCellMotionMsg();
|
|
1072
|
+
var enableMouseAllMotion = () => () => new EnableMouseAllMotionMsg();
|
|
1073
|
+
var disableMouse = () => () => new DisableMouseMsg();
|
|
1074
|
+
var showCursor = () => () => new ShowCursorMsg();
|
|
1075
|
+
var hideCursor = () => () => new HideCursorMsg();
|
|
1076
|
+
var setWindowTitle = (title) => () => new SetWindowTitleMsg(title);
|
|
1077
|
+
var windowSize = (platform) => () => {
|
|
1078
|
+
if (platform) {
|
|
1079
|
+
const size = platform.terminal.getSize();
|
|
1080
|
+
return new WindowSizeMsg(size.columns, size.rows);
|
|
1081
|
+
}
|
|
1082
|
+
return new WindowSizeMsg(0, 0);
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
exports.BlurMsg = BlurMsg;
|
|
1086
|
+
exports.ClearScreenMsg = ClearScreenMsg;
|
|
1087
|
+
exports.DisableMouseMsg = DisableMouseMsg;
|
|
1088
|
+
exports.DisableReportFocusMsg = DisableReportFocusMsg;
|
|
1089
|
+
exports.EnableMouseAllMotionMsg = EnableMouseAllMotionMsg;
|
|
1090
|
+
exports.EnableMouseCellMotionMsg = EnableMouseCellMotionMsg;
|
|
1091
|
+
exports.EnableReportFocusMsg = EnableReportFocusMsg;
|
|
1092
|
+
exports.EnterAltScreenMsg = EnterAltScreenMsg;
|
|
1093
|
+
exports.ExitAltScreenMsg = ExitAltScreenMsg;
|
|
1094
|
+
exports.FocusMsg = FocusMsg;
|
|
1095
|
+
exports.HideCursorMsg = HideCursorMsg;
|
|
1096
|
+
exports.InterruptMsg = InterruptMsg;
|
|
1097
|
+
exports.KeyMsg = KeyMsg;
|
|
1098
|
+
exports.KeyType = KeyType;
|
|
1099
|
+
exports.MouseAction = MouseAction;
|
|
1100
|
+
exports.MouseButton = MouseButton;
|
|
1101
|
+
exports.MouseMsg = MouseMsg;
|
|
1102
|
+
exports.Program = Program;
|
|
1103
|
+
exports.QuitMsg = QuitMsg;
|
|
1104
|
+
exports.ResumeMsg = ResumeMsg;
|
|
1105
|
+
exports.SetWindowTitleMsg = SetWindowTitleMsg;
|
|
1106
|
+
exports.ShowCursorMsg = ShowCursorMsg;
|
|
1107
|
+
exports.SuspendMsg = SuspendMsg;
|
|
1108
|
+
exports.WindowSizeMsg = WindowSizeMsg;
|
|
1109
|
+
exports.batch = batch;
|
|
1110
|
+
exports.clearScreen = clearScreen;
|
|
1111
|
+
exports.disableMouse = disableMouse;
|
|
1112
|
+
exports.enableMouseAllMotion = enableMouseAllMotion;
|
|
1113
|
+
exports.enableMouseCellMotion = enableMouseCellMotion;
|
|
1114
|
+
exports.every = every;
|
|
1115
|
+
exports.hideCursor = hideCursor;
|
|
1116
|
+
exports.keyToString = keyToString;
|
|
1117
|
+
exports.msg = msg;
|
|
1118
|
+
exports.quit = quit;
|
|
1119
|
+
exports.sequence = sequence;
|
|
1120
|
+
exports.setWindowTitle = setWindowTitle;
|
|
1121
|
+
exports.showCursor = showCursor;
|
|
1122
|
+
exports.tick = tick;
|
|
1123
|
+
exports.windowSize = windowSize;
|
|
1124
|
+
//# sourceMappingURL=index.cjs.map
|
|
1125
|
+
//# sourceMappingURL=index.cjs.map
|