blun-king-cli 2.6.3 → 2.8.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/bin/blun.js +62 -14
- package/package.json +1 -1
package/bin/blun.js
CHANGED
|
@@ -158,6 +158,33 @@ function checkForUpdates() {
|
|
|
158
158
|
} catch(e) { /* silent */ }
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
// Inline markdown: **bold**, `code`, *italic*
|
|
162
|
+
function renderInline(text) {
|
|
163
|
+
return text
|
|
164
|
+
.replace(/\*\*(.+?)\*\*/g, C.bold + C.brightWhite + "$1" + C.reset)
|
|
165
|
+
.replace(/`(.+?)`/g, C.cyan + "$1" + C.reset)
|
|
166
|
+
.replace(/\*(.+?)\*/g, C.italic + "$1" + C.reset);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Word-wrap text to terminal width
|
|
170
|
+
function wordWrap(text, indent) {
|
|
171
|
+
var maxW = (process.stdout.columns || 80) - indent - 2;
|
|
172
|
+
if (text.length <= maxW) return [text];
|
|
173
|
+
var words = text.split(" ");
|
|
174
|
+
var lines = [];
|
|
175
|
+
var current = "";
|
|
176
|
+
for (var i = 0; i < words.length; i++) {
|
|
177
|
+
if (current.length + words[i].length + 1 > maxW && current.length > 0) {
|
|
178
|
+
lines.push(current);
|
|
179
|
+
current = words[i];
|
|
180
|
+
} else {
|
|
181
|
+
current = current ? current + " " + words[i] : words[i];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (current) lines.push(current);
|
|
185
|
+
return lines;
|
|
186
|
+
}
|
|
187
|
+
|
|
161
188
|
function printAnswer(answer, meta) {
|
|
162
189
|
console.log("");
|
|
163
190
|
console.log(C.green + C.bold + " " + BOX.bot + " BLUN King" + C.reset + (meta ? C.gray + " " + BOX.dot + " " + meta + C.reset : ""));
|
|
@@ -178,19 +205,29 @@ function printAnswer(answer, meta) {
|
|
|
178
205
|
} else if (inCode) {
|
|
179
206
|
console.log(C.cyan + " " + BOX.v + " " + line + C.reset);
|
|
180
207
|
} else if (line.startsWith("# ")) {
|
|
181
|
-
console.log(
|
|
208
|
+
console.log("");
|
|
209
|
+
console.log(C.bold + C.yellow + " \u2588 " + line.slice(2) + C.reset);
|
|
210
|
+
console.log("");
|
|
182
211
|
} else if (line.startsWith("## ")) {
|
|
183
|
-
console.log(
|
|
212
|
+
console.log("");
|
|
213
|
+
console.log(C.bold + C.magenta + " \u25B6 " + line.slice(3) + C.reset);
|
|
184
214
|
} else if (line.startsWith("### ")) {
|
|
185
|
-
console.log(C.bold + " " + line + C.reset);
|
|
186
|
-
} else if (line.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.log(C.
|
|
190
|
-
|
|
191
|
-
|
|
215
|
+
console.log(C.bold + C.brightWhite + " \u25AA " + line.slice(4) + C.reset);
|
|
216
|
+
} else if (line.match(/^\s*[-*] /)) {
|
|
217
|
+
var bulletText = line.replace(/^\s*[-*] /, "");
|
|
218
|
+
var wrapped = wordWrap(bulletText, 8);
|
|
219
|
+
console.log(" " + C.green + "\u2022 " + C.reset + renderInline(wrapped[0]));
|
|
220
|
+
for (var w = 1; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
221
|
+
} else if (line.match(/^\s*\d+\.\s/)) {
|
|
222
|
+
var numMatch = line.match(/^(\s*\d+\.)\s(.*)/);
|
|
223
|
+
var wrapped = wordWrap(numMatch[2], 8);
|
|
224
|
+
console.log(" " + C.yellow + numMatch[1] + C.reset + " " + renderInline(wrapped[0]));
|
|
225
|
+
for (var w = 1; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
226
|
+
} else if (line.trim() === "") {
|
|
227
|
+
console.log("");
|
|
192
228
|
} else {
|
|
193
|
-
|
|
229
|
+
var wrapped = wordWrap(line, 2);
|
|
230
|
+
for (var w = 0; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
194
231
|
}
|
|
195
232
|
}
|
|
196
233
|
console.log("");
|
|
@@ -2600,7 +2637,13 @@ async function main() {
|
|
|
2600
2637
|
return null;
|
|
2601
2638
|
}
|
|
2602
2639
|
|
|
2640
|
+
var inputQueue = [];
|
|
2641
|
+
|
|
2603
2642
|
async function processInput(input) {
|
|
2643
|
+
if (processing) {
|
|
2644
|
+
inputQueue.push(input);
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2604
2647
|
processing = true;
|
|
2605
2648
|
eraseUI();
|
|
2606
2649
|
|
|
@@ -2637,9 +2680,16 @@ async function main() {
|
|
|
2637
2680
|
inputBuffer = "";
|
|
2638
2681
|
cursorPos = 0;
|
|
2639
2682
|
menuSelected = 0;
|
|
2640
|
-
uiStartRow = -1;
|
|
2683
|
+
uiStartRow = -1;
|
|
2641
2684
|
processing = false;
|
|
2642
2685
|
drawPrompt();
|
|
2686
|
+
|
|
2687
|
+
// Process queued inputs
|
|
2688
|
+
if (inputQueue.length > 0) {
|
|
2689
|
+
var next = inputQueue.shift();
|
|
2690
|
+
inputHistory.unshift(next);
|
|
2691
|
+
processInput(next);
|
|
2692
|
+
}
|
|
2643
2693
|
}
|
|
2644
2694
|
|
|
2645
2695
|
// ── Raw Input Handler ──
|
|
@@ -2650,9 +2700,7 @@ async function main() {
|
|
|
2650
2700
|
drawPrompt();
|
|
2651
2701
|
|
|
2652
2702
|
process.stdin.on("data", function(key) {
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
// Ctrl+C / Ctrl+D — exit
|
|
2703
|
+
// Ctrl+C / Ctrl+D — always allow exit
|
|
2656
2704
|
if (key === "\x03" || key === "\x04") {
|
|
2657
2705
|
session.history = chatHistory.slice(-50);
|
|
2658
2706
|
saveSessionHistory(session);
|