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