bfi-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bfi.mjs +13 -0
- package/dist/THIRD-PARTY-LICENSES.md +293 -0
- package/dist/_chunks/agents.mjs +65 -0
- package/dist/_chunks/libs/@clack/core.mjs +758 -0
- package/dist/_chunks/libs/@clack/prompts.mjs +539 -0
- package/dist/_chunks/libs/@kwsites/file-exists.mjs +562 -0
- package/dist/_chunks/libs/@kwsites/promise-deferred.mjs +37 -0
- package/dist/_chunks/libs/@simple-git/args-pathspec.mjs +12 -0
- package/dist/_chunks/libs/@simple-git/argv-parser.mjs +471 -0
- package/dist/_chunks/libs/picocolors.mjs +70 -0
- package/dist/_chunks/libs/simple-git.mjs +3615 -0
- package/dist/_chunks/libs/xdg-basedir.mjs +14 -0
- package/dist/_chunks/rolldown-runtime.mjs +33 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +8320 -0
- package/package.json +52 -0
- package/skills/gbfi-skill/SKILL.md +176 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { a, block, fastStringWidth, getColumns, getRows, n$1, r, require_src, settings, u$2, wrapAnsi, wrapTextWithPrefix } from "./core.mjs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import process$1 from "node:process";
|
|
4
|
+
var import_src = require_src();
|
|
5
|
+
function isUnicodeSupported() {
|
|
6
|
+
if (process$1.platform !== "win32") return process$1.env.TERM !== "linux";
|
|
7
|
+
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";
|
|
8
|
+
}
|
|
9
|
+
const unicode = isUnicodeSupported();
|
|
10
|
+
const isCI = () => process.env.CI === "true";
|
|
11
|
+
const unicodeOr = (o, e) => unicode ? o : e;
|
|
12
|
+
const S_STEP_ACTIVE = unicodeOr("◆", "*");
|
|
13
|
+
const S_STEP_CANCEL = unicodeOr("■", "x");
|
|
14
|
+
const S_STEP_ERROR = unicodeOr("▲", "x");
|
|
15
|
+
const S_STEP_SUBMIT = unicodeOr("◇", "o");
|
|
16
|
+
const S_BAR_START = unicodeOr("┌", "T");
|
|
17
|
+
const S_BAR = unicodeOr("│", "|");
|
|
18
|
+
const S_BAR_END = unicodeOr("└", "—");
|
|
19
|
+
const S_RADIO_ACTIVE = unicodeOr("●", ">");
|
|
20
|
+
const S_RADIO_INACTIVE = unicodeOr("○", " ");
|
|
21
|
+
const S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
|
|
22
|
+
const S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
|
|
23
|
+
const S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
|
|
24
|
+
const S_BAR_H = unicodeOr("─", "-");
|
|
25
|
+
const S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
|
|
26
|
+
const S_CONNECT_LEFT = unicodeOr("├", "+");
|
|
27
|
+
const S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
|
|
28
|
+
const S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
|
|
29
|
+
const S_INFO = unicodeOr("●", "•");
|
|
30
|
+
const S_SUCCESS = unicodeOr("◆", "*");
|
|
31
|
+
const S_WARN = unicodeOr("▲", "!");
|
|
32
|
+
const S_ERROR = unicodeOr("■", "x");
|
|
33
|
+
const symbol = (o) => {
|
|
34
|
+
switch (o) {
|
|
35
|
+
case "initial":
|
|
36
|
+
case "active": return styleText("cyan", S_STEP_ACTIVE);
|
|
37
|
+
case "cancel": return styleText("red", S_STEP_CANCEL);
|
|
38
|
+
case "error": return styleText("yellow", S_STEP_ERROR);
|
|
39
|
+
case "submit": return styleText("green", S_STEP_SUBMIT);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const symbolBar = (o) => {
|
|
43
|
+
switch (o) {
|
|
44
|
+
case "initial":
|
|
45
|
+
case "active": return styleText("cyan", S_BAR);
|
|
46
|
+
case "cancel": return styleText("red", S_BAR);
|
|
47
|
+
case "error": return styleText("yellow", S_BAR);
|
|
48
|
+
case "submit": return styleText("green", S_BAR);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function formatInstructionFooter(o, e) {
|
|
52
|
+
const r = [`${e ? `${styleText("cyan", S_BAR)} ` : ""}${o.join(" • ")}`];
|
|
53
|
+
return e && r.push(styleText("cyan", S_BAR_END)), r;
|
|
54
|
+
}
|
|
55
|
+
const I = (l, e, w, p, b, C = false) => {
|
|
56
|
+
let r = e, O = 0;
|
|
57
|
+
if (C) for (let i = p - 1; i >= w; i--) {
|
|
58
|
+
const m = l[i];
|
|
59
|
+
if (m && (r -= m.length), O++, r <= b) break;
|
|
60
|
+
}
|
|
61
|
+
else for (let i = w; i < p; i++) {
|
|
62
|
+
const m = l[i];
|
|
63
|
+
if (m && (r -= m.length), O++, r <= b) break;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
lineCount: r,
|
|
67
|
+
removals: O
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const limitOptions = ({ cursor: l, options: e, style: w, output: p = process.stdout, maxItems: b = Number.POSITIVE_INFINITY, columnPadding: C = 0, rowPadding: r = 4 }) => {
|
|
71
|
+
const i = getColumns(p) - C, m = getRows(p), M = styleText("dim", "..."), v = Math.max(m - r, 0), a = Math.max(Math.min(b, v), 5);
|
|
72
|
+
let f = 0;
|
|
73
|
+
l >= a - 3 && (f = Math.max(Math.min(l - a + 3, e.length - a), 0));
|
|
74
|
+
let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
|
|
75
|
+
const W = Math.min(f + a, e.length), s = [];
|
|
76
|
+
let g = 0;
|
|
77
|
+
d && g++, c && g++;
|
|
78
|
+
const T = f + (d ? 1 : 0), y = W - (c ? 1 : 0);
|
|
79
|
+
for (let t = T; t < y; t++) {
|
|
80
|
+
const n = e[t], h = wrapAnsi(n ? w(n, t === l) : "", i, {
|
|
81
|
+
hard: true,
|
|
82
|
+
trim: false
|
|
83
|
+
}).split(`
|
|
84
|
+
`);
|
|
85
|
+
s.push(h), g += h.length;
|
|
86
|
+
}
|
|
87
|
+
if (g > v) {
|
|
88
|
+
let t = 0, n = 0, o = g;
|
|
89
|
+
const h = l - T;
|
|
90
|
+
let u = v;
|
|
91
|
+
const L = () => I(s, o, 0, h, u), E = () => I(s, o, h + 1, s.length, u, true);
|
|
92
|
+
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));
|
|
93
|
+
}
|
|
94
|
+
const x = [];
|
|
95
|
+
d && x.push(M);
|
|
96
|
+
for (const t of s) for (const n of t) x.push(n);
|
|
97
|
+
return c && x.push(M), x;
|
|
98
|
+
};
|
|
99
|
+
const confirm = (i) => {
|
|
100
|
+
const a = i.active ?? "Yes", s = i.inactive ?? "No";
|
|
101
|
+
return new r({
|
|
102
|
+
active: a,
|
|
103
|
+
inactive: s,
|
|
104
|
+
signal: i.signal,
|
|
105
|
+
input: i.input,
|
|
106
|
+
output: i.output,
|
|
107
|
+
initialValue: i.initialValue ?? true,
|
|
108
|
+
render() {
|
|
109
|
+
const e = i.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = e ? `${styleText("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(i.output, i.message, l, u), o = `${e ? `${styleText("gray", S_BAR)}
|
|
110
|
+
` : ""}${f}
|
|
111
|
+
`, c = this.value ? a : s;
|
|
112
|
+
switch (this.state) {
|
|
113
|
+
case "submit": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${styleText("dim", c)}`;
|
|
114
|
+
case "cancel": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${styleText(["strikethrough", "dim"], c)}${e ? `
|
|
115
|
+
${styleText("gray", S_BAR)}` : ""}`;
|
|
116
|
+
default: {
|
|
117
|
+
const r = e ? `${styleText("cyan", S_BAR)} ` : "", g = e ? styleText("cyan", S_BAR_END) : "";
|
|
118
|
+
return `${o}${r}${this.value ? `${styleText("green", S_RADIO_ACTIVE)} ${a}` : `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`}${i.vertical ? e ? `
|
|
119
|
+
${styleText("cyan", S_BAR)} ` : `
|
|
120
|
+
` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", s)}` : `${styleText("green", S_RADIO_ACTIVE)} ${s}`}
|
|
121
|
+
${g}
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}).prompt();
|
|
127
|
+
};
|
|
128
|
+
const MULTISELECT_INSTRUCTIONS = [
|
|
129
|
+
`${styleText("dim", "↑/↓")} to navigate`,
|
|
130
|
+
`${styleText("dim", "Space:")} select`,
|
|
131
|
+
`${styleText("dim", "Enter:")} confirm`
|
|
132
|
+
];
|
|
133
|
+
const m = (i, u) => i.split(`
|
|
134
|
+
`).map((d) => u(d)).join(`
|
|
135
|
+
`);
|
|
136
|
+
const multiselect = (i) => {
|
|
137
|
+
const u = (t, a) => {
|
|
138
|
+
const r = t.label ?? String(t.value);
|
|
139
|
+
return a === "disabled" ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText(["strikethrough", "gray"], o))}${t.hint ? ` ${styleText("dim", `(${t.hint ?? "disabled"})`)}` : ""}` : a === "active" ? `${styleText("cyan", S_CHECKBOX_ACTIVE)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${m(r, (o) => styleText("dim", o))}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "cancelled" ? `${m(r, (o) => styleText(["strikethrough", "dim"], o))}` : a === "active-selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "submitted" ? `${m(r, (o) => styleText("dim", o))}` : `${styleText("dim", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText("dim", o))}`;
|
|
140
|
+
}, d = i.required ?? true, v = i.showInstructions ?? true;
|
|
141
|
+
return new a({
|
|
142
|
+
options: i.options,
|
|
143
|
+
signal: i.signal,
|
|
144
|
+
input: i.input,
|
|
145
|
+
output: i.output,
|
|
146
|
+
initialValues: i.initialValues,
|
|
147
|
+
required: d,
|
|
148
|
+
cursorAt: i.cursorAt,
|
|
149
|
+
validate(t) {
|
|
150
|
+
if (d && (t === void 0 || t.length === 0)) return `Please select at least one option.
|
|
151
|
+
${styleText("reset", styleText("dim", `Press ${styleText([
|
|
152
|
+
"gray",
|
|
153
|
+
"bgWhite",
|
|
154
|
+
"inverse"
|
|
155
|
+
], " space ")} to select, ${styleText("gray", styleText("bgWhite", styleText("inverse", " enter ")))} to submit`))}`;
|
|
156
|
+
},
|
|
157
|
+
render() {
|
|
158
|
+
const t = i.withGuide ?? settings.withGuide, a = wrapTextWithPrefix(i.output, i.message, t ? `${symbolBar(this.state)} ` : "", `${symbol(this.state)} `), r = `${t ? `${styleText("gray", S_BAR)}
|
|
159
|
+
` : ""}${a}
|
|
160
|
+
`, o = this.value ?? [], p = (n, l) => {
|
|
161
|
+
if (n.disabled) return u(n, "disabled");
|
|
162
|
+
const s = o.includes(n.value);
|
|
163
|
+
return l && s ? u(n, "active-selected") : s ? u(n, "selected") : u(n, l ? "active" : "inactive");
|
|
164
|
+
};
|
|
165
|
+
switch (this.state) {
|
|
166
|
+
case "submit": {
|
|
167
|
+
const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none");
|
|
168
|
+
return `${r}${wrapTextWithPrefix(i.output, n, t ? `${styleText("gray", S_BAR)} ` : "")}`;
|
|
169
|
+
}
|
|
170
|
+
case "cancel": {
|
|
171
|
+
const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "cancelled")).join(styleText("dim", ", "));
|
|
172
|
+
if (n.trim() === "") return `${r}${styleText("gray", S_BAR)}`;
|
|
173
|
+
return `${r}${wrapTextWithPrefix(i.output, n, t ? `${styleText("gray", S_BAR)} ` : "")}${t ? `
|
|
174
|
+
${styleText("gray", S_BAR)}` : ""}`;
|
|
175
|
+
}
|
|
176
|
+
case "error": {
|
|
177
|
+
const n = t ? `${styleText("yellow", S_BAR)} ` : "", l = this.error.split(`
|
|
178
|
+
`).map(($, C) => C === 0 ? `${t ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", $)}` : ` ${$}`).join(`
|
|
179
|
+
`), s = r.split(`
|
|
180
|
+
`).length, h = l.split(`
|
|
181
|
+
`).length + 1;
|
|
182
|
+
return `${r}${n}${limitOptions({
|
|
183
|
+
output: i.output,
|
|
184
|
+
options: this.options,
|
|
185
|
+
cursor: this.cursor,
|
|
186
|
+
maxItems: i.maxItems,
|
|
187
|
+
columnPadding: n.length,
|
|
188
|
+
rowPadding: s + h,
|
|
189
|
+
style: p
|
|
190
|
+
}).join(`
|
|
191
|
+
${n}`)}
|
|
192
|
+
${l}
|
|
193
|
+
`;
|
|
194
|
+
}
|
|
195
|
+
default: {
|
|
196
|
+
const n = t ? `${styleText("cyan", S_BAR)} ` : "", l = r.split(`
|
|
197
|
+
`).length, s = v ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t) : t ? [styleText("cyan", S_BAR_END)] : [], h = s.join(`
|
|
198
|
+
`), $ = s.length + 1;
|
|
199
|
+
return `${r}${n}${limitOptions({
|
|
200
|
+
output: i.output,
|
|
201
|
+
options: this.options,
|
|
202
|
+
cursor: this.cursor,
|
|
203
|
+
maxItems: i.maxItems,
|
|
204
|
+
columnPadding: n.length,
|
|
205
|
+
rowPadding: l + $,
|
|
206
|
+
style: p
|
|
207
|
+
}).join(`
|
|
208
|
+
${n}`)}
|
|
209
|
+
${h}
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}).prompt();
|
|
215
|
+
};
|
|
216
|
+
const groupMultiselect = (o) => {
|
|
217
|
+
const { selectableGroups: h = true, groupSpacing: x = 0 } = o, m = (n, l, g = []) => {
|
|
218
|
+
const a = n.label ?? String(n.value), t = typeof n.group == "string", s = t && (g[g.indexOf(n) + 1] ?? { group: true }), u = t && s && s.group === true;
|
|
219
|
+
let r = "", c = "";
|
|
220
|
+
t && (h ? (r = u ? `${S_BAR_END} ` : `${S_BAR} `, c = u ? " " : `${S_BAR} `) : r = " ");
|
|
221
|
+
let i = "";
|
|
222
|
+
if (x > 0 && !t && (i = `
|
|
223
|
+
`.repeat(x)), l === "active") return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${styleText("cyan", S_CHECKBOX_ACTIVE)} `, `${i}${styleText("dim", c)} `);
|
|
224
|
+
if (l === "group-active") return wrapTextWithPrefix(o.output, a, `${i}${r} `, `${i}${r}${styleText("cyan", S_CHECKBOX_ACTIVE)} `, `${i}${c} `, (d) => styleText("dim", d));
|
|
225
|
+
if (l === "group-active-selected") return wrapTextWithPrefix(o.output, a, `${i}${r} `, `${i}${r}${styleText("green", S_CHECKBOX_SELECTED)} `, `${i}${c} `, (d) => styleText("dim", d));
|
|
226
|
+
if (l === "selected") {
|
|
227
|
+
const d = t || h ? styleText("green", S_CHECKBOX_SELECTED) : "";
|
|
228
|
+
return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` (${n.hint})` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${d} `, `${i}${styleText("dim", c)} `, (S) => styleText("dim", S));
|
|
229
|
+
}
|
|
230
|
+
if (l === "cancelled") return `${styleText(["strikethrough", "dim"], a)}`;
|
|
231
|
+
if (l === "active-selected") return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${styleText("green", S_CHECKBOX_SELECTED)} `, `${i}${styleText("dim", c)} `);
|
|
232
|
+
if (l === "submitted") return `${styleText("dim", a)}`;
|
|
233
|
+
const f = t || h ? styleText("dim", S_CHECKBOX_INACTIVE) : "";
|
|
234
|
+
return wrapTextWithPrefix(o.output, a, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${f} `, `${i}${styleText("dim", c)} `, (d) => styleText("dim", d));
|
|
235
|
+
}, y = o.required ?? true, I = o.showInstructions ?? true;
|
|
236
|
+
return new u$2({
|
|
237
|
+
options: o.options,
|
|
238
|
+
signal: o.signal,
|
|
239
|
+
input: o.input,
|
|
240
|
+
output: o.output,
|
|
241
|
+
initialValues: o.initialValues,
|
|
242
|
+
required: y,
|
|
243
|
+
cursorAt: o.cursorAt,
|
|
244
|
+
selectableGroups: h,
|
|
245
|
+
validate(n) {
|
|
246
|
+
if (y && (n === void 0 || n.length === 0)) return `Please select at least one option.
|
|
247
|
+
${styleText("reset", styleText("dim", `Press ${styleText([
|
|
248
|
+
"gray",
|
|
249
|
+
"bgWhite",
|
|
250
|
+
"inverse"
|
|
251
|
+
], " space ")} to select, ${styleText("gray", styleText(["bgWhite", "inverse"], " enter "))} to submit`))}`;
|
|
252
|
+
},
|
|
253
|
+
render() {
|
|
254
|
+
const n = o.withGuide ?? settings.withGuide, l = `${n ? `${styleText("gray", S_BAR)}
|
|
255
|
+
` : ""}${symbol(this.state)} ${o.message}
|
|
256
|
+
`, g = this.value ?? [], a = (t, s) => {
|
|
257
|
+
const u = this.options, r = g.includes(t.value) || t.group === true && this.isGroupSelected(`${t.value}`);
|
|
258
|
+
return !s && typeof t.group == "string" && this.options[this.cursor]?.value === t.group ? m(t, r ? "group-active-selected" : "group-active", u) : s && r ? m(t, "active-selected", u) : r ? m(t, "selected", u) : m(t, s ? "active" : "inactive", u);
|
|
259
|
+
};
|
|
260
|
+
switch (this.state) {
|
|
261
|
+
case "submit": {
|
|
262
|
+
const t = this.options.filter(({ value: u }) => g.includes(u)).map((u) => m(u, "submitted")), s = t.length === 0 ? "" : ` ${t.join(styleText("dim", ", "))}`;
|
|
263
|
+
return `${l}${n ? styleText("gray", S_BAR) : ""}${s}`;
|
|
264
|
+
}
|
|
265
|
+
case "cancel": {
|
|
266
|
+
const t = this.options.filter(({ value: s }) => g.includes(s)).map((s) => m(s, "cancelled")).join(styleText("dim", ", "));
|
|
267
|
+
return `${l}${n ? `${styleText("gray", S_BAR)} ` : ""}${t.trim() ? `${t}${n ? `
|
|
268
|
+
${styleText("gray", S_BAR)}` : ""}` : ""}`;
|
|
269
|
+
}
|
|
270
|
+
case "error": {
|
|
271
|
+
const t = n ? `${styleText("yellow", S_BAR)} ` : "", s = this.error.split(`
|
|
272
|
+
`).map((i, f) => f === 0 ? `${n ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", i)}` : ` ${i}`).join(`
|
|
273
|
+
`), u = l.split(`
|
|
274
|
+
`).length, r = s.split(`
|
|
275
|
+
`).length + 1;
|
|
276
|
+
return `${l}${t}${limitOptions({
|
|
277
|
+
output: o.output,
|
|
278
|
+
options: this.options,
|
|
279
|
+
cursor: this.cursor,
|
|
280
|
+
maxItems: o.maxItems,
|
|
281
|
+
columnPadding: t.length,
|
|
282
|
+
rowPadding: u + r,
|
|
283
|
+
style: a
|
|
284
|
+
}).join(`
|
|
285
|
+
${t}`)}
|
|
286
|
+
${s}
|
|
287
|
+
`;
|
|
288
|
+
}
|
|
289
|
+
default: {
|
|
290
|
+
const t = n ? `${styleText("cyan", S_BAR)} ` : "", s = l.split(`
|
|
291
|
+
`).length, u = I ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], r = u.join(`
|
|
292
|
+
`), c = u.length + 1;
|
|
293
|
+
return `${l}${t}${limitOptions({
|
|
294
|
+
output: o.output,
|
|
295
|
+
options: this.options,
|
|
296
|
+
cursor: this.cursor,
|
|
297
|
+
maxItems: o.maxItems,
|
|
298
|
+
columnPadding: t.length,
|
|
299
|
+
rowPadding: s + c,
|
|
300
|
+
style: a
|
|
301
|
+
}).join(`
|
|
302
|
+
${t}`)}
|
|
303
|
+
${r}
|
|
304
|
+
`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}).prompt();
|
|
309
|
+
};
|
|
310
|
+
const log = {
|
|
311
|
+
message: (s = [], { symbol: e = styleText("gray", S_BAR), secondarySymbol: r = styleText("gray", S_BAR), output: m = process.stdout, spacing: l = 1, withGuide: c } = {}) => {
|
|
312
|
+
const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
|
|
313
|
+
for (let i = 0; i < l; i++) t.push(f);
|
|
314
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
315
|
+
`);
|
|
316
|
+
if (g.length > 0) {
|
|
317
|
+
const [i, ...y] = g;
|
|
318
|
+
i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
|
|
319
|
+
for (const p of y) p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
|
|
320
|
+
}
|
|
321
|
+
m.write(`${t.join(`
|
|
322
|
+
`)}
|
|
323
|
+
`);
|
|
324
|
+
},
|
|
325
|
+
info: (s, e) => {
|
|
326
|
+
log.message(s, {
|
|
327
|
+
...e,
|
|
328
|
+
symbol: styleText("blue", S_INFO)
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
success: (s, e) => {
|
|
332
|
+
log.message(s, {
|
|
333
|
+
...e,
|
|
334
|
+
symbol: styleText("green", S_SUCCESS)
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
step: (s, e) => {
|
|
338
|
+
log.message(s, {
|
|
339
|
+
...e,
|
|
340
|
+
symbol: styleText("green", S_STEP_SUBMIT)
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
warn: (s, e) => {
|
|
344
|
+
log.message(s, {
|
|
345
|
+
...e,
|
|
346
|
+
symbol: styleText("yellow", S_WARN)
|
|
347
|
+
});
|
|
348
|
+
},
|
|
349
|
+
warning: (s, e) => {
|
|
350
|
+
log.warn(s, e);
|
|
351
|
+
},
|
|
352
|
+
error: (s, e) => {
|
|
353
|
+
log.message(s, {
|
|
354
|
+
...e,
|
|
355
|
+
symbol: styleText("red", S_ERROR)
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const cancel = (o = "", t) => {
|
|
360
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_END)} ` : "";
|
|
361
|
+
i.write(`${e}${styleText("red", o)}
|
|
362
|
+
|
|
363
|
+
`);
|
|
364
|
+
};
|
|
365
|
+
const intro = (o = "", t) => {
|
|
366
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_START)} ` : "";
|
|
367
|
+
i.write(`${e}${o}
|
|
368
|
+
`);
|
|
369
|
+
};
|
|
370
|
+
const outro = (o = "", t) => {
|
|
371
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR)}
|
|
372
|
+
${styleText("gray", S_BAR_END)} ` : "";
|
|
373
|
+
i.write(`${e}${o}
|
|
374
|
+
|
|
375
|
+
`);
|
|
376
|
+
};
|
|
377
|
+
const W$1 = (o) => o;
|
|
378
|
+
const C = (o, e, s) => {
|
|
379
|
+
const a = {
|
|
380
|
+
hard: true,
|
|
381
|
+
trim: false
|
|
382
|
+
}, i = wrapAnsi(o, e, a).split(`
|
|
383
|
+
`), c = i.reduce((n, t) => Math.max(fastStringWidth(t), n), 0);
|
|
384
|
+
return wrapAnsi(o, e - (i.map(s).reduce((n, t) => Math.max(fastStringWidth(t), n), 0) - c), a);
|
|
385
|
+
};
|
|
386
|
+
const note = (o = "", e = "", s) => {
|
|
387
|
+
const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = [
|
|
388
|
+
"",
|
|
389
|
+
...C(o, getColumns(a) - 6, c).split(`
|
|
390
|
+
`).map(c),
|
|
391
|
+
""
|
|
392
|
+
], n = fastStringWidth(e), t = Math.max(g.reduce((m, F) => {
|
|
393
|
+
const O = fastStringWidth(F);
|
|
394
|
+
return O > m ? O : m;
|
|
395
|
+
}, 0), n) + 2, h = g.map((m) => `${styleText("gray", S_BAR)} ${m}${" ".repeat(t - fastStringWidth(m))}${styleText("gray", S_BAR)}`).join(`
|
|
396
|
+
`), T = i ? `${styleText("gray", S_BAR)}
|
|
397
|
+
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
398
|
+
a.write(`${T}${styleText("green", S_STEP_SUBMIT)} ${styleText("reset", e)} ${styleText("gray", S_BAR_H.repeat(Math.max(t - n - 1, 1)) + S_CORNER_TOP_RIGHT)}
|
|
399
|
+
${h}
|
|
400
|
+
${styleText("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
401
|
+
`);
|
|
402
|
+
};
|
|
403
|
+
const W = (l) => styleText("magenta", l);
|
|
404
|
+
const spinner = ({ indicator: l = "dots", onCancel: h, output: n = process.stdout, cancelMessage: G, errorMessage: O, frames: E = unicode ? [
|
|
405
|
+
"◒",
|
|
406
|
+
"◐",
|
|
407
|
+
"◓",
|
|
408
|
+
"◑"
|
|
409
|
+
] : [
|
|
410
|
+
"•",
|
|
411
|
+
"o",
|
|
412
|
+
"O",
|
|
413
|
+
"0"
|
|
414
|
+
], delay: F = unicode ? 80 : 120, signal: m, ...I } = {}) => {
|
|
415
|
+
const u = isCI();
|
|
416
|
+
let M, T, d = false, S = false, s = "", p, w = performance.now();
|
|
417
|
+
const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
|
|
418
|
+
const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
419
|
+
S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
|
|
420
|
+
}, f = () => g(2), i = () => g(1), A = () => {
|
|
421
|
+
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);
|
|
422
|
+
}, H = () => {
|
|
423
|
+
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);
|
|
424
|
+
}, y = () => {
|
|
425
|
+
if (p === void 0) return;
|
|
426
|
+
u && n.write(`
|
|
427
|
+
`);
|
|
428
|
+
const r = wrapAnsi(p, x, {
|
|
429
|
+
hard: true,
|
|
430
|
+
trim: false
|
|
431
|
+
}).split(`
|
|
432
|
+
`);
|
|
433
|
+
r.length > 1 && n.write(import_src.cursor.up(r.length - 1)), n.write(import_src.cursor.to(0)), n.write(import_src.erase.down());
|
|
434
|
+
}, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
|
|
435
|
+
const r = (performance.now() - e) / 1e3, t = Math.floor(r / 60), o = Math.floor(r % 60);
|
|
436
|
+
return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
|
|
437
|
+
}, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
|
|
438
|
+
d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText("gray", S_BAR)}
|
|
439
|
+
`);
|
|
440
|
+
let r = 0, t = 0;
|
|
441
|
+
A(), T = setInterval(() => {
|
|
442
|
+
if (u && s === p) return;
|
|
443
|
+
y(), p = s;
|
|
444
|
+
const o = k(E[r]);
|
|
445
|
+
let v;
|
|
446
|
+
if (u) v = `${o} ${s}...`;
|
|
447
|
+
else if (l === "timer") v = `${o} ${s} ${_(w)}`;
|
|
448
|
+
else {
|
|
449
|
+
const B = ".".repeat(Math.floor(t)).slice(0, 3);
|
|
450
|
+
v = `${o} ${s}${B}`;
|
|
451
|
+
}
|
|
452
|
+
const j = wrapAnsi(v, x, {
|
|
453
|
+
hard: true,
|
|
454
|
+
trim: false
|
|
455
|
+
});
|
|
456
|
+
n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + .125 : 0;
|
|
457
|
+
}, F);
|
|
458
|
+
}, a = (e = "", r = 0, t = false) => {
|
|
459
|
+
if (!d) return;
|
|
460
|
+
d = false, clearInterval(T), y();
|
|
461
|
+
const o = r === 0 ? styleText("green", S_STEP_SUBMIT) : r === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
|
|
462
|
+
s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
|
|
463
|
+
`) : n.write(`${o} ${s}
|
|
464
|
+
`)), H(), M();
|
|
465
|
+
};
|
|
466
|
+
return {
|
|
467
|
+
start: P,
|
|
468
|
+
stop: (e = "") => a(e, 0),
|
|
469
|
+
message: (e = "") => {
|
|
470
|
+
s = C(e ?? s);
|
|
471
|
+
},
|
|
472
|
+
cancel: (e = "") => a(e, 1),
|
|
473
|
+
error: (e = "") => a(e, 2),
|
|
474
|
+
clear: () => a("", 0, true),
|
|
475
|
+
get isCancelled() {
|
|
476
|
+
return S;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
const SELECT_INSTRUCTIONS = [`${styleText("dim", "↑/↓")} to navigate`, `${styleText("dim", "Enter:")} confirm`];
|
|
481
|
+
const c = (t, o) => t.includes(`
|
|
482
|
+
`) ? t.split(`
|
|
483
|
+
`).map((d) => o(d)).join(`
|
|
484
|
+
`) : o(t);
|
|
485
|
+
const select = (t) => {
|
|
486
|
+
const o = (n, m) => {
|
|
487
|
+
if (n === void 0) return "";
|
|
488
|
+
const s = n.label ?? String(n.value);
|
|
489
|
+
switch (m) {
|
|
490
|
+
case "disabled": return `${styleText("gray", S_RADIO_INACTIVE)} ${c(s, (i) => styleText("gray", i))}${n.hint ? ` ${styleText("dim", `(${n.hint ?? "disabled"})`)}` : ""}`;
|
|
491
|
+
case "selected": return `${c(s, (i) => styleText("dim", i))}`;
|
|
492
|
+
case "active": return `${styleText("green", S_RADIO_ACTIVE)} ${s}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`;
|
|
493
|
+
case "cancelled": return `${c(s, (i) => styleText(["strikethrough", "dim"], i))}`;
|
|
494
|
+
default: return `${styleText("dim", S_RADIO_INACTIVE)} ${c(s, (i) => styleText("dim", i))}`;
|
|
495
|
+
}
|
|
496
|
+
}, d = t.showInstructions ?? true;
|
|
497
|
+
return new n$1({
|
|
498
|
+
options: t.options,
|
|
499
|
+
signal: t.signal,
|
|
500
|
+
input: t.input,
|
|
501
|
+
output: t.output,
|
|
502
|
+
initialValue: t.initialValue,
|
|
503
|
+
render() {
|
|
504
|
+
const n = t.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i = wrapTextWithPrefix(t.output, t.message, s, m), u = `${n ? `${styleText("gray", S_BAR)}
|
|
505
|
+
` : ""}${i}
|
|
506
|
+
`;
|
|
507
|
+
switch (this.state) {
|
|
508
|
+
case "submit": {
|
|
509
|
+
const r = n ? `${styleText("gray", S_BAR)} ` : "";
|
|
510
|
+
return `${u}${wrapTextWithPrefix(t.output, o(this.options[this.cursor], "selected"), r)}`;
|
|
511
|
+
}
|
|
512
|
+
case "cancel": {
|
|
513
|
+
const r = n ? `${styleText("gray", S_BAR)} ` : "";
|
|
514
|
+
return `${u}${wrapTextWithPrefix(t.output, o(this.options[this.cursor], "cancelled"), r)}${n ? `
|
|
515
|
+
${styleText("gray", S_BAR)}` : ""}`;
|
|
516
|
+
}
|
|
517
|
+
default: {
|
|
518
|
+
const r = n ? `${styleText("cyan", S_BAR)} ` : "", a = u.split(`
|
|
519
|
+
`).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], b = p.join(`
|
|
520
|
+
`), f = p.length + 1;
|
|
521
|
+
return `${u}${r}${limitOptions({
|
|
522
|
+
output: t.output,
|
|
523
|
+
cursor: this.cursor,
|
|
524
|
+
options: this.options,
|
|
525
|
+
maxItems: t.maxItems,
|
|
526
|
+
columnPadding: r.length,
|
|
527
|
+
rowPadding: a + f,
|
|
528
|
+
style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
|
|
529
|
+
}).join(`
|
|
530
|
+
${r}`)}
|
|
531
|
+
${b}
|
|
532
|
+
`;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}).prompt();
|
|
537
|
+
};
|
|
538
|
+
`${styleText("gray", S_BAR)}`;
|
|
539
|
+
export { cancel, confirm, groupMultiselect, intro, log, multiselect, note, outro, select, spinner };
|