@voidzero-dev/vite-plus-prompts 0.0.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/dist/index.mjs ADDED
@@ -0,0 +1,1872 @@
1
+ import { AutocompletePrompt, ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, SelectKeyPrompt, SelectPrompt, TextPrompt, block, getColumns, getRows, isCancel, isCancel as isCancel$1, settings, settings as settings$1, updateSettings, wrapTextWithPrefix } from "@clack/core";
2
+ import color from "picocolors";
3
+ import process$1 from "node:process";
4
+ import { randomBytes } from "node:crypto";
5
+ import { existsSync, lstatSync, readdirSync } from "node:fs";
6
+ import { dirname, join } from "node:path";
7
+ import { cursor, erase } from "sisteransi";
8
+ import { stripVTControlCharacters } from "node:util";
9
+ //#region ../../node_modules/.pnpm/is-unicode-supported@1.3.0/node_modules/is-unicode-supported/index.js
10
+ function isUnicodeSupported() {
11
+ if (process$1.platform !== "win32") return process$1.env.TERM !== "linux";
12
+ 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";
13
+ }
14
+ //#endregion
15
+ //#region src/common.ts
16
+ const unicode = isUnicodeSupported();
17
+ const isCI = () => process.env.CI === "true";
18
+ const isTTY = (output) => {
19
+ return output.isTTY === true;
20
+ };
21
+ const unicodeOr = (c, fallback) => unicode ? c : fallback;
22
+ const S_POINTER_ACTIVE = unicodeOr("›", ">");
23
+ const S_POINTER_INACTIVE = " ";
24
+ const S_STEP_ACTIVE = S_POINTER_ACTIVE;
25
+ const S_STEP_CANCEL = unicodeOr("■", "x");
26
+ const S_STEP_ERROR = unicodeOr("▲", "x");
27
+ const S_STEP_SUBMIT = unicodeOr("◇", "o");
28
+ const S_BAR_START = unicodeOr("┌", "T");
29
+ const S_BAR = unicodeOr("│", "|");
30
+ const S_BAR_END = unicodeOr("└", "—");
31
+ const S_BAR_START_RIGHT = unicodeOr("┐", "T");
32
+ const S_BAR_END_RIGHT = unicodeOr("┘", "—");
33
+ const S_RADIO_ACTIVE = S_POINTER_ACTIVE;
34
+ const S_RADIO_INACTIVE = " ";
35
+ const S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
36
+ const S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
37
+ const S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
38
+ const S_PASSWORD_MASK = unicodeOr("▪", "•");
39
+ const S_BAR_H = unicodeOr("─", "-");
40
+ const S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
41
+ const S_CONNECT_LEFT = unicodeOr("├", "+");
42
+ const S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
43
+ const S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
44
+ const S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
45
+ const S_INFO = unicodeOr("●", "•");
46
+ const S_SUCCESS = unicodeOr("◆", "*");
47
+ const S_WARN = unicodeOr("▲", "!");
48
+ const S_ERROR = unicodeOr("■", "x");
49
+ const completeColor = (value) => color.gray(value);
50
+ const symbol = (state) => {
51
+ switch (state) {
52
+ case "initial":
53
+ case "active": return color.blue(S_STEP_ACTIVE);
54
+ case "cancel": return color.red(S_STEP_CANCEL);
55
+ case "error": return color.yellow(S_STEP_ERROR);
56
+ case "submit": return completeColor(S_STEP_SUBMIT);
57
+ default: return color.blue(S_STEP_ACTIVE);
58
+ }
59
+ };
60
+ const symbolBar = (state) => {
61
+ switch (state) {
62
+ case "initial":
63
+ case "active": return color.blue(S_BAR);
64
+ case "cancel": return color.red(S_BAR);
65
+ case "error": return color.yellow(S_BAR);
66
+ case "submit": return completeColor(S_BAR);
67
+ default: return color.blue(S_BAR);
68
+ }
69
+ };
70
+ //#endregion
71
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
72
+ const getCodePointsLength = (() => {
73
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
74
+ return (input) => {
75
+ let surrogatePairsNr = 0;
76
+ SURROGATE_PAIR_RE.lastIndex = 0;
77
+ while (SURROGATE_PAIR_RE.test(input)) surrogatePairsNr += 1;
78
+ return input.length - surrogatePairsNr;
79
+ };
80
+ })();
81
+ const isFullWidth$1 = (x) => {
82
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
83
+ };
84
+ const isWideNotCJKTNotEmoji = (x) => {
85
+ 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;
86
+ };
87
+ //#endregion
88
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
89
+ const ANSI_RE$1 = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
90
+ const CONTROL_RE$1 = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
91
+ 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;
92
+ const TAB_RE$1 = /\t{1,1000}/y;
93
+ const EMOJI_RE$1 = /[\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;
94
+ const LATIN_RE$1 = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
95
+ const MODIFIER_RE$1 = /\p{M}+/gu;
96
+ const NO_TRUNCATION$3 = {
97
+ limit: Infinity,
98
+ ellipsis: ""
99
+ };
100
+ const getStringTruncatedWidth$1 = (input, truncationOptions = {}, widthOptions = {}) => {
101
+ const LIMIT = truncationOptions.limit ?? Infinity;
102
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
103
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth$1(ELLIPSIS, NO_TRUNCATION$3, widthOptions).width : 0);
104
+ const ANSI_WIDTH = 0;
105
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
106
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
107
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
108
+ const FULL_WIDTH_WIDTH = 2;
109
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
110
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
111
+ const PARSE_BLOCKS = [
112
+ [LATIN_RE$1, REGULAR_WIDTH],
113
+ [ANSI_RE$1, ANSI_WIDTH],
114
+ [CONTROL_RE$1, CONTROL_WIDTH],
115
+ [TAB_RE$1, TAB_WIDTH],
116
+ [EMOJI_RE$1, EMOJI_WIDTH],
117
+ [CJKT_WIDE_RE, WIDE_WIDTH]
118
+ ];
119
+ let indexPrev = 0;
120
+ let index = 0;
121
+ let length = input.length;
122
+ let lengthExtra = 0;
123
+ let truncationEnabled = false;
124
+ let truncationIndex = length;
125
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
126
+ let unmatchedStart = 0;
127
+ let unmatchedEnd = 0;
128
+ let width = 0;
129
+ let widthExtra = 0;
130
+ outer: while (true) {
131
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
132
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
133
+ lengthExtra = 0;
134
+ for (const char of unmatched.replaceAll(MODIFIER_RE$1, "")) {
135
+ const codePoint = char.codePointAt(0) || 0;
136
+ if (isFullWidth$1(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
137
+ else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
138
+ else widthExtra = REGULAR_WIDTH;
139
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
140
+ if (width + widthExtra > LIMIT) {
141
+ truncationEnabled = true;
142
+ break outer;
143
+ }
144
+ lengthExtra += char.length;
145
+ width += widthExtra;
146
+ }
147
+ unmatchedStart = unmatchedEnd = 0;
148
+ }
149
+ if (index >= length) break outer;
150
+ for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
151
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
152
+ BLOCK_RE.lastIndex = index;
153
+ if (BLOCK_RE.test(input)) {
154
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE$1 ? 1 : BLOCK_RE.lastIndex - index;
155
+ widthExtra = lengthExtra * BLOCK_WIDTH;
156
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
157
+ if (width + widthExtra > LIMIT) {
158
+ truncationEnabled = true;
159
+ break outer;
160
+ }
161
+ width += widthExtra;
162
+ unmatchedStart = indexPrev;
163
+ unmatchedEnd = index;
164
+ index = indexPrev = BLOCK_RE.lastIndex;
165
+ continue outer;
166
+ }
167
+ }
168
+ index += 1;
169
+ }
170
+ return {
171
+ width: truncationEnabled ? truncationLimit : width,
172
+ index: truncationEnabled ? truncationIndex : length,
173
+ truncated: truncationEnabled,
174
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
175
+ };
176
+ };
177
+ //#endregion
178
+ //#region ../../node_modules/.pnpm/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
179
+ const NO_TRUNCATION$2 = {
180
+ limit: Infinity,
181
+ ellipsis: "",
182
+ ellipsisWidth: 0
183
+ };
184
+ const fastStringWidth$1 = (input, options = {}) => {
185
+ return getStringTruncatedWidth$1(input, NO_TRUNCATION$2, options).width;
186
+ };
187
+ //#endregion
188
+ //#region ../../node_modules/.pnpm/fast-wrap-ansi@0.2.0/node_modules/fast-wrap-ansi/lib/main.js
189
+ const ESC = "\x1B";
190
+ const CSI = "›";
191
+ const END_CODE = 39;
192
+ const ANSI_ESCAPE_BELL = "\x07";
193
+ const ANSI_CSI = "[";
194
+ const ANSI_OSC = "]";
195
+ const ANSI_SGR_TERMINATOR = "m";
196
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
197
+ const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
198
+ const getClosingCode = (openingCode) => {
199
+ if (openingCode >= 30 && openingCode <= 37) return 39;
200
+ if (openingCode >= 90 && openingCode <= 97) return 39;
201
+ if (openingCode >= 40 && openingCode <= 47) return 49;
202
+ if (openingCode >= 100 && openingCode <= 107) return 49;
203
+ if (openingCode === 1 || openingCode === 2) return 22;
204
+ if (openingCode === 3) return 23;
205
+ if (openingCode === 4) return 24;
206
+ if (openingCode === 7) return 27;
207
+ if (openingCode === 8) return 28;
208
+ if (openingCode === 9) return 29;
209
+ if (openingCode === 0) return 0;
210
+ };
211
+ const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
212
+ const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
213
+ const wrapWord = (rows, word, columns) => {
214
+ const characters = word[Symbol.iterator]();
215
+ let isInsideEscape = false;
216
+ let isInsideLinkEscape = false;
217
+ let lastRow = rows.at(-1);
218
+ let visible = lastRow === void 0 ? 0 : fastStringWidth$1(lastRow);
219
+ let currentCharacter = characters.next();
220
+ let nextCharacter = characters.next();
221
+ let rawCharacterIndex = 0;
222
+ while (!currentCharacter.done) {
223
+ const character = currentCharacter.value;
224
+ const characterLength = fastStringWidth$1(character);
225
+ if (visible + characterLength <= columns) rows[rows.length - 1] += character;
226
+ else {
227
+ rows.push(character);
228
+ visible = 0;
229
+ }
230
+ if (character === ESC || character === CSI) {
231
+ isInsideEscape = true;
232
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
233
+ }
234
+ if (isInsideEscape) {
235
+ if (isInsideLinkEscape) {
236
+ if (character === ANSI_ESCAPE_BELL) {
237
+ isInsideEscape = false;
238
+ isInsideLinkEscape = false;
239
+ }
240
+ } else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
241
+ } else {
242
+ visible += characterLength;
243
+ if (visible === columns && !nextCharacter.done) {
244
+ rows.push("");
245
+ visible = 0;
246
+ }
247
+ }
248
+ currentCharacter = nextCharacter;
249
+ nextCharacter = characters.next();
250
+ rawCharacterIndex += character.length;
251
+ }
252
+ lastRow = rows.at(-1);
253
+ if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
254
+ };
255
+ const stringVisibleTrimSpacesRight = (string) => {
256
+ const words = string.split(" ");
257
+ let last = words.length;
258
+ while (last) {
259
+ if (fastStringWidth$1(words[last - 1])) break;
260
+ last--;
261
+ }
262
+ if (last === words.length) return string;
263
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
264
+ };
265
+ const exec = (string, columns, options = {}) => {
266
+ if (options.trim !== false && string.trim() === "") return "";
267
+ let returnValue = "";
268
+ let escapeCode;
269
+ let escapeUrl;
270
+ const words = string.split(" ");
271
+ let rows = [""];
272
+ let rowLength = 0;
273
+ for (let index = 0; index < words.length; index++) {
274
+ const word = words[index];
275
+ if (options.trim !== false) {
276
+ const row = rows.at(-1) ?? "";
277
+ const trimmed = row.trimStart();
278
+ if (row.length !== trimmed.length) {
279
+ rows[rows.length - 1] = trimmed;
280
+ rowLength = fastStringWidth$1(trimmed);
281
+ }
282
+ }
283
+ if (index !== 0) {
284
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
285
+ rows.push("");
286
+ rowLength = 0;
287
+ }
288
+ if (rowLength || options.trim === false) {
289
+ rows[rows.length - 1] += " ";
290
+ rowLength++;
291
+ }
292
+ }
293
+ const wordLength = fastStringWidth$1(word);
294
+ if (options.hard && wordLength > columns) {
295
+ const remainingColumns = columns - rowLength;
296
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
297
+ if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
298
+ wrapWord(rows, word, columns);
299
+ rowLength = fastStringWidth$1(rows.at(-1) ?? "");
300
+ continue;
301
+ }
302
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
303
+ if (options.wordWrap === false && rowLength < columns) {
304
+ wrapWord(rows, word, columns);
305
+ rowLength = fastStringWidth$1(rows.at(-1) ?? "");
306
+ continue;
307
+ }
308
+ rows.push("");
309
+ rowLength = 0;
310
+ }
311
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
312
+ wrapWord(rows, word, columns);
313
+ rowLength = fastStringWidth$1(rows.at(-1) ?? "");
314
+ continue;
315
+ }
316
+ rows[rows.length - 1] += word;
317
+ rowLength += wordLength;
318
+ }
319
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
320
+ const preString = rows.join("\n");
321
+ let inSurrogate = false;
322
+ for (let i = 0; i < preString.length; i++) {
323
+ const character = preString[i];
324
+ returnValue += character;
325
+ if (!inSurrogate) {
326
+ inSurrogate = character >= "\ud800" && character <= "\udbff";
327
+ if (inSurrogate) continue;
328
+ } else inSurrogate = false;
329
+ if (character === ESC || character === CSI) {
330
+ GROUP_REGEX.lastIndex = i + 1;
331
+ const groups = GROUP_REGEX.exec(preString)?.groups;
332
+ if (groups?.code !== void 0) {
333
+ const code = Number.parseFloat(groups.code);
334
+ escapeCode = code === END_CODE ? void 0 : code;
335
+ } else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
336
+ }
337
+ if (preString[i + 1] === "\n") {
338
+ if (escapeUrl) returnValue += wrapAnsiHyperlink("");
339
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
340
+ if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
341
+ } else if (character === "\n") {
342
+ if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
343
+ if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
344
+ }
345
+ }
346
+ return returnValue;
347
+ };
348
+ const CRLF_OR_LF = /\r?\n/;
349
+ function wrapAnsi(string, columns, options) {
350
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
351
+ }
352
+ //#endregion
353
+ //#region src/limit-options.ts
354
+ const trimLines = (groups, initialLineCount, startIndex, endIndex, maxLines) => {
355
+ let lineCount = initialLineCount;
356
+ let removals = 0;
357
+ for (let i = startIndex; i < endIndex; i++) {
358
+ const group = groups[i];
359
+ lineCount = lineCount - group.length;
360
+ removals++;
361
+ if (lineCount <= maxLines) break;
362
+ }
363
+ return {
364
+ lineCount,
365
+ removals
366
+ };
367
+ };
368
+ const limitOptions = (params) => {
369
+ const { cursor, options, style } = params;
370
+ const output = params.output ?? process.stdout;
371
+ const columns = getColumns(output);
372
+ const columnPadding = params.columnPadding ?? 0;
373
+ const rowPadding = params.rowPadding ?? 4;
374
+ const maxWidth = columns - columnPadding;
375
+ const rows = getRows(output);
376
+ const overflowFormat = color.dim("...");
377
+ const paramMaxItems = params.maxItems ?? Number.POSITIVE_INFINITY;
378
+ const outputMaxItems = Math.max(rows - rowPadding, 0);
379
+ const maxItems = Math.max(Math.min(paramMaxItems, outputMaxItems), 5);
380
+ let slidingWindowLocation = 0;
381
+ if (cursor >= maxItems - 3) slidingWindowLocation = Math.max(Math.min(cursor - maxItems + 3, options.length - maxItems), 0);
382
+ let shouldRenderTopEllipsis = maxItems < options.length && slidingWindowLocation > 0;
383
+ let shouldRenderBottomEllipsis = maxItems < options.length && slidingWindowLocation + maxItems < options.length;
384
+ const slidingWindowLocationEnd = Math.min(slidingWindowLocation + maxItems, options.length);
385
+ const lineGroups = [];
386
+ let lineCount = 0;
387
+ if (shouldRenderTopEllipsis) lineCount++;
388
+ if (shouldRenderBottomEllipsis) lineCount++;
389
+ const slidingWindowLocationWithEllipsis = slidingWindowLocation + (shouldRenderTopEllipsis ? 1 : 0);
390
+ const slidingWindowLocationEndWithEllipsis = slidingWindowLocationEnd - (shouldRenderBottomEllipsis ? 1 : 0);
391
+ for (let i = slidingWindowLocationWithEllipsis; i < slidingWindowLocationEndWithEllipsis; i++) {
392
+ const wrappedLines = wrapAnsi(style(options[i], i === cursor), maxWidth, {
393
+ hard: true,
394
+ trim: false
395
+ }).split("\n");
396
+ lineGroups.push(wrappedLines);
397
+ lineCount += wrappedLines.length;
398
+ }
399
+ if (lineCount > outputMaxItems) {
400
+ let precedingRemovals = 0;
401
+ let followingRemovals = 0;
402
+ let newLineCount = lineCount;
403
+ const cursorGroupIndex = cursor - slidingWindowLocationWithEllipsis;
404
+ const trimLinesLocal = (startIndex, endIndex) => trimLines(lineGroups, newLineCount, startIndex, endIndex, outputMaxItems);
405
+ if (shouldRenderTopEllipsis) {
406
+ ({lineCount: newLineCount, removals: precedingRemovals} = trimLinesLocal(0, cursorGroupIndex));
407
+ if (newLineCount > outputMaxItems) ({lineCount: newLineCount, removals: followingRemovals} = trimLinesLocal(cursorGroupIndex + 1, lineGroups.length));
408
+ } else {
409
+ ({lineCount: newLineCount, removals: followingRemovals} = trimLinesLocal(cursorGroupIndex + 1, lineGroups.length));
410
+ if (newLineCount > outputMaxItems) ({lineCount: newLineCount, removals: precedingRemovals} = trimLinesLocal(0, cursorGroupIndex));
411
+ }
412
+ if (precedingRemovals > 0) {
413
+ shouldRenderTopEllipsis = true;
414
+ lineGroups.splice(0, precedingRemovals);
415
+ }
416
+ if (followingRemovals > 0) {
417
+ shouldRenderBottomEllipsis = true;
418
+ lineGroups.splice(lineGroups.length - followingRemovals, followingRemovals);
419
+ }
420
+ }
421
+ const result = [];
422
+ if (shouldRenderTopEllipsis) result.push(overflowFormat);
423
+ for (const lineGroup of lineGroups) for (const line of lineGroup) result.push(line);
424
+ if (shouldRenderBottomEllipsis) result.push(overflowFormat);
425
+ return result;
426
+ };
427
+ //#endregion
428
+ //#region src/autocomplete.ts
429
+ function getLabel(option) {
430
+ return option.label ?? String(option.value ?? "");
431
+ }
432
+ function getFilteredOption(searchText, option) {
433
+ if (!searchText) return true;
434
+ const label = (option.label ?? String(option.value ?? "")).toLowerCase();
435
+ const hint = (option.hint ?? "").toLowerCase();
436
+ const value = String(option.value).toLowerCase();
437
+ const term = searchText.toLowerCase();
438
+ return label.includes(term) || hint.includes(term) || value.includes(term);
439
+ }
440
+ function getSelectedOptions(values, options) {
441
+ const results = [];
442
+ for (const option of options) if (values.includes(option.value)) results.push(option);
443
+ return results;
444
+ }
445
+ const withMarker$1 = (marker, label, format, firstLineSuffix = "") => {
446
+ const lines = label.split("\n");
447
+ if (lines.length === 1) return `${marker} ${format(lines[0])}${firstLineSuffix}`;
448
+ const [firstLine, ...rest] = lines;
449
+ return [`${marker} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => ` ${format(line)}`)].join("\n");
450
+ };
451
+ const withMarkerAndIndicator = (marker, indicator, indicatorWidth, label, format, firstLineSuffix = "") => {
452
+ const lines = label.split("\n");
453
+ const continuationPrefix = ` ${" ".repeat(indicatorWidth)} `;
454
+ if (lines.length === 1) return `${marker} ${indicator} ${format(lines[0])}${firstLineSuffix}`;
455
+ const [firstLine, ...rest] = lines;
456
+ return [`${marker} ${indicator} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
457
+ };
458
+ const autocomplete = (opts) => {
459
+ return new AutocompletePrompt({
460
+ options: opts.options,
461
+ initialValue: opts.initialValue ? [opts.initialValue] : void 0,
462
+ initialUserInput: opts.initialUserInput,
463
+ filter: opts.filter ?? ((search, opt) => {
464
+ return getFilteredOption(search, opt);
465
+ }),
466
+ signal: opts.signal,
467
+ input: opts.input,
468
+ output: opts.output,
469
+ validate: opts.validate,
470
+ render() {
471
+ const hasGuide = opts.withGuide ?? false;
472
+ const nestedPrefix = " ";
473
+ const headings = hasGuide ? [color.gray(S_BAR), `${symbol(this.state)} ${opts.message}`] : [`${symbol(this.state)} ${opts.message}`];
474
+ const userInput = this.userInput;
475
+ const options = this.options;
476
+ const placeholder = opts.placeholder;
477
+ const showPlaceholder = userInput === "" && placeholder !== void 0;
478
+ switch (this.state) {
479
+ case "submit": {
480
+ const selected = getSelectedOptions(this.selectedValues, options);
481
+ const label = selected.length > 0 ? color.dim(selected.map(getLabel).join(", ")) : "";
482
+ const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
483
+ return `${headings.join("\n")}\n${submitPrefix}${label}\n\n`;
484
+ }
485
+ case "cancel": {
486
+ const userInputText = userInput ? color.strikethrough(color.dim(userInput)) : "";
487
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
488
+ return `${headings.join("\n")}\n${cancelPrefix}${userInputText}\n\n`;
489
+ }
490
+ default: {
491
+ const barColor = this.state === "error" ? color.yellow : color.blue;
492
+ const guidePrefix = hasGuide ? `${barColor(S_BAR)} ` : nestedPrefix;
493
+ const guidePrefixEnd = hasGuide ? barColor(S_BAR_END) : "";
494
+ let searchText = "";
495
+ if (this.isNavigating || showPlaceholder) {
496
+ const searchTextValue = showPlaceholder ? placeholder : userInput;
497
+ searchText = searchTextValue !== "" ? ` ${color.dim(searchTextValue)}` : "";
498
+ } else searchText = ` ${this.userInputWithCursor}`;
499
+ const matches = this.filteredOptions.length !== options.length ? color.dim(` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "";
500
+ const noResults = this.filteredOptions.length === 0 && userInput ? [`${guidePrefix}${color.yellow("No matches found")}`] : [];
501
+ const validationError = this.state === "error" ? [`${guidePrefix}${color.yellow(this.error)}`] : [];
502
+ if (hasGuide) headings.push(guidePrefix.trimEnd());
503
+ headings.push(`${guidePrefix}${color.dim("Search:")}${searchText}${matches}`, ...noResults, ...validationError);
504
+ const footers = [`${guidePrefix}${[
505
+ `${color.dim("↑/↓")} to select`,
506
+ `${color.dim("Enter:")} confirm`,
507
+ `${color.dim("Type:")} to search`
508
+ ].join(" • ")}`, guidePrefixEnd];
509
+ const displayOptions = this.filteredOptions.length === 0 ? [] : limitOptions({
510
+ cursor: this.cursor,
511
+ options: this.filteredOptions,
512
+ columnPadding: hasGuide ? 2 : 2,
513
+ rowPadding: headings.length + footers.length,
514
+ style: (option, active) => {
515
+ const label = getLabel(option);
516
+ const hint = option.hint && option.value === this.focusedValue ? color.gray(` (${option.hint})`) : "";
517
+ return active ? withMarker$1(color.blue(S_POINTER_ACTIVE), label, (text) => color.blue(color.bold(text)), hint) : withMarker$1(color.dim(" "), label, color.dim, hint);
518
+ },
519
+ maxItems: opts.maxItems,
520
+ output: opts.output
521
+ });
522
+ return [
523
+ ...headings,
524
+ ...displayOptions.map((option) => `${guidePrefix}${option}`),
525
+ ...footers
526
+ ].join("\n");
527
+ }
528
+ }
529
+ }
530
+ }).prompt();
531
+ };
532
+ /**
533
+ * Integrated autocomplete multiselect - combines type-ahead filtering with multiselect in one UI
534
+ */
535
+ const autocompleteMultiselect = (opts) => {
536
+ const formatOption = (option, active, selectedValues, focusedValue) => {
537
+ const isSelected = selectedValues.includes(option.value);
538
+ const label = option.label ?? String(option.value ?? "");
539
+ const hint = option.hint && focusedValue !== void 0 && option.value === focusedValue ? color.gray(` (${option.hint})`) : "";
540
+ const checkboxRaw = isSelected ? S_CHECKBOX_SELECTED : S_CHECKBOX_INACTIVE;
541
+ const checkbox = isSelected ? color.blue(checkboxRaw) : color.dim(checkboxRaw);
542
+ const marker = active ? color.blue(S_POINTER_ACTIVE) : color.dim(" ");
543
+ return withMarkerAndIndicator(marker, checkbox, checkboxRaw.length, label, active ? (text) => color.blue(color.bold(text)) : color.dim, hint);
544
+ };
545
+ const prompt = new AutocompletePrompt({
546
+ options: opts.options,
547
+ multiple: true,
548
+ filter: opts.filter ?? ((search, opt) => {
549
+ return getFilteredOption(search, opt);
550
+ }),
551
+ validate: () => {
552
+ if (opts.required && prompt.selectedValues.length === 0) return "Please select at least one item";
553
+ },
554
+ initialValue: opts.initialValues,
555
+ signal: opts.signal,
556
+ input: opts.input,
557
+ output: opts.output,
558
+ render() {
559
+ const hasGuide = opts.withGuide ?? false;
560
+ const nestedPrefix = " ";
561
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
562
+ const userInput = this.userInput;
563
+ const placeholder = opts.placeholder;
564
+ const showPlaceholder = userInput === "" && placeholder !== void 0;
565
+ const searchText = this.isNavigating || showPlaceholder ? color.dim(showPlaceholder ? placeholder : userInput) : this.userInputWithCursor;
566
+ const options = this.options;
567
+ const matches = this.filteredOptions.length !== options.length ? color.dim(` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "";
568
+ switch (this.state) {
569
+ case "submit": {
570
+ const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : "";
571
+ return `${title}${hasGuide ? submitPrefix : nestedPrefix}${color.dim(`${this.selectedValues.length} items selected`)}\n\n`;
572
+ }
573
+ case "cancel": {
574
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : "";
575
+ return `${title}${hasGuide ? cancelPrefix : nestedPrefix}${color.strikethrough(color.dim(userInput))}\n\n`;
576
+ }
577
+ default: {
578
+ const barColor = this.state === "error" ? color.yellow : color.blue;
579
+ const prefix = hasGuide ? `${barColor(S_BAR)} ` : nestedPrefix;
580
+ const footerEnd = hasGuide ? [barColor(S_BAR_END)] : [];
581
+ const instructions = [
582
+ `${color.dim("↑/↓")} to navigate`,
583
+ `${color.dim(this.isNavigating ? "Space/Tab:" : "Tab:")} select`,
584
+ `${color.dim("Enter:")} confirm`,
585
+ `${color.dim("Type:")} to search`
586
+ ];
587
+ const noResults = this.filteredOptions.length === 0 && userInput ? [`${prefix}${color.yellow("No matches found")}`] : [];
588
+ const errorMessage = this.state === "error" ? [`${prefix}${color.yellow(this.error)}`] : [];
589
+ const headerLines = [
590
+ ...title.trimEnd().split("\n"),
591
+ `${prefix}${color.dim("Search:")} ${searchText}${matches}`,
592
+ ...noResults,
593
+ ...errorMessage
594
+ ];
595
+ const footerLines = [`${prefix}${instructions.join(" • ")}`, ...footerEnd];
596
+ const displayOptions = limitOptions({
597
+ cursor: this.cursor,
598
+ options: this.filteredOptions,
599
+ style: (option, active) => formatOption(option, active, this.selectedValues, this.focusedValue),
600
+ maxItems: opts.maxItems,
601
+ output: opts.output,
602
+ rowPadding: headerLines.length + footerLines.length
603
+ });
604
+ return [
605
+ ...headerLines,
606
+ ...displayOptions.map((option) => `${prefix}${option}`),
607
+ ...footerLines
608
+ ].join("\n");
609
+ }
610
+ }
611
+ }
612
+ });
613
+ return prompt.prompt();
614
+ };
615
+ //#endregion
616
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/utils.js
617
+ const isAmbiguous = (x) => {
618
+ return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
619
+ };
620
+ const isFullWidth = (x) => {
621
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
622
+ };
623
+ const isWide = (x) => {
624
+ return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9800 && x <= 9811 || x === 9855 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || 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 >= 19968 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101632 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129672 || x >= 129680 && x <= 129725 || x >= 129727 && x <= 129733 || x >= 129742 && x <= 129755 || x >= 129760 && x <= 129768 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
625
+ };
626
+ //#endregion
627
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/index.js
628
+ const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
629
+ const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
630
+ const TAB_RE = /\t{1,1000}/y;
631
+ 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;
632
+ const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
633
+ const MODIFIER_RE = /\p{M}+/gu;
634
+ const NO_TRUNCATION$1 = {
635
+ limit: Infinity,
636
+ ellipsis: ""
637
+ };
638
+ const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
639
+ const LIMIT = truncationOptions.limit ?? Infinity;
640
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
641
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
642
+ const ANSI_WIDTH = widthOptions.ansiWidth ?? 0;
643
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
644
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
645
+ const AMBIGUOUS_WIDTH = widthOptions.ambiguousWidth ?? 1;
646
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
647
+ const FULL_WIDTH_WIDTH = widthOptions.fullWidthWidth ?? 2;
648
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
649
+ const WIDE_WIDTH = widthOptions.wideWidth ?? 2;
650
+ let indexPrev = 0;
651
+ let index = 0;
652
+ let length = input.length;
653
+ let lengthExtra = 0;
654
+ let truncationEnabled = false;
655
+ let truncationIndex = length;
656
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
657
+ let unmatchedStart = 0;
658
+ let unmatchedEnd = 0;
659
+ let width = 0;
660
+ let widthExtra = 0;
661
+ outer: while (true) {
662
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
663
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
664
+ lengthExtra = 0;
665
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
666
+ const codePoint = char.codePointAt(0) || 0;
667
+ if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
668
+ else if (isWide(codePoint)) widthExtra = WIDE_WIDTH;
669
+ else if (AMBIGUOUS_WIDTH !== REGULAR_WIDTH && isAmbiguous(codePoint)) widthExtra = AMBIGUOUS_WIDTH;
670
+ else widthExtra = REGULAR_WIDTH;
671
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
672
+ if (width + widthExtra > LIMIT) {
673
+ truncationEnabled = true;
674
+ break outer;
675
+ }
676
+ lengthExtra += char.length;
677
+ width += widthExtra;
678
+ }
679
+ unmatchedStart = unmatchedEnd = 0;
680
+ }
681
+ if (index >= length) break;
682
+ LATIN_RE.lastIndex = index;
683
+ if (LATIN_RE.test(input)) {
684
+ lengthExtra = LATIN_RE.lastIndex - index;
685
+ widthExtra = lengthExtra * REGULAR_WIDTH;
686
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / REGULAR_WIDTH));
687
+ if (width + widthExtra > LIMIT) {
688
+ truncationEnabled = true;
689
+ break;
690
+ }
691
+ width += widthExtra;
692
+ unmatchedStart = indexPrev;
693
+ unmatchedEnd = index;
694
+ index = indexPrev = LATIN_RE.lastIndex;
695
+ continue;
696
+ }
697
+ ANSI_RE.lastIndex = index;
698
+ if (ANSI_RE.test(input)) {
699
+ if (width + ANSI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
700
+ if (width + ANSI_WIDTH > LIMIT) {
701
+ truncationEnabled = true;
702
+ break;
703
+ }
704
+ width += ANSI_WIDTH;
705
+ unmatchedStart = indexPrev;
706
+ unmatchedEnd = index;
707
+ index = indexPrev = ANSI_RE.lastIndex;
708
+ continue;
709
+ }
710
+ CONTROL_RE.lastIndex = index;
711
+ if (CONTROL_RE.test(input)) {
712
+ lengthExtra = CONTROL_RE.lastIndex - index;
713
+ widthExtra = lengthExtra * CONTROL_WIDTH;
714
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / CONTROL_WIDTH));
715
+ if (width + widthExtra > LIMIT) {
716
+ truncationEnabled = true;
717
+ break;
718
+ }
719
+ width += widthExtra;
720
+ unmatchedStart = indexPrev;
721
+ unmatchedEnd = index;
722
+ index = indexPrev = CONTROL_RE.lastIndex;
723
+ continue;
724
+ }
725
+ TAB_RE.lastIndex = index;
726
+ if (TAB_RE.test(input)) {
727
+ lengthExtra = TAB_RE.lastIndex - index;
728
+ widthExtra = lengthExtra * TAB_WIDTH;
729
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / TAB_WIDTH));
730
+ if (width + widthExtra > LIMIT) {
731
+ truncationEnabled = true;
732
+ break;
733
+ }
734
+ width += widthExtra;
735
+ unmatchedStart = indexPrev;
736
+ unmatchedEnd = index;
737
+ index = indexPrev = TAB_RE.lastIndex;
738
+ continue;
739
+ }
740
+ EMOJI_RE.lastIndex = index;
741
+ if (EMOJI_RE.test(input)) {
742
+ if (width + EMOJI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
743
+ if (width + EMOJI_WIDTH > LIMIT) {
744
+ truncationEnabled = true;
745
+ break;
746
+ }
747
+ width += EMOJI_WIDTH;
748
+ unmatchedStart = indexPrev;
749
+ unmatchedEnd = index;
750
+ index = indexPrev = EMOJI_RE.lastIndex;
751
+ continue;
752
+ }
753
+ index += 1;
754
+ }
755
+ return {
756
+ width: truncationEnabled ? truncationLimit : width,
757
+ index: truncationEnabled ? truncationIndex : length,
758
+ truncated: truncationEnabled,
759
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
760
+ };
761
+ };
762
+ //#endregion
763
+ //#region ../../node_modules/.pnpm/fast-string-width@1.1.0/node_modules/fast-string-width/dist/index.js
764
+ const NO_TRUNCATION = {
765
+ limit: Infinity,
766
+ ellipsis: "",
767
+ ellipsisWidth: 0
768
+ };
769
+ const fastStringWidth = (input, options = {}) => {
770
+ return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
771
+ };
772
+ //#endregion
773
+ //#region src/box.ts
774
+ const roundedSymbols = [
775
+ S_CORNER_TOP_LEFT,
776
+ S_CORNER_TOP_RIGHT,
777
+ S_CORNER_BOTTOM_LEFT,
778
+ S_CORNER_BOTTOM_RIGHT
779
+ ];
780
+ const squareSymbols = [
781
+ S_BAR_START,
782
+ S_BAR_START_RIGHT,
783
+ S_BAR_END,
784
+ S_BAR_END_RIGHT
785
+ ];
786
+ function getPaddingForLine(lineLength, innerWidth, padding, contentAlign) {
787
+ let leftPadding = padding;
788
+ let rightPadding = padding;
789
+ if (contentAlign === "center") leftPadding = Math.floor((innerWidth - lineLength) / 2);
790
+ else if (contentAlign === "right") leftPadding = innerWidth - lineLength - padding;
791
+ rightPadding = innerWidth - leftPadding - lineLength;
792
+ return [leftPadding, rightPadding];
793
+ }
794
+ const defaultFormatBorder = (text) => text;
795
+ const box = (message = "", title = "", opts) => {
796
+ const output = opts?.output ?? process.stdout;
797
+ const columns = getColumns(output);
798
+ const borderTotalWidth = 2;
799
+ const titlePadding = opts?.titlePadding ?? 1;
800
+ const contentPadding = opts?.contentPadding ?? 2;
801
+ const width = opts?.width === void 0 || opts.width === "auto" ? 1 : Math.min(1, opts.width);
802
+ const linePrefix = !(opts?.withGuide ?? false) ? "" : `${S_BAR} `;
803
+ const formatBorder = opts?.formatBorder ?? defaultFormatBorder;
804
+ const symbols = (opts?.rounded ? roundedSymbols : squareSymbols).map(formatBorder);
805
+ const hSymbol = formatBorder(S_BAR_H);
806
+ const vSymbol = formatBorder(S_BAR);
807
+ const linePrefixWidth = fastStringWidth(linePrefix);
808
+ const titleWidth = fastStringWidth(title);
809
+ const maxBoxWidth = columns - linePrefixWidth;
810
+ let boxWidth = Math.floor(columns * width) - linePrefixWidth;
811
+ if (opts?.width === "auto") {
812
+ const lines = message.split("\n");
813
+ let longestLine = titleWidth + titlePadding * 2;
814
+ for (const line of lines) {
815
+ const lineWithPadding = fastStringWidth(line) + contentPadding * 2;
816
+ if (lineWithPadding > longestLine) longestLine = lineWithPadding;
817
+ }
818
+ const longestLineWidth = longestLine + borderTotalWidth;
819
+ if (longestLineWidth < boxWidth) boxWidth = longestLineWidth;
820
+ }
821
+ if (boxWidth % 2 !== 0) {
822
+ if (boxWidth < maxBoxWidth) boxWidth++;
823
+ else boxWidth--;
824
+ }
825
+ const innerWidth = boxWidth - borderTotalWidth;
826
+ const maxTitleLength = innerWidth - titlePadding * 2;
827
+ const truncatedTitle = titleWidth > maxTitleLength ? `${title.slice(0, maxTitleLength - 3)}...` : title;
828
+ const [titlePaddingLeft, titlePaddingRight] = getPaddingForLine(fastStringWidth(truncatedTitle), innerWidth, titlePadding, opts?.titleAlign);
829
+ const wrappedMessage = wrapAnsi(message, innerWidth - contentPadding * 2, {
830
+ hard: true,
831
+ trim: false
832
+ });
833
+ output.write(`${linePrefix}${symbols[0]}${hSymbol.repeat(titlePaddingLeft)}${truncatedTitle}${hSymbol.repeat(titlePaddingRight)}${symbols[1]}\n`);
834
+ const wrappedLines = wrappedMessage.split("\n");
835
+ for (const line of wrappedLines) {
836
+ const [leftLinePadding, rightLinePadding] = getPaddingForLine(fastStringWidth(line), innerWidth, contentPadding, opts?.contentAlign);
837
+ output.write(`${linePrefix}${vSymbol}${" ".repeat(leftLinePadding)}${line}${" ".repeat(rightLinePadding)}${vSymbol}\n`);
838
+ }
839
+ output.write(`${linePrefix}${symbols[2]}${hSymbol.repeat(innerWidth)}${symbols[3]}\n`);
840
+ };
841
+ //#endregion
842
+ //#region src/milestone.ts
843
+ /**
844
+ * Render-milestone markers for the PTY snapshot suite
845
+ * (crates/vp_cli_snapshots): invisible window-title updates the runner
846
+ * synchronizes on via `expect-milestone` interactions. Emission is gated on
847
+ * `VP_EMIT_MILESTONES=1`, which only the runner sets; real terminals and
848
+ * piped output never see these markers as content (they only update the
849
+ * window title, which the runner's PTY captures).
850
+ *
851
+ * Protocol (shared with vite-task's `pty_terminal_test_client` crate):
852
+ * `OSC 2 ; pty-terminal-test:<32-hex-id>:<base64url(name)> ST`. The runner
853
+ * decodes the title with `decode_milestone_title`, ignoring ordinary title
854
+ * updates. A fresh random id per emission keeps repeated milestones with the
855
+ * same name observable as distinct title changes through Windows ConPTY.
856
+ */
857
+ const MILESTONE_TITLE_MARKER = "pty-terminal-test:";
858
+ const OSC2_OPEN = "\x1B]2;";
859
+ const ST = "\x1B\\";
860
+ const MILESTONES_ENABLED = process.env.VP_EMIT_MILESTONES === "1";
861
+ /**
862
+ * Returns the encoded milestone byte sequence for `name`, or an empty string
863
+ * when emission is disabled. Append the result to a rendered prompt frame so
864
+ * the marker arrives in the output stream together with the render it marks.
865
+ */
866
+ function milestone(name) {
867
+ if (!MILESTONES_ENABLED) return "";
868
+ const id = randomBytes(16).toString("hex");
869
+ const encodedName = Buffer.from(name, "utf8").toString("base64url");
870
+ return `${OSC2_OPEN}${MILESTONE_TITLE_MARKER}${id}:${encodedName}${ST}`;
871
+ }
872
+ /**
873
+ * Milestone for a prompt render, following the runner naming convention
874
+ * `<kind>:<id>:<state>` (e.g. `select:template:1`, `confirm:approve:yes`,
875
+ * `text:project-name:my-app`). `id` defaults to the prompt kind; pass
876
+ * `testId` at ambiguous call sites (multiple prompts of one kind in a flow).
877
+ */
878
+ function promptMilestone(kind, id, state) {
879
+ return milestone(`${kind}:${id ?? kind}:${state}`);
880
+ }
881
+ //#endregion
882
+ //#region src/confirm.ts
883
+ const confirm = (opts) => {
884
+ const active = opts.active ?? "Yes";
885
+ const inactive = opts.inactive ?? "No";
886
+ return new ConfirmPrompt({
887
+ active,
888
+ inactive,
889
+ signal: opts.signal,
890
+ input: opts.input,
891
+ output: opts.output,
892
+ initialValue: opts.initialValue ?? true,
893
+ render() {
894
+ const hasGuide = opts.withGuide ?? false;
895
+ const nestedPrefix = " ";
896
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
897
+ const value = this.value ? active : inactive;
898
+ switch (this.state) {
899
+ case "submit": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${color.dim(value)}\n${promptMilestone("confirm", opts.testId, "submit")}`;
900
+ case "cancel": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${color.strikethrough(color.dim(value))}${hasGuide ? `\n${color.gray(S_BAR)}` : ""}\n${promptMilestone("confirm", opts.testId, "cancel")}`;
901
+ default: {
902
+ const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
903
+ const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
904
+ return `${title}${defaultPrefix}${this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(active)}` : `${color.dim(" ")} ${color.dim(active)}`}${opts.vertical ? hasGuide ? `\n${color.blue(S_BAR)} ` : `\n${nestedPrefix}` : ` ${color.dim("/")} `}${!this.value ? `${color.blue(S_POINTER_ACTIVE)} ${color.bold(inactive)}` : `${color.dim(" ")} ${color.dim(inactive)}`}\n${defaultPrefixEnd}\n${promptMilestone("confirm", opts.testId, this.value ? "yes" : "no")}`;
905
+ }
906
+ }
907
+ }
908
+ }).prompt();
909
+ };
910
+ //#endregion
911
+ //#region src/group.ts
912
+ /**
913
+ * Define a group of prompts to be displayed
914
+ * and return a results of objects within the group
915
+ */
916
+ const group = async (prompts, opts) => {
917
+ const results = {};
918
+ const promptNames = Object.keys(prompts);
919
+ for (const name of promptNames) {
920
+ const prompt = prompts[name];
921
+ const result = await prompt({ results })?.catch((e) => {
922
+ throw e;
923
+ });
924
+ if (typeof opts?.onCancel === "function" && isCancel$1(result)) {
925
+ results[name] = "canceled";
926
+ opts.onCancel({ results });
927
+ continue;
928
+ }
929
+ results[name] = result;
930
+ }
931
+ return results;
932
+ };
933
+ //#endregion
934
+ //#region src/group-multi-select.ts
935
+ const groupMultiselect = (opts) => {
936
+ const { selectableGroups = true, groupSpacing = 0 } = opts;
937
+ const hasGuide = opts.withGuide ?? false;
938
+ const nestedPrefix = " ";
939
+ const withMarkerAndPrefix = (marker, prefix, prefixWidth, label, format, firstLineSuffix = "", spacingPrefix = "") => {
940
+ const lines = label.split("\n");
941
+ const continuationPrefix = ` ${" ".repeat(prefixWidth)}`;
942
+ if (lines.length === 1) return `${spacingPrefix}${marker} ${prefix}${format(lines[0])}${firstLineSuffix}`;
943
+ const [firstLine, ...rest] = lines;
944
+ return [`${spacingPrefix}${marker} ${prefix}${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
945
+ };
946
+ const opt = (option, state, options = []) => {
947
+ const label = option.label ?? String(option.value);
948
+ const hint = option.hint ? ` ${color.gray(`(${option.hint})`)}` : "";
949
+ const isItem = typeof option.group === "string";
950
+ const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
951
+ const isLast = isItem && next && next.group === true;
952
+ const branchPrefixRaw = isItem ? selectableGroups ? `${isLast ? S_BAR_END : S_BAR} ` : " " : "";
953
+ let spacingPrefix = "";
954
+ if (groupSpacing > 0 && !isItem) {
955
+ const spacingPrefixText = hasGuide ? `\n${color.blue(S_BAR)}` : "\n";
956
+ const spacingSuffix = hasGuide ? " " : "";
957
+ spacingPrefix = `${spacingPrefixText.repeat(groupSpacing - 1)}${spacingPrefixText}${spacingSuffix}`;
958
+ }
959
+ if (state === "cancelled") return color.strikethrough(color.dim(label));
960
+ if (state === "submitted") return color.dim(label);
961
+ const marker = state === "active" || state === "active-selected" ? color.blue(S_POINTER_ACTIVE) : color.dim(" ");
962
+ const branchPrefix = color.dim(branchPrefixRaw);
963
+ const hasCheckbox = isItem || selectableGroups;
964
+ const checkboxRaw = hasCheckbox ? state === "active" || state === "group-active" ? S_CHECKBOX_ACTIVE : state === "selected" || state === "active-selected" || state === "group-active-selected" ? S_CHECKBOX_SELECTED : S_CHECKBOX_INACTIVE : "";
965
+ const checkbox = hasCheckbox ? checkboxRaw === S_CHECKBOX_SELECTED ? color.blue(checkboxRaw) : checkboxRaw === S_CHECKBOX_ACTIVE ? color.blue(checkboxRaw) : color.dim(checkboxRaw) : "";
966
+ const format = state === "active" || state === "active-selected" ? (text) => color.blue(color.bold(text)) : color.dim;
967
+ const styledPrefix = `${branchPrefix}${hasCheckbox ? `${checkbox} ` : ""}`;
968
+ const prefixWidth = branchPrefixRaw.length + (hasCheckbox ? checkboxRaw.length + 1 : 0);
969
+ return withMarkerAndPrefix(marker, styledPrefix, prefixWidth, label, format, hint, spacingPrefix);
970
+ };
971
+ const required = opts.required ?? true;
972
+ return new GroupMultiSelectPrompt({
973
+ options: opts.options,
974
+ signal: opts.signal,
975
+ input: opts.input,
976
+ output: opts.output,
977
+ initialValues: opts.initialValues,
978
+ required,
979
+ cursorAt: opts.cursorAt,
980
+ selectableGroups,
981
+ validate(selected) {
982
+ if (required && (selected === void 0 || selected.length === 0)) return `Please select at least one option.\n${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`))}`;
983
+ },
984
+ render() {
985
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
986
+ const value = this.value ?? [];
987
+ switch (this.state) {
988
+ case "submit": {
989
+ const selectedOptions = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "submitted"));
990
+ return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${selectedOptions.length === 0 ? "" : selectedOptions.join(color.dim(", "))}\n\n`;
991
+ }
992
+ case "cancel": {
993
+ const label = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
994
+ if (!label.trim()) return hasGuide ? `${title}${color.gray(S_BAR)}\n\n` : `${title.trimEnd()}\n\n`;
995
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
996
+ return hasGuide ? `${title}${cancelPrefix}${label}\n${color.gray(S_BAR)}\n\n` : `${title}${cancelPrefix}${label}\n\n`;
997
+ }
998
+ case "error": {
999
+ const prefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
1000
+ const footer = hasGuide ? this.error.split("\n").map((ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`).join("\n") : `${nestedPrefix}${color.yellow(this.error)}`;
1001
+ return `${title}${prefix}${this.options.map((option, i, options) => {
1002
+ const selected = value.includes(option.value) || option.group === true && this.isGroupSelected(String(option.value));
1003
+ const active = i === this.cursor;
1004
+ if (!active && typeof option.group === "string" && this.options[this.cursor].value === option.group) return opt(option, selected ? "group-active-selected" : "group-active", options);
1005
+ if (active && selected) return opt(option, "active-selected", options);
1006
+ if (selected) return opt(option, "selected", options);
1007
+ return opt(option, active ? "active" : "inactive", options);
1008
+ }).join(`\n${prefix}`)}\n${footer}\n`;
1009
+ }
1010
+ default: {
1011
+ const optionsText = this.options.map((option, i, options) => {
1012
+ const selected = value.includes(option.value) || option.group === true && this.isGroupSelected(String(option.value));
1013
+ const active = i === this.cursor;
1014
+ const groupActive = !active && typeof option.group === "string" && this.options[this.cursor].value === option.group;
1015
+ let optionText = "";
1016
+ if (groupActive) optionText = opt(option, selected ? "group-active-selected" : "group-active", options);
1017
+ else if (active && selected) optionText = opt(option, "active-selected", options);
1018
+ else if (selected) optionText = opt(option, "selected", options);
1019
+ else optionText = opt(option, active ? "active" : "inactive", options);
1020
+ return `${i !== 0 && !optionText.startsWith("\n") ? " " : ""}${optionText}`;
1021
+ }).join(hasGuide ? `\n${color.blue(S_BAR)}` : "\n");
1022
+ const optionsPrefix = optionsText.startsWith("\n") ? "" : nestedPrefix;
1023
+ return `${title}${hasGuide ? color.blue(S_BAR) : ""}${optionsPrefix}${optionsText}\n${hasGuide ? color.blue(S_BAR_END) : ""}\n`;
1024
+ }
1025
+ }
1026
+ }
1027
+ }).prompt();
1028
+ };
1029
+ //#endregion
1030
+ //#region src/log.ts
1031
+ const log = {
1032
+ message: (message = [], { symbol = color.gray(S_BAR), secondarySymbol = color.gray(S_BAR), output = process.stdout, spacing = 1, withGuide } = {}) => {
1033
+ const parts = [];
1034
+ const hasGuide = withGuide ?? false;
1035
+ const spacingString = !hasGuide ? "" : secondarySymbol;
1036
+ const prefix = !hasGuide ? "" : `${symbol} `;
1037
+ const secondaryPrefix = !hasGuide ? "" : `${secondarySymbol} `;
1038
+ for (let i = 0; i < spacing; i++) parts.push(spacingString);
1039
+ const messageParts = Array.isArray(message) ? message : message.split("\n");
1040
+ if (messageParts.length > 0) {
1041
+ const [firstLine, ...lines] = messageParts;
1042
+ if (firstLine.length > 0) parts.push(`${prefix}${firstLine}`);
1043
+ else parts.push(hasGuide ? symbol : "");
1044
+ for (const ln of lines) if (ln.length > 0) parts.push(`${secondaryPrefix}${ln}`);
1045
+ else parts.push(hasGuide ? secondarySymbol : "");
1046
+ }
1047
+ output.write(`${parts.join("\n")}\n`);
1048
+ },
1049
+ info: (message, opts) => {
1050
+ log.message(message, {
1051
+ ...opts,
1052
+ symbol: color.blue(S_INFO)
1053
+ });
1054
+ },
1055
+ success: (message, opts) => {
1056
+ log.message(message, {
1057
+ ...opts,
1058
+ symbol: completeColor(S_SUCCESS)
1059
+ });
1060
+ },
1061
+ step: (message, opts) => {
1062
+ log.message(message, {
1063
+ ...opts,
1064
+ symbol: completeColor(S_STEP_SUBMIT)
1065
+ });
1066
+ },
1067
+ warn: (message, opts) => {
1068
+ log.message(message, {
1069
+ ...opts,
1070
+ symbol: color.yellow(S_WARN)
1071
+ });
1072
+ },
1073
+ /** alias for `log.warn()`. */
1074
+ warning: (message, opts) => {
1075
+ log.warn(message, opts);
1076
+ },
1077
+ error: (message, opts) => {
1078
+ log.message(message, {
1079
+ ...opts,
1080
+ symbol: color.red(S_ERROR)
1081
+ });
1082
+ }
1083
+ };
1084
+ //#endregion
1085
+ //#region src/messages.ts
1086
+ const cancel = (message = "", opts) => {
1087
+ (opts?.output ?? process.stdout).write(`${color.red(message)}\n\n`);
1088
+ };
1089
+ const intro = (title = "", opts) => {
1090
+ (opts?.output ?? process.stdout).write(`${title}\n\n`);
1091
+ };
1092
+ const outro = (message = "", opts) => {
1093
+ (opts?.output ?? process.stdout).write(`${message}\n\n`);
1094
+ };
1095
+ //#endregion
1096
+ //#region src/multi-select.ts
1097
+ const computeLabel$1 = (label, format) => {
1098
+ return label.split("\n").map((line) => format(line)).join("\n");
1099
+ };
1100
+ const withMarkerAndCheckbox = (marker, checkbox, checkboxWidth, label, format, firstLineSuffix = "") => {
1101
+ const lines = label.split("\n");
1102
+ const continuationPrefix = ` ${" ".repeat(checkboxWidth)} `;
1103
+ if (lines.length === 1) return `${marker} ${checkbox} ${format(lines[0])}${firstLineSuffix}`;
1104
+ const [firstLine, ...rest] = lines;
1105
+ return [`${marker} ${checkbox} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => `${continuationPrefix}${format(line)}`)].join("\n");
1106
+ };
1107
+ const multiselect = (opts) => {
1108
+ const opt = (option, state) => {
1109
+ const label = option.label ?? String(option.value);
1110
+ const hint = option.hint ? ` ${color.gray(`(${option.hint})`)}` : "";
1111
+ if (state === "disabled") return withMarkerAndCheckbox(color.gray(" "), color.gray(S_CHECKBOX_INACTIVE), S_CHECKBOX_INACTIVE.length, label, (str) => color.strikethrough(color.gray(str)), option.hint ? ` ${color.dim(`(${option.hint ?? "disabled"})`)}` : "");
1112
+ if (state === "active") return withMarkerAndCheckbox(color.blue(S_POINTER_ACTIVE), color.blue(S_CHECKBOX_ACTIVE), S_CHECKBOX_ACTIVE.length, label, (text) => color.blue(color.bold(text)), hint);
1113
+ if (state === "selected") return withMarkerAndCheckbox(color.dim(" "), color.blue(S_CHECKBOX_SELECTED), S_CHECKBOX_SELECTED.length, label, color.dim, hint);
1114
+ if (state === "cancelled") return computeLabel$1(label, (text) => color.strikethrough(color.dim(text)));
1115
+ if (state === "active-selected") return withMarkerAndCheckbox(color.blue(S_POINTER_ACTIVE), color.blue(S_CHECKBOX_SELECTED), S_CHECKBOX_SELECTED.length, label, (text) => color.blue(color.bold(text)), hint);
1116
+ if (state === "submitted") return computeLabel$1(label, color.dim);
1117
+ return withMarkerAndCheckbox(color.dim(" "), color.dim(S_CHECKBOX_INACTIVE), S_CHECKBOX_INACTIVE.length, label, color.dim);
1118
+ };
1119
+ const required = opts.required ?? true;
1120
+ const hint = " " + color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`));
1121
+ return new MultiSelectPrompt({
1122
+ options: opts.options,
1123
+ signal: opts.signal,
1124
+ input: opts.input,
1125
+ output: opts.output,
1126
+ initialValues: opts.initialValues,
1127
+ required,
1128
+ cursorAt: opts.cursorAt,
1129
+ validate(selected) {
1130
+ if (required && (selected === void 0 || selected.length === 0)) return `Please select at least one option.\n${hint}`;
1131
+ },
1132
+ render() {
1133
+ const hasGuide = opts.withGuide ?? false;
1134
+ const nestedPrefix = " ";
1135
+ const formatMessageLines = (message) => {
1136
+ return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
1137
+ };
1138
+ const wrappedMessage = hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
1139
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${wrappedMessage}\n`;
1140
+ const value = this.value ?? [];
1141
+ const styleOption = (option, active) => {
1142
+ if (option.disabled) return opt(option, "disabled");
1143
+ const selected = value.includes(option.value);
1144
+ if (active && selected) return opt(option, "active-selected");
1145
+ if (selected) return opt(option, "selected");
1146
+ return opt(option, active ? "active" : "inactive");
1147
+ };
1148
+ switch (this.state) {
1149
+ case "submit": {
1150
+ const submitText = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "submitted")).join(color.dim(", ")) || color.dim("none");
1151
+ const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1152
+ return `${title}${wrapTextWithPrefix(opts.output, submitText, submitPrefix)}\n`;
1153
+ }
1154
+ case "cancel": {
1155
+ const label = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
1156
+ if (label.trim() === "") return hasGuide ? `${title}${color.gray(S_BAR)}\n` : `${title.trimEnd()}\n`;
1157
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1158
+ const wrappedLabel = wrapTextWithPrefix(opts.output, label, cancelPrefix);
1159
+ return hasGuide ? `${title}${wrappedLabel}\n${color.gray(S_BAR)}\n` : `${title}${wrappedLabel}\n`;
1160
+ }
1161
+ case "error": {
1162
+ const prefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
1163
+ const footer = hasGuide ? this.error.split("\n").map((ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`).join("\n") : `${nestedPrefix}${color.yellow(this.error)}`;
1164
+ const titleLineCount = title.split("\n").length;
1165
+ const footerLineCount = footer.split("\n").length + 1;
1166
+ return `${title}${prefix}${limitOptions({
1167
+ output: opts.output,
1168
+ options: this.options,
1169
+ cursor: this.cursor,
1170
+ maxItems: opts.maxItems,
1171
+ columnPadding: prefix.length,
1172
+ rowPadding: titleLineCount + footerLineCount,
1173
+ style: styleOption
1174
+ }).join(`\n${prefix}`)}\n${hint}\n${footer}\n`;
1175
+ }
1176
+ default: {
1177
+ const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
1178
+ const titleLineCount = title.split("\n").length;
1179
+ const footerLineCount = hasGuide ? 2 : 1;
1180
+ return `${title}${prefix}${limitOptions({
1181
+ output: opts.output,
1182
+ options: this.options,
1183
+ cursor: this.cursor,
1184
+ maxItems: opts.maxItems,
1185
+ columnPadding: prefix.length,
1186
+ rowPadding: titleLineCount + footerLineCount,
1187
+ style: styleOption
1188
+ }).join(`\n${prefix}`)}\n${hint}\n${hasGuide ? color.blue(S_BAR_END) : ""}\n`;
1189
+ }
1190
+ }
1191
+ }
1192
+ }).prompt();
1193
+ };
1194
+ //#endregion
1195
+ //#region src/note.ts
1196
+ const defaultNoteFormatter = (line) => color.dim(line);
1197
+ const wrapWithFormat = (message, width, format) => {
1198
+ const opts = {
1199
+ hard: true,
1200
+ trim: false
1201
+ };
1202
+ const wrapMsg = wrapAnsi(message, width, opts).split("\n");
1203
+ const maxWidthNormal = wrapMsg.reduce((sum, ln) => Math.max(fastStringWidth(ln), sum), 0);
1204
+ return wrapAnsi(message, width - (wrapMsg.map(format).reduce((sum, ln) => Math.max(fastStringWidth(ln), sum), 0) - maxWidthNormal), opts);
1205
+ };
1206
+ const note = (message = "", title = "", opts) => {
1207
+ const output = opts?.output ?? process$1.stdout;
1208
+ const hasGuide = opts?.withGuide ?? false;
1209
+ const format = opts?.format ?? defaultNoteFormatter;
1210
+ const lines = [
1211
+ "",
1212
+ ...wrapWithFormat(message, getColumns(output) - 6, format).split("\n").map(format),
1213
+ ""
1214
+ ];
1215
+ const titleLen = fastStringWidth(title);
1216
+ const len = Math.max(lines.reduce((sum, ln) => {
1217
+ const width = fastStringWidth(ln);
1218
+ return width > sum ? width : sum;
1219
+ }, 0), titleLen) + 2;
1220
+ const lineSymbol = hasGuide ? color.gray(S_BAR) : " ";
1221
+ const msg = lines.map((ln) => `${lineSymbol} ${ln}${" ".repeat(len - fastStringWidth(ln))}${lineSymbol}`).join("\n");
1222
+ const leadingBorder = hasGuide ? `${color.gray(S_BAR)}\n` : "";
1223
+ const bottomLeft = hasGuide ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
1224
+ output.write(`${leadingBorder}${completeColor(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT)}\n${msg}\n${color.gray(bottomLeft + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`);
1225
+ };
1226
+ //#endregion
1227
+ //#region src/password.ts
1228
+ const password = (opts) => {
1229
+ return new PasswordPrompt({
1230
+ validate: opts.validate,
1231
+ mask: opts.mask ?? S_PASSWORD_MASK,
1232
+ signal: opts.signal,
1233
+ input: opts.input,
1234
+ output: opts.output,
1235
+ render() {
1236
+ const hasGuide = opts.withGuide ?? false;
1237
+ const nestedPrefix = " ";
1238
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
1239
+ const userInput = this.userInputWithCursor;
1240
+ const masked = this.masked;
1241
+ switch (this.state) {
1242
+ case "error": {
1243
+ const errorPrefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
1244
+ const errorPrefixEnd = hasGuide ? `${color.yellow(S_BAR_END)} ` : "";
1245
+ const maskedText = masked ?? "";
1246
+ if (opts.clearOnError) this.clear();
1247
+ return `${title.trim()}\n${errorPrefix}${maskedText}\n${errorPrefixEnd}${color.yellow(this.error)}\n`;
1248
+ }
1249
+ case "submit": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${masked ? color.dim(masked) : ""}\n`;
1250
+ case "cancel": return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${masked ? color.strikethrough(color.dim(masked)) : ""}${masked && hasGuide ? `\n${color.gray(S_BAR)}` : ""}\n`;
1251
+ default: return `${title}${hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix}${userInput}\n${hasGuide ? color.blue(S_BAR_END) : ""}\n`;
1252
+ }
1253
+ }
1254
+ }).prompt();
1255
+ };
1256
+ //#endregion
1257
+ //#region src/path.ts
1258
+ const path = (opts) => {
1259
+ const validate = opts.validate;
1260
+ return autocomplete({
1261
+ ...opts,
1262
+ initialUserInput: opts.initialValue ?? opts.root ?? process.cwd(),
1263
+ maxItems: 5,
1264
+ validate(value) {
1265
+ if (Array.isArray(value)) return;
1266
+ if (!value) return "Please select a path";
1267
+ if (validate) return validate(value);
1268
+ },
1269
+ options() {
1270
+ const userInput = this.userInput;
1271
+ if (userInput === "") return [];
1272
+ try {
1273
+ let searchPath;
1274
+ if (!existsSync(userInput)) searchPath = dirname(userInput);
1275
+ else if (lstatSync(userInput).isDirectory()) searchPath = userInput;
1276
+ else searchPath = dirname(userInput);
1277
+ return readdirSync(searchPath).map((item) => {
1278
+ const path = join(searchPath, item);
1279
+ return {
1280
+ name: item,
1281
+ path,
1282
+ isDirectory: lstatSync(path).isDirectory()
1283
+ };
1284
+ }).filter(({ path, isDirectory }) => path.startsWith(userInput) && (opts.directory || !isDirectory)).map((item) => ({ value: item.path }));
1285
+ } catch {
1286
+ return [];
1287
+ }
1288
+ }
1289
+ });
1290
+ };
1291
+ //#endregion
1292
+ //#region src/spinner.ts
1293
+ const defaultStyleFn = color.magenta;
1294
+ const removeTrailingDots = (msg) => {
1295
+ return msg.replace(/\.+$/, "");
1296
+ };
1297
+ const formatTimer = (durationMs) => {
1298
+ const duration = durationMs / 1e3;
1299
+ const min = Math.floor(duration / 60);
1300
+ const secs = Math.floor(duration % 60);
1301
+ return color.gray(min > 0 ? `(${min}m ${secs}s)` : `(${secs}s)`);
1302
+ };
1303
+ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancelMessage, errorMessage, frames = unicode ? [
1304
+ "◒",
1305
+ "◐",
1306
+ "◓",
1307
+ "◑"
1308
+ ] : [
1309
+ "•",
1310
+ "o",
1311
+ "O",
1312
+ "0"
1313
+ ], delay = unicode ? 80 : 120, signal, ...opts } = {}) => {
1314
+ const isCI$1 = isCI();
1315
+ let unblock;
1316
+ let loop;
1317
+ let isSpinnerActive = false;
1318
+ let isCancelled = false;
1319
+ let _message = "";
1320
+ let _prevMessage;
1321
+ let _origin = performance.now();
1322
+ let _elapsedMs = 0;
1323
+ const columns = getColumns(output);
1324
+ const styleFn = opts?.styleFrame ?? defaultStyleFn;
1325
+ const getElapsedMs = () => {
1326
+ if (!isSpinnerActive) return _elapsedMs;
1327
+ return _elapsedMs + (performance.now() - _origin);
1328
+ };
1329
+ const handleExit = (code) => {
1330
+ const msg = code > 1 ? errorMessage ?? settings$1.messages.error : cancelMessage ?? settings$1.messages.cancel;
1331
+ isCancelled = code === 1;
1332
+ if (isSpinnerActive) {
1333
+ _stop(msg, code);
1334
+ if (isCancelled && typeof onCancel === "function") onCancel();
1335
+ }
1336
+ };
1337
+ const errorEventHandler = () => handleExit(2);
1338
+ const signalEventHandler = () => handleExit(1);
1339
+ const registerHooks = () => {
1340
+ process.on("uncaughtExceptionMonitor", errorEventHandler);
1341
+ process.on("unhandledRejection", errorEventHandler);
1342
+ process.on("SIGINT", signalEventHandler);
1343
+ process.on("SIGTERM", signalEventHandler);
1344
+ process.on("exit", handleExit);
1345
+ if (signal) signal.addEventListener("abort", signalEventHandler);
1346
+ };
1347
+ const clearHooks = () => {
1348
+ process.removeListener("uncaughtExceptionMonitor", errorEventHandler);
1349
+ process.removeListener("unhandledRejection", errorEventHandler);
1350
+ process.removeListener("SIGINT", signalEventHandler);
1351
+ process.removeListener("SIGTERM", signalEventHandler);
1352
+ process.removeListener("exit", handleExit);
1353
+ if (signal) signal.removeEventListener("abort", signalEventHandler);
1354
+ };
1355
+ const clearPrevMessage = () => {
1356
+ if (_prevMessage === void 0) return;
1357
+ if (isCI$1) output.write("\n");
1358
+ const prevLines = wrapAnsi(_prevMessage, columns, {
1359
+ hard: true,
1360
+ trim: false
1361
+ }).split("\n");
1362
+ if (prevLines.length > 1) output.write(cursor.up(prevLines.length - 1));
1363
+ output.write(cursor.to(0));
1364
+ output.write(erase.down());
1365
+ };
1366
+ const hasGuide = opts.withGuide ?? false;
1367
+ const startLoop = () => {
1368
+ isSpinnerActive = true;
1369
+ unblock = block({ output });
1370
+ _origin = performance.now();
1371
+ _prevMessage = void 0;
1372
+ if (hasGuide) output.write(`${color.gray(S_BAR)}\n`);
1373
+ let frameIndex = 0;
1374
+ let indicatorTimer = 0;
1375
+ registerHooks();
1376
+ const renderFrame = () => {
1377
+ if (isCI$1 && _message === _prevMessage) return;
1378
+ clearPrevMessage();
1379
+ _prevMessage = _message;
1380
+ const frame = styleFn(frames[frameIndex]);
1381
+ let outputMessage;
1382
+ if (isCI$1) outputMessage = `${frame} ${_message}...`;
1383
+ else if (indicator === "timer") outputMessage = `${frame} ${_message} ${formatTimer(getElapsedMs())}`;
1384
+ else {
1385
+ const loadingDots = ".".repeat(Math.floor(indicatorTimer)).slice(0, 3);
1386
+ outputMessage = `${frame} ${_message}${loadingDots}`;
1387
+ }
1388
+ const wrapped = wrapAnsi(outputMessage, columns, {
1389
+ hard: true,
1390
+ trim: false
1391
+ });
1392
+ output.write(wrapped);
1393
+ frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0;
1394
+ indicatorTimer = indicatorTimer < 4 ? indicatorTimer + .125 : 0;
1395
+ };
1396
+ renderFrame();
1397
+ loop = setInterval(renderFrame, delay);
1398
+ };
1399
+ const start = (msg = "") => {
1400
+ _elapsedMs = 0;
1401
+ _message = removeTrailingDots(msg);
1402
+ startLoop();
1403
+ };
1404
+ const _stop = (msg = "", code = 0, silent = false, preserveElapsed = false) => {
1405
+ if (!isSpinnerActive) return;
1406
+ isSpinnerActive = false;
1407
+ clearInterval(loop);
1408
+ clearPrevMessage();
1409
+ const elapsedMs = getElapsedMs();
1410
+ const step = code === 0 ? completeColor(S_STEP_SUBMIT) : code === 1 ? color.red(S_STEP_CANCEL) : color.red(S_STEP_ERROR);
1411
+ _message = msg ?? _message;
1412
+ if (!silent) {
1413
+ if (indicator === "timer") output.write(`${step} ${_message} ${formatTimer(elapsedMs)}\n\n`);
1414
+ else output.write(`${step} ${_message}\n\n`);
1415
+ }
1416
+ if (!preserveElapsed) _elapsedMs = 0;
1417
+ _prevMessage = void 0;
1418
+ clearHooks();
1419
+ unblock();
1420
+ };
1421
+ const pause = () => {
1422
+ if (!isSpinnerActive) return;
1423
+ _elapsedMs = getElapsedMs();
1424
+ _stop(_message, 0, true, true);
1425
+ };
1426
+ const resume = (msg = _message) => {
1427
+ if (isSpinnerActive) return;
1428
+ _message = removeTrailingDots(msg);
1429
+ startLoop();
1430
+ };
1431
+ const stop = (msg = "") => _stop(msg, 0);
1432
+ const cancel = (msg = "") => _stop(msg, 1);
1433
+ const error = (msg = "") => _stop(msg, 2);
1434
+ const clear = () => _stop("", 0, true);
1435
+ const message = (msg = "") => {
1436
+ _message = removeTrailingDots(msg ?? _message);
1437
+ };
1438
+ return {
1439
+ start,
1440
+ pause,
1441
+ resume,
1442
+ stop,
1443
+ message,
1444
+ cancel,
1445
+ error,
1446
+ clear,
1447
+ get isCancelled() {
1448
+ return isCancelled;
1449
+ }
1450
+ };
1451
+ };
1452
+ //#endregion
1453
+ //#region src/progress-bar.ts
1454
+ const S_PROGRESS_CHAR = {
1455
+ light: unicodeOr("─", "-"),
1456
+ heavy: unicodeOr("━", "="),
1457
+ block: unicodeOr("█", "#")
1458
+ };
1459
+ function progress({ style = "heavy", max: userMax = 100, size: userSize = 40, ...spinnerOptions } = {}) {
1460
+ const spin = spinner(spinnerOptions);
1461
+ let value = 0;
1462
+ let previousMessage = "";
1463
+ const max = Math.max(1, userMax);
1464
+ const size = Math.max(1, userSize);
1465
+ const activeStyle = (state) => {
1466
+ switch (state) {
1467
+ case "initial":
1468
+ case "active": return color.magenta;
1469
+ case "error":
1470
+ case "cancel": return color.red;
1471
+ case "submit": return completeColor;
1472
+ default: return color.magenta;
1473
+ }
1474
+ };
1475
+ const drawProgress = (state, msg) => {
1476
+ const active = Math.floor(value / max * size);
1477
+ return `${activeStyle(state)(S_PROGRESS_CHAR[style].repeat(active))}${color.dim(S_PROGRESS_CHAR[style].repeat(size - active))} ${msg}`;
1478
+ };
1479
+ const start = (msg = "") => {
1480
+ previousMessage = msg;
1481
+ spin.start(drawProgress("initial", msg));
1482
+ };
1483
+ const advance = (step = 1, msg) => {
1484
+ value = Math.min(max, step + value);
1485
+ spin.message(drawProgress("active", msg ?? previousMessage));
1486
+ previousMessage = msg ?? previousMessage;
1487
+ };
1488
+ return {
1489
+ start,
1490
+ pause: spin.pause.bind(spin),
1491
+ resume: (msg) => {
1492
+ const nextMessage = msg ?? previousMessage;
1493
+ previousMessage = nextMessage;
1494
+ spin.resume(drawProgress("active", nextMessage));
1495
+ },
1496
+ stop: spin.stop.bind(spin),
1497
+ cancel: spin.cancel.bind(spin),
1498
+ error: spin.error.bind(spin),
1499
+ clear: spin.clear.bind(spin),
1500
+ advance,
1501
+ message: (msg) => advance(0, msg),
1502
+ get isCancelled() {
1503
+ return spin.isCancelled;
1504
+ }
1505
+ };
1506
+ }
1507
+ //#endregion
1508
+ //#region src/select.ts
1509
+ const computeLabel = (label, format) => {
1510
+ if (!label.includes("\n")) return format(label);
1511
+ return label.split("\n").map((line) => format(line)).join("\n");
1512
+ };
1513
+ const withMarker = (marker, label, format, firstLineSuffix = "") => {
1514
+ const lines = label.split("\n");
1515
+ if (lines.length === 1) return `${marker} ${format(lines[0])}${firstLineSuffix}`;
1516
+ const [firstLine, ...rest] = lines;
1517
+ return [`${marker} ${format(firstLine)}${firstLineSuffix}`, ...rest.map((line) => ` ${format(line)}`)].join("\n");
1518
+ };
1519
+ const select = (opts) => {
1520
+ const opt = (option, state) => {
1521
+ const label = option.label ?? String(option.value);
1522
+ const hint = option.hint ? `: ${color.gray(option.hint)}` : "";
1523
+ switch (state) {
1524
+ case "disabled": return withMarker(color.gray(" "), label, (text) => color.strikethrough(color.gray(text)), option.hint ? `: ${color.gray(option.hint ?? "disabled")}` : "");
1525
+ case "selected": return computeLabel(label, color.dim);
1526
+ case "active": return withMarker(color.blue(S_POINTER_ACTIVE), label, (text) => color.blue(color.bold(text)), hint);
1527
+ case "cancelled": return computeLabel(label, (str) => color.strikethrough(color.dim(str)));
1528
+ default: return withMarker(color.dim(" "), label, (text) => text, hint);
1529
+ }
1530
+ };
1531
+ return new SelectPrompt({
1532
+ options: opts.options,
1533
+ signal: opts.signal,
1534
+ input: opts.input,
1535
+ output: opts.output,
1536
+ initialValue: opts.initialValue,
1537
+ render() {
1538
+ const hasGuide = opts.withGuide ?? false;
1539
+ const nestedPrefix = " ";
1540
+ const formatMessageLines = (message) => {
1541
+ return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
1542
+ };
1543
+ const hasMessage = opts.message.trim().length > 0;
1544
+ const messageLines = !hasMessage ? "" : hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
1545
+ const title = hasMessage ? `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${messageLines}\n` : "";
1546
+ switch (this.state) {
1547
+ case "submit": {
1548
+ const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1549
+ return `${title}${wrapTextWithPrefix(opts.output, opt(this.options[this.cursor], "selected"), submitPrefix)}\n${promptMilestone("select", opts.testId, "submit")}`;
1550
+ }
1551
+ case "cancel": {
1552
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1553
+ return `${title}${wrapTextWithPrefix(opts.output, opt(this.options[this.cursor], "cancelled"), cancelPrefix)}${hasGuide ? `\n${color.gray(S_BAR)}` : ""}\n${promptMilestone("select", opts.testId, "cancel")}`;
1554
+ }
1555
+ default: {
1556
+ const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
1557
+ const prefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
1558
+ const titleLineCount = title ? title.split("\n").length : 0;
1559
+ const footerLineCount = hasGuide ? 2 : 1;
1560
+ return `${title}${prefix}${limitOptions({
1561
+ output: opts.output,
1562
+ cursor: this.cursor,
1563
+ options: this.options,
1564
+ maxItems: opts.maxItems,
1565
+ columnPadding: prefix.length,
1566
+ rowPadding: titleLineCount + footerLineCount,
1567
+ style: (item, active) => opt(item, item.disabled ? "disabled" : active ? "active" : "inactive")
1568
+ }).join(`\n${prefix}`)}\n${prefixEnd}\n${promptMilestone("select", opts.testId, String(this.cursor))}`;
1569
+ }
1570
+ }
1571
+ }
1572
+ }).prompt();
1573
+ };
1574
+ //#endregion
1575
+ //#region src/select-key.ts
1576
+ const selectKey = (opts) => {
1577
+ const withMarker = (marker, value) => {
1578
+ const lines = value.split("\n");
1579
+ if (lines.length === 1) return `${marker} ${lines[0]}`;
1580
+ const [firstLine, ...rest] = lines;
1581
+ return [`${marker} ${firstLine}`, ...rest.map((line) => ` ${line}`)].join("\n");
1582
+ };
1583
+ const opt = (option, state = "inactive") => {
1584
+ const label = option.label ?? option.value;
1585
+ if (state === "selected") return color.dim(label);
1586
+ if (state === "cancelled") return color.strikethrough(color.dim(label));
1587
+ if (state === "active") return withMarker(color.blue(S_POINTER_ACTIVE), `${color.bgBlue(color.white(` ${option.value} `))} ${color.bold(label)}${option.hint ? ` ${color.dim(`(${option.hint})`)}` : ""}`);
1588
+ return withMarker(color.dim(" "), `${color.gray(color.bgWhite(color.inverse(` ${option.value} `)))} ${color.dim(label)}${option.hint ? ` ${color.dim(`(${option.hint})`)}` : ""}`);
1589
+ };
1590
+ return new SelectKeyPrompt({
1591
+ options: opts.options,
1592
+ signal: opts.signal,
1593
+ input: opts.input,
1594
+ output: opts.output,
1595
+ initialValue: opts.initialValue,
1596
+ caseSensitive: opts.caseSensitive,
1597
+ render() {
1598
+ const hasGuide = opts.withGuide ?? false;
1599
+ const nestedPrefix = " ";
1600
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
1601
+ switch (this.state) {
1602
+ case "submit": {
1603
+ const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1604
+ const selectedOption = this.options.find((opt) => opt.value === this.value) ?? opts.options[0];
1605
+ return `${title}${wrapTextWithPrefix(opts.output, opt(selectedOption, "selected"), submitPrefix)}\n`;
1606
+ }
1607
+ case "cancel": {
1608
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1609
+ return `${title}${wrapTextWithPrefix(opts.output, opt(this.options[0], "cancelled"), cancelPrefix)}${hasGuide ? `\n${color.gray(S_BAR)}` : ""}\n`;
1610
+ }
1611
+ default: {
1612
+ const defaultPrefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
1613
+ const defaultPrefixEnd = hasGuide ? color.blue(S_BAR_END) : "";
1614
+ return `${title}${this.options.map((option, i) => wrapTextWithPrefix(opts.output, opt(option, i === this.cursor ? "active" : "inactive"), defaultPrefix)).join("\n")}\n${defaultPrefixEnd}\n`;
1615
+ }
1616
+ }
1617
+ }
1618
+ }).prompt();
1619
+ };
1620
+ //#endregion
1621
+ //#region src/stream.ts
1622
+ const prefix = " ";
1623
+ const stream = {
1624
+ message: async (iterable, { symbol = "" } = {}) => {
1625
+ process.stdout.write(symbol ? `${symbol} ` : "");
1626
+ const initialWidth = symbol ? 3 : 0;
1627
+ let lineWidth = initialWidth;
1628
+ for await (let chunk of iterable) {
1629
+ chunk = chunk.replace(/\n/g, `\n${prefix}`);
1630
+ if (chunk.includes("\n")) lineWidth = initialWidth + stripVTControlCharacters(chunk.slice(chunk.lastIndexOf("\n"))).length;
1631
+ const chunkLen = stripVTControlCharacters(chunk).length;
1632
+ if (lineWidth + chunkLen < process.stdout.columns) {
1633
+ lineWidth += chunkLen;
1634
+ process.stdout.write(chunk);
1635
+ } else {
1636
+ process.stdout.write(`\n${prefix}${chunk.trimStart()}`);
1637
+ lineWidth = initialWidth + stripVTControlCharacters(chunk.trimStart()).length;
1638
+ }
1639
+ }
1640
+ process.stdout.write("\n");
1641
+ },
1642
+ info: (iterable) => {
1643
+ return stream.message(iterable, { symbol: color.blue(S_INFO) });
1644
+ },
1645
+ success: (iterable) => {
1646
+ return stream.message(iterable, { symbol: completeColor(S_SUCCESS) });
1647
+ },
1648
+ step: (iterable) => {
1649
+ return stream.message(iterable, { symbol: completeColor(S_STEP_SUBMIT) });
1650
+ },
1651
+ warn: (iterable) => {
1652
+ return stream.message(iterable, { symbol: color.yellow(S_WARN) });
1653
+ },
1654
+ /** alias for `log.warn()`. */
1655
+ warning: (iterable) => {
1656
+ return stream.warn(iterable);
1657
+ },
1658
+ error: (iterable) => {
1659
+ return stream.message(iterable, { symbol: color.red(S_ERROR) });
1660
+ }
1661
+ };
1662
+ //#endregion
1663
+ //#region src/task.ts
1664
+ /**
1665
+ * Define a group of tasks to be executed
1666
+ */
1667
+ const tasks = async (tasks, opts) => {
1668
+ for (const task of tasks) {
1669
+ if (task.enabled === false) continue;
1670
+ const s = spinner(opts);
1671
+ s.start(task.title);
1672
+ const result = await task.task(s.message.bind(s));
1673
+ s.stop(result || task.title);
1674
+ }
1675
+ };
1676
+ //#endregion
1677
+ //#region src/task-log.ts
1678
+ const stripDestructiveANSI = (input) => {
1679
+ return input.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g, "");
1680
+ };
1681
+ /**
1682
+ * Renders a log which clears on success and remains on failure
1683
+ */
1684
+ const taskLog = (opts) => {
1685
+ const output = opts.output ?? process.stdout;
1686
+ const columns = getColumns(output);
1687
+ const secondarySymbol = color.gray(S_BAR);
1688
+ const spacing = opts.spacing ?? 1;
1689
+ const barSize = 3;
1690
+ const retainLog = opts.retainLog === true;
1691
+ const isTTY$1 = !isCI() && isTTY(output);
1692
+ output.write(`${secondarySymbol}\n`);
1693
+ output.write(`${completeColor(S_STEP_SUBMIT)} ${opts.title}\n`);
1694
+ for (let i = 0; i < spacing; i++) output.write(`${secondarySymbol}\n`);
1695
+ const buffers = [{
1696
+ value: "",
1697
+ full: ""
1698
+ }];
1699
+ let lastMessageWasRaw = false;
1700
+ const clear = (clearTitle) => {
1701
+ if (buffers.length === 0) return;
1702
+ let lines = 0;
1703
+ if (clearTitle) lines += spacing + 2;
1704
+ for (const buffer of buffers) {
1705
+ const { value, result } = buffer;
1706
+ let text = result?.message ?? value;
1707
+ if (text.length === 0) continue;
1708
+ if (result === void 0 && buffer.header !== void 0 && buffer.header !== "") text += `\n${buffer.header}`;
1709
+ const bufferHeight = text.split("\n").reduce((count, line) => {
1710
+ if (line === "") return count + 1;
1711
+ return count + Math.ceil((line.length + barSize) / columns);
1712
+ }, 0);
1713
+ lines += bufferHeight;
1714
+ }
1715
+ if (lines > 0) {
1716
+ lines += 1;
1717
+ output.write(erase.lines(lines));
1718
+ }
1719
+ };
1720
+ const printBuffer = (buffer, messageSpacing, full) => {
1721
+ const messages = full ? `${buffer.full}\n${buffer.value}` : buffer.value;
1722
+ if (buffer.header !== void 0 && buffer.header !== "") log.message(buffer.header.split("\n").map(color.bold), {
1723
+ output,
1724
+ secondarySymbol,
1725
+ symbol: secondarySymbol,
1726
+ spacing: 0
1727
+ });
1728
+ log.message(messages.split("\n").map(color.dim), {
1729
+ output,
1730
+ secondarySymbol,
1731
+ symbol: secondarySymbol,
1732
+ spacing: messageSpacing ?? spacing
1733
+ });
1734
+ };
1735
+ const renderBuffer = () => {
1736
+ for (const buffer of buffers) {
1737
+ const { header, value, full } = buffer;
1738
+ if ((header === void 0 || header.length === 0) && value.length === 0) continue;
1739
+ printBuffer(buffer, void 0, retainLog === true && full.length > 0);
1740
+ }
1741
+ };
1742
+ const message = (buffer, msg, mopts) => {
1743
+ clear(false);
1744
+ if ((mopts?.raw !== true || !lastMessageWasRaw) && buffer.value !== "") buffer.value += "\n";
1745
+ buffer.value += stripDestructiveANSI(msg);
1746
+ lastMessageWasRaw = mopts?.raw === true;
1747
+ if (opts.limit !== void 0) {
1748
+ const lines = buffer.value.split("\n");
1749
+ const linesToRemove = lines.length - opts.limit;
1750
+ if (linesToRemove > 0) {
1751
+ const removedLines = lines.splice(0, linesToRemove);
1752
+ if (retainLog) buffer.full += (buffer.full === "" ? "" : "\n") + removedLines.join("\n");
1753
+ }
1754
+ buffer.value = lines.join("\n");
1755
+ }
1756
+ if (isTTY$1) printBuffers();
1757
+ };
1758
+ const printBuffers = () => {
1759
+ for (const buffer of buffers) if (buffer.result) {
1760
+ if (buffer.result.status === "error") log.error(buffer.result.message, {
1761
+ output,
1762
+ secondarySymbol,
1763
+ spacing: 0
1764
+ });
1765
+ else log.success(buffer.result.message, {
1766
+ output,
1767
+ secondarySymbol,
1768
+ spacing: 0
1769
+ });
1770
+ } else if (buffer.value !== "") printBuffer(buffer, 0);
1771
+ };
1772
+ const completeBuffer = (buffer, result) => {
1773
+ clear(false);
1774
+ buffer.result = result;
1775
+ if (isTTY$1) printBuffers();
1776
+ };
1777
+ return {
1778
+ message(msg, mopts) {
1779
+ message(buffers[0], msg, mopts);
1780
+ },
1781
+ group(name) {
1782
+ const buffer = {
1783
+ header: name,
1784
+ value: "",
1785
+ full: ""
1786
+ };
1787
+ buffers.push(buffer);
1788
+ return {
1789
+ message(msg, mopts) {
1790
+ message(buffer, msg, mopts);
1791
+ },
1792
+ error(message) {
1793
+ completeBuffer(buffer, {
1794
+ status: "error",
1795
+ message
1796
+ });
1797
+ },
1798
+ success(message) {
1799
+ completeBuffer(buffer, {
1800
+ status: "success",
1801
+ message
1802
+ });
1803
+ }
1804
+ };
1805
+ },
1806
+ error(message, opts) {
1807
+ clear(true);
1808
+ log.error(message, {
1809
+ output,
1810
+ secondarySymbol,
1811
+ spacing: 1
1812
+ });
1813
+ if (opts?.showLog !== false) renderBuffer();
1814
+ buffers.splice(1, buffers.length - 1);
1815
+ buffers[0].value = "";
1816
+ buffers[0].full = "";
1817
+ },
1818
+ success(message, opts) {
1819
+ clear(true);
1820
+ log.success(message, {
1821
+ output,
1822
+ secondarySymbol,
1823
+ spacing: 1
1824
+ });
1825
+ if (opts?.showLog === true) renderBuffer();
1826
+ buffers.splice(1, buffers.length - 1);
1827
+ buffers[0].value = "";
1828
+ buffers[0].full = "";
1829
+ }
1830
+ };
1831
+ };
1832
+ //#endregion
1833
+ //#region src/text.ts
1834
+ const text = (opts) => {
1835
+ return new TextPrompt({
1836
+ validate: opts.validate,
1837
+ placeholder: opts.placeholder,
1838
+ defaultValue: opts.defaultValue,
1839
+ initialValue: opts.initialValue,
1840
+ output: opts.output,
1841
+ signal: opts.signal,
1842
+ input: opts.input,
1843
+ render() {
1844
+ const hasGuide = opts?.withGuide ?? false;
1845
+ const nestedPrefix = " ";
1846
+ const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ""}${symbol(this.state)} ${opts.message}\n`;
1847
+ const placeholder = opts.placeholder ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) : color.inverse(color.hidden("_"));
1848
+ const userInput = !this.userInput ? placeholder : this.userInputWithCursor;
1849
+ const value = this.value ?? "";
1850
+ switch (this.state) {
1851
+ case "error": {
1852
+ const errorText = this.error ? ` ${color.yellow(this.error)}` : "";
1853
+ const errorPrefix = hasGuide ? `${color.yellow(S_BAR)} ` : nestedPrefix;
1854
+ const errorPrefixEnd = hasGuide ? color.yellow(S_BAR_END) : "";
1855
+ return `${title.trim()}\n${errorPrefix}${userInput}\n${errorPrefixEnd}${errorText}\n${promptMilestone("text", opts.testId, "error")}`;
1856
+ }
1857
+ case "submit": {
1858
+ const valueText = value ? color.dim(value) : "";
1859
+ return `${title}${hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix}${valueText}\n${promptMilestone("text", opts.testId, "submit")}`;
1860
+ }
1861
+ case "cancel": {
1862
+ const valueText = value ? color.strikethrough(color.dim(value)) : "";
1863
+ const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : nestedPrefix;
1864
+ return `${title}${cancelPrefix}${valueText}${value.trim() ? `\n${cancelPrefix}` : ""}\n${promptMilestone("text", opts.testId, "cancel")}`;
1865
+ }
1866
+ default: return `${title}${hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix}${userInput}\n${hasGuide ? color.blue(S_BAR_END) : ""}\n${promptMilestone("text", opts.testId, this.value ?? "")}`;
1867
+ }
1868
+ }
1869
+ }).prompt();
1870
+ };
1871
+ //#endregion
1872
+ export { S_BAR, S_BAR_END, S_BAR_END_RIGHT, S_BAR_H, S_BAR_START, S_BAR_START_RIGHT, S_CHECKBOX_ACTIVE, S_CHECKBOX_INACTIVE, S_CHECKBOX_SELECTED, S_CONNECT_LEFT, S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, S_ERROR, S_INFO, S_PASSWORD_MASK, S_POINTER_ACTIVE, S_POINTER_INACTIVE, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_SUCCESS, S_WARN, autocomplete, autocompleteMultiselect, box, cancel, completeColor, confirm, group, groupMultiselect, intro, isCI, isCancel, isTTY, limitOptions, log, milestone, multiselect, note, outro, password, path, progress, promptMilestone, select, selectKey, settings, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr, updateSettings };