sharkcode 0.3.1 → 0.3.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/dist/cli.mjs +70 -13
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -513,18 +513,73 @@ async function showSetupFlow(multiConfig) {
|
|
|
513
513
|
return { multiConfig, config: resolveConfig(multiConfig) };
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
|
-
async function
|
|
516
|
+
async function readLineRaw(promptStr) {
|
|
517
|
+
process.stdout.write(promptStr);
|
|
517
518
|
return new Promise((resolve4) => {
|
|
518
|
-
|
|
519
|
-
let
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
519
|
+
let buffer = "";
|
|
520
|
+
let finished = false;
|
|
521
|
+
const finish = (value) => {
|
|
522
|
+
if (finished) return;
|
|
523
|
+
finished = true;
|
|
524
|
+
process.stdin.removeListener("data", onData);
|
|
525
|
+
try {
|
|
526
|
+
process.stdin.setRawMode(false);
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
process.stdin.pause();
|
|
530
|
+
resolve4(value);
|
|
531
|
+
};
|
|
532
|
+
const onData = (chunk) => {
|
|
533
|
+
const str = chunk.toString("utf8");
|
|
534
|
+
if (str.startsWith("\x1B")) return;
|
|
535
|
+
for (const ch of str) {
|
|
536
|
+
const code = ch.codePointAt(0);
|
|
537
|
+
if (code === 3 || code === 4) {
|
|
538
|
+
process.stdout.write("\n");
|
|
539
|
+
finish(null);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (code === 13 || code === 10) {
|
|
543
|
+
process.stdout.write("\n");
|
|
544
|
+
finish(buffer);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (code === 127 || code === 8) {
|
|
548
|
+
if (buffer.length > 0) {
|
|
549
|
+
const chars = [...buffer];
|
|
550
|
+
chars.pop();
|
|
551
|
+
buffer = chars.join("");
|
|
552
|
+
process.stdout.write("\b \b");
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (code < 32) continue;
|
|
557
|
+
if (ch === "/" && buffer === "") {
|
|
558
|
+
process.stdout.write("\n");
|
|
559
|
+
finish("/");
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
buffer += ch;
|
|
563
|
+
process.stdout.write(ch);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
try {
|
|
567
|
+
process.stdin.setRawMode(true);
|
|
568
|
+
process.stdin.resume();
|
|
569
|
+
process.stdin.on("data", onData);
|
|
570
|
+
} catch {
|
|
571
|
+
finished = true;
|
|
572
|
+
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
573
|
+
let answered = false;
|
|
574
|
+
rl.question(promptStr, (answer) => {
|
|
575
|
+
answered = true;
|
|
576
|
+
rl.close();
|
|
577
|
+
resolve4(answer);
|
|
578
|
+
});
|
|
579
|
+
rl.on("close", () => {
|
|
580
|
+
if (!answered) resolve4(null);
|
|
581
|
+
});
|
|
582
|
+
}
|
|
528
583
|
});
|
|
529
584
|
}
|
|
530
585
|
function statusLine(config) {
|
|
@@ -542,7 +597,7 @@ async function main() {
|
|
|
542
597
|
return;
|
|
543
598
|
}
|
|
544
599
|
if (args[0] === "--version" || args[0] === "-v") {
|
|
545
|
-
console.log("sharkcode v0.3.
|
|
600
|
+
console.log("sharkcode v0.3.2");
|
|
546
601
|
return;
|
|
547
602
|
}
|
|
548
603
|
if (args.length > 0) {
|
|
@@ -570,7 +625,7 @@ async function main() {
|
|
|
570
625
|
}
|
|
571
626
|
let messages = [];
|
|
572
627
|
while (true) {
|
|
573
|
-
const raw = await
|
|
628
|
+
const raw = await readLineRaw(PURPLE2("\n\u25C6 "));
|
|
574
629
|
if (raw === null) {
|
|
575
630
|
console.log(GRAY("\nBye! \u{1F988}"));
|
|
576
631
|
break;
|
|
@@ -587,6 +642,7 @@ async function main() {
|
|
|
587
642
|
config = r.config;
|
|
588
643
|
if (r.clearHistory) messages = [];
|
|
589
644
|
if (r.exit) break;
|
|
645
|
+
console.log(statusLine(config));
|
|
590
646
|
continue;
|
|
591
647
|
}
|
|
592
648
|
if (trimmed === "/provider" || trimmed.startsWith("/provider ") || trimmed === "/model" || trimmed.startsWith("/model ") || trimmed === "/key" || trimmed.startsWith("/key ")) {
|
|
@@ -594,6 +650,7 @@ async function main() {
|
|
|
594
650
|
multiConfig = r.multiConfig;
|
|
595
651
|
config = r.config;
|
|
596
652
|
if (r.exit) break;
|
|
653
|
+
console.log(statusLine(config));
|
|
597
654
|
continue;
|
|
598
655
|
}
|
|
599
656
|
if (trimmed.startsWith("/")) {
|