blecsd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +220 -0
- package/dist/3d/index.d.ts +5 -0
- package/dist/3d/index.js +1 -0
- package/dist/audio/index.d.ts +177 -0
- package/dist/audio/index.js +1 -0
- package/dist/border-D_Jb4ZJV.d.ts +257 -0
- package/dist/cell-DwIu2ryP.d.ts +505 -0
- package/dist/chunk-2UBBZFE4.js +1 -0
- package/dist/chunk-35LCBY6P.js +1 -0
- package/dist/chunk-3B7MIVW6.js +1 -0
- package/dist/chunk-3EGGGI5J.js +3 -0
- package/dist/chunk-4LWWONFK.js +1 -0
- package/dist/chunk-4X4N4HNQ.js +2 -0
- package/dist/chunk-5PELJRUQ.js +1 -0
- package/dist/chunk-AEJIX2MW.js +1 -0
- package/dist/chunk-AQ7LW75B.js +1 -0
- package/dist/chunk-AXZQAH4X.js +1 -0
- package/dist/chunk-B6Z2JFRY.js +1 -0
- package/dist/chunk-BCADUCOZ.js +1 -0
- package/dist/chunk-C5PCEQ6G.js +1 -0
- package/dist/chunk-CIK4AMUA.js +1 -0
- package/dist/chunk-DNRXW56C.js +1 -0
- package/dist/chunk-FC5FFAAC.js +12 -0
- package/dist/chunk-FGHEFXLK.js +1 -0
- package/dist/chunk-FYEBZAWN.js +1 -0
- package/dist/chunk-G7GIWWLE.js +1 -0
- package/dist/chunk-GYHI26UE.js +1 -0
- package/dist/chunk-H2YAOJDW.js +1 -0
- package/dist/chunk-J4JZ2NU2.js +1 -0
- package/dist/chunk-JKVHO4LH.js +1 -0
- package/dist/chunk-K2B2OXQ5.js +5 -0
- package/dist/chunk-K37L3G4Z.js +4 -0
- package/dist/chunk-KD55INV7.js +1 -0
- package/dist/chunk-KFAK4A3G.js +1 -0
- package/dist/chunk-LCN2ZITE.js +1 -0
- package/dist/chunk-LYSK5S63.js +1 -0
- package/dist/chunk-NZ55KBM6.js +1 -0
- package/dist/chunk-OMMJ7B5P.js +1 -0
- package/dist/chunk-OUXUPF3V.js +33 -0
- package/dist/chunk-OVT2PPGW.js +19 -0
- package/dist/chunk-P6CJO3BC.js +1 -0
- package/dist/chunk-PSXXMBVJ.js +1 -0
- package/dist/chunk-PXXGH3BV.js +1 -0
- package/dist/chunk-QIKIOVP2.js +1 -0
- package/dist/chunk-SHUC6JWA.js +1 -0
- package/dist/chunk-TDXJDLY6.js +6 -0
- package/dist/chunk-TWSWTBYL.js +1 -0
- package/dist/chunk-TYMY2TBR.js +3 -0
- package/dist/chunk-VNZ6CWJA.js +2 -0
- package/dist/chunk-VOCM5T2G.js +5 -0
- package/dist/chunk-W5OU7Z6J.js +1 -0
- package/dist/chunk-WNG4A3K7.js +4 -0
- package/dist/chunk-XQIGERNI.js +1 -0
- package/dist/chunk-XZA63ZPO.js +1 -0
- package/dist/chunk-YAMOSPWB.js +4 -0
- package/dist/chunk-YD6ULIUR.js +1 -0
- package/dist/chunk-Z4EZERNE.js +1 -0
- package/dist/cli/init.d.ts +86 -0
- package/dist/cli/init.js +179 -0
- package/dist/color-B78w3zH-.d.ts +79 -0
- package/dist/components/index.d.ts +10298 -0
- package/dist/components/index.js +1 -0
- package/dist/core/index.d.ts +6700 -0
- package/dist/core/index.js +1 -0
- package/dist/debug/index.d.ts +711 -0
- package/dist/debug/index.js +1 -0
- package/dist/doubleBuffer-CKQFmlPN.d.ts +95 -0
- package/dist/errors/index.d.ts +1110 -0
- package/dist/errors/index.js +1 -0
- package/dist/events-BbbxkgvX.d.ts +125 -0
- package/dist/game/index.d.ts +486 -0
- package/dist/game/index.js +1 -0
- package/dist/gameLoop-BIPW7-OY.d.ts +219 -0
- package/dist/index-zSGJ2eUk.d.ts +3156 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +1 -0
- package/dist/input/index.d.ts +158 -0
- package/dist/input/index.js +1 -0
- package/dist/inputActions-CefRUBuT.d.ts +2637 -0
- package/dist/keyParser-Bwm8-l7v.d.ts +229 -0
- package/dist/mouseParser-Cfrbn3AX.d.ts +177 -0
- package/dist/parser-iMHmQuUh.d.ts +265 -0
- package/dist/program-BZaKqDKH.d.ts +141 -0
- package/dist/renderable-jTMOA-GK.d.ts +302 -0
- package/dist/scheduler-DcfoFuum.d.ts +86 -0
- package/dist/schemas/index.d.ts +936 -0
- package/dist/schemas/index.js +1 -0
- package/dist/systems/index.d.ts +4036 -0
- package/dist/systems/index.js +1 -0
- package/dist/terminal/index.d.ts +7357 -0
- package/dist/terminal/index.js +1 -0
- package/dist/terminus-14-bold-HWSPRLJD.js +1 -0
- package/dist/terminus-14-normal-T3SWMH4D.js +1 -0
- package/dist/tilemap-D1HJvKy3.d.ts +1211 -0
- package/dist/types-BcsvoKzf.d.ts +68 -0
- package/dist/utils/index.d.ts +6104 -0
- package/dist/utils/index.js +1 -0
- package/dist/viewport3d-xI33-_wq.d.ts +182 -0
- package/dist/virtualScrollback-DvZTRU8a.d.ts +274 -0
- package/dist/virtualViewport-Dx2iJliO.d.ts +2334 -0
- package/dist/virtualizedLineStore-DwPEvPkk.d.ts +297 -0
- package/dist/widgets/bigText.d.ts +230 -0
- package/dist/widgets/bigText.js +1 -0
- package/dist/widgets/fonts/index.d.ts +211 -0
- package/dist/widgets/fonts/index.js +1 -0
- package/dist/widgets/index.d.ts +8591 -0
- package/dist/widgets/index.js +1 -0
- package/package.json +213 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Key event parser for ANSI escape sequences.
|
|
5
|
+
* Rewrite of blessed keys.js with strict typing.
|
|
6
|
+
* @module terminal/keyParser
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* All recognized key names.
|
|
11
|
+
* Includes letters, numbers, function keys, and navigation keys.
|
|
12
|
+
*/
|
|
13
|
+
type KeyName = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'f1' | 'f2' | 'f3' | 'f4' | 'f5' | 'f6' | 'f7' | 'f8' | 'f9' | 'f10' | 'f11' | 'f12' | 'up' | 'down' | 'left' | 'right' | 'home' | 'end' | 'pageup' | 'pagedown' | 'insert' | 'delete' | 'clear' | 'return' | 'enter' | 'tab' | 'backspace' | 'escape' | 'space' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '-' | '_' | '=' | '+' | '[' | ']' | '{' | '}' | '\\' | '|' | ';' | ':' | "'" | '"' | ',' | '.' | '<' | '>' | '/' | '?' | '`' | '~' | 'undefined';
|
|
14
|
+
/**
|
|
15
|
+
* Parsed keyboard event with modifiers.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { parseKeySequence, KeyEvent } from 'blecsd';
|
|
20
|
+
*
|
|
21
|
+
* const event = parseKeySequence(Buffer.from([0x1b, 0x5b, 0x41]));
|
|
22
|
+
* if (event) {
|
|
23
|
+
* console.log(event.name); // 'up'
|
|
24
|
+
* console.log(event.ctrl); // false
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface KeyEvent {
|
|
29
|
+
/** The raw sequence string that generated this event */
|
|
30
|
+
readonly sequence: string;
|
|
31
|
+
/** Normalized key name */
|
|
32
|
+
readonly name: KeyName;
|
|
33
|
+
/** Ctrl modifier was pressed */
|
|
34
|
+
readonly ctrl: boolean;
|
|
35
|
+
/** Alt/Meta modifier was pressed */
|
|
36
|
+
readonly meta: boolean;
|
|
37
|
+
/** Shift modifier was pressed */
|
|
38
|
+
readonly shift: boolean;
|
|
39
|
+
/** Terminal-specific escape code (if applicable) */
|
|
40
|
+
readonly code?: string;
|
|
41
|
+
/** Raw buffer data */
|
|
42
|
+
readonly raw: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Zod schema for KeyEvent validation.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { KeyEventSchema } from 'blecsd';
|
|
50
|
+
*
|
|
51
|
+
* const result = KeyEventSchema.safeParse(event);
|
|
52
|
+
* if (result.success) {
|
|
53
|
+
* console.log('Valid key event');
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const KeyEventSchema: z.ZodObject<{
|
|
58
|
+
sequence: z.ZodString;
|
|
59
|
+
name: z.ZodEnum<{
|
|
60
|
+
undefined: "undefined";
|
|
61
|
+
x: "x";
|
|
62
|
+
y: "y";
|
|
63
|
+
r: "r";
|
|
64
|
+
g: "g";
|
|
65
|
+
b: "b";
|
|
66
|
+
a: "a";
|
|
67
|
+
0: "0";
|
|
68
|
+
1: "1";
|
|
69
|
+
2: "2";
|
|
70
|
+
3: "3";
|
|
71
|
+
4: "4";
|
|
72
|
+
escape: "escape";
|
|
73
|
+
5: "5";
|
|
74
|
+
6: "6";
|
|
75
|
+
7: "7";
|
|
76
|
+
"!": "!";
|
|
77
|
+
"#": "#";
|
|
78
|
+
";": ";";
|
|
79
|
+
$: "$";
|
|
80
|
+
"-": "-";
|
|
81
|
+
left: "left";
|
|
82
|
+
z: "z";
|
|
83
|
+
"/": "/";
|
|
84
|
+
v: "v";
|
|
85
|
+
f: "f";
|
|
86
|
+
o: "o";
|
|
87
|
+
right: "right";
|
|
88
|
+
up: "up";
|
|
89
|
+
down: "down";
|
|
90
|
+
return: "return";
|
|
91
|
+
enter: "enter";
|
|
92
|
+
space: "space";
|
|
93
|
+
"*": "*";
|
|
94
|
+
end: "end";
|
|
95
|
+
insert: "insert";
|
|
96
|
+
delete: "delete";
|
|
97
|
+
home: "home";
|
|
98
|
+
backspace: "backspace";
|
|
99
|
+
tab: "tab";
|
|
100
|
+
k: "k";
|
|
101
|
+
j: "j";
|
|
102
|
+
pageup: "pageup";
|
|
103
|
+
pagedown: "pagedown";
|
|
104
|
+
"|": "|";
|
|
105
|
+
"\\": "\\";
|
|
106
|
+
8: "8";
|
|
107
|
+
9: "9";
|
|
108
|
+
"[": "[";
|
|
109
|
+
"]": "]";
|
|
110
|
+
c: "c";
|
|
111
|
+
m: "m";
|
|
112
|
+
h: "h";
|
|
113
|
+
l: "l";
|
|
114
|
+
s: "s";
|
|
115
|
+
u: "u";
|
|
116
|
+
"?": "?";
|
|
117
|
+
",": ",";
|
|
118
|
+
"%": "%";
|
|
119
|
+
d: "d";
|
|
120
|
+
e: "e";
|
|
121
|
+
i: "i";
|
|
122
|
+
n: "n";
|
|
123
|
+
p: "p";
|
|
124
|
+
q: "q";
|
|
125
|
+
t: "t";
|
|
126
|
+
w: "w";
|
|
127
|
+
f1: "f1";
|
|
128
|
+
f2: "f2";
|
|
129
|
+
f3: "f3";
|
|
130
|
+
f4: "f4";
|
|
131
|
+
f5: "f5";
|
|
132
|
+
f6: "f6";
|
|
133
|
+
f7: "f7";
|
|
134
|
+
f8: "f8";
|
|
135
|
+
f9: "f9";
|
|
136
|
+
f10: "f10";
|
|
137
|
+
f11: "f11";
|
|
138
|
+
f12: "f12";
|
|
139
|
+
clear: "clear";
|
|
140
|
+
"@": "@";
|
|
141
|
+
"^": "^";
|
|
142
|
+
"&": "&";
|
|
143
|
+
"(": "(";
|
|
144
|
+
")": ")";
|
|
145
|
+
_: "_";
|
|
146
|
+
"=": "=";
|
|
147
|
+
"+": "+";
|
|
148
|
+
"{": "{";
|
|
149
|
+
"}": "}";
|
|
150
|
+
":": ":";
|
|
151
|
+
"'": "'";
|
|
152
|
+
"\"": "\"";
|
|
153
|
+
".": ".";
|
|
154
|
+
"<": "<";
|
|
155
|
+
">": ">";
|
|
156
|
+
"`": "`";
|
|
157
|
+
"~": "~";
|
|
158
|
+
}>;
|
|
159
|
+
ctrl: z.ZodBoolean;
|
|
160
|
+
meta: z.ZodBoolean;
|
|
161
|
+
shift: z.ZodBoolean;
|
|
162
|
+
code: z.ZodOptional<z.ZodString>;
|
|
163
|
+
raw: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
/**
|
|
166
|
+
* Check if a buffer starts with a mouse sequence.
|
|
167
|
+
* Mouse sequences are handled separately by the mouse parser.
|
|
168
|
+
*
|
|
169
|
+
* @param buffer - Input buffer to check
|
|
170
|
+
* @returns true if buffer contains a mouse sequence
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
declare function isMouseSequence(buffer: Uint8Array): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Parse a key sequence from a buffer.
|
|
177
|
+
*
|
|
178
|
+
* Handles:
|
|
179
|
+
* - Regular characters (a-z, A-Z, 0-9)
|
|
180
|
+
* - Control characters (Ctrl+A through Ctrl+Z)
|
|
181
|
+
* - Function keys (F1-F12)
|
|
182
|
+
* - Navigation keys (arrows, home, end, pageup, pagedown)
|
|
183
|
+
* - Modifier combinations (shift, ctrl, alt/meta)
|
|
184
|
+
* - Special keys (escape, enter, tab, backspace, space)
|
|
185
|
+
*
|
|
186
|
+
* @param buffer - Raw input buffer to parse
|
|
187
|
+
* @returns Parsed KeyEvent or null if not a key sequence
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import { parseKeySequence } from 'blecsd';
|
|
192
|
+
*
|
|
193
|
+
* // Parse Ctrl+C
|
|
194
|
+
* const ctrlC = parseKeySequence(Buffer.from([0x03]));
|
|
195
|
+
* console.log(ctrlC?.name); // 'c'
|
|
196
|
+
* console.log(ctrlC?.ctrl); // true
|
|
197
|
+
*
|
|
198
|
+
* // Parse Up arrow
|
|
199
|
+
* const up = parseKeySequence(Buffer.from([0x1b, 0x5b, 0x41]));
|
|
200
|
+
* console.log(up?.name); // 'up'
|
|
201
|
+
*
|
|
202
|
+
* // Parse F1
|
|
203
|
+
* const f1 = parseKeySequence(Buffer.from([0x1b, 0x4f, 0x50]));
|
|
204
|
+
* console.log(f1?.name); // 'f1'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare function parseKeySequence(buffer: Uint8Array): KeyEvent | null;
|
|
208
|
+
/**
|
|
209
|
+
* Parse multiple key sequences from a buffer.
|
|
210
|
+
* Handles cases where multiple keypresses arrive in a single read.
|
|
211
|
+
*
|
|
212
|
+
* @param buffer - Raw input buffer that may contain multiple key sequences
|
|
213
|
+
* @returns Array of parsed KeyEvents
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* import { parseKeyBuffer } from 'blecsd';
|
|
218
|
+
*
|
|
219
|
+
* // Parse buffer with multiple characters
|
|
220
|
+
* const events = parseKeyBuffer(Buffer.from('abc'));
|
|
221
|
+
* console.log(events.length); // 3
|
|
222
|
+
* console.log(events[0].name); // 'a'
|
|
223
|
+
* console.log(events[1].name); // 'b'
|
|
224
|
+
* console.log(events[2].name); // 'c'
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare function parseKeyBuffer(buffer: Uint8Array): readonly KeyEvent[];
|
|
228
|
+
|
|
229
|
+
export { type KeyName as K, KeyEventSchema as a, type KeyEvent as b, parseKeySequence as c, isMouseSequence as i, parseKeyBuffer as p };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mouse event parser for terminal mouse protocols.
|
|
5
|
+
* Supports X10, SGR, URXVT, DEC, and VT300 protocols.
|
|
6
|
+
* @module terminal/mouseParser
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mouse button identifiers.
|
|
11
|
+
*/
|
|
12
|
+
type MouseButton = 'left' | 'middle' | 'right' | 'wheelUp' | 'wheelDown' | 'unknown';
|
|
13
|
+
/**
|
|
14
|
+
* Mouse action types.
|
|
15
|
+
*/
|
|
16
|
+
type MouseAction = 'press' | 'release' | 'move' | 'wheel';
|
|
17
|
+
/**
|
|
18
|
+
* Mouse protocol types.
|
|
19
|
+
*/
|
|
20
|
+
type MouseProtocol = 'x10' | 'sgr' | 'urxvt' | 'dec' | 'vt300';
|
|
21
|
+
/**
|
|
22
|
+
* Parsed mouse event with position and modifiers.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { parseMouseSequence, MouseEvent } from 'blecsd';
|
|
27
|
+
*
|
|
28
|
+
* const event = parseMouseSequence(Buffer.from('\x1b[<0;10;20M'));
|
|
29
|
+
* if (event) {
|
|
30
|
+
* console.log(event.x); // 10
|
|
31
|
+
* console.log(event.y); // 20
|
|
32
|
+
* console.log(event.button); // 'left'
|
|
33
|
+
* console.log(event.action); // 'press'
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
interface MouseEvent {
|
|
38
|
+
/** X coordinate (0-indexed) */
|
|
39
|
+
readonly x: number;
|
|
40
|
+
/** Y coordinate (0-indexed) */
|
|
41
|
+
readonly y: number;
|
|
42
|
+
/** Mouse button */
|
|
43
|
+
readonly button: MouseButton;
|
|
44
|
+
/** Action type */
|
|
45
|
+
readonly action: MouseAction;
|
|
46
|
+
/** Ctrl modifier was pressed */
|
|
47
|
+
readonly ctrl: boolean;
|
|
48
|
+
/** Alt/Meta modifier was pressed */
|
|
49
|
+
readonly meta: boolean;
|
|
50
|
+
/** Shift modifier was pressed */
|
|
51
|
+
readonly shift: boolean;
|
|
52
|
+
/** Protocol used to encode this event */
|
|
53
|
+
readonly protocol: MouseProtocol;
|
|
54
|
+
/** Raw buffer data */
|
|
55
|
+
readonly raw: Uint8Array;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Zod schema for MouseEvent validation.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { MouseEventSchema } from 'blecsd';
|
|
63
|
+
*
|
|
64
|
+
* const result = MouseEventSchema.safeParse(event);
|
|
65
|
+
* if (result.success) {
|
|
66
|
+
* console.log('Valid mouse event');
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare const MouseEventSchema: z.ZodObject<{
|
|
71
|
+
x: z.ZodNumber;
|
|
72
|
+
y: z.ZodNumber;
|
|
73
|
+
button: z.ZodEnum<{
|
|
74
|
+
unknown: "unknown";
|
|
75
|
+
left: "left";
|
|
76
|
+
right: "right";
|
|
77
|
+
middle: "middle";
|
|
78
|
+
wheelUp: "wheelUp";
|
|
79
|
+
wheelDown: "wheelDown";
|
|
80
|
+
}>;
|
|
81
|
+
action: z.ZodEnum<{
|
|
82
|
+
press: "press";
|
|
83
|
+
release: "release";
|
|
84
|
+
move: "move";
|
|
85
|
+
wheel: "wheel";
|
|
86
|
+
}>;
|
|
87
|
+
ctrl: z.ZodBoolean;
|
|
88
|
+
meta: z.ZodBoolean;
|
|
89
|
+
shift: z.ZodBoolean;
|
|
90
|
+
protocol: z.ZodEnum<{
|
|
91
|
+
x10: "x10";
|
|
92
|
+
sgr: "sgr";
|
|
93
|
+
urxvt: "urxvt";
|
|
94
|
+
dec: "dec";
|
|
95
|
+
vt300: "vt300";
|
|
96
|
+
}>;
|
|
97
|
+
raw: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
/**
|
|
100
|
+
* Focus event result (not a full mouse event).
|
|
101
|
+
*/
|
|
102
|
+
interface FocusEvent {
|
|
103
|
+
/** Whether the terminal gained or lost focus */
|
|
104
|
+
readonly focused: boolean;
|
|
105
|
+
/** Raw buffer data */
|
|
106
|
+
readonly raw: Uint8Array;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Zod schema for FocusEvent validation.
|
|
110
|
+
*/
|
|
111
|
+
declare const FocusEventSchema: z.ZodObject<{
|
|
112
|
+
focused: z.ZodBoolean;
|
|
113
|
+
raw: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
/**
|
|
116
|
+
* Result of parsing a mouse/focus sequence.
|
|
117
|
+
*/
|
|
118
|
+
type ParseMouseResult = {
|
|
119
|
+
type: 'mouse';
|
|
120
|
+
event: MouseEvent;
|
|
121
|
+
} | {
|
|
122
|
+
type: 'focus';
|
|
123
|
+
event: FocusEvent;
|
|
124
|
+
} | null;
|
|
125
|
+
/**
|
|
126
|
+
* Parse a mouse or focus sequence from a buffer.
|
|
127
|
+
*
|
|
128
|
+
* Supports multiple mouse protocols:
|
|
129
|
+
* - X10/X11: Basic mouse reporting (ESC [ M ...)
|
|
130
|
+
* - SGR: Extended mouse reporting with release info (ESC [ < ...)
|
|
131
|
+
* - URXVT: rxvt-unicode mouse format (ESC [ ... M)
|
|
132
|
+
* - DEC: DEC locator format (ESC [ < ... & w)
|
|
133
|
+
* - VT300: VT300 locator format (ESC [ 24X ~ ...)
|
|
134
|
+
*
|
|
135
|
+
* Also handles terminal focus events (ESC [ I/O).
|
|
136
|
+
*
|
|
137
|
+
* @param buffer - Raw input buffer to parse
|
|
138
|
+
* @returns Parsed result or null if not a mouse sequence
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* import { parseMouseSequence } from 'blecsd';
|
|
143
|
+
*
|
|
144
|
+
* // Parse SGR mouse press at (10, 20)
|
|
145
|
+
* const result = parseMouseSequence(Buffer.from('\x1b[<0;10;20M'));
|
|
146
|
+
* if (result?.type === 'mouse') {
|
|
147
|
+
* console.log(result.event.x); // 9 (0-indexed)
|
|
148
|
+
* console.log(result.event.y); // 19 (0-indexed)
|
|
149
|
+
* console.log(result.event.button); // 'left'
|
|
150
|
+
* console.log(result.event.action); // 'press'
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* // Parse focus event
|
|
154
|
+
* const focus = parseMouseSequence(Buffer.from('\x1b[I'));
|
|
155
|
+
* if (focus?.type === 'focus') {
|
|
156
|
+
* console.log(focus.event.focused); // true
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function parseMouseSequence(buffer: Uint8Array): ParseMouseResult;
|
|
161
|
+
/**
|
|
162
|
+
* Check if a buffer contains a mouse sequence.
|
|
163
|
+
*
|
|
164
|
+
* @param buffer - Input buffer to check
|
|
165
|
+
* @returns true if buffer contains a mouse sequence
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { isMouseBuffer } from 'blecsd';
|
|
170
|
+
*
|
|
171
|
+
* const buffer = Buffer.from('\x1b[<0;10;20M');
|
|
172
|
+
* console.log(isMouseBuffer(buffer)); // true
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function isMouseBuffer(buffer: Uint8Array): boolean;
|
|
176
|
+
|
|
177
|
+
export { type FocusEvent as F, type MouseEvent as M, type ParseMouseResult as P, FocusEventSchema as a, type MouseAction as b, type MouseButton as c, MouseEventSchema as d, type MouseProtocol as e, isMouseBuffer as i, parseMouseSequence as p };
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ANSI SGR Attribute Code Parser
|
|
5
|
+
*
|
|
6
|
+
* Parses ANSI SGR (Select Graphic Rendition) codes from escape sequences
|
|
7
|
+
* and converts them to internal attribute representations.
|
|
8
|
+
*
|
|
9
|
+
* @module terminal/ansi/parser
|
|
10
|
+
* @internal This module is internal and not exported from the main package.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Text style flags packed as a bitmask.
|
|
15
|
+
*/
|
|
16
|
+
declare const TextStyle: {
|
|
17
|
+
readonly NONE: 0;
|
|
18
|
+
readonly BOLD: number;
|
|
19
|
+
readonly DIM: number;
|
|
20
|
+
readonly ITALIC: number;
|
|
21
|
+
readonly UNDERLINE: number;
|
|
22
|
+
readonly BLINK: number;
|
|
23
|
+
readonly RAPID_BLINK: number;
|
|
24
|
+
readonly INVERSE: number;
|
|
25
|
+
readonly HIDDEN: number;
|
|
26
|
+
readonly STRIKETHROUGH: number;
|
|
27
|
+
readonly DOUBLE_UNDERLINE: number;
|
|
28
|
+
readonly OVERLINE: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Color type enum for internal representation.
|
|
32
|
+
*/
|
|
33
|
+
declare const ColorType: {
|
|
34
|
+
readonly DEFAULT: 0;
|
|
35
|
+
readonly BASIC: 1;
|
|
36
|
+
readonly COLOR_256: 2;
|
|
37
|
+
readonly RGB: 3;
|
|
38
|
+
};
|
|
39
|
+
type ColorTypeValue = (typeof ColorType)[keyof typeof ColorType];
|
|
40
|
+
/**
|
|
41
|
+
* Internal color representation.
|
|
42
|
+
*/
|
|
43
|
+
interface InternalColor {
|
|
44
|
+
type: ColorTypeValue;
|
|
45
|
+
/** For BASIC: 0-15, for COLOR_256: 0-255, for RGB: packed as 0xRRGGBB */
|
|
46
|
+
value: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Terminal attribute representation.
|
|
50
|
+
*/
|
|
51
|
+
interface Attribute {
|
|
52
|
+
/** Foreground color */
|
|
53
|
+
fg: InternalColor;
|
|
54
|
+
/** Background color */
|
|
55
|
+
bg: InternalColor;
|
|
56
|
+
/** Style flags bitmask */
|
|
57
|
+
styles: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Zod schema for Attribute validation.
|
|
61
|
+
*/
|
|
62
|
+
declare const AttributeSchema: z.ZodObject<{
|
|
63
|
+
fg: z.ZodObject<{
|
|
64
|
+
type: z.ZodNumber;
|
|
65
|
+
value: z.ZodNumber;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
bg: z.ZodObject<{
|
|
68
|
+
type: z.ZodNumber;
|
|
69
|
+
value: z.ZodNumber;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
styles: z.ZodNumber;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
/**
|
|
74
|
+
* Default attribute (reset state).
|
|
75
|
+
*/
|
|
76
|
+
declare const DEFAULT_ATTRIBUTE: Readonly<Attribute>;
|
|
77
|
+
/**
|
|
78
|
+
* Create a new attribute with default values.
|
|
79
|
+
*
|
|
80
|
+
* @returns New attribute object
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const attr = createAttribute();
|
|
85
|
+
* // attr.fg.type === ColorType.DEFAULT
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function createAttribute(): Attribute;
|
|
89
|
+
/**
|
|
90
|
+
* Clone an attribute.
|
|
91
|
+
*
|
|
92
|
+
* @param attr - Attribute to clone
|
|
93
|
+
* @returns New attribute object
|
|
94
|
+
*/
|
|
95
|
+
declare function cloneAttribute(attr: Attribute): Attribute;
|
|
96
|
+
/**
|
|
97
|
+
* Extract SGR code sequences from a string.
|
|
98
|
+
*
|
|
99
|
+
* @param input - String containing ANSI sequences
|
|
100
|
+
* @returns Array of SGR code arrays
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const codes = extractSgrCodes('\x1b[1;31m');
|
|
105
|
+
* // codes = [[1, 31]]
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function extractSgrCodes(input: string): number[][];
|
|
109
|
+
/**
|
|
110
|
+
* Apply a sequence of SGR codes to an attribute.
|
|
111
|
+
*
|
|
112
|
+
* @param codes - Array of SGR code numbers
|
|
113
|
+
* @param attr - Attribute to modify (mutated in place)
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const attr = createAttribute();
|
|
118
|
+
* applySgrCodes([1, 31], attr);
|
|
119
|
+
* // attr now has bold style and red foreground
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare function applySgrCodes(codes: readonly number[], attr: Attribute): void;
|
|
123
|
+
declare function parseSgrString(input: string, attr: Attribute): void;
|
|
124
|
+
/**
|
|
125
|
+
* Apply a single SGR code to an attribute, returning a new attribute.
|
|
126
|
+
* This is the main entry point for processing individual codes.
|
|
127
|
+
*
|
|
128
|
+
* @param code - SGR code number or array of codes
|
|
129
|
+
* @param attr - Current attribute
|
|
130
|
+
* @param defaultAttr - Default attribute to reset to (default: DEFAULT_ATTRIBUTE)
|
|
131
|
+
* @returns New attribute with code applied
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const attr = createAttribute();
|
|
136
|
+
* const newAttr = attrCode(1, attr); // Apply bold
|
|
137
|
+
* const redAttr = attrCode([31], newAttr); // Apply red
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare function attrCode(code: number | readonly number[], attr: Attribute, defaultAttr?: Attribute): Attribute;
|
|
141
|
+
/**
|
|
142
|
+
* Color depth for output.
|
|
143
|
+
*/
|
|
144
|
+
type OutputColorDepth = 'truecolor' | '256' | '16' | 'none';
|
|
145
|
+
/**
|
|
146
|
+
* Options for codeAttr.
|
|
147
|
+
*/
|
|
148
|
+
interface CodeAttrOptions {
|
|
149
|
+
/** Maximum color depth to output. Defaults to 'truecolor'. */
|
|
150
|
+
colorDepth?: OutputColorDepth;
|
|
151
|
+
/** Include reset code at start. Defaults to false. */
|
|
152
|
+
includeReset?: boolean;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Convert an attribute to an SGR escape sequence string.
|
|
156
|
+
*
|
|
157
|
+
* This is the reverse of attrCode() - it takes an internal Attribute
|
|
158
|
+
* and converts it to an ANSI escape sequence that will produce that attribute.
|
|
159
|
+
*
|
|
160
|
+
* @param attr - Attribute to convert
|
|
161
|
+
* @param options - Conversion options
|
|
162
|
+
* @returns SGR escape sequence string
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { codeAttr, createAttribute, attrCode, TextStyle } from 'blecsd';
|
|
167
|
+
*
|
|
168
|
+
* // Create a bold red attribute
|
|
169
|
+
* let attr = createAttribute();
|
|
170
|
+
* attr = attrCode([1, 31], attr);
|
|
171
|
+
*
|
|
172
|
+
* // Convert to SGR string
|
|
173
|
+
* const sgr = codeAttr(attr);
|
|
174
|
+
* // sgr = '\x1b[1;31m'
|
|
175
|
+
*
|
|
176
|
+
* // With color depth reduction
|
|
177
|
+
* const sgrReduced = codeAttr(attr, { colorDepth: '16' });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function codeAttr(attr: Attribute, options?: CodeAttrOptions): string;
|
|
181
|
+
/**
|
|
182
|
+
* Convert an attribute to SGR codes array.
|
|
183
|
+
*
|
|
184
|
+
* @param attr - Attribute to convert
|
|
185
|
+
* @param options - Conversion options
|
|
186
|
+
* @returns Array of SGR code numbers
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const codes = attrToSgrCodes(attr);
|
|
191
|
+
* // [1, 31] for bold red
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare function attrToSgrCodes(attr: Attribute, options?: CodeAttrOptions): number[];
|
|
195
|
+
/**
|
|
196
|
+
* Get the SGR reset sequence.
|
|
197
|
+
*
|
|
198
|
+
* @returns Reset SGR sequence
|
|
199
|
+
*/
|
|
200
|
+
declare function sgrReset(): string;
|
|
201
|
+
/**
|
|
202
|
+
* Check if an attribute has a specific style.
|
|
203
|
+
*
|
|
204
|
+
* @param attr - Attribute to check
|
|
205
|
+
* @param style - Style flag from TextStyle
|
|
206
|
+
* @returns true if style is set
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const attr = attrCode(1, createAttribute()); // bold
|
|
211
|
+
* hasStyle(attr, TextStyle.BOLD); // true
|
|
212
|
+
* hasStyle(attr, TextStyle.ITALIC); // false
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function hasStyle(attr: Attribute, style: number): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Check if two attributes are equal.
|
|
218
|
+
*
|
|
219
|
+
* @param a - First attribute
|
|
220
|
+
* @param b - Second attribute
|
|
221
|
+
* @returns true if attributes are equal
|
|
222
|
+
*/
|
|
223
|
+
declare function attributesEqual(a: Attribute, b: Attribute): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Unpack RGB value to components.
|
|
226
|
+
*
|
|
227
|
+
* @param packed - Packed RGB value (0xRRGGBB)
|
|
228
|
+
* @returns RGB components
|
|
229
|
+
*/
|
|
230
|
+
declare function unpackRgb(packed: number): {
|
|
231
|
+
r: number;
|
|
232
|
+
g: number;
|
|
233
|
+
b: number;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Pack RGB components into a single value.
|
|
237
|
+
*
|
|
238
|
+
* @param r - Red component (0-255)
|
|
239
|
+
* @param g - Green component (0-255)
|
|
240
|
+
* @param b - Blue component (0-255)
|
|
241
|
+
* @returns Packed RGB value
|
|
242
|
+
*/
|
|
243
|
+
declare function packRgb(r: number, g: number, b: number): number;
|
|
244
|
+
/**
|
|
245
|
+
* Strip all ANSI escape sequences from a string.
|
|
246
|
+
*
|
|
247
|
+
* @param input - String with ANSI sequences
|
|
248
|
+
* @returns String without ANSI sequences
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* stripAnsi('\x1b[1;31mHello\x1b[0m');
|
|
253
|
+
* // 'Hello'
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
declare function stripAnsi(input: string): string;
|
|
257
|
+
/**
|
|
258
|
+
* Get the visible length of a string (excluding ANSI sequences).
|
|
259
|
+
*
|
|
260
|
+
* @param input - String with possible ANSI sequences
|
|
261
|
+
* @returns Length of visible characters
|
|
262
|
+
*/
|
|
263
|
+
declare function visibleLength(input: string): number;
|
|
264
|
+
|
|
265
|
+
export { type Attribute as A, type CodeAttrOptions as C, DEFAULT_ATTRIBUTE as D, type InternalColor as I, type OutputColorDepth as O, TextStyle as T, AttributeSchema as a, ColorType as b, applySgrCodes as c, attrCode as d, attrToSgrCodes as e, attributesEqual as f, cloneAttribute as g, codeAttr as h, createAttribute as i, extractSgrCodes as j, hasStyle as k, parseSgrString as l, stripAnsi as m, packRgb as p, sgrReset as s, unpackRgb as u, visibleLength as v };
|