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,758 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../rolldown-runtime.mjs";
|
|
2
|
+
import "node:util";
|
|
3
|
+
import { stdin, stdout } from "node:process";
|
|
4
|
+
import * as l from "node:readline";
|
|
5
|
+
import l__default from "node:readline";
|
|
6
|
+
import { ReadStream } from "node:tty";
|
|
7
|
+
const getCodePointsLength = (() => {
|
|
8
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
9
|
+
return (input) => {
|
|
10
|
+
let surrogatePairsNr = 0;
|
|
11
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
12
|
+
while (SURROGATE_PAIR_RE.test(input)) surrogatePairsNr += 1;
|
|
13
|
+
return input.length - surrogatePairsNr;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
const isFullWidth = (x) => {
|
|
17
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
18
|
+
};
|
|
19
|
+
const isWideNotCJKTNotEmoji = (x) => {
|
|
20
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
21
|
+
};
|
|
22
|
+
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
23
|
+
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
24
|
+
const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy;
|
|
25
|
+
const TAB_RE = /\t{1,1000}/y;
|
|
26
|
+
const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
|
|
27
|
+
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
28
|
+
const MODIFIER_RE = /\p{M}+/gu;
|
|
29
|
+
const NO_TRUNCATION$1 = {
|
|
30
|
+
limit: Infinity,
|
|
31
|
+
ellipsis: ""
|
|
32
|
+
};
|
|
33
|
+
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
34
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
35
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
36
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
|
|
37
|
+
const ANSI_WIDTH = 0;
|
|
38
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
39
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
40
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
41
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
42
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
43
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
44
|
+
const PARSE_BLOCKS = [
|
|
45
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
46
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
47
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
48
|
+
[TAB_RE, TAB_WIDTH],
|
|
49
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
50
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
51
|
+
];
|
|
52
|
+
let indexPrev = 0;
|
|
53
|
+
let index = 0;
|
|
54
|
+
let length = input.length;
|
|
55
|
+
let lengthExtra = 0;
|
|
56
|
+
let truncationEnabled = false;
|
|
57
|
+
let truncationIndex = length;
|
|
58
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
59
|
+
let unmatchedStart = 0;
|
|
60
|
+
let unmatchedEnd = 0;
|
|
61
|
+
let width = 0;
|
|
62
|
+
let widthExtra = 0;
|
|
63
|
+
outer: while (true) {
|
|
64
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
65
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
66
|
+
lengthExtra = 0;
|
|
67
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
68
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
69
|
+
if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
|
|
70
|
+
else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
|
|
71
|
+
else widthExtra = REGULAR_WIDTH;
|
|
72
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
73
|
+
if (width + widthExtra > LIMIT) {
|
|
74
|
+
truncationEnabled = true;
|
|
75
|
+
break outer;
|
|
76
|
+
}
|
|
77
|
+
lengthExtra += char.length;
|
|
78
|
+
width += widthExtra;
|
|
79
|
+
}
|
|
80
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
81
|
+
}
|
|
82
|
+
if (index >= length) break outer;
|
|
83
|
+
for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
|
|
84
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
85
|
+
BLOCK_RE.lastIndex = index;
|
|
86
|
+
if (BLOCK_RE.test(input)) {
|
|
87
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
88
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
89
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
90
|
+
if (width + widthExtra > LIMIT) {
|
|
91
|
+
truncationEnabled = true;
|
|
92
|
+
break outer;
|
|
93
|
+
}
|
|
94
|
+
width += widthExtra;
|
|
95
|
+
unmatchedStart = indexPrev;
|
|
96
|
+
unmatchedEnd = index;
|
|
97
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
98
|
+
continue outer;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
index += 1;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
105
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
106
|
+
truncated: truncationEnabled,
|
|
107
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const NO_TRUNCATION = {
|
|
111
|
+
limit: Infinity,
|
|
112
|
+
ellipsis: "",
|
|
113
|
+
ellipsisWidth: 0
|
|
114
|
+
};
|
|
115
|
+
const fastStringWidth = (input, options = {}) => {
|
|
116
|
+
return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
|
117
|
+
};
|
|
118
|
+
const ESC = "\x1B";
|
|
119
|
+
const CSI = "";
|
|
120
|
+
const END_CODE = 39;
|
|
121
|
+
const ANSI_ESCAPE_BELL = "\x07";
|
|
122
|
+
const ANSI_CSI = "[";
|
|
123
|
+
const ANSI_OSC = "]";
|
|
124
|
+
const ANSI_SGR_TERMINATOR = "m";
|
|
125
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
126
|
+
const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
127
|
+
const getClosingCode = (openingCode) => {
|
|
128
|
+
if (openingCode >= 30 && openingCode <= 37) return 39;
|
|
129
|
+
if (openingCode >= 90 && openingCode <= 97) return 39;
|
|
130
|
+
if (openingCode >= 40 && openingCode <= 47) return 49;
|
|
131
|
+
if (openingCode >= 100 && openingCode <= 107) return 49;
|
|
132
|
+
if (openingCode === 1 || openingCode === 2) return 22;
|
|
133
|
+
if (openingCode === 3) return 23;
|
|
134
|
+
if (openingCode === 4) return 24;
|
|
135
|
+
if (openingCode === 7) return 27;
|
|
136
|
+
if (openingCode === 8) return 28;
|
|
137
|
+
if (openingCode === 9) return 29;
|
|
138
|
+
if (openingCode === 0) return 0;
|
|
139
|
+
};
|
|
140
|
+
const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
141
|
+
const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
142
|
+
const wrapWord = (rows, word, columns) => {
|
|
143
|
+
const characters = word[Symbol.iterator]();
|
|
144
|
+
let isInsideEscape = false;
|
|
145
|
+
let isInsideLinkEscape = false;
|
|
146
|
+
let lastRow = rows.at(-1);
|
|
147
|
+
let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
|
|
148
|
+
let currentCharacter = characters.next();
|
|
149
|
+
let nextCharacter = characters.next();
|
|
150
|
+
let rawCharacterIndex = 0;
|
|
151
|
+
while (!currentCharacter.done) {
|
|
152
|
+
const character = currentCharacter.value;
|
|
153
|
+
const characterLength = fastStringWidth(character);
|
|
154
|
+
if (visible + characterLength <= columns) rows[rows.length - 1] += character;
|
|
155
|
+
else {
|
|
156
|
+
rows.push(character);
|
|
157
|
+
visible = 0;
|
|
158
|
+
}
|
|
159
|
+
if (character === ESC || character === CSI) {
|
|
160
|
+
isInsideEscape = true;
|
|
161
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
162
|
+
}
|
|
163
|
+
if (isInsideEscape) {
|
|
164
|
+
if (isInsideLinkEscape) {
|
|
165
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
166
|
+
isInsideEscape = false;
|
|
167
|
+
isInsideLinkEscape = false;
|
|
168
|
+
}
|
|
169
|
+
} else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
|
|
170
|
+
} else {
|
|
171
|
+
visible += characterLength;
|
|
172
|
+
if (visible === columns && !nextCharacter.done) {
|
|
173
|
+
rows.push("");
|
|
174
|
+
visible = 0;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
currentCharacter = nextCharacter;
|
|
178
|
+
nextCharacter = characters.next();
|
|
179
|
+
rawCharacterIndex += character.length;
|
|
180
|
+
}
|
|
181
|
+
lastRow = rows.at(-1);
|
|
182
|
+
if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
|
|
183
|
+
};
|
|
184
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
185
|
+
const words = string.split(" ");
|
|
186
|
+
let last = words.length;
|
|
187
|
+
while (last) {
|
|
188
|
+
if (fastStringWidth(words[last - 1])) break;
|
|
189
|
+
last--;
|
|
190
|
+
}
|
|
191
|
+
if (last === words.length) return string;
|
|
192
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
193
|
+
};
|
|
194
|
+
const exec = (string, columns, options = {}) => {
|
|
195
|
+
if (options.trim !== false && string.trim() === "") return "";
|
|
196
|
+
let returnValue = "";
|
|
197
|
+
let escapeCode;
|
|
198
|
+
let escapeUrl;
|
|
199
|
+
const words = string.split(" ");
|
|
200
|
+
let rows = [""];
|
|
201
|
+
let rowLength = 0;
|
|
202
|
+
for (let index = 0; index < words.length; index++) {
|
|
203
|
+
const word = words[index];
|
|
204
|
+
if (options.trim !== false) {
|
|
205
|
+
const row = rows.at(-1) ?? "";
|
|
206
|
+
const trimmed = row.trimStart();
|
|
207
|
+
if (row.length !== trimmed.length) {
|
|
208
|
+
rows[rows.length - 1] = trimmed;
|
|
209
|
+
rowLength = fastStringWidth(trimmed);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (index !== 0) {
|
|
213
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
214
|
+
rows.push("");
|
|
215
|
+
rowLength = 0;
|
|
216
|
+
}
|
|
217
|
+
if (rowLength || options.trim === false) {
|
|
218
|
+
rows[rows.length - 1] += " ";
|
|
219
|
+
rowLength++;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const wordLength = fastStringWidth(word);
|
|
223
|
+
if (options.hard && wordLength > columns) {
|
|
224
|
+
const remainingColumns = columns - rowLength;
|
|
225
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
226
|
+
if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
|
|
227
|
+
wrapWord(rows, word, columns);
|
|
228
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
232
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
233
|
+
wrapWord(rows, word, columns);
|
|
234
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
rows.push("");
|
|
238
|
+
rowLength = 0;
|
|
239
|
+
}
|
|
240
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
241
|
+
wrapWord(rows, word, columns);
|
|
242
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
rows[rows.length - 1] += word;
|
|
246
|
+
rowLength += wordLength;
|
|
247
|
+
}
|
|
248
|
+
if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
249
|
+
const preString = rows.join("\n");
|
|
250
|
+
let inSurrogate = false;
|
|
251
|
+
for (let i = 0; i < preString.length; i++) {
|
|
252
|
+
const character = preString[i];
|
|
253
|
+
returnValue += character;
|
|
254
|
+
if (!inSurrogate) {
|
|
255
|
+
inSurrogate = character >= "\ud800" && character <= "\udbff";
|
|
256
|
+
if (inSurrogate) continue;
|
|
257
|
+
} else inSurrogate = false;
|
|
258
|
+
if (character === ESC || character === CSI) {
|
|
259
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
260
|
+
const groups = GROUP_REGEX.exec(preString)?.groups;
|
|
261
|
+
if (groups?.code !== void 0) {
|
|
262
|
+
const code = Number.parseFloat(groups.code);
|
|
263
|
+
escapeCode = code === END_CODE ? void 0 : code;
|
|
264
|
+
} else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
265
|
+
}
|
|
266
|
+
if (preString[i + 1] === "\n") {
|
|
267
|
+
if (escapeUrl) returnValue += wrapAnsiHyperlink("");
|
|
268
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
|
|
269
|
+
if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
|
|
270
|
+
} else if (character === "\n") {
|
|
271
|
+
if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
|
|
272
|
+
if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return returnValue;
|
|
276
|
+
};
|
|
277
|
+
const CRLF_OR_LF = /\r?\n/;
|
|
278
|
+
function wrapAnsi(string, columns, options) {
|
|
279
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
|
|
280
|
+
}
|
|
281
|
+
var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
282
|
+
const ESC = "\x1B";
|
|
283
|
+
const CSI = `${ESC}[`;
|
|
284
|
+
const beep = "\x07";
|
|
285
|
+
const cursor = {
|
|
286
|
+
to(x, y) {
|
|
287
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
288
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
289
|
+
},
|
|
290
|
+
move(x, y) {
|
|
291
|
+
let ret = "";
|
|
292
|
+
if (x < 0) ret += `${CSI}${-x}D`;
|
|
293
|
+
else if (x > 0) ret += `${CSI}${x}C`;
|
|
294
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
295
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
296
|
+
return ret;
|
|
297
|
+
},
|
|
298
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
299
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
300
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
301
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
302
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
303
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
304
|
+
left: `${CSI}G`,
|
|
305
|
+
hide: `${CSI}?25l`,
|
|
306
|
+
show: `${CSI}?25h`,
|
|
307
|
+
save: `${ESC}7`,
|
|
308
|
+
restore: `${ESC}8`
|
|
309
|
+
};
|
|
310
|
+
module.exports = {
|
|
311
|
+
cursor,
|
|
312
|
+
scroll: {
|
|
313
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
314
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
315
|
+
},
|
|
316
|
+
erase: {
|
|
317
|
+
screen: `${CSI}2J`,
|
|
318
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
319
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
320
|
+
line: `${CSI}2K`,
|
|
321
|
+
lineEnd: `${CSI}K`,
|
|
322
|
+
lineStart: `${CSI}1K`,
|
|
323
|
+
lines(count) {
|
|
324
|
+
let clear = "";
|
|
325
|
+
for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
326
|
+
if (count) clear += cursor.left;
|
|
327
|
+
return clear;
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
beep
|
|
331
|
+
};
|
|
332
|
+
}));
|
|
333
|
+
var import_src = require_src();
|
|
334
|
+
function findCursor(s, o, l) {
|
|
335
|
+
if (!l.some((r) => !r.disabled)) return s;
|
|
336
|
+
const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
337
|
+
return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
|
|
338
|
+
}
|
|
339
|
+
const settings = {
|
|
340
|
+
actions: /* @__PURE__ */ new Set([
|
|
341
|
+
"up",
|
|
342
|
+
"down",
|
|
343
|
+
"left",
|
|
344
|
+
"right",
|
|
345
|
+
"space",
|
|
346
|
+
"enter",
|
|
347
|
+
"cancel"
|
|
348
|
+
]),
|
|
349
|
+
aliases: /* @__PURE__ */ new Map([
|
|
350
|
+
["k", "up"],
|
|
351
|
+
["j", "down"],
|
|
352
|
+
["h", "left"],
|
|
353
|
+
["l", "right"],
|
|
354
|
+
["", "cancel"],
|
|
355
|
+
["escape", "cancel"]
|
|
356
|
+
]),
|
|
357
|
+
messages: {
|
|
358
|
+
cancel: "Canceled",
|
|
359
|
+
error: "Something went wrong"
|
|
360
|
+
},
|
|
361
|
+
withGuide: true,
|
|
362
|
+
date: {
|
|
363
|
+
monthNames: [...[
|
|
364
|
+
"January",
|
|
365
|
+
"February",
|
|
366
|
+
"March",
|
|
367
|
+
"April",
|
|
368
|
+
"May",
|
|
369
|
+
"June",
|
|
370
|
+
"July",
|
|
371
|
+
"August",
|
|
372
|
+
"September",
|
|
373
|
+
"October",
|
|
374
|
+
"November",
|
|
375
|
+
"December"
|
|
376
|
+
]],
|
|
377
|
+
messages: {
|
|
378
|
+
required: "Please enter a valid date",
|
|
379
|
+
invalidMonth: "There are only 12 months in a year",
|
|
380
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
381
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
382
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
function isActionKey(n, e) {
|
|
387
|
+
if (typeof n == "string") return settings.aliases.get(n) === e;
|
|
388
|
+
for (const s of n) if (s !== void 0 && isActionKey(s, e)) return true;
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
function diffLines(i, s) {
|
|
392
|
+
if (i === s) return;
|
|
393
|
+
const e = i.split(`
|
|
394
|
+
`), t = s.split(`
|
|
395
|
+
`), r = Math.max(e.length, t.length), f = [];
|
|
396
|
+
for (let n = 0; n < r; n++) e[n] !== t[n] && f.push(n);
|
|
397
|
+
return {
|
|
398
|
+
lines: f,
|
|
399
|
+
numLinesBefore: e.length,
|
|
400
|
+
numLinesAfter: t.length,
|
|
401
|
+
numLines: r
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
const R = globalThis.process.platform.startsWith("win");
|
|
405
|
+
const CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
406
|
+
function isCancel(e) {
|
|
407
|
+
return e === CANCEL_SYMBOL;
|
|
408
|
+
}
|
|
409
|
+
function setRawMode(e, r) {
|
|
410
|
+
const o = e;
|
|
411
|
+
o.isTTY && o.setRawMode(r);
|
|
412
|
+
}
|
|
413
|
+
function block({ input: e = stdin, output: r = stdout, overwrite: o = true, hideCursor: t = true } = {}) {
|
|
414
|
+
const s = l.createInterface({
|
|
415
|
+
input: e,
|
|
416
|
+
output: r,
|
|
417
|
+
prompt: "",
|
|
418
|
+
tabSize: 1
|
|
419
|
+
});
|
|
420
|
+
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
421
|
+
const n = (f, { name: a, sequence: p }) => {
|
|
422
|
+
if (isActionKey([
|
|
423
|
+
String(f),
|
|
424
|
+
a,
|
|
425
|
+
p
|
|
426
|
+
], "cancel")) {
|
|
427
|
+
t && r.write(import_src.cursor.show), process.exit(0);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (!o) return;
|
|
431
|
+
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
432
|
+
l.moveCursor(r, i, m, () => {
|
|
433
|
+
l.clearLine(r, 1, () => {
|
|
434
|
+
e.once("keypress", n);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
return t && r.write(import_src.cursor.hide), e.once("keypress", n), () => {
|
|
439
|
+
e.off("keypress", n), t && r.write(import_src.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
const getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
|
|
443
|
+
const getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
|
|
444
|
+
function wrapTextWithPrefix(e, r, o, t = o, s = o, n) {
|
|
445
|
+
return wrapAnsi(r, getColumns(e ?? stdout) - o.length, {
|
|
446
|
+
hard: true,
|
|
447
|
+
trim: false
|
|
448
|
+
}).split(`
|
|
449
|
+
`).map((c, i, m) => {
|
|
450
|
+
const d = n ? n(c, i) : c;
|
|
451
|
+
return i === 0 ? `${t}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
452
|
+
}).join(`
|
|
453
|
+
`);
|
|
454
|
+
}
|
|
455
|
+
function runValidation(e, n) {
|
|
456
|
+
if ("~standard" in e) {
|
|
457
|
+
const a = e["~standard"].validate(n);
|
|
458
|
+
if (a instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
459
|
+
return a.issues?.at(0)?.message;
|
|
460
|
+
}
|
|
461
|
+
return e(n);
|
|
462
|
+
}
|
|
463
|
+
var V = class {
|
|
464
|
+
input;
|
|
465
|
+
output;
|
|
466
|
+
_abortSignal;
|
|
467
|
+
rl;
|
|
468
|
+
opts;
|
|
469
|
+
_render;
|
|
470
|
+
_track = false;
|
|
471
|
+
_prevFrame = "";
|
|
472
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
473
|
+
_cursor = 0;
|
|
474
|
+
state = "initial";
|
|
475
|
+
error = "";
|
|
476
|
+
value;
|
|
477
|
+
userInput = "";
|
|
478
|
+
constructor(t, e = true) {
|
|
479
|
+
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t;
|
|
480
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
481
|
+
}
|
|
482
|
+
unsubscribe() {
|
|
483
|
+
this._subscribers.clear();
|
|
484
|
+
}
|
|
485
|
+
setSubscriber(t, e) {
|
|
486
|
+
const i = this._subscribers.get(t) ?? [];
|
|
487
|
+
i.push(e), this._subscribers.set(t, i);
|
|
488
|
+
}
|
|
489
|
+
on(t, e) {
|
|
490
|
+
this.setSubscriber(t, { cb: e });
|
|
491
|
+
}
|
|
492
|
+
once(t, e) {
|
|
493
|
+
this.setSubscriber(t, {
|
|
494
|
+
cb: e,
|
|
495
|
+
once: true
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
emit(t, ...e) {
|
|
499
|
+
const i = this._subscribers.get(t) ?? [], n = [];
|
|
500
|
+
for (const s of i) s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
|
|
501
|
+
for (const s of n) s();
|
|
502
|
+
}
|
|
503
|
+
prompt() {
|
|
504
|
+
return new Promise((t) => {
|
|
505
|
+
if (this._abortSignal) {
|
|
506
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
|
|
507
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
508
|
+
this.state = "cancel", this.close();
|
|
509
|
+
}, { once: true });
|
|
510
|
+
}
|
|
511
|
+
this.rl = l__default.createInterface({
|
|
512
|
+
input: this.input,
|
|
513
|
+
tabSize: 2,
|
|
514
|
+
prompt: "",
|
|
515
|
+
escapeCodeTimeout: 50,
|
|
516
|
+
terminal: true
|
|
517
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && 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", () => {
|
|
518
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
|
|
519
|
+
}), this.once("cancel", () => {
|
|
520
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
_isActionKey(t, e) {
|
|
525
|
+
return t === " ";
|
|
526
|
+
}
|
|
527
|
+
_shouldSubmit(t, e) {
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
_setValue(t) {
|
|
531
|
+
this.value = t, this.emit("value", this.value);
|
|
532
|
+
}
|
|
533
|
+
_setUserInput(t, e) {
|
|
534
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
535
|
+
}
|
|
536
|
+
_clearUserInput() {
|
|
537
|
+
this.rl?.write(null, {
|
|
538
|
+
ctrl: true,
|
|
539
|
+
name: "u"
|
|
540
|
+
}), this._setUserInput("");
|
|
541
|
+
}
|
|
542
|
+
onKeypress(t, e) {
|
|
543
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, {
|
|
544
|
+
ctrl: true,
|
|
545
|
+
name: "h"
|
|
546
|
+
}), 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)) {
|
|
547
|
+
if (this.opts.validate) {
|
|
548
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
549
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
550
|
+
}
|
|
551
|
+
this.state !== "error" && (this.state = "submit");
|
|
552
|
+
}
|
|
553
|
+
isActionKey([
|
|
554
|
+
t,
|
|
555
|
+
e?.name,
|
|
556
|
+
e?.sequence
|
|
557
|
+
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
558
|
+
}
|
|
559
|
+
close() {
|
|
560
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
561
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
562
|
+
}
|
|
563
|
+
restoreCursor() {
|
|
564
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, {
|
|
565
|
+
hard: true,
|
|
566
|
+
trim: false
|
|
567
|
+
}).split(`
|
|
568
|
+
`).length - 1;
|
|
569
|
+
this.output.write(import_src.cursor.move(-999, t * -1));
|
|
570
|
+
}
|
|
571
|
+
render() {
|
|
572
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
573
|
+
hard: true,
|
|
574
|
+
trim: false
|
|
575
|
+
});
|
|
576
|
+
if (t !== this._prevFrame) {
|
|
577
|
+
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
578
|
+
else {
|
|
579
|
+
const e = diffLines(this._prevFrame, t), i = getRows(this.output);
|
|
580
|
+
if (this.restoreCursor(), e) {
|
|
581
|
+
const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
|
|
582
|
+
let r = e.lines.find((o) => o >= n);
|
|
583
|
+
if (r === void 0) {
|
|
584
|
+
this._prevFrame = t;
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (e.lines.length === 1) {
|
|
588
|
+
this.output.write(import_src.cursor.move(0, r - s)), this.output.write(import_src.erase.lines(1));
|
|
589
|
+
const o = t.split(`
|
|
590
|
+
`);
|
|
591
|
+
this.output.write(o[r]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, o.length - r - 1));
|
|
592
|
+
return;
|
|
593
|
+
} else if (e.lines.length > 1) {
|
|
594
|
+
if (n < s) r = n;
|
|
595
|
+
else {
|
|
596
|
+
const h = r - s;
|
|
597
|
+
h > 0 && this.output.write(import_src.cursor.move(0, h));
|
|
598
|
+
}
|
|
599
|
+
this.output.write(import_src.erase.down());
|
|
600
|
+
const f = t.split(`
|
|
601
|
+
`).slice(r);
|
|
602
|
+
this.output.write(f.join(`
|
|
603
|
+
`)), this._prevFrame = t;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
this.output.write(import_src.erase.down());
|
|
608
|
+
}
|
|
609
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
var r = class extends V {
|
|
614
|
+
get cursor() {
|
|
615
|
+
return this.value ? 0 : 1;
|
|
616
|
+
}
|
|
617
|
+
get _value() {
|
|
618
|
+
return this.cursor === 0;
|
|
619
|
+
}
|
|
620
|
+
constructor(t) {
|
|
621
|
+
super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
622
|
+
this.value = this._value;
|
|
623
|
+
}), this.on("confirm", (i) => {
|
|
624
|
+
this.output.write(import_src.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
625
|
+
}), this.on("cursor", () => {
|
|
626
|
+
this.value = !this.value;
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
let u$2 = class u extends V {
|
|
631
|
+
options;
|
|
632
|
+
cursor = 0;
|
|
633
|
+
#t;
|
|
634
|
+
getGroupItems(t) {
|
|
635
|
+
return this.options.filter((r) => r.group === t);
|
|
636
|
+
}
|
|
637
|
+
isGroupSelected(t) {
|
|
638
|
+
const r = this.getGroupItems(t), e = this.value;
|
|
639
|
+
return e === void 0 ? false : r.every((s) => e.includes(s.value));
|
|
640
|
+
}
|
|
641
|
+
toggleValue() {
|
|
642
|
+
const t = this.options[this.cursor];
|
|
643
|
+
if (t !== void 0) if (this.value === void 0 && (this.value = []), t.group === true) {
|
|
644
|
+
const r = t.value, e = this.getGroupItems(r);
|
|
645
|
+
this.isGroupSelected(r) ? 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));
|
|
646
|
+
} else {
|
|
647
|
+
const r = this.value.includes(t.value);
|
|
648
|
+
this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
constructor(t) {
|
|
652
|
+
super(t, false);
|
|
653
|
+
const { options: r } = t;
|
|
654
|
+
this.#t = t.selectableGroups !== false, this.options = Object.entries(r).flatMap(([e, s]) => [{
|
|
655
|
+
value: e,
|
|
656
|
+
group: true,
|
|
657
|
+
label: e
|
|
658
|
+
}, ...s.map((i) => ({
|
|
659
|
+
...i,
|
|
660
|
+
group: e
|
|
661
|
+
}))]), this.value = [...t.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
662
|
+
switch (e) {
|
|
663
|
+
case "left":
|
|
664
|
+
case "up": {
|
|
665
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
666
|
+
const s = this.options[this.cursor]?.group === true;
|
|
667
|
+
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
case "down":
|
|
671
|
+
case "right": {
|
|
672
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
673
|
+
const s = this.options[this.cursor]?.group === true;
|
|
674
|
+
!this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "space":
|
|
678
|
+
this.toggleValue();
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
var a = class extends V {
|
|
685
|
+
options;
|
|
686
|
+
cursor = 0;
|
|
687
|
+
get _value() {
|
|
688
|
+
return this.options[this.cursor]?.value;
|
|
689
|
+
}
|
|
690
|
+
get _enabledOptions() {
|
|
691
|
+
return this.options.filter((e) => e.disabled !== true);
|
|
692
|
+
}
|
|
693
|
+
toggleAll() {
|
|
694
|
+
const e = this._enabledOptions, i = this.value !== void 0 && this.value.length === e.length;
|
|
695
|
+
this.value = i ? [] : e.map((t) => t.value);
|
|
696
|
+
}
|
|
697
|
+
toggleInvert() {
|
|
698
|
+
const e = this.value;
|
|
699
|
+
if (!e) return;
|
|
700
|
+
const i = this._enabledOptions.filter((t) => !e.includes(t.value));
|
|
701
|
+
this.value = i.map((t) => t.value);
|
|
702
|
+
}
|
|
703
|
+
toggleValue() {
|
|
704
|
+
this.value === void 0 && (this.value = []);
|
|
705
|
+
const e = this.value.includes(this._value);
|
|
706
|
+
this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
|
|
707
|
+
}
|
|
708
|
+
constructor(e) {
|
|
709
|
+
super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
710
|
+
const i = Math.max(this.options.findIndex(({ value: t }) => t === e.cursorAt), 0);
|
|
711
|
+
this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
|
|
712
|
+
l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
|
|
713
|
+
}), this.on("cursor", (t) => {
|
|
714
|
+
switch (t) {
|
|
715
|
+
case "left":
|
|
716
|
+
case "up":
|
|
717
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
718
|
+
break;
|
|
719
|
+
case "down":
|
|
720
|
+
case "right":
|
|
721
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
722
|
+
break;
|
|
723
|
+
case "space":
|
|
724
|
+
this.toggleValue();
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
let n$1 = class n extends V {
|
|
731
|
+
options;
|
|
732
|
+
cursor = 0;
|
|
733
|
+
get _selectedValue() {
|
|
734
|
+
return this.options[this.cursor];
|
|
735
|
+
}
|
|
736
|
+
changeValue() {
|
|
737
|
+
const e = this._selectedValue;
|
|
738
|
+
this.value = e === void 0 ? void 0 : e.value;
|
|
739
|
+
}
|
|
740
|
+
constructor(e) {
|
|
741
|
+
super(e, false), this.options = e.options;
|
|
742
|
+
const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o;
|
|
743
|
+
this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => {
|
|
744
|
+
switch (s) {
|
|
745
|
+
case "left":
|
|
746
|
+
case "up":
|
|
747
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
748
|
+
break;
|
|
749
|
+
case "down":
|
|
750
|
+
case "right":
|
|
751
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
this.changeValue();
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
export { a, block, fastStringWidth, getColumns, getRows, isCancel, n$1, r, require_src, settings, u$2, wrapAnsi, wrapTextWithPrefix };
|