blun-king-cli 7.2.4 → 7.2.5
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/lib/ui.js +47 -1
- package/package.json +1 -1
package/lib/ui.js
CHANGED
|
@@ -318,6 +318,39 @@ function stopSpinner(success, message) {
|
|
|
318
318
|
activeSpinner = null;
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
// ── Word Wrap ────────────────────────────────────────────
|
|
322
|
+
function wordWrap(text, width) {
|
|
323
|
+
if (!width) width = getWidth();
|
|
324
|
+
var lines = text.split("\n");
|
|
325
|
+
var result = [];
|
|
326
|
+
for (var i = 0; i < lines.length; i++) {
|
|
327
|
+
var line = lines[i];
|
|
328
|
+
// Strip ANSI for length calculation
|
|
329
|
+
var plain = line.replace(/\x1b\[[0-9;]*m/g, "");
|
|
330
|
+
if (plain.length <= width) {
|
|
331
|
+
result.push(line);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
// Word wrap: work on plain text, rebuild with breaks
|
|
335
|
+
var words = line.split(/( +)/);
|
|
336
|
+
var current = "";
|
|
337
|
+
var currentPlain = "";
|
|
338
|
+
for (var j = 0; j < words.length; j++) {
|
|
339
|
+
var wordPlain = words[j].replace(/\x1b\[[0-9;]*m/g, "");
|
|
340
|
+
if (currentPlain.length + wordPlain.length > width && currentPlain.length > 0) {
|
|
341
|
+
result.push(current);
|
|
342
|
+
current = words[j];
|
|
343
|
+
currentPlain = wordPlain;
|
|
344
|
+
} else {
|
|
345
|
+
current += words[j];
|
|
346
|
+
currentPlain += wordPlain;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (current) result.push(current);
|
|
350
|
+
}
|
|
351
|
+
return result.join("\n");
|
|
352
|
+
}
|
|
353
|
+
|
|
321
354
|
// ── Markdown Rendering ────────────────────────────────────
|
|
322
355
|
function renderMarkdown(text) {
|
|
323
356
|
var out = text;
|
|
@@ -342,7 +375,20 @@ function renderMarkdown(text) {
|
|
|
342
375
|
out = out.replace(/`([^`]+)`/g, function (_, c) { return chalk.bgGray.white(" " + c + " "); });
|
|
343
376
|
out = out.replace(/^(\s*)[-*] (.+)$/gm, function (_, sp, t) { return sp + chalk.green("\u25cf") + " " + t; });
|
|
344
377
|
out = out.replace(/^(\s*)\d+\. (.+)$/gm, function (_, sp, t) { return sp + chalk.yellow("\u25b8") + " " + t; });
|
|
345
|
-
|
|
378
|
+
// Word wrap the final output (skip code block lines)
|
|
379
|
+
var wrapWidth = (process.stdout.columns || 80) - 4;
|
|
380
|
+
var outLines = out.split("\n");
|
|
381
|
+
var wrapped = [];
|
|
382
|
+
for (var wi = 0; wi < outLines.length; wi++) {
|
|
383
|
+
var ol = outLines[wi];
|
|
384
|
+
// Don't wrap code block lines (they have │ prefix)
|
|
385
|
+
if (ol.indexOf("\u2502") >= 0 || ol.indexOf("\u250c") >= 0 || ol.indexOf("\u2514") >= 0) {
|
|
386
|
+
wrapped.push(ol);
|
|
387
|
+
} else {
|
|
388
|
+
wrapped.push(wordWrap(ol, wrapWidth));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return wrapped.join("\n");
|
|
346
392
|
}
|
|
347
393
|
|
|
348
394
|
// ── Token Tracking ────────────────────────────────────────
|