agentlas 1.0.41 → 1.0.43
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/CHANGELOG.md +40 -8
- package/engine/agentlas-workforce.cjs +1 -1
- package/engine/commands/index.cjs +5 -5
- package/engine/hephaestus/runtime.cjs +1 -1
- package/engine/storm/storm.cjs +1 -1
- package/engine/storm/swarm.cjs +1 -1
- package/engine/ui/repl.cjs +4 -4
- package/engine/ui/{pitui-screens.cjs → screens.cjs} +143 -6
- package/engine/ui/{pitui-shell.cjs → shell.cjs} +42 -27
- package/engine/ui/width.cjs +1 -1
- package/engine/vendor/mermaid/LICENSE +205 -0
- package/engine/vendor/mermaid/ansi.js +23 -0
- package/engine/vendor/mermaid/canvas.js +366 -0
- package/engine/vendor/mermaid/graph.js +91 -0
- package/engine/vendor/mermaid/index.js +100 -0
- package/engine/vendor/mermaid/labels.js +324 -0
- package/engine/vendor/mermaid/layout-seq.js +194 -0
- package/engine/vendor/mermaid/layout.js +881 -0
- package/engine/vendor/mermaid/package.json +1 -0
- package/engine/vendor/mermaid/parse.js +1108 -0
- package/engine/vendor/mermaid/source-box.js +78 -0
- package/engine/vendor/mermaid/types.js +1 -0
- package/engine/vendor/mermaid/width-data.js +994 -0
- package/engine/vendor/mermaid/width.js +76 -0
- package/engine/vendor/tui/LICENSE +20 -0
- package/engine/vendor/tui/autocomplete.js +632 -0
- package/engine/vendor/tui/components/alt-screen-flash.js +37 -0
- package/engine/vendor/tui/components/box.js +104 -0
- package/engine/vendor/tui/components/cancellable-loader.js +35 -0
- package/engine/vendor/tui/components/editor.js +1961 -0
- package/engine/vendor/tui/components/h-stack.js +43 -0
- package/engine/vendor/tui/components/image.js +90 -0
- package/engine/vendor/tui/components/input.js +378 -0
- package/engine/vendor/tui/components/loader.js +69 -0
- package/engine/vendor/tui/components/markdown.js +806 -0
- package/engine/vendor/tui/components/scroll-view.js +173 -0
- package/engine/vendor/tui/components/select-list.js +159 -0
- package/engine/vendor/tui/components/settings-list.js +182 -0
- package/engine/vendor/tui/components/spacer.js +23 -0
- package/engine/vendor/tui/components/stack.js +111 -0
- package/engine/vendor/tui/components/text.js +89 -0
- package/engine/vendor/tui/components/truncated-text.js +51 -0
- package/engine/vendor/tui/components/v-stack.js +26 -0
- package/engine/vendor/tui/deps/east-asian-width/LICENSE +9 -0
- package/engine/vendor/tui/deps/east-asian-width/index.js +30 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup-data.js +21 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup.js +138 -0
- package/engine/vendor/tui/deps/east-asian-width/utilities.js +24 -0
- package/engine/vendor/tui/deps/marked/LICENSE +44 -0
- package/engine/vendor/tui/deps/marked/index.js +77 -0
- package/engine/vendor/tui/editor-component.js +2 -0
- package/engine/vendor/tui/fuzzy.js +110 -0
- package/engine/vendor/tui/index.js +42 -0
- package/engine/vendor/tui/keybindings.js +209 -0
- package/engine/vendor/tui/keys.js +1174 -0
- package/engine/vendor/tui/kill-ring.js +44 -0
- package/engine/vendor/tui/latex.js +1264 -0
- package/engine/vendor/tui/layout-node.js +6 -0
- package/engine/vendor/tui/layout.js +314 -0
- package/engine/vendor/tui/native-modifiers.js +60 -0
- package/engine/vendor/tui/package.json +1 -0
- package/engine/vendor/tui/stdin-buffer.js +361 -0
- package/engine/vendor/tui/terminal-colors.js +59 -0
- package/engine/vendor/tui/terminal-image.js +518 -0
- package/engine/vendor/tui/terminal.js +436 -0
- package/engine/vendor/tui/tui-alt-screen.js +902 -0
- package/engine/vendor/tui/tui-main-screen.js +533 -0
- package/engine/vendor/tui/tui.js +937 -0
- package/engine/vendor/tui/undo-stack.js +25 -0
- package/engine/vendor/tui/utils.js +1191 -0
- package/engine/vendor/tui/word-navigation.js +96 -0
- package/package.json +2 -6
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StdinBuffer buffers input and emits complete sequences.
|
|
3
|
+
*
|
|
4
|
+
* This is necessary because stdin data events can arrive in partial chunks,
|
|
5
|
+
* especially for escape sequences like mouse events. Without buffering,
|
|
6
|
+
* partial sequences can be misinterpreted as regular keypresses.
|
|
7
|
+
*
|
|
8
|
+
* For example, the mouse SGR sequence `\x1b[<35;20;5m` might arrive as:
|
|
9
|
+
* - Event 1: `\x1b`
|
|
10
|
+
* - Event 2: `[<35`
|
|
11
|
+
* - Event 3: `;20;5m`
|
|
12
|
+
*
|
|
13
|
+
* The buffer accumulates these until a complete sequence is detected.
|
|
14
|
+
* Call the `process()` method to feed input data.
|
|
15
|
+
*
|
|
16
|
+
* Based on code from OpenTUI (https://github.com/anomalyco/opentui)
|
|
17
|
+
* MIT License - Copyright (c) 2025 opentui
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from "events";
|
|
20
|
+
const ESC = "\x1b";
|
|
21
|
+
const BRACKETED_PASTE_START = "\x1b[200~";
|
|
22
|
+
const BRACKETED_PASTE_END = "\x1b[201~";
|
|
23
|
+
/**
|
|
24
|
+
* Check if a string is a complete escape sequence or needs more data
|
|
25
|
+
*/
|
|
26
|
+
function isCompleteSequence(data) {
|
|
27
|
+
if (!data.startsWith(ESC)) {
|
|
28
|
+
return "not-escape";
|
|
29
|
+
}
|
|
30
|
+
if (data.length === 1) {
|
|
31
|
+
return "incomplete";
|
|
32
|
+
}
|
|
33
|
+
const afterEsc = data.slice(1);
|
|
34
|
+
// CSI sequences: ESC [
|
|
35
|
+
if (afterEsc.startsWith("[")) {
|
|
36
|
+
// Check for old-style mouse sequence: ESC[M + 3 bytes
|
|
37
|
+
if (afterEsc.startsWith("[M")) {
|
|
38
|
+
// Old-style mouse needs ESC[M + 3 bytes = 6 total
|
|
39
|
+
return data.length >= 6 ? "complete" : "incomplete";
|
|
40
|
+
}
|
|
41
|
+
return isCompleteCsiSequence(data);
|
|
42
|
+
}
|
|
43
|
+
// OSC sequences: ESC ]
|
|
44
|
+
if (afterEsc.startsWith("]")) {
|
|
45
|
+
return isCompleteOscSequence(data);
|
|
46
|
+
}
|
|
47
|
+
// DCS sequences: ESC P ... ESC \ (includes XTVersion responses)
|
|
48
|
+
if (afterEsc.startsWith("P")) {
|
|
49
|
+
return isCompleteDcsSequence(data);
|
|
50
|
+
}
|
|
51
|
+
// APC sequences: ESC _ ... ESC \ (includes Kitty graphics responses)
|
|
52
|
+
if (afterEsc.startsWith("_")) {
|
|
53
|
+
return isCompleteApcSequence(data);
|
|
54
|
+
}
|
|
55
|
+
// SS3 sequences: ESC O
|
|
56
|
+
if (afterEsc.startsWith("O")) {
|
|
57
|
+
// ESC O followed by a single character
|
|
58
|
+
return afterEsc.length >= 2 ? "complete" : "incomplete";
|
|
59
|
+
}
|
|
60
|
+
// Meta key sequences: ESC followed by a single character
|
|
61
|
+
if (afterEsc.length === 1) {
|
|
62
|
+
return "complete";
|
|
63
|
+
}
|
|
64
|
+
// Unknown escape sequence - treat as complete
|
|
65
|
+
return "complete";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if CSI sequence is complete
|
|
69
|
+
* CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)
|
|
70
|
+
*/
|
|
71
|
+
function isCompleteCsiSequence(data) {
|
|
72
|
+
if (!data.startsWith(`${ESC}[`)) {
|
|
73
|
+
return "complete";
|
|
74
|
+
}
|
|
75
|
+
// Need at least ESC [ and one more character
|
|
76
|
+
if (data.length < 3) {
|
|
77
|
+
return "incomplete";
|
|
78
|
+
}
|
|
79
|
+
const payload = data.slice(2);
|
|
80
|
+
// CSI sequences end with a byte in the range 0x40-0x7E (@-~)
|
|
81
|
+
// This includes all letters and several special characters
|
|
82
|
+
const lastChar = payload[payload.length - 1];
|
|
83
|
+
const lastCharCode = lastChar.charCodeAt(0);
|
|
84
|
+
if (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {
|
|
85
|
+
// Special handling for SGR mouse sequences
|
|
86
|
+
// Format: ESC[<B;X;Ym or ESC[<B;X;YM
|
|
87
|
+
if (payload.startsWith("<")) {
|
|
88
|
+
// Must have format: <digits;digits;digits[Mm]
|
|
89
|
+
const mouseMatch = /^<\d+;\d+;\d+[Mm]$/.test(payload);
|
|
90
|
+
if (mouseMatch) {
|
|
91
|
+
return "complete";
|
|
92
|
+
}
|
|
93
|
+
// If it ends with M or m but doesn't match the pattern, still incomplete
|
|
94
|
+
if (lastChar === "M" || lastChar === "m") {
|
|
95
|
+
// Check if we have the right structure
|
|
96
|
+
const parts = payload.slice(1, -1).split(";");
|
|
97
|
+
if (parts.length === 3 && parts.every((p) => /^\d+$/.test(p))) {
|
|
98
|
+
return "complete";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return "incomplete";
|
|
102
|
+
}
|
|
103
|
+
return "complete";
|
|
104
|
+
}
|
|
105
|
+
return "incomplete";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if OSC sequence is complete
|
|
109
|
+
* OSC sequences: ESC ] ... ST (where ST is ESC \ or BEL)
|
|
110
|
+
*/
|
|
111
|
+
function isCompleteOscSequence(data) {
|
|
112
|
+
if (!data.startsWith(`${ESC}]`)) {
|
|
113
|
+
return "complete";
|
|
114
|
+
}
|
|
115
|
+
// OSC sequences end with ST (ESC \) or BEL (\x07)
|
|
116
|
+
if (data.endsWith(`${ESC}\\`) || data.endsWith("\x07")) {
|
|
117
|
+
return "complete";
|
|
118
|
+
}
|
|
119
|
+
return "incomplete";
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Check if DCS (Device Control String) sequence is complete
|
|
123
|
+
* DCS sequences: ESC P ... ST (where ST is ESC \)
|
|
124
|
+
* Used for XTVersion responses like ESC P >| ... ESC \
|
|
125
|
+
*/
|
|
126
|
+
function isCompleteDcsSequence(data) {
|
|
127
|
+
if (!data.startsWith(`${ESC}P`)) {
|
|
128
|
+
return "complete";
|
|
129
|
+
}
|
|
130
|
+
// DCS sequences end with ST (ESC \)
|
|
131
|
+
if (data.endsWith(`${ESC}\\`)) {
|
|
132
|
+
return "complete";
|
|
133
|
+
}
|
|
134
|
+
return "incomplete";
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if APC (Application Program Command) sequence is complete
|
|
138
|
+
* APC sequences: ESC _ ... ST (where ST is ESC \)
|
|
139
|
+
* Used for Kitty graphics responses like ESC _ G ... ESC \
|
|
140
|
+
*/
|
|
141
|
+
function isCompleteApcSequence(data) {
|
|
142
|
+
if (!data.startsWith(`${ESC}_`)) {
|
|
143
|
+
return "complete";
|
|
144
|
+
}
|
|
145
|
+
// APC sequences end with ST (ESC \)
|
|
146
|
+
if (data.endsWith(`${ESC}\\`)) {
|
|
147
|
+
return "complete";
|
|
148
|
+
}
|
|
149
|
+
return "incomplete";
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Split accumulated buffer into complete sequences
|
|
153
|
+
*/
|
|
154
|
+
function parseUnmodifiedKittyPrintableCodepoint(sequence) {
|
|
155
|
+
const match = sequence.match(/^\x1b\[(\d+)(?::\d*)?(?::\d+)?u$/);
|
|
156
|
+
if (!match)
|
|
157
|
+
return undefined;
|
|
158
|
+
const codepoint = parseInt(match[1], 10);
|
|
159
|
+
return codepoint >= 32 ? codepoint : undefined;
|
|
160
|
+
}
|
|
161
|
+
function extractCompleteSequences(buffer) {
|
|
162
|
+
const sequences = [];
|
|
163
|
+
let pos = 0;
|
|
164
|
+
while (pos < buffer.length) {
|
|
165
|
+
const remaining = buffer.slice(pos);
|
|
166
|
+
// Try to extract a sequence starting at this position
|
|
167
|
+
if (remaining.startsWith(ESC)) {
|
|
168
|
+
// Find the end of this escape sequence
|
|
169
|
+
let seqEnd = 1;
|
|
170
|
+
while (seqEnd <= remaining.length) {
|
|
171
|
+
const candidate = remaining.slice(0, seqEnd);
|
|
172
|
+
const status = isCompleteSequence(candidate);
|
|
173
|
+
if (status === "complete") {
|
|
174
|
+
// WezTerm with enable_kitty_keyboard sends the Escape key press as a
|
|
175
|
+
// raw '\x1b' byte (simple text path in encode_kitty, ignoring
|
|
176
|
+
// DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u
|
|
177
|
+
// sequence. These arrive concatenated as '\x1b\x1b[27;...u'.
|
|
178
|
+
// The buffer would normally treat '\x1b\x1b' as a complete meta-key
|
|
179
|
+
// sequence (ESC + single char), leaving '[27;...u' to be typed as
|
|
180
|
+
// plain text. If the character immediately following '\x1b\x1b'
|
|
181
|
+
// would begin a new escape sequence, emit only the first ESC and
|
|
182
|
+
// restart from the second.
|
|
183
|
+
if (candidate === "\x1b\x1b") {
|
|
184
|
+
const nextChar = remaining[seqEnd];
|
|
185
|
+
if (nextChar === "[" || // CSI
|
|
186
|
+
nextChar === "]" || // OSC
|
|
187
|
+
nextChar === "O" || // SS3
|
|
188
|
+
nextChar === "P" || // DCS
|
|
189
|
+
nextChar === "_" // APC
|
|
190
|
+
) {
|
|
191
|
+
sequences.push(ESC);
|
|
192
|
+
pos += 1;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
sequences.push(candidate);
|
|
197
|
+
pos += seqEnd;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
else if (status === "incomplete") {
|
|
201
|
+
seqEnd++;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// Should not happen when starting with ESC
|
|
205
|
+
sequences.push(candidate);
|
|
206
|
+
pos += seqEnd;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (seqEnd > remaining.length) {
|
|
211
|
+
return { sequences, remainder: remaining };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// Not an escape sequence - take a single character
|
|
216
|
+
sequences.push(remaining[0]);
|
|
217
|
+
pos++;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { sequences, remainder: "" };
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Buffers stdin input and emits complete sequences via the 'data' event.
|
|
224
|
+
* Handles partial escape sequences that arrive across multiple chunks.
|
|
225
|
+
*/
|
|
226
|
+
export class StdinBuffer extends EventEmitter {
|
|
227
|
+
buffer = "";
|
|
228
|
+
timeout = null;
|
|
229
|
+
timeoutMs;
|
|
230
|
+
pasteMode = false;
|
|
231
|
+
pasteBuffer = "";
|
|
232
|
+
pendingKittyPrintableCodepoint;
|
|
233
|
+
constructor(options = {}) {
|
|
234
|
+
super();
|
|
235
|
+
this.timeoutMs = options.timeout ?? 10;
|
|
236
|
+
}
|
|
237
|
+
process(data) {
|
|
238
|
+
// Clear any pending timeout
|
|
239
|
+
if (this.timeout) {
|
|
240
|
+
clearTimeout(this.timeout);
|
|
241
|
+
this.timeout = null;
|
|
242
|
+
}
|
|
243
|
+
// Handle high-byte conversion (for compatibility with parseKeypress)
|
|
244
|
+
// If buffer has single byte > 127, convert to ESC + (byte - 128)
|
|
245
|
+
let str;
|
|
246
|
+
if (Buffer.isBuffer(data)) {
|
|
247
|
+
if (data.length === 1 && data[0] > 127) {
|
|
248
|
+
const byte = data[0] - 128;
|
|
249
|
+
str = `\x1b${String.fromCharCode(byte)}`;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
str = data.toString();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
str = data;
|
|
257
|
+
}
|
|
258
|
+
if (str.length === 0 && this.buffer.length === 0) {
|
|
259
|
+
this.emitDataSequence("");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.buffer += str;
|
|
263
|
+
if (this.pasteMode) {
|
|
264
|
+
this.pasteBuffer += this.buffer;
|
|
265
|
+
this.buffer = "";
|
|
266
|
+
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
267
|
+
if (endIndex !== -1) {
|
|
268
|
+
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
269
|
+
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
270
|
+
this.pasteMode = false;
|
|
271
|
+
this.pasteBuffer = "";
|
|
272
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
273
|
+
this.emit("paste", pastedContent);
|
|
274
|
+
if (remaining.length > 0) {
|
|
275
|
+
this.process(remaining);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);
|
|
281
|
+
if (startIndex !== -1) {
|
|
282
|
+
if (startIndex > 0) {
|
|
283
|
+
const beforePaste = this.buffer.slice(0, startIndex);
|
|
284
|
+
const result = extractCompleteSequences(beforePaste);
|
|
285
|
+
for (const sequence of result.sequences) {
|
|
286
|
+
this.emitDataSequence(sequence);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
290
|
+
this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);
|
|
291
|
+
this.pasteMode = true;
|
|
292
|
+
this.pasteBuffer = this.buffer;
|
|
293
|
+
this.buffer = "";
|
|
294
|
+
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
295
|
+
if (endIndex !== -1) {
|
|
296
|
+
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
297
|
+
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
298
|
+
this.pasteMode = false;
|
|
299
|
+
this.pasteBuffer = "";
|
|
300
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
301
|
+
this.emit("paste", pastedContent);
|
|
302
|
+
if (remaining.length > 0) {
|
|
303
|
+
this.process(remaining);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const result = extractCompleteSequences(this.buffer);
|
|
309
|
+
this.buffer = result.remainder;
|
|
310
|
+
for (const sequence of result.sequences) {
|
|
311
|
+
this.emitDataSequence(sequence);
|
|
312
|
+
}
|
|
313
|
+
if (this.buffer.length > 0) {
|
|
314
|
+
this.timeout = setTimeout(() => {
|
|
315
|
+
const flushed = this.flush();
|
|
316
|
+
for (const sequence of flushed) {
|
|
317
|
+
this.emitDataSequence(sequence);
|
|
318
|
+
}
|
|
319
|
+
}, this.timeoutMs);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
emitDataSequence(sequence) {
|
|
323
|
+
const rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;
|
|
324
|
+
if (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {
|
|
325
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);
|
|
329
|
+
this.emit("data", sequence);
|
|
330
|
+
}
|
|
331
|
+
flush() {
|
|
332
|
+
if (this.timeout) {
|
|
333
|
+
clearTimeout(this.timeout);
|
|
334
|
+
this.timeout = null;
|
|
335
|
+
}
|
|
336
|
+
if (this.buffer.length === 0) {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
const sequences = [this.buffer];
|
|
340
|
+
this.buffer = "";
|
|
341
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
342
|
+
return sequences;
|
|
343
|
+
}
|
|
344
|
+
clear() {
|
|
345
|
+
if (this.timeout) {
|
|
346
|
+
clearTimeout(this.timeout);
|
|
347
|
+
this.timeout = null;
|
|
348
|
+
}
|
|
349
|
+
this.buffer = "";
|
|
350
|
+
this.pasteMode = false;
|
|
351
|
+
this.pasteBuffer = "";
|
|
352
|
+
this.pendingKittyPrintableCodepoint = undefined;
|
|
353
|
+
}
|
|
354
|
+
getBuffer() {
|
|
355
|
+
return this.buffer;
|
|
356
|
+
}
|
|
357
|
+
destroy() {
|
|
358
|
+
this.clear();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
//# sourceMappingURL=stdin-buffer.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function hexToRgb(hex) {
|
|
2
|
+
const normalized = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
3
|
+
const r = parseInt(normalized.slice(0, 2), 16);
|
|
4
|
+
const g = parseInt(normalized.slice(2, 4), 16);
|
|
5
|
+
const b = parseInt(normalized.slice(4, 6), 16);
|
|
6
|
+
return { r, g, b };
|
|
7
|
+
}
|
|
8
|
+
function parseOscHexChannel(channel) {
|
|
9
|
+
if (!/^[0-9a-f]+$/i.test(channel)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const max = 16 ** channel.length - 1;
|
|
13
|
+
if (max <= 0) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return Math.round((parseInt(channel, 16) / max) * 255);
|
|
17
|
+
}
|
|
18
|
+
const OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN = /^\x1b\]11;([^\x07\x1b]*)(?:\x07|\x1b\\)$/i;
|
|
19
|
+
const COLOR_SCHEME_REPORT_PATTERN = /^(?:\x1b\[\?997;(1|2)n)+$/;
|
|
20
|
+
export function isOsc11BackgroundColorResponse(data) {
|
|
21
|
+
return OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN.test(data);
|
|
22
|
+
}
|
|
23
|
+
export function parseOsc11BackgroundColor(data) {
|
|
24
|
+
const match = data.match(OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN);
|
|
25
|
+
if (!match) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const value = match[1].trim();
|
|
29
|
+
if (value.startsWith("#")) {
|
|
30
|
+
const hex = value.slice(1);
|
|
31
|
+
if (/^[0-9a-f]{6}$/i.test(hex)) {
|
|
32
|
+
return hexToRgb(value);
|
|
33
|
+
}
|
|
34
|
+
if (/^[0-9a-f]{12}$/i.test(hex)) {
|
|
35
|
+
const r = parseOscHexChannel(hex.slice(0, 4));
|
|
36
|
+
const g = parseOscHexChannel(hex.slice(4, 8));
|
|
37
|
+
const b = parseOscHexChannel(hex.slice(8, 12));
|
|
38
|
+
return r !== undefined && g !== undefined && b !== undefined ? { r, g, b } : undefined;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const rgbValue = value.replace(/^rgba?:/i, "");
|
|
43
|
+
const [red, green, blue] = rgbValue.split("/");
|
|
44
|
+
if (red === undefined || green === undefined || blue === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const r = parseOscHexChannel(red);
|
|
48
|
+
const g = parseOscHexChannel(green);
|
|
49
|
+
const b = parseOscHexChannel(blue);
|
|
50
|
+
return r !== undefined && g !== undefined && b !== undefined ? { r, g, b } : undefined;
|
|
51
|
+
}
|
|
52
|
+
export function parseTerminalColorSchemeReport(data) {
|
|
53
|
+
const match = data.match(COLOR_SCHEME_REPORT_PATTERN);
|
|
54
|
+
if (!match) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return match[1] === "2" ? "light" : "dark";
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=terminal-colors.js.map
|