@oracle-agent/oracle 0.9.6 → 0.9.8
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/package.json +1 -1
- package/public/oracle-splash/index.html +105 -1
- package/src/cards.mjs +369 -0
- package/src/cli/__pycache__/oracle-harness.cpython-311.pyc +0 -0
- package/src/cli/commands/chat.mjs +31 -2
- package/src/cli/oracle-harness.py +29 -8
- package/src/router/best-execution.mjs +105 -0
- package/src/router/index.mjs +42 -1
- package/src/router/prepare-route.mjs +17 -1
- package/src/tui/app.mjs +427 -0
- package/src/tui/format.mjs +272 -0
- package/src/tui/gateway-client.mjs +177 -0
- package/src/tui/input.mjs +501 -0
- package/src/tui/renderer.mjs +443 -0
- package/src/tui/theme.mjs +81 -0
- package/protocols/templates/safe-erc20/README.md +0 -9
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
const HIDE_CURSOR = "\u001b[?25l";
|
|
2
|
+
const SHOW_CURSOR = "\u001b[?25h";
|
|
3
|
+
const CLEAR_LINE = "\u001b[2K";
|
|
4
|
+
const ERASE_DOWN = "\u001b[0J";
|
|
5
|
+
const DEFAULT_ROWS = 24;
|
|
6
|
+
const DEFAULT_COLUMNS = 80;
|
|
7
|
+
const ANSI_SOURCE = "\u001b\\[[0-9;?]*[a-zA-Z]";
|
|
8
|
+
|
|
9
|
+
function ansiRegex() {
|
|
10
|
+
return new RegExp(ANSI_SOURCE, "g");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function stripAnsi(text) {
|
|
14
|
+
return String(text ?? "").replace(ansiRegex(), "");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function inRanges(code, ranges) {
|
|
18
|
+
return ranges.some(([start, end]) => code >= start && code <= end);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function codePointWidth(code) {
|
|
22
|
+
if (code === 0) return 0;
|
|
23
|
+
if (code < 32 || (code >= 0x7f && code < 0xa0)) return 0;
|
|
24
|
+
if (inRanges(code, [
|
|
25
|
+
[0x0300, 0x036f],
|
|
26
|
+
[0x0483, 0x0489],
|
|
27
|
+
[0x0591, 0x05bd],
|
|
28
|
+
[0x05bf, 0x05bf],
|
|
29
|
+
[0x05c1, 0x05c2],
|
|
30
|
+
[0x05c4, 0x05c5],
|
|
31
|
+
[0x05c7, 0x05c7],
|
|
32
|
+
[0x0610, 0x061a],
|
|
33
|
+
[0x064b, 0x065f],
|
|
34
|
+
[0x0670, 0x0670],
|
|
35
|
+
[0x06d6, 0x06dd],
|
|
36
|
+
[0x06df, 0x06e4],
|
|
37
|
+
[0x06e7, 0x06e8],
|
|
38
|
+
[0x06ea, 0x06ed],
|
|
39
|
+
[0x0711, 0x0711],
|
|
40
|
+
[0x0730, 0x074a],
|
|
41
|
+
[0x07a6, 0x07b0],
|
|
42
|
+
[0x07eb, 0x07f3],
|
|
43
|
+
[0x0816, 0x0819],
|
|
44
|
+
[0x081b, 0x0823],
|
|
45
|
+
[0x0825, 0x0827],
|
|
46
|
+
[0x0829, 0x082d],
|
|
47
|
+
[0x0859, 0x085b],
|
|
48
|
+
[0x08d3, 0x08e1],
|
|
49
|
+
[0x08e3, 0x0903],
|
|
50
|
+
[0x093a, 0x093c],
|
|
51
|
+
[0x0941, 0x0948],
|
|
52
|
+
[0x094d, 0x094d],
|
|
53
|
+
[0x0951, 0x0957],
|
|
54
|
+
[0x0962, 0x0963],
|
|
55
|
+
[0x0981, 0x0981],
|
|
56
|
+
[0x09bc, 0x09bc],
|
|
57
|
+
[0x09c1, 0x09c4],
|
|
58
|
+
[0x09cd, 0x09cd],
|
|
59
|
+
[0x09e2, 0x09e3],
|
|
60
|
+
[0x0a01, 0x0a02],
|
|
61
|
+
[0x0a3c, 0x0a3c],
|
|
62
|
+
[0x0a41, 0x0a42],
|
|
63
|
+
[0x0a47, 0x0a48],
|
|
64
|
+
[0x0a4b, 0x0a4d],
|
|
65
|
+
[0x0a51, 0x0a51],
|
|
66
|
+
[0x0a70, 0x0a71],
|
|
67
|
+
[0x0a75, 0x0a75],
|
|
68
|
+
[0x0a81, 0x0a82],
|
|
69
|
+
[0x0abc, 0x0abc],
|
|
70
|
+
[0x0ac1, 0x0ac5],
|
|
71
|
+
[0x0ac7, 0x0ac8],
|
|
72
|
+
[0x0acd, 0x0acd],
|
|
73
|
+
[0x0ae2, 0x0ae3],
|
|
74
|
+
[0x0b01, 0x0b01],
|
|
75
|
+
[0x0b3c, 0x0b3c],
|
|
76
|
+
[0x0b3f, 0x0b3f],
|
|
77
|
+
[0x0b41, 0x0b44],
|
|
78
|
+
[0x0b4d, 0x0b4d],
|
|
79
|
+
[0x0b56, 0x0b56],
|
|
80
|
+
[0x0b62, 0x0b63],
|
|
81
|
+
[0x0b82, 0x0b82],
|
|
82
|
+
[0x0bc0, 0x0bc0],
|
|
83
|
+
[0x0bcd, 0x0bcd],
|
|
84
|
+
[0x0c00, 0x0c00],
|
|
85
|
+
[0x0c3e, 0x0c40],
|
|
86
|
+
[0x0c46, 0x0c48],
|
|
87
|
+
[0x0c4a, 0x0c4d],
|
|
88
|
+
[0x0c55, 0x0c56],
|
|
89
|
+
[0x0c62, 0x0c63],
|
|
90
|
+
[0x0c81, 0x0c81],
|
|
91
|
+
[0x0cbc, 0x0cbc],
|
|
92
|
+
[0x0cbf, 0x0cbf],
|
|
93
|
+
[0x0cc6, 0x0cc6],
|
|
94
|
+
[0x0ccc, 0x0ccd],
|
|
95
|
+
[0x0ce2, 0x0ce3],
|
|
96
|
+
[0x0d01, 0x0d01],
|
|
97
|
+
[0x0d41, 0x0d44],
|
|
98
|
+
[0x0d4d, 0x0d4d],
|
|
99
|
+
[0x0d62, 0x0d63],
|
|
100
|
+
[0x0dd2, 0x0dd4],
|
|
101
|
+
[0x0dd6, 0x0dd6],
|
|
102
|
+
[0x0e31, 0x0e31],
|
|
103
|
+
[0x0e34, 0x0e3a],
|
|
104
|
+
[0x0e47, 0x0e4e],
|
|
105
|
+
[0x0eb1, 0x0eb1],
|
|
106
|
+
[0x0eb4, 0x0eb9],
|
|
107
|
+
[0x0ebb, 0x0ebc],
|
|
108
|
+
[0x0ec8, 0x0ecd],
|
|
109
|
+
[0x0f18, 0x0f19],
|
|
110
|
+
[0x0f35, 0x0f35],
|
|
111
|
+
[0x0f37, 0x0f37],
|
|
112
|
+
[0x0f39, 0x0f39],
|
|
113
|
+
[0x0f71, 0x0f7e],
|
|
114
|
+
[0x0f80, 0x0f84],
|
|
115
|
+
[0x0f86, 0x0f87],
|
|
116
|
+
[0x0f8d, 0x0f97],
|
|
117
|
+
[0x0f99, 0x0fbc],
|
|
118
|
+
[0x0fc6, 0x0fc6],
|
|
119
|
+
[0x102d, 0x1030],
|
|
120
|
+
[0x1032, 0x1037],
|
|
121
|
+
[0x1039, 0x103a],
|
|
122
|
+
[0x103d, 0x103e],
|
|
123
|
+
[0x1058, 0x1059],
|
|
124
|
+
[0x105e, 0x1060],
|
|
125
|
+
[0x1071, 0x1074],
|
|
126
|
+
[0x1082, 0x1082],
|
|
127
|
+
[0x1085, 0x1086],
|
|
128
|
+
[0x108d, 0x108d],
|
|
129
|
+
[0x109d, 0x109d],
|
|
130
|
+
[0x135d, 0x135f],
|
|
131
|
+
[0x1712, 0x1714],
|
|
132
|
+
[0x1732, 0x1734],
|
|
133
|
+
[0x1752, 0x1753],
|
|
134
|
+
[0x1772, 0x1773],
|
|
135
|
+
[0x17b4, 0x17b5],
|
|
136
|
+
[0x17b7, 0x17bd],
|
|
137
|
+
[0x17c6, 0x17c6],
|
|
138
|
+
[0x17c9, 0x17d3],
|
|
139
|
+
[0x17dd, 0x17dd],
|
|
140
|
+
[0x180b, 0x180d],
|
|
141
|
+
[0x1885, 0x1886],
|
|
142
|
+
[0x18a9, 0x18a9],
|
|
143
|
+
[0x1920, 0x1922],
|
|
144
|
+
[0x1927, 0x1928],
|
|
145
|
+
[0x1932, 0x1932],
|
|
146
|
+
[0x1939, 0x193b],
|
|
147
|
+
[0x1a17, 0x1a18],
|
|
148
|
+
[0x1a1b, 0x1a1b],
|
|
149
|
+
[0x1a56, 0x1a56],
|
|
150
|
+
[0x1a58, 0x1a5e],
|
|
151
|
+
[0x1a60, 0x1a60],
|
|
152
|
+
[0x1a62, 0x1a62],
|
|
153
|
+
[0x1a65, 0x1a6c],
|
|
154
|
+
[0x1a73, 0x1a7c],
|
|
155
|
+
[0x1a7f, 0x1a7f],
|
|
156
|
+
[0x1ab0, 0x1aff],
|
|
157
|
+
[0x1b00, 0x1b03],
|
|
158
|
+
[0x1b34, 0x1b34],
|
|
159
|
+
[0x1b36, 0x1b3a],
|
|
160
|
+
[0x1b3c, 0x1b3c],
|
|
161
|
+
[0x1b42, 0x1b42],
|
|
162
|
+
[0x1b6b, 0x1b73],
|
|
163
|
+
[0x1b80, 0x1b81],
|
|
164
|
+
[0x1ba2, 0x1ba5],
|
|
165
|
+
[0x1ba8, 0x1ba9],
|
|
166
|
+
[0x1bab, 0x1bad],
|
|
167
|
+
[0x1be6, 0x1be6],
|
|
168
|
+
[0x1be8, 0x1be9],
|
|
169
|
+
[0x1bed, 0x1bed],
|
|
170
|
+
[0x1bef, 0x1bf1],
|
|
171
|
+
[0x1c2c, 0x1c33],
|
|
172
|
+
[0x1c36, 0x1c37],
|
|
173
|
+
[0x1cd0, 0x1cd2],
|
|
174
|
+
[0x1cd4, 0x1ce0],
|
|
175
|
+
[0x1ce2, 0x1ce8],
|
|
176
|
+
[0x1ced, 0x1ced],
|
|
177
|
+
[0x1cf4, 0x1cf4],
|
|
178
|
+
[0x1cf8, 0x1cf9],
|
|
179
|
+
[0x1dc0, 0x1dff],
|
|
180
|
+
[0x200b, 0x200f],
|
|
181
|
+
[0x202a, 0x202e],
|
|
182
|
+
[0x2060, 0x2064],
|
|
183
|
+
[0x2066, 0x206f],
|
|
184
|
+
[0x20d0, 0x20ff],
|
|
185
|
+
[0xfe00, 0xfe0f],
|
|
186
|
+
[0xfe20, 0xfe2f],
|
|
187
|
+
[0xe0100, 0xe01ef],
|
|
188
|
+
])) return 0;
|
|
189
|
+
if (inRanges(code, [
|
|
190
|
+
[0x1100, 0x115f],
|
|
191
|
+
[0x231a, 0x231b],
|
|
192
|
+
[0x2329, 0x232a],
|
|
193
|
+
[0x23e9, 0x23ec],
|
|
194
|
+
[0x23f0, 0x23f0],
|
|
195
|
+
[0x23f3, 0x23f3],
|
|
196
|
+
[0x25fd, 0x25fe],
|
|
197
|
+
[0x2614, 0x2615],
|
|
198
|
+
[0x2648, 0x2653],
|
|
199
|
+
[0x267f, 0x267f],
|
|
200
|
+
[0x2693, 0x2693],
|
|
201
|
+
[0x26a1, 0x26a1],
|
|
202
|
+
[0x26aa, 0x26ab],
|
|
203
|
+
[0x26bd, 0x26be],
|
|
204
|
+
[0x26c4, 0x26c5],
|
|
205
|
+
[0x26ce, 0x26ce],
|
|
206
|
+
[0x26d4, 0x26d4],
|
|
207
|
+
[0x26ea, 0x26ea],
|
|
208
|
+
[0x26f2, 0x26f3],
|
|
209
|
+
[0x26f5, 0x26f5],
|
|
210
|
+
[0x26fa, 0x26fa],
|
|
211
|
+
[0x26fd, 0x26fd],
|
|
212
|
+
[0x2705, 0x2705],
|
|
213
|
+
[0x270a, 0x270b],
|
|
214
|
+
[0x2728, 0x2728],
|
|
215
|
+
[0x274c, 0x274c],
|
|
216
|
+
[0x274e, 0x274e],
|
|
217
|
+
[0x2753, 0x2755],
|
|
218
|
+
[0x2757, 0x2757],
|
|
219
|
+
[0x2795, 0x2797],
|
|
220
|
+
[0x27b0, 0x27b0],
|
|
221
|
+
[0x27bf, 0x27bf],
|
|
222
|
+
[0x2b1b, 0x2b1c],
|
|
223
|
+
[0x2b50, 0x2b50],
|
|
224
|
+
[0x2b55, 0x2b55],
|
|
225
|
+
[0x2e80, 0x303e],
|
|
226
|
+
[0x3040, 0xa4cf],
|
|
227
|
+
[0xac00, 0xd7a3],
|
|
228
|
+
[0xf900, 0xfaff],
|
|
229
|
+
[0xfe10, 0xfe19],
|
|
230
|
+
[0xfe30, 0xfe6f],
|
|
231
|
+
[0xff00, 0xff60],
|
|
232
|
+
[0xffe0, 0xffe6],
|
|
233
|
+
[0x1f300, 0x1f64f],
|
|
234
|
+
[0x1f900, 0x1f9ff],
|
|
235
|
+
[0x20000, 0x3fffd],
|
|
236
|
+
])) return 2;
|
|
237
|
+
return 1;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function stringWidth(text) {
|
|
241
|
+
let width = 0;
|
|
242
|
+
for (const point of Array.from(text)) {
|
|
243
|
+
width += codePointWidth(point.codePointAt(0));
|
|
244
|
+
}
|
|
245
|
+
return width;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function visibleWidth(text) {
|
|
249
|
+
return stringWidth(stripAnsi(text));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isReset(sequence) {
|
|
253
|
+
return /^\u001b\[0*m$/.test(sequence);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function takeVisible(chunk, budget) {
|
|
257
|
+
let text = "";
|
|
258
|
+
let width = 0;
|
|
259
|
+
for (const point of Array.from(chunk)) {
|
|
260
|
+
const nextWidth = codePointWidth(point.codePointAt(0));
|
|
261
|
+
if (width + nextWidth > budget) break;
|
|
262
|
+
text += point;
|
|
263
|
+
width += nextWidth;
|
|
264
|
+
}
|
|
265
|
+
return { text, width };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function truncateToWidth(text, max) {
|
|
269
|
+
const source = String(text ?? "");
|
|
270
|
+
if (max <= 0) return "";
|
|
271
|
+
if (visibleWidth(source) <= max) return source;
|
|
272
|
+
|
|
273
|
+
const re = ansiRegex();
|
|
274
|
+
let out = "";
|
|
275
|
+
let width = 0;
|
|
276
|
+
let styled = false;
|
|
277
|
+
let cursor = 0;
|
|
278
|
+
let match = re.exec(source);
|
|
279
|
+
|
|
280
|
+
while (match !== null) {
|
|
281
|
+
const taken = takeVisible(source.slice(cursor, match.index), max - width);
|
|
282
|
+
out += taken.text;
|
|
283
|
+
width += taken.width;
|
|
284
|
+
if (width >= max) return styled ? `${out}\u001b[0m` : out;
|
|
285
|
+
out += match[0];
|
|
286
|
+
if (match[0].endsWith("m")) styled = !isReset(match[0]);
|
|
287
|
+
cursor = match.index + match[0].length;
|
|
288
|
+
match = re.exec(source);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const tail = takeVisible(source.slice(cursor), max - width);
|
|
292
|
+
out += tail.text;
|
|
293
|
+
return styled ? `${out}\u001b[0m` : out;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function sameLines(a, b) {
|
|
297
|
+
if (a.length !== b.length) return false;
|
|
298
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
299
|
+
if (a[i] !== b[i]) return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function createRenderer({ stdout, rows, columns } = {}) {
|
|
305
|
+
if (!stdout || typeof stdout.write !== "function") {
|
|
306
|
+
throw new TypeError("createRenderer requires a stdout with a write(string) method");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const fixedRows = Number.isFinite(rows) ? Math.trunc(rows) : null;
|
|
310
|
+
const fixedColumns = Number.isFinite(columns) ? Math.trunc(columns) : null;
|
|
311
|
+
|
|
312
|
+
let currentRows = fixedRows ?? (Number.isFinite(stdout.rows) ? Math.trunc(stdout.rows) : DEFAULT_ROWS);
|
|
313
|
+
let currentColumns = fixedColumns ?? (Number.isFinite(stdout.columns) ? Math.trunc(stdout.columns) : DEFAULT_COLUMNS);
|
|
314
|
+
|
|
315
|
+
let painted = [];
|
|
316
|
+
let cursorRow = 0;
|
|
317
|
+
let regionHeight = null;
|
|
318
|
+
let forceFull = false;
|
|
319
|
+
let disposed = false;
|
|
320
|
+
|
|
321
|
+
const onResize = () => {
|
|
322
|
+
if (fixedRows === null) currentRows = Number.isFinite(stdout.rows) ? Math.trunc(stdout.rows) : DEFAULT_ROWS;
|
|
323
|
+
if (fixedColumns === null) currentColumns = Number.isFinite(stdout.columns) ? Math.trunc(stdout.columns) : DEFAULT_COLUMNS;
|
|
324
|
+
forceFull = true;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const listens = typeof stdout.on === "function";
|
|
328
|
+
if (listens) stdout.on("resize", onResize);
|
|
329
|
+
|
|
330
|
+
function moveTo(row) {
|
|
331
|
+
const delta = row - cursorRow;
|
|
332
|
+
cursorRow = row;
|
|
333
|
+
if (delta === 0) return "";
|
|
334
|
+
if (delta < 0) return `\u001b[${-delta}A`;
|
|
335
|
+
return `\u001b[${delta}B`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function normalize(input) {
|
|
339
|
+
const source = Array.isArray(input) ? input : [];
|
|
340
|
+
let out = source.map((line) => truncateToWidth(String(line ?? ""), currentColumns));
|
|
341
|
+
if (regionHeight !== null) {
|
|
342
|
+
if (out.length > regionHeight) out = out.slice(0, regionHeight);
|
|
343
|
+
while (out.length < regionHeight) out.push("");
|
|
344
|
+
}
|
|
345
|
+
return out;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function paint(target) {
|
|
349
|
+
if (!forceFull && sameLines(painted, target)) return;
|
|
350
|
+
|
|
351
|
+
const out = [HIDE_CURSOR];
|
|
352
|
+
|
|
353
|
+
if (forceFull && painted.length > 0) {
|
|
354
|
+
out.push(moveTo(0), "\r", ERASE_DOWN);
|
|
355
|
+
painted = [];
|
|
356
|
+
cursorRow = 0;
|
|
357
|
+
}
|
|
358
|
+
forceFull = false;
|
|
359
|
+
|
|
360
|
+
const shared = Math.min(painted.length, target.length);
|
|
361
|
+
for (let i = 0; i < shared; i += 1) {
|
|
362
|
+
if (painted[i] === target[i]) continue;
|
|
363
|
+
out.push(moveTo(i), "\r", CLEAR_LINE, target[i]);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (target.length > painted.length) {
|
|
367
|
+
if (painted.length > 0) out.push(moveTo(painted.length - 1));
|
|
368
|
+
for (let i = painted.length; i < target.length; i += 1) {
|
|
369
|
+
if (i > 0) out.push("\n");
|
|
370
|
+
out.push("\r", CLEAR_LINE, target[i]);
|
|
371
|
+
cursorRow = i;
|
|
372
|
+
}
|
|
373
|
+
} else if (target.length < painted.length) {
|
|
374
|
+
out.push(moveTo(target.length), "\r", ERASE_DOWN);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (target.length > 0) out.push(moveTo(target.length - 1));
|
|
378
|
+
out.push(SHOW_CURSOR);
|
|
379
|
+
|
|
380
|
+
painted = target;
|
|
381
|
+
stdout.write(out.join(""));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
render(lines) {
|
|
386
|
+
if (disposed) return;
|
|
387
|
+
paint(normalize(lines));
|
|
388
|
+
},
|
|
389
|
+
|
|
390
|
+
writeAbove(text) {
|
|
391
|
+
if (disposed) return;
|
|
392
|
+
const body = String(text ?? "");
|
|
393
|
+
let head = HIDE_CURSOR;
|
|
394
|
+
if (painted.length > 0) head += `${moveTo(0)}\r${ERASE_DOWN}`;
|
|
395
|
+
head += body.endsWith("\n") || body === "" ? body : `${body}\n`;
|
|
396
|
+
stdout.write(head);
|
|
397
|
+
|
|
398
|
+
const saved = painted;
|
|
399
|
+
painted = [];
|
|
400
|
+
cursorRow = 0;
|
|
401
|
+
if (saved.length > 0) {
|
|
402
|
+
paint(saved);
|
|
403
|
+
} else {
|
|
404
|
+
stdout.write(SHOW_CURSOR);
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
clear() {
|
|
409
|
+
if (disposed) return;
|
|
410
|
+
let out = HIDE_CURSOR;
|
|
411
|
+
if (painted.length > 0) out += `${moveTo(0)}\r${ERASE_DOWN}`;
|
|
412
|
+
out += SHOW_CURSOR;
|
|
413
|
+
stdout.write(out);
|
|
414
|
+
painted = [];
|
|
415
|
+
cursorRow = 0;
|
|
416
|
+
forceFull = false;
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
setLines(n) {
|
|
420
|
+
regionHeight = Number.isFinite(n) && n >= 0 ? Math.trunc(n) : null;
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
getLines() {
|
|
424
|
+
return painted.slice();
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
getSize() {
|
|
428
|
+
return { rows: currentRows, columns: currentColumns };
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
dispose() {
|
|
432
|
+
if (disposed) return;
|
|
433
|
+
disposed = true;
|
|
434
|
+
if (listens) {
|
|
435
|
+
const off = typeof stdout.off === "function" ? stdout.off : stdout.removeListener;
|
|
436
|
+
if (typeof off === "function") off.call(stdout, "resize", onResize);
|
|
437
|
+
}
|
|
438
|
+
stdout.write(SHOW_CURSOR);
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export default createRenderer;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const THEME = Object.freeze({
|
|
2
|
+
accent: "#B8F0FF",
|
|
3
|
+
prompt: "#B8F0FF",
|
|
4
|
+
banner_title: "#B8F0FF",
|
|
5
|
+
banner_accent: "#91C2D7",
|
|
6
|
+
ui_label: "#A5D9EB",
|
|
7
|
+
banner_text: "#EAF2F8",
|
|
8
|
+
status_bar_strong: "#EAF2F8",
|
|
9
|
+
banner_border: "#455867",
|
|
10
|
+
input_rule: "#455867",
|
|
11
|
+
session_border: "#455867",
|
|
12
|
+
banner_dim: "#60717F",
|
|
13
|
+
status_bar_dim: "#60717F",
|
|
14
|
+
status_bar_bg: "#11161B",
|
|
15
|
+
status_bar_text: "#91A2B1",
|
|
16
|
+
ok: "#7EE7B5",
|
|
17
|
+
error: "#FF7B7B",
|
|
18
|
+
warn: "#F0C674",
|
|
19
|
+
bad: "#FF9B71",
|
|
20
|
+
selection_bg: "#23313B",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export function hexToRgb(hex) {
|
|
24
|
+
if (typeof hex !== "string") return null;
|
|
25
|
+
const value = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
26
|
+
if (!/^(?:[\da-f]{3}|[\da-f]{6})$/i.test(value)) return null;
|
|
27
|
+
const expanded = value.length === 3
|
|
28
|
+
? [...value].map((character) => character.repeat(2)).join("")
|
|
29
|
+
: value;
|
|
30
|
+
return {
|
|
31
|
+
r: Number.parseInt(expanded.slice(0, 2), 16),
|
|
32
|
+
g: Number.parseInt(expanded.slice(2, 4), 16),
|
|
33
|
+
b: Number.parseInt(expanded.slice(4, 6), 16),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function colorSequence(code, hex, text) {
|
|
38
|
+
const rgb = hexToRgb(hex);
|
|
39
|
+
if (!rgb) return String(text);
|
|
40
|
+
return `\u001B[${code};2;${rgb.r};${rgb.g};${rgb.b}m${String(text)}\u001B[0m`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createPalette({ color = true } = {}) {
|
|
44
|
+
const enabled = color && !Object.hasOwn(process.env, "NO_COLOR");
|
|
45
|
+
if (!enabled) {
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
fg: (_hex, text) => String(text),
|
|
48
|
+
bg: (_hex, text) => String(text),
|
|
49
|
+
bold: (text) => String(text),
|
|
50
|
+
dim: (text) => String(text),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
fg: (hex, text) => colorSequence(38, hex, text),
|
|
55
|
+
bg: (hex, text) => colorSequence(48, hex, text),
|
|
56
|
+
bold: (text) => `\u001B[1m${String(text)}\u001B[0m`,
|
|
57
|
+
dim: (text) => `\u001B[2m${String(text)}\u001B[0m`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const defaultPalette = createPalette();
|
|
62
|
+
|
|
63
|
+
export function fg(hex, text) {
|
|
64
|
+
return defaultPalette.fg(hex, text);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function bg(hex, text) {
|
|
68
|
+
return defaultPalette.bg(hex, text);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function bold(text) {
|
|
72
|
+
return defaultPalette.bold(text);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function dim(text) {
|
|
76
|
+
return defaultPalette.dim(text);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function stripAnsi(text) {
|
|
80
|
+
return String(text).replace(/\u001B\[[0-9;]*m/g, "");
|
|
81
|
+
}
|