@userreason/wizard 0.0.0-stage → 0.2.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.
@@ -0,0 +1,1477 @@
1
+ import { createRequire as createWizardRequire } from 'node:module'; import { fileURLToPath as wizardFileURLToPath } from 'node:url'; import { dirname as wizardDirname } from 'node:path'; const require = createWizardRequire(import.meta.url); const __filename = wizardFileURLToPath(import.meta.url); const __dirname = wizardDirname(__filename);
2
+ import {
3
+ createSpinner,
4
+ createUiKit,
5
+ detectColorLevel,
6
+ origin,
7
+ plainLine,
8
+ stripAnsi,
9
+ textWidth
10
+ } from "./chunk-GGARVSPT.js";
11
+ import {
12
+ __commonJS,
13
+ __toESM
14
+ } from "./chunk-WL3NOIM6.js";
15
+
16
+ // node_modules/sisteransi/src/index.js
17
+ var require_src = __commonJS({
18
+ "node_modules/sisteransi/src/index.js"(exports, module) {
19
+ "use strict";
20
+ var ESC2 = "\x1B";
21
+ var CSI2 = `${ESC2}[`;
22
+ var beep = "\x07";
23
+ var cursor3 = {
24
+ to(x, y2) {
25
+ if (!y2) return `${CSI2}${x + 1}G`;
26
+ return `${CSI2}${y2 + 1};${x + 1}H`;
27
+ },
28
+ move(x, y2) {
29
+ let ret = "";
30
+ if (x < 0) ret += `${CSI2}${-x}D`;
31
+ else if (x > 0) ret += `${CSI2}${x}C`;
32
+ if (y2 < 0) ret += `${CSI2}${-y2}A`;
33
+ else if (y2 > 0) ret += `${CSI2}${y2}B`;
34
+ return ret;
35
+ },
36
+ up: (count = 1) => `${CSI2}${count}A`,
37
+ down: (count = 1) => `${CSI2}${count}B`,
38
+ forward: (count = 1) => `${CSI2}${count}C`,
39
+ backward: (count = 1) => `${CSI2}${count}D`,
40
+ nextLine: (count = 1) => `${CSI2}E`.repeat(count),
41
+ prevLine: (count = 1) => `${CSI2}F`.repeat(count),
42
+ left: `${CSI2}G`,
43
+ hide: `${CSI2}?25l`,
44
+ show: `${CSI2}?25h`,
45
+ save: `${ESC2}7`,
46
+ restore: `${ESC2}8`
47
+ };
48
+ var scroll = {
49
+ up: (count = 1) => `${CSI2}S`.repeat(count),
50
+ down: (count = 1) => `${CSI2}T`.repeat(count)
51
+ };
52
+ var erase3 = {
53
+ screen: `${CSI2}2J`,
54
+ up: (count = 1) => `${CSI2}1J`.repeat(count),
55
+ down: (count = 1) => `${CSI2}J`.repeat(count),
56
+ line: `${CSI2}2K`,
57
+ lineEnd: `${CSI2}K`,
58
+ lineStart: `${CSI2}1K`,
59
+ lines(count) {
60
+ let clear = "";
61
+ for (let i2 = 0; i2 < count; i2++)
62
+ clear += this.line + (i2 < count - 1 ? cursor3.up() : "");
63
+ if (count)
64
+ clear += cursor3.left;
65
+ return clear;
66
+ }
67
+ };
68
+ module.exports = { cursor: cursor3, scroll, erase: erase3, beep };
69
+ }
70
+ });
71
+
72
+ // node_modules/@clack/core/dist/index.mjs
73
+ import { styleText } from "node:util";
74
+ import { stdout, stdin } from "node:process";
75
+ import l__default from "node:readline";
76
+
77
+ // node_modules/fast-string-truncated-width/dist/utils.js
78
+ var getCodePointsLength = /* @__PURE__ */ (() => {
79
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
80
+ return (input) => {
81
+ let surrogatePairsNr = 0;
82
+ SURROGATE_PAIR_RE.lastIndex = 0;
83
+ while (SURROGATE_PAIR_RE.test(input)) {
84
+ surrogatePairsNr += 1;
85
+ }
86
+ return input.length - surrogatePairsNr;
87
+ };
88
+ })();
89
+ var isFullWidth = (x) => {
90
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
91
+ };
92
+ var isWideNotCJKTNotEmoji = (x) => {
93
+ 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;
94
+ };
95
+
96
+ // node_modules/fast-string-truncated-width/dist/index.js
97
+ var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
98
+ var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
99
+ var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
100
+ var TAB_RE = /\t{1,1000}/y;
101
+ var EMOJI_RE = new RegExp("[\\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?))*", "yu");
102
+ var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
103
+ var MODIFIER_RE = new RegExp("\\p{M}+", "gu");
104
+ var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
105
+ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
106
+ const LIMIT = truncationOptions.limit ?? Infinity;
107
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
108
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
109
+ const ANSI_WIDTH = 0;
110
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
111
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
112
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
113
+ const FULL_WIDTH_WIDTH = 2;
114
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
115
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
116
+ const PARSE_BLOCKS = [
117
+ [LATIN_RE, REGULAR_WIDTH],
118
+ [ANSI_RE, ANSI_WIDTH],
119
+ [CONTROL_RE, CONTROL_WIDTH],
120
+ [TAB_RE, TAB_WIDTH],
121
+ [EMOJI_RE, EMOJI_WIDTH],
122
+ [CJKT_WIDE_RE, WIDE_WIDTH]
123
+ ];
124
+ let indexPrev = 0;
125
+ let index = 0;
126
+ let length = input.length;
127
+ let lengthExtra = 0;
128
+ let truncationEnabled = false;
129
+ let truncationIndex = length;
130
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
131
+ let unmatchedStart = 0;
132
+ let unmatchedEnd = 0;
133
+ let width = 0;
134
+ let widthExtra = 0;
135
+ outer: while (true) {
136
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
137
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
138
+ lengthExtra = 0;
139
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
140
+ const codePoint = char.codePointAt(0) || 0;
141
+ if (isFullWidth(codePoint)) {
142
+ widthExtra = FULL_WIDTH_WIDTH;
143
+ } else if (isWideNotCJKTNotEmoji(codePoint)) {
144
+ widthExtra = WIDE_WIDTH;
145
+ } else {
146
+ widthExtra = REGULAR_WIDTH;
147
+ }
148
+ if (width + widthExtra > truncationLimit) {
149
+ truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
150
+ }
151
+ if (width + widthExtra > LIMIT) {
152
+ truncationEnabled = true;
153
+ break outer;
154
+ }
155
+ lengthExtra += char.length;
156
+ width += widthExtra;
157
+ }
158
+ unmatchedStart = unmatchedEnd = 0;
159
+ }
160
+ if (index >= length) {
161
+ break outer;
162
+ }
163
+ for (let i2 = 0, l = PARSE_BLOCKS.length; i2 < l; i2++) {
164
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i2];
165
+ BLOCK_RE.lastIndex = index;
166
+ if (BLOCK_RE.test(input)) {
167
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
168
+ widthExtra = lengthExtra * BLOCK_WIDTH;
169
+ if (width + widthExtra > truncationLimit) {
170
+ truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
171
+ }
172
+ if (width + widthExtra > LIMIT) {
173
+ truncationEnabled = true;
174
+ break outer;
175
+ }
176
+ width += widthExtra;
177
+ unmatchedStart = indexPrev;
178
+ unmatchedEnd = index;
179
+ index = indexPrev = BLOCK_RE.lastIndex;
180
+ continue outer;
181
+ }
182
+ }
183
+ index += 1;
184
+ }
185
+ return {
186
+ width: truncationEnabled ? truncationLimit : width,
187
+ index: truncationEnabled ? truncationIndex : length,
188
+ truncated: truncationEnabled,
189
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
190
+ };
191
+ };
192
+ var dist_default = getStringTruncatedWidth;
193
+
194
+ // node_modules/fast-string-width/dist/index.js
195
+ var NO_TRUNCATION2 = {
196
+ limit: Infinity,
197
+ ellipsis: "",
198
+ ellipsisWidth: 0
199
+ };
200
+ var fastStringWidth = (input, options = {}) => {
201
+ return dist_default(input, NO_TRUNCATION2, options).width;
202
+ };
203
+ var dist_default2 = fastStringWidth;
204
+
205
+ // node_modules/fast-wrap-ansi/lib/main.js
206
+ var ESC = "\x1B";
207
+ var CSI = "\x9B";
208
+ var END_CODE = 39;
209
+ var ANSI_ESCAPE_BELL = "\x07";
210
+ var ANSI_CSI = "[";
211
+ var ANSI_OSC = "]";
212
+ var ANSI_SGR_TERMINATOR = "m";
213
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
214
+ var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
215
+ var getClosingCode = (openingCode) => {
216
+ if (openingCode >= 30 && openingCode <= 37)
217
+ return 39;
218
+ if (openingCode >= 90 && openingCode <= 97)
219
+ return 39;
220
+ if (openingCode >= 40 && openingCode <= 47)
221
+ return 49;
222
+ if (openingCode >= 100 && openingCode <= 107)
223
+ return 49;
224
+ if (openingCode === 1 || openingCode === 2)
225
+ return 22;
226
+ if (openingCode === 3)
227
+ return 23;
228
+ if (openingCode === 4)
229
+ return 24;
230
+ if (openingCode === 7)
231
+ return 27;
232
+ if (openingCode === 8)
233
+ return 28;
234
+ if (openingCode === 9)
235
+ return 29;
236
+ if (openingCode === 0)
237
+ return 0;
238
+ return void 0;
239
+ };
240
+ var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
241
+ var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
242
+ var wrapWord = (rows, word, columns) => {
243
+ const characters = word[Symbol.iterator]();
244
+ let isInsideEscape = false;
245
+ let isInsideLinkEscape = false;
246
+ let lastRow = rows.at(-1);
247
+ let visible = lastRow === void 0 ? 0 : dist_default2(lastRow);
248
+ let currentCharacter = characters.next();
249
+ let nextCharacter = characters.next();
250
+ let rawCharacterIndex = 0;
251
+ while (!currentCharacter.done) {
252
+ const character = currentCharacter.value;
253
+ const characterLength = dist_default2(character);
254
+ if (visible + characterLength <= columns) {
255
+ rows[rows.length - 1] += character;
256
+ } else {
257
+ rows.push(character);
258
+ visible = 0;
259
+ }
260
+ if (character === ESC || character === CSI) {
261
+ isInsideEscape = true;
262
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
263
+ }
264
+ if (isInsideEscape) {
265
+ if (isInsideLinkEscape) {
266
+ if (character === ANSI_ESCAPE_BELL) {
267
+ isInsideEscape = false;
268
+ isInsideLinkEscape = false;
269
+ }
270
+ } else if (character === ANSI_SGR_TERMINATOR) {
271
+ isInsideEscape = false;
272
+ }
273
+ } else {
274
+ visible += characterLength;
275
+ if (visible === columns && !nextCharacter.done) {
276
+ rows.push("");
277
+ visible = 0;
278
+ }
279
+ }
280
+ currentCharacter = nextCharacter;
281
+ nextCharacter = characters.next();
282
+ rawCharacterIndex += character.length;
283
+ }
284
+ lastRow = rows.at(-1);
285
+ if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) {
286
+ rows[rows.length - 2] += rows.pop();
287
+ }
288
+ };
289
+ var stringVisibleTrimSpacesRight = (string) => {
290
+ const words = string.split(" ");
291
+ let last = words.length;
292
+ while (last) {
293
+ if (dist_default2(words[last - 1])) {
294
+ break;
295
+ }
296
+ last--;
297
+ }
298
+ if (last === words.length) {
299
+ return string;
300
+ }
301
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
302
+ };
303
+ var exec = (string, columns, options = {}) => {
304
+ if (options.trim !== false && string.trim() === "") {
305
+ return "";
306
+ }
307
+ let returnValue = "";
308
+ let escapeCode;
309
+ let escapeUrl;
310
+ const words = string.split(" ");
311
+ let rows = [""];
312
+ let rowLength = 0;
313
+ for (let index = 0; index < words.length; index++) {
314
+ const word = words[index];
315
+ if (options.trim !== false) {
316
+ const row = rows.at(-1) ?? "";
317
+ const trimmed = row.trimStart();
318
+ if (row.length !== trimmed.length) {
319
+ rows[rows.length - 1] = trimmed;
320
+ rowLength = dist_default2(trimmed);
321
+ }
322
+ }
323
+ if (index !== 0) {
324
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
325
+ rows.push("");
326
+ rowLength = 0;
327
+ }
328
+ if (rowLength || options.trim === false) {
329
+ rows[rows.length - 1] += " ";
330
+ rowLength++;
331
+ }
332
+ }
333
+ const wordLength = dist_default2(word);
334
+ if (options.hard && wordLength > columns) {
335
+ const remainingColumns = columns - rowLength;
336
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
337
+ const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
338
+ if (breaksStartingNextLine < breaksStartingThisLine) {
339
+ rows.push("");
340
+ }
341
+ wrapWord(rows, word, columns);
342
+ rowLength = dist_default2(rows.at(-1) ?? "");
343
+ continue;
344
+ }
345
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
346
+ if (options.wordWrap === false && rowLength < columns) {
347
+ wrapWord(rows, word, columns);
348
+ rowLength = dist_default2(rows.at(-1) ?? "");
349
+ continue;
350
+ }
351
+ rows.push("");
352
+ rowLength = 0;
353
+ }
354
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
355
+ wrapWord(rows, word, columns);
356
+ rowLength = dist_default2(rows.at(-1) ?? "");
357
+ continue;
358
+ }
359
+ rows[rows.length - 1] += word;
360
+ rowLength += wordLength;
361
+ }
362
+ if (options.trim !== false) {
363
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
364
+ }
365
+ const preString = rows.join("\n");
366
+ let inSurrogate = false;
367
+ for (let i2 = 0; i2 < preString.length; i2++) {
368
+ const character = preString[i2];
369
+ returnValue += character;
370
+ if (!inSurrogate) {
371
+ inSurrogate = character >= "\uD800" && character <= "\uDBFF";
372
+ if (inSurrogate) {
373
+ continue;
374
+ }
375
+ } else {
376
+ inSurrogate = false;
377
+ }
378
+ if (character === ESC || character === CSI) {
379
+ GROUP_REGEX.lastIndex = i2 + 1;
380
+ const groupsResult = GROUP_REGEX.exec(preString);
381
+ const groups = groupsResult?.groups;
382
+ if (groups?.code !== void 0) {
383
+ const code = Number.parseFloat(groups.code);
384
+ escapeCode = code === END_CODE ? void 0 : code;
385
+ } else if (groups?.uri !== void 0) {
386
+ escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
387
+ }
388
+ }
389
+ if (preString[i2 + 1] === "\n") {
390
+ if (escapeUrl) {
391
+ returnValue += wrapAnsiHyperlink("");
392
+ }
393
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
394
+ if (escapeCode && closingCode) {
395
+ returnValue += wrapAnsiCode(closingCode);
396
+ }
397
+ } else if (character === "\n") {
398
+ if (escapeCode && getClosingCode(escapeCode)) {
399
+ returnValue += wrapAnsiCode(escapeCode);
400
+ }
401
+ if (escapeUrl) {
402
+ returnValue += wrapAnsiHyperlink(escapeUrl);
403
+ }
404
+ }
405
+ }
406
+ return returnValue;
407
+ };
408
+ var CRLF_OR_LF = /\r?\n/;
409
+ function wrapAnsi(string, columns, options) {
410
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
411
+ }
412
+
413
+ // node_modules/@clack/core/dist/index.mjs
414
+ var import_sisteransi = __toESM(require_src(), 1);
415
+ function findCursor(s, o, l) {
416
+ if (!l.some((r2) => !r2.disabled))
417
+ return s;
418
+ const t2 = s + o, n3 = Math.max(l.length - 1, 0), e = t2 < 0 ? n3 : t2 > n3 ? 0 : t2;
419
+ return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
420
+ }
421
+ var a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
422
+ var t = [
423
+ "January",
424
+ "February",
425
+ "March",
426
+ "April",
427
+ "May",
428
+ "June",
429
+ "July",
430
+ "August",
431
+ "September",
432
+ "October",
433
+ "November",
434
+ "December"
435
+ ];
436
+ var settings = {
437
+ actions: new Set(a$1),
438
+ aliases: /* @__PURE__ */ new Map([
439
+ // vim support
440
+ ["k", "up"],
441
+ ["j", "down"],
442
+ ["h", "left"],
443
+ ["l", "right"],
444
+ ["", "cancel"],
445
+ // opinionated defaults!
446
+ ["escape", "cancel"]
447
+ ]),
448
+ messages: {
449
+ cancel: "Canceled",
450
+ error: "Something went wrong"
451
+ },
452
+ withGuide: true,
453
+ accessible: void 0,
454
+ date: {
455
+ monthNames: [...t],
456
+ messages: {
457
+ required: "Please enter a valid date",
458
+ invalidMonth: "There are only 12 months in a year",
459
+ invalidDay: (n3, e) => `There are only ${n3} days in ${e}`,
460
+ afterMin: (n3) => `Date must be on or after ${n3.toISOString().slice(0, 10)}`,
461
+ beforeMax: (n3) => `Date must be on or before ${n3.toISOString().slice(0, 10)}`
462
+ }
463
+ }
464
+ };
465
+ function isAccessible(n3) {
466
+ if (n3 !== void 0) return n3;
467
+ if (settings.accessible !== void 0) return settings.accessible;
468
+ const e = process.env.ACCESSIBLE;
469
+ return e !== void 0 && e !== "" && e !== "0" && e !== "false";
470
+ }
471
+ function isActionKey(n3, e) {
472
+ if (typeof n3 == "string")
473
+ return settings.aliases.get(n3) === e;
474
+ for (const s of n3)
475
+ if (s !== void 0 && isActionKey(s, e))
476
+ return true;
477
+ return false;
478
+ }
479
+ function diffLines(i2, s) {
480
+ if (i2 === s) return;
481
+ const e = i2.split(`
482
+ `), t2 = s.split(`
483
+ `), r2 = Math.max(e.length, t2.length), f = [];
484
+ for (let n3 = 0; n3 < r2; n3++)
485
+ e[n3] !== t2[n3] && f.push(n3);
486
+ return {
487
+ lines: f,
488
+ numLinesBefore: e.length,
489
+ numLinesAfter: t2.length,
490
+ numLines: r2
491
+ };
492
+ }
493
+ var R = globalThis.process.platform.startsWith("win");
494
+ var CANCEL_SYMBOL = /* @__PURE__ */ Symbol("clack:cancel");
495
+ function isCancel(e) {
496
+ return e === CANCEL_SYMBOL;
497
+ }
498
+ function setRawMode(e, r2) {
499
+ const o = e;
500
+ o.isTTY && o.setRawMode(r2);
501
+ }
502
+ var getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
503
+ var getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
504
+ function wrapTextWithPrefix(e, r2, o, n3 = o, s = o, t2) {
505
+ const f = getColumns(e ?? stdout);
506
+ return wrapAnsi(r2, f - o.length, {
507
+ hard: true,
508
+ trim: false
509
+ }).split(`
510
+ `).map((c2, i2, m2) => {
511
+ const d = t2 ? t2(c2, i2) : c2;
512
+ return i2 === 0 ? `${n3}${d}` : i2 === m2.length - 1 ? `${s}${d}` : `${o}${d}`;
513
+ }).join(`
514
+ `);
515
+ }
516
+ function runValidation(e, a2) {
517
+ if ("~standard" in e) {
518
+ const n3 = e["~standard"].validate(a2);
519
+ return n3 instanceof Promise ? n3.then((r2) => r2.issues?.at(0)?.message) : n3.issues?.at(0)?.message;
520
+ }
521
+ return e(a2);
522
+ }
523
+ var y = class {
524
+ input;
525
+ output;
526
+ _abortSignal;
527
+ rl;
528
+ opts;
529
+ _render;
530
+ _track = false;
531
+ _prevFrame = "";
532
+ _subscribers = /* @__PURE__ */ new Map();
533
+ _cursor = 0;
534
+ state = "initial";
535
+ error = "";
536
+ value;
537
+ userInput = "";
538
+ /**
539
+ * Whether accessible (static, screen-reader friendly) output is enabled for
540
+ * this prompt, resolved from the `accessible` option, the global setting,
541
+ * and the `ACCESSIBLE` env var.
542
+ */
543
+ get accessible() {
544
+ return isAccessible(this.opts.accessible);
545
+ }
546
+ constructor(t2, e = true) {
547
+ const { input: i2 = stdin, output: s = stdout, render: r2, signal: n3, ...o } = t2;
548
+ this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = r2.bind(this), this._track = e, this._abortSignal = n3, this.input = i2, this.output = s;
549
+ }
550
+ /**
551
+ * Unsubscribe all listeners
552
+ */
553
+ unsubscribe() {
554
+ this._subscribers.clear();
555
+ }
556
+ /**
557
+ * Set a subscriber with opts
558
+ * @param event - The event name
559
+ */
560
+ setSubscriber(t2, e) {
561
+ const i2 = this._subscribers.get(t2) ?? [];
562
+ i2.push(e), this._subscribers.set(t2, i2);
563
+ }
564
+ /**
565
+ * Subscribe to an event
566
+ * @param event - The event name
567
+ * @param cb - The callback
568
+ */
569
+ on(t2, e) {
570
+ this.setSubscriber(t2, { cb: e });
571
+ }
572
+ /**
573
+ * Subscribe to an event once
574
+ * @param event - The event name
575
+ * @param cb - The callback
576
+ */
577
+ once(t2, e) {
578
+ this.setSubscriber(t2, { cb: e, once: true });
579
+ }
580
+ /**
581
+ * Emit an event with data
582
+ * @param event - The event name
583
+ * @param data - The data to pass to the callback
584
+ */
585
+ emit(t2, ...e) {
586
+ const i2 = this._subscribers.get(t2) ?? [], s = [];
587
+ for (const r2 of i2)
588
+ r2.cb(...e), r2.once && s.push(() => i2.splice(i2.indexOf(r2), 1));
589
+ for (const r2 of s)
590
+ r2();
591
+ }
592
+ prompt() {
593
+ return new Promise((t2) => {
594
+ if (this._abortSignal) {
595
+ if (this._abortSignal.aborted)
596
+ return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
597
+ this._abortSignal.addEventListener(
598
+ "abort",
599
+ () => {
600
+ this.state = "cancel", this.close();
601
+ },
602
+ { once: true }
603
+ );
604
+ }
605
+ this.rl = l__default.createInterface({
606
+ input: this.input,
607
+ tabSize: 2,
608
+ prompt: "",
609
+ escapeCodeTimeout: 50,
610
+ terminal: true
611
+ }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
612
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
613
+ }), this.once("cancel", () => {
614
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
615
+ });
616
+ });
617
+ }
618
+ _isActionKey(t2, e) {
619
+ return t2 === " ";
620
+ }
621
+ _shouldSubmit(t2, e) {
622
+ return true;
623
+ }
624
+ _setValue(t2) {
625
+ this.value = t2, this.emit("value", this.value);
626
+ }
627
+ _setUserInput(t2, e) {
628
+ this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
629
+ }
630
+ _clearUserInput() {
631
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
632
+ }
633
+ async onKeypress(t2, e) {
634
+ if (this.state !== "validating") {
635
+ if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
636
+ if (this.opts.validate) {
637
+ const i2 = runValidation(this.opts.validate, this.value);
638
+ let s;
639
+ i2 instanceof Promise ? (this.state = "validating", this.render(), s = await i2) : s = i2, s && (this.error = s instanceof Error ? s.message : s, this.state = "error", this.rl?.write(this.userInput));
640
+ }
641
+ this.state !== "error" && (this.state = "submit");
642
+ }
643
+ isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
644
+ }
645
+ }
646
+ close() {
647
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
648
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
649
+ }
650
+ restoreCursor() {
651
+ const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
652
+ `).length - 1;
653
+ this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
654
+ }
655
+ render() {
656
+ const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
657
+ hard: true,
658
+ trim: false
659
+ });
660
+ if (t2 !== this._prevFrame) {
661
+ if (this.state === "initial")
662
+ this.output.write(import_sisteransi.cursor.hide);
663
+ else {
664
+ const e = diffLines(this._prevFrame, t2), i2 = getRows(this.output);
665
+ if (this.restoreCursor(), e) {
666
+ const s = Math.max(0, e.numLinesAfter - i2), r2 = Math.max(0, e.numLinesBefore - i2);
667
+ let n3 = e.lines.find((o) => o >= s);
668
+ if (n3 === void 0) {
669
+ this._prevFrame = t2;
670
+ return;
671
+ }
672
+ if (e.lines.length === 1) {
673
+ this.output.write(import_sisteransi.cursor.move(0, n3 - r2)), this.output.write(import_sisteransi.erase.lines(1));
674
+ const o = t2.split(`
675
+ `);
676
+ this.output.write(o[n3]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - n3 - 1));
677
+ return;
678
+ } else if (e.lines.length > 1) {
679
+ if (s < r2)
680
+ n3 = s;
681
+ else {
682
+ const h2 = n3 - r2;
683
+ h2 > 0 && this.output.write(import_sisteransi.cursor.move(0, h2));
684
+ }
685
+ this.output.write(import_sisteransi.erase.down());
686
+ const f = t2.split(`
687
+ `).slice(n3);
688
+ this.output.write(f.join(`
689
+ `)), this._prevFrame = t2;
690
+ return;
691
+ }
692
+ }
693
+ this.output.write(import_sisteransi.erase.down());
694
+ }
695
+ this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
696
+ }
697
+ }
698
+ };
699
+ var a = class extends y {
700
+ options;
701
+ cursor = 0;
702
+ get _value() {
703
+ return this.options[this.cursor]?.value;
704
+ }
705
+ get _enabledOptions() {
706
+ return this.options.filter((e) => e.disabled !== true);
707
+ }
708
+ toggleAll() {
709
+ const e = this._enabledOptions, i2 = this.value !== void 0 && this.value.length === e.length;
710
+ this.value = i2 ? [] : e.map((t2) => t2.value);
711
+ }
712
+ toggleInvert() {
713
+ const e = this.value;
714
+ if (!e)
715
+ return;
716
+ const i2 = this._enabledOptions.filter((t2) => !e.includes(t2.value));
717
+ this.value = i2.map((t2) => t2.value);
718
+ }
719
+ toggleValue() {
720
+ this.value === void 0 && (this.value = []);
721
+ const e = this.value.includes(this._value);
722
+ this.value = e ? this.value.filter((i2) => i2 !== this._value) : [...this.value, this._value];
723
+ }
724
+ constructor(e) {
725
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
726
+ const i2 = Math.max(
727
+ this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt),
728
+ 0
729
+ );
730
+ this.cursor = this.options[i2]?.disabled ? findCursor(i2, 1, this.options) : i2, this.on("key", (t2, l) => {
731
+ l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
732
+ }), this.on("cursor", (t2) => {
733
+ switch (t2) {
734
+ case "left":
735
+ case "up":
736
+ this.cursor = findCursor(this.cursor, -1, this.options);
737
+ break;
738
+ case "down":
739
+ case "right":
740
+ this.cursor = findCursor(this.cursor, 1, this.options);
741
+ break;
742
+ case "space":
743
+ this.toggleValue();
744
+ break;
745
+ }
746
+ });
747
+ }
748
+ };
749
+ var n$1 = class n extends y {
750
+ options;
751
+ cursor = 0;
752
+ get _selectedValue() {
753
+ return this.options[this.cursor];
754
+ }
755
+ changeValue() {
756
+ const e = this._selectedValue;
757
+ this.value = e === void 0 ? void 0 : e.value;
758
+ }
759
+ constructor(e) {
760
+ super(e, false), this.options = e.options;
761
+ const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t2 = o === -1 ? 0 : o;
762
+ this.cursor = this.options[t2]?.disabled ? findCursor(t2, 1, this.options) : t2, this.changeValue(), this.on("cursor", (s) => {
763
+ switch (s) {
764
+ case "left":
765
+ case "up":
766
+ this.cursor = findCursor(this.cursor, -1, this.options);
767
+ break;
768
+ case "down":
769
+ case "right":
770
+ this.cursor = findCursor(this.cursor, 1, this.options);
771
+ break;
772
+ }
773
+ this.changeValue();
774
+ });
775
+ }
776
+ };
777
+ var n2 = class extends y {
778
+ get userInputWithCursor() {
779
+ if (this.state === "submit")
780
+ return this.userInput;
781
+ const t2 = this.userInput;
782
+ if (this.cursor >= t2.length)
783
+ return `${this.userInput}\u2588`;
784
+ const r2 = t2.slice(0, this.cursor), s = t2.slice(this.cursor, this.cursor + 1), e = t2.slice(this.cursor + 1);
785
+ return `${r2}${styleText("inverse", s)}${e}`;
786
+ }
787
+ get cursor() {
788
+ return this._cursor;
789
+ }
790
+ constructor(t2) {
791
+ super({
792
+ ...t2,
793
+ initialUserInput: t2.initialUserInput ?? t2.initialValue
794
+ }), this.on("userInput", (r2) => {
795
+ this._setValue(r2);
796
+ }), this.on("finalize", () => {
797
+ this.value || (this.value = t2.defaultValue), this.value === void 0 && (this.value = "");
798
+ });
799
+ }
800
+ };
801
+
802
+ // node_modules/@clack/prompts/dist/index.mjs
803
+ import { styleText as styleText2, stripVTControlCharacters } from "node:util";
804
+ import process$1 from "node:process";
805
+ var import_sisteransi2 = __toESM(require_src(), 1);
806
+ function isUnicodeSupported() {
807
+ if (process$1.platform !== "win32") {
808
+ return process$1.env.TERM !== "linux";
809
+ }
810
+ 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";
811
+ }
812
+ var unicode = isUnicodeSupported();
813
+ var unicodeOr = (o, e) => unicode ? o : e;
814
+ var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
815
+ var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
816
+ var S_STEP_ERROR = unicodeOr("\u25B2", "x");
817
+ var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
818
+ var S_BAR_START = unicodeOr("\u250C", "T");
819
+ var S_BAR = unicodeOr("\u2502", "|");
820
+ var S_BAR_END = unicodeOr("\u2514", "\u2014");
821
+ var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
822
+ var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
823
+ var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
824
+ var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
825
+ var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
826
+ var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
827
+ var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
828
+ var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
829
+ var S_BAR_H = unicodeOr("\u2500", "-");
830
+ var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
831
+ var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
832
+ var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
833
+ var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
834
+ var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
835
+ var S_INFO = unicodeOr("\u25CF", "\u2022");
836
+ var S_SUCCESS = unicodeOr("\u25C6", "*");
837
+ var S_WARN = unicodeOr("\u25B2", "!");
838
+ var S_ERROR = unicodeOr("\u25A0", "x");
839
+ var symbol = (o) => {
840
+ switch (o) {
841
+ case "initial":
842
+ case "active":
843
+ return styleText2("cyan", S_STEP_ACTIVE);
844
+ case "cancel":
845
+ return styleText2("red", S_STEP_CANCEL);
846
+ case "error":
847
+ return styleText2("yellow", S_STEP_ERROR);
848
+ case "submit":
849
+ return styleText2("green", S_STEP_SUBMIT);
850
+ case "validating":
851
+ return styleText2("dim", S_STEP_ACTIVE);
852
+ }
853
+ };
854
+ var symbolBar = (o) => {
855
+ switch (o) {
856
+ case "initial":
857
+ case "active":
858
+ return styleText2("cyan", S_BAR);
859
+ case "cancel":
860
+ return styleText2("red", S_BAR);
861
+ case "error":
862
+ return styleText2("yellow", S_BAR);
863
+ case "submit":
864
+ return styleText2("green", S_BAR);
865
+ }
866
+ };
867
+ function formatInstructionFooter(o, e) {
868
+ const r2 = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o.join(" \u2022 ")}`];
869
+ return e && r2.push(styleText2("cyan", S_BAR_END)), r2;
870
+ }
871
+ var I = (l, e, w, p, b, C = false) => {
872
+ let r2 = e, O = 0;
873
+ if (C)
874
+ for (let i2 = p - 1; i2 >= w; i2--) {
875
+ const m2 = l[i2];
876
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
877
+ }
878
+ else
879
+ for (let i2 = w; i2 < p; i2++) {
880
+ const m2 = l[i2];
881
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
882
+ }
883
+ return { lineCount: r2, removals: O };
884
+ };
885
+ var limitOptions = ({
886
+ cursor: l,
887
+ options: e,
888
+ style: w,
889
+ output: p = process.stdout,
890
+ maxItems: b = Number.POSITIVE_INFINITY,
891
+ columnPadding: C = 0,
892
+ rowPadding: r2 = 4
893
+ }) => {
894
+ const i2 = getColumns(p) - C, m2 = getRows(p), M = styleText2("dim", "..."), v = Math.max(m2 - r2, 0), a2 = Math.max(Math.min(b, v), 5);
895
+ let f = 0;
896
+ l >= a2 - 3 && (f = Math.max(
897
+ Math.min(l - a2 + 3, e.length - a2),
898
+ 0
899
+ ));
900
+ let d = a2 < e.length && f > 0, c2 = a2 < e.length && f + a2 < e.length;
901
+ const W = Math.min(
902
+ f + a2,
903
+ e.length
904
+ ), s = [];
905
+ let g = 0;
906
+ d && g++, c2 && g++;
907
+ const T = f + (d ? 1 : 0), y2 = W - (c2 ? 1 : 0);
908
+ for (let t2 = T; t2 < y2; t2++) {
909
+ const n3 = e[t2], o = n3 ? w(n3, t2 === l) : "", h2 = wrapAnsi(o, i2, {
910
+ hard: true,
911
+ trim: false
912
+ }).split(`
913
+ `);
914
+ s.push(h2), g += h2.length;
915
+ }
916
+ if (g > v) {
917
+ let t2 = 0, n3 = 0, o = g;
918
+ const h2 = l - T;
919
+ let u3 = v;
920
+ const L = () => I(s, o, 0, h2, u3), E = () => I(
921
+ s,
922
+ o,
923
+ h2 + 1,
924
+ s.length,
925
+ u3,
926
+ true
927
+ );
928
+ d ? ({ lineCount: o, removals: t2 } = L(), o > u3 && (c2 || (u3 -= 1), { lineCount: o, removals: n3 } = E())) : (c2 || (u3 -= 1), { lineCount: o, removals: n3 } = E(), o > u3 && (u3 -= 1, { lineCount: o, removals: t2 } = L())), t2 > 0 && (d = true, s.splice(0, t2)), n3 > 0 && (c2 = true, s.splice(s.length - n3, n3));
929
+ }
930
+ const x = [];
931
+ d && x.push(M);
932
+ for (const t2 of s)
933
+ for (const n3 of t2)
934
+ x.push(n3);
935
+ return c2 && x.push(M), x;
936
+ };
937
+ var MULTISELECT_INSTRUCTIONS = [
938
+ `${styleText2("dim", "\u2191/\u2193")} to navigate`,
939
+ `${styleText2("dim", "Space:")} select`,
940
+ `${styleText2("dim", "Enter:")} confirm`
941
+ ];
942
+ var m = (i2, u3) => i2.split(`
943
+ `).map((d) => u3(d)).join(`
944
+ `);
945
+ var multiselect = (i2) => {
946
+ const u3 = (t2, a2) => {
947
+ const r2 = t2.label ?? String(t2.value);
948
+ return a2 === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${m(r2, (o) => styleText2(["strikethrough", "gray"], o))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}` : a2 === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a2 === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${m(r2, (o) => styleText2("dim", o))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a2 === "cancelled" ? `${m(r2, (o) => styleText2(["strikethrough", "dim"], o))}` : a2 === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a2 === "submitted" ? `${m(r2, (o) => styleText2("dim", o))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${m(r2, (o) => styleText2("dim", o))}`;
949
+ }, d = i2.required ?? true, x = i2.showInstructions ?? true;
950
+ return new a({
951
+ options: i2.options,
952
+ signal: i2.signal,
953
+ input: i2.input,
954
+ output: i2.output,
955
+ initialValues: i2.initialValues,
956
+ required: d,
957
+ cursorAt: i2.cursorAt,
958
+ validate(t2) {
959
+ if (d && (t2 === void 0 || t2.length === 0))
960
+ return `Please select at least one option.
961
+ ${styleText2(
962
+ "reset",
963
+ styleText2(
964
+ "dim",
965
+ `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2(
966
+ "gray",
967
+ styleText2("bgWhite", styleText2("inverse", " enter "))
968
+ )} to submit`
969
+ )
970
+ )}`;
971
+ },
972
+ render() {
973
+ const t2 = i2.withGuide ?? settings.withGuide, a2 = wrapTextWithPrefix(
974
+ i2.output,
975
+ i2.message,
976
+ t2 ? `${symbolBar(this.state)} ` : "",
977
+ `${symbol(this.state)} `
978
+ ), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
979
+ ` : ""}${a2}
980
+ `, o = this.value ?? [], g = (n3, l) => {
981
+ if (n3.disabled)
982
+ return u3(n3, "disabled");
983
+ const s = o.includes(n3.value);
984
+ return l && s ? u3(n3, "active-selected") : s ? u3(n3, "selected") : u3(n3, l ? "active" : "inactive");
985
+ };
986
+ switch (this.state) {
987
+ case "submit": {
988
+ const n3 = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u3(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), l = wrapTextWithPrefix(
989
+ i2.output,
990
+ n3,
991
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
992
+ );
993
+ return `${r2}${l}`;
994
+ }
995
+ case "cancel": {
996
+ const n3 = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u3(s, "cancelled")).join(styleText2("dim", ", "));
997
+ if (n3.trim() === "")
998
+ return `${r2}${styleText2("gray", S_BAR)}`;
999
+ const l = wrapTextWithPrefix(
1000
+ i2.output,
1001
+ n3,
1002
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
1003
+ );
1004
+ return `${r2}${l}${t2 ? `
1005
+ ${styleText2("gray", S_BAR)}` : ""}`;
1006
+ }
1007
+ case "error": {
1008
+ const n3 = t2 ? `${styleText2("yellow", S_BAR)} ` : "", l = this.error.split(`
1009
+ `).map(
1010
+ ($, v) => v === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $)}` : ` ${$}`
1011
+ ).join(`
1012
+ `), s = r2.split(`
1013
+ `).length, h2 = l.split(`
1014
+ `).length + 1;
1015
+ return `${r2}${n3}${limitOptions({
1016
+ output: i2.output,
1017
+ options: this.options,
1018
+ cursor: this.cursor,
1019
+ maxItems: i2.maxItems,
1020
+ columnPadding: n3.length,
1021
+ rowPadding: s + h2,
1022
+ style: g
1023
+ }).join(`
1024
+ ${n3}`)}
1025
+ ${l}
1026
+ `;
1027
+ }
1028
+ default: {
1029
+ const n3 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", l = r2.split(`
1030
+ `).length, s = x ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t2) : t2 ? [styleText2("cyan", S_BAR_END)] : [], h2 = s.join(`
1031
+ `), $ = s.length + 1;
1032
+ return `${r2}${n3}${limitOptions({
1033
+ output: i2.output,
1034
+ options: this.options,
1035
+ cursor: this.cursor,
1036
+ maxItems: i2.maxItems,
1037
+ columnPadding: n3.length,
1038
+ rowPadding: l + $,
1039
+ style: g
1040
+ }).join(`
1041
+ ${n3}`)}
1042
+ ${h2}
1043
+ `;
1044
+ }
1045
+ }
1046
+ }
1047
+ }).prompt();
1048
+ };
1049
+ var log = {
1050
+ message: (s = [], {
1051
+ symbol: e = styleText2("gray", S_BAR),
1052
+ secondarySymbol: r2 = styleText2("gray", S_BAR),
1053
+ output: m2 = process.stdout,
1054
+ spacing: l = 1,
1055
+ withGuide: c2
1056
+ } = {}) => {
1057
+ const t2 = [], o = c2 ?? settings.withGuide, f = o ? r2 : "", O = o ? `${e} ` : "", u3 = o ? `${r2} ` : "";
1058
+ for (let i2 = 0; i2 < l; i2++)
1059
+ t2.push(f);
1060
+ const g = Array.isArray(s) ? s : s.split(`
1061
+ `);
1062
+ if (g.length > 0) {
1063
+ const [i2, ...y2] = g;
1064
+ i2.length > 0 ? t2.push(`${O}${i2}`) : t2.push(o ? e : "");
1065
+ for (const p of y2)
1066
+ p.length > 0 ? t2.push(`${u3}${p}`) : t2.push(o ? r2 : "");
1067
+ }
1068
+ m2.write(`${t2.join(`
1069
+ `)}
1070
+ `);
1071
+ },
1072
+ info: (s, e) => {
1073
+ log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
1074
+ },
1075
+ success: (s, e) => {
1076
+ log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
1077
+ },
1078
+ step: (s, e) => {
1079
+ log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
1080
+ },
1081
+ warn: (s, e) => {
1082
+ log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
1083
+ },
1084
+ /** alias for `log.warn()`. */
1085
+ warning: (s, e) => {
1086
+ log.warn(s, e);
1087
+ },
1088
+ error: (s, e) => {
1089
+ log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
1090
+ }
1091
+ };
1092
+ var u2 = {
1093
+ light: unicodeOr("\u2500", "-"),
1094
+ heavy: unicodeOr("\u2501", "="),
1095
+ block: unicodeOr("\u2588", "#")
1096
+ };
1097
+ var SELECT_INSTRUCTIONS = [
1098
+ `${styleText2("dim", "\u2191/\u2193")} to navigate`,
1099
+ `${styleText2("dim", "Enter:")} confirm`
1100
+ ];
1101
+ var c = (t2, o) => t2.includes(`
1102
+ `) ? t2.split(`
1103
+ `).map((d) => o(d)).join(`
1104
+ `) : o(t2);
1105
+ var select = (t2) => {
1106
+ const o = (n3, m2) => {
1107
+ if (n3 === void 0)
1108
+ return "";
1109
+ const s = n3.label ?? String(n3.value);
1110
+ switch (m2) {
1111
+ case "disabled":
1112
+ return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (i2) => styleText2("gray", i2))}${n3.hint ? ` ${styleText2("dim", `(${n3.hint ?? "disabled"})`)}` : ""}`;
1113
+ case "selected":
1114
+ return `${c(s, (i2) => styleText2("dim", i2))}`;
1115
+ case "active":
1116
+ return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${n3.hint ? ` ${styleText2("dim", `(${n3.hint})`)}` : ""}`;
1117
+ case "cancelled":
1118
+ return `${c(s, (i2) => styleText2(["strikethrough", "dim"], i2))}`;
1119
+ default:
1120
+ return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (i2) => styleText2("dim", i2))}`;
1121
+ }
1122
+ }, d = t2.showInstructions ?? true;
1123
+ return new n$1({
1124
+ options: t2.options,
1125
+ signal: t2.signal,
1126
+ input: t2.input,
1127
+ output: t2.output,
1128
+ initialValue: t2.initialValue,
1129
+ render() {
1130
+ const n3 = t2.withGuide ?? settings.withGuide, m2 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i2 = wrapTextWithPrefix(
1131
+ t2.output,
1132
+ t2.message,
1133
+ s,
1134
+ m2
1135
+ ), u3 = `${n3 ? `${styleText2("gray", S_BAR)}
1136
+ ` : ""}${i2}
1137
+ `;
1138
+ switch (this.state) {
1139
+ case "submit": {
1140
+ const r2 = n3 ? `${styleText2("gray", S_BAR)} ` : "", a2 = wrapTextWithPrefix(
1141
+ t2.output,
1142
+ o(this.options[this.cursor], "selected"),
1143
+ r2
1144
+ );
1145
+ return `${u3}${a2}`;
1146
+ }
1147
+ case "cancel": {
1148
+ const r2 = n3 ? `${styleText2("gray", S_BAR)} ` : "", a2 = wrapTextWithPrefix(
1149
+ t2.output,
1150
+ o(this.options[this.cursor], "cancelled"),
1151
+ r2
1152
+ );
1153
+ return `${u3}${a2}${n3 ? `
1154
+ ${styleText2("gray", S_BAR)}` : ""}`;
1155
+ }
1156
+ default: {
1157
+ const r2 = n3 ? `${styleText2("cyan", S_BAR)} ` : "", a2 = u3.split(`
1158
+ `).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n3) : n3 ? [styleText2("cyan", S_BAR_END)] : [], f = p.join(`
1159
+ `), b = p.length + 1;
1160
+ return `${u3}${r2}${limitOptions({
1161
+ output: t2.output,
1162
+ cursor: this.cursor,
1163
+ options: this.options,
1164
+ maxItems: t2.maxItems,
1165
+ columnPadding: r2.length,
1166
+ rowPadding: a2 + b,
1167
+ style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
1168
+ }).join(`
1169
+ ${r2}`)}
1170
+ ${f}
1171
+ `;
1172
+ }
1173
+ }
1174
+ }
1175
+ }).prompt();
1176
+ };
1177
+ var i = `${styleText2("gray", S_BAR)} `;
1178
+ var text = (t2) => new n2({
1179
+ validate: t2.validate,
1180
+ placeholder: t2.placeholder,
1181
+ defaultValue: t2.defaultValue,
1182
+ initialValue: t2.initialValue,
1183
+ output: t2.output,
1184
+ signal: t2.signal,
1185
+ input: t2.input,
1186
+ render() {
1187
+ const r2 = t2?.withGuide ?? settings.withGuide, l = `${`${r2 ? `${styleText2("gray", S_BAR)}
1188
+ ` : ""}${symbol(this.state)} `}${t2.message}
1189
+ `, d = t2.placeholder && t2.placeholder.length > 0 ? (
1190
+ // biome-ignore lint/style/noNonNullAssertion: guarded by placeholder.length > 0
1191
+ styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1))
1192
+ ) : styleText2(["inverse", "hidden"], "_"), o = this.userInput ? this.userInputWithCursor : d, s = this.value ?? "";
1193
+ switch (this.state) {
1194
+ case "validating": {
1195
+ const n3 = r2 ? `${styleText2("cyan", S_BAR)} ` : "", i2 = r2 ? styleText2("cyan", S_BAR_END) : "", c2 = styleText2("dim", o), $ = styleText2("dim", "Validating...");
1196
+ return `${l}${n3}${c2}
1197
+ ${i2} ${$}
1198
+ `;
1199
+ }
1200
+ case "error": {
1201
+ const n3 = this.error ? ` ${styleText2("yellow", this.error)}` : "", i2 = r2 ? `${styleText2("yellow", S_BAR)} ` : "", c2 = r2 ? styleText2("yellow", S_BAR_END) : "";
1202
+ return `${l.trim()}
1203
+ ${i2}${o}
1204
+ ${c2}${n3}
1205
+ `;
1206
+ }
1207
+ case "submit": {
1208
+ const n3 = s ? `${r2 ? " " : ""}${styleText2("dim", s)}` : "", i2 = r2 ? styleText2("gray", S_BAR) : "";
1209
+ return `${l}${i2}${n3}`;
1210
+ }
1211
+ case "cancel": {
1212
+ const n3 = s ? ` ${styleText2(["strikethrough", "dim"], s)}` : "", i2 = r2 ? styleText2("gray", S_BAR) : "";
1213
+ return `${l}${i2}${n3}${s.trim() ? `
1214
+ ${i2}` : ""}`;
1215
+ }
1216
+ default: {
1217
+ const n3 = r2 ? `${styleText2("cyan", S_BAR)} ` : "", i2 = r2 ? styleText2("cyan", S_BAR_END) : "";
1218
+ return `${l}${n3}${o}
1219
+ ${i2}
1220
+ `;
1221
+ }
1222
+ }
1223
+ }
1224
+ }).prompt();
1225
+
1226
+ // src/ui.ts
1227
+ import { spawn } from "node:child_process";
1228
+ function approvalStatus(progress) {
1229
+ return progress.phase === "waiting" ? "Approve in the browser" : progress.httpStatus === 429 ? "Approval API is rate limited; retrying" : progress.httpStatus ? `Approval API returned HTTP ${progress.httpStatus}; retrying` : "Approval API connection interrupted; retrying";
1230
+ }
1231
+ function approvalProgressMessage(progress) {
1232
+ const status = progress.phase === "waiting" ? "Waiting for browser approval" : approvalStatus(progress);
1233
+ return `${status} \xB7 ${progress.elapsedSeconds}s elapsed`;
1234
+ }
1235
+ var Cancelled = class extends Error {
1236
+ constructor() {
1237
+ super("Installation cancelled.");
1238
+ }
1239
+ };
1240
+ var clean = (value) => value.replace(/\r\n?/g, "\n").replace(/\t/g, " ").replace(/[\x00-\x09\x0b-\x1f\x7f-\x9f]/g, "");
1241
+ var STYLE = /\x1b\[(?:1|22|39|3[0-7]|9[0-7]|38;2;\d{1,3};\d{1,3};\d{1,3}|38;5;\d{1,3})m/y;
1242
+ function cleanStyled(value) {
1243
+ let out = "";
1244
+ const text2 = value.replace(/\r\n?/g, "\n").replace(/\t/g, " ");
1245
+ for (let i2 = 0; i2 < text2.length; i2++) {
1246
+ const ch = text2[i2];
1247
+ if (ch === "\x1B") {
1248
+ STYLE.lastIndex = i2;
1249
+ const match = STYLE.exec(text2);
1250
+ if (match) {
1251
+ out += match[0];
1252
+ i2 += match[0].length - 1;
1253
+ }
1254
+ continue;
1255
+ }
1256
+ if (/[\x00-\x09\x0b-\x1f\x7f-\x9f]/.test(ch)) continue;
1257
+ out += ch;
1258
+ }
1259
+ return out;
1260
+ }
1261
+ function normalizeOrigin(value, environment) {
1262
+ const text2 = value.trim();
1263
+ if (!text2) throw new Error("Enter your app URL, for example app.example.com.");
1264
+ const loopback = /^(localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/?$/i.test(text2);
1265
+ const candidate = /^[a-z][a-z\d+.-]*:\/\//i.test(text2) ? text2 : `${loopback && environment === "development" ? "http" : "https"}://${text2}`;
1266
+ try {
1267
+ return origin(candidate, environment);
1268
+ } catch {
1269
+ throw new Error(
1270
+ environment === "production" ? "Enter an HTTPS app origin such as app.example.com, without a path, query or credentials." : "Enter an app origin such as app.example.com or localhost:3000, without a path, query or credentials."
1271
+ );
1272
+ }
1273
+ }
1274
+ function answer(value) {
1275
+ if (isCancel(value)) throw new Cancelled();
1276
+ return value;
1277
+ }
1278
+ var Terminal = class {
1279
+ constructor(interactive, json, options = {}) {
1280
+ this.interactive = interactive;
1281
+ this.json = json;
1282
+ this.kit = createUiKit({ level: detectColorLevel({ stream: process.stdout, off: options.color === false }) });
1283
+ }
1284
+ interactive;
1285
+ json;
1286
+ kit;
1287
+ /** What to say about the state of the project if the person cancels now. */
1288
+ cancelState = "nothing was written";
1289
+ /** True after output that leaves no guide line behind, so the next event adds one. */
1290
+ gap = false;
1291
+ header(options) {
1292
+ const lines = this.kit.header({ ...options, trademark: this.interactive });
1293
+ if (this.interactive) for (const line of lines) process.stdout.write(cleanStyled(line) + "\n");
1294
+ else process.stderr.write(clean(stripAnsi(lines[0])) + "\n");
1295
+ }
1296
+ event(kind, message) {
1297
+ if (this.interactive) {
1298
+ log.message(cleanStyled(message), { symbol: this.kit.symbol[kind], spacing: this.gap ? 1 : 0 });
1299
+ this.gap = false;
1300
+ } else process.stderr.write(plainLine(kind, clean(stripAnsi(message)).split("\n").join("\n ")) + "\n");
1301
+ }
1302
+ info(message) {
1303
+ this.event("info", message);
1304
+ }
1305
+ success(message) {
1306
+ this.event("done", message);
1307
+ }
1308
+ warn(message) {
1309
+ this.event("warn", message);
1310
+ }
1311
+ /** A stopped run: what failed, what is true now, and what to do next. */
1312
+ error(message, hints = []) {
1313
+ this.event("error", [message, ...hints.map((hint) => ` ${this.kit.c.muted(hint)}`)].join("\n"));
1314
+ }
1315
+ /** A titled block of rows, such as Changes, Ready or Next steps. */
1316
+ block(title, rows, options = {}) {
1317
+ const { c: c2, S } = this.kit;
1318
+ const heading = `${c2.bold(title)}${options.suffix ? ` ${options.suffix}` : ""}`;
1319
+ if (this.interactive) {
1320
+ log.message([heading, ...rows.map((row) => ` ${row}`)].map(cleanStyled).join("\n"), { symbol: c2.faint(S.section), spacing: 1 });
1321
+ this.gap = true;
1322
+ } else if (options.each) for (const row of rows) process.stderr.write(plainLine(options.kind ?? "info", clean(stripAnsi(row))) + "\n");
1323
+ else {
1324
+ process.stderr.write(plainLine(options.kind ?? "info", clean(stripAnsi(heading))) + "\n");
1325
+ for (const row of rows) process.stderr.write(` ${clean(stripAnsi(row))}
1326
+ `);
1327
+ }
1328
+ }
1329
+ note(message, title) {
1330
+ const rows = clean(message).split("\n");
1331
+ while (rows.length && !rows[rows.length - 1].trim()) rows.pop();
1332
+ this.block(clean(title), rows);
1333
+ }
1334
+ /**
1335
+ * Work that waits for a person, such as a browser approval. The instruction is the spinner line, so it is on
1336
+ * screen only while it matters; `stop` removes it (and the link under it) for the caller to replace with a result.
1337
+ */
1338
+ waiting(message, options = {}) {
1339
+ let lastReport = Date.now(), lastStatus = message.split(" \xB7 ")[0], rows = 0;
1340
+ const link = options.link ? clean(options.link) : void 0;
1341
+ if (!this.interactive || link) {
1342
+ if (this.interactive && link) {
1343
+ const columns = process.stdout.columns || 80;
1344
+ rows = (this.gap ? 1 : 0) + [`\u25CF ${message}`, `\u2502 ${link}`].reduce((total, line) => total + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1345
+ }
1346
+ this.info(link ? `${message}
1347
+ ${this.kit.c.code(link)}` : message);
1348
+ }
1349
+ const spinner = this.interactive ? createSpinner(this.kit, process.stdout, { onCancel: () => this.cancelled(true) }) : void 0;
1350
+ spinner?.start(cleanStyled(message));
1351
+ return {
1352
+ stop: (result) => {
1353
+ spinner?.stop();
1354
+ if (rows) process.stdout.write(`\x1B[${rows}A\x1B[J`);
1355
+ if (rows) this.gap = false;
1356
+ if (result) this.success(result);
1357
+ },
1358
+ update: (next) => {
1359
+ if (spinner) {
1360
+ spinner.message(cleanStyled(next));
1361
+ return;
1362
+ }
1363
+ const status = next.split(" \xB7 ")[0];
1364
+ if (status !== lastStatus || Date.now() - lastReport >= 15e3) {
1365
+ this.info(next);
1366
+ lastReport = Date.now();
1367
+ lastStatus = status;
1368
+ }
1369
+ }
1370
+ };
1371
+ }
1372
+ /** Print the state of the project and leave: used when the run is stopped from the keyboard. */
1373
+ cancelled(afterSpinner = false) {
1374
+ if (this.interactive && afterSpinner) process.stdout.write("\n");
1375
+ this.error(`Cancelled ${this.kit.c.muted(`${this.kit.S.dot} ${this.cancelState}`)}`);
1376
+ process.exit(130);
1377
+ }
1378
+ async text(message, initialValue, validate) {
1379
+ if (!this.interactive) {
1380
+ if (initialValue !== void 0) {
1381
+ const error = validate?.(initialValue);
1382
+ if (error) throw new Error(error);
1383
+ return initialValue;
1384
+ }
1385
+ throw new Error(`Missing ${message.toLowerCase()}. Supply the corresponding command option.`);
1386
+ }
1387
+ const value = answer(
1388
+ await text({
1389
+ message,
1390
+ defaultValue: initialValue,
1391
+ placeholder: initialValue,
1392
+ // Clack validates before applying defaultValue on submission.
1393
+ validate: (value2) => validate?.(value2 || initialValue || "")
1394
+ })
1395
+ );
1396
+ this.gap = true;
1397
+ return value;
1398
+ }
1399
+ async select(message, options, initialValue) {
1400
+ if (!this.interactive)
1401
+ throw new Error(`${message}: supply an explicit workspace/site option in non-interactive mode.`);
1402
+ const value = answer(
1403
+ await select({
1404
+ message,
1405
+ options: options.map((item) => ({ ...item, label: cleanStyled(item.label) })),
1406
+ initialValue
1407
+ })
1408
+ );
1409
+ this.gap = true;
1410
+ return value;
1411
+ }
1412
+ /** Several optional steps in one prompt. Descriptions are hints, which clack shows on the focused row. */
1413
+ async multiselect(message, options, initialValues) {
1414
+ if (!this.interactive) return initialValues.filter((value) => options.some((item) => item.value === value));
1415
+ const values = answer(
1416
+ await multiselect({
1417
+ message: cleanStyled(message),
1418
+ options: options.map((item) => ({ ...item, label: clean(item.label), ...item.hint ? { hint: clean(item.hint) } : {} })),
1419
+ initialValues,
1420
+ required: false
1421
+ })
1422
+ );
1423
+ this.gap = true;
1424
+ return values;
1425
+ }
1426
+ async confirm(message, initialValue = true, options = {}) {
1427
+ if (!this.interactive) return false;
1428
+ const value = answer(await select({
1429
+ message: clean(message),
1430
+ initialValue,
1431
+ options: [
1432
+ { value: true, label: options.recommended ? "Yes (recommended)" : "Yes" },
1433
+ { value: false, label: "No" }
1434
+ ]
1435
+ }));
1436
+ this.gap = true;
1437
+ return value;
1438
+ }
1439
+ /** Work with a spinner. `done` may be computed from the outcome, and may return nothing to print no result line. */
1440
+ async task(message, operation, done = message) {
1441
+ const spinner = this.interactive ? createSpinner(this.kit, process.stdout, { onCancel: () => this.cancelled(true) }) : void 0;
1442
+ spinner?.start(cleanStyled(message));
1443
+ try {
1444
+ const value = await operation();
1445
+ spinner?.stop();
1446
+ const result = typeof done === "function" ? done() : done;
1447
+ if (result) this.success(result);
1448
+ return value;
1449
+ } catch (error) {
1450
+ spinner?.stop();
1451
+ throw error;
1452
+ }
1453
+ }
1454
+ };
1455
+ async function openBrowser(value) {
1456
+ const url = new URL(value);
1457
+ if (url.username || url.password || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)))
1458
+ throw new Error("Invalid browser URL");
1459
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "rundll32" : "xdg-open";
1460
+ const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", url.href] : [url.href];
1461
+ return new Promise((resolve) => {
1462
+ const child = spawn(command, args, { stdio: "ignore", shell: false });
1463
+ child.once("error", () => resolve(false));
1464
+ child.once("exit", (code) => resolve(code === 0));
1465
+ });
1466
+ }
1467
+
1468
+ export {
1469
+ approvalStatus,
1470
+ approvalProgressMessage,
1471
+ Cancelled,
1472
+ clean,
1473
+ cleanStyled,
1474
+ normalizeOrigin,
1475
+ Terminal,
1476
+ openBrowser
1477
+ };