zapdev 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/dist/index.js +2357 -1950
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -90,2043 +90,1631 @@ var require_src = __commonJS((exports, module) => {
|
|
|
90
90
|
module.exports = { cursor, scroll, erase, beep };
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
// node_modules/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
108
|
-
const parts = [];
|
|
109
|
-
if (!str || typeof str !== "string")
|
|
110
|
-
return parts;
|
|
111
|
-
let buff = "";
|
|
112
|
-
let previousUpper;
|
|
113
|
-
let previousSplitter;
|
|
114
|
-
for (const char of str) {
|
|
115
|
-
const isSplitter = splitters.includes(char);
|
|
116
|
-
if (isSplitter === true) {
|
|
117
|
-
parts.push(buff);
|
|
118
|
-
buff = "";
|
|
119
|
-
previousUpper = undefined;
|
|
120
|
-
continue;
|
|
93
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
94
|
+
import { styleText } from "util";
|
|
95
|
+
import { stdout, stdin } from "process";
|
|
96
|
+
import * as l from "readline";
|
|
97
|
+
import l__default from "readline";
|
|
98
|
+
|
|
99
|
+
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
100
|
+
var getCodePointsLength = (() => {
|
|
101
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
102
|
+
return (input) => {
|
|
103
|
+
let surrogatePairsNr = 0;
|
|
104
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
105
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
106
|
+
surrogatePairsNr += 1;
|
|
121
107
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
return input.length - surrogatePairsNr;
|
|
109
|
+
};
|
|
110
|
+
})();
|
|
111
|
+
var isFullWidth = (x) => {
|
|
112
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
113
|
+
};
|
|
114
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
115
|
+
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;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// node_modules/fast-string-truncated-width/dist/index.js
|
|
119
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
120
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
121
|
+
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;
|
|
122
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
123
|
+
var 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?))*/yu;
|
|
124
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
125
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
126
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
127
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
128
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
129
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
130
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
131
|
+
const ANSI_WIDTH = 0;
|
|
132
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
133
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
134
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
135
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
136
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
137
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
138
|
+
const PARSE_BLOCKS = [
|
|
139
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
140
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
141
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
142
|
+
[TAB_RE, TAB_WIDTH],
|
|
143
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
144
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
145
|
+
];
|
|
146
|
+
let indexPrev = 0;
|
|
147
|
+
let index = 0;
|
|
148
|
+
let length = input.length;
|
|
149
|
+
let lengthExtra = 0;
|
|
150
|
+
let truncationEnabled = false;
|
|
151
|
+
let truncationIndex = length;
|
|
152
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
153
|
+
let unmatchedStart = 0;
|
|
154
|
+
let unmatchedEnd = 0;
|
|
155
|
+
let width = 0;
|
|
156
|
+
let widthExtra = 0;
|
|
157
|
+
outer:
|
|
158
|
+
while (true) {
|
|
159
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
160
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
161
|
+
lengthExtra = 0;
|
|
162
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
163
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
164
|
+
if (isFullWidth(codePoint)) {
|
|
165
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
166
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
167
|
+
widthExtra = WIDE_WIDTH;
|
|
168
|
+
} else {
|
|
169
|
+
widthExtra = REGULAR_WIDTH;
|
|
170
|
+
}
|
|
171
|
+
if (width + widthExtra > truncationLimit) {
|
|
172
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
173
|
+
}
|
|
174
|
+
if (width + widthExtra > LIMIT) {
|
|
175
|
+
truncationEnabled = true;
|
|
176
|
+
break outer;
|
|
177
|
+
}
|
|
178
|
+
lengthExtra += char.length;
|
|
179
|
+
width += widthExtra;
|
|
180
|
+
}
|
|
181
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
129
182
|
}
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
if (index >= length) {
|
|
184
|
+
break outer;
|
|
185
|
+
}
|
|
186
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
187
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
188
|
+
BLOCK_RE.lastIndex = index;
|
|
189
|
+
if (BLOCK_RE.test(input)) {
|
|
190
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
191
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
192
|
+
if (width + widthExtra > truncationLimit) {
|
|
193
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
194
|
+
}
|
|
195
|
+
if (width + widthExtra > LIMIT) {
|
|
196
|
+
truncationEnabled = true;
|
|
197
|
+
break outer;
|
|
198
|
+
}
|
|
199
|
+
width += widthExtra;
|
|
200
|
+
unmatchedStart = indexPrev;
|
|
201
|
+
unmatchedEnd = index;
|
|
202
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
203
|
+
continue outer;
|
|
204
|
+
}
|
|
136
205
|
}
|
|
206
|
+
index += 1;
|
|
137
207
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
147
|
-
}
|
|
148
|
-
function lowerFirst(str) {
|
|
149
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
150
|
-
}
|
|
151
|
-
function pascalCase(str, opts) {
|
|
152
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
153
|
-
}
|
|
154
|
-
function camelCase(str, opts) {
|
|
155
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
156
|
-
}
|
|
157
|
-
function kebabCase(str, joiner) {
|
|
158
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
159
|
-
}
|
|
160
|
-
function snakeCase(str) {
|
|
161
|
-
return kebabCase(str || "", "_");
|
|
162
|
-
}
|
|
208
|
+
return {
|
|
209
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
210
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
211
|
+
truncated: truncationEnabled,
|
|
212
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
var dist_default = getStringTruncatedWidth;
|
|
163
216
|
|
|
164
|
-
// node_modules/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return val === undefined ? [] : [val];
|
|
170
|
-
}
|
|
171
|
-
function formatLineColumns(lines, linePrefix = "") {
|
|
172
|
-
const maxLength = [];
|
|
173
|
-
for (const line of lines)
|
|
174
|
-
for (const [i, element] of line.entries())
|
|
175
|
-
maxLength[i] = Math.max(maxLength[i] || 0, element.length);
|
|
176
|
-
return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join(`
|
|
177
|
-
`);
|
|
178
|
-
}
|
|
179
|
-
function resolveValue(input) {
|
|
180
|
-
return typeof input === "function" ? input() : input;
|
|
181
|
-
}
|
|
182
|
-
var CLIError = class extends Error {
|
|
183
|
-
code;
|
|
184
|
-
constructor(message, code) {
|
|
185
|
-
super(message);
|
|
186
|
-
this.name = "CLIError";
|
|
187
|
-
this.code = code;
|
|
188
|
-
}
|
|
217
|
+
// node_modules/fast-string-width/dist/index.js
|
|
218
|
+
var NO_TRUNCATION2 = {
|
|
219
|
+
limit: Infinity,
|
|
220
|
+
ellipsis: "",
|
|
221
|
+
ellipsisWidth: 0
|
|
189
222
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (arg === "--") {
|
|
250
|
-
processedArgs.push(...args.slice(i));
|
|
251
|
-
break;
|
|
223
|
+
var fastStringWidth = (input, options = {}) => {
|
|
224
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
225
|
+
};
|
|
226
|
+
var dist_default2 = fastStringWidth;
|
|
227
|
+
|
|
228
|
+
// node_modules/fast-wrap-ansi/lib/main.js
|
|
229
|
+
var ESC = "\x1B";
|
|
230
|
+
var CSI = "\x9B";
|
|
231
|
+
var END_CODE = 39;
|
|
232
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
233
|
+
var ANSI_CSI = "[";
|
|
234
|
+
var ANSI_OSC = "]";
|
|
235
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
236
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
237
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
238
|
+
var getClosingCode = (openingCode) => {
|
|
239
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
240
|
+
return 39;
|
|
241
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
242
|
+
return 39;
|
|
243
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
244
|
+
return 49;
|
|
245
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
246
|
+
return 49;
|
|
247
|
+
if (openingCode === 1 || openingCode === 2)
|
|
248
|
+
return 22;
|
|
249
|
+
if (openingCode === 3)
|
|
250
|
+
return 23;
|
|
251
|
+
if (openingCode === 4)
|
|
252
|
+
return 24;
|
|
253
|
+
if (openingCode === 7)
|
|
254
|
+
return 27;
|
|
255
|
+
if (openingCode === 8)
|
|
256
|
+
return 28;
|
|
257
|
+
if (openingCode === 9)
|
|
258
|
+
return 29;
|
|
259
|
+
if (openingCode === 0)
|
|
260
|
+
return 0;
|
|
261
|
+
return;
|
|
262
|
+
};
|
|
263
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
264
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
265
|
+
var wrapWord = (rows, word, columns) => {
|
|
266
|
+
const characters = word[Symbol.iterator]();
|
|
267
|
+
let isInsideEscape = false;
|
|
268
|
+
let isInsideLinkEscape = false;
|
|
269
|
+
let lastRow = rows.at(-1);
|
|
270
|
+
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
271
|
+
let currentCharacter = characters.next();
|
|
272
|
+
let nextCharacter = characters.next();
|
|
273
|
+
let rawCharacterIndex = 0;
|
|
274
|
+
while (!currentCharacter.done) {
|
|
275
|
+
const character = currentCharacter.value;
|
|
276
|
+
const characterLength = dist_default2(character);
|
|
277
|
+
if (visible + characterLength <= columns) {
|
|
278
|
+
rows[rows.length - 1] += character;
|
|
279
|
+
} else {
|
|
280
|
+
rows.push(character);
|
|
281
|
+
visible = 0;
|
|
252
282
|
}
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
continue;
|
|
283
|
+
if (character === ESC || character === CSI) {
|
|
284
|
+
isInsideEscape = true;
|
|
285
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
257
286
|
}
|
|
258
|
-
|
|
287
|
+
if (isInsideEscape) {
|
|
288
|
+
if (isInsideLinkEscape) {
|
|
289
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
290
|
+
isInsideEscape = false;
|
|
291
|
+
isInsideLinkEscape = false;
|
|
292
|
+
}
|
|
293
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
294
|
+
isInsideEscape = false;
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
visible += characterLength;
|
|
298
|
+
if (visible === columns && !nextCharacter.done) {
|
|
299
|
+
rows.push("");
|
|
300
|
+
visible = 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
currentCharacter = nextCharacter;
|
|
304
|
+
nextCharacter = characters.next();
|
|
305
|
+
rawCharacterIndex += character.length;
|
|
259
306
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
args: processedArgs,
|
|
264
|
-
options: Object.keys(options).length > 0 ? options : undefined,
|
|
265
|
-
allowPositionals: true,
|
|
266
|
-
strict: false
|
|
267
|
-
});
|
|
268
|
-
} catch {
|
|
269
|
-
parsed = {
|
|
270
|
-
values: {},
|
|
271
|
-
positionals: processedArgs
|
|
272
|
-
};
|
|
307
|
+
lastRow = rows.at(-1);
|
|
308
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
309
|
+
rows[rows.length - 2] += rows.pop();
|
|
273
310
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
311
|
+
};
|
|
312
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
313
|
+
const words = string.split(" ");
|
|
314
|
+
let last = words.length;
|
|
315
|
+
while (last) {
|
|
316
|
+
if (dist_default2(words[last - 1])) {
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
last--;
|
|
283
320
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const mainName = aliasToMain.get(name);
|
|
287
|
-
if (mainName)
|
|
288
|
-
out[mainName] = false;
|
|
289
|
-
const aliases = mainToAliases.get(name);
|
|
290
|
-
if (aliases)
|
|
291
|
-
for (const alias of aliases)
|
|
292
|
-
out[alias] = false;
|
|
321
|
+
if (last === words.length) {
|
|
322
|
+
return string;
|
|
293
323
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (out[alias] !== out[main] && defaults[main] === out[main])
|
|
300
|
-
out[main] = out[alias];
|
|
324
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
325
|
+
};
|
|
326
|
+
var exec = (string, columns, options = {}) => {
|
|
327
|
+
if (options.trim !== false && string.trim() === "") {
|
|
328
|
+
return "";
|
|
301
329
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
330
|
+
let returnValue = "";
|
|
331
|
+
let escapeCode;
|
|
332
|
+
let escapeUrl;
|
|
333
|
+
const words = string.split(" ");
|
|
334
|
+
let rows = [""];
|
|
335
|
+
let rowLength = 0;
|
|
336
|
+
for (let index = 0;index < words.length; index++) {
|
|
337
|
+
const word = words[index];
|
|
338
|
+
if (options.trim !== false) {
|
|
339
|
+
const row = rows.at(-1) ?? "";
|
|
340
|
+
const trimmed = row.trimStart();
|
|
341
|
+
if (row.length !== trimmed.length) {
|
|
342
|
+
rows[rows.length - 1] = trimmed;
|
|
343
|
+
rowLength = dist_default2(trimmed);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (index !== 0) {
|
|
347
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
348
|
+
rows.push("");
|
|
349
|
+
rowLength = 0;
|
|
350
|
+
}
|
|
351
|
+
if (rowLength || options.trim === false) {
|
|
352
|
+
rows[rows.length - 1] += " ";
|
|
353
|
+
rowLength++;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const wordLength = dist_default2(word);
|
|
357
|
+
if (options.hard && wordLength > columns) {
|
|
358
|
+
const remainingColumns = columns - rowLength;
|
|
359
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
360
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
361
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
362
|
+
rows.push("");
|
|
363
|
+
}
|
|
364
|
+
wrapWord(rows, word, columns);
|
|
365
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
369
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
370
|
+
wrapWord(rows, word, columns);
|
|
371
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
rows.push("");
|
|
375
|
+
rowLength = 0;
|
|
376
|
+
}
|
|
377
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
378
|
+
wrapWord(rows, word, columns);
|
|
379
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
323
380
|
continue;
|
|
324
|
-
if (arg.type === "string" || arg.type === "enum")
|
|
325
|
-
parseOptions.string.push(arg.name);
|
|
326
|
-
else if (arg.type === "boolean")
|
|
327
|
-
parseOptions.boolean.push(arg.name);
|
|
328
|
-
if (arg.default !== undefined)
|
|
329
|
-
parseOptions.default[arg.name] = arg.default;
|
|
330
|
-
if (arg.alias)
|
|
331
|
-
parseOptions.alias[arg.name] = arg.alias;
|
|
332
|
-
const camelName = camelCase(arg.name);
|
|
333
|
-
const kebabName = kebabCase(arg.name);
|
|
334
|
-
if (camelName !== arg.name || kebabName !== arg.name) {
|
|
335
|
-
const existingAliases = toArray(parseOptions.alias[arg.name] || []);
|
|
336
|
-
if (camelName !== arg.name && !existingAliases.includes(camelName))
|
|
337
|
-
existingAliases.push(camelName);
|
|
338
|
-
if (kebabName !== arg.name && !existingAliases.includes(kebabName))
|
|
339
|
-
existingAliases.push(kebabName);
|
|
340
|
-
if (existingAliases.length > 0)
|
|
341
|
-
parseOptions.alias[arg.name] = existingAliases;
|
|
342
381
|
}
|
|
382
|
+
rows[rows.length - 1] += word;
|
|
383
|
+
rowLength += wordLength;
|
|
343
384
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
parsedArgsProxy[arg.name] = arg.default;
|
|
358
|
-
} else if (arg.type === "enum") {
|
|
359
|
-
const argument = parsedArgsProxy[arg.name];
|
|
360
|
-
const options = arg.options || [];
|
|
361
|
-
if (argument !== undefined && options.length > 0 && !options.includes(argument))
|
|
362
|
-
throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
|
|
363
|
-
} else if (arg.required && parsedArgsProxy[arg.name] === undefined)
|
|
364
|
-
throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
365
|
-
return parsedArgsProxy;
|
|
366
|
-
}
|
|
367
|
-
function resolveArgs(argsDef) {
|
|
368
|
-
const args = [];
|
|
369
|
-
for (const [name, argDef] of Object.entries(argsDef || {}))
|
|
370
|
-
args.push({
|
|
371
|
-
...argDef,
|
|
372
|
-
name,
|
|
373
|
-
alias: toArray(argDef.alias)
|
|
374
|
-
});
|
|
375
|
-
return args;
|
|
376
|
-
}
|
|
377
|
-
async function resolvePlugins(plugins) {
|
|
378
|
-
return Promise.all(plugins.map((p) => resolveValue(p)));
|
|
379
|
-
}
|
|
380
|
-
function defineCommand(def) {
|
|
381
|
-
return def;
|
|
382
|
-
}
|
|
383
|
-
async function runCommand(cmd, opts) {
|
|
384
|
-
const cmdArgs = await resolveValue(cmd.args || {});
|
|
385
|
-
const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
|
|
386
|
-
const context = {
|
|
387
|
-
rawArgs: opts.rawArgs,
|
|
388
|
-
args: parsedArgs,
|
|
389
|
-
data: opts.data,
|
|
390
|
-
cmd
|
|
391
|
-
};
|
|
392
|
-
const plugins = await resolvePlugins(cmd.plugins ?? []);
|
|
393
|
-
let result;
|
|
394
|
-
let runError;
|
|
395
|
-
try {
|
|
396
|
-
for (const plugin of plugins)
|
|
397
|
-
await plugin.setup?.(context);
|
|
398
|
-
if (typeof cmd.setup === "function")
|
|
399
|
-
await cmd.setup(context);
|
|
400
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
401
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
402
|
-
const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
|
|
403
|
-
const explicitName = opts.rawArgs[subCommandArgIndex];
|
|
404
|
-
if (explicitName) {
|
|
405
|
-
const subCommand = await _findSubCommand(subCommands, explicitName);
|
|
406
|
-
if (!subCommand)
|
|
407
|
-
throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
|
|
408
|
-
await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
409
|
-
} else {
|
|
410
|
-
const defaultSubCommand = await resolveValue(cmd.default);
|
|
411
|
-
if (defaultSubCommand) {
|
|
412
|
-
if (cmd.run)
|
|
413
|
-
throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
|
|
414
|
-
const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
|
|
415
|
-
if (!subCommand)
|
|
416
|
-
throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
|
|
417
|
-
await runCommand(subCommand, { rawArgs: opts.rawArgs });
|
|
418
|
-
} else if (!cmd.run)
|
|
419
|
-
throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
385
|
+
if (options.trim !== false) {
|
|
386
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
387
|
+
}
|
|
388
|
+
const preString = rows.join(`
|
|
389
|
+
`);
|
|
390
|
+
let inSurrogate = false;
|
|
391
|
+
for (let i = 0;i < preString.length; i++) {
|
|
392
|
+
const character = preString[i];
|
|
393
|
+
returnValue += character;
|
|
394
|
+
if (!inSurrogate) {
|
|
395
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
396
|
+
if (inSurrogate) {
|
|
397
|
+
continue;
|
|
420
398
|
}
|
|
399
|
+
} else {
|
|
400
|
+
inSurrogate = false;
|
|
421
401
|
}
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
cleanupErrors.push(error);
|
|
402
|
+
if (character === ESC || character === CSI) {
|
|
403
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
404
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
405
|
+
const groups = groupsResult?.groups;
|
|
406
|
+
if (groups?.code !== undefined) {
|
|
407
|
+
const code = Number.parseFloat(groups.code);
|
|
408
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
409
|
+
} else if (groups?.uri !== undefined) {
|
|
410
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
411
|
+
}
|
|
433
412
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
413
|
+
if (preString[i + 1] === `
|
|
414
|
+
`) {
|
|
415
|
+
if (escapeUrl) {
|
|
416
|
+
returnValue += wrapAnsiHyperlink("");
|
|
417
|
+
}
|
|
418
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
419
|
+
if (escapeCode && closingCode) {
|
|
420
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
421
|
+
}
|
|
422
|
+
} else if (character === `
|
|
423
|
+
`) {
|
|
424
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
425
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
426
|
+
}
|
|
427
|
+
if (escapeUrl) {
|
|
428
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
429
|
+
}
|
|
439
430
|
}
|
|
440
|
-
if (runError)
|
|
441
|
-
throw runError;
|
|
442
|
-
if (cleanupErrors.length === 1)
|
|
443
|
-
throw cleanupErrors[0];
|
|
444
|
-
if (cleanupErrors.length > 1)
|
|
445
|
-
throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
|
|
446
|
-
return { result };
|
|
447
|
-
}
|
|
448
|
-
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
449
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
450
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
451
|
-
const subCommandArgIndex = findSubCommandIndex(rawArgs, await resolveValue(cmd.args || {}));
|
|
452
|
-
const subCommandName = rawArgs[subCommandArgIndex];
|
|
453
|
-
const subCommand = await _findSubCommand(subCommands, subCommandName);
|
|
454
|
-
if (subCommand)
|
|
455
|
-
return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
456
431
|
}
|
|
457
|
-
return
|
|
432
|
+
return returnValue;
|
|
433
|
+
};
|
|
434
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
435
|
+
function wrapAnsi(string, columns, options) {
|
|
436
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
437
|
+
`);
|
|
458
438
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
439
|
+
|
|
440
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
441
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
442
|
+
import { ReadStream } from "tty";
|
|
443
|
+
function findCursor(s, o, l2) {
|
|
444
|
+
if (!l2.some((r) => !r.disabled))
|
|
445
|
+
return s;
|
|
446
|
+
const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
447
|
+
return l2[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
|
|
448
|
+
}
|
|
449
|
+
function findTextCursor(s, o, l2, i) {
|
|
450
|
+
const t = i.split(`
|
|
451
|
+
`);
|
|
452
|
+
let n = 0, e = s;
|
|
453
|
+
for (const r of t) {
|
|
454
|
+
if (e <= r.length)
|
|
455
|
+
break;
|
|
456
|
+
e -= r.length + 1, n++;
|
|
469
457
|
}
|
|
458
|
+
for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
|
|
459
|
+
n--, e += t[n].length + 1;
|
|
460
|
+
for (;e > t[n].length && n < t.length - 1; )
|
|
461
|
+
e -= t[n].length + 1, n++;
|
|
462
|
+
e = Math.max(0, Math.min(t[n].length, e));
|
|
463
|
+
let h = 0;
|
|
464
|
+
for (let r = 0;r < n; r++)
|
|
465
|
+
h += t[r].length + 1;
|
|
466
|
+
return h + e;
|
|
470
467
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
468
|
+
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
469
|
+
var t = [
|
|
470
|
+
"January",
|
|
471
|
+
"February",
|
|
472
|
+
"March",
|
|
473
|
+
"April",
|
|
474
|
+
"May",
|
|
475
|
+
"June",
|
|
476
|
+
"July",
|
|
477
|
+
"August",
|
|
478
|
+
"September",
|
|
479
|
+
"October",
|
|
480
|
+
"November",
|
|
481
|
+
"December"
|
|
482
|
+
];
|
|
483
|
+
var settings = {
|
|
484
|
+
actions: new Set(a$2),
|
|
485
|
+
aliases: /* @__PURE__ */ new Map([
|
|
486
|
+
["k", "up"],
|
|
487
|
+
["j", "down"],
|
|
488
|
+
["h", "left"],
|
|
489
|
+
["l", "right"],
|
|
490
|
+
["\x03", "cancel"],
|
|
491
|
+
["escape", "cancel"]
|
|
492
|
+
]),
|
|
493
|
+
messages: {
|
|
494
|
+
cancel: "Canceled",
|
|
495
|
+
error: "Something went wrong"
|
|
496
|
+
},
|
|
497
|
+
withGuide: true,
|
|
498
|
+
date: {
|
|
499
|
+
monthNames: [...t],
|
|
500
|
+
messages: {
|
|
501
|
+
required: "Please enter a valid date",
|
|
502
|
+
invalidMonth: "There are only 12 months in a year",
|
|
503
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
504
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
505
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
480
506
|
}
|
|
481
|
-
return i;
|
|
482
507
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
if (def.type !== "string" && def.type !== "enum")
|
|
490
|
-
continue;
|
|
491
|
-
if (normalized === camelCase(key))
|
|
492
|
-
return true;
|
|
493
|
-
if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name))
|
|
508
|
+
};
|
|
509
|
+
function isActionKey(n, e) {
|
|
510
|
+
if (typeof n == "string")
|
|
511
|
+
return settings.aliases.get(n) === e;
|
|
512
|
+
for (const s of n)
|
|
513
|
+
if (s !== undefined && isActionKey(s, e))
|
|
494
514
|
return true;
|
|
495
|
-
}
|
|
496
515
|
return false;
|
|
497
516
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
`
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const argLines = [];
|
|
513
|
-
const posLines = [];
|
|
514
|
-
const commandsLines = [];
|
|
515
|
-
const usageLine = [];
|
|
516
|
-
for (const arg of cmdArgs)
|
|
517
|
-
if (arg.type === "positional") {
|
|
518
|
-
const name = arg.name.toUpperCase();
|
|
519
|
-
const isRequired = arg.required !== false && arg.default === undefined;
|
|
520
|
-
posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
|
|
521
|
-
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
522
|
-
} else {
|
|
523
|
-
const isRequired = arg.required === true && arg.default === undefined;
|
|
524
|
-
const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
|
|
525
|
-
argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
|
|
526
|
-
if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
|
|
527
|
-
const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
|
|
528
|
-
argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
|
|
529
|
-
}
|
|
530
|
-
if (isRequired)
|
|
531
|
-
usageLine.push(`--${arg.name}` + renderValueHint(arg));
|
|
532
|
-
}
|
|
533
|
-
if (cmd.subCommands) {
|
|
534
|
-
const commandNames = [];
|
|
535
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
536
|
-
for (const [name, sub] of Object.entries(subCommands)) {
|
|
537
|
-
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
538
|
-
if (meta?.hidden)
|
|
539
|
-
continue;
|
|
540
|
-
const aliases = toArray(meta?.alias);
|
|
541
|
-
const label = [name, ...aliases].join(", ");
|
|
542
|
-
commandsLines.push([cyan(label), meta?.description || ""]);
|
|
543
|
-
commandNames.push(name, ...aliases);
|
|
544
|
-
}
|
|
545
|
-
usageLine.push(commandNames.join("|"));
|
|
546
|
-
}
|
|
547
|
-
const usageLines = [];
|
|
548
|
-
const version = cmdMeta.version || parentMeta.version;
|
|
549
|
-
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
550
|
-
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
551
|
-
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
552
|
-
if (posLines.length > 0) {
|
|
553
|
-
usageLines.push(underline(bold("ARGUMENTS")), "");
|
|
554
|
-
usageLines.push(formatLineColumns(posLines, " "));
|
|
555
|
-
usageLines.push("");
|
|
556
|
-
}
|
|
557
|
-
if (argLines.length > 0) {
|
|
558
|
-
usageLines.push(underline(bold("OPTIONS")), "");
|
|
559
|
-
usageLines.push(formatLineColumns(argLines, " "));
|
|
560
|
-
usageLines.push("");
|
|
561
|
-
}
|
|
562
|
-
if (commandsLines.length > 0) {
|
|
563
|
-
usageLines.push(underline(bold("COMMANDS")), "");
|
|
564
|
-
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
565
|
-
usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
|
|
566
|
-
}
|
|
567
|
-
return usageLines.filter((l) => typeof l === "string").join(`
|
|
568
|
-
`);
|
|
517
|
+
function diffLines(i, s) {
|
|
518
|
+
if (i === s)
|
|
519
|
+
return;
|
|
520
|
+
const e = i.split(`
|
|
521
|
+
`), t2 = s.split(`
|
|
522
|
+
`), r = Math.max(e.length, t2.length), f = [];
|
|
523
|
+
for (let n = 0;n < r; n++)
|
|
524
|
+
e[n] !== t2[n] && f.push(n);
|
|
525
|
+
return {
|
|
526
|
+
lines: f,
|
|
527
|
+
numLinesBefore: e.length,
|
|
528
|
+
numLinesAfter: t2.length,
|
|
529
|
+
numLines: r
|
|
530
|
+
};
|
|
569
531
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return valueHint;
|
|
575
|
-
if (arg.type === "enum" && arg.options?.length)
|
|
576
|
-
return `=<${arg.options.join("|")}>`;
|
|
577
|
-
return fallbackValueHint;
|
|
532
|
+
var R = globalThis.process.platform.startsWith("win");
|
|
533
|
+
var CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
534
|
+
function isCancel(e) {
|
|
535
|
+
return e === CANCEL_SYMBOL;
|
|
578
536
|
}
|
|
579
|
-
function
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
return [
|
|
583
|
-
arg.description,
|
|
584
|
-
requiredHint,
|
|
585
|
-
defaultHint
|
|
586
|
-
].filter(Boolean).join(" ");
|
|
537
|
+
function setRawMode(e, r) {
|
|
538
|
+
const o = e;
|
|
539
|
+
o.isTTY && o.setRawMode(r);
|
|
587
540
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
541
|
+
function block({
|
|
542
|
+
input: e = stdin,
|
|
543
|
+
output: r = stdout,
|
|
544
|
+
overwrite: o = true,
|
|
545
|
+
hideCursor: t2 = true
|
|
546
|
+
} = {}) {
|
|
547
|
+
const s = l.createInterface({
|
|
548
|
+
input: e,
|
|
549
|
+
output: r,
|
|
550
|
+
prompt: "",
|
|
551
|
+
tabSize: 1
|
|
552
|
+
});
|
|
553
|
+
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
554
|
+
const n = (f, { name: a, sequence: p }) => {
|
|
555
|
+
const c = String(f);
|
|
556
|
+
if (isActionKey([c, a, p], "cancel")) {
|
|
557
|
+
t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (!o)
|
|
561
|
+
return;
|
|
562
|
+
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
563
|
+
l.moveCursor(r, i, m, () => {
|
|
564
|
+
l.clearLine(r, 1, () => {
|
|
565
|
+
e.once("keypress", n);
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
|
|
570
|
+
e.off("keypress", n), t2 && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
|
|
574
|
+
var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
|
|
575
|
+
function wrapTextWithPrefix(e, r, o, t2 = o, s = o, n) {
|
|
576
|
+
const f = getColumns(e ?? stdout);
|
|
577
|
+
return wrapAnsi(r, f - o.length, {
|
|
578
|
+
hard: true,
|
|
579
|
+
trim: false
|
|
580
|
+
}).split(`
|
|
581
|
+
`).map((c, i, m) => {
|
|
582
|
+
const d = n ? n(c, i) : c;
|
|
583
|
+
return i === 0 ? `${t2}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
584
|
+
}).join(`
|
|
609
585
|
`);
|
|
610
|
-
process.exit(1);
|
|
611
|
-
}
|
|
612
586
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
for (const alias of toArray(def.alias))
|
|
620
|
-
userAliases.add(alias);
|
|
587
|
+
function runValidation(e, n) {
|
|
588
|
+
if ("~standard" in e) {
|
|
589
|
+
const a = e["~standard"].validate(n);
|
|
590
|
+
if (a instanceof Promise)
|
|
591
|
+
throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
592
|
+
return a.issues?.at(0)?.message;
|
|
621
593
|
}
|
|
622
|
-
return
|
|
623
|
-
help: _getBuiltinFlags("help", "h", userNames, userAliases),
|
|
624
|
-
version: _getBuiltinFlags("version", "v", userNames, userAliases)
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function _getBuiltinFlags(long, short, userNames, userAliases) {
|
|
628
|
-
if (userNames.has(long) || userAliases.has(long))
|
|
629
|
-
return [];
|
|
630
|
-
if (userNames.has(short) || userAliases.has(short))
|
|
631
|
-
return [`--${long}`];
|
|
632
|
-
return [`--${long}`, `-${short}`];
|
|
594
|
+
return e(n);
|
|
633
595
|
}
|
|
634
596
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
[ANSI_RE, ANSI_WIDTH],
|
|
683
|
-
[CONTROL_RE, CONTROL_WIDTH],
|
|
684
|
-
[TAB_RE, TAB_WIDTH],
|
|
685
|
-
[EMOJI_RE, EMOJI_WIDTH],
|
|
686
|
-
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
687
|
-
];
|
|
688
|
-
let indexPrev = 0;
|
|
689
|
-
let index = 0;
|
|
690
|
-
let length = input.length;
|
|
691
|
-
let lengthExtra = 0;
|
|
692
|
-
let truncationEnabled = false;
|
|
693
|
-
let truncationIndex = length;
|
|
694
|
-
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
695
|
-
let unmatchedStart = 0;
|
|
696
|
-
let unmatchedEnd = 0;
|
|
697
|
-
let width = 0;
|
|
698
|
-
let widthExtra = 0;
|
|
699
|
-
outer:
|
|
700
|
-
while (true) {
|
|
701
|
-
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
702
|
-
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
703
|
-
lengthExtra = 0;
|
|
704
|
-
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
705
|
-
const codePoint = char.codePointAt(0) || 0;
|
|
706
|
-
if (isFullWidth(codePoint)) {
|
|
707
|
-
widthExtra = FULL_WIDTH_WIDTH;
|
|
708
|
-
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
709
|
-
widthExtra = WIDE_WIDTH;
|
|
710
|
-
} else {
|
|
711
|
-
widthExtra = REGULAR_WIDTH;
|
|
712
|
-
}
|
|
713
|
-
if (width + widthExtra > truncationLimit) {
|
|
714
|
-
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
715
|
-
}
|
|
716
|
-
if (width + widthExtra > LIMIT) {
|
|
717
|
-
truncationEnabled = true;
|
|
718
|
-
break outer;
|
|
719
|
-
}
|
|
720
|
-
lengthExtra += char.length;
|
|
721
|
-
width += widthExtra;
|
|
722
|
-
}
|
|
723
|
-
unmatchedStart = unmatchedEnd = 0;
|
|
597
|
+
class V {
|
|
598
|
+
input;
|
|
599
|
+
output;
|
|
600
|
+
_abortSignal;
|
|
601
|
+
rl;
|
|
602
|
+
opts;
|
|
603
|
+
_render;
|
|
604
|
+
_track = false;
|
|
605
|
+
_prevFrame = "";
|
|
606
|
+
_subscribers = /* @__PURE__ */ new Map;
|
|
607
|
+
_cursor = 0;
|
|
608
|
+
state = "initial";
|
|
609
|
+
error = "";
|
|
610
|
+
value;
|
|
611
|
+
userInput = "";
|
|
612
|
+
constructor(t2, e = true) {
|
|
613
|
+
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
|
|
614
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
615
|
+
}
|
|
616
|
+
unsubscribe() {
|
|
617
|
+
this._subscribers.clear();
|
|
618
|
+
}
|
|
619
|
+
setSubscriber(t2, e) {
|
|
620
|
+
const i = this._subscribers.get(t2) ?? [];
|
|
621
|
+
i.push(e), this._subscribers.set(t2, i);
|
|
622
|
+
}
|
|
623
|
+
on(t2, e) {
|
|
624
|
+
this.setSubscriber(t2, { cb: e });
|
|
625
|
+
}
|
|
626
|
+
once(t2, e) {
|
|
627
|
+
this.setSubscriber(t2, { cb: e, once: true });
|
|
628
|
+
}
|
|
629
|
+
emit(t2, ...e) {
|
|
630
|
+
const i = this._subscribers.get(t2) ?? [], n = [];
|
|
631
|
+
for (const s of i)
|
|
632
|
+
s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
|
|
633
|
+
for (const s of n)
|
|
634
|
+
s();
|
|
635
|
+
}
|
|
636
|
+
prompt() {
|
|
637
|
+
return new Promise((t2) => {
|
|
638
|
+
if (this._abortSignal) {
|
|
639
|
+
if (this._abortSignal.aborted)
|
|
640
|
+
return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
|
|
641
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
642
|
+
this.state = "cancel", this.close();
|
|
643
|
+
}, { once: true });
|
|
724
644
|
}
|
|
725
|
-
|
|
726
|
-
|
|
645
|
+
this.rl = l__default.createInterface({
|
|
646
|
+
input: this.input,
|
|
647
|
+
tabSize: 2,
|
|
648
|
+
prompt: "",
|
|
649
|
+
escapeCodeTimeout: 50,
|
|
650
|
+
terminal: true
|
|
651
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
652
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
|
|
653
|
+
}), this.once("cancel", () => {
|
|
654
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
_isActionKey(t2, e) {
|
|
659
|
+
return t2 === "\t";
|
|
660
|
+
}
|
|
661
|
+
_shouldSubmit(t2, e) {
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
_setValue(t2) {
|
|
665
|
+
this.value = t2, this.emit("value", this.value);
|
|
666
|
+
}
|
|
667
|
+
_setUserInput(t2, e) {
|
|
668
|
+
this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
669
|
+
}
|
|
670
|
+
_clearUserInput() {
|
|
671
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
672
|
+
}
|
|
673
|
+
onKeypress(t2, e) {
|
|
674
|
+
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)) {
|
|
675
|
+
if (this.opts.validate) {
|
|
676
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
677
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
727
678
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
679
|
+
this.state !== "error" && (this.state = "submit");
|
|
680
|
+
}
|
|
681
|
+
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();
|
|
682
|
+
}
|
|
683
|
+
close() {
|
|
684
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
685
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
686
|
+
}
|
|
687
|
+
restoreCursor() {
|
|
688
|
+
const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
689
|
+
`).length - 1;
|
|
690
|
+
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
691
|
+
}
|
|
692
|
+
render() {
|
|
693
|
+
const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
694
|
+
hard: true,
|
|
695
|
+
trim: false
|
|
696
|
+
});
|
|
697
|
+
if (t2 !== this._prevFrame) {
|
|
698
|
+
if (this.state === "initial")
|
|
699
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
700
|
+
else {
|
|
701
|
+
const e = diffLines(this._prevFrame, t2), i = getRows(this.output);
|
|
702
|
+
if (this.restoreCursor(), e) {
|
|
703
|
+
const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
|
|
704
|
+
let r = e.lines.find((o) => o >= n);
|
|
705
|
+
if (r === undefined) {
|
|
706
|
+
this._prevFrame = t2;
|
|
707
|
+
return;
|
|
736
708
|
}
|
|
737
|
-
if (
|
|
738
|
-
|
|
739
|
-
|
|
709
|
+
if (e.lines.length === 1) {
|
|
710
|
+
this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
711
|
+
const o = t2.split(`
|
|
712
|
+
`);
|
|
713
|
+
this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
|
|
714
|
+
return;
|
|
715
|
+
} else if (e.lines.length > 1) {
|
|
716
|
+
if (n < s)
|
|
717
|
+
r = n;
|
|
718
|
+
else {
|
|
719
|
+
const h = r - s;
|
|
720
|
+
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
721
|
+
}
|
|
722
|
+
this.output.write(import_sisteransi.erase.down());
|
|
723
|
+
const f = t2.split(`
|
|
724
|
+
`).slice(r);
|
|
725
|
+
this.output.write(f.join(`
|
|
726
|
+
`)), this._prevFrame = t2;
|
|
727
|
+
return;
|
|
740
728
|
}
|
|
741
|
-
width += widthExtra;
|
|
742
|
-
unmatchedStart = indexPrev;
|
|
743
|
-
unmatchedEnd = index;
|
|
744
|
-
index = indexPrev = BLOCK_RE.lastIndex;
|
|
745
|
-
continue outer;
|
|
746
729
|
}
|
|
730
|
+
this.output.write(import_sisteransi.erase.down());
|
|
747
731
|
}
|
|
748
|
-
|
|
732
|
+
this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
|
|
749
733
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function p$1(l2, e) {
|
|
737
|
+
if (l2 === undefined || e.length === 0)
|
|
738
|
+
return 0;
|
|
739
|
+
const i = e.findIndex((s) => s.value === l2);
|
|
740
|
+
return i !== -1 ? i : 0;
|
|
741
|
+
}
|
|
742
|
+
function g(l2, e) {
|
|
743
|
+
return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
|
|
744
|
+
}
|
|
745
|
+
function m(l2, e) {
|
|
746
|
+
if (e)
|
|
747
|
+
return l2 ? e : e[0];
|
|
748
|
+
}
|
|
749
|
+
var T$1 = class T extends V {
|
|
750
|
+
filteredOptions;
|
|
751
|
+
multiple;
|
|
752
|
+
isNavigating = false;
|
|
753
|
+
selectedValues = [];
|
|
754
|
+
focusedValue;
|
|
755
|
+
#e = 0;
|
|
756
|
+
#s = "";
|
|
757
|
+
#t;
|
|
758
|
+
#i;
|
|
759
|
+
#n;
|
|
760
|
+
get cursor() {
|
|
761
|
+
return this.#e;
|
|
762
|
+
}
|
|
763
|
+
get userInputWithCursor() {
|
|
764
|
+
if (!this.userInput)
|
|
765
|
+
return styleText(["inverse", "hidden"], "_");
|
|
766
|
+
if (this._cursor >= this.userInput.length)
|
|
767
|
+
return `${this.userInput}\u2588`;
|
|
768
|
+
const e = this.userInput.slice(0, this._cursor), [t2, ...i] = this.userInput.slice(this._cursor);
|
|
769
|
+
return `${e}${styleText("inverse", t2)}${i.join("")}`;
|
|
770
|
+
}
|
|
771
|
+
get options() {
|
|
772
|
+
return typeof this.#i == "function" ? this.#i() : this.#i;
|
|
773
|
+
}
|
|
774
|
+
constructor(e) {
|
|
775
|
+
super(e), this.#i = e.options, this.#n = e.placeholder;
|
|
776
|
+
const t2 = this.options;
|
|
777
|
+
this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
|
|
778
|
+
let i;
|
|
779
|
+
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
|
|
780
|
+
for (const s of i) {
|
|
781
|
+
const n = t2.findIndex((o) => o.value === s);
|
|
782
|
+
n !== -1 && (this.toggleSelected(s), this.#e = n);
|
|
783
|
+
}
|
|
784
|
+
this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
|
|
785
|
+
}
|
|
786
|
+
_isActionKey(e, t2) {
|
|
787
|
+
return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
|
|
788
|
+
}
|
|
789
|
+
#l(e, t2) {
|
|
790
|
+
const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#n, h = this.options, f = u !== undefined && u !== "" && h.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
|
|
791
|
+
if (t2.name === "tab" && o && f) {
|
|
792
|
+
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
796
|
+
}
|
|
797
|
+
deselectAll() {
|
|
798
|
+
this.selectedValues = [];
|
|
799
|
+
}
|
|
800
|
+
toggleSelected(e) {
|
|
801
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
802
|
+
}
|
|
803
|
+
#u(e) {
|
|
804
|
+
if (e !== this.#s) {
|
|
805
|
+
this.#s = e;
|
|
806
|
+
const t2 = this.options;
|
|
807
|
+
e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
|
|
808
|
+
const i = p$1(this.focusedValue, this.filteredOptions);
|
|
809
|
+
this.#e = findCursor(i, 0, this.filteredOptions);
|
|
810
|
+
const s = this.filteredOptions[this.#e];
|
|
811
|
+
s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
812
|
+
}
|
|
813
|
+
}
|
|
756
814
|
};
|
|
757
|
-
var dist_default = getStringTruncatedWidth;
|
|
758
815
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
ellipsis: "",
|
|
763
|
-
ellipsisWidth: 0
|
|
764
|
-
};
|
|
765
|
-
var fastStringWidth = (input, options = {}) => {
|
|
766
|
-
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
767
|
-
};
|
|
768
|
-
var dist_default2 = fastStringWidth;
|
|
769
|
-
|
|
770
|
-
// node_modules/fast-wrap-ansi/lib/main.js
|
|
771
|
-
var ESC = "\x1B";
|
|
772
|
-
var CSI = "\x9B";
|
|
773
|
-
var END_CODE = 39;
|
|
774
|
-
var ANSI_ESCAPE_BELL = "\x07";
|
|
775
|
-
var ANSI_CSI = "[";
|
|
776
|
-
var ANSI_OSC = "]";
|
|
777
|
-
var ANSI_SGR_TERMINATOR = "m";
|
|
778
|
-
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
779
|
-
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
780
|
-
var getClosingCode = (openingCode) => {
|
|
781
|
-
if (openingCode >= 30 && openingCode <= 37)
|
|
782
|
-
return 39;
|
|
783
|
-
if (openingCode >= 90 && openingCode <= 97)
|
|
784
|
-
return 39;
|
|
785
|
-
if (openingCode >= 40 && openingCode <= 47)
|
|
786
|
-
return 49;
|
|
787
|
-
if (openingCode >= 100 && openingCode <= 107)
|
|
788
|
-
return 49;
|
|
789
|
-
if (openingCode === 1 || openingCode === 2)
|
|
790
|
-
return 22;
|
|
791
|
-
if (openingCode === 3)
|
|
792
|
-
return 23;
|
|
793
|
-
if (openingCode === 4)
|
|
794
|
-
return 24;
|
|
795
|
-
if (openingCode === 7)
|
|
796
|
-
return 27;
|
|
797
|
-
if (openingCode === 8)
|
|
798
|
-
return 28;
|
|
799
|
-
if (openingCode === 9)
|
|
800
|
-
return 29;
|
|
801
|
-
if (openingCode === 0)
|
|
802
|
-
return 0;
|
|
803
|
-
return;
|
|
804
|
-
};
|
|
805
|
-
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
806
|
-
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
807
|
-
var wrapWord = (rows, word, columns) => {
|
|
808
|
-
const characters = word[Symbol.iterator]();
|
|
809
|
-
let isInsideEscape = false;
|
|
810
|
-
let isInsideLinkEscape = false;
|
|
811
|
-
let lastRow = rows.at(-1);
|
|
812
|
-
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
813
|
-
let currentCharacter = characters.next();
|
|
814
|
-
let nextCharacter = characters.next();
|
|
815
|
-
let rawCharacterIndex = 0;
|
|
816
|
-
while (!currentCharacter.done) {
|
|
817
|
-
const character = currentCharacter.value;
|
|
818
|
-
const characterLength = dist_default2(character);
|
|
819
|
-
if (visible + characterLength <= columns) {
|
|
820
|
-
rows[rows.length - 1] += character;
|
|
821
|
-
} else {
|
|
822
|
-
rows.push(character);
|
|
823
|
-
visible = 0;
|
|
824
|
-
}
|
|
825
|
-
if (character === ESC || character === CSI) {
|
|
826
|
-
isInsideEscape = true;
|
|
827
|
-
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
828
|
-
}
|
|
829
|
-
if (isInsideEscape) {
|
|
830
|
-
if (isInsideLinkEscape) {
|
|
831
|
-
if (character === ANSI_ESCAPE_BELL) {
|
|
832
|
-
isInsideEscape = false;
|
|
833
|
-
isInsideLinkEscape = false;
|
|
834
|
-
}
|
|
835
|
-
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
836
|
-
isInsideEscape = false;
|
|
837
|
-
}
|
|
838
|
-
} else {
|
|
839
|
-
visible += characterLength;
|
|
840
|
-
if (visible === columns && !nextCharacter.done) {
|
|
841
|
-
rows.push("");
|
|
842
|
-
visible = 0;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
currentCharacter = nextCharacter;
|
|
846
|
-
nextCharacter = characters.next();
|
|
847
|
-
rawCharacterIndex += character.length;
|
|
848
|
-
}
|
|
849
|
-
lastRow = rows.at(-1);
|
|
850
|
-
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
851
|
-
rows[rows.length - 2] += rows.pop();
|
|
816
|
+
class r extends V {
|
|
817
|
+
get cursor() {
|
|
818
|
+
return this.value ? 0 : 1;
|
|
852
819
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const words = string.split(" ");
|
|
856
|
-
let last = words.length;
|
|
857
|
-
while (last) {
|
|
858
|
-
if (dist_default2(words[last - 1])) {
|
|
859
|
-
break;
|
|
860
|
-
}
|
|
861
|
-
last--;
|
|
820
|
+
get _value() {
|
|
821
|
+
return this.cursor === 0;
|
|
862
822
|
}
|
|
863
|
-
|
|
864
|
-
|
|
823
|
+
constructor(t2) {
|
|
824
|
+
super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
|
|
825
|
+
this.value = this._value;
|
|
826
|
+
}), this.on("confirm", (i) => {
|
|
827
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
828
|
+
}), this.on("cursor", () => {
|
|
829
|
+
this.value = !this.value;
|
|
830
|
+
});
|
|
865
831
|
}
|
|
866
|
-
|
|
832
|
+
}
|
|
833
|
+
var _ = {
|
|
834
|
+
Y: { type: "year", len: 4 },
|
|
835
|
+
M: { type: "month", len: 2 },
|
|
836
|
+
D: { type: "day", len: 2 }
|
|
867
837
|
};
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
838
|
+
function M(r2) {
|
|
839
|
+
return [...r2].map((t2) => _[t2]);
|
|
840
|
+
}
|
|
841
|
+
function P(r2) {
|
|
842
|
+
const i = new Intl.DateTimeFormat(r2, {
|
|
843
|
+
year: "numeric",
|
|
844
|
+
month: "2-digit",
|
|
845
|
+
day: "2-digit"
|
|
846
|
+
}).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
847
|
+
let n = "/";
|
|
848
|
+
for (const e of i)
|
|
849
|
+
e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
|
|
850
|
+
return { segments: s, separator: n };
|
|
851
|
+
}
|
|
852
|
+
function p(r2) {
|
|
853
|
+
return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
|
|
854
|
+
}
|
|
855
|
+
function f(r2) {
|
|
856
|
+
return {
|
|
857
|
+
year: p(r2.year),
|
|
858
|
+
month: p(r2.month),
|
|
859
|
+
day: p(r2.day)
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function c(r2, t2) {
|
|
863
|
+
return new Date(r2 || 2001, t2 || 1, 0).getDate();
|
|
864
|
+
}
|
|
865
|
+
function b(r2) {
|
|
866
|
+
const { year: t2, month: i, day: s } = f(r2);
|
|
867
|
+
if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
|
|
868
|
+
return;
|
|
869
|
+
const n = new Date(Date.UTC(t2, i - 1, s));
|
|
870
|
+
if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
|
|
871
|
+
return { year: t2, month: i, day: s };
|
|
872
|
+
}
|
|
873
|
+
function C(r2) {
|
|
874
|
+
const t2 = b(r2);
|
|
875
|
+
return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
|
|
876
|
+
}
|
|
877
|
+
function T2(r2, t2, i, s) {
|
|
878
|
+
const n = i ? {
|
|
879
|
+
year: i.getUTCFullYear(),
|
|
880
|
+
month: i.getUTCMonth() + 1,
|
|
881
|
+
day: i.getUTCDate()
|
|
882
|
+
} : null, e = s ? {
|
|
883
|
+
year: s.getUTCFullYear(),
|
|
884
|
+
month: s.getUTCMonth() + 1,
|
|
885
|
+
day: s.getUTCDate()
|
|
886
|
+
} : null;
|
|
887
|
+
return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
|
|
888
|
+
min: n && t2.year === n.year ? n.month : 1,
|
|
889
|
+
max: e && t2.year === e.year ? e.month : 12
|
|
890
|
+
} : {
|
|
891
|
+
min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
|
|
892
|
+
max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
class U extends V {
|
|
897
|
+
#i;
|
|
898
|
+
#o;
|
|
899
|
+
#t;
|
|
900
|
+
#h;
|
|
901
|
+
#u;
|
|
902
|
+
#e = { segmentIndex: 0, positionInSegment: 0 };
|
|
903
|
+
#n = true;
|
|
904
|
+
#s = null;
|
|
905
|
+
inlineError = "";
|
|
906
|
+
get segmentCursor() {
|
|
907
|
+
return { ...this.#e };
|
|
871
908
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
let escapeUrl;
|
|
875
|
-
const words = string.split(" ");
|
|
876
|
-
let rows = [""];
|
|
877
|
-
let rowLength = 0;
|
|
878
|
-
for (let index = 0;index < words.length; index++) {
|
|
879
|
-
const word = words[index];
|
|
880
|
-
if (options.trim !== false) {
|
|
881
|
-
const row = rows.at(-1) ?? "";
|
|
882
|
-
const trimmed = row.trimStart();
|
|
883
|
-
if (row.length !== trimmed.length) {
|
|
884
|
-
rows[rows.length - 1] = trimmed;
|
|
885
|
-
rowLength = dist_default2(trimmed);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
if (index !== 0) {
|
|
889
|
-
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
890
|
-
rows.push("");
|
|
891
|
-
rowLength = 0;
|
|
892
|
-
}
|
|
893
|
-
if (rowLength || options.trim === false) {
|
|
894
|
-
rows[rows.length - 1] += " ";
|
|
895
|
-
rowLength++;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
const wordLength = dist_default2(word);
|
|
899
|
-
if (options.hard && wordLength > columns) {
|
|
900
|
-
const remainingColumns = columns - rowLength;
|
|
901
|
-
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
902
|
-
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
903
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
904
|
-
rows.push("");
|
|
905
|
-
}
|
|
906
|
-
wrapWord(rows, word, columns);
|
|
907
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
908
|
-
continue;
|
|
909
|
-
}
|
|
910
|
-
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
911
|
-
if (options.wordWrap === false && rowLength < columns) {
|
|
912
|
-
wrapWord(rows, word, columns);
|
|
913
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
914
|
-
continue;
|
|
915
|
-
}
|
|
916
|
-
rows.push("");
|
|
917
|
-
rowLength = 0;
|
|
918
|
-
}
|
|
919
|
-
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
920
|
-
wrapWord(rows, word, columns);
|
|
921
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
922
|
-
continue;
|
|
923
|
-
}
|
|
924
|
-
rows[rows.length - 1] += word;
|
|
925
|
-
rowLength += wordLength;
|
|
909
|
+
get segmentValues() {
|
|
910
|
+
return { ...this.#t };
|
|
926
911
|
}
|
|
927
|
-
|
|
928
|
-
|
|
912
|
+
get segments() {
|
|
913
|
+
return this.#i;
|
|
929
914
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
915
|
+
get separator() {
|
|
916
|
+
return this.#o;
|
|
917
|
+
}
|
|
918
|
+
get formattedValue() {
|
|
919
|
+
return this.#l(this.#t);
|
|
920
|
+
}
|
|
921
|
+
#l(t2) {
|
|
922
|
+
return this.#i.map((i) => t2[i.type]).join(this.#o);
|
|
923
|
+
}
|
|
924
|
+
#r() {
|
|
925
|
+
this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
|
|
926
|
+
}
|
|
927
|
+
constructor(t2) {
|
|
928
|
+
const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
|
|
929
|
+
year: String(e.getUTCFullYear()).padStart(4, "0"),
|
|
930
|
+
month: String(e.getUTCMonth() + 1).padStart(2, "0"),
|
|
931
|
+
day: String(e.getUTCDate()).padStart(2, "0")
|
|
932
|
+
} : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
|
|
933
|
+
super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
|
|
934
|
+
}
|
|
935
|
+
#a() {
|
|
936
|
+
const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
|
|
937
|
+
if (i)
|
|
938
|
+
return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
|
|
939
|
+
}
|
|
940
|
+
#m(t2) {
|
|
941
|
+
this.inlineError = "", this.#s = null;
|
|
942
|
+
const i = this.#a();
|
|
943
|
+
i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
|
|
944
|
+
}
|
|
945
|
+
#d(t2) {
|
|
946
|
+
const i = this.#a();
|
|
947
|
+
if (!i)
|
|
948
|
+
return;
|
|
949
|
+
const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m2 = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T2(s.type, f(this.#t), this.#h, this.#u);
|
|
950
|
+
let a;
|
|
951
|
+
e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
|
|
952
|
+
...this.#t,
|
|
953
|
+
[s.type]: a.toString().padStart(s.len, "0")
|
|
954
|
+
}, this.#n = true, this.#s = null, this.#r();
|
|
955
|
+
}
|
|
956
|
+
#f(t2) {
|
|
957
|
+
if (t2)
|
|
958
|
+
switch (t2) {
|
|
959
|
+
case "right":
|
|
960
|
+
return this.#m(1);
|
|
961
|
+
case "left":
|
|
962
|
+
return this.#m(-1);
|
|
963
|
+
case "up":
|
|
964
|
+
return this.#d(1);
|
|
965
|
+
case "down":
|
|
966
|
+
return this.#d(-1);
|
|
940
967
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
if (
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
} else if (groups?.uri !== undefined) {
|
|
952
|
-
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
968
|
+
}
|
|
969
|
+
#y(t2, i) {
|
|
970
|
+
if (i?.name === "backspace" || i?.sequence === "\x7F" || i?.sequence === "\b" || t2 === "\x7F" || t2 === "\b") {
|
|
971
|
+
this.inlineError = "";
|
|
972
|
+
const n = this.#a();
|
|
973
|
+
if (!n)
|
|
974
|
+
return;
|
|
975
|
+
if (!this.#t[n.segment.type].replace(/_/g, "")) {
|
|
976
|
+
this.#m(-1);
|
|
977
|
+
return;
|
|
953
978
|
}
|
|
979
|
+
this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
|
|
980
|
+
return;
|
|
954
981
|
}
|
|
955
|
-
if (
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
982
|
+
if (i?.name === "tab") {
|
|
983
|
+
this.inlineError = "";
|
|
984
|
+
const n = this.#a();
|
|
985
|
+
if (!n)
|
|
986
|
+
return;
|
|
987
|
+
const e = i.shift ? -1 : 1, m2 = n.index + e;
|
|
988
|
+
m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (t2 && /^[0-9]$/.test(t2)) {
|
|
992
|
+
const n = this.#a();
|
|
993
|
+
if (!n)
|
|
994
|
+
return;
|
|
995
|
+
const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
|
|
996
|
+
if (this.#n && this.#s !== null && !m2) {
|
|
997
|
+
const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
|
|
998
|
+
if (g2) {
|
|
999
|
+
this.inlineError = g2, this.#s = null, this.#n = false;
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
|
|
1003
|
+
return;
|
|
959
1004
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1005
|
+
this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
|
|
1006
|
+
const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
|
|
1007
|
+
if (u < 0 || u >= e.len)
|
|
1008
|
+
return;
|
|
1009
|
+
let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
|
|
1010
|
+
if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
|
|
1011
|
+
const h = Number.parseInt(t2, 10);
|
|
1012
|
+
l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
|
|
963
1013
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1014
|
+
if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
|
|
1015
|
+
const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
|
|
1016
|
+
if (d) {
|
|
1017
|
+
this.inlineError = d;
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
968
1020
|
}
|
|
969
|
-
|
|
970
|
-
|
|
1021
|
+
this.inlineError = "", this.#t[e.type] = l2;
|
|
1022
|
+
const y = l2.includes("_") ? undefined : b(this.#t);
|
|
1023
|
+
if (y) {
|
|
1024
|
+
const { year: h, month: d } = y, g2 = c(h, d);
|
|
1025
|
+
this.#t = {
|
|
1026
|
+
year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
|
|
1027
|
+
month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
|
|
1028
|
+
day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
|
|
1029
|
+
};
|
|
971
1030
|
}
|
|
1031
|
+
this.#r();
|
|
1032
|
+
const S = l2.indexOf("_");
|
|
1033
|
+
D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
|
|
972
1034
|
}
|
|
973
1035
|
}
|
|
974
|
-
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
// node_modules/@clack/core/dist/index.mjs
|
|
983
|
-
var import_sisteransi = __toESM(require_src(), 1);
|
|
984
|
-
import { ReadStream } from "tty";
|
|
985
|
-
function findCursor(s, o, l2) {
|
|
986
|
-
if (!l2.some((r) => !r.disabled))
|
|
987
|
-
return s;
|
|
988
|
-
const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
989
|
-
return l2[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
|
|
990
|
-
}
|
|
991
|
-
function findTextCursor(s, o, l2, i) {
|
|
992
|
-
const t = i.split(`
|
|
993
|
-
`);
|
|
994
|
-
let n = 0, e = s;
|
|
995
|
-
for (const r of t) {
|
|
996
|
-
if (e <= r.length)
|
|
997
|
-
break;
|
|
998
|
-
e -= r.length + 1, n++;
|
|
1036
|
+
#g(t2, i) {
|
|
1037
|
+
const { month: s, day: n } = f(t2);
|
|
1038
|
+
if (i.type === "month" && (s < 0 || s > 12))
|
|
1039
|
+
return settings.date.messages.invalidMonth;
|
|
1040
|
+
if (i.type === "day" && (n < 0 || n > 31))
|
|
1041
|
+
return settings.date.messages.invalidDay(31, "any month");
|
|
999
1042
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
return h + e;
|
|
1009
|
-
}
|
|
1010
|
-
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
1011
|
-
var t = [
|
|
1012
|
-
"January",
|
|
1013
|
-
"February",
|
|
1014
|
-
"March",
|
|
1015
|
-
"April",
|
|
1016
|
-
"May",
|
|
1017
|
-
"June",
|
|
1018
|
-
"July",
|
|
1019
|
-
"August",
|
|
1020
|
-
"September",
|
|
1021
|
-
"October",
|
|
1022
|
-
"November",
|
|
1023
|
-
"December"
|
|
1024
|
-
];
|
|
1025
|
-
var settings = {
|
|
1026
|
-
actions: new Set(a$2),
|
|
1027
|
-
aliases: /* @__PURE__ */ new Map([
|
|
1028
|
-
["k", "up"],
|
|
1029
|
-
["j", "down"],
|
|
1030
|
-
["h", "left"],
|
|
1031
|
-
["l", "right"],
|
|
1032
|
-
["\x03", "cancel"],
|
|
1033
|
-
["escape", "cancel"]
|
|
1034
|
-
]),
|
|
1035
|
-
messages: {
|
|
1036
|
-
cancel: "Canceled",
|
|
1037
|
-
error: "Something went wrong"
|
|
1038
|
-
},
|
|
1039
|
-
withGuide: true,
|
|
1040
|
-
date: {
|
|
1041
|
-
monthNames: [...t],
|
|
1042
|
-
messages: {
|
|
1043
|
-
required: "Please enter a valid date",
|
|
1044
|
-
invalidMonth: "There are only 12 months in a year",
|
|
1045
|
-
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
1046
|
-
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
1047
|
-
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
1043
|
+
#p(t2) {
|
|
1044
|
+
const { year: i, month: s, day: n } = f(this.#t);
|
|
1045
|
+
if (i && s && n) {
|
|
1046
|
+
const e = c(i, s);
|
|
1047
|
+
this.#t = {
|
|
1048
|
+
...this.#t,
|
|
1049
|
+
day: String(Math.min(n, e)).padStart(2, "0")
|
|
1050
|
+
};
|
|
1048
1051
|
}
|
|
1052
|
+
this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
|
|
1049
1053
|
}
|
|
1050
|
-
};
|
|
1051
|
-
function isActionKey(n, e) {
|
|
1052
|
-
if (typeof n == "string")
|
|
1053
|
-
return settings.aliases.get(n) === e;
|
|
1054
|
-
for (const s of n)
|
|
1055
|
-
if (s !== undefined && isActionKey(s, e))
|
|
1056
|
-
return true;
|
|
1057
|
-
return false;
|
|
1058
1054
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
function setRawMode(e, r) {
|
|
1080
|
-
const o = e;
|
|
1081
|
-
o.isTTY && o.setRawMode(r);
|
|
1082
|
-
}
|
|
1083
|
-
function block({
|
|
1084
|
-
input: e = stdin,
|
|
1085
|
-
output: r = stdout,
|
|
1086
|
-
overwrite: o = true,
|
|
1087
|
-
hideCursor: t2 = true
|
|
1088
|
-
} = {}) {
|
|
1089
|
-
const s = l.createInterface({
|
|
1090
|
-
input: e,
|
|
1091
|
-
output: r,
|
|
1092
|
-
prompt: "",
|
|
1093
|
-
tabSize: 1
|
|
1094
|
-
});
|
|
1095
|
-
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
1096
|
-
const n = (f, { name: a, sequence: p }) => {
|
|
1097
|
-
const c = String(f);
|
|
1098
|
-
if (isActionKey([c, a, p], "cancel")) {
|
|
1099
|
-
t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
1100
|
-
return;
|
|
1055
|
+
var u$1 = class u extends V {
|
|
1056
|
+
options;
|
|
1057
|
+
cursor = 0;
|
|
1058
|
+
#t;
|
|
1059
|
+
getGroupItems(t2) {
|
|
1060
|
+
return this.options.filter((r2) => r2.group === t2);
|
|
1061
|
+
}
|
|
1062
|
+
isGroupSelected(t2) {
|
|
1063
|
+
const r2 = this.getGroupItems(t2), e = this.value;
|
|
1064
|
+
return e === undefined ? false : r2.every((s) => e.includes(s.value));
|
|
1065
|
+
}
|
|
1066
|
+
toggleValue() {
|
|
1067
|
+
const t2 = this.options[this.cursor];
|
|
1068
|
+
if (this.value === undefined && (this.value = []), t2.group === true) {
|
|
1069
|
+
const r2 = t2.value, e = this.getGroupItems(r2);
|
|
1070
|
+
this.isGroupSelected(r2) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
|
|
1071
|
+
} else {
|
|
1072
|
+
const r2 = this.value.includes(t2.value);
|
|
1073
|
+
this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
|
|
1101
1074
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
})
|
|
1075
|
+
}
|
|
1076
|
+
constructor(t2) {
|
|
1077
|
+
super(t2, false);
|
|
1078
|
+
const { options: r2 } = t2;
|
|
1079
|
+
this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
|
|
1080
|
+
{ value: e, group: true, label: e },
|
|
1081
|
+
...s.map((i) => ({ ...i, group: e }))
|
|
1082
|
+
]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
1083
|
+
switch (e) {
|
|
1084
|
+
case "left":
|
|
1085
|
+
case "up": {
|
|
1086
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1087
|
+
const s = this.options[this.cursor]?.group === true;
|
|
1088
|
+
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
case "down":
|
|
1092
|
+
case "right": {
|
|
1093
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1094
|
+
const s = this.options[this.cursor]?.group === true;
|
|
1095
|
+
!this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
case "space":
|
|
1099
|
+
this.toggleValue();
|
|
1100
|
+
break;
|
|
1101
|
+
}
|
|
1109
1102
|
});
|
|
1110
|
-
};
|
|
1111
|
-
return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
|
|
1112
|
-
e.off("keypress", n), t2 && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
|
|
1116
|
-
var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
|
|
1117
|
-
function wrapTextWithPrefix(e, r, o, t2 = o, s = o, n) {
|
|
1118
|
-
const f = getColumns(e ?? stdout);
|
|
1119
|
-
return wrapAnsi(r, f - o.length, {
|
|
1120
|
-
hard: true,
|
|
1121
|
-
trim: false
|
|
1122
|
-
}).split(`
|
|
1123
|
-
`).map((c, i, m) => {
|
|
1124
|
-
const d = n ? n(c, i) : c;
|
|
1125
|
-
return i === 0 ? `${t2}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
1126
|
-
}).join(`
|
|
1127
|
-
`);
|
|
1128
|
-
}
|
|
1129
|
-
function runValidation(e, n) {
|
|
1130
|
-
if ("~standard" in e) {
|
|
1131
|
-
const a = e["~standard"].validate(n);
|
|
1132
|
-
if (a instanceof Promise)
|
|
1133
|
-
throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
1134
|
-
return a.issues?.at(0)?.message;
|
|
1135
1103
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1104
|
+
};
|
|
1105
|
+
var o$1 = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
|
|
1138
1106
|
|
|
1139
|
-
class V {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
userInput = "";
|
|
1154
|
-
constructor(t2, e = true) {
|
|
1155
|
-
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
|
|
1156
|
-
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
1157
|
-
}
|
|
1158
|
-
unsubscribe() {
|
|
1159
|
-
this._subscribers.clear();
|
|
1107
|
+
class h extends V {
|
|
1108
|
+
#t = false;
|
|
1109
|
+
#s;
|
|
1110
|
+
focused = "editor";
|
|
1111
|
+
get userInputWithCursor() {
|
|
1112
|
+
if (this.state === "submit")
|
|
1113
|
+
return this.userInput;
|
|
1114
|
+
const t2 = this.userInput;
|
|
1115
|
+
if (this.cursor >= t2.length)
|
|
1116
|
+
return `${t2}\u2588`;
|
|
1117
|
+
const s = t2.slice(0, this.cursor), r2 = t2[this.cursor], i = t2.slice(this.cursor + 1);
|
|
1118
|
+
return r2 === `
|
|
1119
|
+
` ? `${s}\u2588
|
|
1120
|
+
${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
1160
1121
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
i.push(e), this._subscribers.set(t2, i);
|
|
1122
|
+
get cursor() {
|
|
1123
|
+
return this._cursor;
|
|
1164
1124
|
}
|
|
1165
|
-
|
|
1166
|
-
this.
|
|
1125
|
+
#r(t2) {
|
|
1126
|
+
if (this.userInput.length === 0) {
|
|
1127
|
+
this._setUserInput(t2);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
|
|
1167
1131
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1132
|
+
#i(t2) {
|
|
1133
|
+
const s = this.value ?? "";
|
|
1134
|
+
switch (t2) {
|
|
1135
|
+
case "up":
|
|
1136
|
+
this._cursor = findTextCursor(this._cursor, 0, -1, s);
|
|
1137
|
+
return;
|
|
1138
|
+
case "down":
|
|
1139
|
+
this._cursor = findTextCursor(this._cursor, 0, 1, s);
|
|
1140
|
+
return;
|
|
1141
|
+
case "left":
|
|
1142
|
+
this._cursor = findTextCursor(this._cursor, -1, 0, s);
|
|
1143
|
+
return;
|
|
1144
|
+
case "right":
|
|
1145
|
+
this._cursor = findTextCursor(this._cursor, 1, 0, s);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1170
1148
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1149
|
+
_shouldSubmit(t2, s) {
|
|
1150
|
+
if (this.#s)
|
|
1151
|
+
return this.focused === "submit" ? true : (this.#r(`
|
|
1152
|
+
`), this._cursor++, false);
|
|
1153
|
+
const r2 = this.#t;
|
|
1154
|
+
return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
|
|
1155
|
+
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
|
|
1156
|
+
`), this._cursor++, false);
|
|
1177
1157
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1158
|
+
constructor(t2) {
|
|
1159
|
+
const s = t2.initialUserInput ?? t2.initialValue;
|
|
1160
|
+
super({
|
|
1161
|
+
...t2,
|
|
1162
|
+
initialUserInput: s
|
|
1163
|
+
}, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
|
|
1164
|
+
if (i?.name && o$1.has(i.name)) {
|
|
1165
|
+
this.#t = false, this.#i(i.name);
|
|
1166
|
+
return;
|
|
1186
1167
|
}
|
|
1187
|
-
this
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1168
|
+
if (r2 === "\t" && this.#s) {
|
|
1169
|
+
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (i?.name !== "return") {
|
|
1173
|
+
if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
|
|
1174
|
+
this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (i?.name === "delete" && this.cursor < this.userInput.length) {
|
|
1178
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
r2 && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r2 ?? ""), this._cursor++);
|
|
1182
|
+
}
|
|
1183
|
+
}), this.on("userInput", (r2) => {
|
|
1184
|
+
this._setValue(r2);
|
|
1185
|
+
}), this.on("finalize", () => {
|
|
1186
|
+
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1198
1187
|
});
|
|
1199
1188
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1189
|
+
}
|
|
1190
|
+
var a$1 = class a extends V {
|
|
1191
|
+
options;
|
|
1192
|
+
cursor = 0;
|
|
1193
|
+
get _value() {
|
|
1194
|
+
return this.options[this.cursor].value;
|
|
1202
1195
|
}
|
|
1203
|
-
|
|
1204
|
-
return true;
|
|
1196
|
+
get _enabledOptions() {
|
|
1197
|
+
return this.options.filter((e) => e.disabled !== true);
|
|
1205
1198
|
}
|
|
1206
|
-
|
|
1207
|
-
this.
|
|
1199
|
+
toggleAll() {
|
|
1200
|
+
const e = this._enabledOptions, i = this.value !== undefined && this.value.length === e.length;
|
|
1201
|
+
this.value = i ? [] : e.map((t2) => t2.value);
|
|
1208
1202
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1203
|
+
toggleInvert() {
|
|
1204
|
+
const e = this.value;
|
|
1205
|
+
if (!e)
|
|
1206
|
+
return;
|
|
1207
|
+
const i = this._enabledOptions.filter((t2) => !e.includes(t2.value));
|
|
1208
|
+
this.value = i.map((t2) => t2.value);
|
|
1211
1209
|
}
|
|
1212
|
-
|
|
1213
|
-
this.
|
|
1210
|
+
toggleValue() {
|
|
1211
|
+
this.value === undefined && (this.value = []);
|
|
1212
|
+
const e = this.value.includes(this._value);
|
|
1213
|
+
this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
|
|
1214
1214
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1215
|
+
constructor(e) {
|
|
1216
|
+
super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
1217
|
+
const i = Math.max(this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt), 0);
|
|
1218
|
+
this.cursor = this.options[i].disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t2, l2) => {
|
|
1219
|
+
l2.name === "a" && this.toggleAll(), l2.name === "i" && this.toggleInvert();
|
|
1220
|
+
}), this.on("cursor", (t2) => {
|
|
1221
|
+
switch (t2) {
|
|
1222
|
+
case "left":
|
|
1223
|
+
case "up":
|
|
1224
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1225
|
+
break;
|
|
1226
|
+
case "down":
|
|
1227
|
+
case "right":
|
|
1228
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1229
|
+
break;
|
|
1230
|
+
case "space":
|
|
1231
|
+
this.toggleValue();
|
|
1232
|
+
break;
|
|
1220
1233
|
}
|
|
1221
|
-
|
|
1222
|
-
}
|
|
1223
|
-
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();
|
|
1234
|
+
});
|
|
1224
1235
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1236
|
+
};
|
|
1237
|
+
class a2 extends V {
|
|
1238
|
+
options;
|
|
1239
|
+
cursor = 0;
|
|
1240
|
+
get _selectedValue() {
|
|
1241
|
+
return this.options[this.cursor];
|
|
1228
1242
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
`).length - 1;
|
|
1232
|
-
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
1243
|
+
changeValue() {
|
|
1244
|
+
this.value = this._selectedValue.value;
|
|
1233
1245
|
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
if (r === undefined) {
|
|
1248
|
-
this._prevFrame = t2;
|
|
1249
|
-
return;
|
|
1250
|
-
}
|
|
1251
|
-
if (e.lines.length === 1) {
|
|
1252
|
-
this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
1253
|
-
const o = t2.split(`
|
|
1254
|
-
`);
|
|
1255
|
-
this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
|
|
1256
|
-
return;
|
|
1257
|
-
} else if (e.lines.length > 1) {
|
|
1258
|
-
if (n < s)
|
|
1259
|
-
r = n;
|
|
1260
|
-
else {
|
|
1261
|
-
const h = r - s;
|
|
1262
|
-
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
1263
|
-
}
|
|
1264
|
-
this.output.write(import_sisteransi.erase.down());
|
|
1265
|
-
const f = t2.split(`
|
|
1266
|
-
`).slice(r);
|
|
1267
|
-
this.output.write(f.join(`
|
|
1268
|
-
`)), this._prevFrame = t2;
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
this.output.write(import_sisteransi.erase.down());
|
|
1246
|
+
constructor(t2) {
|
|
1247
|
+
super(t2, false), this.options = t2.options;
|
|
1248
|
+
const i = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i === -1 ? 0 : i;
|
|
1249
|
+
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
1250
|
+
switch (s) {
|
|
1251
|
+
case "left":
|
|
1252
|
+
case "up":
|
|
1253
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1254
|
+
break;
|
|
1255
|
+
case "down":
|
|
1256
|
+
case "right":
|
|
1257
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1258
|
+
break;
|
|
1273
1259
|
}
|
|
1274
|
-
this.
|
|
1275
|
-
}
|
|
1260
|
+
this.changeValue();
|
|
1261
|
+
});
|
|
1276
1262
|
}
|
|
1277
1263
|
}
|
|
1278
|
-
|
|
1279
|
-
if (l2 === undefined || e.length === 0)
|
|
1280
|
-
return 0;
|
|
1281
|
-
const i = e.findIndex((s) => s.value === l2);
|
|
1282
|
-
return i !== -1 ? i : 0;
|
|
1283
|
-
}
|
|
1284
|
-
function g(l2, e) {
|
|
1285
|
-
return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
|
|
1286
|
-
}
|
|
1287
|
-
function m(l2, e) {
|
|
1288
|
-
if (e)
|
|
1289
|
-
return l2 ? e : e[0];
|
|
1290
|
-
}
|
|
1291
|
-
var T$1 = class T extends V {
|
|
1292
|
-
filteredOptions;
|
|
1293
|
-
multiple;
|
|
1294
|
-
isNavigating = false;
|
|
1295
|
-
selectedValues = [];
|
|
1296
|
-
focusedValue;
|
|
1297
|
-
#e = 0;
|
|
1298
|
-
#s = "";
|
|
1299
|
-
#t;
|
|
1300
|
-
#i;
|
|
1301
|
-
#n;
|
|
1302
|
-
get cursor() {
|
|
1303
|
-
return this.#e;
|
|
1304
|
-
}
|
|
1264
|
+
class n extends V {
|
|
1305
1265
|
get userInputWithCursor() {
|
|
1306
|
-
if (
|
|
1307
|
-
return
|
|
1308
|
-
|
|
1266
|
+
if (this.state === "submit")
|
|
1267
|
+
return this.userInput;
|
|
1268
|
+
const t2 = this.userInput;
|
|
1269
|
+
if (this.cursor >= t2.length)
|
|
1309
1270
|
return `${this.userInput}\u2588`;
|
|
1310
|
-
const e =
|
|
1311
|
-
return `${e}${styleText("inverse",
|
|
1312
|
-
}
|
|
1313
|
-
get options() {
|
|
1314
|
-
return typeof this.#i == "function" ? this.#i() : this.#i;
|
|
1315
|
-
}
|
|
1316
|
-
constructor(e) {
|
|
1317
|
-
super(e), this.#i = e.options, this.#n = e.placeholder;
|
|
1318
|
-
const t2 = this.options;
|
|
1319
|
-
this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
|
|
1320
|
-
let i;
|
|
1321
|
-
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
|
|
1322
|
-
for (const s of i) {
|
|
1323
|
-
const n = t2.findIndex((o) => o.value === s);
|
|
1324
|
-
n !== -1 && (this.toggleSelected(s), this.#e = n);
|
|
1325
|
-
}
|
|
1326
|
-
this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
|
|
1327
|
-
}
|
|
1328
|
-
_isActionKey(e, t2) {
|
|
1329
|
-
return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
|
|
1330
|
-
}
|
|
1331
|
-
#l(e, t2) {
|
|
1332
|
-
const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#n, h = this.options, f = u !== undefined && u !== "" && h.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
|
|
1333
|
-
if (t2.name === "tab" && o && f) {
|
|
1334
|
-
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
1335
|
-
return;
|
|
1336
|
-
}
|
|
1337
|
-
i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
1338
|
-
}
|
|
1339
|
-
deselectAll() {
|
|
1340
|
-
this.selectedValues = [];
|
|
1341
|
-
}
|
|
1342
|
-
toggleSelected(e) {
|
|
1343
|
-
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
1344
|
-
}
|
|
1345
|
-
#u(e) {
|
|
1346
|
-
if (e !== this.#s) {
|
|
1347
|
-
this.#s = e;
|
|
1348
|
-
const t2 = this.options;
|
|
1349
|
-
e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
|
|
1350
|
-
const i = p$1(this.focusedValue, this.filteredOptions);
|
|
1351
|
-
this.#e = findCursor(i, 0, this.filteredOptions);
|
|
1352
|
-
const s = this.filteredOptions[this.#e];
|
|
1353
|
-
s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
1354
|
-
}
|
|
1271
|
+
const e = t2.slice(0, this.cursor), [s, ...r2] = t2.slice(this.cursor);
|
|
1272
|
+
return `${e}${styleText("inverse", s)}${r2.join("")}`;
|
|
1355
1273
|
}
|
|
1356
|
-
};
|
|
1357
|
-
|
|
1358
|
-
class r extends V {
|
|
1359
1274
|
get cursor() {
|
|
1360
|
-
return this.
|
|
1361
|
-
}
|
|
1362
|
-
get _value() {
|
|
1363
|
-
return this.cursor === 0;
|
|
1275
|
+
return this._cursor;
|
|
1364
1276
|
}
|
|
1365
1277
|
constructor(t2) {
|
|
1366
|
-
super(
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1278
|
+
super({
|
|
1279
|
+
...t2,
|
|
1280
|
+
initialUserInput: t2.initialUserInput ?? t2.initialValue
|
|
1281
|
+
}), this.on("userInput", (e) => {
|
|
1282
|
+
this._setValue(e);
|
|
1283
|
+
}), this.on("finalize", () => {
|
|
1284
|
+
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1372
1285
|
});
|
|
1373
1286
|
}
|
|
1374
1287
|
}
|
|
1375
|
-
var _ = {
|
|
1376
|
-
Y: { type: "year", len: 4 },
|
|
1377
|
-
M: { type: "month", len: 2 },
|
|
1378
|
-
D: { type: "day", len: 2 }
|
|
1379
|
-
};
|
|
1380
|
-
function M(r2) {
|
|
1381
|
-
return [...r2].map((t2) => _[t2]);
|
|
1382
|
-
}
|
|
1383
|
-
function P(r2) {
|
|
1384
|
-
const i = new Intl.DateTimeFormat(r2, {
|
|
1385
|
-
year: "numeric",
|
|
1386
|
-
month: "2-digit",
|
|
1387
|
-
day: "2-digit"
|
|
1388
|
-
}).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
1389
|
-
let n = "/";
|
|
1390
|
-
for (const e of i)
|
|
1391
|
-
e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
|
|
1392
|
-
return { segments: s, separator: n };
|
|
1393
|
-
}
|
|
1394
|
-
function p(r2) {
|
|
1395
|
-
return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
|
|
1396
|
-
}
|
|
1397
|
-
function f(r2) {
|
|
1398
|
-
return {
|
|
1399
|
-
year: p(r2.year),
|
|
1400
|
-
month: p(r2.month),
|
|
1401
|
-
day: p(r2.day)
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
function c(r2, t2) {
|
|
1405
|
-
return new Date(r2 || 2001, t2 || 1, 0).getDate();
|
|
1406
|
-
}
|
|
1407
|
-
function b(r2) {
|
|
1408
|
-
const { year: t2, month: i, day: s } = f(r2);
|
|
1409
|
-
if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
|
|
1410
|
-
return;
|
|
1411
|
-
const n = new Date(Date.UTC(t2, i - 1, s));
|
|
1412
|
-
if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
|
|
1413
|
-
return { year: t2, month: i, day: s };
|
|
1414
|
-
}
|
|
1415
|
-
function C(r2) {
|
|
1416
|
-
const t2 = b(r2);
|
|
1417
|
-
return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
|
|
1418
|
-
}
|
|
1419
|
-
function T2(r2, t2, i, s) {
|
|
1420
|
-
const n = i ? {
|
|
1421
|
-
year: i.getUTCFullYear(),
|
|
1422
|
-
month: i.getUTCMonth() + 1,
|
|
1423
|
-
day: i.getUTCDate()
|
|
1424
|
-
} : null, e = s ? {
|
|
1425
|
-
year: s.getUTCFullYear(),
|
|
1426
|
-
month: s.getUTCMonth() + 1,
|
|
1427
|
-
day: s.getUTCDate()
|
|
1428
|
-
} : null;
|
|
1429
|
-
return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
|
|
1430
|
-
min: n && t2.year === n.year ? n.month : 1,
|
|
1431
|
-
max: e && t2.year === e.year ? e.month : 12
|
|
1432
|
-
} : {
|
|
1433
|
-
min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
|
|
1434
|
-
max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
1288
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
#n = true;
|
|
1446
|
-
#s = null;
|
|
1447
|
-
inlineError = "";
|
|
1448
|
-
get segmentCursor() {
|
|
1449
|
-
return { ...this.#e };
|
|
1450
|
-
}
|
|
1451
|
-
get segmentValues() {
|
|
1452
|
-
return { ...this.#t };
|
|
1453
|
-
}
|
|
1454
|
-
get segments() {
|
|
1455
|
-
return this.#i;
|
|
1456
|
-
}
|
|
1457
|
-
get separator() {
|
|
1458
|
-
return this.#o;
|
|
1459
|
-
}
|
|
1460
|
-
get formattedValue() {
|
|
1461
|
-
return this.#l(this.#t);
|
|
1462
|
-
}
|
|
1463
|
-
#l(t2) {
|
|
1464
|
-
return this.#i.map((i) => t2[i.type]).join(this.#o);
|
|
1465
|
-
}
|
|
1466
|
-
#r() {
|
|
1467
|
-
this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
|
|
1468
|
-
}
|
|
1469
|
-
constructor(t2) {
|
|
1470
|
-
const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
|
|
1471
|
-
year: String(e.getUTCFullYear()).padStart(4, "0"),
|
|
1472
|
-
month: String(e.getUTCMonth() + 1).padStart(2, "0"),
|
|
1473
|
-
day: String(e.getUTCDate()).padStart(2, "0")
|
|
1474
|
-
} : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
|
|
1475
|
-
super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
|
|
1289
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
1290
|
+
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
1291
|
+
import process$1 from "process";
|
|
1292
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1293
|
+
function isUnicodeSupported() {
|
|
1294
|
+
if (process$1.platform !== "win32") {
|
|
1295
|
+
return process$1.env.TERM !== "linux";
|
|
1476
1296
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1297
|
+
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";
|
|
1298
|
+
}
|
|
1299
|
+
var unicode = isUnicodeSupported();
|
|
1300
|
+
var isCI = () => process.env.CI === "true";
|
|
1301
|
+
var unicodeOr = (o2, e) => unicode ? o2 : e;
|
|
1302
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
1303
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
1304
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
1305
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
1306
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
1307
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
1308
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
1309
|
+
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
1310
|
+
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
1311
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
1312
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
1313
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
1314
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
1315
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
1316
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
1317
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
1318
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
1319
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
1320
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
1321
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
1322
|
+
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
1323
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
1324
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
1325
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
1326
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
1327
|
+
var symbol = (o2) => {
|
|
1328
|
+
switch (o2) {
|
|
1329
|
+
case "initial":
|
|
1330
|
+
case "active":
|
|
1331
|
+
return styleText2("cyan", S_STEP_ACTIVE);
|
|
1332
|
+
case "cancel":
|
|
1333
|
+
return styleText2("red", S_STEP_CANCEL);
|
|
1334
|
+
case "error":
|
|
1335
|
+
return styleText2("yellow", S_STEP_ERROR);
|
|
1336
|
+
case "submit":
|
|
1337
|
+
return styleText2("green", S_STEP_SUBMIT);
|
|
1481
1338
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1339
|
+
};
|
|
1340
|
+
var symbolBar = (o2) => {
|
|
1341
|
+
switch (o2) {
|
|
1342
|
+
case "initial":
|
|
1343
|
+
case "active":
|
|
1344
|
+
return styleText2("cyan", S_BAR);
|
|
1345
|
+
case "cancel":
|
|
1346
|
+
return styleText2("red", S_BAR);
|
|
1347
|
+
case "error":
|
|
1348
|
+
return styleText2("yellow", S_BAR);
|
|
1349
|
+
case "submit":
|
|
1350
|
+
return styleText2("green", S_BAR);
|
|
1486
1351
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1352
|
+
};
|
|
1353
|
+
function formatInstructionFooter(o2, e) {
|
|
1354
|
+
const r2 = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o2.join(" \u2022 ")}`];
|
|
1355
|
+
return e && r2.push(styleText2("cyan", S_BAR_END)), r2;
|
|
1356
|
+
}
|
|
1357
|
+
var E$1 = (l2, o2, g2, c2, h2, O = false) => {
|
|
1358
|
+
let r2 = o2, w = 0;
|
|
1359
|
+
if (O)
|
|
1360
|
+
for (let i = c2 - 1;i >= g2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i--)
|
|
1361
|
+
;
|
|
1362
|
+
else
|
|
1363
|
+
for (let i = g2;i < c2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i++)
|
|
1364
|
+
;
|
|
1365
|
+
return { lineCount: r2, removals: w };
|
|
1366
|
+
};
|
|
1367
|
+
var limitOptions = ({
|
|
1368
|
+
cursor: l2,
|
|
1369
|
+
options: o2,
|
|
1370
|
+
style: g2,
|
|
1371
|
+
output: c2 = process.stdout,
|
|
1372
|
+
maxItems: h2 = Number.POSITIVE_INFINITY,
|
|
1373
|
+
columnPadding: O = 0,
|
|
1374
|
+
rowPadding: r2 = 4
|
|
1375
|
+
}) => {
|
|
1376
|
+
const i = getColumns(c2) - O, I = getRows(c2), C2 = styleText2("dim", "..."), x = Math.max(I - r2, 0), m2 = Math.max(Math.min(h2, x), 5);
|
|
1377
|
+
let p2 = 0;
|
|
1378
|
+
l2 >= m2 - 3 && (p2 = Math.max(Math.min(l2 - m2 + 3, o2.length - m2), 0));
|
|
1379
|
+
let f2 = m2 < o2.length && p2 > 0, u3 = m2 < o2.length && p2 + m2 < o2.length;
|
|
1380
|
+
const W = Math.min(p2 + m2, o2.length), e = [];
|
|
1381
|
+
let d = 0;
|
|
1382
|
+
f2 && d++, u3 && d++;
|
|
1383
|
+
const v = p2 + (f2 ? 1 : 0), P2 = W - (u3 ? 1 : 0);
|
|
1384
|
+
for (let t2 = v;t2 < P2; t2++) {
|
|
1385
|
+
const n2 = wrapAnsi(g2(o2[t2], t2 === l2), i, {
|
|
1386
|
+
hard: true,
|
|
1387
|
+
trim: false
|
|
1388
|
+
}).split(`
|
|
1389
|
+
`);
|
|
1390
|
+
e.push(n2), d += n2.length;
|
|
1497
1391
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
return this.#m(-1);
|
|
1505
|
-
case "up":
|
|
1506
|
-
return this.#d(1);
|
|
1507
|
-
case "down":
|
|
1508
|
-
return this.#d(-1);
|
|
1509
|
-
}
|
|
1392
|
+
if (d > x) {
|
|
1393
|
+
let t2 = 0, n2 = 0, s = d;
|
|
1394
|
+
const M2 = l2 - v;
|
|
1395
|
+
let a3 = x;
|
|
1396
|
+
const T3 = () => E$1(e, s, 0, M2, a3), L = () => E$1(e, s, M2 + 1, e.length, a3, true);
|
|
1397
|
+
f2 ? ({ lineCount: s, removals: t2 } = T3(), s > a3 && (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L(), s > a3 && (a3 -= 1, { lineCount: s, removals: t2 } = T3())), t2 > 0 && (f2 = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
|
|
1510
1398
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
if (!n)
|
|
1536
|
-
return;
|
|
1537
|
-
const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
|
|
1538
|
-
if (this.#n && this.#s !== null && !m2) {
|
|
1539
|
-
const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
|
|
1540
|
-
if (g2) {
|
|
1541
|
-
this.inlineError = g2, this.#s = null, this.#n = false;
|
|
1542
|
-
return;
|
|
1399
|
+
const b2 = [];
|
|
1400
|
+
f2 && b2.push(C2);
|
|
1401
|
+
for (const t2 of e)
|
|
1402
|
+
for (const n2 of t2)
|
|
1403
|
+
b2.push(n2);
|
|
1404
|
+
return u3 && b2.push(C2), b2;
|
|
1405
|
+
};
|
|
1406
|
+
var confirm = (i) => {
|
|
1407
|
+
const a3 = i.active ?? "Yes", s = i.inactive ?? "No";
|
|
1408
|
+
return new r({
|
|
1409
|
+
active: a3,
|
|
1410
|
+
inactive: s,
|
|
1411
|
+
signal: i.signal,
|
|
1412
|
+
input: i.input,
|
|
1413
|
+
output: i.output,
|
|
1414
|
+
initialValue: i.initialValue ?? true,
|
|
1415
|
+
render() {
|
|
1416
|
+
const e = i.withGuide ?? settings.withGuide, u3 = `${symbol(this.state)} `, l2 = e ? `${styleText2("gray", S_BAR)} ` : "", f2 = wrapTextWithPrefix(i.output, i.message, l2, u3), o2 = `${e ? `${styleText2("gray", S_BAR)}
|
|
1417
|
+
` : ""}${f2}
|
|
1418
|
+
`, c2 = this.value ? a3 : s;
|
|
1419
|
+
switch (this.state) {
|
|
1420
|
+
case "submit": {
|
|
1421
|
+
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1422
|
+
return `${o2}${r2}${styleText2("dim", c2)}`;
|
|
1543
1423
|
}
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
|
|
1557
|
-
const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
|
|
1558
|
-
if (d) {
|
|
1559
|
-
this.inlineError = d;
|
|
1560
|
-
return;
|
|
1424
|
+
case "cancel": {
|
|
1425
|
+
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1426
|
+
return `${o2}${r2}${styleText2(["strikethrough", "dim"], c2)}${e ? `
|
|
1427
|
+
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1428
|
+
}
|
|
1429
|
+
default: {
|
|
1430
|
+
const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g2 = e ? styleText2("cyan", S_BAR_END) : "";
|
|
1431
|
+
return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a3}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a3)}`}${i.vertical ? e ? `
|
|
1432
|
+
${styleText2("cyan", S_BAR)} ` : `
|
|
1433
|
+
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
|
|
1434
|
+
${g2}
|
|
1435
|
+
`;
|
|
1561
1436
|
}
|
|
1562
1437
|
}
|
|
1563
|
-
this.inlineError = "", this.#t[e.type] = l2;
|
|
1564
|
-
const y = l2.includes("_") ? undefined : b(this.#t);
|
|
1565
|
-
if (y) {
|
|
1566
|
-
const { year: h, month: d } = y, g2 = c(h, d);
|
|
1567
|
-
this.#t = {
|
|
1568
|
-
year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
|
|
1569
|
-
month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
|
|
1570
|
-
day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
this.#r();
|
|
1574
|
-
const S = l2.indexOf("_");
|
|
1575
|
-
D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
|
|
1576
1438
|
}
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1439
|
+
}).prompt();
|
|
1440
|
+
};
|
|
1441
|
+
var MULTISELECT_INSTRUCTIONS = [
|
|
1442
|
+
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
1443
|
+
`${styleText2("dim", "Space:")} select`,
|
|
1444
|
+
`${styleText2("dim", "Enter:")} confirm`
|
|
1445
|
+
];
|
|
1446
|
+
var m2 = (n2, o2) => n2.split(`
|
|
1447
|
+
`).map((d) => o2(d)).join(`
|
|
1448
|
+
`);
|
|
1449
|
+
var multiselect = (n2) => {
|
|
1450
|
+
const o2 = (t2, a3) => {
|
|
1451
|
+
const r2 = t2.label ?? String(t2.value);
|
|
1452
|
+
return a3 === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${m2(r2, (l2) => styleText2(["strikethrough", "gray"], l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}` : a3 === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${m2(r2, (l2) => styleText2("dim", l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "cancelled" ? `${m2(r2, (l2) => styleText2(["strikethrough", "dim"], l2))}` : a3 === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "submitted" ? `${m2(r2, (l2) => styleText2("dim", l2))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${m2(r2, (l2) => styleText2("dim", l2))}`;
|
|
1453
|
+
}, d = n2.required ?? true;
|
|
1454
|
+
return new a$1({
|
|
1455
|
+
options: n2.options,
|
|
1456
|
+
signal: n2.signal,
|
|
1457
|
+
input: n2.input,
|
|
1458
|
+
output: n2.output,
|
|
1459
|
+
initialValues: n2.initialValues,
|
|
1460
|
+
required: d,
|
|
1461
|
+
cursorAt: n2.cursorAt,
|
|
1462
|
+
validate(t2) {
|
|
1463
|
+
if (d && (t2 === undefined || t2.length === 0))
|
|
1464
|
+
return `Please select at least one option.
|
|
1465
|
+
${styleText2("reset", styleText2("dim", `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2("gray", styleText2("bgWhite", styleText2("inverse", " enter ")))} to submit`))}`;
|
|
1466
|
+
},
|
|
1467
|
+
render() {
|
|
1468
|
+
const t2 = n2.withGuide ?? settings.withGuide, a3 = wrapTextWithPrefix(n2.output, n2.message, t2 ? `${symbolBar(this.state)} ` : "", `${symbol(this.state)} `), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
|
|
1469
|
+
` : ""}${a3}
|
|
1470
|
+
`, l2 = this.value ?? [], p2 = (i, u3) => {
|
|
1471
|
+
if (i.disabled)
|
|
1472
|
+
return o2(i, "disabled");
|
|
1473
|
+
const s = l2.includes(i.value);
|
|
1474
|
+
return u3 && s ? o2(i, "active-selected") : s ? o2(i, "selected") : o2(i, u3 ? "active" : "inactive");
|
|
1592
1475
|
};
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
var u$1 = class u extends V {
|
|
1598
|
-
options;
|
|
1599
|
-
cursor = 0;
|
|
1600
|
-
#t;
|
|
1601
|
-
getGroupItems(t2) {
|
|
1602
|
-
return this.options.filter((r2) => r2.group === t2);
|
|
1603
|
-
}
|
|
1604
|
-
isGroupSelected(t2) {
|
|
1605
|
-
const r2 = this.getGroupItems(t2), e = this.value;
|
|
1606
|
-
return e === undefined ? false : r2.every((s) => e.includes(s.value));
|
|
1607
|
-
}
|
|
1608
|
-
toggleValue() {
|
|
1609
|
-
const t2 = this.options[this.cursor];
|
|
1610
|
-
if (this.value === undefined && (this.value = []), t2.group === true) {
|
|
1611
|
-
const r2 = t2.value, e = this.getGroupItems(r2);
|
|
1612
|
-
this.isGroupSelected(r2) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
|
|
1613
|
-
} else {
|
|
1614
|
-
const r2 = this.value.includes(t2.value);
|
|
1615
|
-
this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
constructor(t2) {
|
|
1619
|
-
super(t2, false);
|
|
1620
|
-
const { options: r2 } = t2;
|
|
1621
|
-
this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
|
|
1622
|
-
{ value: e, group: true, label: e },
|
|
1623
|
-
...s.map((i) => ({ ...i, group: e }))
|
|
1624
|
-
]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
1625
|
-
switch (e) {
|
|
1626
|
-
case "left":
|
|
1627
|
-
case "up": {
|
|
1628
|
-
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1629
|
-
const s = this.options[this.cursor]?.group === true;
|
|
1630
|
-
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1631
|
-
break;
|
|
1476
|
+
switch (this.state) {
|
|
1477
|
+
case "submit": {
|
|
1478
|
+
const i = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => o2(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), u3 = wrapTextWithPrefix(n2.output, i, t2 ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1479
|
+
return `${r2}${u3}`;
|
|
1632
1480
|
}
|
|
1633
|
-
case "
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1481
|
+
case "cancel": {
|
|
1482
|
+
const i = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => o2(s, "cancelled")).join(styleText2("dim", ", "));
|
|
1483
|
+
if (i.trim() === "")
|
|
1484
|
+
return `${r2}${styleText2("gray", S_BAR)}`;
|
|
1485
|
+
const u3 = wrapTextWithPrefix(n2.output, i, t2 ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1486
|
+
return `${r2}${u3}${t2 ? `
|
|
1487
|
+
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1488
|
+
}
|
|
1489
|
+
case "error": {
|
|
1490
|
+
const i = t2 ? `${styleText2("yellow", S_BAR)} ` : "", u3 = this.error.split(`
|
|
1491
|
+
`).map(($, x) => x === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $)}` : ` ${$}`).join(`
|
|
1492
|
+
`), s = r2.split(`
|
|
1493
|
+
`).length, g2 = u3.split(`
|
|
1494
|
+
`).length + 1;
|
|
1495
|
+
return `${r2}${i}${limitOptions({
|
|
1496
|
+
output: n2.output,
|
|
1497
|
+
options: this.options,
|
|
1498
|
+
cursor: this.cursor,
|
|
1499
|
+
maxItems: n2.maxItems,
|
|
1500
|
+
columnPadding: i.length,
|
|
1501
|
+
rowPadding: s + g2,
|
|
1502
|
+
style: p2
|
|
1503
|
+
}).join(`
|
|
1504
|
+
${i}`)}
|
|
1505
|
+
${u3}
|
|
1506
|
+
`;
|
|
1507
|
+
}
|
|
1508
|
+
default: {
|
|
1509
|
+
const i = t2 ? `${styleText2("cyan", S_BAR)} ` : "", u3 = r2.split(`
|
|
1510
|
+
`).length, s = formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t2), g2 = s.join(`
|
|
1511
|
+
`), $ = s.length + 1;
|
|
1512
|
+
return `${r2}${i}${limitOptions({
|
|
1513
|
+
output: n2.output,
|
|
1514
|
+
options: this.options,
|
|
1515
|
+
cursor: this.cursor,
|
|
1516
|
+
maxItems: n2.maxItems,
|
|
1517
|
+
columnPadding: i.length,
|
|
1518
|
+
rowPadding: u3 + $,
|
|
1519
|
+
style: p2
|
|
1520
|
+
}).join(`
|
|
1521
|
+
${i}`)}
|
|
1522
|
+
${g2}
|
|
1523
|
+
`;
|
|
1639
1524
|
}
|
|
1640
|
-
case "space":
|
|
1641
|
-
this.toggleValue();
|
|
1642
|
-
break;
|
|
1643
1525
|
}
|
|
1644
|
-
}
|
|
1526
|
+
}
|
|
1527
|
+
}).prompt();
|
|
1528
|
+
};
|
|
1529
|
+
var log = {
|
|
1530
|
+
message: (s = [], {
|
|
1531
|
+
symbol: e = styleText2("gray", S_BAR),
|
|
1532
|
+
secondarySymbol: r2 = styleText2("gray", S_BAR),
|
|
1533
|
+
output: m3 = process.stdout,
|
|
1534
|
+
spacing: l2 = 1,
|
|
1535
|
+
withGuide: c2
|
|
1536
|
+
} = {}) => {
|
|
1537
|
+
const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
1538
|
+
for (let i = 0;i < l2; i++)
|
|
1539
|
+
t2.push(f2);
|
|
1540
|
+
const g2 = Array.isArray(s) ? s : s.split(`
|
|
1541
|
+
`);
|
|
1542
|
+
if (g2.length > 0) {
|
|
1543
|
+
const [i, ...y] = g2;
|
|
1544
|
+
i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
|
|
1545
|
+
for (const p2 of y)
|
|
1546
|
+
p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
|
|
1547
|
+
}
|
|
1548
|
+
m3.write(`${t2.join(`
|
|
1549
|
+
`)}
|
|
1550
|
+
`);
|
|
1551
|
+
},
|
|
1552
|
+
info: (s, e) => {
|
|
1553
|
+
log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
|
|
1554
|
+
},
|
|
1555
|
+
success: (s, e) => {
|
|
1556
|
+
log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
|
|
1557
|
+
},
|
|
1558
|
+
step: (s, e) => {
|
|
1559
|
+
log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
|
|
1560
|
+
},
|
|
1561
|
+
warn: (s, e) => {
|
|
1562
|
+
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
1563
|
+
},
|
|
1564
|
+
warning: (s, e) => {
|
|
1565
|
+
log.warn(s, e);
|
|
1566
|
+
},
|
|
1567
|
+
error: (s, e) => {
|
|
1568
|
+
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
1645
1569
|
}
|
|
1646
1570
|
};
|
|
1647
|
-
var
|
|
1571
|
+
var cancel = (o2 = "", t2) => {
|
|
1572
|
+
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
|
|
1573
|
+
i.write(`${e}${styleText2("red", o2)}
|
|
1648
1574
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
`
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1575
|
+
`);
|
|
1576
|
+
};
|
|
1577
|
+
var intro = (o2 = "", t2) => {
|
|
1578
|
+
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
1579
|
+
i.write(`${e}${o2}
|
|
1580
|
+
`);
|
|
1581
|
+
};
|
|
1582
|
+
var outro = (o2 = "", t2) => {
|
|
1583
|
+
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
1584
|
+
${styleText2("gray", S_BAR_END)} ` : "";
|
|
1585
|
+
i.write(`${e}${o2}
|
|
1586
|
+
|
|
1587
|
+
`);
|
|
1588
|
+
};
|
|
1589
|
+
var W = (l2) => styleText2("magenta", l2);
|
|
1590
|
+
var spinner = ({
|
|
1591
|
+
indicator: l2 = "dots",
|
|
1592
|
+
onCancel: h2,
|
|
1593
|
+
output: n2 = process.stdout,
|
|
1594
|
+
cancelMessage: G,
|
|
1595
|
+
errorMessage: O,
|
|
1596
|
+
frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
|
|
1597
|
+
delay: F = unicode ? 80 : 120,
|
|
1598
|
+
signal: m3,
|
|
1599
|
+
...I
|
|
1600
|
+
} = {}) => {
|
|
1601
|
+
const u3 = isCI();
|
|
1602
|
+
let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
|
|
1603
|
+
const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
|
|
1604
|
+
const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
1605
|
+
S = e === 1, d && (a3(r2, e), S && typeof h2 == "function" && h2());
|
|
1606
|
+
}, f2 = () => g2(2), i = () => g2(1), A = () => {
|
|
1607
|
+
process.on("uncaughtExceptionMonitor", f2), process.on("unhandledRejection", f2), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g2), m3 && m3.addEventListener("abort", i);
|
|
1608
|
+
}, H = () => {
|
|
1609
|
+
process.removeListener("uncaughtExceptionMonitor", f2), process.removeListener("unhandledRejection", f2), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g2), m3 && m3.removeEventListener("abort", i);
|
|
1610
|
+
}, y = () => {
|
|
1611
|
+
if (p2 === undefined)
|
|
1670
1612
|
return;
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
_shouldSubmit(t2, s) {
|
|
1692
|
-
if (this.#s)
|
|
1693
|
-
return this.focused === "submit" ? true : (this.#r(`
|
|
1694
|
-
`), this._cursor++, false);
|
|
1695
|
-
const r2 = this.#t;
|
|
1696
|
-
return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
|
|
1697
|
-
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
|
|
1698
|
-
`), this._cursor++, false);
|
|
1699
|
-
}
|
|
1700
|
-
constructor(t2) {
|
|
1701
|
-
const s = t2.initialUserInput ?? t2.initialValue;
|
|
1702
|
-
super({
|
|
1703
|
-
...t2,
|
|
1704
|
-
initialUserInput: s
|
|
1705
|
-
}, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
|
|
1706
|
-
if (i?.name && o$1.has(i.name)) {
|
|
1707
|
-
this.#t = false, this.#i(i.name);
|
|
1708
|
-
return;
|
|
1709
|
-
}
|
|
1710
|
-
if (r2 === "\t" && this.#s) {
|
|
1711
|
-
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
1613
|
+
u3 && n2.write(`
|
|
1614
|
+
`);
|
|
1615
|
+
const r2 = wrapAnsi(p2, x, {
|
|
1616
|
+
hard: true,
|
|
1617
|
+
trim: false
|
|
1618
|
+
}).split(`
|
|
1619
|
+
`);
|
|
1620
|
+
r2.length > 1 && n2.write(import_sisteransi2.cursor.up(r2.length - 1)), n2.write(import_sisteransi2.cursor.to(0)), n2.write(import_sisteransi2.erase.down());
|
|
1621
|
+
}, C2 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
|
|
1622
|
+
const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
|
|
1623
|
+
return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
|
|
1624
|
+
}, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
|
|
1625
|
+
d = true, M2 = block({ output: n2 }), s = C2(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
|
|
1626
|
+
`);
|
|
1627
|
+
let r2 = 0, t2 = 0;
|
|
1628
|
+
A(), T3 = setInterval(() => {
|
|
1629
|
+
if (u3 && s === p2)
|
|
1712
1630
|
return;
|
|
1631
|
+
y(), p2 = s;
|
|
1632
|
+
const o2 = k(E[r2]);
|
|
1633
|
+
let v;
|
|
1634
|
+
if (u3)
|
|
1635
|
+
v = `${o2} ${s}...`;
|
|
1636
|
+
else if (l2 === "timer")
|
|
1637
|
+
v = `${o2} ${s} ${_2(w)}`;
|
|
1638
|
+
else {
|
|
1639
|
+
const B = ".".repeat(Math.floor(t2)).slice(0, 3);
|
|
1640
|
+
v = `${o2} ${s}${B}`;
|
|
1713
1641
|
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
super(t2, false), this.options = t2.options;
|
|
1743
|
-
const i = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i === -1 ? 0 : i;
|
|
1744
|
-
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
1745
|
-
switch (s) {
|
|
1746
|
-
case "left":
|
|
1747
|
-
case "up":
|
|
1748
|
-
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1749
|
-
break;
|
|
1750
|
-
case "down":
|
|
1751
|
-
case "right":
|
|
1752
|
-
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1753
|
-
break;
|
|
1754
|
-
}
|
|
1755
|
-
this.changeValue();
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
class n extends V {
|
|
1760
|
-
get userInputWithCursor() {
|
|
1761
|
-
if (this.state === "submit")
|
|
1762
|
-
return this.userInput;
|
|
1763
|
-
const t2 = this.userInput;
|
|
1764
|
-
if (this.cursor >= t2.length)
|
|
1765
|
-
return `${this.userInput}\u2588`;
|
|
1766
|
-
const e = t2.slice(0, this.cursor), [s, ...r2] = t2.slice(this.cursor);
|
|
1767
|
-
return `${e}${styleText("inverse", s)}${r2.join("")}`;
|
|
1768
|
-
}
|
|
1769
|
-
get cursor() {
|
|
1770
|
-
return this._cursor;
|
|
1771
|
-
}
|
|
1772
|
-
constructor(t2) {
|
|
1773
|
-
super({
|
|
1774
|
-
...t2,
|
|
1775
|
-
initialUserInput: t2.initialUserInput ?? t2.initialValue
|
|
1776
|
-
}), this.on("userInput", (e) => {
|
|
1777
|
-
this._setValue(e);
|
|
1778
|
-
}), this.on("finalize", () => {
|
|
1779
|
-
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
// node_modules/@clack/prompts/dist/index.mjs
|
|
1785
|
-
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
1786
|
-
import process$1 from "process";
|
|
1787
|
-
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1788
|
-
function isUnicodeSupported() {
|
|
1789
|
-
if (process$1.platform !== "win32") {
|
|
1790
|
-
return process$1.env.TERM !== "linux";
|
|
1791
|
-
}
|
|
1792
|
-
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";
|
|
1793
|
-
}
|
|
1794
|
-
var unicode = isUnicodeSupported();
|
|
1795
|
-
var isCI = () => process.env.CI === "true";
|
|
1796
|
-
var unicodeOr = (o2, e) => unicode ? o2 : e;
|
|
1797
|
-
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
1798
|
-
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
1799
|
-
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
1800
|
-
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
1801
|
-
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
1802
|
-
var S_BAR = unicodeOr("\u2502", "|");
|
|
1803
|
-
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
1804
|
-
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
1805
|
-
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
1806
|
-
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
1807
|
-
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
1808
|
-
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
1809
|
-
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
1810
|
-
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
1811
|
-
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
1812
|
-
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
1813
|
-
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
1814
|
-
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
1815
|
-
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
1816
|
-
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
1817
|
-
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
1818
|
-
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
1819
|
-
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
1820
|
-
var S_WARN = unicodeOr("\u25B2", "!");
|
|
1821
|
-
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
1822
|
-
var symbol = (o2) => {
|
|
1823
|
-
switch (o2) {
|
|
1824
|
-
case "initial":
|
|
1825
|
-
case "active":
|
|
1826
|
-
return styleText2("cyan", S_STEP_ACTIVE);
|
|
1827
|
-
case "cancel":
|
|
1828
|
-
return styleText2("red", S_STEP_CANCEL);
|
|
1829
|
-
case "error":
|
|
1830
|
-
return styleText2("yellow", S_STEP_ERROR);
|
|
1831
|
-
case "submit":
|
|
1832
|
-
return styleText2("green", S_STEP_SUBMIT);
|
|
1833
|
-
}
|
|
1834
|
-
};
|
|
1835
|
-
var symbolBar = (o2) => {
|
|
1836
|
-
switch (o2) {
|
|
1837
|
-
case "initial":
|
|
1838
|
-
case "active":
|
|
1839
|
-
return styleText2("cyan", S_BAR);
|
|
1840
|
-
case "cancel":
|
|
1841
|
-
return styleText2("red", S_BAR);
|
|
1842
|
-
case "error":
|
|
1843
|
-
return styleText2("yellow", S_BAR);
|
|
1844
|
-
case "submit":
|
|
1845
|
-
return styleText2("green", S_BAR);
|
|
1846
|
-
}
|
|
1847
|
-
};
|
|
1848
|
-
function formatInstructionFooter(o2, e) {
|
|
1849
|
-
const r2 = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o2.join(" \u2022 ")}`];
|
|
1850
|
-
return e && r2.push(styleText2("cyan", S_BAR_END)), r2;
|
|
1851
|
-
}
|
|
1852
|
-
var E$1 = (l2, o2, g2, c2, h2, O = false) => {
|
|
1853
|
-
let r2 = o2, w = 0;
|
|
1854
|
-
if (O)
|
|
1855
|
-
for (let i = c2 - 1;i >= g2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i--)
|
|
1856
|
-
;
|
|
1857
|
-
else
|
|
1858
|
-
for (let i = g2;i < c2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i++)
|
|
1859
|
-
;
|
|
1860
|
-
return { lineCount: r2, removals: w };
|
|
1642
|
+
const j = wrapAnsi(v, x, {
|
|
1643
|
+
hard: true,
|
|
1644
|
+
trim: false
|
|
1645
|
+
});
|
|
1646
|
+
n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
|
|
1647
|
+
}, F);
|
|
1648
|
+
}, a3 = (e = "", r2 = 0, t2 = false) => {
|
|
1649
|
+
if (!d)
|
|
1650
|
+
return;
|
|
1651
|
+
d = false, clearInterval(T3), y();
|
|
1652
|
+
const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
1653
|
+
s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
|
|
1654
|
+
`) : n2.write(`${o2} ${s}
|
|
1655
|
+
`)), H(), M2();
|
|
1656
|
+
};
|
|
1657
|
+
return {
|
|
1658
|
+
start: P2,
|
|
1659
|
+
stop: (e = "") => a3(e, 0),
|
|
1660
|
+
message: (e = "") => {
|
|
1661
|
+
s = C2(e ?? s);
|
|
1662
|
+
},
|
|
1663
|
+
cancel: (e = "") => a3(e, 1),
|
|
1664
|
+
error: (e = "") => a3(e, 2),
|
|
1665
|
+
clear: () => a3("", 0, true),
|
|
1666
|
+
get isCancelled() {
|
|
1667
|
+
return S;
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1861
1670
|
};
|
|
1862
|
-
var
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
output: c2 = process.stdout,
|
|
1867
|
-
maxItems: h2 = Number.POSITIVE_INFINITY,
|
|
1868
|
-
columnPadding: O = 0,
|
|
1869
|
-
rowPadding: r2 = 4
|
|
1870
|
-
}) => {
|
|
1871
|
-
const i = getColumns(c2) - O, I = getRows(c2), C2 = styleText2("dim", "..."), x = Math.max(I - r2, 0), m2 = Math.max(Math.min(h2, x), 5);
|
|
1872
|
-
let p2 = 0;
|
|
1873
|
-
l2 >= m2 - 3 && (p2 = Math.max(Math.min(l2 - m2 + 3, o2.length - m2), 0));
|
|
1874
|
-
let f2 = m2 < o2.length && p2 > 0, u3 = m2 < o2.length && p2 + m2 < o2.length;
|
|
1875
|
-
const W = Math.min(p2 + m2, o2.length), e = [];
|
|
1876
|
-
let d = 0;
|
|
1877
|
-
f2 && d++, u3 && d++;
|
|
1878
|
-
const v = p2 + (f2 ? 1 : 0), P2 = W - (u3 ? 1 : 0);
|
|
1879
|
-
for (let t2 = v;t2 < P2; t2++) {
|
|
1880
|
-
const n2 = wrapAnsi(g2(o2[t2], t2 === l2), i, {
|
|
1881
|
-
hard: true,
|
|
1882
|
-
trim: false
|
|
1883
|
-
}).split(`
|
|
1884
|
-
`);
|
|
1885
|
-
e.push(n2), d += n2.length;
|
|
1886
|
-
}
|
|
1887
|
-
if (d > x) {
|
|
1888
|
-
let t2 = 0, n2 = 0, s = d;
|
|
1889
|
-
const M2 = l2 - v;
|
|
1890
|
-
let a2 = x;
|
|
1891
|
-
const T3 = () => E$1(e, s, 0, M2, a2), L = () => E$1(e, s, M2 + 1, e.length, a2, true);
|
|
1892
|
-
f2 ? ({ lineCount: s, removals: t2 } = T3(), s > a2 && (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L(), s > a2 && (a2 -= 1, { lineCount: s, removals: t2 } = T3())), t2 > 0 && (f2 = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
|
|
1893
|
-
}
|
|
1894
|
-
const b2 = [];
|
|
1895
|
-
f2 && b2.push(C2);
|
|
1896
|
-
for (const t2 of e)
|
|
1897
|
-
for (const n2 of t2)
|
|
1898
|
-
b2.push(n2);
|
|
1899
|
-
return u3 && b2.push(C2), b2;
|
|
1671
|
+
var u3 = {
|
|
1672
|
+
light: unicodeOr("\u2500", "-"),
|
|
1673
|
+
heavy: unicodeOr("\u2501", "="),
|
|
1674
|
+
block: unicodeOr("\u2588", "#")
|
|
1900
1675
|
};
|
|
1901
|
-
var
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1676
|
+
var SELECT_INSTRUCTIONS = [
|
|
1677
|
+
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
1678
|
+
`${styleText2("dim", "Enter:")} confirm`
|
|
1679
|
+
];
|
|
1680
|
+
var c2 = (t2, a3) => t2.includes(`
|
|
1681
|
+
`) ? t2.split(`
|
|
1682
|
+
`).map((i) => a3(i)).join(`
|
|
1683
|
+
`) : a3(t2);
|
|
1684
|
+
var select = (t2) => {
|
|
1685
|
+
const a3 = (i, m3) => {
|
|
1686
|
+
const s = i.label ?? String(i.value);
|
|
1687
|
+
switch (m3) {
|
|
1688
|
+
case "disabled":
|
|
1689
|
+
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("gray", n2))}${i.hint ? ` ${styleText2("dim", `(${i.hint ?? "disabled"})`)}` : ""}`;
|
|
1690
|
+
case "selected":
|
|
1691
|
+
return `${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
1692
|
+
case "active":
|
|
1693
|
+
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${i.hint ? ` ${styleText2("dim", `(${i.hint})`)}` : ""}`;
|
|
1694
|
+
case "cancelled":
|
|
1695
|
+
return `${c2(s, (n2) => styleText2(["strikethrough", "dim"], n2))}`;
|
|
1696
|
+
default:
|
|
1697
|
+
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
return new a2({
|
|
1701
|
+
options: t2.options,
|
|
1702
|
+
signal: t2.signal,
|
|
1703
|
+
input: t2.input,
|
|
1704
|
+
output: t2.output,
|
|
1705
|
+
initialValue: t2.initialValue,
|
|
1910
1706
|
render() {
|
|
1911
|
-
const
|
|
1912
|
-
` : ""}${
|
|
1913
|
-
|
|
1707
|
+
const i = t2.withGuide ?? settings.withGuide, m3 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(t2.output, t2.message, s, m3), u4 = `${i ? `${styleText2("gray", S_BAR)}
|
|
1708
|
+
` : ""}${n2}
|
|
1709
|
+
`;
|
|
1914
1710
|
switch (this.state) {
|
|
1915
1711
|
case "submit": {
|
|
1916
|
-
const r2 =
|
|
1917
|
-
return `${
|
|
1712
|
+
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a3(this.options[this.cursor], "selected"), r2);
|
|
1713
|
+
return `${u4}${o2}`;
|
|
1918
1714
|
}
|
|
1919
1715
|
case "cancel": {
|
|
1920
|
-
const r2 =
|
|
1921
|
-
return `${
|
|
1922
|
-
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1923
|
-
}
|
|
1924
|
-
default: {
|
|
1925
|
-
const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g2 = e ? styleText2("cyan", S_BAR_END) : "";
|
|
1926
|
-
return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a2}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a2)}`}${i.vertical ? e ? `
|
|
1927
|
-
${styleText2("cyan", S_BAR)} ` : `
|
|
1928
|
-
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
|
|
1929
|
-
${g2}
|
|
1930
|
-
`;
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
}).prompt();
|
|
1935
|
-
};
|
|
1936
|
-
var MULTISELECT_INSTRUCTIONS = [
|
|
1937
|
-
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
1938
|
-
`${styleText2("dim", "Space:")} select`,
|
|
1939
|
-
`${styleText2("dim", "Enter:")} confirm`
|
|
1940
|
-
];
|
|
1941
|
-
var log = {
|
|
1942
|
-
message: (s = [], {
|
|
1943
|
-
symbol: e = styleText2("gray", S_BAR),
|
|
1944
|
-
secondarySymbol: r2 = styleText2("gray", S_BAR),
|
|
1945
|
-
output: m2 = process.stdout,
|
|
1946
|
-
spacing: l2 = 1,
|
|
1947
|
-
withGuide: c2
|
|
1948
|
-
} = {}) => {
|
|
1949
|
-
const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
1950
|
-
for (let i = 0;i < l2; i++)
|
|
1951
|
-
t2.push(f2);
|
|
1952
|
-
const g2 = Array.isArray(s) ? s : s.split(`
|
|
1953
|
-
`);
|
|
1954
|
-
if (g2.length > 0) {
|
|
1955
|
-
const [i, ...y] = g2;
|
|
1956
|
-
i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
|
|
1957
|
-
for (const p2 of y)
|
|
1958
|
-
p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
|
|
1959
|
-
}
|
|
1960
|
-
m2.write(`${t2.join(`
|
|
1961
|
-
`)}
|
|
1962
|
-
`);
|
|
1963
|
-
},
|
|
1964
|
-
info: (s, e) => {
|
|
1965
|
-
log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
|
|
1966
|
-
},
|
|
1967
|
-
success: (s, e) => {
|
|
1968
|
-
log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
|
|
1969
|
-
},
|
|
1970
|
-
step: (s, e) => {
|
|
1971
|
-
log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
|
|
1972
|
-
},
|
|
1973
|
-
warn: (s, e) => {
|
|
1974
|
-
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
1975
|
-
},
|
|
1976
|
-
warning: (s, e) => {
|
|
1977
|
-
log.warn(s, e);
|
|
1978
|
-
},
|
|
1979
|
-
error: (s, e) => {
|
|
1980
|
-
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
1981
|
-
}
|
|
1982
|
-
};
|
|
1983
|
-
var cancel = (o2 = "", t2) => {
|
|
1984
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
|
|
1985
|
-
i.write(`${e}${styleText2("red", o2)}
|
|
1986
|
-
|
|
1987
|
-
`);
|
|
1988
|
-
};
|
|
1989
|
-
var intro = (o2 = "", t2) => {
|
|
1990
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
1991
|
-
i.write(`${e}${o2}
|
|
1992
|
-
`);
|
|
1993
|
-
};
|
|
1994
|
-
var outro = (o2 = "", t2) => {
|
|
1995
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
1996
|
-
${styleText2("gray", S_BAR_END)} ` : "";
|
|
1997
|
-
i.write(`${e}${o2}
|
|
1998
|
-
|
|
1999
|
-
`);
|
|
2000
|
-
};
|
|
2001
|
-
var W = (l2) => styleText2("magenta", l2);
|
|
2002
|
-
var spinner = ({
|
|
2003
|
-
indicator: l2 = "dots",
|
|
2004
|
-
onCancel: h2,
|
|
2005
|
-
output: n2 = process.stdout,
|
|
2006
|
-
cancelMessage: G,
|
|
2007
|
-
errorMessage: O,
|
|
2008
|
-
frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
|
|
2009
|
-
delay: F = unicode ? 80 : 120,
|
|
2010
|
-
signal: m2,
|
|
2011
|
-
...I
|
|
2012
|
-
} = {}) => {
|
|
2013
|
-
const u3 = isCI();
|
|
2014
|
-
let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
|
|
2015
|
-
const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
|
|
2016
|
-
const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
2017
|
-
S = e === 1, d && (a2(r2, e), S && typeof h2 == "function" && h2());
|
|
2018
|
-
}, f2 = () => g2(2), i = () => g2(1), A = () => {
|
|
2019
|
-
process.on("uncaughtExceptionMonitor", f2), process.on("unhandledRejection", f2), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g2), m2 && m2.addEventListener("abort", i);
|
|
2020
|
-
}, H = () => {
|
|
2021
|
-
process.removeListener("uncaughtExceptionMonitor", f2), process.removeListener("unhandledRejection", f2), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g2), m2 && m2.removeEventListener("abort", i);
|
|
2022
|
-
}, y = () => {
|
|
2023
|
-
if (p2 === undefined)
|
|
2024
|
-
return;
|
|
2025
|
-
u3 && n2.write(`
|
|
2026
|
-
`);
|
|
2027
|
-
const r2 = wrapAnsi(p2, x, {
|
|
2028
|
-
hard: true,
|
|
2029
|
-
trim: false
|
|
2030
|
-
}).split(`
|
|
2031
|
-
`);
|
|
2032
|
-
r2.length > 1 && n2.write(import_sisteransi2.cursor.up(r2.length - 1)), n2.write(import_sisteransi2.cursor.to(0)), n2.write(import_sisteransi2.erase.down());
|
|
2033
|
-
}, C2 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
|
|
2034
|
-
const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
|
|
2035
|
-
return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
|
|
2036
|
-
}, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
|
|
2037
|
-
d = true, M2 = block({ output: n2 }), s = C2(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
|
|
2038
|
-
`);
|
|
2039
|
-
let r2 = 0, t2 = 0;
|
|
2040
|
-
A(), T3 = setInterval(() => {
|
|
2041
|
-
if (u3 && s === p2)
|
|
2042
|
-
return;
|
|
2043
|
-
y(), p2 = s;
|
|
2044
|
-
const o2 = k(E[r2]);
|
|
2045
|
-
let v;
|
|
2046
|
-
if (u3)
|
|
2047
|
-
v = `${o2} ${s}...`;
|
|
2048
|
-
else if (l2 === "timer")
|
|
2049
|
-
v = `${o2} ${s} ${_2(w)}`;
|
|
2050
|
-
else {
|
|
2051
|
-
const B = ".".repeat(Math.floor(t2)).slice(0, 3);
|
|
2052
|
-
v = `${o2} ${s}${B}`;
|
|
2053
|
-
}
|
|
2054
|
-
const j = wrapAnsi(v, x, {
|
|
2055
|
-
hard: true,
|
|
2056
|
-
trim: false
|
|
2057
|
-
});
|
|
2058
|
-
n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
|
|
2059
|
-
}, F);
|
|
2060
|
-
}, a2 = (e = "", r2 = 0, t2 = false) => {
|
|
2061
|
-
if (!d)
|
|
2062
|
-
return;
|
|
2063
|
-
d = false, clearInterval(T3), y();
|
|
2064
|
-
const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
2065
|
-
s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
|
|
2066
|
-
`) : n2.write(`${o2} ${s}
|
|
2067
|
-
`)), H(), M2();
|
|
2068
|
-
};
|
|
2069
|
-
return {
|
|
2070
|
-
start: P2,
|
|
2071
|
-
stop: (e = "") => a2(e, 0),
|
|
2072
|
-
message: (e = "") => {
|
|
2073
|
-
s = C2(e ?? s);
|
|
2074
|
-
},
|
|
2075
|
-
cancel: (e = "") => a2(e, 1),
|
|
2076
|
-
error: (e = "") => a2(e, 2),
|
|
2077
|
-
clear: () => a2("", 0, true),
|
|
2078
|
-
get isCancelled() {
|
|
2079
|
-
return S;
|
|
2080
|
-
}
|
|
2081
|
-
};
|
|
2082
|
-
};
|
|
2083
|
-
var u3 = {
|
|
2084
|
-
light: unicodeOr("\u2500", "-"),
|
|
2085
|
-
heavy: unicodeOr("\u2501", "="),
|
|
2086
|
-
block: unicodeOr("\u2588", "#")
|
|
2087
|
-
};
|
|
2088
|
-
var SELECT_INSTRUCTIONS = [
|
|
2089
|
-
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
2090
|
-
`${styleText2("dim", "Enter:")} confirm`
|
|
2091
|
-
];
|
|
2092
|
-
var c2 = (t2, a2) => t2.includes(`
|
|
2093
|
-
`) ? t2.split(`
|
|
2094
|
-
`).map((i) => a2(i)).join(`
|
|
2095
|
-
`) : a2(t2);
|
|
2096
|
-
var select = (t2) => {
|
|
2097
|
-
const a2 = (i, m2) => {
|
|
2098
|
-
const s = i.label ?? String(i.value);
|
|
2099
|
-
switch (m2) {
|
|
2100
|
-
case "disabled":
|
|
2101
|
-
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("gray", n2))}${i.hint ? ` ${styleText2("dim", `(${i.hint ?? "disabled"})`)}` : ""}`;
|
|
2102
|
-
case "selected":
|
|
2103
|
-
return `${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
2104
|
-
case "active":
|
|
2105
|
-
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${i.hint ? ` ${styleText2("dim", `(${i.hint})`)}` : ""}`;
|
|
2106
|
-
case "cancelled":
|
|
2107
|
-
return `${c2(s, (n2) => styleText2(["strikethrough", "dim"], n2))}`;
|
|
2108
|
-
default:
|
|
2109
|
-
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
2110
|
-
}
|
|
2111
|
-
};
|
|
2112
|
-
return new a({
|
|
2113
|
-
options: t2.options,
|
|
2114
|
-
signal: t2.signal,
|
|
2115
|
-
input: t2.input,
|
|
2116
|
-
output: t2.output,
|
|
2117
|
-
initialValue: t2.initialValue,
|
|
2118
|
-
render() {
|
|
2119
|
-
const i = t2.withGuide ?? settings.withGuide, m2 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(t2.output, t2.message, s, m2), u4 = `${i ? `${styleText2("gray", S_BAR)}
|
|
2120
|
-
` : ""}${n2}
|
|
2121
|
-
`;
|
|
2122
|
-
switch (this.state) {
|
|
2123
|
-
case "submit": {
|
|
2124
|
-
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a2(this.options[this.cursor], "selected"), r2);
|
|
2125
|
-
return `${u4}${o2}`;
|
|
2126
|
-
}
|
|
2127
|
-
case "cancel": {
|
|
2128
|
-
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a2(this.options[this.cursor], "cancelled"), r2);
|
|
2129
|
-
return `${u4}${o2}${i ? `
|
|
1716
|
+
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a3(this.options[this.cursor], "cancelled"), r2);
|
|
1717
|
+
return `${u4}${o2}${i ? `
|
|
2130
1718
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
2131
1719
|
}
|
|
2132
1720
|
default: {
|
|
@@ -2140,7 +1728,7 @@ ${styleText2("gray", S_BAR)}` : ""}`;
|
|
|
2140
1728
|
maxItems: t2.maxItems,
|
|
2141
1729
|
columnPadding: r2.length,
|
|
2142
1730
|
rowPadding: o2 + b2,
|
|
2143
|
-
style: (p2, x) =>
|
|
1731
|
+
style: (p2, x) => a3(p2, p2.disabled ? "disabled" : x ? "active" : "inactive")
|
|
2144
1732
|
}).join(`
|
|
2145
1733
|
${r2}`)}
|
|
2146
1734
|
${h2}
|
|
@@ -2162,7 +1750,7 @@ var text = (t2) => new n({
|
|
|
2162
1750
|
render() {
|
|
2163
1751
|
const i2 = t2?.withGuide ?? settings.withGuide, s = `${`${i2 ? `${styleText2("gray", S_BAR)}
|
|
2164
1752
|
` : ""}${symbol(this.state)} `}${t2.message}
|
|
2165
|
-
`, c3 = t2.placeholder ? styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o2 = this.userInput ? this.userInputWithCursor : c3,
|
|
1753
|
+
`, c3 = t2.placeholder ? styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o2 = this.userInput ? this.userInputWithCursor : c3, a3 = this.value ?? "";
|
|
2166
1754
|
switch (this.state) {
|
|
2167
1755
|
case "error": {
|
|
2168
1756
|
const n2 = this.error ? ` ${styleText2("yellow", this.error)}` : "", r2 = i2 ? `${styleText2("yellow", S_BAR)} ` : "", d = i2 ? styleText2("yellow", S_BAR_END) : "";
|
|
@@ -2172,12 +1760,12 @@ ${d}${n2}
|
|
|
2172
1760
|
`;
|
|
2173
1761
|
}
|
|
2174
1762
|
case "submit": {
|
|
2175
|
-
const n2 =
|
|
1763
|
+
const n2 = a3 ? ` ${styleText2("dim", a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
2176
1764
|
return `${s}${r2}${n2}`;
|
|
2177
1765
|
}
|
|
2178
1766
|
case "cancel": {
|
|
2179
|
-
const n2 =
|
|
2180
|
-
return `${s}${r2}${n2}${
|
|
1767
|
+
const n2 = a3 ? ` ${styleText2(["strikethrough", "dim"], a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
1768
|
+
return `${s}${r2}${n2}${a3.trim() ? `
|
|
2181
1769
|
${r2}` : ""}`;
|
|
2182
1770
|
}
|
|
2183
1771
|
default: {
|
|
@@ -2188,21 +1776,577 @@ ${r2}
|
|
|
2188
1776
|
}
|
|
2189
1777
|
}
|
|
2190
1778
|
}
|
|
2191
|
-
}).prompt();
|
|
2192
|
-
|
|
2193
|
-
//
|
|
2194
|
-
var
|
|
2195
|
-
var
|
|
2196
|
-
|
|
1779
|
+
}).prompt();
|
|
1780
|
+
|
|
1781
|
+
// node_modules/citty/dist/_chunks/libs/scule.mjs
|
|
1782
|
+
var NUMBER_CHAR_RE = /\d/;
|
|
1783
|
+
var STR_SPLITTERS = [
|
|
1784
|
+
"-",
|
|
1785
|
+
"_",
|
|
1786
|
+
"/",
|
|
1787
|
+
"."
|
|
1788
|
+
];
|
|
1789
|
+
function isUppercase(char = "") {
|
|
1790
|
+
if (NUMBER_CHAR_RE.test(char))
|
|
1791
|
+
return;
|
|
1792
|
+
return char !== char.toLowerCase();
|
|
1793
|
+
}
|
|
1794
|
+
function splitByCase(str, separators) {
|
|
1795
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
1796
|
+
const parts = [];
|
|
1797
|
+
if (!str || typeof str !== "string")
|
|
1798
|
+
return parts;
|
|
1799
|
+
let buff = "";
|
|
1800
|
+
let previousUpper;
|
|
1801
|
+
let previousSplitter;
|
|
1802
|
+
for (const char of str) {
|
|
1803
|
+
const isSplitter = splitters.includes(char);
|
|
1804
|
+
if (isSplitter === true) {
|
|
1805
|
+
parts.push(buff);
|
|
1806
|
+
buff = "";
|
|
1807
|
+
previousUpper = undefined;
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
const isUpper = isUppercase(char);
|
|
1811
|
+
if (previousSplitter === false) {
|
|
1812
|
+
if (previousUpper === false && isUpper === true) {
|
|
1813
|
+
parts.push(buff);
|
|
1814
|
+
buff = char;
|
|
1815
|
+
previousUpper = isUpper;
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
1819
|
+
const lastChar = buff.at(-1);
|
|
1820
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
1821
|
+
buff = lastChar + char;
|
|
1822
|
+
previousUpper = isUpper;
|
|
1823
|
+
continue;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
buff += char;
|
|
1827
|
+
previousUpper = isUpper;
|
|
1828
|
+
previousSplitter = isSplitter;
|
|
1829
|
+
}
|
|
1830
|
+
parts.push(buff);
|
|
1831
|
+
return parts;
|
|
1832
|
+
}
|
|
1833
|
+
function upperFirst(str) {
|
|
1834
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
1835
|
+
}
|
|
1836
|
+
function lowerFirst(str) {
|
|
1837
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
1838
|
+
}
|
|
1839
|
+
function pascalCase(str, opts) {
|
|
1840
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p2) => upperFirst(opts?.normalize ? p2.toLowerCase() : p2)).join("") : "";
|
|
1841
|
+
}
|
|
1842
|
+
function camelCase(str, opts) {
|
|
1843
|
+
return lowerFirst(pascalCase(str || "", opts));
|
|
1844
|
+
}
|
|
1845
|
+
function kebabCase(str, joiner) {
|
|
1846
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p2) => p2.toLowerCase()).join(joiner ?? "-") : "";
|
|
1847
|
+
}
|
|
1848
|
+
function snakeCase(str) {
|
|
1849
|
+
return kebabCase(str || "", "_");
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
// node_modules/citty/dist/index.mjs
|
|
1853
|
+
import { parseArgs as parseArgs$1 } from "util";
|
|
1854
|
+
function toArray(val) {
|
|
1855
|
+
if (Array.isArray(val))
|
|
1856
|
+
return val;
|
|
1857
|
+
return val === undefined ? [] : [val];
|
|
1858
|
+
}
|
|
1859
|
+
function formatLineColumns(lines, linePrefix = "") {
|
|
1860
|
+
const maxLength = [];
|
|
1861
|
+
for (const line of lines)
|
|
1862
|
+
for (const [i2, element] of line.entries())
|
|
1863
|
+
maxLength[i2] = Math.max(maxLength[i2] || 0, element.length);
|
|
1864
|
+
return lines.map((l2) => l2.map((c3, i2) => linePrefix + c3[i2 === 0 ? "padStart" : "padEnd"](maxLength[i2])).join(" ")).join(`
|
|
1865
|
+
`);
|
|
1866
|
+
}
|
|
1867
|
+
function resolveValue(input) {
|
|
1868
|
+
return typeof input === "function" ? input() : input;
|
|
1869
|
+
}
|
|
1870
|
+
var CLIError = class extends Error {
|
|
1871
|
+
code;
|
|
1872
|
+
constructor(message, code) {
|
|
1873
|
+
super(message);
|
|
1874
|
+
this.name = "CLIError";
|
|
1875
|
+
this.code = code;
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
function parseRawArgs(args = [], opts = {}) {
|
|
1879
|
+
const booleans = new Set(opts.boolean || []);
|
|
1880
|
+
const strings = new Set(opts.string || []);
|
|
1881
|
+
const aliasMap = opts.alias || {};
|
|
1882
|
+
const defaults = opts.default || {};
|
|
1883
|
+
const aliasToMain = /* @__PURE__ */ new Map;
|
|
1884
|
+
const mainToAliases = /* @__PURE__ */ new Map;
|
|
1885
|
+
for (const [key, value] of Object.entries(aliasMap)) {
|
|
1886
|
+
const targets = value;
|
|
1887
|
+
for (const target of targets) {
|
|
1888
|
+
aliasToMain.set(key, target);
|
|
1889
|
+
if (!mainToAliases.has(target))
|
|
1890
|
+
mainToAliases.set(target, []);
|
|
1891
|
+
mainToAliases.get(target).push(key);
|
|
1892
|
+
aliasToMain.set(target, key);
|
|
1893
|
+
if (!mainToAliases.has(key))
|
|
1894
|
+
mainToAliases.set(key, []);
|
|
1895
|
+
mainToAliases.get(key).push(target);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
const options = {};
|
|
1899
|
+
function getType(name) {
|
|
1900
|
+
if (booleans.has(name))
|
|
1901
|
+
return "boolean";
|
|
1902
|
+
const aliases = mainToAliases.get(name) || [];
|
|
1903
|
+
for (const alias of aliases)
|
|
1904
|
+
if (booleans.has(alias))
|
|
1905
|
+
return "boolean";
|
|
1906
|
+
return "string";
|
|
1907
|
+
}
|
|
1908
|
+
function isStringType(name) {
|
|
1909
|
+
if (strings.has(name))
|
|
1910
|
+
return true;
|
|
1911
|
+
const aliases = mainToAliases.get(name) || [];
|
|
1912
|
+
for (const alias of aliases)
|
|
1913
|
+
if (strings.has(alias))
|
|
1914
|
+
return true;
|
|
1915
|
+
return false;
|
|
1916
|
+
}
|
|
1917
|
+
const allOptions = new Set([
|
|
1918
|
+
...booleans,
|
|
1919
|
+
...strings,
|
|
1920
|
+
...Object.keys(aliasMap),
|
|
1921
|
+
...Object.values(aliasMap).flat(),
|
|
1922
|
+
...Object.keys(defaults)
|
|
1923
|
+
]);
|
|
1924
|
+
for (const name of allOptions)
|
|
1925
|
+
if (!options[name])
|
|
1926
|
+
options[name] = {
|
|
1927
|
+
type: getType(name),
|
|
1928
|
+
default: defaults[name]
|
|
1929
|
+
};
|
|
1930
|
+
for (const [alias, main] of aliasToMain.entries())
|
|
1931
|
+
if (alias.length === 1 && options[main] && !options[main].short)
|
|
1932
|
+
options[main].short = alias;
|
|
1933
|
+
const processedArgs = [];
|
|
1934
|
+
const negatedFlags = {};
|
|
1935
|
+
for (let i2 = 0;i2 < args.length; i2++) {
|
|
1936
|
+
const arg = args[i2];
|
|
1937
|
+
if (arg === "--") {
|
|
1938
|
+
processedArgs.push(...args.slice(i2));
|
|
1939
|
+
break;
|
|
1940
|
+
}
|
|
1941
|
+
if (arg.startsWith("--no-")) {
|
|
1942
|
+
const flagName = arg.slice(5);
|
|
1943
|
+
negatedFlags[flagName] = true;
|
|
1944
|
+
continue;
|
|
1945
|
+
}
|
|
1946
|
+
processedArgs.push(arg);
|
|
1947
|
+
}
|
|
1948
|
+
let parsed;
|
|
1949
|
+
try {
|
|
1950
|
+
parsed = parseArgs$1({
|
|
1951
|
+
args: processedArgs,
|
|
1952
|
+
options: Object.keys(options).length > 0 ? options : undefined,
|
|
1953
|
+
allowPositionals: true,
|
|
1954
|
+
strict: false
|
|
1955
|
+
});
|
|
1956
|
+
} catch {
|
|
1957
|
+
parsed = {
|
|
1958
|
+
values: {},
|
|
1959
|
+
positionals: processedArgs
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
const out = { _: [] };
|
|
1963
|
+
out._ = parsed.positionals;
|
|
1964
|
+
for (const [key, value] of Object.entries(parsed.values)) {
|
|
1965
|
+
let coerced = value;
|
|
1966
|
+
if (getType(key) === "boolean" && typeof value === "string")
|
|
1967
|
+
coerced = value !== "false";
|
|
1968
|
+
else if (isStringType(key) && typeof value === "boolean")
|
|
1969
|
+
coerced = "";
|
|
1970
|
+
out[key] = coerced;
|
|
1971
|
+
}
|
|
1972
|
+
for (const [name] of Object.entries(negatedFlags)) {
|
|
1973
|
+
out[name] = false;
|
|
1974
|
+
const mainName = aliasToMain.get(name);
|
|
1975
|
+
if (mainName)
|
|
1976
|
+
out[mainName] = false;
|
|
1977
|
+
const aliases = mainToAliases.get(name);
|
|
1978
|
+
if (aliases)
|
|
1979
|
+
for (const alias of aliases)
|
|
1980
|
+
out[alias] = false;
|
|
1981
|
+
}
|
|
1982
|
+
for (const [alias, main] of aliasToMain.entries()) {
|
|
1983
|
+
if (out[alias] !== undefined && out[main] === undefined)
|
|
1984
|
+
out[main] = out[alias];
|
|
1985
|
+
if (out[main] !== undefined && out[alias] === undefined)
|
|
1986
|
+
out[alias] = out[main];
|
|
1987
|
+
if (out[alias] !== out[main] && defaults[main] === out[main])
|
|
1988
|
+
out[main] = out[alias];
|
|
1989
|
+
}
|
|
1990
|
+
return out;
|
|
1991
|
+
}
|
|
1992
|
+
var noColor = /* @__PURE__ */ (() => {
|
|
1993
|
+
const env = globalThis.process?.env ?? {};
|
|
1994
|
+
return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
|
|
1995
|
+
})();
|
|
1996
|
+
var _c = (c3, r2 = 39) => (t2) => noColor ? t2 : `\x1B[${c3}m${t2}\x1B[${r2}m`;
|
|
1997
|
+
var bold = /* @__PURE__ */ _c(1, 22);
|
|
1998
|
+
var cyan = /* @__PURE__ */ _c(36);
|
|
1999
|
+
var gray = /* @__PURE__ */ _c(90);
|
|
2000
|
+
var underline = /* @__PURE__ */ _c(4, 24);
|
|
2001
|
+
function parseArgs(rawArgs, argsDef) {
|
|
2002
|
+
const parseOptions = {
|
|
2003
|
+
boolean: [],
|
|
2004
|
+
string: [],
|
|
2005
|
+
alias: {},
|
|
2006
|
+
default: {}
|
|
2007
|
+
};
|
|
2008
|
+
const args = resolveArgs(argsDef);
|
|
2009
|
+
for (const arg of args) {
|
|
2010
|
+
if (arg.type === "positional")
|
|
2011
|
+
continue;
|
|
2012
|
+
if (arg.type === "string" || arg.type === "enum")
|
|
2013
|
+
parseOptions.string.push(arg.name);
|
|
2014
|
+
else if (arg.type === "boolean")
|
|
2015
|
+
parseOptions.boolean.push(arg.name);
|
|
2016
|
+
if (arg.default !== undefined)
|
|
2017
|
+
parseOptions.default[arg.name] = arg.default;
|
|
2018
|
+
if (arg.alias)
|
|
2019
|
+
parseOptions.alias[arg.name] = arg.alias;
|
|
2020
|
+
const camelName = camelCase(arg.name);
|
|
2021
|
+
const kebabName = kebabCase(arg.name);
|
|
2022
|
+
if (camelName !== arg.name || kebabName !== arg.name) {
|
|
2023
|
+
const existingAliases = toArray(parseOptions.alias[arg.name] || []);
|
|
2024
|
+
if (camelName !== arg.name && !existingAliases.includes(camelName))
|
|
2025
|
+
existingAliases.push(camelName);
|
|
2026
|
+
if (kebabName !== arg.name && !existingAliases.includes(kebabName))
|
|
2027
|
+
existingAliases.push(kebabName);
|
|
2028
|
+
if (existingAliases.length > 0)
|
|
2029
|
+
parseOptions.alias[arg.name] = existingAliases;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
2033
|
+
const [...positionalArguments] = parsed._;
|
|
2034
|
+
const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
|
|
2035
|
+
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
2036
|
+
} });
|
|
2037
|
+
for (const [, arg] of args.entries())
|
|
2038
|
+
if (arg.type === "positional") {
|
|
2039
|
+
const nextPositionalArgument = positionalArguments.shift();
|
|
2040
|
+
if (nextPositionalArgument !== undefined)
|
|
2041
|
+
parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
2042
|
+
else if (arg.default === undefined && arg.required !== false)
|
|
2043
|
+
throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
|
|
2044
|
+
else
|
|
2045
|
+
parsedArgsProxy[arg.name] = arg.default;
|
|
2046
|
+
} else if (arg.type === "enum") {
|
|
2047
|
+
const argument = parsedArgsProxy[arg.name];
|
|
2048
|
+
const options = arg.options || [];
|
|
2049
|
+
if (argument !== undefined && options.length > 0 && !options.includes(argument))
|
|
2050
|
+
throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o2) => cyan(o2)).join(", ")}.`, "EARG");
|
|
2051
|
+
} else if (arg.required && parsedArgsProxy[arg.name] === undefined)
|
|
2052
|
+
throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
2053
|
+
return parsedArgsProxy;
|
|
2054
|
+
}
|
|
2055
|
+
function resolveArgs(argsDef) {
|
|
2056
|
+
const args = [];
|
|
2057
|
+
for (const [name, argDef] of Object.entries(argsDef || {}))
|
|
2058
|
+
args.push({
|
|
2059
|
+
...argDef,
|
|
2060
|
+
name,
|
|
2061
|
+
alias: toArray(argDef.alias)
|
|
2062
|
+
});
|
|
2063
|
+
return args;
|
|
2064
|
+
}
|
|
2065
|
+
async function resolvePlugins(plugins) {
|
|
2066
|
+
return Promise.all(plugins.map((p2) => resolveValue(p2)));
|
|
2067
|
+
}
|
|
2068
|
+
function defineCommand(def) {
|
|
2069
|
+
return def;
|
|
2070
|
+
}
|
|
2071
|
+
async function runCommand(cmd, opts) {
|
|
2072
|
+
const cmdArgs = await resolveValue(cmd.args || {});
|
|
2073
|
+
const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
|
|
2074
|
+
const context = {
|
|
2075
|
+
rawArgs: opts.rawArgs,
|
|
2076
|
+
args: parsedArgs,
|
|
2077
|
+
data: opts.data,
|
|
2078
|
+
cmd
|
|
2079
|
+
};
|
|
2080
|
+
const plugins = await resolvePlugins(cmd.plugins ?? []);
|
|
2081
|
+
let result;
|
|
2082
|
+
let runError;
|
|
2083
|
+
try {
|
|
2084
|
+
for (const plugin of plugins)
|
|
2085
|
+
await plugin.setup?.(context);
|
|
2086
|
+
if (typeof cmd.setup === "function")
|
|
2087
|
+
await cmd.setup(context);
|
|
2088
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
2089
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
2090
|
+
const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
|
|
2091
|
+
const explicitName = opts.rawArgs[subCommandArgIndex];
|
|
2092
|
+
if (explicitName) {
|
|
2093
|
+
const subCommand = await _findSubCommand(subCommands, explicitName);
|
|
2094
|
+
if (!subCommand)
|
|
2095
|
+
throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
|
|
2096
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
2097
|
+
} else {
|
|
2098
|
+
const defaultSubCommand = await resolveValue(cmd.default);
|
|
2099
|
+
if (defaultSubCommand) {
|
|
2100
|
+
if (cmd.run)
|
|
2101
|
+
throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
|
|
2102
|
+
const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
|
|
2103
|
+
if (!subCommand)
|
|
2104
|
+
throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
|
|
2105
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs });
|
|
2106
|
+
} else if (!cmd.run)
|
|
2107
|
+
throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
if (typeof cmd.run === "function")
|
|
2111
|
+
result = await cmd.run(context);
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
runError = error;
|
|
2114
|
+
}
|
|
2115
|
+
const cleanupErrors = [];
|
|
2116
|
+
if (typeof cmd.cleanup === "function")
|
|
2117
|
+
try {
|
|
2118
|
+
await cmd.cleanup(context);
|
|
2119
|
+
} catch (error) {
|
|
2120
|
+
cleanupErrors.push(error);
|
|
2121
|
+
}
|
|
2122
|
+
for (const plugin of [...plugins].reverse())
|
|
2123
|
+
try {
|
|
2124
|
+
await plugin.cleanup?.(context);
|
|
2125
|
+
} catch (error) {
|
|
2126
|
+
cleanupErrors.push(error);
|
|
2127
|
+
}
|
|
2128
|
+
if (runError)
|
|
2129
|
+
throw runError;
|
|
2130
|
+
if (cleanupErrors.length === 1)
|
|
2131
|
+
throw cleanupErrors[0];
|
|
2132
|
+
if (cleanupErrors.length > 1)
|
|
2133
|
+
throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
|
|
2134
|
+
return { result };
|
|
2135
|
+
}
|
|
2136
|
+
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
2137
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
2138
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
2139
|
+
const subCommandArgIndex = findSubCommandIndex(rawArgs, await resolveValue(cmd.args || {}));
|
|
2140
|
+
const subCommandName = rawArgs[subCommandArgIndex];
|
|
2141
|
+
const subCommand = await _findSubCommand(subCommands, subCommandName);
|
|
2142
|
+
if (subCommand)
|
|
2143
|
+
return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
2144
|
+
}
|
|
2145
|
+
return [cmd, parent];
|
|
2146
|
+
}
|
|
2147
|
+
async function _findSubCommand(subCommands, name) {
|
|
2148
|
+
if (name in subCommands)
|
|
2149
|
+
return resolveValue(subCommands[name]);
|
|
2150
|
+
for (const sub of Object.values(subCommands)) {
|
|
2151
|
+
const resolved = await resolveValue(sub);
|
|
2152
|
+
const meta = await resolveValue(resolved?.meta);
|
|
2153
|
+
if (meta?.alias) {
|
|
2154
|
+
if (toArray(meta.alias).includes(name))
|
|
2155
|
+
return resolved;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
function findSubCommandIndex(rawArgs, argsDef) {
|
|
2160
|
+
for (let i2 = 0;i2 < rawArgs.length; i2++) {
|
|
2161
|
+
const arg = rawArgs[i2];
|
|
2162
|
+
if (arg === "--")
|
|
2163
|
+
return -1;
|
|
2164
|
+
if (arg.startsWith("-")) {
|
|
2165
|
+
if (!arg.includes("=") && _isValueFlag(arg, argsDef))
|
|
2166
|
+
i2++;
|
|
2167
|
+
continue;
|
|
2168
|
+
}
|
|
2169
|
+
return i2;
|
|
2170
|
+
}
|
|
2171
|
+
return -1;
|
|
2172
|
+
}
|
|
2173
|
+
function _isValueFlag(flag, argsDef) {
|
|
2174
|
+
const name = flag.replace(/^-{1,2}/, "");
|
|
2175
|
+
const normalized = camelCase(name);
|
|
2176
|
+
for (const [key, def] of Object.entries(argsDef)) {
|
|
2177
|
+
if (def.type !== "string" && def.type !== "enum")
|
|
2178
|
+
continue;
|
|
2179
|
+
if (normalized === camelCase(key))
|
|
2180
|
+
return true;
|
|
2181
|
+
if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name))
|
|
2182
|
+
return true;
|
|
2183
|
+
}
|
|
2184
|
+
return false;
|
|
2185
|
+
}
|
|
2186
|
+
async function showUsage(cmd, parent) {
|
|
2187
|
+
try {
|
|
2188
|
+
console.log(await renderUsage(cmd, parent) + `
|
|
2189
|
+
`);
|
|
2190
|
+
} catch (error) {
|
|
2191
|
+
console.error(error);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
var negativePrefixRe = /^no[-A-Z]/;
|
|
2195
|
+
async function renderUsage(cmd, parent) {
|
|
2196
|
+
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
2197
|
+
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
2198
|
+
const parentMeta = await resolveValue(parent?.meta || {});
|
|
2199
|
+
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
|
|
2200
|
+
const argLines = [];
|
|
2201
|
+
const posLines = [];
|
|
2202
|
+
const commandsLines = [];
|
|
2203
|
+
const usageLine = [];
|
|
2204
|
+
for (const arg of cmdArgs)
|
|
2205
|
+
if (arg.type === "positional") {
|
|
2206
|
+
const name = arg.name.toUpperCase();
|
|
2207
|
+
const isRequired = arg.required !== false && arg.default === undefined;
|
|
2208
|
+
posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
|
|
2209
|
+
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
2210
|
+
} else {
|
|
2211
|
+
const isRequired = arg.required === true && arg.default === undefined;
|
|
2212
|
+
const argStr = [...(arg.alias || []).map((a3) => `-${a3}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
|
|
2213
|
+
argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
|
|
2214
|
+
if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
|
|
2215
|
+
const negativeArgStr = [...(arg.alias || []).map((a3) => `--no-${a3}`), `--no-${arg.name}`].join(", ");
|
|
2216
|
+
argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
|
|
2217
|
+
}
|
|
2218
|
+
if (isRequired)
|
|
2219
|
+
usageLine.push(`--${arg.name}` + renderValueHint(arg));
|
|
2220
|
+
}
|
|
2221
|
+
if (cmd.subCommands) {
|
|
2222
|
+
const commandNames = [];
|
|
2223
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
2224
|
+
for (const [name, sub] of Object.entries(subCommands)) {
|
|
2225
|
+
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
2226
|
+
if (meta?.hidden)
|
|
2227
|
+
continue;
|
|
2228
|
+
const aliases = toArray(meta?.alias);
|
|
2229
|
+
const label = [name, ...aliases].join(", ");
|
|
2230
|
+
commandsLines.push([cyan(label), meta?.description || ""]);
|
|
2231
|
+
commandNames.push(name, ...aliases);
|
|
2232
|
+
}
|
|
2233
|
+
usageLine.push(commandNames.join("|"));
|
|
2234
|
+
}
|
|
2235
|
+
const usageLines = [];
|
|
2236
|
+
const version = cmdMeta.version || parentMeta.version;
|
|
2237
|
+
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
2238
|
+
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
2239
|
+
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
2240
|
+
if (posLines.length > 0) {
|
|
2241
|
+
usageLines.push(underline(bold("ARGUMENTS")), "");
|
|
2242
|
+
usageLines.push(formatLineColumns(posLines, " "));
|
|
2243
|
+
usageLines.push("");
|
|
2244
|
+
}
|
|
2245
|
+
if (argLines.length > 0) {
|
|
2246
|
+
usageLines.push(underline(bold("OPTIONS")), "");
|
|
2247
|
+
usageLines.push(formatLineColumns(argLines, " "));
|
|
2248
|
+
usageLines.push("");
|
|
2249
|
+
}
|
|
2250
|
+
if (commandsLines.length > 0) {
|
|
2251
|
+
usageLines.push(underline(bold("COMMANDS")), "");
|
|
2252
|
+
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
2253
|
+
usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
|
|
2254
|
+
}
|
|
2255
|
+
return usageLines.filter((l2) => typeof l2 === "string").join(`
|
|
2256
|
+
`);
|
|
2257
|
+
}
|
|
2258
|
+
function renderValueHint(arg) {
|
|
2259
|
+
const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
|
|
2260
|
+
const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
|
|
2261
|
+
if (!arg.type || arg.type === "positional" || arg.type === "boolean")
|
|
2262
|
+
return valueHint;
|
|
2263
|
+
if (arg.type === "enum" && arg.options?.length)
|
|
2264
|
+
return `=<${arg.options.join("|")}>`;
|
|
2265
|
+
return fallbackValueHint;
|
|
2266
|
+
}
|
|
2267
|
+
function renderDescription(arg, required) {
|
|
2268
|
+
const requiredHint = required ? gray("(Required)") : "";
|
|
2269
|
+
const defaultHint = arg.default === undefined ? "" : gray(`(Default: ${arg.default})`);
|
|
2270
|
+
return [
|
|
2271
|
+
arg.description,
|
|
2272
|
+
requiredHint,
|
|
2273
|
+
defaultHint
|
|
2274
|
+
].filter(Boolean).join(" ");
|
|
2275
|
+
}
|
|
2276
|
+
async function runMain(cmd, opts = {}) {
|
|
2277
|
+
const rawArgs = opts.rawArgs || process.argv.slice(2);
|
|
2278
|
+
const showUsage$1 = opts.showUsage || showUsage;
|
|
2279
|
+
try {
|
|
2280
|
+
const builtinFlags = await _resolveBuiltinFlags(cmd);
|
|
2281
|
+
if (builtinFlags.help.length > 0 && rawArgs.some((arg) => builtinFlags.help.includes(arg))) {
|
|
2282
|
+
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
2283
|
+
process.exit(0);
|
|
2284
|
+
} else if (rawArgs.length === 1 && builtinFlags.version.includes(rawArgs[0])) {
|
|
2285
|
+
const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
|
|
2286
|
+
if (!meta?.version)
|
|
2287
|
+
throw new CLIError("No version specified", "E_NO_VERSION");
|
|
2288
|
+
console.log(meta.version);
|
|
2289
|
+
} else
|
|
2290
|
+
await runCommand(cmd, { rawArgs });
|
|
2291
|
+
} catch (error) {
|
|
2292
|
+
if (error instanceof CLIError) {
|
|
2293
|
+
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
2294
|
+
console.error(error.message);
|
|
2295
|
+
} else
|
|
2296
|
+
console.error(error, `
|
|
2297
|
+
`);
|
|
2298
|
+
process.exit(1);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
async function _resolveBuiltinFlags(cmd) {
|
|
2302
|
+
const argsDef = await resolveValue(cmd.args || {});
|
|
2303
|
+
const userNames = /* @__PURE__ */ new Set;
|
|
2304
|
+
const userAliases = /* @__PURE__ */ new Set;
|
|
2305
|
+
for (const [name, def] of Object.entries(argsDef)) {
|
|
2306
|
+
userNames.add(name);
|
|
2307
|
+
for (const alias of toArray(def.alias))
|
|
2308
|
+
userAliases.add(alias);
|
|
2309
|
+
}
|
|
2197
2310
|
return {
|
|
2198
|
-
|
|
2199
|
-
|
|
2311
|
+
help: _getBuiltinFlags("help", "h", userNames, userAliases),
|
|
2312
|
+
version: _getBuiltinFlags("version", "v", userNames, userAliases)
|
|
2200
2313
|
};
|
|
2201
2314
|
}
|
|
2315
|
+
function _getBuiltinFlags(long, short, userNames, userAliases) {
|
|
2316
|
+
if (userNames.has(long) || userAliases.has(long))
|
|
2317
|
+
return [];
|
|
2318
|
+
if (userNames.has(short) || userAliases.has(short))
|
|
2319
|
+
return [`--${long}`];
|
|
2320
|
+
return [`--${long}`, `-${short}`];
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
// src/lib/branches.ts
|
|
2324
|
+
function parseDefaultBranch(originHead) {
|
|
2325
|
+
const trimmed = originHead.trim();
|
|
2326
|
+
if (!trimmed)
|
|
2327
|
+
return null;
|
|
2328
|
+
return trimmed.replace(/^origin\//, "");
|
|
2329
|
+
}
|
|
2330
|
+
function parseBranches(raw) {
|
|
2331
|
+
return raw.split(`
|
|
2332
|
+
`).map((branch) => branch.trim()).filter(Boolean);
|
|
2333
|
+
}
|
|
2334
|
+
function deletableBranches(all, protectedBranches) {
|
|
2335
|
+
const kept = new Set(protectedBranches.filter(Boolean));
|
|
2336
|
+
return all.filter((branch) => !kept.has(branch));
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// src/lib/errors.ts
|
|
2340
|
+
function errorMessage(error) {
|
|
2341
|
+
return error instanceof Error ? error.message : String(error);
|
|
2342
|
+
}
|
|
2202
2343
|
|
|
2203
2344
|
// src/lib/git.ts
|
|
2345
|
+
import { readdir } from "fs/promises";
|
|
2346
|
+
import { join } from "path";
|
|
2204
2347
|
var {$ } = globalThis.Bun;
|
|
2205
2348
|
var UPSTREAM_REF = "@{upstream}";
|
|
2349
|
+
var BRANCH_FORMAT = "%(refname:short)";
|
|
2206
2350
|
async function stageAll() {
|
|
2207
2351
|
await $`git add -A`.quiet();
|
|
2208
2352
|
}
|
|
@@ -2225,6 +2369,234 @@ async function push() {
|
|
|
2225
2369
|
async function pushSetUpstream(branch) {
|
|
2226
2370
|
await $`git push -u origin ${branch}`.quiet();
|
|
2227
2371
|
}
|
|
2372
|
+
async function findGitRepos(start) {
|
|
2373
|
+
const repos = [];
|
|
2374
|
+
await collectRepos(start, repos);
|
|
2375
|
+
return repos.sort();
|
|
2376
|
+
}
|
|
2377
|
+
async function collectRepos(dir, repos) {
|
|
2378
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => null);
|
|
2379
|
+
if (!entries)
|
|
2380
|
+
return;
|
|
2381
|
+
if (entries.some((entry) => entry.name === ".git")) {
|
|
2382
|
+
repos.push(dir);
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
const subdirs = entries.filter((entry) => entry.isDirectory() && entry.name !== "node_modules");
|
|
2386
|
+
await Promise.all(subdirs.map((entry) => collectRepos(join(dir, entry.name), repos)));
|
|
2387
|
+
}
|
|
2388
|
+
async function fetchPrune(repo) {
|
|
2389
|
+
await $`git fetch --prune`.cwd(repo).quiet();
|
|
2390
|
+
}
|
|
2391
|
+
async function defaultBranch(repo) {
|
|
2392
|
+
const result = await $`git symbolic-ref --quiet --short refs/remotes/origin/HEAD`.cwd(repo).nothrow().quiet();
|
|
2393
|
+
return result.exitCode === 0 ? parseDefaultBranch(result.text()) : null;
|
|
2394
|
+
}
|
|
2395
|
+
async function currentBranchAt(repo) {
|
|
2396
|
+
const result = await $`git symbolic-ref --quiet --short HEAD`.cwd(repo).nothrow().quiet();
|
|
2397
|
+
return result.exitCode === 0 ? result.text().trim() : null;
|
|
2398
|
+
}
|
|
2399
|
+
async function localBranches(repo) {
|
|
2400
|
+
return parseBranches(await $`git branch --format=${BRANCH_FORMAT}`.cwd(repo).quiet().text());
|
|
2401
|
+
}
|
|
2402
|
+
async function switchBranch(repo, branch) {
|
|
2403
|
+
await $`git switch ${branch}`.cwd(repo).quiet();
|
|
2404
|
+
}
|
|
2405
|
+
async function deleteBranch(repo, branch) {
|
|
2406
|
+
await $`git branch -D ${branch}`.cwd(repo).quiet();
|
|
2407
|
+
}
|
|
2408
|
+
async function pull(repo) {
|
|
2409
|
+
await $`git pull`.cwd(repo).quiet();
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
// src/commands/cleanup.ts
|
|
2413
|
+
var cleanupCommand = defineCommand({
|
|
2414
|
+
meta: {
|
|
2415
|
+
name: "cleanup",
|
|
2416
|
+
description: "Prune every git repo under a path, then delete stale local branches."
|
|
2417
|
+
},
|
|
2418
|
+
args: {
|
|
2419
|
+
path: {
|
|
2420
|
+
type: "positional",
|
|
2421
|
+
required: false,
|
|
2422
|
+
default: ".",
|
|
2423
|
+
description: "Directory to scan for git repos (recursively)."
|
|
2424
|
+
},
|
|
2425
|
+
stay: {
|
|
2426
|
+
type: "boolean",
|
|
2427
|
+
alias: "s",
|
|
2428
|
+
description: "Stay on the current branch instead of switching to the default."
|
|
2429
|
+
},
|
|
2430
|
+
pull: {
|
|
2431
|
+
type: "boolean",
|
|
2432
|
+
alias: "p",
|
|
2433
|
+
description: "Pull the checked-out branch after cleanup without asking."
|
|
2434
|
+
},
|
|
2435
|
+
yes: {
|
|
2436
|
+
type: "boolean",
|
|
2437
|
+
alias: "y",
|
|
2438
|
+
description: "Non-interactive: switch to default and delete every other local branch."
|
|
2439
|
+
}
|
|
2440
|
+
},
|
|
2441
|
+
async run({ args }) {
|
|
2442
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY) && !args.yes;
|
|
2443
|
+
const options = { stay: Boolean(args.stay), pull: Boolean(args.pull) };
|
|
2444
|
+
const path = args.path || ".";
|
|
2445
|
+
if (interactive)
|
|
2446
|
+
intro("zapdev cleanup");
|
|
2447
|
+
const repos = await findGitRepos(path);
|
|
2448
|
+
if (repos.length === 0) {
|
|
2449
|
+
log.warn(`No git repository found under ${path}.`);
|
|
2450
|
+
if (interactive)
|
|
2451
|
+
outro("Nothing to do.");
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
for (const repo of repos) {
|
|
2455
|
+
const cancelled = await cleanupRepo(repo, options, interactive);
|
|
2456
|
+
if (cancelled) {
|
|
2457
|
+
cancel("Cancelled.");
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
if (interactive)
|
|
2462
|
+
outro(`Done (${repos.length} repo${repos.length > 1 ? "s" : ""}).`);
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2465
|
+
async function cleanupRepo(repo, options, interactive) {
|
|
2466
|
+
log.step(`Cleaning ${repo}`);
|
|
2467
|
+
const fetchLoader = interactive ? spinner() : undefined;
|
|
2468
|
+
fetchLoader?.start("Fetching + pruning\u2026");
|
|
2469
|
+
try {
|
|
2470
|
+
await fetchPrune(repo);
|
|
2471
|
+
fetchLoader?.stop("Fetched + pruned");
|
|
2472
|
+
} catch (error) {
|
|
2473
|
+
fetchLoader?.error("Fetch failed");
|
|
2474
|
+
log.warn(` Fetch failed, continuing: ${errorMessage(error)}`);
|
|
2475
|
+
}
|
|
2476
|
+
const base = await defaultBranch(repo);
|
|
2477
|
+
if (!base) {
|
|
2478
|
+
log.warn(" Skipped: no origin/HEAD.");
|
|
2479
|
+
return false;
|
|
2480
|
+
}
|
|
2481
|
+
const current = await currentBranchAt(repo);
|
|
2482
|
+
let endBranch = base;
|
|
2483
|
+
if (current && current !== base) {
|
|
2484
|
+
if (options.stay) {
|
|
2485
|
+
endBranch = current;
|
|
2486
|
+
} else if (interactive) {
|
|
2487
|
+
const choice = await select({
|
|
2488
|
+
message: "After cleanup, be on:",
|
|
2489
|
+
initialValue: base,
|
|
2490
|
+
options: [
|
|
2491
|
+
{ value: base, label: `Switch to ${base}` },
|
|
2492
|
+
{ value: current, label: `Stay on ${current} (keep it)` }
|
|
2493
|
+
]
|
|
2494
|
+
});
|
|
2495
|
+
if (isCancel(choice))
|
|
2496
|
+
return true;
|
|
2497
|
+
endBranch = choice;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
if (current !== endBranch) {
|
|
2501
|
+
try {
|
|
2502
|
+
await switchBranch(repo, endBranch);
|
|
2503
|
+
} catch (error) {
|
|
2504
|
+
log.error(` Could not switch to ${endBranch}: ${errorMessage(error)}`);
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
const candidates = deletableBranches(await localBranches(repo), [base, endBranch]);
|
|
2509
|
+
if (candidates.length === 0) {
|
|
2510
|
+
log.info(" No branch to delete.");
|
|
2511
|
+
} else {
|
|
2512
|
+
let toDelete = candidates;
|
|
2513
|
+
if (interactive) {
|
|
2514
|
+
const selected = await multiselect({
|
|
2515
|
+
message: "Branches to delete",
|
|
2516
|
+
options: candidates.map((branch) => ({ value: branch, label: branch })),
|
|
2517
|
+
required: false
|
|
2518
|
+
});
|
|
2519
|
+
if (isCancel(selected))
|
|
2520
|
+
return true;
|
|
2521
|
+
toDelete = selected;
|
|
2522
|
+
}
|
|
2523
|
+
let deleted = 0;
|
|
2524
|
+
for (const branch of toDelete) {
|
|
2525
|
+
try {
|
|
2526
|
+
await deleteBranch(repo, branch);
|
|
2527
|
+
deleted += 1;
|
|
2528
|
+
} catch (error) {
|
|
2529
|
+
log.error(` Could not delete ${branch}: ${errorMessage(error)}`);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
if (deleted > 0)
|
|
2533
|
+
log.success(` Deleted ${deleted} branch${deleted > 1 ? "es" : ""}.`);
|
|
2534
|
+
}
|
|
2535
|
+
let shouldPull = options.pull;
|
|
2536
|
+
if (!shouldPull && interactive) {
|
|
2537
|
+
const answer = await confirm({ message: `Pull ${endBranch}?`, initialValue: false });
|
|
2538
|
+
if (isCancel(answer))
|
|
2539
|
+
return true;
|
|
2540
|
+
shouldPull = answer;
|
|
2541
|
+
}
|
|
2542
|
+
if (shouldPull) {
|
|
2543
|
+
const pullLoader = interactive ? spinner() : undefined;
|
|
2544
|
+
pullLoader?.start(`Pulling ${endBranch}\u2026`);
|
|
2545
|
+
try {
|
|
2546
|
+
await pull(repo);
|
|
2547
|
+
pullLoader?.stop(`\u2713 Pulled ${endBranch}`);
|
|
2548
|
+
} catch (error) {
|
|
2549
|
+
pullLoader?.error("Pull failed");
|
|
2550
|
+
log.error(` Pull failed: ${errorMessage(error)}`);
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
return false;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
// src/types/commit.ts
|
|
2557
|
+
var COMMIT_TYPES = [
|
|
2558
|
+
"feat",
|
|
2559
|
+
"fix",
|
|
2560
|
+
"chore",
|
|
2561
|
+
"docs",
|
|
2562
|
+
"style",
|
|
2563
|
+
"refactor",
|
|
2564
|
+
"perf",
|
|
2565
|
+
"test",
|
|
2566
|
+
"build",
|
|
2567
|
+
"ci",
|
|
2568
|
+
"revert"
|
|
2569
|
+
];
|
|
2570
|
+
|
|
2571
|
+
// src/lib/commit-message.ts
|
|
2572
|
+
function normalizeCommitType(input) {
|
|
2573
|
+
const normalized = input.trim().toLowerCase();
|
|
2574
|
+
return COMMIT_TYPES.includes(normalized) ? normalized : null;
|
|
2575
|
+
}
|
|
2576
|
+
function applyCommitType(systemPrompt, type) {
|
|
2577
|
+
return `${systemPrompt}
|
|
2578
|
+
|
|
2579
|
+
The type MUST be exactly "${type}".`;
|
|
2580
|
+
}
|
|
2581
|
+
var MAX_DIFF_CHARS = 12000;
|
|
2582
|
+
function truncateDiff(diff, max = MAX_DIFF_CHARS) {
|
|
2583
|
+
return diff.length > max ? diff.slice(0, max) : diff;
|
|
2584
|
+
}
|
|
2585
|
+
function sanitizeCommitMessage(raw) {
|
|
2586
|
+
const firstLine = raw.split(`
|
|
2587
|
+
`, 1)[0] ?? "";
|
|
2588
|
+
return firstLine.replace(/[`"]/g, "").trim();
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
// src/lib/config.ts
|
|
2592
|
+
var DEFAULT_OLLAMA_URL = "http://localhost:11434";
|
|
2593
|
+
var DEFAULT_MODEL = "deepseek-v4-flash:cloud";
|
|
2594
|
+
function resolveConfig(env = process.env, overrides = {}) {
|
|
2595
|
+
return {
|
|
2596
|
+
ollamaUrl: overrides.ollamaUrl ?? env.OLLAMA_URL ?? DEFAULT_OLLAMA_URL,
|
|
2597
|
+
model: overrides.model ?? env.OLLAMA_MODEL ?? DEFAULT_MODEL
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2228
2600
|
|
|
2229
2601
|
// node_modules/ollama/dist/index.mjs
|
|
2230
2602
|
import fs, { promises } from "fs";
|
|
@@ -3183,35 +3555,37 @@ class Ollama2 extends Ollama$1 {
|
|
|
3183
3555
|
}
|
|
3184
3556
|
var index = new Ollama2;
|
|
3185
3557
|
|
|
3186
|
-
// src/
|
|
3187
|
-
var
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3558
|
+
// src/prompts/commit-message.md
|
|
3559
|
+
var commit_message_default = `You are zapdev, a CLI tool that creates commits quickly and reliably.
|
|
3560
|
+
|
|
3561
|
+
Generate ONE commit message in Conventional Commits format.
|
|
3562
|
+
A single line: imperative, English, \u226472 chars.
|
|
3563
|
+
|
|
3564
|
+
Strictly follow this format:
|
|
3565
|
+
|
|
3566
|
+
\`\`\`text
|
|
3567
|
+
type(scope): description
|
|
3568
|
+
\`\`\`
|
|
3569
|
+
|
|
3570
|
+
Reply ONLY with the message, no backticks, no quotes, no explanation.
|
|
3571
|
+
`;
|
|
3572
|
+
|
|
3573
|
+
// src/prompts/index.ts
|
|
3574
|
+
var COMMIT_SYSTEM_PROMPT = commit_message_default.trim();
|
|
3202
3575
|
|
|
3203
3576
|
// src/lib/ollama.ts
|
|
3204
3577
|
var REQUEST_TIMEOUT_MS = 25000;
|
|
3205
3578
|
var fetchWithTimeout = Object.assign((input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) }), { preconnect: fetch.preconnect });
|
|
3206
|
-
async function generateCommitMessage(diff, config) {
|
|
3579
|
+
async function generateCommitMessage(diff, config, type) {
|
|
3207
3580
|
const client = new Ollama2({ host: config.ollamaUrl, fetch: fetchWithTimeout });
|
|
3581
|
+
const systemPrompt = type ? applyCommitType(COMMIT_SYSTEM_PROMPT, type) : COMMIT_SYSTEM_PROMPT;
|
|
3208
3582
|
const response = await client.chat({
|
|
3209
3583
|
model: config.model,
|
|
3210
3584
|
stream: false,
|
|
3211
3585
|
keep_alive: "30m",
|
|
3212
3586
|
options: { temperature: 0.2 },
|
|
3213
3587
|
messages: [
|
|
3214
|
-
{ role: "system", content:
|
|
3588
|
+
{ role: "system", content: systemPrompt },
|
|
3215
3589
|
{ role: "user", content: truncateDiff(diff) }
|
|
3216
3590
|
]
|
|
3217
3591
|
});
|
|
@@ -3230,6 +3604,11 @@ var commitCommand = defineCommand({
|
|
|
3230
3604
|
alias: "m",
|
|
3231
3605
|
description: "Override the Ollama model (defaults to $OLLAMA_MODEL)."
|
|
3232
3606
|
},
|
|
3607
|
+
type: {
|
|
3608
|
+
type: "string",
|
|
3609
|
+
alias: "t",
|
|
3610
|
+
description: `Force the Conventional Commits type (${COMMIT_TYPES.join(", ")}).`
|
|
3611
|
+
},
|
|
3233
3612
|
push: {
|
|
3234
3613
|
type: "boolean",
|
|
3235
3614
|
alias: "p",
|
|
@@ -3244,6 +3623,12 @@ var commitCommand = defineCommand({
|
|
|
3244
3623
|
async run({ args }) {
|
|
3245
3624
|
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
3246
3625
|
const config = resolveConfig(process.env, args.model ? { model: args.model } : {});
|
|
3626
|
+
const type = args.type ? normalizeCommitType(args.type) : undefined;
|
|
3627
|
+
if (type === null) {
|
|
3628
|
+
log.error(`Invalid type "${args.type}". Valid types: ${COMMIT_TYPES.join(", ")}.`);
|
|
3629
|
+
process.exitCode = 1;
|
|
3630
|
+
return;
|
|
3631
|
+
}
|
|
3247
3632
|
if (interactive)
|
|
3248
3633
|
intro("zapdev commit");
|
|
3249
3634
|
await stageAll();
|
|
@@ -3258,7 +3643,7 @@ var commitCommand = defineCommand({
|
|
|
3258
3643
|
loader?.start("Generating commit message\u2026");
|
|
3259
3644
|
let message;
|
|
3260
3645
|
try {
|
|
3261
|
-
message = await generateCommitMessage(diff, config);
|
|
3646
|
+
message = await generateCommitMessage(diff, config, type);
|
|
3262
3647
|
} catch (error) {
|
|
3263
3648
|
loader?.error("Generation failed");
|
|
3264
3649
|
log.error(`Generation failed (machine unreachable?): ${errorMessage(error)}`);
|
|
@@ -3336,20 +3721,42 @@ var commitCommand = defineCommand({
|
|
|
3336
3721
|
outro("Done.");
|
|
3337
3722
|
}
|
|
3338
3723
|
});
|
|
3339
|
-
function errorMessage(error) {
|
|
3340
|
-
return error instanceof Error ? error.message : String(error);
|
|
3341
|
-
}
|
|
3342
3724
|
|
|
3343
3725
|
// src/index.ts
|
|
3726
|
+
var commands = {
|
|
3727
|
+
commit: commitCommand,
|
|
3728
|
+
cleanup: cleanupCommand
|
|
3729
|
+
};
|
|
3730
|
+
var MENU = {
|
|
3731
|
+
commit: "Stage all changes and commit with an AI-generated message",
|
|
3732
|
+
cleanup: "Prune repos and delete stale local branches"
|
|
3733
|
+
};
|
|
3734
|
+
var menuOptions = Object.keys(MENU).map((value) => ({
|
|
3735
|
+
value,
|
|
3736
|
+
label: value,
|
|
3737
|
+
hint: MENU[value]
|
|
3738
|
+
}));
|
|
3344
3739
|
var main = defineCommand({
|
|
3345
3740
|
meta: {
|
|
3346
3741
|
name: "zapdev",
|
|
3347
3742
|
version: "0.1.0",
|
|
3348
3743
|
description: "Fast, precise git chores from your terminal."
|
|
3349
3744
|
},
|
|
3350
|
-
subCommands:
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3745
|
+
subCommands: commands,
|
|
3746
|
+
async run({ args, cmd }) {
|
|
3747
|
+
const selected = args._[0];
|
|
3748
|
+
if (selected && selected in commands)
|
|
3749
|
+
return;
|
|
3750
|
+
if (!(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
3751
|
+
await showUsage(cmd);
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
const choice = await select({ message: "Which command?", options: menuOptions });
|
|
3755
|
+
if (isCancel(choice)) {
|
|
3756
|
+
cancel("Cancelled.");
|
|
3757
|
+
return;
|
|
3758
|
+
}
|
|
3759
|
+
await runCommand(commands[choice], { rawArgs: [] });
|
|
3760
|
+
}
|
|
3354
3761
|
});
|
|
3355
3762
|
await runMain(main);
|