terminal-richjs 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/README.md +241 -0
- package/dist/index.cjs +2738 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +751 -0
- package/dist/index.d.ts +751 -0
- package/dist/index.js +2674 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.cjs +4 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/logging.d.cts +2 -0
- package/dist/logging.d.ts +2 -0
- package/dist/logging.js +3 -0
- package/dist/logging.js.map +1 -0
- package/package.json +81 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2738 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var process2 = require('process');
|
|
4
|
+
var wrapAnsi = require('wrap-ansi');
|
|
5
|
+
var terminalSize = require('terminal-size');
|
|
6
|
+
var os = require('os');
|
|
7
|
+
var stringWidth3 = require('string-width');
|
|
8
|
+
var chalk = require('chalk');
|
|
9
|
+
var tinycolor = require('tinycolor2');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var hljs = require('highlight.js');
|
|
12
|
+
var ansiEscapes = require('ansi-escapes');
|
|
13
|
+
var cliSpinners = require('cli-spinners');
|
|
14
|
+
var boxes = require('cli-boxes');
|
|
15
|
+
var readline = require('readline');
|
|
16
|
+
var marked = require('marked');
|
|
17
|
+
var TerminalRenderer = require('marked-terminal');
|
|
18
|
+
|
|
19
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
|
|
21
|
+
var process2__default = /*#__PURE__*/_interopDefault(process2);
|
|
22
|
+
var wrapAnsi__default = /*#__PURE__*/_interopDefault(wrapAnsi);
|
|
23
|
+
var terminalSize__default = /*#__PURE__*/_interopDefault(terminalSize);
|
|
24
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
25
|
+
var stringWidth3__default = /*#__PURE__*/_interopDefault(stringWidth3);
|
|
26
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
27
|
+
var tinycolor__default = /*#__PURE__*/_interopDefault(tinycolor);
|
|
28
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
29
|
+
var hljs__default = /*#__PURE__*/_interopDefault(hljs);
|
|
30
|
+
var ansiEscapes__default = /*#__PURE__*/_interopDefault(ansiEscapes);
|
|
31
|
+
var cliSpinners__default = /*#__PURE__*/_interopDefault(cliSpinners);
|
|
32
|
+
var boxes__default = /*#__PURE__*/_interopDefault(boxes);
|
|
33
|
+
var readline__default = /*#__PURE__*/_interopDefault(readline);
|
|
34
|
+
var TerminalRenderer__default = /*#__PURE__*/_interopDefault(TerminalRenderer);
|
|
35
|
+
|
|
36
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
37
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
38
|
+
}) : x)(function(x) {
|
|
39
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
40
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
41
|
+
});
|
|
42
|
+
var Terminal = class {
|
|
43
|
+
constructor() {
|
|
44
|
+
}
|
|
45
|
+
get width() {
|
|
46
|
+
return terminalSize__default.default().columns;
|
|
47
|
+
}
|
|
48
|
+
get height() {
|
|
49
|
+
return terminalSize__default.default().rows;
|
|
50
|
+
}
|
|
51
|
+
get isInteractive() {
|
|
52
|
+
return !!process2__default.default.stdout.isTTY;
|
|
53
|
+
}
|
|
54
|
+
get isLegacyWindows() {
|
|
55
|
+
return os__default.default.platform() === "win32" && !process2__default.default.env.WT_SESSION;
|
|
56
|
+
}
|
|
57
|
+
get colorSystem() {
|
|
58
|
+
const env = process2__default.default.env;
|
|
59
|
+
if (env.NO_COLOR) return "none";
|
|
60
|
+
if (env.COLORTERM === "truecolor" || env.COLORTERM === "24bit") {
|
|
61
|
+
return "truecolor";
|
|
62
|
+
}
|
|
63
|
+
if (this.isLegacyWindows) {
|
|
64
|
+
return "standard";
|
|
65
|
+
}
|
|
66
|
+
if (env.TERM && env.TERM.includes("256")) {
|
|
67
|
+
return "256";
|
|
68
|
+
}
|
|
69
|
+
return "standard";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var Style = class _Style {
|
|
73
|
+
color;
|
|
74
|
+
backgroundColor;
|
|
75
|
+
bold;
|
|
76
|
+
italic;
|
|
77
|
+
underline;
|
|
78
|
+
strikethrough;
|
|
79
|
+
dim;
|
|
80
|
+
reverse;
|
|
81
|
+
blink;
|
|
82
|
+
hidden;
|
|
83
|
+
constructor(options = {}) {
|
|
84
|
+
this.color = options.color;
|
|
85
|
+
this.backgroundColor = options.backgroundColor;
|
|
86
|
+
this.bold = options.bold;
|
|
87
|
+
this.italic = options.italic;
|
|
88
|
+
this.underline = options.underline;
|
|
89
|
+
this.strikethrough = options.strikethrough;
|
|
90
|
+
this.dim = options.dim;
|
|
91
|
+
this.reverse = options.reverse;
|
|
92
|
+
this.blink = options.blink;
|
|
93
|
+
this.hidden = options.hidden;
|
|
94
|
+
}
|
|
95
|
+
static null() {
|
|
96
|
+
return new _Style({});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse a style string into a Style object.
|
|
100
|
+
* Supports:
|
|
101
|
+
* - Modifiers: bold, italic, underline, dim, strike, reverse, blink, hidden
|
|
102
|
+
* - Named colors: red, green, blue, cyan, magenta, yellow, white, black
|
|
103
|
+
* - Bright colors: bright_red, bright_green, etc.
|
|
104
|
+
* - Hex colors: #ff0000
|
|
105
|
+
* - RGB colors: rgb(255,0,0)
|
|
106
|
+
* - 256 colors: color(196)
|
|
107
|
+
* - Background: on red, on #ff0000, on rgb(255,0,0)
|
|
108
|
+
*/
|
|
109
|
+
static parse(styleString) {
|
|
110
|
+
if (!styleString.trim()) return _Style.null();
|
|
111
|
+
const options = {};
|
|
112
|
+
const words = styleString.trim().split(/\s+/);
|
|
113
|
+
let i = 0;
|
|
114
|
+
while (i < words.length) {
|
|
115
|
+
const word = words[i];
|
|
116
|
+
if (word === "bold") {
|
|
117
|
+
options.bold = true;
|
|
118
|
+
i++;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (word === "italic") {
|
|
122
|
+
options.italic = true;
|
|
123
|
+
i++;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (word === "underline") {
|
|
127
|
+
options.underline = true;
|
|
128
|
+
i++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (word === "strike" || word === "strikethrough") {
|
|
132
|
+
options.strikethrough = true;
|
|
133
|
+
i++;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (word === "dim") {
|
|
137
|
+
options.dim = true;
|
|
138
|
+
i++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (word === "reverse") {
|
|
142
|
+
options.reverse = true;
|
|
143
|
+
i++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (word === "blink") {
|
|
147
|
+
options.blink = true;
|
|
148
|
+
i++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (word === "hidden") {
|
|
152
|
+
options.hidden = true;
|
|
153
|
+
i++;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (word === "on") {
|
|
157
|
+
if (i + 1 < words.length) {
|
|
158
|
+
const bgColor = _Style.parseColor(words[i + 1]);
|
|
159
|
+
if (bgColor !== null) {
|
|
160
|
+
options.backgroundColor = bgColor;
|
|
161
|
+
i += 2;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
i++;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const color = _Style.parseColor(word);
|
|
169
|
+
if (color !== null) {
|
|
170
|
+
options.color = color;
|
|
171
|
+
i++;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
i++;
|
|
175
|
+
}
|
|
176
|
+
return new _Style(options);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parse a single color value.
|
|
180
|
+
* Supports hex (#ff0000), RGB (rgb(255,0,0)), 256-color (color(196)), and named colors.
|
|
181
|
+
*/
|
|
182
|
+
static parseColor(word) {
|
|
183
|
+
if (word.startsWith("#")) {
|
|
184
|
+
if (/^#[0-9a-fA-F]{6}$/.test(word) || /^#[0-9a-fA-F]{3}$/.test(word)) {
|
|
185
|
+
return word;
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const rgbMatch = word.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
|
|
190
|
+
if (rgbMatch) {
|
|
191
|
+
return {
|
|
192
|
+
r: Math.min(255, parseInt(rgbMatch[1], 10)),
|
|
193
|
+
g: Math.min(255, parseInt(rgbMatch[2], 10)),
|
|
194
|
+
b: Math.min(255, parseInt(rgbMatch[3], 10))
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const color256Match = word.match(/^color\(\s*(\d+)\s*\)$/i);
|
|
198
|
+
if (color256Match) {
|
|
199
|
+
return Math.min(255, parseInt(color256Match[1], 10));
|
|
200
|
+
}
|
|
201
|
+
const namedColors = [
|
|
202
|
+
"black",
|
|
203
|
+
"red",
|
|
204
|
+
"green",
|
|
205
|
+
"yellow",
|
|
206
|
+
"blue",
|
|
207
|
+
"magenta",
|
|
208
|
+
"cyan",
|
|
209
|
+
"white",
|
|
210
|
+
"gray",
|
|
211
|
+
"grey",
|
|
212
|
+
"blackBright",
|
|
213
|
+
"redBright",
|
|
214
|
+
"greenBright",
|
|
215
|
+
"yellowBright",
|
|
216
|
+
"blueBright",
|
|
217
|
+
"magentaBright",
|
|
218
|
+
"cyanBright",
|
|
219
|
+
"whiteBright",
|
|
220
|
+
// Underscore variants commonly used
|
|
221
|
+
"bright_black",
|
|
222
|
+
"bright_red",
|
|
223
|
+
"bright_green",
|
|
224
|
+
"bright_yellow",
|
|
225
|
+
"bright_blue",
|
|
226
|
+
"bright_magenta",
|
|
227
|
+
"bright_cyan",
|
|
228
|
+
"bright_white"
|
|
229
|
+
];
|
|
230
|
+
let normalizedWord = word;
|
|
231
|
+
if (word.startsWith("bright_")) {
|
|
232
|
+
const base = word.slice(7);
|
|
233
|
+
normalizedWord = `${base}Bright`;
|
|
234
|
+
}
|
|
235
|
+
if (namedColors.includes(word) || namedColors.includes(normalizedWord)) {
|
|
236
|
+
return word;
|
|
237
|
+
}
|
|
238
|
+
if (/^[a-zA-Z]+$/.test(word)) {
|
|
239
|
+
return word;
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
combine(other) {
|
|
244
|
+
return new _Style({
|
|
245
|
+
color: other.color ?? this.color,
|
|
246
|
+
backgroundColor: other.backgroundColor ?? this.backgroundColor,
|
|
247
|
+
bold: other.bold ?? this.bold,
|
|
248
|
+
italic: other.italic ?? this.italic,
|
|
249
|
+
underline: other.underline ?? this.underline,
|
|
250
|
+
strikethrough: other.strikethrough ?? this.strikethrough,
|
|
251
|
+
dim: other.dim ?? this.dim,
|
|
252
|
+
reverse: other.reverse ?? this.reverse,
|
|
253
|
+
blink: other.blink ?? this.blink,
|
|
254
|
+
hidden: other.hidden ?? this.hidden
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
render(text) {
|
|
258
|
+
let result = chalk__default.default;
|
|
259
|
+
if (this.color) {
|
|
260
|
+
result = this.applyColor(result, this.color, false);
|
|
261
|
+
}
|
|
262
|
+
if (this.backgroundColor) {
|
|
263
|
+
result = this.applyColor(result, this.backgroundColor, true);
|
|
264
|
+
}
|
|
265
|
+
if (this.bold) result = result.bold;
|
|
266
|
+
if (this.italic) result = result.italic;
|
|
267
|
+
if (this.underline) result = result.underline;
|
|
268
|
+
if (this.strikethrough) result = result.strikethrough;
|
|
269
|
+
if (this.dim) result = result.dim;
|
|
270
|
+
if (this.reverse) result = result.inverse;
|
|
271
|
+
if (this.blink) result = result.blink;
|
|
272
|
+
if (this.hidden) result = result.hidden;
|
|
273
|
+
return result(text);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Apply a color to a chalk instance.
|
|
277
|
+
*/
|
|
278
|
+
applyColor(chalkInstance, color, isBackground) {
|
|
279
|
+
if (typeof color === "string") {
|
|
280
|
+
if (color.startsWith("#")) {
|
|
281
|
+
return isBackground ? chalkInstance.bgHex(color) : chalkInstance.hex(color);
|
|
282
|
+
}
|
|
283
|
+
let colorName = color;
|
|
284
|
+
if (color.startsWith("bright_")) {
|
|
285
|
+
const base = color.slice(7);
|
|
286
|
+
colorName = `${base}Bright`;
|
|
287
|
+
}
|
|
288
|
+
if (isBackground) {
|
|
289
|
+
const bgMethod = `bg${colorName.charAt(0).toUpperCase()}${colorName.slice(1)}`;
|
|
290
|
+
if (bgMethod in chalkInstance) {
|
|
291
|
+
return chalkInstance[bgMethod];
|
|
292
|
+
}
|
|
293
|
+
const altMethod = `bg${color.charAt(0).toUpperCase()}${color.slice(1)}`;
|
|
294
|
+
if (altMethod in chalkInstance) {
|
|
295
|
+
return chalkInstance[altMethod];
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
if (colorName in chalkInstance) {
|
|
299
|
+
return chalkInstance[colorName];
|
|
300
|
+
}
|
|
301
|
+
if (color in chalkInstance) {
|
|
302
|
+
return chalkInstance[color];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return chalkInstance;
|
|
306
|
+
}
|
|
307
|
+
if (this.isRGB(color)) {
|
|
308
|
+
return isBackground ? chalkInstance.bgRgb(color.r, color.g, color.b) : chalkInstance.rgb(color.r, color.g, color.b);
|
|
309
|
+
}
|
|
310
|
+
if (typeof color === "number") {
|
|
311
|
+
return isBackground ? chalkInstance.bgAnsi256(color) : chalkInstance.ansi256(color);
|
|
312
|
+
}
|
|
313
|
+
return chalkInstance;
|
|
314
|
+
}
|
|
315
|
+
isRGB(color) {
|
|
316
|
+
return typeof color === "object" && color !== null && "r" in color && "g" in color && "b" in color;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/core/segment.ts
|
|
321
|
+
var Segment = class _Segment {
|
|
322
|
+
constructor(text, style = Style.null(), isControl = false) {
|
|
323
|
+
this.text = text;
|
|
324
|
+
this.style = style;
|
|
325
|
+
this.isControl = isControl;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Implementation of Renderable protocol.
|
|
329
|
+
*/
|
|
330
|
+
__rich_console__(_console, _options) {
|
|
331
|
+
return {
|
|
332
|
+
segments: [this],
|
|
333
|
+
width: this.cellLength()
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Calculates the cell length of the text.
|
|
338
|
+
*/
|
|
339
|
+
cellLength() {
|
|
340
|
+
if (this.isControl) return 0;
|
|
341
|
+
return stringWidth3__default.default(this.text);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Renders the segment to an ANSI string.
|
|
345
|
+
*/
|
|
346
|
+
render() {
|
|
347
|
+
if (this.isControl) return this.text;
|
|
348
|
+
if (typeof this.style?.render === "function") {
|
|
349
|
+
return this.style.render(this.text);
|
|
350
|
+
}
|
|
351
|
+
return this.text;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Splits the segment into lines.
|
|
355
|
+
*/
|
|
356
|
+
splitLines(_allowEmpty = false) {
|
|
357
|
+
const lines = this.text.split("\n");
|
|
358
|
+
return lines.map((line) => {
|
|
359
|
+
return [new _Segment(line, this.style, this.isControl)];
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new Segment with modified properties.
|
|
364
|
+
*/
|
|
365
|
+
clone(text, style, isControl) {
|
|
366
|
+
return new _Segment(text ?? this.text, style ?? this.style, isControl ?? this.isControl);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
var Color = class _Color {
|
|
370
|
+
tc;
|
|
371
|
+
constructor(color) {
|
|
372
|
+
this.tc = tinycolor__default.default(color);
|
|
373
|
+
}
|
|
374
|
+
static parse(color) {
|
|
375
|
+
return new _Color(color);
|
|
376
|
+
}
|
|
377
|
+
get hex() {
|
|
378
|
+
return this.tc.toHexString();
|
|
379
|
+
}
|
|
380
|
+
get rgb() {
|
|
381
|
+
return this.tc.toRgb();
|
|
382
|
+
}
|
|
383
|
+
get isDark() {
|
|
384
|
+
return this.tc.isDark();
|
|
385
|
+
}
|
|
386
|
+
get isLight() {
|
|
387
|
+
return this.tc.isLight();
|
|
388
|
+
}
|
|
389
|
+
contrast(other) {
|
|
390
|
+
return tinycolor__default.default.readability(this.tc, other.tc);
|
|
391
|
+
}
|
|
392
|
+
lighten(amount = 10) {
|
|
393
|
+
return new _Color(this.tc.lighten(amount));
|
|
394
|
+
}
|
|
395
|
+
darken(amount = 10) {
|
|
396
|
+
return new _Color(this.tc.darken(amount));
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Returns a readable foreground color (black or white) for this background color.
|
|
400
|
+
*/
|
|
401
|
+
getContrastColor() {
|
|
402
|
+
return this.isDark ? new _Color("#ffffff") : new _Color("#000000");
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/themes/palette.ts
|
|
407
|
+
var Palette = class _Palette {
|
|
408
|
+
constructor(colors = {}) {
|
|
409
|
+
this.colors = colors;
|
|
410
|
+
}
|
|
411
|
+
get(name) {
|
|
412
|
+
return this.colors[name];
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Generates a simple palette from a primary color.
|
|
416
|
+
*/
|
|
417
|
+
static fromPrimary(primary) {
|
|
418
|
+
const p = new Color(primary);
|
|
419
|
+
return new _Palette({
|
|
420
|
+
primary: p.hex,
|
|
421
|
+
secondary: p.lighten(20).hex,
|
|
422
|
+
background: "#121212",
|
|
423
|
+
surface: "#1e1e1e",
|
|
424
|
+
text: "#ffffff",
|
|
425
|
+
error: "#cf6679",
|
|
426
|
+
success: "#03dac6",
|
|
427
|
+
warning: "#bb86fc"
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var DEFAULT_PALETTE = new Palette({
|
|
432
|
+
primary: "#007bff",
|
|
433
|
+
secondary: "#6c757d",
|
|
434
|
+
success: "#28a745",
|
|
435
|
+
info: "#17a2b8",
|
|
436
|
+
warning: "#ffc107",
|
|
437
|
+
danger: "#dc3545",
|
|
438
|
+
light: "#f8f9fa",
|
|
439
|
+
dark: "#343a40"
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// src/themes/theme.ts
|
|
443
|
+
var Theme = class _Theme {
|
|
444
|
+
constructor(styles = {}, palette) {
|
|
445
|
+
this.styles = styles;
|
|
446
|
+
this.palette = palette ?? DEFAULT_PALETTE;
|
|
447
|
+
}
|
|
448
|
+
palette;
|
|
449
|
+
get(name) {
|
|
450
|
+
const style = this.styles[name];
|
|
451
|
+
if (style) {
|
|
452
|
+
return typeof style === "string" ? this.parseWithPalette(style) : style;
|
|
453
|
+
}
|
|
454
|
+
const paletteColor = this.palette.get(name);
|
|
455
|
+
if (paletteColor) {
|
|
456
|
+
return new Style({ color: paletteColor });
|
|
457
|
+
}
|
|
458
|
+
return Style.null();
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Parses a style string replacing palette references.
|
|
462
|
+
* e.g. "bold primary" -> "bold #007bff"
|
|
463
|
+
*/
|
|
464
|
+
parseWithPalette(styleString) {
|
|
465
|
+
const parts = styleString.split(" ");
|
|
466
|
+
const resolvedParts = parts.map((part) => {
|
|
467
|
+
const color = this.palette.get(part);
|
|
468
|
+
if (color) return color;
|
|
469
|
+
if (part.startsWith("on")) {
|
|
470
|
+
const bgName = part.startsWith("on_") ? part.slice(3) : part.slice(2) || parts[parts.indexOf(part) + 1];
|
|
471
|
+
const bgColor = this.palette.get(bgName);
|
|
472
|
+
if (bgColor) return `on ${bgColor}`;
|
|
473
|
+
}
|
|
474
|
+
return part;
|
|
475
|
+
});
|
|
476
|
+
return Style.parse(resolvedParts.join(" "));
|
|
477
|
+
}
|
|
478
|
+
static fromPalette(palette) {
|
|
479
|
+
return new _Theme({
|
|
480
|
+
"danger": `bold ${palette.get("danger")}`,
|
|
481
|
+
"success": `bold ${palette.get("success")}`,
|
|
482
|
+
"warning": `bold ${palette.get("warning")}`,
|
|
483
|
+
"info": `${palette.get("info")}`
|
|
484
|
+
}, palette);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
var DEFAULT_THEME = new Theme({
|
|
488
|
+
"none": Style.null(),
|
|
489
|
+
"dim": Style.parse("dim"),
|
|
490
|
+
"bright": Style.parse("bold"),
|
|
491
|
+
// Semantic
|
|
492
|
+
"danger": Style.parse("bold red"),
|
|
493
|
+
"success": Style.parse("bold green"),
|
|
494
|
+
"warning": Style.parse("bold yellow"),
|
|
495
|
+
"info": Style.parse("cyan"),
|
|
496
|
+
// Components
|
|
497
|
+
"rule.line": Style.parse("green"),
|
|
498
|
+
"repr.str": Style.parse("green"),
|
|
499
|
+
"repr.brace": Style.parse("bold")
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// src/core/markup.ts
|
|
503
|
+
var MarkupParser = class _MarkupParser {
|
|
504
|
+
// Regex that matches standard tags [tag] and closing tags [/] or [/tag]
|
|
505
|
+
// We use a non-greedy match for content inside brackets
|
|
506
|
+
static TAG_REGEX = /\[(\/)?([\w\s#.,()]*?)\]/g;
|
|
507
|
+
theme;
|
|
508
|
+
constructor(theme) {
|
|
509
|
+
this.theme = theme ?? DEFAULT_THEME;
|
|
510
|
+
}
|
|
511
|
+
parse(markup) {
|
|
512
|
+
const segments = [];
|
|
513
|
+
const styleStack = [Style.null()];
|
|
514
|
+
let lastIndex = 0;
|
|
515
|
+
let match;
|
|
516
|
+
_MarkupParser.TAG_REGEX.lastIndex = 0;
|
|
517
|
+
while ((match = _MarkupParser.TAG_REGEX.exec(markup)) !== null) {
|
|
518
|
+
const fullMatch = match[0];
|
|
519
|
+
const isClosing = !!match[1];
|
|
520
|
+
const tagContent = match[2];
|
|
521
|
+
const index = match.index;
|
|
522
|
+
if (!isClosing && !tagContent) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
if (index > lastIndex) {
|
|
526
|
+
const text = markup.substring(lastIndex, index);
|
|
527
|
+
segments.push(new Segment(text, styleStack[styleStack.length - 1]));
|
|
528
|
+
}
|
|
529
|
+
if (isClosing) {
|
|
530
|
+
if (styleStack.length > 1) {
|
|
531
|
+
styleStack.pop();
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
const currentStyle = styleStack[styleStack.length - 1];
|
|
535
|
+
let nextStyle = this.theme.get(tagContent);
|
|
536
|
+
if (nextStyle === Style.null() && !this.theme.styles[tagContent]) {
|
|
537
|
+
nextStyle = Style.parse(tagContent);
|
|
538
|
+
} else if (this.theme.styles[tagContent]) ;
|
|
539
|
+
if (tagContent.includes(" ")) {
|
|
540
|
+
nextStyle = Style.parse(tagContent);
|
|
541
|
+
} else {
|
|
542
|
+
const themeStyle = this.theme.styles[tagContent];
|
|
543
|
+
if (themeStyle) {
|
|
544
|
+
nextStyle = typeof themeStyle === "string" ? Style.parse(themeStyle) : themeStyle;
|
|
545
|
+
} else {
|
|
546
|
+
nextStyle = Style.parse(tagContent);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const newStyle = currentStyle.combine(nextStyle);
|
|
550
|
+
styleStack.push(newStyle);
|
|
551
|
+
}
|
|
552
|
+
lastIndex = index + fullMatch.length;
|
|
553
|
+
}
|
|
554
|
+
if (lastIndex < markup.length) {
|
|
555
|
+
const text = markup.substring(lastIndex);
|
|
556
|
+
segments.push(new Segment(text, styleStack[styleStack.length - 1]));
|
|
557
|
+
}
|
|
558
|
+
return segments.filter((s) => s.text.length > 0);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// src/types/renderable.ts
|
|
563
|
+
function isRenderable(obj) {
|
|
564
|
+
return typeof obj === "object" && obj !== null && "__rich_console__" in obj && typeof obj.__rich_console__ === "function";
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/traceback/trace.ts
|
|
568
|
+
var Trace = class {
|
|
569
|
+
static parse(error) {
|
|
570
|
+
if (!error.stack) return [];
|
|
571
|
+
const lines = error.stack.split("\n");
|
|
572
|
+
const frames = [];
|
|
573
|
+
for (let i = 1; i < lines.length; i++) {
|
|
574
|
+
const line = lines[i].trim();
|
|
575
|
+
if (!line.startsWith("at ")) continue;
|
|
576
|
+
let functionName = "";
|
|
577
|
+
let location = "";
|
|
578
|
+
if (line.includes("(")) {
|
|
579
|
+
const parts = line.substring(3).split(" (");
|
|
580
|
+
functionName = parts[0];
|
|
581
|
+
location = parts[1].slice(0, -1);
|
|
582
|
+
} else {
|
|
583
|
+
location = line.substring(3);
|
|
584
|
+
}
|
|
585
|
+
const locParts = location.split(":");
|
|
586
|
+
const columnNumber = parseInt(locParts.pop() || "0");
|
|
587
|
+
const lineNumber = parseInt(locParts.pop() || "0");
|
|
588
|
+
const filePath = locParts.join(":");
|
|
589
|
+
frames.push({
|
|
590
|
+
functionName: functionName || "<anonymous>",
|
|
591
|
+
filePath,
|
|
592
|
+
lineNumber,
|
|
593
|
+
columnNumber
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
return frames;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// src/syntax/theme.ts
|
|
601
|
+
var MONOKAI = {
|
|
602
|
+
name: "monokai",
|
|
603
|
+
background: "#272822",
|
|
604
|
+
styles: {
|
|
605
|
+
// Keywords and control flow
|
|
606
|
+
keyword: Style.parse("#f92672 bold"),
|
|
607
|
+
built_in: Style.parse("#66d9ef"),
|
|
608
|
+
type: Style.parse("#66d9ef italic"),
|
|
609
|
+
literal: Style.parse("#ae81ff"),
|
|
610
|
+
// Values
|
|
611
|
+
number: Style.parse("#ae81ff"),
|
|
612
|
+
string: Style.parse("#e6db74"),
|
|
613
|
+
regexp: Style.parse("#e6db74"),
|
|
614
|
+
symbol: Style.parse("#ae81ff"),
|
|
615
|
+
// Comments and docs
|
|
616
|
+
comment: Style.parse("#75715e dim"),
|
|
617
|
+
doctag: Style.parse("#75715e"),
|
|
618
|
+
meta: Style.parse("#75715e"),
|
|
619
|
+
// Functions and classes
|
|
620
|
+
function: Style.parse("#a6e22e"),
|
|
621
|
+
title: Style.parse("#a6e22e"),
|
|
622
|
+
"title.function": Style.parse("#a6e22e"),
|
|
623
|
+
"title.class": Style.parse("#a6e22e italic"),
|
|
624
|
+
"title.class.inherited": Style.parse("#a6e22e"),
|
|
625
|
+
// Variables and parameters
|
|
626
|
+
params: Style.parse("#fd971f italic"),
|
|
627
|
+
variable: Style.parse("#f8f8f2"),
|
|
628
|
+
"variable.language": Style.parse("#fd971f"),
|
|
629
|
+
"variable.constant": Style.parse("#ae81ff"),
|
|
630
|
+
// Properties and attributes
|
|
631
|
+
property: Style.parse("#66d9ef"),
|
|
632
|
+
attr: Style.parse("#a6e22e"),
|
|
633
|
+
attribute: Style.parse("#a6e22e"),
|
|
634
|
+
// Operators and punctuation
|
|
635
|
+
operator: Style.parse("#f92672"),
|
|
636
|
+
punctuation: Style.parse("#f8f8f2"),
|
|
637
|
+
// Misc
|
|
638
|
+
tag: Style.parse("#f92672"),
|
|
639
|
+
name: Style.parse("#a6e22e"),
|
|
640
|
+
"selector-tag": Style.parse("#f92672"),
|
|
641
|
+
"selector-class": Style.parse("#a6e22e"),
|
|
642
|
+
"selector-id": Style.parse("#a6e22e"),
|
|
643
|
+
// Template literals
|
|
644
|
+
"template-variable": Style.parse("#e6db74"),
|
|
645
|
+
"template-tag": Style.parse("#f92672"),
|
|
646
|
+
subst: Style.parse("#f8f8f2")
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
var DRACULA = {
|
|
650
|
+
name: "dracula",
|
|
651
|
+
background: "#282a36",
|
|
652
|
+
styles: {
|
|
653
|
+
keyword: Style.parse("#ff79c6 bold"),
|
|
654
|
+
built_in: Style.parse("#8be9fd"),
|
|
655
|
+
type: Style.parse("#8be9fd italic"),
|
|
656
|
+
literal: Style.parse("#bd93f9"),
|
|
657
|
+
number: Style.parse("#bd93f9"),
|
|
658
|
+
string: Style.parse("#f1fa8c"),
|
|
659
|
+
regexp: Style.parse("#f1fa8c"),
|
|
660
|
+
comment: Style.parse("#6272a4 dim"),
|
|
661
|
+
function: Style.parse("#50fa7b"),
|
|
662
|
+
title: Style.parse("#50fa7b"),
|
|
663
|
+
"title.function": Style.parse("#50fa7b"),
|
|
664
|
+
"title.class": Style.parse("#50fa7b italic"),
|
|
665
|
+
params: Style.parse("#ffb86c italic"),
|
|
666
|
+
variable: Style.parse("#f8f8f2"),
|
|
667
|
+
property: Style.parse("#8be9fd"),
|
|
668
|
+
attr: Style.parse("#50fa7b"),
|
|
669
|
+
operator: Style.parse("#ff79c6"),
|
|
670
|
+
tag: Style.parse("#ff79c6")
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
var GITHUB_LIGHT = {
|
|
674
|
+
name: "github",
|
|
675
|
+
styles: {
|
|
676
|
+
keyword: Style.parse("#d73a49 bold"),
|
|
677
|
+
built_in: Style.parse("#005cc5"),
|
|
678
|
+
type: Style.parse("#005cc5"),
|
|
679
|
+
literal: Style.parse("#005cc5"),
|
|
680
|
+
number: Style.parse("#005cc5"),
|
|
681
|
+
string: Style.parse("#032f62"),
|
|
682
|
+
regexp: Style.parse("#032f62"),
|
|
683
|
+
comment: Style.parse("#6a737d dim"),
|
|
684
|
+
function: Style.parse("#6f42c1"),
|
|
685
|
+
title: Style.parse("#6f42c1"),
|
|
686
|
+
"title.function": Style.parse("#6f42c1"),
|
|
687
|
+
"title.class": Style.parse("#6f42c1 bold"),
|
|
688
|
+
params: Style.parse("#24292e"),
|
|
689
|
+
variable: Style.parse("#24292e"),
|
|
690
|
+
property: Style.parse("#005cc5"),
|
|
691
|
+
attr: Style.parse("#6f42c1"),
|
|
692
|
+
operator: Style.parse("#d73a49"),
|
|
693
|
+
tag: Style.parse("#22863a")
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
var ONE_DARK = {
|
|
697
|
+
name: "one-dark",
|
|
698
|
+
background: "#282c34",
|
|
699
|
+
styles: {
|
|
700
|
+
keyword: Style.parse("#c678dd bold"),
|
|
701
|
+
built_in: Style.parse("#e5c07b"),
|
|
702
|
+
type: Style.parse("#e5c07b italic"),
|
|
703
|
+
literal: Style.parse("#d19a66"),
|
|
704
|
+
number: Style.parse("#d19a66"),
|
|
705
|
+
string: Style.parse("#98c379"),
|
|
706
|
+
regexp: Style.parse("#98c379"),
|
|
707
|
+
comment: Style.parse("#5c6370 dim"),
|
|
708
|
+
function: Style.parse("#61afef"),
|
|
709
|
+
title: Style.parse("#61afef"),
|
|
710
|
+
"title.function": Style.parse("#61afef"),
|
|
711
|
+
"title.class": Style.parse("#e5c07b bold"),
|
|
712
|
+
params: Style.parse("#abb2bf italic"),
|
|
713
|
+
variable: Style.parse("#e06c75"),
|
|
714
|
+
property: Style.parse("#e06c75"),
|
|
715
|
+
attr: Style.parse("#d19a66"),
|
|
716
|
+
operator: Style.parse("#56b6c2"),
|
|
717
|
+
tag: Style.parse("#e06c75")
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
var SYNTAX_THEMES = {
|
|
721
|
+
monokai: MONOKAI,
|
|
722
|
+
dracula: DRACULA,
|
|
723
|
+
github: GITHUB_LIGHT,
|
|
724
|
+
"github-light": GITHUB_LIGHT,
|
|
725
|
+
"one-dark": ONE_DARK,
|
|
726
|
+
atom: ONE_DARK
|
|
727
|
+
};
|
|
728
|
+
function getTheme(name) {
|
|
729
|
+
return SYNTAX_THEMES[name] ?? MONOKAI;
|
|
730
|
+
}
|
|
731
|
+
var MONOKAI_THEME = {
|
|
732
|
+
keyword: Style.parse("bold magenta"),
|
|
733
|
+
string: Style.parse("yellow"),
|
|
734
|
+
number: Style.parse("magenta"),
|
|
735
|
+
comment: Style.parse("dim white"),
|
|
736
|
+
operator: Style.parse("bold white"),
|
|
737
|
+
function: Style.parse("green"),
|
|
738
|
+
class: Style.parse("bold blue"),
|
|
739
|
+
title: Style.parse("bold white")
|
|
740
|
+
};
|
|
741
|
+
var Syntax = class _Syntax {
|
|
742
|
+
constructor(code, lexer, options = {}) {
|
|
743
|
+
this.code = code;
|
|
744
|
+
this.lexer = lexer;
|
|
745
|
+
this.options = options;
|
|
746
|
+
this.syntaxTheme = getTheme(options.theme ?? "monokai");
|
|
747
|
+
}
|
|
748
|
+
syntaxTheme;
|
|
749
|
+
/**
|
|
750
|
+
* Create Syntax from a file path (convenience method).
|
|
751
|
+
*/
|
|
752
|
+
static fromPath(filePath, options = {}) {
|
|
753
|
+
const fs2 = __require("fs");
|
|
754
|
+
const path = __require("path");
|
|
755
|
+
const code = fs2.readFileSync(filePath, "utf-8");
|
|
756
|
+
const ext = path.extname(filePath).slice(1);
|
|
757
|
+
const lexerMap = {
|
|
758
|
+
ts: "typescript",
|
|
759
|
+
tsx: "typescript",
|
|
760
|
+
js: "javascript",
|
|
761
|
+
jsx: "javascript",
|
|
762
|
+
py: "python",
|
|
763
|
+
rb: "ruby",
|
|
764
|
+
rs: "rust",
|
|
765
|
+
go: "go",
|
|
766
|
+
java: "java",
|
|
767
|
+
cpp: "cpp",
|
|
768
|
+
c: "c",
|
|
769
|
+
h: "c",
|
|
770
|
+
hpp: "cpp",
|
|
771
|
+
cs: "csharp",
|
|
772
|
+
php: "php",
|
|
773
|
+
sh: "bash",
|
|
774
|
+
bash: "bash",
|
|
775
|
+
zsh: "bash",
|
|
776
|
+
md: "markdown",
|
|
777
|
+
json: "json",
|
|
778
|
+
yaml: "yaml",
|
|
779
|
+
yml: "yaml",
|
|
780
|
+
toml: "ini",
|
|
781
|
+
css: "css",
|
|
782
|
+
scss: "scss",
|
|
783
|
+
html: "html",
|
|
784
|
+
xml: "xml",
|
|
785
|
+
sql: "sql"
|
|
786
|
+
};
|
|
787
|
+
const lexer = lexerMap[ext] ?? ext;
|
|
788
|
+
return new _Syntax(code, lexer, options);
|
|
789
|
+
}
|
|
790
|
+
__rich_console__(_console, _options) {
|
|
791
|
+
const segments = [];
|
|
792
|
+
const startLine = this.options.startLine ?? 1;
|
|
793
|
+
const showLineNumbers = this.options.lineNumbers ?? false;
|
|
794
|
+
const highlightLines = new Set(this.options.highlightLines ?? []);
|
|
795
|
+
let highlighted;
|
|
796
|
+
try {
|
|
797
|
+
highlighted = hljs__default.default.highlight(this.code, { language: this.lexer });
|
|
798
|
+
} catch {
|
|
799
|
+
highlighted = hljs__default.default.highlightAuto(this.code);
|
|
800
|
+
}
|
|
801
|
+
const tokens = this.parseHighlightedHtml(highlighted.value);
|
|
802
|
+
const lines = this.groupTokensByLine(tokens);
|
|
803
|
+
const lastLineNumber = startLine + lines.length - 1;
|
|
804
|
+
const lineNumberWidth = showLineNumbers ? String(lastLineNumber).length + 1 : 0;
|
|
805
|
+
let maxWidth = 0;
|
|
806
|
+
lines.forEach((lineTokens, i) => {
|
|
807
|
+
const lineNumber = startLine + i;
|
|
808
|
+
const isHighlighted = highlightLines.has(lineNumber);
|
|
809
|
+
if (isHighlighted) {
|
|
810
|
+
segments.push(new Segment("\u2771 ", Style.parse("#ff5555 bold")));
|
|
811
|
+
} else if (showLineNumbers) {
|
|
812
|
+
segments.push(new Segment(" ", Style.null()));
|
|
813
|
+
}
|
|
814
|
+
if (showLineNumbers) {
|
|
815
|
+
const lineNumStr = String(lineNumber).padStart(lineNumberWidth - 1);
|
|
816
|
+
const lineNumStyle = isHighlighted ? Style.parse("#ff5555 bold") : Style.parse("#6e7681 dim");
|
|
817
|
+
segments.push(new Segment(`${lineNumStr} \u2502 `, lineNumStyle));
|
|
818
|
+
}
|
|
819
|
+
let lineWidth = 0;
|
|
820
|
+
for (const token of lineTokens) {
|
|
821
|
+
let style = token.style;
|
|
822
|
+
if (isHighlighted) {
|
|
823
|
+
style = style.combine(Style.parse("on #3a1d1d"));
|
|
824
|
+
}
|
|
825
|
+
segments.push(new Segment(token.text, style));
|
|
826
|
+
lineWidth += stringWidth3__default.default(token.text);
|
|
827
|
+
}
|
|
828
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
829
|
+
const totalLineWidth = lineWidth + (showLineNumbers ? lineNumberWidth + 5 : 0);
|
|
830
|
+
if (totalLineWidth > maxWidth) maxWidth = totalLineWidth;
|
|
831
|
+
});
|
|
832
|
+
return {
|
|
833
|
+
segments,
|
|
834
|
+
width: maxWidth
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Parse highlight.js HTML output into styled tokens.
|
|
839
|
+
*/
|
|
840
|
+
parseHighlightedHtml(html) {
|
|
841
|
+
const tokens = [];
|
|
842
|
+
const processHtml = (input, inheritedScope = []) => {
|
|
843
|
+
let remaining = input;
|
|
844
|
+
while (remaining.length > 0) {
|
|
845
|
+
const openMatch = remaining.match(/^<span class="hljs-([^"]+)">/);
|
|
846
|
+
if (openMatch) {
|
|
847
|
+
remaining = remaining.slice(openMatch[0].length);
|
|
848
|
+
const scope = openMatch[1];
|
|
849
|
+
let depth = 1;
|
|
850
|
+
let innerEnd = 0;
|
|
851
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
852
|
+
if (remaining.slice(i).startsWith("<span")) {
|
|
853
|
+
depth++;
|
|
854
|
+
} else if (remaining.slice(i).startsWith("</span>")) {
|
|
855
|
+
depth--;
|
|
856
|
+
if (depth === 0) {
|
|
857
|
+
innerEnd = i;
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
const innerContent = remaining.slice(0, innerEnd);
|
|
863
|
+
remaining = remaining.slice(innerEnd + "</span>".length);
|
|
864
|
+
const newScope = [...inheritedScope, scope];
|
|
865
|
+
processHtml(innerContent, newScope);
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
const textMatch = remaining.match(/^([^<]+)/);
|
|
869
|
+
if (textMatch) {
|
|
870
|
+
const text = this.decodeHtmlEntities(textMatch[1]);
|
|
871
|
+
const scope = inheritedScope[inheritedScope.length - 1] ?? "";
|
|
872
|
+
const style = this.getStyleForScope(scope);
|
|
873
|
+
tokens.push({ text, style });
|
|
874
|
+
remaining = remaining.slice(textMatch[0].length);
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
const tagMatch = remaining.match(/^<[^>]+>/);
|
|
878
|
+
if (tagMatch) {
|
|
879
|
+
remaining = remaining.slice(tagMatch[0].length);
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
if (remaining.length > 0) {
|
|
883
|
+
tokens.push({ text: remaining[0], style: Style.null() });
|
|
884
|
+
remaining = remaining.slice(1);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
processHtml(html);
|
|
889
|
+
return tokens;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Decode HTML entities to their character equivalents.
|
|
893
|
+
*/
|
|
894
|
+
decodeHtmlEntities(text) {
|
|
895
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/'/g, "'").replace(/ /g, " ");
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Get style for a highlight.js scope/class.
|
|
899
|
+
*/
|
|
900
|
+
getStyleForScope(scope) {
|
|
901
|
+
if (!scope) return Style.null();
|
|
902
|
+
if (this.syntaxTheme.styles[scope]) {
|
|
903
|
+
return this.syntaxTheme.styles[scope];
|
|
904
|
+
}
|
|
905
|
+
const parts = scope.split(".");
|
|
906
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
907
|
+
const partialScope = parts.slice(0, i + 1).join(".");
|
|
908
|
+
if (this.syntaxTheme.styles[partialScope]) {
|
|
909
|
+
return this.syntaxTheme.styles[partialScope];
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
if (this.syntaxTheme.styles[parts[0]]) {
|
|
913
|
+
return this.syntaxTheme.styles[parts[0]];
|
|
914
|
+
}
|
|
915
|
+
return Style.null();
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Group tokens by line (split on newlines).
|
|
919
|
+
*/
|
|
920
|
+
groupTokensByLine(tokens) {
|
|
921
|
+
const lines = [[]];
|
|
922
|
+
for (const token of tokens) {
|
|
923
|
+
const parts = token.text.split("\n");
|
|
924
|
+
for (let i = 0; i < parts.length; i++) {
|
|
925
|
+
if (i > 0) {
|
|
926
|
+
lines.push([]);
|
|
927
|
+
}
|
|
928
|
+
if (parts[i]) {
|
|
929
|
+
lines[lines.length - 1].push({ text: parts[i], style: token.style });
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return lines;
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
// src/traceback/traceback.ts
|
|
938
|
+
var Traceback = class {
|
|
939
|
+
constructor(error, options = {}) {
|
|
940
|
+
this.error = error;
|
|
941
|
+
this.options = options;
|
|
942
|
+
this.frames = Trace.parse(error);
|
|
943
|
+
}
|
|
944
|
+
frames;
|
|
945
|
+
__rich_console__(console, consoleOptions) {
|
|
946
|
+
const segments = [];
|
|
947
|
+
const extraLines = this.options.extraLines ?? 3;
|
|
948
|
+
const theme = this.options.theme ?? "monokai";
|
|
949
|
+
const suppressInternal = this.options.suppressInternal ?? true;
|
|
950
|
+
const maxFrames = this.options.maxFrames ?? 100;
|
|
951
|
+
const width = consoleOptions.width ?? console.width;
|
|
952
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
953
|
+
const headerStyle = Style.parse("#ff5555 bold");
|
|
954
|
+
segments.push(new Segment("Traceback", headerStyle));
|
|
955
|
+
segments.push(new Segment(" (most recent call last)\n", Style.parse("dim")));
|
|
956
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
957
|
+
let filteredFrames = this.frames;
|
|
958
|
+
if (suppressInternal) {
|
|
959
|
+
filteredFrames = filteredFrames.filter(
|
|
960
|
+
(f) => !f.filePath.startsWith("node:") && !f.filePath.includes("node_modules")
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
filteredFrames = filteredFrames.slice(0, maxFrames);
|
|
964
|
+
for (const frame of filteredFrames) {
|
|
965
|
+
const frameHeaderStyle = Style.parse("#6e7681");
|
|
966
|
+
segments.push(new Segment(" File ", frameHeaderStyle));
|
|
967
|
+
segments.push(new Segment(`"${frame.filePath}"`, Style.parse("#61afef")));
|
|
968
|
+
segments.push(new Segment(", line ", frameHeaderStyle));
|
|
969
|
+
segments.push(new Segment(String(frame.lineNumber), Style.parse("#e5c07b bold")));
|
|
970
|
+
segments.push(new Segment(", in ", frameHeaderStyle));
|
|
971
|
+
segments.push(new Segment(frame.functionName, Style.parse("#98c379 italic")));
|
|
972
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
973
|
+
let codeSnippet = "";
|
|
974
|
+
try {
|
|
975
|
+
if (fs__default.default.existsSync(frame.filePath)) {
|
|
976
|
+
const content = fs__default.default.readFileSync(frame.filePath, "utf-8");
|
|
977
|
+
const lines = content.split("\n");
|
|
978
|
+
const start = Math.max(0, frame.lineNumber - extraLines - 1);
|
|
979
|
+
const end = Math.min(lines.length, frame.lineNumber + extraLines);
|
|
980
|
+
codeSnippet = lines.slice(start, end).join("\n");
|
|
981
|
+
const ext = frame.filePath.split(".").pop() ?? "txt";
|
|
982
|
+
const lexerMap = {
|
|
983
|
+
ts: "typescript",
|
|
984
|
+
tsx: "typescript",
|
|
985
|
+
js: "javascript",
|
|
986
|
+
jsx: "javascript",
|
|
987
|
+
py: "python",
|
|
988
|
+
rb: "ruby",
|
|
989
|
+
rs: "rust",
|
|
990
|
+
go: "go"
|
|
991
|
+
};
|
|
992
|
+
const lexer = lexerMap[ext] ?? ext;
|
|
993
|
+
const syntax = new Syntax(codeSnippet, lexer, {
|
|
994
|
+
theme,
|
|
995
|
+
lineNumbers: true,
|
|
996
|
+
startLine: start + 1,
|
|
997
|
+
highlightLines: [frame.lineNumber]
|
|
998
|
+
});
|
|
999
|
+
const syntaxResult = syntax.__rich_console__(console, {
|
|
1000
|
+
...consoleOptions,
|
|
1001
|
+
width: width - 4
|
|
1002
|
+
});
|
|
1003
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1004
|
+
for (const seg of syntaxResult.segments) {
|
|
1005
|
+
if (seg.isControl && seg.text === "\n") {
|
|
1006
|
+
segments.push(seg);
|
|
1007
|
+
segments.push(new Segment(" "));
|
|
1008
|
+
} else {
|
|
1009
|
+
segments.push(seg);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
} catch {
|
|
1014
|
+
segments.push(new Segment(" ", Style.null()));
|
|
1015
|
+
segments.push(new Segment("[source not available]", Style.parse("dim italic")));
|
|
1016
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1017
|
+
}
|
|
1018
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1019
|
+
}
|
|
1020
|
+
const errorNameStyle = Style.parse("#ff5555 bold");
|
|
1021
|
+
const errorMsgStyle = Style.parse("#ff5555");
|
|
1022
|
+
segments.push(new Segment(this.error.name, errorNameStyle));
|
|
1023
|
+
segments.push(new Segment(": ", Style.parse("dim")));
|
|
1024
|
+
segments.push(new Segment(this.error.message, errorMsgStyle));
|
|
1025
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1026
|
+
return { segments, width };
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
function installTracebackHandler(options = {}) {
|
|
1030
|
+
const console = new Console();
|
|
1031
|
+
process.on("uncaughtException", (error) => {
|
|
1032
|
+
const traceback = new Traceback(error, options);
|
|
1033
|
+
console.print(traceback);
|
|
1034
|
+
process.exit(1);
|
|
1035
|
+
});
|
|
1036
|
+
process.on("unhandledRejection", (reason) => {
|
|
1037
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
1038
|
+
const traceback = new Traceback(error, options);
|
|
1039
|
+
console.print(traceback);
|
|
1040
|
+
process.exit(1);
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/utils/render-utils.ts
|
|
1045
|
+
function getRenderResult(renderable, console, options) {
|
|
1046
|
+
const result = renderable.__rich_console__(console, options);
|
|
1047
|
+
if ("segments" in result) {
|
|
1048
|
+
return result;
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
segments: Array.from(result),
|
|
1052
|
+
width: options.width
|
|
1053
|
+
// approximation
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
var Live = class {
|
|
1057
|
+
constructor(renderable, console, autoRefresh = true) {
|
|
1058
|
+
this.renderable = renderable;
|
|
1059
|
+
this.console = console;
|
|
1060
|
+
this.autoRefresh = autoRefresh;
|
|
1061
|
+
}
|
|
1062
|
+
_started = false;
|
|
1063
|
+
_lastHeight = 0;
|
|
1064
|
+
start() {
|
|
1065
|
+
this._started = true;
|
|
1066
|
+
this.refresh();
|
|
1067
|
+
}
|
|
1068
|
+
stop() {
|
|
1069
|
+
this._started = false;
|
|
1070
|
+
this.console.print("");
|
|
1071
|
+
}
|
|
1072
|
+
update(renderable) {
|
|
1073
|
+
this.renderable = renderable;
|
|
1074
|
+
this.refresh();
|
|
1075
|
+
}
|
|
1076
|
+
refresh() {
|
|
1077
|
+
if (!this._started) return;
|
|
1078
|
+
if (this._lastHeight > 0) {
|
|
1079
|
+
process.stdout.write(ansiEscapes__default.default.eraseLines(this._lastHeight));
|
|
1080
|
+
}
|
|
1081
|
+
const output = this.console.render(this.renderable);
|
|
1082
|
+
const lines = output.split("\n").length;
|
|
1083
|
+
this._lastHeight = lines;
|
|
1084
|
+
process.stdout.write(output);
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
var Spinner = class {
|
|
1088
|
+
// Type definition issues with cli-spinners
|
|
1089
|
+
constructor(name = "dots", style = Style.null()) {
|
|
1090
|
+
this.name = name;
|
|
1091
|
+
this.style = style;
|
|
1092
|
+
this.spinner = cliSpinners__default.default[name];
|
|
1093
|
+
}
|
|
1094
|
+
frame = 0;
|
|
1095
|
+
// @ts-ignore
|
|
1096
|
+
spinner;
|
|
1097
|
+
get currentFrame() {
|
|
1098
|
+
return this.spinner.frames[this.frame];
|
|
1099
|
+
}
|
|
1100
|
+
__rich_console__(_console, _options) {
|
|
1101
|
+
return {
|
|
1102
|
+
segments: [new Segment(this.currentFrame, this.style)],
|
|
1103
|
+
width: 1
|
|
1104
|
+
// approximates
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
nextFrame() {
|
|
1108
|
+
this.frame = (this.frame + 1) % this.spinner.frames.length;
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
// src/core/lines.ts
|
|
1113
|
+
function splitLines(segments) {
|
|
1114
|
+
const lines = [];
|
|
1115
|
+
let currentLine = [];
|
|
1116
|
+
for (const segment of segments) {
|
|
1117
|
+
if (segment.text.includes("\n")) {
|
|
1118
|
+
const parts = segment.text.split("\n");
|
|
1119
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1120
|
+
const part = parts[i];
|
|
1121
|
+
if (part) {
|
|
1122
|
+
currentLine.push(new Segment(part, segment.style, segment.isControl));
|
|
1123
|
+
}
|
|
1124
|
+
if (i < parts.length - 1) {
|
|
1125
|
+
lines.push(currentLine);
|
|
1126
|
+
currentLine = [];
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
} else {
|
|
1130
|
+
currentLine.push(segment);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
if (currentLine.length > 0) {
|
|
1134
|
+
lines.push(currentLine);
|
|
1135
|
+
}
|
|
1136
|
+
return lines;
|
|
1137
|
+
}
|
|
1138
|
+
function padLine(line, width, style = Style.null()) {
|
|
1139
|
+
const currentWidth = line.reduce((acc, s) => acc + s.cellLength(), 0);
|
|
1140
|
+
if (currentWidth >= width) return line;
|
|
1141
|
+
const padding = width - currentWidth;
|
|
1142
|
+
return [...line, new Segment(" ".repeat(padding), style)];
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/layout/layout.ts
|
|
1146
|
+
var Layout = class _Layout {
|
|
1147
|
+
_renderable = null;
|
|
1148
|
+
_children = [];
|
|
1149
|
+
_direction = "column";
|
|
1150
|
+
size;
|
|
1151
|
+
ratio = 1;
|
|
1152
|
+
minimumSize = 0;
|
|
1153
|
+
visible = true;
|
|
1154
|
+
constructor(renderable, options = {}) {
|
|
1155
|
+
if (renderable) this._renderable = renderable;
|
|
1156
|
+
this.size = options.size;
|
|
1157
|
+
this.ratio = options.ratio ?? 1;
|
|
1158
|
+
this.minimumSize = options.minimumSize ?? 0;
|
|
1159
|
+
this.visible = options.visible ?? true;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Split the layout into a row (horizontal split).
|
|
1163
|
+
*/
|
|
1164
|
+
splitRow(...layouts) {
|
|
1165
|
+
this._direction = "row";
|
|
1166
|
+
this._children = layouts.map((l) => l instanceof _Layout ? l : new _Layout(l));
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Split the layout into a column (vertical split).
|
|
1170
|
+
*/
|
|
1171
|
+
splitColumn(...layouts) {
|
|
1172
|
+
this._direction = "column";
|
|
1173
|
+
this._children = layouts.map((l) => l instanceof _Layout ? l : new _Layout(l));
|
|
1174
|
+
}
|
|
1175
|
+
get renderable() {
|
|
1176
|
+
return this._renderable;
|
|
1177
|
+
}
|
|
1178
|
+
update(renderable) {
|
|
1179
|
+
this._renderable = renderable;
|
|
1180
|
+
}
|
|
1181
|
+
__rich_console__(console, options) {
|
|
1182
|
+
if (!this.visible) return { segments: [], width: 0, height: 0 };
|
|
1183
|
+
const width = options.width ?? console.width;
|
|
1184
|
+
const height = options.height ?? console.height;
|
|
1185
|
+
if (this._children.length === 0) {
|
|
1186
|
+
if (this._renderable) {
|
|
1187
|
+
return getRenderResult(this._renderable, console, { ...options, width, height });
|
|
1188
|
+
}
|
|
1189
|
+
return { segments: [], width, height: 0 };
|
|
1190
|
+
}
|
|
1191
|
+
const segments = [];
|
|
1192
|
+
if (this._direction === "column") {
|
|
1193
|
+
for (const child of this._children) {
|
|
1194
|
+
if (!child.visible) continue;
|
|
1195
|
+
const result = getRenderResult(child, console, { ...options, width });
|
|
1196
|
+
segments.push(...result.segments);
|
|
1197
|
+
const last = result.segments[result.segments.length - 1];
|
|
1198
|
+
if (last && !last.text.endsWith("\n")) {
|
|
1199
|
+
segments.push(new Segment("\n"));
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
} else {
|
|
1203
|
+
const childWidths = this.calculateSizes(width, this._children);
|
|
1204
|
+
const renderedLines = [];
|
|
1205
|
+
let maxHeight = 0;
|
|
1206
|
+
this._children.forEach((child, i) => {
|
|
1207
|
+
if (!child.visible) {
|
|
1208
|
+
renderedLines.push([]);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const w = childWidths[i];
|
|
1212
|
+
const result = getRenderResult(child, console, { ...options, width: w });
|
|
1213
|
+
let childSegments = result.segments;
|
|
1214
|
+
const lines = splitLines(childSegments);
|
|
1215
|
+
renderedLines.push(lines);
|
|
1216
|
+
if (lines.length > maxHeight) maxHeight = lines.length;
|
|
1217
|
+
});
|
|
1218
|
+
for (let y = 0; y < maxHeight; y++) {
|
|
1219
|
+
for (let x = 0; x < this._children.length; x++) {
|
|
1220
|
+
if (!this._children[x].visible) continue;
|
|
1221
|
+
const lines = renderedLines[x];
|
|
1222
|
+
const w = childWidths[x];
|
|
1223
|
+
if (y < lines.length) {
|
|
1224
|
+
const line = lines[y];
|
|
1225
|
+
segments.push(...padLine(line, w));
|
|
1226
|
+
} else {
|
|
1227
|
+
segments.push(new Segment(" ".repeat(w)));
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
segments.push(new Segment("\n"));
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return { segments, width, height };
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Calculates the size (width for rows, height for columns) for each child
|
|
1237
|
+
* based on constraints.
|
|
1238
|
+
*/
|
|
1239
|
+
calculateSizes(availableSpace, children) {
|
|
1240
|
+
const sizes = new Array(children.length).fill(0);
|
|
1241
|
+
const visibleChildren = children.map((c, i) => ({ child: c, index: i })).filter((x) => x.child.visible);
|
|
1242
|
+
if (visibleChildren.length === 0) return sizes;
|
|
1243
|
+
let remainingSpace = availableSpace;
|
|
1244
|
+
let totalRatio = 0;
|
|
1245
|
+
for (const { child, index } of visibleChildren) {
|
|
1246
|
+
if (child.size !== void 0) {
|
|
1247
|
+
const size = Math.min(child.size, remainingSpace);
|
|
1248
|
+
sizes[index] = size;
|
|
1249
|
+
remainingSpace -= size;
|
|
1250
|
+
} else if (child.minimumSize > 0) {
|
|
1251
|
+
sizes[index] = child.minimumSize;
|
|
1252
|
+
remainingSpace -= child.minimumSize;
|
|
1253
|
+
}
|
|
1254
|
+
if (child.size === void 0) {
|
|
1255
|
+
totalRatio += child.ratio;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (remainingSpace <= 0) return sizes;
|
|
1259
|
+
if (totalRatio > 0) {
|
|
1260
|
+
let distributed = 0;
|
|
1261
|
+
for (let i = 0; i < visibleChildren.length; i++) {
|
|
1262
|
+
const { child, index } = visibleChildren[i];
|
|
1263
|
+
if (child.size === void 0) {
|
|
1264
|
+
const share = Math.floor(child.ratio / totalRatio * remainingSpace);
|
|
1265
|
+
sizes[index] += share;
|
|
1266
|
+
distributed += share;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
const dust = remainingSpace - distributed;
|
|
1270
|
+
if (dust > 0) {
|
|
1271
|
+
for (let i = visibleChildren.length - 1; i >= 0; i--) {
|
|
1272
|
+
const { child, index } = visibleChildren[i];
|
|
1273
|
+
if (child.size === void 0) {
|
|
1274
|
+
sizes[index] += dust;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
return sizes;
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
var Text = class {
|
|
1284
|
+
constructor(content, style = Style.null(), justify = "left", overflow = "fold", noWrap = false) {
|
|
1285
|
+
this.style = style;
|
|
1286
|
+
this.justify = justify;
|
|
1287
|
+
this.overflow = overflow;
|
|
1288
|
+
this.noWrap = noWrap;
|
|
1289
|
+
if (typeof content === "string") {
|
|
1290
|
+
const parser = new MarkupParser();
|
|
1291
|
+
this.segments = parser.parse(content);
|
|
1292
|
+
} else {
|
|
1293
|
+
this.segments = content;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
segments;
|
|
1297
|
+
__rich_console__(console, options) {
|
|
1298
|
+
const width = options.width ?? console.width;
|
|
1299
|
+
const text = this.segments.map((s) => s.render()).join("");
|
|
1300
|
+
let wrapped = text;
|
|
1301
|
+
if (!this.noWrap) {
|
|
1302
|
+
wrapped = wrapAnsi__default.default(text, width, { hard: true, trim: false });
|
|
1303
|
+
}
|
|
1304
|
+
const resultSegments = wrapped.split("\n").flatMap((line) => {
|
|
1305
|
+
return [new Segment(line), new Segment("\n", Style.null(), true)];
|
|
1306
|
+
});
|
|
1307
|
+
return {
|
|
1308
|
+
segments: resultSegments,
|
|
1309
|
+
width
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
// src/status/status.ts
|
|
1315
|
+
var Status = class {
|
|
1316
|
+
live;
|
|
1317
|
+
spinner;
|
|
1318
|
+
message;
|
|
1319
|
+
interval = null;
|
|
1320
|
+
constructor(message, options = {}) {
|
|
1321
|
+
this.message = message;
|
|
1322
|
+
this.spinner = new Spinner(options.spinner ?? "dots");
|
|
1323
|
+
const console = options.console ?? new Console();
|
|
1324
|
+
this.live = new Live(this.render(), console);
|
|
1325
|
+
}
|
|
1326
|
+
start() {
|
|
1327
|
+
this.live.start();
|
|
1328
|
+
this.interval = setInterval(() => {
|
|
1329
|
+
this.spinner.nextFrame();
|
|
1330
|
+
this.live.update(this.render());
|
|
1331
|
+
}, 80);
|
|
1332
|
+
}
|
|
1333
|
+
stop() {
|
|
1334
|
+
if (this.interval) clearInterval(this.interval);
|
|
1335
|
+
this.live.stop();
|
|
1336
|
+
}
|
|
1337
|
+
update(message) {
|
|
1338
|
+
this.message = message;
|
|
1339
|
+
this.live.update(this.render());
|
|
1340
|
+
}
|
|
1341
|
+
render() {
|
|
1342
|
+
const layout = new Layout();
|
|
1343
|
+
layout.splitRow(
|
|
1344
|
+
this.spinner,
|
|
1345
|
+
new Text(" " + this.message)
|
|
1346
|
+
);
|
|
1347
|
+
return layout;
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
// src/console/console.ts
|
|
1352
|
+
var Console = class {
|
|
1353
|
+
terminal;
|
|
1354
|
+
markupParser;
|
|
1355
|
+
options;
|
|
1356
|
+
theme;
|
|
1357
|
+
constructor(options = {}) {
|
|
1358
|
+
this.options = options;
|
|
1359
|
+
this.terminal = new Terminal();
|
|
1360
|
+
this.theme = options.theme ?? DEFAULT_THEME;
|
|
1361
|
+
this.markupParser = new MarkupParser(this.theme);
|
|
1362
|
+
}
|
|
1363
|
+
get width() {
|
|
1364
|
+
return this.options.width ?? this.terminal.width;
|
|
1365
|
+
}
|
|
1366
|
+
get height() {
|
|
1367
|
+
return this.options.height ?? this.terminal.height;
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Prints objects to the console.
|
|
1371
|
+
*/
|
|
1372
|
+
print(...objects) {
|
|
1373
|
+
const lastObj = objects[objects.length - 1];
|
|
1374
|
+
let printObjects = objects;
|
|
1375
|
+
let options = {};
|
|
1376
|
+
if (objects.length > 1 && typeof lastObj === "object" && lastObj !== null && !isRenderable(lastObj) && ("style" in lastObj || "markup" in lastObj)) {
|
|
1377
|
+
options = objects.pop();
|
|
1378
|
+
printObjects = objects;
|
|
1379
|
+
}
|
|
1380
|
+
const output = printObjects.map((obj) => {
|
|
1381
|
+
if (typeof obj === "string") {
|
|
1382
|
+
return this.renderString(obj, options.markup ?? true);
|
|
1383
|
+
}
|
|
1384
|
+
if (isRenderable(obj)) {
|
|
1385
|
+
return this.render(obj);
|
|
1386
|
+
}
|
|
1387
|
+
return String(obj);
|
|
1388
|
+
}).join(" ");
|
|
1389
|
+
this.write(output + "\n");
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Prints a formatted exception.
|
|
1393
|
+
*/
|
|
1394
|
+
printException(error) {
|
|
1395
|
+
const traceback = new Traceback(error);
|
|
1396
|
+
this.print(traceback);
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Displays a status spinner.
|
|
1400
|
+
*/
|
|
1401
|
+
status(message, options = {}) {
|
|
1402
|
+
return new Status(message, { console: this, ...options });
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Run a task with a status spinner.
|
|
1406
|
+
*/
|
|
1407
|
+
async withStatus(message, task, options = {}) {
|
|
1408
|
+
const status = new Status(message, { console: this, ...options });
|
|
1409
|
+
status.start();
|
|
1410
|
+
try {
|
|
1411
|
+
return await task(status);
|
|
1412
|
+
} finally {
|
|
1413
|
+
status.stop();
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Renders a renderable object to a string.
|
|
1418
|
+
*/
|
|
1419
|
+
render(renderable) {
|
|
1420
|
+
const result = getRenderResult(renderable, this, this.options);
|
|
1421
|
+
return result.segments.map((s) => s.render()).join("");
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Internal string rendering with markup and wrapping.
|
|
1425
|
+
*/
|
|
1426
|
+
renderString(text, markup = true) {
|
|
1427
|
+
const segments = markup ? this.markupParser.parse(text) : [new Segment(text)];
|
|
1428
|
+
const rendered = segments.map((s) => s.render()).join("");
|
|
1429
|
+
return wrapAnsi__default.default(rendered, this.width, { hard: true });
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Low-level write to stdout.
|
|
1433
|
+
*/
|
|
1434
|
+
write(text) {
|
|
1435
|
+
process2__default.default.stdout.write(text);
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
var CUSTOM_BOXES = {
|
|
1439
|
+
// Rounded corners (may not be in all versions of cli-boxes)
|
|
1440
|
+
rounded: {
|
|
1441
|
+
topLeft: "\u256D",
|
|
1442
|
+
top: "\u2500",
|
|
1443
|
+
topRight: "\u256E",
|
|
1444
|
+
right: "\u2502",
|
|
1445
|
+
bottomRight: "\u256F",
|
|
1446
|
+
bottom: "\u2500",
|
|
1447
|
+
bottomLeft: "\u2570",
|
|
1448
|
+
left: "\u2502",
|
|
1449
|
+
topMid: "\u252C",
|
|
1450
|
+
midMid: "\u253C",
|
|
1451
|
+
bottomMid: "\u2534",
|
|
1452
|
+
leftMid: "\u251C",
|
|
1453
|
+
rightMid: "\u2524",
|
|
1454
|
+
mid: "\u2500",
|
|
1455
|
+
verticalMid: "\u2502"
|
|
1456
|
+
},
|
|
1457
|
+
round: {
|
|
1458
|
+
topLeft: "\u256D",
|
|
1459
|
+
top: "\u2500",
|
|
1460
|
+
topRight: "\u256E",
|
|
1461
|
+
right: "\u2502",
|
|
1462
|
+
bottomRight: "\u256F",
|
|
1463
|
+
bottom: "\u2500",
|
|
1464
|
+
bottomLeft: "\u2570",
|
|
1465
|
+
left: "\u2502",
|
|
1466
|
+
topMid: "\u252C",
|
|
1467
|
+
midMid: "\u253C",
|
|
1468
|
+
bottomMid: "\u2534",
|
|
1469
|
+
leftMid: "\u251C",
|
|
1470
|
+
rightMid: "\u2524",
|
|
1471
|
+
mid: "\u2500",
|
|
1472
|
+
verticalMid: "\u2502"
|
|
1473
|
+
},
|
|
1474
|
+
// Heavy/bold lines
|
|
1475
|
+
heavy: {
|
|
1476
|
+
topLeft: "\u250F",
|
|
1477
|
+
top: "\u2501",
|
|
1478
|
+
topRight: "\u2513",
|
|
1479
|
+
right: "\u2503",
|
|
1480
|
+
bottomRight: "\u251B",
|
|
1481
|
+
bottom: "\u2501",
|
|
1482
|
+
bottomLeft: "\u2517",
|
|
1483
|
+
left: "\u2503",
|
|
1484
|
+
topMid: "\u2533",
|
|
1485
|
+
midMid: "\u254B",
|
|
1486
|
+
bottomMid: "\u253B",
|
|
1487
|
+
leftMid: "\u2523",
|
|
1488
|
+
rightMid: "\u252B",
|
|
1489
|
+
mid: "\u2501",
|
|
1490
|
+
verticalMid: "\u2503"
|
|
1491
|
+
},
|
|
1492
|
+
// Double lines
|
|
1493
|
+
double: {
|
|
1494
|
+
topLeft: "\u2554",
|
|
1495
|
+
top: "\u2550",
|
|
1496
|
+
topRight: "\u2557",
|
|
1497
|
+
right: "\u2551",
|
|
1498
|
+
bottomRight: "\u255D",
|
|
1499
|
+
bottom: "\u2550",
|
|
1500
|
+
bottomLeft: "\u255A",
|
|
1501
|
+
left: "\u2551",
|
|
1502
|
+
topMid: "\u2566",
|
|
1503
|
+
midMid: "\u256C",
|
|
1504
|
+
bottomMid: "\u2569",
|
|
1505
|
+
leftMid: "\u2560",
|
|
1506
|
+
rightMid: "\u2563",
|
|
1507
|
+
mid: "\u2550",
|
|
1508
|
+
verticalMid: "\u2551"
|
|
1509
|
+
},
|
|
1510
|
+
// Single/square lines
|
|
1511
|
+
single: {
|
|
1512
|
+
topLeft: "\u250C",
|
|
1513
|
+
top: "\u2500",
|
|
1514
|
+
topRight: "\u2510",
|
|
1515
|
+
right: "\u2502",
|
|
1516
|
+
bottomRight: "\u2518",
|
|
1517
|
+
bottom: "\u2500",
|
|
1518
|
+
bottomLeft: "\u2514",
|
|
1519
|
+
left: "\u2502",
|
|
1520
|
+
topMid: "\u252C",
|
|
1521
|
+
midMid: "\u253C",
|
|
1522
|
+
bottomMid: "\u2534",
|
|
1523
|
+
leftMid: "\u251C",
|
|
1524
|
+
rightMid: "\u2524",
|
|
1525
|
+
mid: "\u2500",
|
|
1526
|
+
verticalMid: "\u2502"
|
|
1527
|
+
},
|
|
1528
|
+
square: {
|
|
1529
|
+
topLeft: "\u250C",
|
|
1530
|
+
top: "\u2500",
|
|
1531
|
+
topRight: "\u2510",
|
|
1532
|
+
right: "\u2502",
|
|
1533
|
+
bottomRight: "\u2518",
|
|
1534
|
+
bottom: "\u2500",
|
|
1535
|
+
bottomLeft: "\u2514",
|
|
1536
|
+
left: "\u2502",
|
|
1537
|
+
topMid: "\u252C",
|
|
1538
|
+
midMid: "\u253C",
|
|
1539
|
+
bottomMid: "\u2534",
|
|
1540
|
+
leftMid: "\u251C",
|
|
1541
|
+
rightMid: "\u2524",
|
|
1542
|
+
mid: "\u2500",
|
|
1543
|
+
verticalMid: "\u2502"
|
|
1544
|
+
},
|
|
1545
|
+
// ASCII-safe
|
|
1546
|
+
ascii: {
|
|
1547
|
+
topLeft: "+",
|
|
1548
|
+
top: "-",
|
|
1549
|
+
topRight: "+",
|
|
1550
|
+
right: "|",
|
|
1551
|
+
bottomRight: "+",
|
|
1552
|
+
bottom: "-",
|
|
1553
|
+
bottomLeft: "+",
|
|
1554
|
+
left: "|",
|
|
1555
|
+
topMid: "+",
|
|
1556
|
+
midMid: "+",
|
|
1557
|
+
bottomMid: "+",
|
|
1558
|
+
leftMid: "+",
|
|
1559
|
+
rightMid: "+",
|
|
1560
|
+
mid: "-",
|
|
1561
|
+
verticalMid: "|"
|
|
1562
|
+
},
|
|
1563
|
+
// Minimal - no borders
|
|
1564
|
+
minimal: {
|
|
1565
|
+
topLeft: " ",
|
|
1566
|
+
top: " ",
|
|
1567
|
+
topRight: " ",
|
|
1568
|
+
right: " ",
|
|
1569
|
+
bottomRight: " ",
|
|
1570
|
+
bottom: " ",
|
|
1571
|
+
bottomLeft: " ",
|
|
1572
|
+
left: " ",
|
|
1573
|
+
topMid: " ",
|
|
1574
|
+
midMid: " ",
|
|
1575
|
+
bottomMid: " ",
|
|
1576
|
+
leftMid: " ",
|
|
1577
|
+
rightMid: " ",
|
|
1578
|
+
mid: "\u2500",
|
|
1579
|
+
verticalMid: " "
|
|
1580
|
+
},
|
|
1581
|
+
// Simple - just horizontal lines
|
|
1582
|
+
simple: {
|
|
1583
|
+
topLeft: " ",
|
|
1584
|
+
top: "\u2500",
|
|
1585
|
+
topRight: " ",
|
|
1586
|
+
right: " ",
|
|
1587
|
+
bottomRight: " ",
|
|
1588
|
+
bottom: "\u2500",
|
|
1589
|
+
bottomLeft: " ",
|
|
1590
|
+
left: " ",
|
|
1591
|
+
topMid: " ",
|
|
1592
|
+
midMid: "\u2500",
|
|
1593
|
+
bottomMid: " ",
|
|
1594
|
+
leftMid: " ",
|
|
1595
|
+
rightMid: " ",
|
|
1596
|
+
mid: "\u2500",
|
|
1597
|
+
verticalMid: " "
|
|
1598
|
+
},
|
|
1599
|
+
// Markdown style
|
|
1600
|
+
markdown: {
|
|
1601
|
+
topLeft: " ",
|
|
1602
|
+
top: " ",
|
|
1603
|
+
topRight: " ",
|
|
1604
|
+
right: "|",
|
|
1605
|
+
bottomRight: " ",
|
|
1606
|
+
bottom: " ",
|
|
1607
|
+
bottomLeft: " ",
|
|
1608
|
+
left: "|",
|
|
1609
|
+
topMid: " ",
|
|
1610
|
+
midMid: "|",
|
|
1611
|
+
bottomMid: " ",
|
|
1612
|
+
leftMid: "|",
|
|
1613
|
+
rightMid: "|",
|
|
1614
|
+
mid: "-",
|
|
1615
|
+
verticalMid: "|"
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
function getBox(style) {
|
|
1619
|
+
if (style === "none") return null;
|
|
1620
|
+
if (style in CUSTOM_BOXES) {
|
|
1621
|
+
return CUSTOM_BOXES[style];
|
|
1622
|
+
}
|
|
1623
|
+
if (style === "bold") {
|
|
1624
|
+
return CUSTOM_BOXES.heavy;
|
|
1625
|
+
}
|
|
1626
|
+
const cliBox = boxes__default.default[style];
|
|
1627
|
+
if (cliBox) {
|
|
1628
|
+
return {
|
|
1629
|
+
...cliBox,
|
|
1630
|
+
topMid: cliBox.topMid ?? "\u252C",
|
|
1631
|
+
midMid: cliBox.midMid ?? "\u253C",
|
|
1632
|
+
bottomMid: cliBox.bottomMid ?? "\u2534",
|
|
1633
|
+
leftMid: cliBox.leftMid ?? "\u251C",
|
|
1634
|
+
rightMid: cliBox.rightMid ?? "\u2524",
|
|
1635
|
+
mid: cliBox.mid ?? "\u2500",
|
|
1636
|
+
verticalMid: cliBox.verticalMid ?? "\u2502"
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
return CUSTOM_BOXES.rounded;
|
|
1640
|
+
}
|
|
1641
|
+
function listBoxStyles() {
|
|
1642
|
+
const customStyles = Object.keys(CUSTOM_BOXES);
|
|
1643
|
+
const cliBoxStyles = Object.keys(boxes__default.default);
|
|
1644
|
+
return [.../* @__PURE__ */ new Set([...customStyles, ...cliBoxStyles])];
|
|
1645
|
+
}
|
|
1646
|
+
var Panel = class _Panel {
|
|
1647
|
+
constructor(renderable, options = {}) {
|
|
1648
|
+
this.renderable = renderable;
|
|
1649
|
+
this.options = options;
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Create a panel that fits its content (expand=false).
|
|
1653
|
+
*/
|
|
1654
|
+
static fit(renderable, options = {}) {
|
|
1655
|
+
return new _Panel(renderable, { ...options, expand: false });
|
|
1656
|
+
}
|
|
1657
|
+
__rich_console__(console, consoleOptions) {
|
|
1658
|
+
const box = getBox(this.options.box ?? "rounded");
|
|
1659
|
+
const expand = this.options.expand ?? true;
|
|
1660
|
+
const maxWidth = this.options.width ?? consoleOptions.width ?? console.width;
|
|
1661
|
+
const borderStyle = typeof this.options.borderStyle === "string" ? Style.parse(this.options.borderStyle) : this.options.borderStyle ?? Style.parse("dim");
|
|
1662
|
+
const titleAlign = this.options.titleAlign ?? "center";
|
|
1663
|
+
const subtitleAlign = this.options.subtitleAlign ?? "center";
|
|
1664
|
+
const padding = this.normalizePadding(this.options.padding ?? 1);
|
|
1665
|
+
const segments = [];
|
|
1666
|
+
if (!box) {
|
|
1667
|
+
return { segments: [], width: 0 };
|
|
1668
|
+
}
|
|
1669
|
+
let contentSegments = [];
|
|
1670
|
+
if (typeof this.renderable === "string") {
|
|
1671
|
+
contentSegments = [new Segment(this.renderable)];
|
|
1672
|
+
} else if (isRenderable(this.renderable)) {
|
|
1673
|
+
const contentWidth = maxWidth - 2 - padding[1] - padding[3];
|
|
1674
|
+
const result = this.renderable.__rich_console__(console, {
|
|
1675
|
+
...consoleOptions,
|
|
1676
|
+
width: contentWidth
|
|
1677
|
+
});
|
|
1678
|
+
if ("segments" in result) {
|
|
1679
|
+
contentSegments = Array.from(result.segments);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
const lines = splitLines(contentSegments);
|
|
1683
|
+
let maxContentWidth = 0;
|
|
1684
|
+
for (const line of lines) {
|
|
1685
|
+
const lineWidth = line.reduce((w, seg) => w + stringWidth3__default.default(seg.text), 0);
|
|
1686
|
+
if (lineWidth > maxContentWidth) maxContentWidth = lineWidth;
|
|
1687
|
+
}
|
|
1688
|
+
const titleWidth = this.options.title ? stringWidth3__default.default(this.options.title) + 4 : 0;
|
|
1689
|
+
const subtitleWidth = this.options.subtitle ? stringWidth3__default.default(this.options.subtitle) + 4 : 0;
|
|
1690
|
+
let panelWidth;
|
|
1691
|
+
if (expand) {
|
|
1692
|
+
panelWidth = maxWidth;
|
|
1693
|
+
} else {
|
|
1694
|
+
panelWidth = Math.min(
|
|
1695
|
+
maxWidth,
|
|
1696
|
+
Math.max(maxContentWidth + 2 + padding[1] + padding[3], titleWidth + 2, subtitleWidth + 2)
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
const innerWidth = panelWidth - 2;
|
|
1700
|
+
segments.push(...this.renderTopBorder(box, innerWidth, borderStyle, titleAlign));
|
|
1701
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1702
|
+
for (let i = 0; i < padding[0]; i++) {
|
|
1703
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1704
|
+
segments.push(new Segment(" ".repeat(innerWidth)));
|
|
1705
|
+
segments.push(new Segment(box.right, borderStyle));
|
|
1706
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1707
|
+
}
|
|
1708
|
+
for (const line of lines) {
|
|
1709
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1710
|
+
segments.push(new Segment(" ".repeat(padding[3])));
|
|
1711
|
+
const contentPaddedWidth = innerWidth - padding[1] - padding[3];
|
|
1712
|
+
const paddedLine = padLine(line, contentPaddedWidth);
|
|
1713
|
+
segments.push(...paddedLine);
|
|
1714
|
+
segments.push(new Segment(" ".repeat(padding[1])));
|
|
1715
|
+
segments.push(new Segment(box.right, borderStyle));
|
|
1716
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1717
|
+
}
|
|
1718
|
+
if (lines.length === 0) {
|
|
1719
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1720
|
+
segments.push(new Segment(" ".repeat(innerWidth)));
|
|
1721
|
+
segments.push(new Segment(box.right, borderStyle));
|
|
1722
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1723
|
+
}
|
|
1724
|
+
for (let i = 0; i < padding[2]; i++) {
|
|
1725
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1726
|
+
segments.push(new Segment(" ".repeat(innerWidth)));
|
|
1727
|
+
segments.push(new Segment(box.right, borderStyle));
|
|
1728
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1729
|
+
}
|
|
1730
|
+
segments.push(...this.renderBottomBorder(box, innerWidth, borderStyle, subtitleAlign));
|
|
1731
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1732
|
+
return {
|
|
1733
|
+
segments,
|
|
1734
|
+
width: panelWidth
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Normalize padding to [top, right, bottom, left] format.
|
|
1739
|
+
*/
|
|
1740
|
+
normalizePadding(padding) {
|
|
1741
|
+
if (typeof padding === "number") {
|
|
1742
|
+
return [padding, padding, padding, padding];
|
|
1743
|
+
}
|
|
1744
|
+
if (padding.length === 2) {
|
|
1745
|
+
return [padding[0], padding[1], padding[0], padding[1]];
|
|
1746
|
+
}
|
|
1747
|
+
return padding;
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Render top border with optional title.
|
|
1751
|
+
*/
|
|
1752
|
+
renderTopBorder(box, innerWidth, borderStyle, align) {
|
|
1753
|
+
const segments = [];
|
|
1754
|
+
if (this.options.title) {
|
|
1755
|
+
const title = ` ${this.options.title} `;
|
|
1756
|
+
const titleWidth = stringWidth3__default.default(title);
|
|
1757
|
+
const remainingWidth = Math.max(0, innerWidth - titleWidth);
|
|
1758
|
+
let leftLine;
|
|
1759
|
+
let rightLine;
|
|
1760
|
+
switch (align) {
|
|
1761
|
+
case "left":
|
|
1762
|
+
leftLine = "";
|
|
1763
|
+
rightLine = box.top.repeat(remainingWidth);
|
|
1764
|
+
break;
|
|
1765
|
+
case "right":
|
|
1766
|
+
leftLine = box.top.repeat(remainingWidth);
|
|
1767
|
+
rightLine = "";
|
|
1768
|
+
break;
|
|
1769
|
+
case "center":
|
|
1770
|
+
default: {
|
|
1771
|
+
const leftWidth = Math.floor(remainingWidth / 2);
|
|
1772
|
+
leftLine = box.top.repeat(leftWidth);
|
|
1773
|
+
rightLine = box.top.repeat(remainingWidth - leftWidth);
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
segments.push(new Segment(box.topLeft, borderStyle));
|
|
1778
|
+
segments.push(new Segment(leftLine, borderStyle));
|
|
1779
|
+
segments.push(new Segment(title, Style.parse("bold")));
|
|
1780
|
+
segments.push(new Segment(rightLine, borderStyle));
|
|
1781
|
+
segments.push(new Segment(box.topRight, borderStyle));
|
|
1782
|
+
} else {
|
|
1783
|
+
segments.push(
|
|
1784
|
+
new Segment(box.topLeft + box.top.repeat(innerWidth) + box.topRight, borderStyle)
|
|
1785
|
+
);
|
|
1786
|
+
}
|
|
1787
|
+
return segments;
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Render bottom border with optional subtitle.
|
|
1791
|
+
*/
|
|
1792
|
+
renderBottomBorder(box, innerWidth, borderStyle, align) {
|
|
1793
|
+
const segments = [];
|
|
1794
|
+
if (this.options.subtitle) {
|
|
1795
|
+
const subtitle = ` ${this.options.subtitle} `;
|
|
1796
|
+
const subtitleWidth = stringWidth3__default.default(subtitle);
|
|
1797
|
+
const remainingWidth = Math.max(0, innerWidth - subtitleWidth);
|
|
1798
|
+
let leftLine;
|
|
1799
|
+
let rightLine;
|
|
1800
|
+
switch (align) {
|
|
1801
|
+
case "left":
|
|
1802
|
+
leftLine = "";
|
|
1803
|
+
rightLine = box.bottom.repeat(remainingWidth);
|
|
1804
|
+
break;
|
|
1805
|
+
case "right":
|
|
1806
|
+
leftLine = box.bottom.repeat(remainingWidth);
|
|
1807
|
+
rightLine = "";
|
|
1808
|
+
break;
|
|
1809
|
+
case "center":
|
|
1810
|
+
default: {
|
|
1811
|
+
const leftWidth = Math.floor(remainingWidth / 2);
|
|
1812
|
+
leftLine = box.bottom.repeat(leftWidth);
|
|
1813
|
+
rightLine = box.bottom.repeat(remainingWidth - leftWidth);
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
segments.push(new Segment(box.bottomLeft, borderStyle));
|
|
1818
|
+
segments.push(new Segment(leftLine, borderStyle));
|
|
1819
|
+
segments.push(new Segment(subtitle, Style.parse("dim italic")));
|
|
1820
|
+
segments.push(new Segment(rightLine, borderStyle));
|
|
1821
|
+
segments.push(new Segment(box.bottomRight, borderStyle));
|
|
1822
|
+
} else {
|
|
1823
|
+
segments.push(
|
|
1824
|
+
new Segment(box.bottomLeft + box.bottom.repeat(innerWidth) + box.bottomRight, borderStyle)
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
return segments;
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
var Rule = class {
|
|
1831
|
+
constructor(title = "", characters = "\u2500", style = Style.null()) {
|
|
1832
|
+
this.title = title;
|
|
1833
|
+
this.characters = characters;
|
|
1834
|
+
this.style = style;
|
|
1835
|
+
}
|
|
1836
|
+
__rich_console__(console, options) {
|
|
1837
|
+
const width = options.width ?? console.width;
|
|
1838
|
+
let line = "";
|
|
1839
|
+
if (this.title) {
|
|
1840
|
+
const titleText = ` ${this.title} `;
|
|
1841
|
+
const titleWidth = stringWidth3__default.default(titleText);
|
|
1842
|
+
const sideWidth = Math.floor((width - titleWidth) / 2);
|
|
1843
|
+
line = this.characters.repeat(sideWidth) + titleText + this.characters.repeat(width - titleWidth - sideWidth);
|
|
1844
|
+
} else {
|
|
1845
|
+
line = this.characters.repeat(width);
|
|
1846
|
+
}
|
|
1847
|
+
return {
|
|
1848
|
+
segments: [new Segment(line, this.style), new Segment("\n", Style.null(), true)],
|
|
1849
|
+
width
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
var Column = class {
|
|
1854
|
+
constructor(options) {
|
|
1855
|
+
this.options = options;
|
|
1856
|
+
}
|
|
1857
|
+
get header() {
|
|
1858
|
+
return this.options.header ?? "";
|
|
1859
|
+
}
|
|
1860
|
+
get footer() {
|
|
1861
|
+
return this.options.footer ?? "";
|
|
1862
|
+
}
|
|
1863
|
+
get justify() {
|
|
1864
|
+
return this.options.justify ?? "left";
|
|
1865
|
+
}
|
|
1866
|
+
get style() {
|
|
1867
|
+
return typeof this.options.style === "string" ? Style.parse(this.options.style) : this.options.style ?? Style.null();
|
|
1868
|
+
}
|
|
1869
|
+
get headerStyle() {
|
|
1870
|
+
return typeof this.options.headerStyle === "string" ? Style.parse(this.options.headerStyle) : this.options.headerStyle ?? Style.null();
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
var Table = class {
|
|
1874
|
+
constructor(options = {}) {
|
|
1875
|
+
this.options = options;
|
|
1876
|
+
}
|
|
1877
|
+
columns = [];
|
|
1878
|
+
rows = [];
|
|
1879
|
+
footerRow = [];
|
|
1880
|
+
addColumn(header, options) {
|
|
1881
|
+
if (typeof header === "string") {
|
|
1882
|
+
this.columns.push(new Column({ header, ...options }));
|
|
1883
|
+
} else {
|
|
1884
|
+
this.columns.push(new Column(header));
|
|
1885
|
+
}
|
|
1886
|
+
return this;
|
|
1887
|
+
}
|
|
1888
|
+
addRow(...cells) {
|
|
1889
|
+
this.rows.push(cells);
|
|
1890
|
+
return this;
|
|
1891
|
+
}
|
|
1892
|
+
addFooter(...cells) {
|
|
1893
|
+
this.footerRow = cells;
|
|
1894
|
+
return this;
|
|
1895
|
+
}
|
|
1896
|
+
alignText(text, width, justify) {
|
|
1897
|
+
const textWidth = stringWidth3__default.default(text);
|
|
1898
|
+
const space = Math.max(0, width - textWidth);
|
|
1899
|
+
if (justify === "left") return text + " ".repeat(space);
|
|
1900
|
+
if (justify === "right") return " ".repeat(space) + text;
|
|
1901
|
+
const leftSpace = Math.floor(space / 2);
|
|
1902
|
+
const rightSpace = space - leftSpace;
|
|
1903
|
+
return " ".repeat(leftSpace) + text + " ".repeat(rightSpace);
|
|
1904
|
+
}
|
|
1905
|
+
__rich_console__(console, consoleOptions) {
|
|
1906
|
+
const width = consoleOptions.width ?? console.width;
|
|
1907
|
+
const box = getBox(this.options.box ?? "rounded");
|
|
1908
|
+
const segments = [];
|
|
1909
|
+
const borderStyle = typeof this.options.borderStyle === "string" ? Style.parse(this.options.borderStyle) : this.options.borderStyle ?? Style.parse("dim");
|
|
1910
|
+
const headerStyle = typeof this.options.headerStyle === "string" ? Style.parse(this.options.headerStyle) : this.options.headerStyle ?? Style.parse("bold cyan");
|
|
1911
|
+
const titleStyle = typeof this.options.titleStyle === "string" ? Style.parse(this.options.titleStyle) : this.options.titleStyle ?? Style.parse("bold");
|
|
1912
|
+
const showLines = this.options.showLines ?? false;
|
|
1913
|
+
const rowStyles = this.options.rowStyles ?? [];
|
|
1914
|
+
const padding = this.options.padding ?? 1;
|
|
1915
|
+
if (!box) return { segments: [], width: 0 };
|
|
1916
|
+
const totalBorderWidth = this.columns.length + 1;
|
|
1917
|
+
const paddingWidth = padding * 2 * this.columns.length;
|
|
1918
|
+
const availableWidth = width - totalBorderWidth - paddingWidth;
|
|
1919
|
+
const colWidth = Math.max(1, Math.floor(availableWidth / this.columns.length));
|
|
1920
|
+
const paddingStr = " ".repeat(padding);
|
|
1921
|
+
if (this.options.title) {
|
|
1922
|
+
const titleLine = this.alignText(this.options.title, width, "center");
|
|
1923
|
+
segments.push(new Segment(titleLine, titleStyle), new Segment("\n", Style.null(), true));
|
|
1924
|
+
}
|
|
1925
|
+
if (this.options.showHeader !== false) {
|
|
1926
|
+
segments.push(
|
|
1927
|
+
new Segment(
|
|
1928
|
+
box.topLeft + this.columns.map(() => (box.top || "\u2500").repeat(colWidth + padding * 2)).join(box.topMid || "\u252C") + box.topRight,
|
|
1929
|
+
borderStyle
|
|
1930
|
+
),
|
|
1931
|
+
new Segment("\n", Style.null(), true)
|
|
1932
|
+
);
|
|
1933
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1934
|
+
this.columns.forEach((col, i) => {
|
|
1935
|
+
const text = this.alignText(col.header, colWidth, col.justify);
|
|
1936
|
+
const cellStyle = col.headerStyle.combine(headerStyle);
|
|
1937
|
+
segments.push(new Segment(paddingStr + text + paddingStr, cellStyle));
|
|
1938
|
+
segments.push(
|
|
1939
|
+
new Segment(
|
|
1940
|
+
i === this.columns.length - 1 ? box.right : box.verticalMid || "\u2502",
|
|
1941
|
+
borderStyle
|
|
1942
|
+
)
|
|
1943
|
+
);
|
|
1944
|
+
});
|
|
1945
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1946
|
+
segments.push(
|
|
1947
|
+
new Segment(
|
|
1948
|
+
(box.leftMid || "\u251C") + this.columns.map(() => (box.mid || "\u2500").repeat(colWidth + padding * 2)).join(box.midMid || "\u253C") + (box.rightMid || "\u2524"),
|
|
1949
|
+
borderStyle
|
|
1950
|
+
),
|
|
1951
|
+
new Segment("\n", Style.null(), true)
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
this.rows.forEach((row, rowIndex) => {
|
|
1955
|
+
let rowStyle = Style.null();
|
|
1956
|
+
if (rowStyles.length > 0) {
|
|
1957
|
+
const styleStr = rowStyles[rowIndex % rowStyles.length];
|
|
1958
|
+
if (styleStr) {
|
|
1959
|
+
rowStyle = Style.parse(styleStr);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
1963
|
+
this.columns.forEach((col, i) => {
|
|
1964
|
+
const cell = row[i];
|
|
1965
|
+
let cellSegments = [];
|
|
1966
|
+
if (typeof cell === "string") {
|
|
1967
|
+
const text = this.alignText(cell, colWidth, col.justify);
|
|
1968
|
+
const cellStyle = col.style.combine(rowStyle);
|
|
1969
|
+
cellSegments = [new Segment(paddingStr + text + paddingStr, cellStyle)];
|
|
1970
|
+
} else if (isRenderable(cell)) {
|
|
1971
|
+
const result = getRenderResult(cell, console, { ...consoleOptions, width: colWidth });
|
|
1972
|
+
segments.push(new Segment(paddingStr));
|
|
1973
|
+
cellSegments = result.segments.map((s) => {
|
|
1974
|
+
return new Segment(s.text, s.style.combine(rowStyle), s.isControl);
|
|
1975
|
+
});
|
|
1976
|
+
const contentWidth = result.width ?? 0;
|
|
1977
|
+
const space = Math.max(0, colWidth - contentWidth);
|
|
1978
|
+
if (space > 0) {
|
|
1979
|
+
cellSegments.push(new Segment(" ".repeat(space), rowStyle));
|
|
1980
|
+
}
|
|
1981
|
+
cellSegments.push(new Segment(paddingStr));
|
|
1982
|
+
}
|
|
1983
|
+
segments.push(...cellSegments);
|
|
1984
|
+
segments.push(
|
|
1985
|
+
new Segment(
|
|
1986
|
+
i === this.columns.length - 1 ? box.right : box.verticalMid || "\u2502",
|
|
1987
|
+
borderStyle
|
|
1988
|
+
)
|
|
1989
|
+
);
|
|
1990
|
+
});
|
|
1991
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
1992
|
+
if (showLines && rowIndex < this.rows.length - 1) {
|
|
1993
|
+
segments.push(
|
|
1994
|
+
new Segment(
|
|
1995
|
+
(box.leftMid || "\u251C") + this.columns.map(() => (box.mid || "\u2500").repeat(colWidth + padding * 2)).join(box.midMid || "\u253C") + (box.rightMid || "\u2524"),
|
|
1996
|
+
borderStyle
|
|
1997
|
+
),
|
|
1998
|
+
new Segment("\n", Style.null(), true)
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
if (this.options.showFooter && this.footerRow.length > 0) {
|
|
2003
|
+
const footerStyle = typeof this.options.footerStyle === "string" ? Style.parse(this.options.footerStyle) : this.options.footerStyle ?? Style.parse("bold");
|
|
2004
|
+
segments.push(
|
|
2005
|
+
new Segment(
|
|
2006
|
+
(box.leftMid || "\u251C") + this.columns.map(() => (box.mid || "\u2500").repeat(colWidth + padding * 2)).join(box.midMid || "\u253C") + (box.rightMid || "\u2524"),
|
|
2007
|
+
borderStyle
|
|
2008
|
+
),
|
|
2009
|
+
new Segment("\n", Style.null(), true)
|
|
2010
|
+
);
|
|
2011
|
+
segments.push(new Segment(box.left, borderStyle));
|
|
2012
|
+
this.columns.forEach((col, i) => {
|
|
2013
|
+
const cell = this.footerRow[i];
|
|
2014
|
+
const text = typeof cell === "string" ? cell : "";
|
|
2015
|
+
const alignedText = this.alignText(text, colWidth, col.justify);
|
|
2016
|
+
segments.push(new Segment(paddingStr + alignedText + paddingStr, footerStyle));
|
|
2017
|
+
segments.push(
|
|
2018
|
+
new Segment(
|
|
2019
|
+
i === this.columns.length - 1 ? box.right : box.verticalMid || "\u2502",
|
|
2020
|
+
borderStyle
|
|
2021
|
+
)
|
|
2022
|
+
);
|
|
2023
|
+
});
|
|
2024
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
2025
|
+
}
|
|
2026
|
+
segments.push(
|
|
2027
|
+
new Segment(
|
|
2028
|
+
box.bottomLeft + this.columns.map(() => (box.bottom || "\u2500").repeat(colWidth + padding * 2)).join(box.bottomMid || "\u2534") + box.bottomRight,
|
|
2029
|
+
borderStyle
|
|
2030
|
+
),
|
|
2031
|
+
new Segment("\n", Style.null(), true)
|
|
2032
|
+
);
|
|
2033
|
+
if (this.options.caption) {
|
|
2034
|
+
const captionStyle = typeof this.options.captionStyle === "string" ? Style.parse(this.options.captionStyle) : this.options.captionStyle ?? Style.parse("dim italic");
|
|
2035
|
+
const captionLine = this.alignText(this.options.caption, width, "center");
|
|
2036
|
+
segments.push(new Segment(captionLine, captionStyle), new Segment("\n", Style.null(), true));
|
|
2037
|
+
}
|
|
2038
|
+
return { segments, width };
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
|
|
2042
|
+
// src/renderables/tree.ts
|
|
2043
|
+
var TREE_GUIDES = {
|
|
2044
|
+
standard: {
|
|
2045
|
+
branch: "\u251C\u2500\u2500 ",
|
|
2046
|
+
last: "\u2514\u2500\u2500 ",
|
|
2047
|
+
vertical: "\u2502 ",
|
|
2048
|
+
space: " "
|
|
2049
|
+
},
|
|
2050
|
+
bold: {
|
|
2051
|
+
branch: "\u2523\u2501\u2501 ",
|
|
2052
|
+
last: "\u2517\u2501\u2501 ",
|
|
2053
|
+
vertical: "\u2503 ",
|
|
2054
|
+
space: " "
|
|
2055
|
+
},
|
|
2056
|
+
double: {
|
|
2057
|
+
branch: "\u2560\u2550\u2550 ",
|
|
2058
|
+
last: "\u255A\u2550\u2550 ",
|
|
2059
|
+
vertical: "\u2551 ",
|
|
2060
|
+
space: " "
|
|
2061
|
+
},
|
|
2062
|
+
ascii: {
|
|
2063
|
+
branch: "|-- ",
|
|
2064
|
+
last: "`-- ",
|
|
2065
|
+
vertical: "| ",
|
|
2066
|
+
space: " "
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
var Tree = class _Tree {
|
|
2070
|
+
constructor(label, options = {}) {
|
|
2071
|
+
this.label = label;
|
|
2072
|
+
this.options = options;
|
|
2073
|
+
this.guideStyle = Style.parse(options.guideStyle ?? "#6e7681 dim");
|
|
2074
|
+
if (options.guideStyle === "bold") {
|
|
2075
|
+
this.guides = TREE_GUIDES.bold;
|
|
2076
|
+
} else if (options.guideStyle === "double") {
|
|
2077
|
+
this.guides = TREE_GUIDES.double;
|
|
2078
|
+
} else if (options.guideStyle === "ascii") {
|
|
2079
|
+
this.guides = TREE_GUIDES.ascii;
|
|
2080
|
+
} else {
|
|
2081
|
+
this.guides = TREE_GUIDES.standard;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
children = [];
|
|
2085
|
+
guideStyle;
|
|
2086
|
+
guides;
|
|
2087
|
+
/**
|
|
2088
|
+
* Add a child node to the tree.
|
|
2089
|
+
* Returns the added Tree node for method chaining.
|
|
2090
|
+
*/
|
|
2091
|
+
add(label) {
|
|
2092
|
+
if (label instanceof _Tree) {
|
|
2093
|
+
this.children.push(label);
|
|
2094
|
+
return label;
|
|
2095
|
+
}
|
|
2096
|
+
const node = new _Tree(label, this.options);
|
|
2097
|
+
this.children.push(node);
|
|
2098
|
+
return node;
|
|
2099
|
+
}
|
|
2100
|
+
__rich_console__(console, options) {
|
|
2101
|
+
const segments = [];
|
|
2102
|
+
if (!this.options.hideRoot) {
|
|
2103
|
+
this.renderLabel(this.label, segments, console, options);
|
|
2104
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
2105
|
+
}
|
|
2106
|
+
this.renderChildren(this.children, "", segments, console, options);
|
|
2107
|
+
return { segments, width: 0 };
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Render a label (string or renderable) and add segments.
|
|
2111
|
+
*/
|
|
2112
|
+
renderLabel(label, segments, console, options) {
|
|
2113
|
+
if (typeof label === "string") {
|
|
2114
|
+
segments.push(new Segment(label));
|
|
2115
|
+
} else if (isRenderable(label)) {
|
|
2116
|
+
const result = label.__rich_console__(console, options);
|
|
2117
|
+
if ("segments" in result) {
|
|
2118
|
+
const labelSegments = result.segments.filter((s) => !s.isControl || s.text !== "\n");
|
|
2119
|
+
segments.push(...labelSegments);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Render child nodes with appropriate prefixes.
|
|
2125
|
+
*/
|
|
2126
|
+
renderChildren(children, prefix, segments, console, options) {
|
|
2127
|
+
children.forEach((child, index) => {
|
|
2128
|
+
const isLast = index === children.length - 1;
|
|
2129
|
+
const connector = isLast ? this.guides.last : this.guides.branch;
|
|
2130
|
+
const continuation = isLast ? this.guides.space : this.guides.vertical;
|
|
2131
|
+
const labelSegments = [];
|
|
2132
|
+
if (typeof child.label === "string") {
|
|
2133
|
+
labelSegments.push(new Segment(child.label));
|
|
2134
|
+
} else if (isRenderable(child.label)) {
|
|
2135
|
+
const result = child.label.__rich_console__(console, options);
|
|
2136
|
+
if ("segments" in result) {
|
|
2137
|
+
labelSegments.push(...result.segments);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
const labelLines = splitLines(labelSegments);
|
|
2141
|
+
if (labelLines.length > 0) {
|
|
2142
|
+
segments.push(new Segment(prefix, this.guideStyle));
|
|
2143
|
+
segments.push(new Segment(connector, this.guideStyle));
|
|
2144
|
+
segments.push(...labelLines[0]);
|
|
2145
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
2146
|
+
}
|
|
2147
|
+
for (let i = 1; i < labelLines.length; i++) {
|
|
2148
|
+
segments.push(new Segment(prefix, this.guideStyle));
|
|
2149
|
+
segments.push(new Segment(continuation, this.guideStyle));
|
|
2150
|
+
segments.push(...labelLines[i]);
|
|
2151
|
+
segments.push(new Segment("\n", Style.null(), true));
|
|
2152
|
+
}
|
|
2153
|
+
const newPrefix = prefix + continuation;
|
|
2154
|
+
this.renderChildren(child.children, newPrefix, segments, console, options);
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
// src/layout/grid.ts
|
|
2160
|
+
var Grid = class extends Layout {
|
|
2161
|
+
constructor() {
|
|
2162
|
+
super();
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Adds a row to the grid with optional constraints.
|
|
2166
|
+
*/
|
|
2167
|
+
addRow(content, options = {}) {
|
|
2168
|
+
const layout = content instanceof Layout ? content : new Layout(content, options);
|
|
2169
|
+
if (!(content instanceof Layout)) {
|
|
2170
|
+
layout.size = options.size;
|
|
2171
|
+
layout.ratio = options.ratio ?? 1;
|
|
2172
|
+
layout.minimumSize = options.minimumSize ?? 0;
|
|
2173
|
+
}
|
|
2174
|
+
this.splitColumn(...this["_children"] || [], layout);
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
|
|
2178
|
+
// src/renderables/padding.ts
|
|
2179
|
+
var Padding = class {
|
|
2180
|
+
constructor(renderable, padding) {
|
|
2181
|
+
this.renderable = renderable;
|
|
2182
|
+
if (typeof padding === "number") {
|
|
2183
|
+
this.top = this.right = this.bottom = this.left = padding;
|
|
2184
|
+
} else if (Array.isArray(padding)) {
|
|
2185
|
+
if (padding.length === 2) {
|
|
2186
|
+
this.top = this.bottom = padding[0];
|
|
2187
|
+
this.right = this.left = padding[1];
|
|
2188
|
+
} else {
|
|
2189
|
+
[this.top, this.right, this.bottom, this.left] = padding;
|
|
2190
|
+
}
|
|
2191
|
+
} else {
|
|
2192
|
+
this.top = this.right = this.bottom = this.left = 0;
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
top;
|
|
2196
|
+
right;
|
|
2197
|
+
bottom;
|
|
2198
|
+
left;
|
|
2199
|
+
__rich_console__(console, options) {
|
|
2200
|
+
const width = options.width ?? console.width;
|
|
2201
|
+
const innerWidth = Math.max(0, width - this.left - this.right);
|
|
2202
|
+
let contentSegments = [];
|
|
2203
|
+
if (typeof this.renderable === "string") {
|
|
2204
|
+
contentSegments = [new Segment(this.renderable)];
|
|
2205
|
+
} else if (isRenderable(this.renderable)) {
|
|
2206
|
+
const result = this.renderable.__rich_console__(console, { ...options, width: innerWidth });
|
|
2207
|
+
if ("segments" in result) contentSegments = result.segments;
|
|
2208
|
+
}
|
|
2209
|
+
const lines = splitLines(contentSegments);
|
|
2210
|
+
const segments = [];
|
|
2211
|
+
for (let i = 0; i < this.top; i++) {
|
|
2212
|
+
segments.push(new Segment(" ".repeat(width) + "\n"));
|
|
2213
|
+
}
|
|
2214
|
+
const leftPad = " ".repeat(this.left);
|
|
2215
|
+
for (const line of lines) {
|
|
2216
|
+
segments.push(new Segment(leftPad));
|
|
2217
|
+
segments.push(...line);
|
|
2218
|
+
segments.push(new Segment("\n"));
|
|
2219
|
+
}
|
|
2220
|
+
for (let i = 0; i < this.bottom; i++) {
|
|
2221
|
+
segments.push(new Segment(" ".repeat(width) + "\n"));
|
|
2222
|
+
}
|
|
2223
|
+
return { segments, width };
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
// src/renderables/align.ts
|
|
2228
|
+
var Align = class _Align {
|
|
2229
|
+
constructor(renderable, align, style) {
|
|
2230
|
+
this.renderable = renderable;
|
|
2231
|
+
this.align = align;
|
|
2232
|
+
this.style = style;
|
|
2233
|
+
}
|
|
2234
|
+
static left(renderable) {
|
|
2235
|
+
return new _Align(renderable, "left");
|
|
2236
|
+
}
|
|
2237
|
+
static center(renderable) {
|
|
2238
|
+
return new _Align(renderable, "center");
|
|
2239
|
+
}
|
|
2240
|
+
static right(renderable) {
|
|
2241
|
+
return new _Align(renderable, "right");
|
|
2242
|
+
}
|
|
2243
|
+
__rich_console__(console, options) {
|
|
2244
|
+
const width = options.width ?? console.width;
|
|
2245
|
+
let contentSegments = [];
|
|
2246
|
+
if (typeof this.renderable === "string") {
|
|
2247
|
+
contentSegments = [new Segment(this.renderable)];
|
|
2248
|
+
} else if (isRenderable(this.renderable)) {
|
|
2249
|
+
const result = this.renderable.__rich_console__(console, options);
|
|
2250
|
+
if ("segments" in result) contentSegments = result.segments;
|
|
2251
|
+
}
|
|
2252
|
+
const lines = splitLines(contentSegments);
|
|
2253
|
+
const segments = [];
|
|
2254
|
+
for (const line of lines) {
|
|
2255
|
+
const lineWidth = line.reduce((acc, s) => acc + s.cellLength(), 0);
|
|
2256
|
+
const remaining = Math.max(0, width - lineWidth);
|
|
2257
|
+
if (remaining === 0) {
|
|
2258
|
+
segments.push(...line);
|
|
2259
|
+
} else {
|
|
2260
|
+
let leftSpace = 0;
|
|
2261
|
+
if (this.align === "center") leftSpace = Math.floor(remaining / 2);
|
|
2262
|
+
else if (this.align === "right") leftSpace = remaining;
|
|
2263
|
+
if (leftSpace > 0) segments.push(new Segment(" ".repeat(leftSpace)));
|
|
2264
|
+
segments.push(...line);
|
|
2265
|
+
}
|
|
2266
|
+
segments.push(new Segment("\n"));
|
|
2267
|
+
}
|
|
2268
|
+
return { segments, width };
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
var Prompt = class {
|
|
2272
|
+
static async ask(message, options = {}) {
|
|
2273
|
+
const console = options.console ?? new Console();
|
|
2274
|
+
const rl = readline__default.default.createInterface({
|
|
2275
|
+
input: process.stdin,
|
|
2276
|
+
output: process.stdout,
|
|
2277
|
+
terminal: true
|
|
2278
|
+
});
|
|
2279
|
+
const defaultStr = options.default !== void 0 ? ` [default: ${options.default}]` : "";
|
|
2280
|
+
const choicesStr = options.choices ? ` [${options.choices.join("/")}]` : "";
|
|
2281
|
+
const query = `${message}${choicesStr}${defaultStr}: `;
|
|
2282
|
+
console.print(query);
|
|
2283
|
+
return new Promise((resolve) => {
|
|
2284
|
+
const askQuestion = () => {
|
|
2285
|
+
process.stdout.write("> ");
|
|
2286
|
+
rl.question("", (answer) => {
|
|
2287
|
+
let value = answer.trim();
|
|
2288
|
+
if (value === "" && options.default !== void 0) {
|
|
2289
|
+
value = String(options.default);
|
|
2290
|
+
}
|
|
2291
|
+
if (options.choices && !options.choices.includes(value)) {
|
|
2292
|
+
console.print(`[red]Please select one of: ${options.choices.join(", ")}[/]`);
|
|
2293
|
+
askQuestion();
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
if (options.validate) {
|
|
2297
|
+
const validation = options.validate(value);
|
|
2298
|
+
if (validation !== true) {
|
|
2299
|
+
const msg = typeof validation === "string" ? validation : "Invalid input";
|
|
2300
|
+
console.print(`[red]${msg}[/]`);
|
|
2301
|
+
askQuestion();
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
rl.close();
|
|
2306
|
+
resolve(value);
|
|
2307
|
+
});
|
|
2308
|
+
};
|
|
2309
|
+
askQuestion();
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
// src/prompt/confirm.ts
|
|
2315
|
+
var Confirm = class {
|
|
2316
|
+
static async ask(message, options = {}) {
|
|
2317
|
+
const defaultValue = options.default ?? true;
|
|
2318
|
+
const choices = defaultValue ? ["Y", "n"] : ["y", "N"];
|
|
2319
|
+
const answer = await Prompt.ask(message, {
|
|
2320
|
+
...options,
|
|
2321
|
+
choices,
|
|
2322
|
+
default: defaultValue ? "y" : "n",
|
|
2323
|
+
validate: (input) => {
|
|
2324
|
+
const norm2 = input.toLowerCase();
|
|
2325
|
+
return norm2 === "y" || norm2 === "yes" || norm2 === "n" || norm2 === "no";
|
|
2326
|
+
}
|
|
2327
|
+
});
|
|
2328
|
+
const norm = answer.toLowerCase();
|
|
2329
|
+
return norm === "y" || norm === "yes";
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
// src/logging/handler.ts
|
|
2334
|
+
var RichHandler = class {
|
|
2335
|
+
console;
|
|
2336
|
+
constructor(console) {
|
|
2337
|
+
this.console = console ?? new Console();
|
|
2338
|
+
}
|
|
2339
|
+
handle(record) {
|
|
2340
|
+
const time = record.timestamp.toLocaleTimeString();
|
|
2341
|
+
const levelStyle = this.getLevelStyle(record.level);
|
|
2342
|
+
const parts = [
|
|
2343
|
+
`[dim]${time}[/dim]`,
|
|
2344
|
+
// Pad level to align messages
|
|
2345
|
+
new Segment(` ${record.level.toUpperCase()} `.padEnd(7), levelStyle),
|
|
2346
|
+
record.message
|
|
2347
|
+
];
|
|
2348
|
+
if (record.context && Object.keys(record.context).length > 0) {
|
|
2349
|
+
parts.push(`[dim]${JSON.stringify(record.context)}[/dim]`);
|
|
2350
|
+
}
|
|
2351
|
+
this.console.print(...parts);
|
|
2352
|
+
}
|
|
2353
|
+
getLevelStyle(level) {
|
|
2354
|
+
switch (level) {
|
|
2355
|
+
case "debug":
|
|
2356
|
+
return Style.parse("dim cyan");
|
|
2357
|
+
case "info":
|
|
2358
|
+
return Style.parse("green");
|
|
2359
|
+
case "warn":
|
|
2360
|
+
return Style.parse("yellow");
|
|
2361
|
+
case "error":
|
|
2362
|
+
return Style.parse("bold red");
|
|
2363
|
+
default:
|
|
2364
|
+
return Style.null();
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
|
|
2369
|
+
// src/hooks/install.ts
|
|
2370
|
+
function install(consoleOptions = {}) {
|
|
2371
|
+
if (global.__rich_installed__) return;
|
|
2372
|
+
const richConsole = new Console(consoleOptions);
|
|
2373
|
+
const handler = new RichHandler(richConsole);
|
|
2374
|
+
const originalLog = global.console.log;
|
|
2375
|
+
const originalWarn = global.console.warn;
|
|
2376
|
+
const originalError = global.console.error;
|
|
2377
|
+
global.console.log = (...args) => {
|
|
2378
|
+
richConsole.print(...args);
|
|
2379
|
+
};
|
|
2380
|
+
global.console.warn = (...args) => {
|
|
2381
|
+
handler.handle({
|
|
2382
|
+
level: "warn",
|
|
2383
|
+
message: args.map(String).join(" "),
|
|
2384
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
2385
|
+
});
|
|
2386
|
+
};
|
|
2387
|
+
global.console.error = (...args) => {
|
|
2388
|
+
handler.handle({
|
|
2389
|
+
level: "error",
|
|
2390
|
+
message: args.map(String).join(" "),
|
|
2391
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
2392
|
+
});
|
|
2393
|
+
};
|
|
2394
|
+
global.__rich_installed__ = true;
|
|
2395
|
+
global.__rich_original_console__ = {
|
|
2396
|
+
log: originalLog,
|
|
2397
|
+
warn: originalWarn,
|
|
2398
|
+
error: originalError
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
marked.marked.setOptions({
|
|
2402
|
+
renderer: new TerminalRenderer__default.default()
|
|
2403
|
+
});
|
|
2404
|
+
var Markdown = class {
|
|
2405
|
+
constructor(markup) {
|
|
2406
|
+
this.markup = markup;
|
|
2407
|
+
}
|
|
2408
|
+
__rich_console__(_console, _options) {
|
|
2409
|
+
const rendered = marked.marked.parse(this.markup);
|
|
2410
|
+
return {
|
|
2411
|
+
segments: [new Segment(rendered)],
|
|
2412
|
+
width: 0
|
|
2413
|
+
// Placeholder
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
|
|
2418
|
+
// src/progress/bar.ts
|
|
2419
|
+
var ProgressBar = class {
|
|
2420
|
+
constructor(total = 100, completed = 0, options = {}) {
|
|
2421
|
+
this.total = total;
|
|
2422
|
+
this.completed = completed;
|
|
2423
|
+
this.options = options;
|
|
2424
|
+
}
|
|
2425
|
+
pulseOffset = 0;
|
|
2426
|
+
lastPulseTime = 0;
|
|
2427
|
+
__rich_console__(console, consoleOptions) {
|
|
2428
|
+
const width = this.options.width ?? Math.min(40, (consoleOptions.width ?? console.width) - 20);
|
|
2429
|
+
const percentage = Math.min(1, Math.max(0, this.completed / this.total));
|
|
2430
|
+
const isComplete = percentage >= 1;
|
|
2431
|
+
const isPulse = this.options.pulse ?? false;
|
|
2432
|
+
const completeChar = this.options.completeChar ?? "\u2501";
|
|
2433
|
+
const remainingChar = this.options.remainingChar ?? "\u2501";
|
|
2434
|
+
const completeStyleStr = isComplete ? this.options.finishedStyle ?? "#50fa7b bold" : this.options.completeStyle ?? "#61afef";
|
|
2435
|
+
const remainingStyleStr = this.options.remainingStyle ?? "#3a3a3a dim";
|
|
2436
|
+
const pulseStyleStr = this.options.pulseStyle ?? "#98c379 bold";
|
|
2437
|
+
const completeStyle = Style.parse(completeStyleStr);
|
|
2438
|
+
const remainingStyle = Style.parse(remainingStyleStr);
|
|
2439
|
+
const pulseStyle = Style.parse(pulseStyleStr);
|
|
2440
|
+
const filledWidth = Math.floor(width * percentage);
|
|
2441
|
+
const segments = [];
|
|
2442
|
+
if (isPulse && !isComplete) {
|
|
2443
|
+
const now = Date.now();
|
|
2444
|
+
if (now - this.lastPulseTime > 100) {
|
|
2445
|
+
this.pulseOffset = (this.pulseOffset + 1) % width;
|
|
2446
|
+
this.lastPulseTime = now;
|
|
2447
|
+
}
|
|
2448
|
+
for (let i = 0; i < width; i++) {
|
|
2449
|
+
const isPulsePos = Math.abs(i - this.pulseOffset) < 3;
|
|
2450
|
+
const style = isPulsePos ? pulseStyle : remainingStyle;
|
|
2451
|
+
segments.push(new Segment(remainingChar, style));
|
|
2452
|
+
}
|
|
2453
|
+
} else {
|
|
2454
|
+
if (filledWidth > 0) {
|
|
2455
|
+
if (width >= 20 && !isComplete) {
|
|
2456
|
+
const gradientColors = ["#61afef", "#66d9ef", "#50fa7b"];
|
|
2457
|
+
for (let i = 0; i < filledWidth; i++) {
|
|
2458
|
+
const colorIndex = Math.floor(i / filledWidth * gradientColors.length);
|
|
2459
|
+
const color = gradientColors[Math.min(colorIndex, gradientColors.length - 1)];
|
|
2460
|
+
segments.push(new Segment(completeChar, Style.parse(color)));
|
|
2461
|
+
}
|
|
2462
|
+
} else {
|
|
2463
|
+
segments.push(new Segment(completeChar.repeat(filledWidth), completeStyle));
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
const remainingWidth = width - filledWidth;
|
|
2467
|
+
if (remainingWidth > 0) {
|
|
2468
|
+
segments.push(new Segment(remainingChar.repeat(remainingWidth), remainingStyle));
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
return {
|
|
2472
|
+
segments,
|
|
2473
|
+
width
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
var PercentageColumn = class {
|
|
2478
|
+
constructor(percentage, style) {
|
|
2479
|
+
this.percentage = percentage;
|
|
2480
|
+
this.style = style;
|
|
2481
|
+
}
|
|
2482
|
+
__rich_console__(_console, _options) {
|
|
2483
|
+
const pct = Math.floor(this.percentage * 100);
|
|
2484
|
+
const text = `${pct.toString().padStart(3)}%`;
|
|
2485
|
+
const style = Style.parse(this.style ?? (pct >= 100 ? "#50fa7b bold" : "#61afef"));
|
|
2486
|
+
return {
|
|
2487
|
+
segments: [new Segment(text, style)],
|
|
2488
|
+
width: 4
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
var TimeElapsedColumn = class {
|
|
2493
|
+
constructor(elapsedMs, style) {
|
|
2494
|
+
this.elapsedMs = elapsedMs;
|
|
2495
|
+
this.style = style;
|
|
2496
|
+
}
|
|
2497
|
+
__rich_console__(_console, _options) {
|
|
2498
|
+
const seconds = Math.floor(this.elapsedMs / 1e3);
|
|
2499
|
+
const minutes = Math.floor(seconds / 60);
|
|
2500
|
+
const hours = Math.floor(minutes / 60);
|
|
2501
|
+
let text;
|
|
2502
|
+
if (hours > 0) {
|
|
2503
|
+
text = `${hours}:${(minutes % 60).toString().padStart(2, "0")}:${(seconds % 60).toString().padStart(2, "0")}`;
|
|
2504
|
+
} else if (minutes > 0) {
|
|
2505
|
+
text = `${minutes}:${(seconds % 60).toString().padStart(2, "0")}`;
|
|
2506
|
+
} else {
|
|
2507
|
+
text = `0:${seconds.toString().padStart(2, "0")}`;
|
|
2508
|
+
}
|
|
2509
|
+
const style = Style.parse(this.style ?? "#e5c07b");
|
|
2510
|
+
return {
|
|
2511
|
+
segments: [new Segment(text, style)],
|
|
2512
|
+
width: text.length
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
var TimeRemainingColumn = class {
|
|
2517
|
+
constructor(percentage, elapsedMs, style) {
|
|
2518
|
+
this.percentage = percentage;
|
|
2519
|
+
this.elapsedMs = elapsedMs;
|
|
2520
|
+
this.style = style;
|
|
2521
|
+
}
|
|
2522
|
+
__rich_console__(_console, _options) {
|
|
2523
|
+
if (this.percentage <= 0 || this.percentage >= 1) {
|
|
2524
|
+
const text2 = "-:--";
|
|
2525
|
+
return {
|
|
2526
|
+
segments: [new Segment(text2, Style.parse(this.style ?? "dim"))],
|
|
2527
|
+
width: 4
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
const estimatedTotal = this.elapsedMs / this.percentage;
|
|
2531
|
+
const remainingMs = estimatedTotal - this.elapsedMs;
|
|
2532
|
+
const seconds = Math.floor(remainingMs / 1e3);
|
|
2533
|
+
const minutes = Math.floor(seconds / 60);
|
|
2534
|
+
const hours = Math.floor(minutes / 60);
|
|
2535
|
+
let text;
|
|
2536
|
+
if (hours > 0) {
|
|
2537
|
+
text = `${hours}:${(minutes % 60).toString().padStart(2, "0")}:${(seconds % 60).toString().padStart(2, "0")}`;
|
|
2538
|
+
} else if (minutes > 0) {
|
|
2539
|
+
text = `${minutes}:${(seconds % 60).toString().padStart(2, "0")}`;
|
|
2540
|
+
} else {
|
|
2541
|
+
text = `0:${seconds.toString().padStart(2, "0")}`;
|
|
2542
|
+
}
|
|
2543
|
+
const style = Style.parse(this.style ?? "#c678dd");
|
|
2544
|
+
return {
|
|
2545
|
+
segments: [new Segment(text, style)],
|
|
2546
|
+
width: text.length
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
|
|
2551
|
+
// src/progress/progress.ts
|
|
2552
|
+
var Progress = class {
|
|
2553
|
+
tasks = [];
|
|
2554
|
+
live;
|
|
2555
|
+
console;
|
|
2556
|
+
taskIdCounter = 0;
|
|
2557
|
+
constructor(options = {}) {
|
|
2558
|
+
this.console = options.console ?? new Console();
|
|
2559
|
+
this.live = new Live(new Layout(), this.console);
|
|
2560
|
+
}
|
|
2561
|
+
addTask(description, options = {}) {
|
|
2562
|
+
const taskId = this.taskIdCounter++;
|
|
2563
|
+
this.tasks.push({
|
|
2564
|
+
id: taskId,
|
|
2565
|
+
description,
|
|
2566
|
+
total: options.total ?? 100,
|
|
2567
|
+
completed: options.completed ?? 0,
|
|
2568
|
+
visible: true,
|
|
2569
|
+
finished: false,
|
|
2570
|
+
startTime: Date.now(),
|
|
2571
|
+
endTime: null
|
|
2572
|
+
});
|
|
2573
|
+
this.refresh();
|
|
2574
|
+
return taskId;
|
|
2575
|
+
}
|
|
2576
|
+
update(taskId, options) {
|
|
2577
|
+
const task = this.tasks.find((t) => t.id === taskId);
|
|
2578
|
+
if (!task) return;
|
|
2579
|
+
if (options.completed !== void 0) task.completed = options.completed;
|
|
2580
|
+
if (options.description !== void 0) task.description = options.description;
|
|
2581
|
+
if (task.completed >= task.total) {
|
|
2582
|
+
task.finished = true;
|
|
2583
|
+
task.endTime = Date.now();
|
|
2584
|
+
}
|
|
2585
|
+
this.refresh();
|
|
2586
|
+
}
|
|
2587
|
+
start() {
|
|
2588
|
+
this.live.start();
|
|
2589
|
+
}
|
|
2590
|
+
stop() {
|
|
2591
|
+
this.live.stop();
|
|
2592
|
+
}
|
|
2593
|
+
refresh() {
|
|
2594
|
+
const layout = new Layout();
|
|
2595
|
+
const children = this.tasks.filter((t) => t.visible).map((task) => {
|
|
2596
|
+
const row = new Layout();
|
|
2597
|
+
row.splitRow(
|
|
2598
|
+
new Text(task.description, void 0, "right"),
|
|
2599
|
+
// Label
|
|
2600
|
+
new ProgressBar(task.total, task.completed),
|
|
2601
|
+
// Bar
|
|
2602
|
+
new Text(`${Math.floor(task.completed / task.total * 100)}%`)
|
|
2603
|
+
// Percent
|
|
2604
|
+
);
|
|
2605
|
+
return row;
|
|
2606
|
+
});
|
|
2607
|
+
layout.splitColumn(...children);
|
|
2608
|
+
this.live.update(layout);
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
// src/progress/track.ts
|
|
2613
|
+
function* track(sequence, description = "Working...") {
|
|
2614
|
+
const progress = new Progress();
|
|
2615
|
+
const arr = Array.isArray(sequence) ? sequence : Array.from(sequence);
|
|
2616
|
+
const total = arr.length;
|
|
2617
|
+
progress.start();
|
|
2618
|
+
const taskId = progress.addTask(description, { total });
|
|
2619
|
+
try {
|
|
2620
|
+
for (let i = 0; i < total; i++) {
|
|
2621
|
+
yield arr[i];
|
|
2622
|
+
progress.update(taskId, { completed: i + 1 });
|
|
2623
|
+
}
|
|
2624
|
+
} finally {
|
|
2625
|
+
progress.stop();
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// src/logging/logger.ts
|
|
2630
|
+
var Logger = class {
|
|
2631
|
+
handler;
|
|
2632
|
+
constructor(console) {
|
|
2633
|
+
this.handler = new RichHandler(console);
|
|
2634
|
+
}
|
|
2635
|
+
debug(message, context) {
|
|
2636
|
+
this.log("debug", message, context);
|
|
2637
|
+
}
|
|
2638
|
+
info(message, context) {
|
|
2639
|
+
this.log("info", message, context);
|
|
2640
|
+
}
|
|
2641
|
+
warn(message, context) {
|
|
2642
|
+
this.log("warn", message, context);
|
|
2643
|
+
}
|
|
2644
|
+
error(message, context) {
|
|
2645
|
+
this.log("error", message, context);
|
|
2646
|
+
}
|
|
2647
|
+
log(level, message, context) {
|
|
2648
|
+
const record = {
|
|
2649
|
+
level,
|
|
2650
|
+
message,
|
|
2651
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2652
|
+
context
|
|
2653
|
+
};
|
|
2654
|
+
this.handler.handle(record);
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2658
|
+
// src/utils/inspect.ts
|
|
2659
|
+
function inspect(obj, options = {}) {
|
|
2660
|
+
const console = new Console();
|
|
2661
|
+
const title = options.title ?? `Inspect: ${obj?.constructor?.name ?? typeof obj}`;
|
|
2662
|
+
const table = new Table({ box: "single", showHeader: true });
|
|
2663
|
+
table.addColumn("Property", { style: "cyan" });
|
|
2664
|
+
table.addColumn("Type", { style: "magenta" });
|
|
2665
|
+
table.addColumn("Value");
|
|
2666
|
+
const props = Object.getOwnPropertyNames(obj);
|
|
2667
|
+
props.sort();
|
|
2668
|
+
for (const prop of props) {
|
|
2669
|
+
const value = obj[prop];
|
|
2670
|
+
let type = typeof value;
|
|
2671
|
+
let valueStr = String(value);
|
|
2672
|
+
if (value === null) type = "null";
|
|
2673
|
+
else if (Array.isArray(value)) type = "Array";
|
|
2674
|
+
if (valueStr.length > 50) valueStr = valueStr.substring(0, 47) + "...";
|
|
2675
|
+
table.addRow(prop, type, valueStr);
|
|
2676
|
+
}
|
|
2677
|
+
let json = "";
|
|
2678
|
+
try {
|
|
2679
|
+
json = JSON.stringify(obj, null, 2);
|
|
2680
|
+
} catch {
|
|
2681
|
+
json = "[Circular]";
|
|
2682
|
+
}
|
|
2683
|
+
new Syntax(json, "json");
|
|
2684
|
+
console.print(new Panel(table, { title, box: "round", borderStyle: void 0 }));
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
// src/index.ts
|
|
2688
|
+
var globalConsole = new Console();
|
|
2689
|
+
var print = globalConsole.print.bind(globalConsole);
|
|
2690
|
+
|
|
2691
|
+
exports.Align = Align;
|
|
2692
|
+
exports.Color = Color;
|
|
2693
|
+
exports.Confirm = Confirm;
|
|
2694
|
+
exports.Console = Console;
|
|
2695
|
+
exports.DEFAULT_THEME = DEFAULT_THEME;
|
|
2696
|
+
exports.DRACULA = DRACULA;
|
|
2697
|
+
exports.GITHUB_LIGHT = GITHUB_LIGHT;
|
|
2698
|
+
exports.Grid = Grid;
|
|
2699
|
+
exports.Layout = Layout;
|
|
2700
|
+
exports.Logger = Logger;
|
|
2701
|
+
exports.MONOKAI = MONOKAI;
|
|
2702
|
+
exports.MONOKAI_THEME = MONOKAI_THEME;
|
|
2703
|
+
exports.Markdown = Markdown;
|
|
2704
|
+
exports.MarkupParser = MarkupParser;
|
|
2705
|
+
exports.ONE_DARK = ONE_DARK;
|
|
2706
|
+
exports.Padding = Padding;
|
|
2707
|
+
exports.Palette = Palette;
|
|
2708
|
+
exports.Panel = Panel;
|
|
2709
|
+
exports.PercentageColumn = PercentageColumn;
|
|
2710
|
+
exports.Progress = Progress;
|
|
2711
|
+
exports.ProgressBar = ProgressBar;
|
|
2712
|
+
exports.Prompt = Prompt;
|
|
2713
|
+
exports.RichHandler = RichHandler;
|
|
2714
|
+
exports.Rule = Rule;
|
|
2715
|
+
exports.SYNTAX_THEMES = SYNTAX_THEMES;
|
|
2716
|
+
exports.Segment = Segment;
|
|
2717
|
+
exports.Spinner = Spinner;
|
|
2718
|
+
exports.Status = Status;
|
|
2719
|
+
exports.Style = Style;
|
|
2720
|
+
exports.Syntax = Syntax;
|
|
2721
|
+
exports.Table = Table;
|
|
2722
|
+
exports.Text = Text;
|
|
2723
|
+
exports.Theme = Theme;
|
|
2724
|
+
exports.TimeElapsedColumn = TimeElapsedColumn;
|
|
2725
|
+
exports.TimeRemainingColumn = TimeRemainingColumn;
|
|
2726
|
+
exports.Traceback = Traceback;
|
|
2727
|
+
exports.Tree = Tree;
|
|
2728
|
+
exports.getBox = getBox;
|
|
2729
|
+
exports.getTheme = getTheme;
|
|
2730
|
+
exports.inspect = inspect;
|
|
2731
|
+
exports.install = install;
|
|
2732
|
+
exports.installTracebackHandler = installTracebackHandler;
|
|
2733
|
+
exports.isRenderable = isRenderable;
|
|
2734
|
+
exports.listBoxStyles = listBoxStyles;
|
|
2735
|
+
exports.print = print;
|
|
2736
|
+
exports.track = track;
|
|
2737
|
+
//# sourceMappingURL=index.cjs.map
|
|
2738
|
+
//# sourceMappingURL=index.cjs.map
|