@reliverse/rempts 1.7.52 → 1.7.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/libs/animate/animate-mod.d.ts +14 -0
- package/bin/libs/animate/animate-mod.js +60 -0
- package/bin/libs/anykey/anykey-mod.d.ts +12 -0
- package/bin/libs/anykey/anykey-mod.js +125 -0
- package/bin/libs/cancel/cancel.d.ts +45 -0
- package/bin/libs/cancel/cancel.js +72 -0
- package/bin/libs/confirm/confirm-alias.d.ts +2 -0
- package/bin/libs/confirm/confirm-alias.js +2 -0
- package/bin/libs/confirm/confirm-mod.d.ts +5 -0
- package/bin/libs/confirm/confirm-mod.js +179 -0
- package/bin/libs/date/date.d.ts +2 -0
- package/bin/libs/date/date.js +214 -0
- package/bin/libs/editor/editor-mod.d.ts +25 -0
- package/bin/libs/editor/editor-mod.js +1133 -0
- package/bin/libs/figures/figures-mod.d.ts +461 -0
- package/bin/libs/figures/figures-mod.js +285 -0
- package/bin/libs/group/group-mod.d.ts +33 -0
- package/bin/libs/group/group-mod.js +89 -0
- package/bin/libs/input/input-alias.d.ts +5 -0
- package/bin/libs/input/input-alias.js +4 -0
- package/bin/libs/input/input-mod.d.ts +16 -0
- package/bin/libs/input/input-mod.js +372 -0
- package/bin/libs/intro/intro-alias.d.ts +3 -0
- package/bin/libs/intro/intro-alias.js +3 -0
- package/bin/libs/intro/intro-mod.d.ts +20 -0
- package/bin/libs/intro/intro-mod.js +77 -0
- package/bin/libs/launcher/command-runner.d.ts +31 -0
- package/bin/libs/launcher/command-runner.js +229 -0
- package/bin/libs/launcher/launcher-alias.d.ts +2 -0
- package/bin/libs/launcher/launcher-alias.js +2 -0
- package/bin/libs/launcher/launcher-mod.d.ts +66 -0
- package/bin/libs/launcher/launcher-mod.js +983 -0
- package/bin/libs/launcher/launcher-types.d.ts +176 -0
- package/bin/libs/launcher/launcher-types.js +0 -0
- package/bin/libs/log/log-alias.d.ts +1 -0
- package/bin/libs/log/log-alias.js +2 -0
- package/bin/libs/msg-fmt/colors.d.ts +30 -0
- package/bin/libs/msg-fmt/colors.js +42 -0
- package/bin/libs/msg-fmt/logger.d.ts +17 -0
- package/bin/libs/msg-fmt/logger.js +103 -0
- package/bin/libs/msg-fmt/mapping.d.ts +3 -0
- package/bin/libs/msg-fmt/mapping.js +41 -0
- package/bin/libs/msg-fmt/messages.d.ts +35 -0
- package/bin/libs/msg-fmt/messages.js +305 -0
- package/bin/libs/msg-fmt/terminal.d.ts +15 -0
- package/bin/libs/msg-fmt/terminal.js +60 -0
- package/bin/libs/msg-fmt/variants.d.ts +11 -0
- package/bin/libs/msg-fmt/variants.js +52 -0
- package/bin/libs/multiselect/multiselect-alias.d.ts +2 -0
- package/bin/libs/multiselect/multiselect-alias.js +2 -0
- package/bin/libs/multiselect/multiselect-prompt.d.ts +2 -0
- package/bin/libs/multiselect/multiselect-prompt.js +340 -0
- package/bin/libs/next-steps/next-steps.d.ts +13 -0
- package/bin/libs/next-steps/next-steps.js +24 -0
- package/bin/libs/number/number-mod.d.ts +28 -0
- package/bin/libs/number/number-mod.js +194 -0
- package/bin/libs/outro/outro-alias.d.ts +3 -0
- package/bin/libs/outro/outro-alias.js +3 -0
- package/bin/libs/outro/outro-mod.d.ts +8 -0
- package/bin/libs/outro/outro-mod.js +55 -0
- package/bin/libs/reliarg/reliarg-mod.d.ts +76 -0
- package/bin/libs/reliarg/reliarg-mod.js +276 -0
- package/bin/libs/results/results.d.ts +7 -0
- package/bin/libs/results/results.js +27 -0
- package/bin/libs/select/nummultiselect-prompt.d.ts +6 -0
- package/bin/libs/select/nummultiselect-prompt.js +101 -0
- package/bin/libs/select/numselect-prompt.d.ts +7 -0
- package/bin/libs/select/numselect-prompt.js +111 -0
- package/bin/libs/select/select-alias.d.ts +9 -0
- package/bin/libs/select/select-alias.js +9 -0
- package/bin/libs/select/select-prompt.d.ts +5 -0
- package/bin/libs/select/select-prompt.js +308 -0
- package/bin/libs/select/toggle-prompt.d.ts +5 -0
- package/bin/libs/select/toggle-prompt.js +207 -0
- package/bin/libs/spinner/spinner-alias.d.ts +2 -0
- package/bin/libs/spinner/spinner-alias.js +2 -0
- package/bin/libs/spinner/spinner-mod.d.ts +106 -0
- package/bin/libs/spinner/spinner-mod.js +255 -0
- package/bin/libs/task/progress.d.ts +2 -0
- package/bin/libs/task/progress.js +57 -0
- package/bin/libs/task/task-spin.d.ts +15 -0
- package/bin/libs/task/task-spin.js +106 -0
- package/bin/libs/utils/colorize.d.ts +2 -0
- package/bin/libs/utils/colorize.js +122 -0
- package/bin/libs/utils/errors.d.ts +1 -0
- package/bin/libs/utils/errors.js +17 -0
- package/bin/libs/utils/prevent.d.ts +8 -0
- package/bin/libs/utils/prevent.js +62 -0
- package/bin/libs/utils/prompt-end.d.ts +8 -0
- package/bin/libs/utils/prompt-end.js +34 -0
- package/bin/libs/utils/stream-text.d.ts +18 -0
- package/bin/libs/utils/stream-text.js +138 -0
- package/bin/libs/utils/system.d.ts +6 -0
- package/bin/libs/utils/system.js +7 -0
- package/bin/libs/utils/validate.d.ts +21 -0
- package/bin/libs/utils/validate.js +17 -0
- package/bin/libs/visual/visual-mod.d.ts +6 -0
- package/bin/libs/visual/visual-mod.js +13 -0
- package/bin/mod.d.ts +53 -0
- package/bin/mod.js +107 -0
- package/bin/types.d.ts +371 -0
- package/bin/types.js +0 -0
- package/package.json +34 -59
- package/dist-npm/bin/mod.d.mts +0 -1753
- package/dist-npm/bin/mod.mjs +0 -6779
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import readline from "node:readline/promises";
|
|
2
|
+
import { re } from "@reliverse/relico";
|
|
3
|
+
import { isUnicodeSupported } from "@reliverse/runtime";
|
|
4
|
+
import { bar, msg, msgUndoAll } from "../msg-fmt/messages.js";
|
|
5
|
+
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
6
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
7
|
+
import { streamText } from "../utils/stream-text.js";
|
|
8
|
+
const unicode = isUnicodeSupported();
|
|
9
|
+
const S_MASK = unicode ? "\u258B" : "*";
|
|
10
|
+
function getMaskChar(customMask) {
|
|
11
|
+
if (!unicode) return "*";
|
|
12
|
+
return customMask ?? S_MASK;
|
|
13
|
+
}
|
|
14
|
+
async function ask(terminal, prompt, mode, mask) {
|
|
15
|
+
if (mode === "password") {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
let buffer = "";
|
|
18
|
+
const maskChar = getMaskChar(mask);
|
|
19
|
+
process.stdout.write(prompt);
|
|
20
|
+
const onData = (data) => {
|
|
21
|
+
const str = data.toString("utf-8");
|
|
22
|
+
for (const char of str) {
|
|
23
|
+
if (char === "\n" || char === "\r") {
|
|
24
|
+
process.stdout.write("\n");
|
|
25
|
+
cleanup();
|
|
26
|
+
resolve(buffer);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (char === "") {
|
|
30
|
+
cleanup();
|
|
31
|
+
resolve(null);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (char === "\x7F" || char === "\b") {
|
|
35
|
+
if (buffer.length > 0) {
|
|
36
|
+
buffer = buffer.slice(0, -1);
|
|
37
|
+
}
|
|
38
|
+
redrawPrompt(buffer, prompt);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
buffer += char;
|
|
42
|
+
redrawPrompt(buffer, prompt);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
process.stdin.on("data", onData);
|
|
46
|
+
const cleanup = () => {
|
|
47
|
+
process.stdin.removeListener("data", onData);
|
|
48
|
+
};
|
|
49
|
+
const redrawPrompt = (maskedBuffer, textPrompt) => {
|
|
50
|
+
process.stdout.clearLine(0);
|
|
51
|
+
process.stdout.cursorTo(0);
|
|
52
|
+
process.stdout.write(textPrompt + maskChar.repeat(maskedBuffer.length));
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return terminal.question(prompt);
|
|
57
|
+
}
|
|
58
|
+
function renderPromptUI(params) {
|
|
59
|
+
const {
|
|
60
|
+
title,
|
|
61
|
+
hint = "",
|
|
62
|
+
hintPlaceholderColor = "blue",
|
|
63
|
+
content = "",
|
|
64
|
+
contentColor = "dim",
|
|
65
|
+
contentTypography = "italic",
|
|
66
|
+
contentVariant = "none",
|
|
67
|
+
titleColor = "cyan",
|
|
68
|
+
titleTypography = "none",
|
|
69
|
+
titleVariant = "none",
|
|
70
|
+
borderColor = "dim",
|
|
71
|
+
placeholder = "",
|
|
72
|
+
userInput,
|
|
73
|
+
errorMessage,
|
|
74
|
+
symbol = "step_active",
|
|
75
|
+
customSymbol = "",
|
|
76
|
+
symbolColor = "cyan",
|
|
77
|
+
shouldStream = false,
|
|
78
|
+
streamDelay = 30
|
|
79
|
+
} = params;
|
|
80
|
+
const type = errorMessage !== "" ? "M_ERROR" : "M_GENERAL";
|
|
81
|
+
if (shouldStream) {
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
|
+
msg({
|
|
84
|
+
type,
|
|
85
|
+
title: "",
|
|
86
|
+
titleColor,
|
|
87
|
+
titleTypography,
|
|
88
|
+
titleVariant,
|
|
89
|
+
content: "",
|
|
90
|
+
contentColor,
|
|
91
|
+
contentTypography,
|
|
92
|
+
contentVariant,
|
|
93
|
+
borderColor,
|
|
94
|
+
hint,
|
|
95
|
+
hintPlaceholderColor,
|
|
96
|
+
placeholder: userInput === "" ? placeholder : "",
|
|
97
|
+
errorMessage,
|
|
98
|
+
symbol,
|
|
99
|
+
customSymbol,
|
|
100
|
+
symbolColor
|
|
101
|
+
});
|
|
102
|
+
void streamText({
|
|
103
|
+
text: title || "",
|
|
104
|
+
delay: streamDelay,
|
|
105
|
+
color: titleColor,
|
|
106
|
+
newline: false
|
|
107
|
+
}).then(async () => {
|
|
108
|
+
msgUndoAll();
|
|
109
|
+
msg({
|
|
110
|
+
type,
|
|
111
|
+
...title !== void 0 && { title },
|
|
112
|
+
titleColor,
|
|
113
|
+
titleTypography,
|
|
114
|
+
titleVariant,
|
|
115
|
+
content: "",
|
|
116
|
+
contentColor,
|
|
117
|
+
contentTypography,
|
|
118
|
+
contentVariant,
|
|
119
|
+
borderColor,
|
|
120
|
+
hint,
|
|
121
|
+
hintPlaceholderColor,
|
|
122
|
+
placeholder: userInput === "" ? placeholder : "",
|
|
123
|
+
errorMessage,
|
|
124
|
+
symbol,
|
|
125
|
+
customSymbol,
|
|
126
|
+
symbolColor
|
|
127
|
+
});
|
|
128
|
+
if (content) {
|
|
129
|
+
await streamText({
|
|
130
|
+
text: content,
|
|
131
|
+
delay: streamDelay,
|
|
132
|
+
color: contentColor,
|
|
133
|
+
newline: false
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
msgUndoAll();
|
|
137
|
+
deleteLastLine();
|
|
138
|
+
msg({
|
|
139
|
+
type,
|
|
140
|
+
...title !== void 0 && { title },
|
|
141
|
+
titleColor,
|
|
142
|
+
titleTypography,
|
|
143
|
+
titleVariant,
|
|
144
|
+
content,
|
|
145
|
+
contentColor,
|
|
146
|
+
contentTypography,
|
|
147
|
+
contentVariant,
|
|
148
|
+
borderColor,
|
|
149
|
+
hint,
|
|
150
|
+
hintPlaceholderColor,
|
|
151
|
+
placeholder: userInput === "" ? placeholder : "",
|
|
152
|
+
errorMessage,
|
|
153
|
+
symbol,
|
|
154
|
+
customSymbol,
|
|
155
|
+
symbolColor
|
|
156
|
+
});
|
|
157
|
+
resolve();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
msg({
|
|
162
|
+
type,
|
|
163
|
+
...title !== void 0 && { title },
|
|
164
|
+
titleColor,
|
|
165
|
+
titleTypography,
|
|
166
|
+
titleVariant,
|
|
167
|
+
content,
|
|
168
|
+
contentColor,
|
|
169
|
+
contentTypography,
|
|
170
|
+
contentVariant,
|
|
171
|
+
borderColor,
|
|
172
|
+
hint,
|
|
173
|
+
hintPlaceholderColor,
|
|
174
|
+
placeholder: userInput === "" ? placeholder : "",
|
|
175
|
+
errorMessage,
|
|
176
|
+
symbol,
|
|
177
|
+
customSymbol,
|
|
178
|
+
symbolColor
|
|
179
|
+
});
|
|
180
|
+
if (userInput !== "") {
|
|
181
|
+
msg({ type: "M_MIDDLE", title: ` ${userInput}` });
|
|
182
|
+
}
|
|
183
|
+
return Promise.resolve();
|
|
184
|
+
}
|
|
185
|
+
async function validateInput(input, validate) {
|
|
186
|
+
let isValid = true;
|
|
187
|
+
let errorMessage = "";
|
|
188
|
+
if (validate && isValid) {
|
|
189
|
+
const validationResult = await validate(input);
|
|
190
|
+
if (typeof validationResult === "string") {
|
|
191
|
+
isValid = false;
|
|
192
|
+
errorMessage = validationResult;
|
|
193
|
+
} else if (validationResult === false) {
|
|
194
|
+
isValid = false;
|
|
195
|
+
errorMessage = "Invalid input.";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { isValid, errorMessage };
|
|
199
|
+
}
|
|
200
|
+
export async function inputPrompt(options) {
|
|
201
|
+
const {
|
|
202
|
+
title,
|
|
203
|
+
message,
|
|
204
|
+
// Alias for title
|
|
205
|
+
hint,
|
|
206
|
+
hintPlaceholderColor = "blue",
|
|
207
|
+
validate,
|
|
208
|
+
defaultValue = "",
|
|
209
|
+
initialValue,
|
|
210
|
+
// Alias for defaultValue
|
|
211
|
+
titleColor = "cyan",
|
|
212
|
+
titleTypography = "none",
|
|
213
|
+
titleVariant = "none",
|
|
214
|
+
content,
|
|
215
|
+
contentColor = "dim",
|
|
216
|
+
contentTypography = "italic",
|
|
217
|
+
contentVariant = "none",
|
|
218
|
+
borderColor = "dim",
|
|
219
|
+
placeholder,
|
|
220
|
+
hardcoded,
|
|
221
|
+
endTitle = "",
|
|
222
|
+
endTitleColor = "dim",
|
|
223
|
+
border = true,
|
|
224
|
+
symbol,
|
|
225
|
+
customSymbol,
|
|
226
|
+
symbolColor,
|
|
227
|
+
mode = "plain",
|
|
228
|
+
mask,
|
|
229
|
+
shouldStream = false,
|
|
230
|
+
streamDelay = 20
|
|
231
|
+
} = options;
|
|
232
|
+
const finalTitle = message && title ? `${title}: ${message}` : message ?? title ?? "Input";
|
|
233
|
+
const finalDefaultValue = defaultValue ?? initialValue;
|
|
234
|
+
const terminal = readline.createInterface({
|
|
235
|
+
input: process.stdin,
|
|
236
|
+
output: process.stdout
|
|
237
|
+
});
|
|
238
|
+
async function endPrompt(isCtrlC) {
|
|
239
|
+
await completePrompt(
|
|
240
|
+
"input",
|
|
241
|
+
isCtrlC,
|
|
242
|
+
endTitle,
|
|
243
|
+
endTitleColor,
|
|
244
|
+
titleTypography,
|
|
245
|
+
titleVariant,
|
|
246
|
+
border,
|
|
247
|
+
borderColor,
|
|
248
|
+
void 0,
|
|
249
|
+
false
|
|
250
|
+
);
|
|
251
|
+
terminal.close();
|
|
252
|
+
if (isCtrlC) {
|
|
253
|
+
process.exit(0);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
terminal.on("SIGINT", () => {
|
|
257
|
+
void endPrompt(true);
|
|
258
|
+
});
|
|
259
|
+
let currentInput = hardcoded?.userInput ?? "";
|
|
260
|
+
let errorMessage = hardcoded?.errorMessage ?? "";
|
|
261
|
+
let showPlaceholder = hardcoded?.showPlaceholder ?? true;
|
|
262
|
+
let isRerender = false;
|
|
263
|
+
async function handleHardcodedInput() {
|
|
264
|
+
msgUndoAll();
|
|
265
|
+
await renderPromptUI({
|
|
266
|
+
title: finalTitle,
|
|
267
|
+
...hint !== void 0 && { hint },
|
|
268
|
+
...hintPlaceholderColor !== void 0 && { hintPlaceholderColor },
|
|
269
|
+
content: content ?? "",
|
|
270
|
+
...contentColor !== void 0 && { contentColor },
|
|
271
|
+
...contentTypography !== void 0 && { contentTypography },
|
|
272
|
+
...contentVariant !== void 0 && { contentVariant },
|
|
273
|
+
titleColor,
|
|
274
|
+
titleTypography,
|
|
275
|
+
...titleVariant !== void 0 && { titleVariant },
|
|
276
|
+
borderColor,
|
|
277
|
+
placeholder: showPlaceholder && placeholder ? placeholder : "",
|
|
278
|
+
userInput: currentInput,
|
|
279
|
+
errorMessage,
|
|
280
|
+
border,
|
|
281
|
+
...symbol !== void 0 && { symbol },
|
|
282
|
+
...customSymbol !== void 0 && { customSymbol },
|
|
283
|
+
...symbolColor !== void 0 && { symbolColor },
|
|
284
|
+
...mask !== void 0 && { mask },
|
|
285
|
+
shouldStream,
|
|
286
|
+
streamDelay
|
|
287
|
+
});
|
|
288
|
+
const finalAnswer = currentInput || finalDefaultValue;
|
|
289
|
+
const validated = await validateInput(finalAnswer, validate);
|
|
290
|
+
if (!validated.isValid) {
|
|
291
|
+
terminal.close();
|
|
292
|
+
throw new Error(validated.errorMessage || "Invalid input.");
|
|
293
|
+
}
|
|
294
|
+
msg({ type: "M_MIDDLE", title: ` ${finalAnswer}` });
|
|
295
|
+
msg({ type: "M_BAR", borderColor });
|
|
296
|
+
terminal.close();
|
|
297
|
+
return finalAnswer;
|
|
298
|
+
}
|
|
299
|
+
if (hardcoded?.userInput !== void 0) {
|
|
300
|
+
return handleHardcodedInput();
|
|
301
|
+
}
|
|
302
|
+
while (true) {
|
|
303
|
+
if (isRerender) {
|
|
304
|
+
msgUndoAll();
|
|
305
|
+
}
|
|
306
|
+
const displayedUserInput = mode === "password" ? getMaskChar(mask).repeat(currentInput.length) : currentInput;
|
|
307
|
+
if (errorMessage) {
|
|
308
|
+
deleteLastLine();
|
|
309
|
+
deleteLastLine();
|
|
310
|
+
}
|
|
311
|
+
await renderPromptUI({
|
|
312
|
+
title: finalTitle,
|
|
313
|
+
...hint !== void 0 && { hint },
|
|
314
|
+
hintPlaceholderColor,
|
|
315
|
+
content: content ?? "",
|
|
316
|
+
contentColor,
|
|
317
|
+
contentTypography,
|
|
318
|
+
...contentVariant !== void 0 && { contentVariant },
|
|
319
|
+
titleColor,
|
|
320
|
+
titleTypography,
|
|
321
|
+
...titleVariant !== void 0 && { titleVariant },
|
|
322
|
+
borderColor,
|
|
323
|
+
placeholder: showPlaceholder && placeholder ? placeholder : "",
|
|
324
|
+
userInput: displayedUserInput,
|
|
325
|
+
errorMessage,
|
|
326
|
+
border,
|
|
327
|
+
...symbol !== void 0 && { symbol },
|
|
328
|
+
...customSymbol !== void 0 && { customSymbol },
|
|
329
|
+
...symbolColor !== void 0 && { symbolColor },
|
|
330
|
+
...mask !== void 0 && { mask },
|
|
331
|
+
shouldStream,
|
|
332
|
+
streamDelay
|
|
333
|
+
});
|
|
334
|
+
if (errorMessage) {
|
|
335
|
+
deleteLastLine();
|
|
336
|
+
}
|
|
337
|
+
const formattedBar = bar({ borderColor });
|
|
338
|
+
const userInputRaw = await ask(terminal, `${formattedBar} `, mode, mask);
|
|
339
|
+
isRerender = true;
|
|
340
|
+
if (userInputRaw === null) {
|
|
341
|
+
return "";
|
|
342
|
+
}
|
|
343
|
+
currentInput = userInputRaw.trim();
|
|
344
|
+
if (showPlaceholder && currentInput !== "") {
|
|
345
|
+
showPlaceholder = false;
|
|
346
|
+
}
|
|
347
|
+
const finalAnswer = currentInput || finalDefaultValue;
|
|
348
|
+
const validated = await validateInput(finalAnswer, validate);
|
|
349
|
+
if (validated.isValid) {
|
|
350
|
+
if (!currentInput && finalDefaultValue) {
|
|
351
|
+
if (mode === "password") {
|
|
352
|
+
deleteLastLine();
|
|
353
|
+
deleteLastLine();
|
|
354
|
+
msg({
|
|
355
|
+
type: "M_MIDDLE",
|
|
356
|
+
title: ` ${getMaskChar(mask).repeat(finalDefaultValue.length)}`
|
|
357
|
+
});
|
|
358
|
+
} else {
|
|
359
|
+
deleteLastLine();
|
|
360
|
+
msg({ type: "M_MIDDLE", title: ` ${re.reset(finalDefaultValue)}` });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (errorMessage) {
|
|
364
|
+
deleteLastLine();
|
|
365
|
+
}
|
|
366
|
+
msg({ type: "M_BAR", borderColor });
|
|
367
|
+
terminal.close();
|
|
368
|
+
return finalAnswer;
|
|
369
|
+
}
|
|
370
|
+
errorMessage = validated.errorMessage;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Fonts } from "figlet";
|
|
2
|
+
import type { PreventWrongTerminalSizeOptions, PromptOptions } from "../../types";
|
|
3
|
+
type StartPromptOptions = PromptOptions & {
|
|
4
|
+
clearConsole?: boolean;
|
|
5
|
+
horizontalLine?: boolean;
|
|
6
|
+
horizontalLineLength?: number;
|
|
7
|
+
packageName?: string;
|
|
8
|
+
packageVersion?: string;
|
|
9
|
+
terminalSizeOptions?: PreventWrongTerminalSizeOptions;
|
|
10
|
+
isDev?: boolean;
|
|
11
|
+
prevent?: {
|
|
12
|
+
unsupportedTTY?: boolean;
|
|
13
|
+
wrongTerminalSize?: boolean;
|
|
14
|
+
windowsHomeDirRoot?: boolean;
|
|
15
|
+
};
|
|
16
|
+
variant?: "header" | "ascii-art";
|
|
17
|
+
asciiArtFont?: Fonts;
|
|
18
|
+
};
|
|
19
|
+
export declare function introPrompt(optionsOrTitle: StartPromptOptions | string): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { getCurrentTerminalName } from "@reliverse/runtime";
|
|
3
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
4
|
+
import { getExactTerminalWidth, getTerminalHeight, getTerminalWidth } from "../msg-fmt/terminal.js";
|
|
5
|
+
import {
|
|
6
|
+
preventUnsupportedTTY,
|
|
7
|
+
preventWindowsHomeDirRoot,
|
|
8
|
+
preventWrongTerminalSize
|
|
9
|
+
} from "../utils/prevent.js";
|
|
10
|
+
import { pm, reliversePrompts } from "../utils/system.js";
|
|
11
|
+
import { createAsciiArt } from "../visual/visual-mod.js";
|
|
12
|
+
export async function introPrompt(optionsOrTitle) {
|
|
13
|
+
const options = typeof optionsOrTitle === "string" ? { title: optionsOrTitle } : optionsOrTitle;
|
|
14
|
+
const {
|
|
15
|
+
title = "",
|
|
16
|
+
titleColor = "inverse",
|
|
17
|
+
titleTypography = "none",
|
|
18
|
+
titleVariant,
|
|
19
|
+
borderColor = "dim",
|
|
20
|
+
clearConsole = false,
|
|
21
|
+
horizontalLine = true,
|
|
22
|
+
horizontalLineLength: initialHorizontalLineLength = 0,
|
|
23
|
+
packageName = reliversePrompts.name,
|
|
24
|
+
packageVersion = reliversePrompts.version,
|
|
25
|
+
terminalSizeOptions = {},
|
|
26
|
+
isDev = false,
|
|
27
|
+
prevent = {
|
|
28
|
+
unsupportedTTY: true,
|
|
29
|
+
wrongTerminalSize: true,
|
|
30
|
+
windowsHomeDirRoot: true
|
|
31
|
+
},
|
|
32
|
+
variant = "header",
|
|
33
|
+
asciiArtFont
|
|
34
|
+
} = options;
|
|
35
|
+
let horizontalLineLength = initialHorizontalLineLength;
|
|
36
|
+
if (prevent.windowsHomeDirRoot) {
|
|
37
|
+
preventWindowsHomeDirRoot(process.cwd());
|
|
38
|
+
}
|
|
39
|
+
if (prevent.unsupportedTTY) {
|
|
40
|
+
preventUnsupportedTTY();
|
|
41
|
+
}
|
|
42
|
+
if (prevent.wrongTerminalSize) {
|
|
43
|
+
await preventWrongTerminalSize({ ...terminalSizeOptions, isDev });
|
|
44
|
+
}
|
|
45
|
+
const terminalWidth = getTerminalWidth();
|
|
46
|
+
const exactTerminalWidth = getExactTerminalWidth();
|
|
47
|
+
const terminalHeight = getTerminalHeight();
|
|
48
|
+
const formattedTitle = title !== "" ? title : `${packageName} v${packageVersion} | ${pm.packageManager} v${pm.version} | ${getCurrentTerminalName()}${isDev && terminalWidth > 80 ? ` | isDev | w${terminalWidth} h${terminalHeight}` : ""}`;
|
|
49
|
+
if (variant === "ascii-art") {
|
|
50
|
+
await createAsciiArt({
|
|
51
|
+
message: formattedTitle,
|
|
52
|
+
...asciiArtFont !== void 0 && { font: asciiArtFont },
|
|
53
|
+
clearConsole
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (horizontalLineLength === 0) {
|
|
58
|
+
const titleFullLength = titleColor === "inverse" ? `\u2800${formattedTitle}\u2800`.length + 5 : formattedTitle.length + 5;
|
|
59
|
+
horizontalLineLength = Math.max(1, exactTerminalWidth - titleFullLength);
|
|
60
|
+
}
|
|
61
|
+
if (clearConsole) {
|
|
62
|
+
relinka("clear", "");
|
|
63
|
+
relinka("log", "");
|
|
64
|
+
} else {
|
|
65
|
+
relinka("log", "");
|
|
66
|
+
}
|
|
67
|
+
msg({
|
|
68
|
+
type: "M_START",
|
|
69
|
+
title: titleColor === "inverse" ? `\u2800${formattedTitle}\u2800` : formattedTitle,
|
|
70
|
+
titleColor,
|
|
71
|
+
titleTypography,
|
|
72
|
+
...titleVariant ? { titleVariant } : {},
|
|
73
|
+
borderColor,
|
|
74
|
+
horizontalLine,
|
|
75
|
+
horizontalLineLength
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReliArgParserOptions } from "../reliarg/reliarg-mod";
|
|
2
|
+
import type { ArgDefinitions, Command, CommandContext, EmptyArgs, InferArgTypes } from "./launcher-types";
|
|
3
|
+
export interface CallCmdOptions {
|
|
4
|
+
/** Whether to automatically exit process on errors (default: false for programmatic usage) */
|
|
5
|
+
autoExit?: boolean;
|
|
6
|
+
/** Whether to show debug output */
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
/** Whether to call lifecycle hooks (onCmdInit/onCmdExit) */
|
|
9
|
+
useLifecycleHooks?: boolean;
|
|
10
|
+
/** Custom parser options for argv processing */
|
|
11
|
+
parserOptions?: ReliArgParserOptions;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Programmatically call a defineCommand command with arguments.
|
|
15
|
+
* Fully compatible with launcher-mod.ts execution logic.
|
|
16
|
+
*
|
|
17
|
+
* @param command - The command definition created with defineCommand()
|
|
18
|
+
* @param input - Either argv array (CLI-style) or args object (programmatic style)
|
|
19
|
+
* @param options - Optional configuration for execution
|
|
20
|
+
* @returns Promise resolving to the command context
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // CLI-style with argv array
|
|
25
|
+
* const result = await callCmd(myCommand, ['--flag', 'value', 'positional']);
|
|
26
|
+
*
|
|
27
|
+
* // Programmatic style with object
|
|
28
|
+
* const result = await callCmd(myCommand, { flag: true, name: 'value' });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function callCmd<A extends ArgDefinitions = EmptyArgs>(command: Command<A>, input: string[] | Partial<InferArgTypes<A>>, options?: CallCmdOptions): Promise<CommandContext<InferArgTypes<A>>>;
|