@alcyone-labs/arg-parser 2.10.1 → 2.10.2
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 +78 -10
- package/dist/index.cjs +60 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.min.mjs +1249 -1221
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +60 -2
- package/dist/index.mjs.map +1 -1
- package/dist/ui/components/ScrollArea.d.ts +3 -0
- package/dist/ui/components/ScrollArea.d.ts.map +1 -1
- package/dist/ui/utils/ansi-utils.d.ts +17 -0
- package/dist/ui/utils/ansi-utils.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9301,12 +9301,61 @@ class List extends Component {
|
|
|
9301
9301
|
}
|
|
9302
9302
|
}
|
|
9303
9303
|
}
|
|
9304
|
+
function stripAnsi(str) {
|
|
9305
|
+
return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
|
9306
|
+
}
|
|
9307
|
+
function visualLength(str) {
|
|
9308
|
+
return stripAnsi(str).length;
|
|
9309
|
+
}
|
|
9310
|
+
function wrapText(text, width) {
|
|
9311
|
+
if (width <= 0) return [text];
|
|
9312
|
+
const result = [];
|
|
9313
|
+
const lines = text.split("\n");
|
|
9314
|
+
for (const line of lines) {
|
|
9315
|
+
if (visualLength(line) <= width) {
|
|
9316
|
+
result.push(line);
|
|
9317
|
+
continue;
|
|
9318
|
+
}
|
|
9319
|
+
let currentLine = "";
|
|
9320
|
+
let currentVisibleLength = 0;
|
|
9321
|
+
let activeAnsiCodes = [];
|
|
9322
|
+
const tokenRegex = /(\u001b\[(?:\d{1,3}(?:;\d{1,3})*)?[mK])|([\s\S])/g;
|
|
9323
|
+
let match;
|
|
9324
|
+
while ((match = tokenRegex.exec(line)) !== null) {
|
|
9325
|
+
const ansiCode = match[1];
|
|
9326
|
+
const char2 = match[2];
|
|
9327
|
+
if (ansiCode) {
|
|
9328
|
+
currentLine += ansiCode;
|
|
9329
|
+
if (ansiCode === "\x1B[0m") {
|
|
9330
|
+
activeAnsiCodes = [];
|
|
9331
|
+
} else if (ansiCode.endsWith("m")) {
|
|
9332
|
+
activeAnsiCodes.push(ansiCode);
|
|
9333
|
+
}
|
|
9334
|
+
} else if (char2) {
|
|
9335
|
+
if (currentVisibleLength >= width) {
|
|
9336
|
+
result.push(currentLine + "\x1B[0m");
|
|
9337
|
+
currentLine = activeAnsiCodes.join("") + char2;
|
|
9338
|
+
currentVisibleLength = 1;
|
|
9339
|
+
} else {
|
|
9340
|
+
currentLine += char2;
|
|
9341
|
+
currentVisibleLength++;
|
|
9342
|
+
}
|
|
9343
|
+
}
|
|
9344
|
+
}
|
|
9345
|
+
if (currentLine.length > 0) {
|
|
9346
|
+
result.push(currentLine + "\x1B[0m");
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
return result;
|
|
9350
|
+
}
|
|
9304
9351
|
class ScrollArea extends Component {
|
|
9305
9352
|
constructor(config) {
|
|
9306
9353
|
super(config);
|
|
9307
9354
|
this.contentLines = [];
|
|
9308
9355
|
this.scrollOffset = 0;
|
|
9356
|
+
this.wrapText = false;
|
|
9309
9357
|
this.content = config.content;
|
|
9358
|
+
this.wrapText = !!config.wrapText;
|
|
9310
9359
|
this.updateContentLines();
|
|
9311
9360
|
}
|
|
9312
9361
|
setContent(content) {
|
|
@@ -9314,8 +9363,18 @@ class ScrollArea extends Component {
|
|
|
9314
9363
|
this.scrollOffset = 0;
|
|
9315
9364
|
this.updateContentLines();
|
|
9316
9365
|
}
|
|
9366
|
+
resize(x, y, width, height) {
|
|
9367
|
+
super.resize(x, y, width, height);
|
|
9368
|
+
if (this.wrapText) {
|
|
9369
|
+
this.updateContentLines();
|
|
9370
|
+
}
|
|
9371
|
+
}
|
|
9317
9372
|
updateContentLines() {
|
|
9318
|
-
this.
|
|
9373
|
+
if (this.wrapText && this.width > 0) {
|
|
9374
|
+
this.contentLines = wrapText(this.content, Math.max(1, this.width - 2));
|
|
9375
|
+
} else {
|
|
9376
|
+
this.contentLines = this.content.split("\n");
|
|
9377
|
+
}
|
|
9319
9378
|
}
|
|
9320
9379
|
render() {
|
|
9321
9380
|
const lines = [];
|
|
@@ -9330,7 +9389,6 @@ class ScrollArea extends Component {
|
|
|
9330
9389
|
const maxTop = this.height - scrollbarHeight;
|
|
9331
9390
|
scrollbarTop = Math.floor(scrollPercent * maxTop);
|
|
9332
9391
|
}
|
|
9333
|
-
const stripAnsi = (str) => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
|
9334
9392
|
for (let i = 0; i < this.height; i++) {
|
|
9335
9393
|
const lineContent = visibleLines[i] || "";
|
|
9336
9394
|
let prefix = "";
|