jevgrep 0.2.0 → 0.3.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 +33 -10
- package/dist/jgrep.js +661 -890
- package/package.json +1 -1
- package/skill/SKILL.md +9 -0
package/dist/jgrep.js
CHANGED
|
@@ -4,28 +4,45 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
16
32
|
return to;
|
|
17
33
|
};
|
|
18
34
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
var __esm = (fn, res, err) => () => {
|
|
36
|
+
if (fn)
|
|
37
|
+
try {
|
|
38
|
+
res = fn(fn = 0);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
err = [e];
|
|
41
|
+
}
|
|
42
|
+
if (err)
|
|
43
|
+
throw err[0];
|
|
44
|
+
return res;
|
|
27
45
|
};
|
|
28
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
46
|
|
|
30
47
|
// src/jgrep.ts
|
|
31
48
|
import fs from "node:fs";
|
|
@@ -156,28 +173,30 @@ function buildRequest(question, chunks, kind = "code") {
|
|
|
156
173
|
});
|
|
157
174
|
return { model: MODEL, state, questions };
|
|
158
175
|
}
|
|
159
|
-
async function
|
|
160
|
-
const
|
|
176
|
+
async function postSystemOne(body, apiKey, f = fetch) {
|
|
177
|
+
const json = JSON.stringify(body);
|
|
161
178
|
for (let attempt = 0;; attempt++) {
|
|
162
179
|
const res = await f(ENDPOINT, {
|
|
163
180
|
method: "POST",
|
|
164
181
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
165
|
-
body,
|
|
182
|
+
body: json,
|
|
166
183
|
signal: AbortSignal.timeout(30000)
|
|
167
184
|
});
|
|
168
|
-
if (res.ok)
|
|
169
|
-
|
|
170
|
-
return { ps: chunks.map((_, i) => json.answers[`c${i}`]?.noul ?? NaN), tokens: json.usage?.input_tokens ?? 0 };
|
|
171
|
-
}
|
|
185
|
+
if (res.ok)
|
|
186
|
+
return await res.json();
|
|
172
187
|
if ((res.status === 429 || res.status >= 500) && attempt < 3) {
|
|
173
188
|
await new Promise((r) => setTimeout(r, 500 * 2 ** attempt));
|
|
174
189
|
continue;
|
|
175
190
|
}
|
|
176
191
|
if (res.status === 401)
|
|
177
192
|
throw new Error("TypeSafe API rejected the key (401). Check TYPESAFE_API_KEY.");
|
|
178
|
-
throw new Error(`TypeSafe API ${res.status}: ${(await res.text()).slice(0,
|
|
193
|
+
throw new Error(`TypeSafe API ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
179
194
|
}
|
|
180
195
|
}
|
|
196
|
+
async function ask(question, chunks, kind, apiKey, f) {
|
|
197
|
+
const json = await postSystemOne(buildRequest(question, chunks, kind), apiKey, f);
|
|
198
|
+
return { ps: chunks.map((_, i) => json.answers[`c${i}`]?.noul ?? NaN), tokens: json.usage?.input_tokens ?? 0 };
|
|
199
|
+
}
|
|
181
200
|
function loadCache() {
|
|
182
201
|
try {
|
|
183
202
|
return JSON.parse(fs.readFileSync(CACHE_FILE, "utf8"));
|
|
@@ -614,51 +633,51 @@ var init_main = __esm(() => {
|
|
|
614
633
|
});
|
|
615
634
|
|
|
616
635
|
// node_modules/sisteransi/src/index.js
|
|
617
|
-
var require_src = __commonJS((exports, module)
|
|
618
|
-
var
|
|
619
|
-
var
|
|
636
|
+
var require_src = __commonJS(function(exports, module) {
|
|
637
|
+
var ESC = "\x1B";
|
|
638
|
+
var CSI = `${ESC}[`;
|
|
620
639
|
var beep = "\x07";
|
|
621
640
|
var cursor = {
|
|
622
641
|
to(x, y) {
|
|
623
642
|
if (!y)
|
|
624
|
-
return `${
|
|
625
|
-
return `${
|
|
643
|
+
return `${CSI}${x + 1}G`;
|
|
644
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
626
645
|
},
|
|
627
646
|
move(x, y) {
|
|
628
647
|
let ret = "";
|
|
629
648
|
if (x < 0)
|
|
630
|
-
ret += `${
|
|
649
|
+
ret += `${CSI}${-x}D`;
|
|
631
650
|
else if (x > 0)
|
|
632
|
-
ret += `${
|
|
651
|
+
ret += `${CSI}${x}C`;
|
|
633
652
|
if (y < 0)
|
|
634
|
-
ret += `${
|
|
653
|
+
ret += `${CSI}${-y}A`;
|
|
635
654
|
else if (y > 0)
|
|
636
|
-
ret += `${
|
|
655
|
+
ret += `${CSI}${y}B`;
|
|
637
656
|
return ret;
|
|
638
657
|
},
|
|
639
|
-
up: (count = 1) => `${
|
|
640
|
-
down: (count = 1) => `${
|
|
641
|
-
forward: (count = 1) => `${
|
|
642
|
-
backward: (count = 1) => `${
|
|
643
|
-
nextLine: (count = 1) => `${
|
|
644
|
-
prevLine: (count = 1) => `${
|
|
645
|
-
left: `${
|
|
646
|
-
hide: `${
|
|
647
|
-
show: `${
|
|
648
|
-
save: `${
|
|
649
|
-
restore: `${
|
|
658
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
659
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
660
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
661
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
662
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
663
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
664
|
+
left: `${CSI}G`,
|
|
665
|
+
hide: `${CSI}?25l`,
|
|
666
|
+
show: `${CSI}?25h`,
|
|
667
|
+
save: `${ESC}7`,
|
|
668
|
+
restore: `${ESC}8`
|
|
650
669
|
};
|
|
651
670
|
var scroll = {
|
|
652
|
-
up: (count = 1) => `${
|
|
653
|
-
down: (count = 1) => `${
|
|
671
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
672
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
654
673
|
};
|
|
655
674
|
var erase = {
|
|
656
|
-
screen: `${
|
|
657
|
-
up: (count = 1) => `${
|
|
658
|
-
down: (count = 1) => `${
|
|
659
|
-
line: `${
|
|
660
|
-
lineEnd: `${
|
|
661
|
-
lineStart: `${
|
|
675
|
+
screen: `${CSI}2J`,
|
|
676
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
677
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
678
|
+
line: `${CSI}2K`,
|
|
679
|
+
lineEnd: `${CSI}K`,
|
|
680
|
+
lineStart: `${CSI}1K`,
|
|
662
681
|
lines(count) {
|
|
663
682
|
let clear = "";
|
|
664
683
|
for (let i = 0;i < count; i++)
|
|
@@ -677,30 +696,11 @@ import { stdout, stdin } from "node:process";
|
|
|
677
696
|
import * as l from "node:readline";
|
|
678
697
|
import l__default from "node:readline";
|
|
679
698
|
import { ReadStream } from "node:tty";
|
|
680
|
-
function findCursor(s, o,
|
|
681
|
-
if (!
|
|
699
|
+
function findCursor(s, o, l) {
|
|
700
|
+
if (!l.some((r) => !r.disabled))
|
|
682
701
|
return s;
|
|
683
|
-
const t = s + o, n = Math.max(
|
|
684
|
-
return
|
|
685
|
-
}
|
|
686
|
-
function findTextCursor(s, o, l2, i) {
|
|
687
|
-
const t = i.split(`
|
|
688
|
-
`);
|
|
689
|
-
let n = 0, e = s;
|
|
690
|
-
for (const r of t) {
|
|
691
|
-
if (e <= r.length)
|
|
692
|
-
break;
|
|
693
|
-
e -= r.length + 1, n++;
|
|
694
|
-
}
|
|
695
|
-
for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
|
|
696
|
-
n--, e += t[n].length + 1;
|
|
697
|
-
for (;e > t[n].length && n < t.length - 1; )
|
|
698
|
-
e -= t[n].length + 1, n++;
|
|
699
|
-
e = Math.max(0, Math.min(t[n].length, e));
|
|
700
|
-
let h = 0;
|
|
701
|
-
for (let r = 0;r < n; r++)
|
|
702
|
-
h += t[r].length + 1;
|
|
703
|
-
return h + e;
|
|
702
|
+
const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
703
|
+
return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
|
|
704
704
|
}
|
|
705
705
|
function isAccessible(n) {
|
|
706
706
|
if (n !== undefined)
|
|
@@ -722,14 +722,14 @@ function diffLines(i, s) {
|
|
|
722
722
|
if (i === s)
|
|
723
723
|
return;
|
|
724
724
|
const e = i.split(`
|
|
725
|
-
`),
|
|
726
|
-
`), r = Math.max(e.length,
|
|
725
|
+
`), t = s.split(`
|
|
726
|
+
`), r = Math.max(e.length, t.length), f = [];
|
|
727
727
|
for (let n = 0;n < r; n++)
|
|
728
|
-
e[n] !==
|
|
728
|
+
e[n] !== t[n] && f.push(n);
|
|
729
729
|
return {
|
|
730
730
|
lines: f,
|
|
731
731
|
numLinesBefore: e.length,
|
|
732
|
-
numLinesAfter:
|
|
732
|
+
numLinesAfter: t.length,
|
|
733
733
|
numLines: r
|
|
734
734
|
};
|
|
735
735
|
}
|
|
@@ -753,7 +753,7 @@ function block({
|
|
|
753
753
|
tabSize: 1
|
|
754
754
|
});
|
|
755
755
|
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
756
|
-
const
|
|
756
|
+
const t = (f, { name: a, sequence: w }) => {
|
|
757
757
|
const c = String(f);
|
|
758
758
|
if (isActionKey([c, a, w], "cancel")) {
|
|
759
759
|
n && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
@@ -764,22 +764,22 @@ function block({
|
|
|
764
764
|
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
765
765
|
l.moveCursor(r, i, m, () => {
|
|
766
766
|
l.clearLine(r, 1, () => {
|
|
767
|
-
e.once("keypress",
|
|
767
|
+
e.once("keypress", t);
|
|
768
768
|
});
|
|
769
769
|
});
|
|
770
770
|
};
|
|
771
|
-
return n && r.write(import_sisteransi.cursor.hide), e.once("keypress",
|
|
772
|
-
e.off("keypress",
|
|
771
|
+
return n && r.write(import_sisteransi.cursor.hide), e.once("keypress", t), () => {
|
|
772
|
+
e.off("keypress", t), n && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
773
773
|
};
|
|
774
774
|
}
|
|
775
|
-
function wrapTextWithPrefix(e, r, o, n = o, s = o,
|
|
775
|
+
function wrapTextWithPrefix(e, r, o, n = o, s = o, t) {
|
|
776
776
|
const f = getColumns(e ?? stdout);
|
|
777
777
|
return wrapAnsi(r, f - o.length, {
|
|
778
778
|
hard: true,
|
|
779
779
|
trim: false
|
|
780
780
|
}).split(`
|
|
781
781
|
`).map((c, i, m) => {
|
|
782
|
-
const d =
|
|
782
|
+
const d = t ? t(c, i) : c;
|
|
783
783
|
return i === 0 ? `${n}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
784
784
|
}).join(`
|
|
785
785
|
`);
|
|
@@ -810,35 +810,35 @@ class y {
|
|
|
810
810
|
get accessible() {
|
|
811
811
|
return isAccessible(this.opts.accessible);
|
|
812
812
|
}
|
|
813
|
-
constructor(
|
|
814
|
-
const { input: i = stdin, output: s = stdout, render: r, signal: n, ...o } =
|
|
813
|
+
constructor(t, e = true) {
|
|
814
|
+
const { input: i = stdin, output: s = stdout, render: r, signal: n, ...o } = t;
|
|
815
815
|
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = r.bind(this), this._track = e, this._abortSignal = n, this.input = i, this.output = s;
|
|
816
816
|
}
|
|
817
817
|
unsubscribe() {
|
|
818
818
|
this._subscribers.clear();
|
|
819
819
|
}
|
|
820
|
-
setSubscriber(
|
|
821
|
-
const i = this._subscribers.get(
|
|
822
|
-
i.push(e), this._subscribers.set(
|
|
820
|
+
setSubscriber(t, e) {
|
|
821
|
+
const i = this._subscribers.get(t) ?? [];
|
|
822
|
+
i.push(e), this._subscribers.set(t, i);
|
|
823
823
|
}
|
|
824
|
-
on(
|
|
825
|
-
this.setSubscriber(
|
|
824
|
+
on(t, e) {
|
|
825
|
+
this.setSubscriber(t, { cb: e });
|
|
826
826
|
}
|
|
827
|
-
once(
|
|
828
|
-
this.setSubscriber(
|
|
827
|
+
once(t, e) {
|
|
828
|
+
this.setSubscriber(t, { cb: e, once: true });
|
|
829
829
|
}
|
|
830
|
-
emit(
|
|
831
|
-
const i = this._subscribers.get(
|
|
830
|
+
emit(t, ...e) {
|
|
831
|
+
const i = this._subscribers.get(t) ?? [], s = [];
|
|
832
832
|
for (const r of i)
|
|
833
833
|
r.cb(...e), r.once && s.push(() => i.splice(i.indexOf(r), 1));
|
|
834
834
|
for (const r of s)
|
|
835
835
|
r();
|
|
836
836
|
}
|
|
837
837
|
prompt() {
|
|
838
|
-
return new Promise((
|
|
838
|
+
return new Promise((t) => {
|
|
839
839
|
if (this._abortSignal) {
|
|
840
840
|
if (this._abortSignal.aborted)
|
|
841
|
-
return this.state = "cancel", this.close(),
|
|
841
|
+
return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
|
|
842
842
|
this._abortSignal.addEventListener("abort", () => {
|
|
843
843
|
this.state = "cancel", this.close();
|
|
844
844
|
}, { once: true });
|
|
@@ -850,30 +850,30 @@ class y {
|
|
|
850
850
|
escapeCodeTimeout: 50,
|
|
851
851
|
terminal: true
|
|
852
852
|
}), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
853
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false),
|
|
853
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
|
|
854
854
|
}), this.once("cancel", () => {
|
|
855
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false),
|
|
855
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
|
|
856
856
|
});
|
|
857
857
|
});
|
|
858
858
|
}
|
|
859
|
-
_isActionKey(
|
|
860
|
-
return
|
|
859
|
+
_isActionKey(t, e) {
|
|
860
|
+
return t === "\t";
|
|
861
861
|
}
|
|
862
|
-
_shouldSubmit(
|
|
862
|
+
_shouldSubmit(t, e) {
|
|
863
863
|
return true;
|
|
864
864
|
}
|
|
865
|
-
_setValue(
|
|
866
|
-
this.value =
|
|
865
|
+
_setValue(t) {
|
|
866
|
+
this.value = t, this.emit("value", this.value);
|
|
867
867
|
}
|
|
868
|
-
_setUserInput(
|
|
869
|
-
this.userInput =
|
|
868
|
+
_setUserInput(t, e) {
|
|
869
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
870
870
|
}
|
|
871
871
|
_clearUserInput() {
|
|
872
872
|
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
873
873
|
}
|
|
874
|
-
async onKeypress(
|
|
874
|
+
async onKeypress(t, e) {
|
|
875
875
|
if (this.state !== "validating") {
|
|
876
|
-
if (this._track && e.name !== "return" && (e.name && this._isActionKey(
|
|
876
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, e), e?.name === "return" && this._shouldSubmit(t, e)) {
|
|
877
877
|
if (this.opts.validate) {
|
|
878
878
|
const i = runValidation(this.opts.validate, this.value);
|
|
879
879
|
let s;
|
|
@@ -881,7 +881,7 @@ class y {
|
|
|
881
881
|
}
|
|
882
882
|
this.state !== "error" && (this.state = "submit");
|
|
883
883
|
}
|
|
884
|
-
isActionKey([
|
|
884
|
+
isActionKey([t, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
close() {
|
|
@@ -889,32 +889,32 @@ class y {
|
|
|
889
889
|
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
890
890
|
}
|
|
891
891
|
restoreCursor() {
|
|
892
|
-
const
|
|
892
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
893
893
|
`).length - 1;
|
|
894
|
-
this.output.write(import_sisteransi.cursor.move(-999,
|
|
894
|
+
this.output.write(import_sisteransi.cursor.move(-999, t * -1));
|
|
895
895
|
}
|
|
896
896
|
render() {
|
|
897
|
-
const
|
|
897
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
898
898
|
hard: true,
|
|
899
899
|
trim: false
|
|
900
900
|
});
|
|
901
|
-
if (
|
|
901
|
+
if (t !== this._prevFrame) {
|
|
902
902
|
if (this.state === "initial")
|
|
903
903
|
this.output.write(import_sisteransi.cursor.hide);
|
|
904
904
|
else {
|
|
905
|
-
const e = diffLines(this._prevFrame,
|
|
905
|
+
const e = diffLines(this._prevFrame, t), i = getRows(this.output);
|
|
906
906
|
if (this.restoreCursor(), e) {
|
|
907
907
|
const s = Math.max(0, e.numLinesAfter - i), r = Math.max(0, e.numLinesBefore - i);
|
|
908
908
|
let n = e.lines.find((o) => o >= s);
|
|
909
909
|
if (n === undefined) {
|
|
910
|
-
this._prevFrame =
|
|
910
|
+
this._prevFrame = t;
|
|
911
911
|
return;
|
|
912
912
|
}
|
|
913
913
|
if (e.lines.length === 1) {
|
|
914
914
|
this.output.write(import_sisteransi.cursor.move(0, n - r)), this.output.write(import_sisteransi.erase.lines(1));
|
|
915
|
-
const o =
|
|
915
|
+
const o = t.split(`
|
|
916
916
|
`);
|
|
917
|
-
this.output.write(o[n]), this._prevFrame =
|
|
917
|
+
this.output.write(o[n]), this._prevFrame = t, this.output.write(import_sisteransi.cursor.move(0, o.length - n - 1));
|
|
918
918
|
return;
|
|
919
919
|
} else if (e.lines.length > 1) {
|
|
920
920
|
if (s < r)
|
|
@@ -924,90 +924,20 @@ class y {
|
|
|
924
924
|
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
925
925
|
}
|
|
926
926
|
this.output.write(import_sisteransi.erase.down());
|
|
927
|
-
const f =
|
|
927
|
+
const f = t.split(`
|
|
928
928
|
`).slice(n);
|
|
929
929
|
this.output.write(f.join(`
|
|
930
|
-
`)), this._prevFrame =
|
|
930
|
+
`)), this._prevFrame = t;
|
|
931
931
|
return;
|
|
932
932
|
}
|
|
933
933
|
}
|
|
934
934
|
this.output.write(import_sisteransi.erase.down());
|
|
935
935
|
}
|
|
936
|
-
this.output.write(
|
|
936
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
|
-
|
|
941
|
-
if (l2 === undefined || e.length === 0)
|
|
942
|
-
return 0;
|
|
943
|
-
const i = e.findIndex((s) => s.value === l2);
|
|
944
|
-
return i !== -1 ? i : 0;
|
|
945
|
-
}
|
|
946
|
-
function m(l2, e) {
|
|
947
|
-
return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
|
|
948
|
-
}
|
|
949
|
-
function g(l2, e) {
|
|
950
|
-
if (e)
|
|
951
|
-
return l2 ? e : e[0];
|
|
952
|
-
}
|
|
953
|
-
function M(r2) {
|
|
954
|
-
return [...r2].map((t2) => _[t2]);
|
|
955
|
-
}
|
|
956
|
-
function P(r2) {
|
|
957
|
-
const i = new Intl.DateTimeFormat(r2, {
|
|
958
|
-
year: "numeric",
|
|
959
|
-
month: "2-digit",
|
|
960
|
-
day: "2-digit"
|
|
961
|
-
}).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
962
|
-
let n = "/";
|
|
963
|
-
for (const e of i)
|
|
964
|
-
e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
|
|
965
|
-
return { segments: s, separator: n };
|
|
966
|
-
}
|
|
967
|
-
function p(r2) {
|
|
968
|
-
return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
|
|
969
|
-
}
|
|
970
|
-
function f(r2) {
|
|
971
|
-
return {
|
|
972
|
-
year: p(r2.year),
|
|
973
|
-
month: p(r2.month),
|
|
974
|
-
day: p(r2.day)
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
function c(r2, t2) {
|
|
978
|
-
return new Date(r2 || 2001, t2 || 1, 0).getDate();
|
|
979
|
-
}
|
|
980
|
-
function b(r2) {
|
|
981
|
-
const { year: t2, month: i, day: s } = f(r2);
|
|
982
|
-
if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
|
|
983
|
-
return;
|
|
984
|
-
const n = new Date(Date.UTC(t2, i - 1, s));
|
|
985
|
-
if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
|
|
986
|
-
return { year: t2, month: i, day: s };
|
|
987
|
-
}
|
|
988
|
-
function C(r2) {
|
|
989
|
-
const t2 = b(r2);
|
|
990
|
-
return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
|
|
991
|
-
}
|
|
992
|
-
function T2(r2, t2, i, s) {
|
|
993
|
-
const n = i ? {
|
|
994
|
-
year: i.getUTCFullYear(),
|
|
995
|
-
month: i.getUTCMonth() + 1,
|
|
996
|
-
day: i.getUTCDate()
|
|
997
|
-
} : null, e = s ? {
|
|
998
|
-
year: s.getUTCFullYear(),
|
|
999
|
-
month: s.getUTCMonth() + 1,
|
|
1000
|
-
day: s.getUTCDate()
|
|
1001
|
-
} : null;
|
|
1002
|
-
return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
|
|
1003
|
-
min: n && t2.year === n.year ? n.month : 1,
|
|
1004
|
-
max: e && t2.year === e.year ? e.month : 12
|
|
1005
|
-
} : {
|
|
1006
|
-
min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
|
|
1007
|
-
max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
var import_sisteransi, a$1, t, settings, R, CANCEL_SYMBOL, getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80, getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20, T$1, r, _, U, u$2, o, h, a, u$1, n$1;
|
|
940
|
+
var import_sisteransi, a$1, t, settings, R, CANCEL_SYMBOL, getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80, getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20, r, a, u$1, n$1;
|
|
1011
941
|
var init_dist3 = __esm(() => {
|
|
1012
942
|
init_main();
|
|
1013
943
|
import_sisteransi = __toESM(require_src(), 1);
|
|
@@ -1055,78 +985,6 @@ var init_dist3 = __esm(() => {
|
|
|
1055
985
|
};
|
|
1056
986
|
R = globalThis.process.platform.startsWith("win");
|
|
1057
987
|
CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
1058
|
-
T$1 = class T extends y {
|
|
1059
|
-
filteredOptions;
|
|
1060
|
-
multiple;
|
|
1061
|
-
isNavigating = false;
|
|
1062
|
-
selectedValues = [];
|
|
1063
|
-
focusedValue;
|
|
1064
|
-
#e = 0;
|
|
1065
|
-
#s = "";
|
|
1066
|
-
#t;
|
|
1067
|
-
#i;
|
|
1068
|
-
#n;
|
|
1069
|
-
#l;
|
|
1070
|
-
get cursor() {
|
|
1071
|
-
return this.#e;
|
|
1072
|
-
}
|
|
1073
|
-
get userInputWithCursor() {
|
|
1074
|
-
if (!this.userInput)
|
|
1075
|
-
return styleText(["inverse", "hidden"], "_");
|
|
1076
|
-
if (this._cursor >= this.userInput.length)
|
|
1077
|
-
return `${this.userInput}█`;
|
|
1078
|
-
const e = this.userInput.slice(0, this.cursor), t2 = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1);
|
|
1079
|
-
return `${e}${styleText("inverse", t2)}${i}`;
|
|
1080
|
-
}
|
|
1081
|
-
get options() {
|
|
1082
|
-
return typeof this.#i == "function" ? this.#i() : this.#i;
|
|
1083
|
-
}
|
|
1084
|
-
constructor(e) {
|
|
1085
|
-
super(e), this.#i = e.options, this.#n = e.placeholder, this.#l = e.completeOnTab === true;
|
|
1086
|
-
const t2 = this.options;
|
|
1087
|
-
this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? m;
|
|
1088
|
-
let i;
|
|
1089
|
-
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0]?.value]), i)
|
|
1090
|
-
for (const s of i) {
|
|
1091
|
-
const n = t2.findIndex((r) => r.value === s);
|
|
1092
|
-
n !== -1 && (this.toggleSelected(s), this.#e = n);
|
|
1093
|
-
}
|
|
1094
|
-
this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#u(s, n)), this.on("userInput", (s) => this.#o(s));
|
|
1095
|
-
}
|
|
1096
|
-
_isActionKey(e, t2) {
|
|
1097
|
-
return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
|
|
1098
|
-
}
|
|
1099
|
-
#u(e, t2) {
|
|
1100
|
-
const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", r = this.userInput === "" || this.userInput === "\t", u = this.#n, d = this.options, c = u !== undefined && u !== "" && d.some((o) => !o.disabled && (this.#t ? this.#t(u, o) : true));
|
|
1101
|
-
if (t2.name === "tab" && r && c) {
|
|
1102
|
-
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
if (t2.name === "tab" && this.#l && !this.multiple && this.focusedValue !== undefined) {
|
|
1106
|
-
const o = String(this.focusedValue);
|
|
1107
|
-
this._clearUserInput(), this._setUserInput(o, true), this.isNavigating = false;
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = g(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
1111
|
-
}
|
|
1112
|
-
deselectAll() {
|
|
1113
|
-
this.selectedValues = [];
|
|
1114
|
-
}
|
|
1115
|
-
toggleSelected(e) {
|
|
1116
|
-
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
1117
|
-
}
|
|
1118
|
-
#o(e) {
|
|
1119
|
-
if (e !== this.#s) {
|
|
1120
|
-
this.#s = e;
|
|
1121
|
-
const t2 = this.options;
|
|
1122
|
-
e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
|
|
1123
|
-
const i = p$1(this.focusedValue, this.filteredOptions);
|
|
1124
|
-
this.#e = findCursor(i, 0, this.filteredOptions);
|
|
1125
|
-
const s = this.filteredOptions[this.#e];
|
|
1126
|
-
s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
988
|
r = class r extends y {
|
|
1131
989
|
get cursor() {
|
|
1132
990
|
return this.value ? 0 : 1;
|
|
@@ -1134,8 +992,8 @@ var init_dist3 = __esm(() => {
|
|
|
1134
992
|
get _value() {
|
|
1135
993
|
return this.cursor === 0;
|
|
1136
994
|
}
|
|
1137
|
-
constructor(
|
|
1138
|
-
super(
|
|
995
|
+
constructor(t) {
|
|
996
|
+
super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
1139
997
|
this.value = this._value;
|
|
1140
998
|
}), this.on("confirm", (i) => {
|
|
1141
999
|
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
@@ -1144,305 +1002,6 @@ var init_dist3 = __esm(() => {
|
|
|
1144
1002
|
});
|
|
1145
1003
|
}
|
|
1146
1004
|
};
|
|
1147
|
-
_ = {
|
|
1148
|
-
Y: { type: "year", len: 4 },
|
|
1149
|
-
M: { type: "month", len: 2 },
|
|
1150
|
-
D: { type: "day", len: 2 }
|
|
1151
|
-
};
|
|
1152
|
-
U = class U extends y {
|
|
1153
|
-
#i;
|
|
1154
|
-
#o;
|
|
1155
|
-
#t;
|
|
1156
|
-
#h;
|
|
1157
|
-
#u;
|
|
1158
|
-
#e = { segmentIndex: 0, positionInSegment: 0 };
|
|
1159
|
-
#n = true;
|
|
1160
|
-
#s = null;
|
|
1161
|
-
inlineError = "";
|
|
1162
|
-
get segmentCursor() {
|
|
1163
|
-
return { ...this.#e };
|
|
1164
|
-
}
|
|
1165
|
-
get segmentValues() {
|
|
1166
|
-
return { ...this.#t };
|
|
1167
|
-
}
|
|
1168
|
-
get segments() {
|
|
1169
|
-
return this.#i;
|
|
1170
|
-
}
|
|
1171
|
-
get separator() {
|
|
1172
|
-
return this.#o;
|
|
1173
|
-
}
|
|
1174
|
-
get formattedValue() {
|
|
1175
|
-
return this.#l(this.#t);
|
|
1176
|
-
}
|
|
1177
|
-
#l(t2) {
|
|
1178
|
-
return this.#i.map((i) => t2[i.type]).join(this.#o);
|
|
1179
|
-
}
|
|
1180
|
-
#r() {
|
|
1181
|
-
this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
|
|
1182
|
-
}
|
|
1183
|
-
constructor(t2) {
|
|
1184
|
-
const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
|
|
1185
|
-
year: String(e.getUTCFullYear()).padStart(4, "0"),
|
|
1186
|
-
month: String(e.getUTCMonth() + 1).padStart(2, "0"),
|
|
1187
|
-
day: String(e.getUTCDate()).padStart(2, "0")
|
|
1188
|
-
} : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
|
|
1189
|
-
super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
|
|
1190
|
-
}
|
|
1191
|
-
#a() {
|
|
1192
|
-
const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
|
|
1193
|
-
if (i)
|
|
1194
|
-
return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
|
|
1195
|
-
}
|
|
1196
|
-
#m(t2) {
|
|
1197
|
-
this.inlineError = "", this.#s = null;
|
|
1198
|
-
const i = this.#a();
|
|
1199
|
-
i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
|
|
1200
|
-
}
|
|
1201
|
-
#d(t2) {
|
|
1202
|
-
const i = this.#a();
|
|
1203
|
-
if (!i)
|
|
1204
|
-
return;
|
|
1205
|
-
const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m2 = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T2(s.type, f(this.#t), this.#h, this.#u);
|
|
1206
|
-
let a;
|
|
1207
|
-
e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
|
|
1208
|
-
...this.#t,
|
|
1209
|
-
[s.type]: a.toString().padStart(s.len, "0")
|
|
1210
|
-
}, this.#n = true, this.#s = null, this.#r();
|
|
1211
|
-
}
|
|
1212
|
-
#f(t2) {
|
|
1213
|
-
if (t2)
|
|
1214
|
-
switch (t2) {
|
|
1215
|
-
case "right":
|
|
1216
|
-
return this.#m(1);
|
|
1217
|
-
case "left":
|
|
1218
|
-
return this.#m(-1);
|
|
1219
|
-
case "up":
|
|
1220
|
-
return this.#d(1);
|
|
1221
|
-
case "down":
|
|
1222
|
-
return this.#d(-1);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
#y(t2, i) {
|
|
1226
|
-
if (i?.name === "backspace" || i?.sequence === "" || i?.sequence === "\b" || t2 === "" || t2 === "\b") {
|
|
1227
|
-
this.inlineError = "";
|
|
1228
|
-
const n = this.#a();
|
|
1229
|
-
if (!n)
|
|
1230
|
-
return;
|
|
1231
|
-
if (!this.#t[n.segment.type].replace(/_/g, "")) {
|
|
1232
|
-
this.#m(-1);
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
if (i?.name === "tab") {
|
|
1239
|
-
this.inlineError = "";
|
|
1240
|
-
const n = this.#a();
|
|
1241
|
-
if (!n)
|
|
1242
|
-
return;
|
|
1243
|
-
const e = i.shift ? -1 : 1, m2 = n.index + e;
|
|
1244
|
-
m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
|
|
1245
|
-
return;
|
|
1246
|
-
}
|
|
1247
|
-
if (t2 && /^[0-9]$/.test(t2)) {
|
|
1248
|
-
const n = this.#a();
|
|
1249
|
-
if (!n)
|
|
1250
|
-
return;
|
|
1251
|
-
const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
|
|
1252
|
-
if (this.#n && this.#s !== null && !m2) {
|
|
1253
|
-
const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
|
|
1254
|
-
if (g2) {
|
|
1255
|
-
this.inlineError = g2, this.#s = null, this.#n = false;
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
|
|
1262
|
-
const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
|
|
1263
|
-
if (u < 0 || u >= e.len)
|
|
1264
|
-
return;
|
|
1265
|
-
let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
|
|
1266
|
-
if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
|
|
1267
|
-
const h = Number.parseInt(t2, 10);
|
|
1268
|
-
l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
|
|
1269
|
-
}
|
|
1270
|
-
if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
|
|
1271
|
-
const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
|
|
1272
|
-
if (d) {
|
|
1273
|
-
this.inlineError = d;
|
|
1274
|
-
return;
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
this.inlineError = "", this.#t[e.type] = l2;
|
|
1278
|
-
const y2 = l2.includes("_") ? undefined : b(this.#t);
|
|
1279
|
-
if (y2) {
|
|
1280
|
-
const { year: h, month: d } = y2, g2 = c(h, d);
|
|
1281
|
-
this.#t = {
|
|
1282
|
-
year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
|
|
1283
|
-
month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
|
|
1284
|
-
day: String(Math.max(1, Math.min(g2, y2.day))).padStart(2, "0")
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
this.#r();
|
|
1288
|
-
const S = l2.indexOf("_");
|
|
1289
|
-
D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
#g(t2, i) {
|
|
1293
|
-
const { month: s, day: n } = f(t2);
|
|
1294
|
-
if (i.type === "month" && (s < 0 || s > 12))
|
|
1295
|
-
return settings.date.messages.invalidMonth;
|
|
1296
|
-
if (i.type === "day" && (n < 0 || n > 31))
|
|
1297
|
-
return settings.date.messages.invalidDay(31, "any month");
|
|
1298
|
-
}
|
|
1299
|
-
#p(t2) {
|
|
1300
|
-
const { year: i, month: s, day: n } = f(this.#t);
|
|
1301
|
-
if (i && s && n) {
|
|
1302
|
-
const e = c(i, s);
|
|
1303
|
-
this.#t = {
|
|
1304
|
-
...this.#t,
|
|
1305
|
-
day: String(Math.min(n, e)).padStart(2, "0")
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
|
|
1309
|
-
}
|
|
1310
|
-
};
|
|
1311
|
-
u$2 = class u extends y {
|
|
1312
|
-
options;
|
|
1313
|
-
cursor = 0;
|
|
1314
|
-
#t;
|
|
1315
|
-
getGroupItems(t2) {
|
|
1316
|
-
return this.options.filter((r2) => r2.group === t2);
|
|
1317
|
-
}
|
|
1318
|
-
isGroupSelected(t2) {
|
|
1319
|
-
const r2 = this.getGroupItems(t2), e = this.value;
|
|
1320
|
-
return e === undefined ? false : r2.every((s) => e.includes(s.value));
|
|
1321
|
-
}
|
|
1322
|
-
toggleValue() {
|
|
1323
|
-
const t2 = this.options[this.cursor];
|
|
1324
|
-
if (t2 !== undefined)
|
|
1325
|
-
if (this.value === undefined && (this.value = []), t2.group === true) {
|
|
1326
|
-
const r2 = t2.value, e = this.getGroupItems(r2);
|
|
1327
|
-
this.isGroupSelected(r2) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
|
|
1328
|
-
} else {
|
|
1329
|
-
const r2 = this.value.includes(t2.value);
|
|
1330
|
-
this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
constructor(t2) {
|
|
1334
|
-
super(t2, false);
|
|
1335
|
-
const { options: r2 } = t2;
|
|
1336
|
-
this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
|
|
1337
|
-
{ value: e, group: true, label: e },
|
|
1338
|
-
...s.map((i) => ({ ...i, group: e }))
|
|
1339
|
-
]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
1340
|
-
switch (e) {
|
|
1341
|
-
case "left":
|
|
1342
|
-
case "up": {
|
|
1343
|
-
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1344
|
-
const s = this.options[this.cursor]?.group === true;
|
|
1345
|
-
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1346
|
-
break;
|
|
1347
|
-
}
|
|
1348
|
-
case "down":
|
|
1349
|
-
case "right": {
|
|
1350
|
-
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1351
|
-
const s = this.options[this.cursor]?.group === true;
|
|
1352
|
-
!this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
1353
|
-
break;
|
|
1354
|
-
}
|
|
1355
|
-
case "space":
|
|
1356
|
-
this.toggleValue();
|
|
1357
|
-
break;
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
|
|
1363
|
-
h = class h extends y {
|
|
1364
|
-
#t = false;
|
|
1365
|
-
#s;
|
|
1366
|
-
focused = "editor";
|
|
1367
|
-
get userInputWithCursor() {
|
|
1368
|
-
if (this.state === "submit")
|
|
1369
|
-
return this.userInput;
|
|
1370
|
-
const t2 = this.userInput;
|
|
1371
|
-
if (this.cursor >= t2.length)
|
|
1372
|
-
return `${t2}█`;
|
|
1373
|
-
const s = t2.slice(0, this.cursor), r2 = t2.slice(this.cursor, this.cursor + 1), i = t2.slice(this.cursor + 1);
|
|
1374
|
-
return r2 === `
|
|
1375
|
-
` ? `${s}█
|
|
1376
|
-
${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
1377
|
-
}
|
|
1378
|
-
get cursor() {
|
|
1379
|
-
return this._cursor;
|
|
1380
|
-
}
|
|
1381
|
-
#r(t2) {
|
|
1382
|
-
if (this.userInput.length === 0) {
|
|
1383
|
-
this._setUserInput(t2);
|
|
1384
|
-
return;
|
|
1385
|
-
}
|
|
1386
|
-
this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
|
|
1387
|
-
}
|
|
1388
|
-
#i(t2) {
|
|
1389
|
-
const s = this.value ?? "";
|
|
1390
|
-
switch (t2) {
|
|
1391
|
-
case "up":
|
|
1392
|
-
this._cursor = findTextCursor(this._cursor, 0, -1, s);
|
|
1393
|
-
return;
|
|
1394
|
-
case "down":
|
|
1395
|
-
this._cursor = findTextCursor(this._cursor, 0, 1, s);
|
|
1396
|
-
return;
|
|
1397
|
-
case "left":
|
|
1398
|
-
this._cursor = findTextCursor(this._cursor, -1, 0, s);
|
|
1399
|
-
return;
|
|
1400
|
-
case "right":
|
|
1401
|
-
this._cursor = findTextCursor(this._cursor, 1, 0, s);
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
_shouldSubmit(t2, s) {
|
|
1406
|
-
if (this.#s)
|
|
1407
|
-
return this.focused === "submit" ? true : (this.#r(`
|
|
1408
|
-
`), this._cursor++, false);
|
|
1409
|
-
const r2 = this.#t;
|
|
1410
|
-
return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
|
|
1411
|
-
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
|
|
1412
|
-
`), this._cursor++, false);
|
|
1413
|
-
}
|
|
1414
|
-
constructor(t2) {
|
|
1415
|
-
const s = t2.initialUserInput ?? t2.initialValue;
|
|
1416
|
-
super({
|
|
1417
|
-
...t2,
|
|
1418
|
-
initialUserInput: s
|
|
1419
|
-
}, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
|
|
1420
|
-
if (i?.name && o.has(i.name)) {
|
|
1421
|
-
this.#t = false, this.#i(i.name);
|
|
1422
|
-
return;
|
|
1423
|
-
}
|
|
1424
|
-
if (r2 === "\t" && this.#s) {
|
|
1425
|
-
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
1426
|
-
return;
|
|
1427
|
-
}
|
|
1428
|
-
if (i?.name !== "return") {
|
|
1429
|
-
if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
|
|
1430
|
-
this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
if (i?.name === "delete" && this.cursor < this.userInput.length) {
|
|
1434
|
-
this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
|
|
1435
|
-
return;
|
|
1436
|
-
}
|
|
1437
|
-
r2 && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r2 ?? ""), this._cursor++);
|
|
1438
|
-
}
|
|
1439
|
-
}), this.on("userInput", (r2) => {
|
|
1440
|
-
this._setValue(r2);
|
|
1441
|
-
}), this.on("finalize", () => {
|
|
1442
|
-
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
};
|
|
1446
1005
|
a = class a extends y {
|
|
1447
1006
|
options;
|
|
1448
1007
|
cursor = 0;
|
|
@@ -1454,14 +1013,14 @@ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
|
1454
1013
|
}
|
|
1455
1014
|
toggleAll() {
|
|
1456
1015
|
const e = this._enabledOptions, i = this.value !== undefined && this.value.length === e.length;
|
|
1457
|
-
this.value = i ? [] : e.map((
|
|
1016
|
+
this.value = i ? [] : e.map((t) => t.value);
|
|
1458
1017
|
}
|
|
1459
1018
|
toggleInvert() {
|
|
1460
1019
|
const e = this.value;
|
|
1461
1020
|
if (!e)
|
|
1462
1021
|
return;
|
|
1463
|
-
const i = this._enabledOptions.filter((
|
|
1464
|
-
this.value = i.map((
|
|
1022
|
+
const i = this._enabledOptions.filter((t) => !e.includes(t.value));
|
|
1023
|
+
this.value = i.map((t) => t.value);
|
|
1465
1024
|
}
|
|
1466
1025
|
toggleValue() {
|
|
1467
1026
|
this.value === undefined && (this.value = []);
|
|
@@ -1470,11 +1029,11 @@ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
|
1470
1029
|
}
|
|
1471
1030
|
constructor(e) {
|
|
1472
1031
|
super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
1473
|
-
const i = Math.max(this.options.findIndex(({ value:
|
|
1474
|
-
this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (
|
|
1475
|
-
|
|
1476
|
-
}), this.on("cursor", (
|
|
1477
|
-
switch (
|
|
1032
|
+
const i = Math.max(this.options.findIndex(({ value: t }) => t === e.cursorAt), 0);
|
|
1033
|
+
this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
|
|
1034
|
+
l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
|
|
1035
|
+
}), this.on("cursor", (t) => {
|
|
1036
|
+
switch (t) {
|
|
1478
1037
|
case "left":
|
|
1479
1038
|
case "up":
|
|
1480
1039
|
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
@@ -1490,7 +1049,7 @@ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
|
1490
1049
|
});
|
|
1491
1050
|
}
|
|
1492
1051
|
};
|
|
1493
|
-
u$1 = class
|
|
1052
|
+
u$1 = class u extends y {
|
|
1494
1053
|
_mask = "•";
|
|
1495
1054
|
get cursor() {
|
|
1496
1055
|
return this._cursor;
|
|
@@ -1501,18 +1060,18 @@ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
|
1501
1060
|
get userInputWithCursor() {
|
|
1502
1061
|
if (this.state === "submit" || this.state === "cancel")
|
|
1503
1062
|
return this.masked;
|
|
1504
|
-
const
|
|
1505
|
-
if (this.cursor >=
|
|
1063
|
+
const t = this.userInput;
|
|
1064
|
+
if (this.cursor >= t.length)
|
|
1506
1065
|
return `${this.masked}${styleText(["inverse", "hidden"], "_")}`;
|
|
1507
|
-
const s = this.masked,
|
|
1508
|
-
return `${
|
|
1066
|
+
const s = this.masked, r = s.slice(0, this.cursor), i = s.slice(this.cursor, this.cursor + 1), o = s.slice(this.cursor + 1);
|
|
1067
|
+
return `${r}${styleText("inverse", i)}${o}`;
|
|
1509
1068
|
}
|
|
1510
1069
|
clear() {
|
|
1511
1070
|
this._clearUserInput();
|
|
1512
1071
|
}
|
|
1513
|
-
constructor({ mask:
|
|
1514
|
-
super(s), this._mask =
|
|
1515
|
-
this._setValue(
|
|
1072
|
+
constructor({ mask: t, ...s }) {
|
|
1073
|
+
super(s), this._mask = t ?? "•", this.on("userInput", (r) => {
|
|
1074
|
+
this._setValue(r);
|
|
1516
1075
|
}), this.on("finalize", () => {
|
|
1517
1076
|
this.value === undefined && (this.value = "");
|
|
1518
1077
|
});
|
|
@@ -1530,8 +1089,8 @@ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
|
1530
1089
|
}
|
|
1531
1090
|
constructor(e) {
|
|
1532
1091
|
super(e, false), this.options = e.options;
|
|
1533
|
-
const
|
|
1534
|
-
this.cursor = this.options[
|
|
1092
|
+
const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o;
|
|
1093
|
+
this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => {
|
|
1535
1094
|
switch (s) {
|
|
1536
1095
|
case "left":
|
|
1537
1096
|
case "up":
|
|
@@ -1557,12 +1116,12 @@ function isUnicodeSupported() {
|
|
|
1557
1116
|
}
|
|
1558
1117
|
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1559
1118
|
}
|
|
1560
|
-
function formatInstructionFooter(
|
|
1561
|
-
const
|
|
1562
|
-
return e &&
|
|
1119
|
+
function formatInstructionFooter(o, e) {
|
|
1120
|
+
const r = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o.join(" • ")}`];
|
|
1121
|
+
return e && r.push(styleText2("cyan", S_BAR_END)), r;
|
|
1563
1122
|
}
|
|
1564
|
-
var import_sisteransi2, unicode, isCI = () => process.env.CI === "true", unicodeOr = (
|
|
1565
|
-
switch (
|
|
1123
|
+
var import_sisteransi2, unicode, isCI = () => process.env.CI === "true", unicodeOr = (o, e) => unicode ? o : e, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_BAR_START, S_BAR, S_BAR_END, S_BAR_START_RIGHT, S_BAR_END_RIGHT, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_CHECKBOX_ACTIVE, S_CHECKBOX_SELECTED, S_CHECKBOX_INACTIVE, S_PASSWORD_MASK, S_BAR_H, S_CORNER_TOP_RIGHT, S_CONNECT_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_BOTTOM_LEFT, S_CORNER_TOP_LEFT, S_INFO, S_SUCCESS, S_WARN, S_ERROR, symbol = (o) => {
|
|
1124
|
+
switch (o) {
|
|
1566
1125
|
case "initial":
|
|
1567
1126
|
case "active":
|
|
1568
1127
|
return styleText2("cyan", S_STEP_ACTIVE);
|
|
@@ -1575,8 +1134,8 @@ var import_sisteransi2, unicode, isCI = () => process.env.CI === "true", unicode
|
|
|
1575
1134
|
case "validating":
|
|
1576
1135
|
return styleText2("dim", S_STEP_ACTIVE);
|
|
1577
1136
|
}
|
|
1578
|
-
}, symbolBar = (
|
|
1579
|
-
switch (
|
|
1137
|
+
}, symbolBar = (o) => {
|
|
1138
|
+
switch (o) {
|
|
1580
1139
|
case "initial":
|
|
1581
1140
|
case "active":
|
|
1582
1141
|
return styleText2("cyan", S_BAR);
|
|
@@ -1587,99 +1146,99 @@ var import_sisteransi2, unicode, isCI = () => process.env.CI === "true", unicode
|
|
|
1587
1146
|
case "submit":
|
|
1588
1147
|
return styleText2("green", S_BAR);
|
|
1589
1148
|
}
|
|
1590
|
-
}, I = (
|
|
1591
|
-
let
|
|
1592
|
-
if (
|
|
1593
|
-
for (let i =
|
|
1594
|
-
const
|
|
1595
|
-
if (
|
|
1149
|
+
}, I = (l, e, w, p, b, C = false) => {
|
|
1150
|
+
let r = e, O = 0;
|
|
1151
|
+
if (C)
|
|
1152
|
+
for (let i = p - 1;i >= w; i--) {
|
|
1153
|
+
const m = l[i];
|
|
1154
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
1596
1155
|
break;
|
|
1597
1156
|
}
|
|
1598
1157
|
else
|
|
1599
|
-
for (let i = w;i <
|
|
1600
|
-
const
|
|
1601
|
-
if (
|
|
1158
|
+
for (let i = w;i < p; i++) {
|
|
1159
|
+
const m = l[i];
|
|
1160
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
1602
1161
|
break;
|
|
1603
1162
|
}
|
|
1604
|
-
return { lineCount:
|
|
1163
|
+
return { lineCount: r, removals: O };
|
|
1605
1164
|
}, limitOptions = ({
|
|
1606
|
-
cursor:
|
|
1165
|
+
cursor: l,
|
|
1607
1166
|
options: e,
|
|
1608
1167
|
style: w,
|
|
1609
|
-
output:
|
|
1610
|
-
maxItems:
|
|
1611
|
-
columnPadding:
|
|
1612
|
-
rowPadding:
|
|
1168
|
+
output: p = process.stdout,
|
|
1169
|
+
maxItems: b = Number.POSITIVE_INFINITY,
|
|
1170
|
+
columnPadding: C = 0,
|
|
1171
|
+
rowPadding: r = 4
|
|
1613
1172
|
}) => {
|
|
1614
|
-
const i = getColumns(
|
|
1615
|
-
let
|
|
1616
|
-
|
|
1617
|
-
let d =
|
|
1618
|
-
const W = Math.min(
|
|
1619
|
-
let
|
|
1620
|
-
d &&
|
|
1621
|
-
const
|
|
1622
|
-
for (let
|
|
1623
|
-
const
|
|
1173
|
+
const i = getColumns(p) - C, m = getRows(p), M = styleText2("dim", "..."), v = Math.max(m - r, 0), a = Math.max(Math.min(b, v), 5);
|
|
1174
|
+
let f = 0;
|
|
1175
|
+
l >= a - 3 && (f = Math.max(Math.min(l - a + 3, e.length - a), 0));
|
|
1176
|
+
let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
|
|
1177
|
+
const W = Math.min(f + a, e.length), s = [];
|
|
1178
|
+
let g = 0;
|
|
1179
|
+
d && g++, c && g++;
|
|
1180
|
+
const T = f + (d ? 1 : 0), y = W - (c ? 1 : 0);
|
|
1181
|
+
for (let t = T;t < y; t++) {
|
|
1182
|
+
const n = e[t], o = n ? w(n, t === l) : "", h = wrapAnsi(o, i, {
|
|
1624
1183
|
hard: true,
|
|
1625
1184
|
trim: false
|
|
1626
1185
|
}).split(`
|
|
1627
1186
|
`);
|
|
1628
|
-
s.push(
|
|
1187
|
+
s.push(h), g += h.length;
|
|
1629
1188
|
}
|
|
1630
|
-
if (
|
|
1631
|
-
let
|
|
1632
|
-
const
|
|
1633
|
-
let
|
|
1634
|
-
const L = () => I(s,
|
|
1635
|
-
d ? ({ lineCount:
|
|
1189
|
+
if (g > v) {
|
|
1190
|
+
let t = 0, n = 0, o = g;
|
|
1191
|
+
const h = l - T;
|
|
1192
|
+
let u = v;
|
|
1193
|
+
const L = () => I(s, o, 0, h, u), E = () => I(s, o, h + 1, s.length, u, true);
|
|
1194
|
+
d ? ({ lineCount: o, removals: t } = L(), o > u && (c || (u -= 1), { lineCount: o, removals: n } = E())) : (c || (u -= 1), { lineCount: o, removals: n } = E(), o > u && (u -= 1, { lineCount: o, removals: t } = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
|
|
1636
1195
|
}
|
|
1637
1196
|
const x = [];
|
|
1638
|
-
d && x.push(
|
|
1639
|
-
for (const
|
|
1640
|
-
for (const
|
|
1641
|
-
x.push(
|
|
1642
|
-
return
|
|
1197
|
+
d && x.push(M);
|
|
1198
|
+
for (const t of s)
|
|
1199
|
+
for (const n of t)
|
|
1200
|
+
x.push(n);
|
|
1201
|
+
return c && x.push(M), x;
|
|
1643
1202
|
}, confirm = (e) => {
|
|
1644
|
-
const
|
|
1203
|
+
const a = e.active ?? "Yes", o = e.inactive ?? "No";
|
|
1645
1204
|
return new r({
|
|
1646
|
-
active:
|
|
1647
|
-
inactive:
|
|
1205
|
+
active: a,
|
|
1206
|
+
inactive: o,
|
|
1648
1207
|
signal: e.signal,
|
|
1649
1208
|
input: e.input,
|
|
1650
1209
|
output: e.output,
|
|
1651
1210
|
initialValue: e.initialValue ?? true,
|
|
1652
1211
|
render() {
|
|
1653
|
-
const i = e.withGuide ?? settings.withGuide,
|
|
1654
|
-
` : ""}${
|
|
1655
|
-
`,
|
|
1212
|
+
const i = e.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = i ? `${styleText2("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(e.output, e.message, l, u), s = `${i ? `${styleText2("gray", S_BAR)}
|
|
1213
|
+
` : ""}${f}
|
|
1214
|
+
`, c = this.value ? a : o;
|
|
1656
1215
|
switch (this.state) {
|
|
1657
1216
|
case "submit": {
|
|
1658
|
-
const
|
|
1659
|
-
return `${s}${
|
|
1217
|
+
const r = i ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1218
|
+
return `${s}${r}${styleText2("dim", c)}`;
|
|
1660
1219
|
}
|
|
1661
1220
|
case "cancel": {
|
|
1662
|
-
const
|
|
1663
|
-
return `${s}${
|
|
1221
|
+
const r = i ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1222
|
+
return `${s}${r}${styleText2(["strikethrough", "dim"], c)}${i ? `
|
|
1664
1223
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1665
1224
|
}
|
|
1666
1225
|
default: {
|
|
1667
|
-
const
|
|
1668
|
-
return `${s}${
|
|
1226
|
+
const r = i ? `${styleText2("cyan", S_BAR)} ` : "", g = i ? styleText2("cyan", S_BAR_END) : "";
|
|
1227
|
+
return `${s}${r}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a)}`}${e.vertical ? i ? `
|
|
1669
1228
|
${styleText2("cyan", S_BAR)} ` : `
|
|
1670
|
-
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim",
|
|
1671
|
-
${
|
|
1229
|
+
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", o)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${o}`}
|
|
1230
|
+
${g}
|
|
1672
1231
|
`;
|
|
1673
1232
|
}
|
|
1674
1233
|
}
|
|
1675
1234
|
}
|
|
1676
1235
|
}).prompt();
|
|
1677
|
-
}, MULTISELECT_INSTRUCTIONS,
|
|
1678
|
-
`).map((d) =>
|
|
1236
|
+
}, MULTISELECT_INSTRUCTIONS, m = (i, u) => i.split(`
|
|
1237
|
+
`).map((d) => u(d)).join(`
|
|
1679
1238
|
`), multiselect = (i) => {
|
|
1680
|
-
const
|
|
1681
|
-
const
|
|
1682
|
-
return
|
|
1239
|
+
const u = (t, a) => {
|
|
1240
|
+
const r = t.label ?? String(t.value);
|
|
1241
|
+
return a === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText2(["strikethrough", "gray"], o))}${t.hint ? ` ${styleText2("dim", `(${t.hint ?? "disabled"})`)}` : ""}` : a === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r}${t.hint ? ` ${styleText2("dim", `(${t.hint})`)}` : ""}` : a === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${m(r, (o) => styleText2("dim", o))}${t.hint ? ` ${styleText2("dim", `(${t.hint})`)}` : ""}` : a === "cancelled" ? `${m(r, (o) => styleText2(["strikethrough", "dim"], o))}` : a === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r}${t.hint ? ` ${styleText2("dim", `(${t.hint})`)}` : ""}` : a === "submitted" ? `${m(r, (o) => styleText2("dim", o))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText2("dim", o))}`;
|
|
1683
1242
|
}, d = i.required ?? true, x = i.showInstructions ?? true;
|
|
1684
1243
|
return new a({
|
|
1685
1244
|
options: i.options,
|
|
@@ -1689,105 +1248,105 @@ ${g2}
|
|
|
1689
1248
|
initialValues: i.initialValues,
|
|
1690
1249
|
required: d,
|
|
1691
1250
|
cursorAt: i.cursorAt,
|
|
1692
|
-
validate(
|
|
1693
|
-
if (d && (
|
|
1251
|
+
validate(t) {
|
|
1252
|
+
if (d && (t === undefined || t.length === 0))
|
|
1694
1253
|
return `Please select at least one option.
|
|
1695
1254
|
${styleText2("reset", styleText2("dim", `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2("gray", styleText2("bgWhite", styleText2("inverse", " enter ")))} to submit`))}`;
|
|
1696
1255
|
},
|
|
1697
1256
|
render() {
|
|
1698
|
-
const
|
|
1699
|
-
` : ""}${
|
|
1700
|
-
`,
|
|
1701
|
-
if (
|
|
1702
|
-
return
|
|
1703
|
-
const s =
|
|
1704
|
-
return
|
|
1257
|
+
const t = i.withGuide ?? settings.withGuide, a = wrapTextWithPrefix(i.output, i.message, t ? `${symbolBar(this.state)} ` : "", `${symbol(this.state)} `), r = `${t ? `${styleText2("gray", S_BAR)}
|
|
1258
|
+
` : ""}${a}
|
|
1259
|
+
`, o = this.value ?? [], g = (n, l) => {
|
|
1260
|
+
if (n.disabled)
|
|
1261
|
+
return u(n, "disabled");
|
|
1262
|
+
const s = o.includes(n.value);
|
|
1263
|
+
return l && s ? u(n, "active-selected") : s ? u(n, "selected") : u(n, l ? "active" : "inactive");
|
|
1705
1264
|
};
|
|
1706
1265
|
switch (this.state) {
|
|
1707
1266
|
case "submit": {
|
|
1708
|
-
const
|
|
1709
|
-
return `${
|
|
1267
|
+
const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), l = wrapTextWithPrefix(i.output, n, t ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1268
|
+
return `${r}${l}`;
|
|
1710
1269
|
}
|
|
1711
1270
|
case "cancel": {
|
|
1712
|
-
const
|
|
1713
|
-
if (
|
|
1714
|
-
return `${
|
|
1715
|
-
const
|
|
1716
|
-
return `${
|
|
1271
|
+
const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "cancelled")).join(styleText2("dim", ", "));
|
|
1272
|
+
if (n.trim() === "")
|
|
1273
|
+
return `${r}${styleText2("gray", S_BAR)}`;
|
|
1274
|
+
const l = wrapTextWithPrefix(i.output, n, t ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1275
|
+
return `${r}${l}${t ? `
|
|
1717
1276
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1718
1277
|
}
|
|
1719
1278
|
case "error": {
|
|
1720
|
-
const
|
|
1721
|
-
`).map(($, v) => v === 0 ? `${
|
|
1722
|
-
`), s =
|
|
1723
|
-
`).length,
|
|
1279
|
+
const n = t ? `${styleText2("yellow", S_BAR)} ` : "", l = this.error.split(`
|
|
1280
|
+
`).map(($, v) => v === 0 ? `${t ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $)}` : ` ${$}`).join(`
|
|
1281
|
+
`), s = r.split(`
|
|
1282
|
+
`).length, h = l.split(`
|
|
1724
1283
|
`).length + 1;
|
|
1725
|
-
return `${
|
|
1284
|
+
return `${r}${n}${limitOptions({
|
|
1726
1285
|
output: i.output,
|
|
1727
1286
|
options: this.options,
|
|
1728
1287
|
cursor: this.cursor,
|
|
1729
1288
|
maxItems: i.maxItems,
|
|
1730
|
-
columnPadding:
|
|
1731
|
-
rowPadding: s +
|
|
1732
|
-
style:
|
|
1289
|
+
columnPadding: n.length,
|
|
1290
|
+
rowPadding: s + h,
|
|
1291
|
+
style: g
|
|
1733
1292
|
}).join(`
|
|
1734
|
-
${
|
|
1735
|
-
${
|
|
1293
|
+
${n}`)}
|
|
1294
|
+
${l}
|
|
1736
1295
|
`;
|
|
1737
1296
|
}
|
|
1738
1297
|
default: {
|
|
1739
|
-
const
|
|
1740
|
-
`).length, s = x ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS,
|
|
1298
|
+
const n = t ? `${styleText2("cyan", S_BAR)} ` : "", l = r.split(`
|
|
1299
|
+
`).length, s = x ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t) : t ? [styleText2("cyan", S_BAR_END)] : [], h = s.join(`
|
|
1741
1300
|
`), $ = s.length + 1;
|
|
1742
|
-
return `${
|
|
1301
|
+
return `${r}${n}${limitOptions({
|
|
1743
1302
|
output: i.output,
|
|
1744
1303
|
options: this.options,
|
|
1745
1304
|
cursor: this.cursor,
|
|
1746
1305
|
maxItems: i.maxItems,
|
|
1747
|
-
columnPadding:
|
|
1748
|
-
rowPadding:
|
|
1749
|
-
style:
|
|
1306
|
+
columnPadding: n.length,
|
|
1307
|
+
rowPadding: l + $,
|
|
1308
|
+
style: g
|
|
1750
1309
|
}).join(`
|
|
1751
|
-
${
|
|
1752
|
-
${
|
|
1310
|
+
${n}`)}
|
|
1311
|
+
${h}
|
|
1753
1312
|
`;
|
|
1754
1313
|
}
|
|
1755
1314
|
}
|
|
1756
1315
|
}
|
|
1757
1316
|
}).prompt();
|
|
1758
|
-
}, log, cancel = (
|
|
1759
|
-
const i =
|
|
1760
|
-
i.write(`${e}${styleText2("red",
|
|
1317
|
+
}, log, cancel = (o = "", t) => {
|
|
1318
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
|
|
1319
|
+
i.write(`${e}${styleText2("red", o)}
|
|
1761
1320
|
|
|
1762
1321
|
`);
|
|
1763
|
-
}, intro = (
|
|
1764
|
-
const i =
|
|
1765
|
-
i.write(`${e}${
|
|
1322
|
+
}, intro = (o = "", t) => {
|
|
1323
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
1324
|
+
i.write(`${e}${o}
|
|
1766
1325
|
`);
|
|
1767
|
-
}, outro = (
|
|
1768
|
-
const i =
|
|
1326
|
+
}, outro = (o = "", t) => {
|
|
1327
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
1769
1328
|
${styleText2("gray", S_BAR_END)} ` : "";
|
|
1770
|
-
i.write(`${e}${
|
|
1329
|
+
i.write(`${e}${o}
|
|
1771
1330
|
|
|
1772
1331
|
`);
|
|
1773
|
-
}, W$1 = (
|
|
1774
|
-
const
|
|
1332
|
+
}, W$1 = (o) => o, C = (o, e, s) => {
|
|
1333
|
+
const a = {
|
|
1775
1334
|
hard: true,
|
|
1776
1335
|
trim: false
|
|
1777
|
-
}, i = wrapAnsi(
|
|
1778
|
-
`),
|
|
1779
|
-
return wrapAnsi(
|
|
1780
|
-
}, note = (
|
|
1781
|
-
const
|
|
1782
|
-
`).map(
|
|
1336
|
+
}, i = wrapAnsi(o, e, a).split(`
|
|
1337
|
+
`), c = i.reduce((n, t) => Math.max(dist_default2(t), n), 0), u = i.map(s).reduce((n, t) => Math.max(dist_default2(t), n), 0), g = e - (u - c);
|
|
1338
|
+
return wrapAnsi(o, g, a);
|
|
1339
|
+
}, note = (o = "", e = "", s) => {
|
|
1340
|
+
const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = ["", ...C(o, getColumns(a) - 6, c).split(`
|
|
1341
|
+
`).map(c), ""], n = dist_default2(e), t = Math.max(g.reduce((m, F) => {
|
|
1783
1342
|
const O = dist_default2(F);
|
|
1784
|
-
return O >
|
|
1785
|
-
}, 0),
|
|
1786
|
-
`),
|
|
1343
|
+
return O > m ? O : m;
|
|
1344
|
+
}, 0), n) + 2, h = g.map((m) => `${styleText2("gray", S_BAR)} ${m}${" ".repeat(t - dist_default2(m))}${styleText2("gray", S_BAR)}`).join(`
|
|
1345
|
+
`), T = i ? `${styleText2("gray", S_BAR)}
|
|
1787
1346
|
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
1788
|
-
|
|
1789
|
-
${
|
|
1790
|
-
${styleText2("gray", l$1 + S_BAR_H.repeat(
|
|
1347
|
+
a.write(`${T}${styleText2("green", S_STEP_SUBMIT)} ${styleText2("reset", e)} ${styleText2("gray", S_BAR_H.repeat(Math.max(t - n - 1, 1)) + S_CORNER_TOP_RIGHT)}
|
|
1348
|
+
${h}
|
|
1349
|
+
${styleText2("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
1791
1350
|
`);
|
|
1792
1351
|
}, password = (e) => new u$1({
|
|
1793
1352
|
validate: e.validate,
|
|
@@ -1796,170 +1355,170 @@ ${styleText2("gray", l$1 + S_BAR_H.repeat(t2 + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
|
1796
1355
|
input: e.input,
|
|
1797
1356
|
output: e.output,
|
|
1798
1357
|
render() {
|
|
1799
|
-
const
|
|
1358
|
+
const r = e.withGuide ?? settings.withGuide, o = `${r ? `${styleText2("gray", S_BAR)}
|
|
1800
1359
|
` : ""}${symbol(this.state)} ${e.message}
|
|
1801
|
-
`,
|
|
1360
|
+
`, m = this.userInputWithCursor, i = this.masked;
|
|
1802
1361
|
switch (this.state) {
|
|
1803
1362
|
case "error": {
|
|
1804
|
-
const s =
|
|
1805
|
-
return e.clearOnError && this.clear(), `${
|
|
1363
|
+
const s = r ? `${styleText2("yellow", S_BAR)} ` : "", n = r ? `${styleText2("yellow", S_BAR_END)} ` : "", d = i ?? "";
|
|
1364
|
+
return e.clearOnError && this.clear(), `${o.trim()}
|
|
1806
1365
|
${s}${d}
|
|
1807
|
-
${
|
|
1366
|
+
${n}${styleText2("yellow", this.error)}
|
|
1808
1367
|
`;
|
|
1809
1368
|
}
|
|
1810
1369
|
case "submit": {
|
|
1811
|
-
const s =
|
|
1812
|
-
return `${
|
|
1370
|
+
const s = r ? `${styleText2("gray", S_BAR)} ` : "", n = i ? styleText2("dim", i) : "";
|
|
1371
|
+
return `${o}${s}${n}`;
|
|
1813
1372
|
}
|
|
1814
1373
|
case "cancel": {
|
|
1815
|
-
const s =
|
|
1816
|
-
return `${
|
|
1374
|
+
const s = r ? `${styleText2("gray", S_BAR)} ` : "", n = i ? styleText2(["strikethrough", "dim"], i) : "";
|
|
1375
|
+
return `${o}${s}${n}${i && r ? `
|
|
1817
1376
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1818
1377
|
}
|
|
1819
1378
|
default: {
|
|
1820
|
-
const s =
|
|
1821
|
-
return `${
|
|
1822
|
-
${
|
|
1379
|
+
const s = r ? `${styleText2("cyan", S_BAR)} ` : "", n = r ? styleText2("cyan", S_BAR_END) : "";
|
|
1380
|
+
return `${o}${s}${m}
|
|
1381
|
+
${n}
|
|
1823
1382
|
`;
|
|
1824
1383
|
}
|
|
1825
1384
|
}
|
|
1826
1385
|
}
|
|
1827
|
-
}).prompt(), W = (
|
|
1828
|
-
indicator:
|
|
1829
|
-
onCancel:
|
|
1830
|
-
output:
|
|
1386
|
+
}).prompt(), W = (l) => styleText2("magenta", l), spinner = ({
|
|
1387
|
+
indicator: l = "dots",
|
|
1388
|
+
onCancel: h,
|
|
1389
|
+
output: n = process.stdout,
|
|
1831
1390
|
cancelMessage: G,
|
|
1832
1391
|
errorMessage: O,
|
|
1833
1392
|
frames: E = unicode ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"],
|
|
1834
1393
|
delay: F = unicode ? 80 : 120,
|
|
1835
|
-
signal:
|
|
1836
|
-
...
|
|
1394
|
+
signal: m,
|
|
1395
|
+
...I
|
|
1837
1396
|
} = {}) => {
|
|
1838
|
-
const
|
|
1839
|
-
let
|
|
1840
|
-
const x = getColumns(
|
|
1841
|
-
const
|
|
1842
|
-
S = e === 1, d && (
|
|
1843
|
-
},
|
|
1844
|
-
process.on("uncaughtExceptionMonitor",
|
|
1397
|
+
const u = isCI();
|
|
1398
|
+
let M, T, d = false, S = false, s = "", p, w = performance.now();
|
|
1399
|
+
const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
|
|
1400
|
+
const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
1401
|
+
S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
|
|
1402
|
+
}, f = () => g(2), i = () => g(1), A = () => {
|
|
1403
|
+
process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g), m && m.addEventListener("abort", i);
|
|
1845
1404
|
}, H = () => {
|
|
1846
|
-
process.removeListener("uncaughtExceptionMonitor",
|
|
1847
|
-
},
|
|
1848
|
-
if (
|
|
1405
|
+
process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g), m && m.removeEventListener("abort", i);
|
|
1406
|
+
}, y = () => {
|
|
1407
|
+
if (p === undefined)
|
|
1849
1408
|
return;
|
|
1850
|
-
|
|
1409
|
+
u && n.write(`
|
|
1851
1410
|
`);
|
|
1852
|
-
const
|
|
1411
|
+
const r = wrapAnsi(p, x, {
|
|
1853
1412
|
hard: true,
|
|
1854
1413
|
trim: false
|
|
1855
1414
|
}).split(`
|
|
1856
1415
|
`);
|
|
1857
|
-
|
|
1858
|
-
},
|
|
1859
|
-
const
|
|
1860
|
-
return
|
|
1861
|
-
}, N =
|
|
1862
|
-
d = true,
|
|
1416
|
+
r.length > 1 && n.write(import_sisteransi2.cursor.up(r.length - 1)), n.write(import_sisteransi2.cursor.to(0)), n.write(import_sisteransi2.erase.down());
|
|
1417
|
+
}, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
|
|
1418
|
+
const r = (performance.now() - e) / 1000, t = Math.floor(r / 60), o = Math.floor(r % 60);
|
|
1419
|
+
return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
|
|
1420
|
+
}, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
|
|
1421
|
+
d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText2("gray", S_BAR)}
|
|
1863
1422
|
`);
|
|
1864
|
-
let
|
|
1865
|
-
A(),
|
|
1866
|
-
if (
|
|
1423
|
+
let r = 0, t = 0;
|
|
1424
|
+
A(), T = setInterval(() => {
|
|
1425
|
+
if (u && s === p)
|
|
1867
1426
|
return;
|
|
1868
|
-
|
|
1869
|
-
const
|
|
1427
|
+
y(), p = s;
|
|
1428
|
+
const o = k(E[r]);
|
|
1870
1429
|
let v;
|
|
1871
|
-
if (
|
|
1872
|
-
v = `${
|
|
1873
|
-
else if (
|
|
1874
|
-
v = `${
|
|
1430
|
+
if (u)
|
|
1431
|
+
v = `${o} ${s}...`;
|
|
1432
|
+
else if (l === "timer")
|
|
1433
|
+
v = `${o} ${s} ${_(w)}`;
|
|
1875
1434
|
else {
|
|
1876
|
-
const B = ".".repeat(Math.floor(
|
|
1877
|
-
v = `${
|
|
1435
|
+
const B = ".".repeat(Math.floor(t)).slice(0, 3);
|
|
1436
|
+
v = `${o} ${s}${B}`;
|
|
1878
1437
|
}
|
|
1879
1438
|
const j = wrapAnsi(v, x, {
|
|
1880
1439
|
hard: true,
|
|
1881
1440
|
trim: false
|
|
1882
1441
|
});
|
|
1883
|
-
|
|
1442
|
+
n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + 0.125 : 0;
|
|
1884
1443
|
}, F);
|
|
1885
|
-
},
|
|
1444
|
+
}, a = (e = "", r = 0, t = false) => {
|
|
1886
1445
|
if (!d)
|
|
1887
1446
|
return;
|
|
1888
|
-
d = false, clearInterval(
|
|
1889
|
-
const
|
|
1890
|
-
s = e ?? s,
|
|
1891
|
-
`) :
|
|
1892
|
-
`)), H(),
|
|
1447
|
+
d = false, clearInterval(T), y();
|
|
1448
|
+
const o = r === 0 ? styleText2("green", S_STEP_SUBMIT) : r === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
1449
|
+
s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
|
|
1450
|
+
`) : n.write(`${o} ${s}
|
|
1451
|
+
`)), H(), M();
|
|
1893
1452
|
};
|
|
1894
1453
|
return {
|
|
1895
|
-
start:
|
|
1896
|
-
stop: (e = "") =>
|
|
1454
|
+
start: P,
|
|
1455
|
+
stop: (e = "") => a(e, 0),
|
|
1897
1456
|
message: (e = "") => {
|
|
1898
|
-
s =
|
|
1457
|
+
s = C(e ?? s);
|
|
1899
1458
|
},
|
|
1900
|
-
cancel: (e = "") =>
|
|
1901
|
-
error: (e = "") =>
|
|
1902
|
-
clear: () =>
|
|
1459
|
+
cancel: (e = "") => a(e, 1),
|
|
1460
|
+
error: (e = "") => a(e, 2),
|
|
1461
|
+
clear: () => a("", 0, true),
|
|
1903
1462
|
get isCancelled() {
|
|
1904
1463
|
return S;
|
|
1905
1464
|
}
|
|
1906
1465
|
};
|
|
1907
|
-
},
|
|
1908
|
-
`) ?
|
|
1909
|
-
`).map((d) =>
|
|
1910
|
-
`) :
|
|
1911
|
-
const
|
|
1912
|
-
if (
|
|
1466
|
+
}, u2, SELECT_INSTRUCTIONS, c = (t, o) => t.includes(`
|
|
1467
|
+
`) ? t.split(`
|
|
1468
|
+
`).map((d) => o(d)).join(`
|
|
1469
|
+
`) : o(t), select = (t) => {
|
|
1470
|
+
const o = (n, m) => {
|
|
1471
|
+
if (n === undefined)
|
|
1913
1472
|
return "";
|
|
1914
|
-
const s =
|
|
1915
|
-
switch (
|
|
1473
|
+
const s = n.label ?? String(n.value);
|
|
1474
|
+
switch (m) {
|
|
1916
1475
|
case "disabled":
|
|
1917
|
-
return `${styleText2("gray", S_RADIO_INACTIVE)} ${
|
|
1476
|
+
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (i) => styleText2("gray", i))}${n.hint ? ` ${styleText2("dim", `(${n.hint ?? "disabled"})`)}` : ""}`;
|
|
1918
1477
|
case "selected":
|
|
1919
|
-
return `${
|
|
1478
|
+
return `${c(s, (i) => styleText2("dim", i))}`;
|
|
1920
1479
|
case "active":
|
|
1921
|
-
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${
|
|
1480
|
+
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${n.hint ? ` ${styleText2("dim", `(${n.hint})`)}` : ""}`;
|
|
1922
1481
|
case "cancelled":
|
|
1923
|
-
return `${
|
|
1482
|
+
return `${c(s, (i) => styleText2(["strikethrough", "dim"], i))}`;
|
|
1924
1483
|
default:
|
|
1925
|
-
return `${styleText2("dim", S_RADIO_INACTIVE)} ${
|
|
1484
|
+
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (i) => styleText2("dim", i))}`;
|
|
1926
1485
|
}
|
|
1927
|
-
}, d =
|
|
1486
|
+
}, d = t.showInstructions ?? true;
|
|
1928
1487
|
return new n$1({
|
|
1929
|
-
options:
|
|
1930
|
-
signal:
|
|
1931
|
-
input:
|
|
1932
|
-
output:
|
|
1933
|
-
initialValue:
|
|
1488
|
+
options: t.options,
|
|
1489
|
+
signal: t.signal,
|
|
1490
|
+
input: t.input,
|
|
1491
|
+
output: t.output,
|
|
1492
|
+
initialValue: t.initialValue,
|
|
1934
1493
|
render() {
|
|
1935
|
-
const
|
|
1494
|
+
const n = t.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i = wrapTextWithPrefix(t.output, t.message, s, m), u = `${n ? `${styleText2("gray", S_BAR)}
|
|
1936
1495
|
` : ""}${i}
|
|
1937
1496
|
`;
|
|
1938
1497
|
switch (this.state) {
|
|
1939
1498
|
case "submit": {
|
|
1940
|
-
const
|
|
1941
|
-
return `${
|
|
1499
|
+
const r = n ? `${styleText2("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "selected"), r);
|
|
1500
|
+
return `${u}${a}`;
|
|
1942
1501
|
}
|
|
1943
1502
|
case "cancel": {
|
|
1944
|
-
const
|
|
1945
|
-
return `${
|
|
1503
|
+
const r = n ? `${styleText2("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "cancelled"), r);
|
|
1504
|
+
return `${u}${a}${n ? `
|
|
1946
1505
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1947
1506
|
}
|
|
1948
1507
|
default: {
|
|
1949
|
-
const
|
|
1950
|
-
`).length,
|
|
1951
|
-
`),
|
|
1952
|
-
return `${
|
|
1953
|
-
output:
|
|
1508
|
+
const r = n ? `${styleText2("cyan", S_BAR)} ` : "", a = u.split(`
|
|
1509
|
+
`).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n) : n ? [styleText2("cyan", S_BAR_END)] : [], f = p.join(`
|
|
1510
|
+
`), b = p.length + 1;
|
|
1511
|
+
return `${u}${r}${limitOptions({
|
|
1512
|
+
output: t.output,
|
|
1954
1513
|
cursor: this.cursor,
|
|
1955
1514
|
options: this.options,
|
|
1956
|
-
maxItems:
|
|
1957
|
-
columnPadding:
|
|
1958
|
-
rowPadding:
|
|
1959
|
-
style: (
|
|
1515
|
+
maxItems: t.maxItems,
|
|
1516
|
+
columnPadding: r.length,
|
|
1517
|
+
rowPadding: a + b,
|
|
1518
|
+
style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
|
|
1960
1519
|
}).join(`
|
|
1961
|
-
${
|
|
1962
|
-
${
|
|
1520
|
+
${r}`)}
|
|
1521
|
+
${f}
|
|
1963
1522
|
`;
|
|
1964
1523
|
}
|
|
1965
1524
|
}
|
|
@@ -2006,23 +1565,23 @@ var init_dist4 = __esm(() => {
|
|
|
2006
1565
|
log = {
|
|
2007
1566
|
message: (s = [], {
|
|
2008
1567
|
symbol: e = styleText2("gray", S_BAR),
|
|
2009
|
-
secondarySymbol:
|
|
2010
|
-
output:
|
|
2011
|
-
spacing:
|
|
2012
|
-
withGuide:
|
|
1568
|
+
secondarySymbol: r = styleText2("gray", S_BAR),
|
|
1569
|
+
output: m = process.stdout,
|
|
1570
|
+
spacing: l = 1,
|
|
1571
|
+
withGuide: c
|
|
2013
1572
|
} = {}) => {
|
|
2014
|
-
const
|
|
2015
|
-
for (let i = 0;i <
|
|
2016
|
-
|
|
2017
|
-
const
|
|
1573
|
+
const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
|
|
1574
|
+
for (let i = 0;i < l; i++)
|
|
1575
|
+
t.push(f);
|
|
1576
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
2018
1577
|
`);
|
|
2019
|
-
if (
|
|
2020
|
-
const [i, ...
|
|
2021
|
-
i.length > 0 ?
|
|
2022
|
-
for (const
|
|
2023
|
-
|
|
1578
|
+
if (g.length > 0) {
|
|
1579
|
+
const [i, ...y] = g;
|
|
1580
|
+
i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
|
|
1581
|
+
for (const p of y)
|
|
1582
|
+
p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
|
|
2024
1583
|
}
|
|
2025
|
-
|
|
1584
|
+
m.write(`${t.join(`
|
|
2026
1585
|
`)}
|
|
2027
1586
|
`);
|
|
2028
1587
|
},
|
|
@@ -2045,7 +1604,7 @@ var init_dist4 = __esm(() => {
|
|
|
2045
1604
|
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
2046
1605
|
}
|
|
2047
1606
|
};
|
|
2048
|
-
|
|
1607
|
+
u2 = {
|
|
2049
1608
|
light: unicodeOr("─", "-"),
|
|
2050
1609
|
heavy: unicodeOr("━", "="),
|
|
2051
1610
|
block: unicodeOr("█", "#")
|
|
@@ -2058,12 +1617,7 @@ var init_dist4 = __esm(() => {
|
|
|
2058
1617
|
});
|
|
2059
1618
|
|
|
2060
1619
|
// src/init.ts
|
|
2061
|
-
|
|
2062
|
-
__export(exports_init, {
|
|
2063
|
-
init: () => init,
|
|
2064
|
-
REPO_URL: () => REPO_URL
|
|
2065
|
-
});
|
|
2066
|
-
import fs2 from "node:fs";
|
|
1620
|
+
import fs3 from "node:fs";
|
|
2067
1621
|
import os2 from "node:os";
|
|
2068
1622
|
import path2 from "node:path";
|
|
2069
1623
|
import { fileURLToPath } from "node:url";
|
|
@@ -2101,13 +1655,13 @@ async function init() {
|
|
|
2101
1655
|
const s = spinner();
|
|
2102
1656
|
s.start("Checking the key against api.typesafe.ai");
|
|
2103
1657
|
try {
|
|
2104
|
-
const
|
|
2105
|
-
if (
|
|
2106
|
-
s.stop(`Key accepted (${
|
|
1658
|
+
const r = await verifyApiKey(typed);
|
|
1659
|
+
if (r.ok) {
|
|
1660
|
+
s.stop(`Key accepted (${r.model ?? "jev"})`);
|
|
2107
1661
|
apiKey = typed;
|
|
2108
|
-
model =
|
|
1662
|
+
model = r.model;
|
|
2109
1663
|
} else {
|
|
2110
|
-
s.stop(`Rejected with HTTP ${
|
|
1664
|
+
s.stop(`Rejected with HTTP ${r.status}`, 1);
|
|
2111
1665
|
}
|
|
2112
1666
|
} catch (e) {
|
|
2113
1667
|
s.stop(`Could not reach the API: ${e.message}`, 1);
|
|
@@ -2130,10 +1684,10 @@ async function init() {
|
|
|
2130
1684
|
if (where === "global")
|
|
2131
1685
|
log.success(`Saved to ${saveApiKey(apiKey)} (mode 600)`);
|
|
2132
1686
|
else if (where === "project") {
|
|
2133
|
-
|
|
1687
|
+
fs3.appendFileSync(".env", `TYPESAFE_API_KEY=${apiKey}
|
|
2134
1688
|
`);
|
|
2135
1689
|
log.success("Appended to ./.env");
|
|
2136
|
-
if (!
|
|
1690
|
+
if (!fs3.existsSync(".gitignore") || !fs3.readFileSync(".gitignore", "utf8").split(`
|
|
2137
1691
|
`).includes(".env")) {
|
|
2138
1692
|
log.warn(".env is not in .gitignore");
|
|
2139
1693
|
}
|
|
@@ -2143,8 +1697,8 @@ async function init() {
|
|
|
2143
1697
|
const agents = [
|
|
2144
1698
|
{ value: "claude", label: "Claude Code", hint: "~/.claude/skills/jgrep" },
|
|
2145
1699
|
{ value: "codex", label: "Codex", hint: "~/.codex/skills/jgrep" }
|
|
2146
|
-
].filter((
|
|
2147
|
-
if (agents.length &&
|
|
1700
|
+
].filter((a) => fs3.existsSync(path2.join(os2.homedir(), `.${a.value}`)));
|
|
1701
|
+
if (agents.length && fs3.existsSync(SKILL_SRC)) {
|
|
2148
1702
|
const picked = guard(await multiselect({
|
|
2149
1703
|
message: "Teach your coding agents to use jgrep? (space to toggle, enter to continue)",
|
|
2150
1704
|
options: agents,
|
|
@@ -2177,12 +1731,159 @@ var init_init = __esm(() => {
|
|
|
2177
1731
|
|
|
2178
1732
|
// src/cli.ts
|
|
2179
1733
|
init_jgrep();
|
|
2180
|
-
|
|
1734
|
+
import fs4 from "node:fs";
|
|
1735
|
+
|
|
1736
|
+
// src/rows.ts
|
|
1737
|
+
init_jgrep();
|
|
1738
|
+
import fs2 from "node:fs";
|
|
1739
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1740
|
+
function parseCsv(text) {
|
|
1741
|
+
const recs = [];
|
|
1742
|
+
let rec = [], field = "", q = false;
|
|
1743
|
+
for (let i = 0;i < text.length; i++) {
|
|
1744
|
+
const c = text[i];
|
|
1745
|
+
if (q) {
|
|
1746
|
+
if (c === '"') {
|
|
1747
|
+
if (text[i + 1] === '"') {
|
|
1748
|
+
field += '"';
|
|
1749
|
+
i++;
|
|
1750
|
+
} else
|
|
1751
|
+
q = false;
|
|
1752
|
+
} else
|
|
1753
|
+
field += c;
|
|
1754
|
+
} else if (c === '"')
|
|
1755
|
+
q = true;
|
|
1756
|
+
else if (c === ",") {
|
|
1757
|
+
rec.push(field);
|
|
1758
|
+
field = "";
|
|
1759
|
+
} else if (c === `
|
|
1760
|
+
` || c === "\r") {
|
|
1761
|
+
if (c === "\r" && text[i + 1] === `
|
|
1762
|
+
`)
|
|
1763
|
+
i++;
|
|
1764
|
+
rec.push(field);
|
|
1765
|
+
field = "";
|
|
1766
|
+
recs.push(rec);
|
|
1767
|
+
rec = [];
|
|
1768
|
+
} else
|
|
1769
|
+
field += c;
|
|
1770
|
+
}
|
|
1771
|
+
if (field !== "" || rec.length) {
|
|
1772
|
+
rec.push(field);
|
|
1773
|
+
recs.push(rec);
|
|
1774
|
+
}
|
|
1775
|
+
const [columns = [], ...body] = recs.filter((r) => r.some((f) => f !== ""));
|
|
1776
|
+
const rows = body.map((r) => Object.fromEntries(columns.map((c, i) => [c, r[i] ?? ""])));
|
|
1777
|
+
return { columns, rows };
|
|
1778
|
+
}
|
|
1779
|
+
function readRows(file) {
|
|
1780
|
+
const text = fs2.readFileSync(file, "utf8");
|
|
1781
|
+
if (/\.jsonl?$/i.test(file)) {
|
|
1782
|
+
const rows = file.toLowerCase().endsWith(".json") ? JSON.parse(text) : text.split(`
|
|
1783
|
+
`).filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
1784
|
+
const columns = [...new Set(rows.flatMap((r) => Object.keys(r)))];
|
|
1785
|
+
return { columns, rows };
|
|
1786
|
+
}
|
|
1787
|
+
return parseCsv(text);
|
|
1788
|
+
}
|
|
1789
|
+
function loadQuestions(fileOrText) {
|
|
1790
|
+
if (fs2.existsSync(fileOrText)) {
|
|
1791
|
+
const q = JSON.parse(fs2.readFileSync(fileOrText, "utf8"));
|
|
1792
|
+
for (const [name, spec] of Object.entries(q)) {
|
|
1793
|
+
if (!spec || !["noul", "choice", "score"].includes(spec.type) || typeof spec.instructions !== "string")
|
|
1794
|
+
throw new Error(`question "${name}" needs {type: noul|choice|score, instructions: "..."}`);
|
|
1795
|
+
if (name.includes("."))
|
|
1796
|
+
throw new Error(`question name "${name}" must not contain "."`);
|
|
1797
|
+
}
|
|
1798
|
+
return q;
|
|
1799
|
+
}
|
|
1800
|
+
return { match: { type: "noul", instructions: fileOrText } };
|
|
1801
|
+
}
|
|
1802
|
+
var MAX_QUESTIONS_PER_REQUEST = 64;
|
|
1803
|
+
function buildRowsRequest(rows, questions) {
|
|
1804
|
+
const state = { rows: rows.map((r, i) => ({ id: `r${i}`, ...r })) };
|
|
1805
|
+
const qs = {};
|
|
1806
|
+
rows.forEach((_, i) => {
|
|
1807
|
+
for (const [name, spec] of Object.entries(questions)) {
|
|
1808
|
+
qs[`r${i}.${name}`] = { ...spec, instructions: `Look only at the row with id "r${i}". ${spec.instructions}` };
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
return { model: MODEL, state, questions: qs };
|
|
1812
|
+
}
|
|
1813
|
+
var key2 = (qJson, r) => createHash2("sha1").update(`${MODEL}\x00rows\x00${qJson}\x00${JSON.stringify(r)}`).digest("hex");
|
|
1814
|
+
async function scoreRows(rows, questions, o) {
|
|
1815
|
+
const qJson = JSON.stringify(questions);
|
|
1816
|
+
const cache = o.cache ?? {};
|
|
1817
|
+
const f = o.fetchImpl ?? fetch;
|
|
1818
|
+
const answers = new Array(rows.length);
|
|
1819
|
+
const todo = [];
|
|
1820
|
+
rows.forEach((r, i) => {
|
|
1821
|
+
const hit = cache[key2(qJson, r)];
|
|
1822
|
+
if (hit)
|
|
1823
|
+
answers[i] = hit;
|
|
1824
|
+
else
|
|
1825
|
+
todo.push(i);
|
|
1826
|
+
});
|
|
1827
|
+
const per = Math.max(1, Math.min(o.batch, Math.floor(MAX_QUESTIONS_PER_REQUEST / Object.keys(questions).length)));
|
|
1828
|
+
const batches = [];
|
|
1829
|
+
for (let i = 0;i < todo.length; i += per)
|
|
1830
|
+
batches.push(todo.slice(i, i + per));
|
|
1831
|
+
let tokens = 0, done = 0, next = 0;
|
|
1832
|
+
const worker = async () => {
|
|
1833
|
+
while (next < batches.length) {
|
|
1834
|
+
const b = batches[next++];
|
|
1835
|
+
const res = await postSystemOne(buildRowsRequest(b.map((i) => rows[i]), questions), o.apiKey, f);
|
|
1836
|
+
tokens += res.usage?.input_tokens ?? 0;
|
|
1837
|
+
b.forEach((ri, j) => {
|
|
1838
|
+
const a = {};
|
|
1839
|
+
for (const name of Object.keys(questions))
|
|
1840
|
+
a[name] = res.answers[`r${j}.${name}`] ?? { type: "missing" };
|
|
1841
|
+
answers[ri] = a;
|
|
1842
|
+
if (Object.values(a).every((x) => x.type !== "missing"))
|
|
1843
|
+
cache[key2(qJson, rows[ri])] = a;
|
|
1844
|
+
});
|
|
1845
|
+
o.onProgress?.(++done, batches.length);
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
await Promise.all(Array.from({ length: Math.min(o.concurrency, batches.length) }, worker));
|
|
1849
|
+
return { answers, tokens, cached: rows.length - todo.length, requests: batches.length };
|
|
1850
|
+
}
|
|
1851
|
+
function flatten(a) {
|
|
1852
|
+
const out = {};
|
|
1853
|
+
for (const [name, ans] of Object.entries(a)) {
|
|
1854
|
+
if (ans.type === "noul")
|
|
1855
|
+
out[name] = round(ans.noul);
|
|
1856
|
+
else if (ans.type === "choice") {
|
|
1857
|
+
out[name] = ans.choice ?? "";
|
|
1858
|
+
out[`${name}_p`] = round(ans.probabilities?.[ans.choice ?? ""]);
|
|
1859
|
+
} else if (ans.type === "score") {
|
|
1860
|
+
out[name] = round(ans.score);
|
|
1861
|
+
out[`${name}_conf`] = round(ans.confidence);
|
|
1862
|
+
} else
|
|
1863
|
+
out[name] = "";
|
|
1864
|
+
}
|
|
1865
|
+
return out;
|
|
1866
|
+
}
|
|
1867
|
+
var round = (n) => typeof n === "number" ? Math.round(n * 100) / 100 : "";
|
|
1868
|
+
function toCsv(columns, rows) {
|
|
1869
|
+
const esc = (v) => {
|
|
1870
|
+
const s = v == null ? "" : String(v);
|
|
1871
|
+
return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
1872
|
+
};
|
|
1873
|
+
return [columns.map(esc).join(","), ...rows.map((r) => columns.map((c) => esc(r[c])).join(","))].join(`
|
|
1874
|
+
`) + `
|
|
1875
|
+
`;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// src/cli.ts
|
|
1879
|
+
var VERSION = "0.3.0";
|
|
2181
1880
|
var USAGE = `jgrep ${VERSION} — semantic grep powered by Jev (TypeSafe)
|
|
2182
1881
|
|
|
2183
1882
|
usage: jgrep init interactive setup (API key, agent skills)
|
|
2184
1883
|
jgrep [options] "<description>" [path ...]
|
|
2185
1884
|
jgrep [options] --diff [ref] "<description>"
|
|
1885
|
+
jgrep [options] --rows <file.csv|.jsonl> "<description>"
|
|
1886
|
+
jgrep [options] --rows <file> --questions <q.json> [--out scored.csv]
|
|
2186
1887
|
|
|
2187
1888
|
-t, --threshold <p> print chunks with probability >= p (default 0.7)
|
|
2188
1889
|
-C, --show print the matching chunk body under each hit
|
|
@@ -2191,6 +1892,10 @@ usage: jgrep init interactive setup (API key, agent skills
|
|
|
2191
1892
|
--diff [ref] grep git diff hunks instead of files
|
|
2192
1893
|
(working tree by default, or against <ref>)
|
|
2193
1894
|
--staged with --diff: staged changes only
|
|
1895
|
+
--rows <file> grep rows of a CSV / JSONL file instead of code
|
|
1896
|
+
--questions <f> with --rows: JSON of Jev questions (noul/choice/score)
|
|
1897
|
+
asked of every row; prints the table with answer columns
|
|
1898
|
+
--out <file> with --questions: write the CSV here instead of stdout
|
|
2194
1899
|
-b, --batch <n> chunks per request (default 16)
|
|
2195
1900
|
-c, --concurrency <n> parallel requests (default 16)
|
|
2196
1901
|
--no-cache ignore and do not write ~/.cache/jgrep
|
|
@@ -2201,107 +1906,173 @@ CI lint: ! jgrep --diff origin/main "adds an endpoint without an auth check"
|
|
|
2201
1906
|
|
|
2202
1907
|
examples:
|
|
2203
1908
|
jgrep "catches an error and silently ignores it" src/
|
|
1909
|
+
jgrep --rows creators.csv "beauty is the main content of this account"
|
|
1910
|
+
jgrep --rows creators.csv --questions beauty.json --out scored.csv
|
|
2204
1911
|
jgrep -C "reads user input without validating it" app/
|
|
2205
1912
|
jgrep --diff --staged "changes billing logic without touching tests"`;
|
|
2206
1913
|
var tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
2207
|
-
var
|
|
1914
|
+
var c2 = (code, s) => tty ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
2208
1915
|
function parse(argv) {
|
|
2209
|
-
const
|
|
1916
|
+
const o = { threshold: 0.7, batch: 16, concurrency: 16, all: false, show: false, json: false, cache: true, diff: null, rows: "", questions: "", out: "" };
|
|
2210
1917
|
const rest = [];
|
|
2211
|
-
const positionalsAfter = (
|
|
2212
|
-
for (let
|
|
2213
|
-
const
|
|
2214
|
-
if (
|
|
2215
|
-
|
|
2216
|
-
else if (
|
|
2217
|
-
|
|
2218
|
-
else if (
|
|
2219
|
-
|
|
2220
|
-
else if (
|
|
2221
|
-
|
|
2222
|
-
else if (
|
|
2223
|
-
|
|
2224
|
-
else if (
|
|
2225
|
-
|
|
2226
|
-
else if (
|
|
2227
|
-
|
|
2228
|
-
else if (
|
|
2229
|
-
(
|
|
2230
|
-
else if (
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
1918
|
+
const positionalsAfter = (i) => argv.slice(i + 1).filter((x) => !x.startsWith("-")).length;
|
|
1919
|
+
for (let i = 0;i < argv.length; i++) {
|
|
1920
|
+
const a = argv[i];
|
|
1921
|
+
if (a === "-t" || a === "--threshold")
|
|
1922
|
+
o.threshold = Number(argv[++i]);
|
|
1923
|
+
else if (a === "-b" || a === "--batch")
|
|
1924
|
+
o.batch = Number(argv[++i]);
|
|
1925
|
+
else if (a === "-c" || a === "--concurrency")
|
|
1926
|
+
o.concurrency = Number(argv[++i]);
|
|
1927
|
+
else if (a === "-a" || a === "--all")
|
|
1928
|
+
o.all = true;
|
|
1929
|
+
else if (a === "-C" || a === "--show")
|
|
1930
|
+
o.show = true;
|
|
1931
|
+
else if (a === "--json")
|
|
1932
|
+
o.json = true;
|
|
1933
|
+
else if (a === "--no-cache")
|
|
1934
|
+
o.cache = false;
|
|
1935
|
+
else if (a === "--staged")
|
|
1936
|
+
(o.diff ??= []).push("--staged");
|
|
1937
|
+
else if (a === "--rows")
|
|
1938
|
+
o.rows = argv[++i] ?? "";
|
|
1939
|
+
else if (a === "--questions")
|
|
1940
|
+
o.questions = argv[++i] ?? "";
|
|
1941
|
+
else if (a === "--out")
|
|
1942
|
+
o.out = argv[++i] ?? "";
|
|
1943
|
+
else if (a === "--diff") {
|
|
1944
|
+
o.diff ??= [];
|
|
1945
|
+
const next = argv[i + 1];
|
|
1946
|
+
if (next && !next.startsWith("-") && (rest.length > 0 || positionalsAfter(i + 1) > 0))
|
|
1947
|
+
o.diff.push(argv[++i]);
|
|
1948
|
+
} else if (a === "-h" || a === "--help") {
|
|
2236
1949
|
console.log(USAGE);
|
|
2237
1950
|
process.exit(0);
|
|
2238
|
-
} else if (
|
|
1951
|
+
} else if (a === "-V" || a === "-v" || a === "--version") {
|
|
2239
1952
|
console.log(VERSION);
|
|
2240
1953
|
process.exit(0);
|
|
2241
|
-
} else if (
|
|
2242
|
-
throw new Error(`unknown option ${
|
|
1954
|
+
} else if (a.startsWith("-") && a !== "-")
|
|
1955
|
+
throw new Error(`unknown option ${a} (try --help)`);
|
|
2243
1956
|
else
|
|
2244
|
-
rest.push(
|
|
1957
|
+
rest.push(a);
|
|
2245
1958
|
}
|
|
2246
|
-
if (![
|
|
1959
|
+
if (![o.threshold, o.batch, o.concurrency].every((n) => Number.isFinite(n) && n >= 0))
|
|
2247
1960
|
throw new Error("numeric option expected");
|
|
2248
|
-
return { ...
|
|
1961
|
+
return { ...o, question: rest[0], paths: rest.slice(1) };
|
|
2249
1962
|
}
|
|
2250
1963
|
async function main() {
|
|
2251
1964
|
if (process.argv[2] === "init") {
|
|
2252
|
-
|
|
2253
|
-
return
|
|
1965
|
+
await Promise.resolve().then(() => init_init());
|
|
1966
|
+
return init();
|
|
2254
1967
|
}
|
|
2255
|
-
const
|
|
2256
|
-
if (
|
|
1968
|
+
const o = parse(process.argv.slice(2));
|
|
1969
|
+
if (o.rows)
|
|
1970
|
+
return rowsMain(o);
|
|
1971
|
+
if (!o.question) {
|
|
2257
1972
|
console.error(USAGE);
|
|
2258
1973
|
process.exit(2);
|
|
2259
1974
|
}
|
|
2260
1975
|
const t0 = Date.now();
|
|
2261
|
-
const kind =
|
|
2262
|
-
const chunks =
|
|
1976
|
+
const kind = o.diff ? "diff" : "code";
|
|
1977
|
+
const chunks = o.diff ? diffChunks(gitDiff(o.diff)) : chunkPaths(o.paths.length ? o.paths : ["."]);
|
|
2263
1978
|
if (!chunks.length) {
|
|
2264
|
-
console.error(
|
|
1979
|
+
console.error(o.diff ? "empty diff" : "no text files found");
|
|
2265
1980
|
process.exit(1);
|
|
2266
1981
|
}
|
|
2267
|
-
const cache =
|
|
2268
|
-
const
|
|
2269
|
-
...
|
|
1982
|
+
const cache = o.cache ? loadCache() : {};
|
|
1983
|
+
const r = await jgrep(o.question, chunks, {
|
|
1984
|
+
...o,
|
|
2270
1985
|
kind,
|
|
2271
1986
|
apiKey: resolveApiKey(),
|
|
2272
1987
|
cache,
|
|
2273
|
-
onProgress: (d,
|
|
1988
|
+
onProgress: (d, n) => {
|
|
2274
1989
|
if (process.stderr.isTTY)
|
|
2275
|
-
process.stderr.write(`\r${d}/${
|
|
1990
|
+
process.stderr.write(`\r${d}/${n} requests`);
|
|
2276
1991
|
}
|
|
2277
1992
|
});
|
|
2278
|
-
if (
|
|
1993
|
+
if (o.cache)
|
|
2279
1994
|
saveCache(cache);
|
|
2280
1995
|
if (process.stderr.isTTY)
|
|
2281
1996
|
process.stderr.write("\r\x1B[K");
|
|
2282
|
-
const rows =
|
|
2283
|
-
if (
|
|
2284
|
-
console.log(JSON.stringify(rows.map((
|
|
1997
|
+
const rows = o.all ? [...r.all].sort((a, b) => b.p - a.p) : r.hits;
|
|
1998
|
+
if (o.json) {
|
|
1999
|
+
console.log(JSON.stringify(rows.map((h) => ({ file: h.file, start: h.start, end: h.end, p: h.p, text: h.text })), null, 2));
|
|
2285
2000
|
} else {
|
|
2286
|
-
for (const
|
|
2287
|
-
const head =
|
|
2288
|
-
`).find((
|
|
2289
|
-
const pcol =
|
|
2290
|
-
console.log(`${
|
|
2291
|
-
if (
|
|
2292
|
-
console.log(
|
|
2293
|
-
`).map((
|
|
2001
|
+
for (const h of rows) {
|
|
2002
|
+
const head = h.text.split(`
|
|
2003
|
+
`).find((l) => l.trim() && !l.startsWith("@@"))?.trim().slice(0, 90) ?? "";
|
|
2004
|
+
const pcol = h.p >= o.threshold ? "32" : "90";
|
|
2005
|
+
console.log(`${c2("35", h.file)}${c2("36", ":")}${c2("32", `${h.start}-${h.end}`)} ${c2(pcol, `p=${h.p.toFixed(2)}`)} ${head}`);
|
|
2006
|
+
if (o.show)
|
|
2007
|
+
console.log(h.text.split(`
|
|
2008
|
+
`).map((l) => " " + l).join(`
|
|
2294
2009
|
`) + `
|
|
2295
2010
|
`);
|
|
2296
2011
|
}
|
|
2297
2012
|
}
|
|
2298
|
-
const cost =
|
|
2299
|
-
console.error(
|
|
2300
|
-
process.exit(
|
|
2013
|
+
const cost = r.tokens * USD_PER_M_INPUT / 1e6;
|
|
2014
|
+
console.error(c2("90", `${r.hits.length} hits / ${r.chunks} chunks (${r.cached} cached) · ${r.tokens} tokens · $${cost.toFixed(4)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`));
|
|
2015
|
+
process.exit(r.hits.length ? 0 : 1);
|
|
2016
|
+
}
|
|
2017
|
+
async function rowsMain(o) {
|
|
2018
|
+
if (!o.questions && !o.question) {
|
|
2019
|
+
console.error(USAGE);
|
|
2020
|
+
process.exit(2);
|
|
2021
|
+
}
|
|
2022
|
+
const t0 = Date.now();
|
|
2023
|
+
const { columns, rows } = readRows(o.rows);
|
|
2024
|
+
if (!rows.length) {
|
|
2025
|
+
console.error("no rows");
|
|
2026
|
+
process.exit(1);
|
|
2027
|
+
}
|
|
2028
|
+
const questions = loadQuestions(o.questions || o.question);
|
|
2029
|
+
const cache = o.cache ? loadCache() : {};
|
|
2030
|
+
const r = await scoreRows(rows, questions, {
|
|
2031
|
+
...o,
|
|
2032
|
+
apiKey: resolveApiKey(),
|
|
2033
|
+
cache,
|
|
2034
|
+
onProgress: (d, n) => {
|
|
2035
|
+
if (process.stderr.isTTY)
|
|
2036
|
+
process.stderr.write(`\r${d}/${n} requests`);
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
if (o.cache)
|
|
2040
|
+
saveCache(cache);
|
|
2041
|
+
if (process.stderr.isTTY)
|
|
2042
|
+
process.stderr.write("\r\x1B[K");
|
|
2043
|
+
const flat = r.answers.map(flatten);
|
|
2044
|
+
let hits = rows.length;
|
|
2045
|
+
if (o.questions) {
|
|
2046
|
+
const qCols = [...new Set(flat.flatMap((f) => Object.keys(f)))];
|
|
2047
|
+
const table = rows.map((row, i) => ({ ...row, ...flat[i] }));
|
|
2048
|
+
if (o.json)
|
|
2049
|
+
console.log(JSON.stringify(table, null, 2));
|
|
2050
|
+
else if (o.out)
|
|
2051
|
+
fs4.writeFileSync(o.out, toCsv([...columns, ...qCols], table));
|
|
2052
|
+
else
|
|
2053
|
+
process.stdout.write(toCsv([...columns, ...qCols], table));
|
|
2054
|
+
} else {
|
|
2055
|
+
const scored = rows.map((row, i) => ({ row, i, p: Number(flat[i].match) }));
|
|
2056
|
+
const shown = o.all ? [...scored].sort((a, b) => b.p - a.p) : scored.filter((s) => s.p >= o.threshold);
|
|
2057
|
+
hits = scored.filter((s) => s.p >= o.threshold).length;
|
|
2058
|
+
if (o.json)
|
|
2059
|
+
console.log(JSON.stringify(shown.map((s) => ({ row: s.i + 2, p: s.p, ...s.row })), null, 2));
|
|
2060
|
+
else
|
|
2061
|
+
for (const s of shown) {
|
|
2062
|
+
const preview = Object.values(s.row).filter(Boolean).join(" | ").slice(0, 90);
|
|
2063
|
+
const pcol = s.p >= o.threshold ? "32" : "90";
|
|
2064
|
+
console.log(`${c2("35", o.rows)}${c2("36", ":")}${c2("32", String(s.i + 2))} ${c2(pcol, `p=${s.p.toFixed(2)}`)} ${preview}`);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
const cost = r.tokens * USD_PER_M_INPUT / 1e6;
|
|
2068
|
+
console.error(c2("90", `${o.questions ? Object.keys(questions).length + " questions x " : hits + " hits / "}${rows.length} rows (${r.cached} cached) · ${r.requests} requests · ${r.tokens} tokens · $${cost.toFixed(4)} · ${((Date.now() - t0) / 1000).toFixed(1)}s`));
|
|
2069
|
+
if (o.out && !o.json)
|
|
2070
|
+
console.error(c2("90", `wrote ${o.out}`));
|
|
2071
|
+
process.exit(o.questions || hits ? 0 : 1);
|
|
2301
2072
|
}
|
|
2302
2073
|
if (!process.env.JGREP_NO_MAIN)
|
|
2303
2074
|
main().catch((e) => {
|
|
2304
|
-
console.error(
|
|
2075
|
+
console.error(c2("31", e.message));
|
|
2305
2076
|
process.exit(2);
|
|
2306
2077
|
});
|
|
2307
2078
|
export {
|