@reliverse/rempts 1.7.52 → 1.7.53
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 +975 -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 +137 -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,340 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import readline from "node:readline";
|
|
3
|
+
import { re } from "@reliverse/relico";
|
|
4
|
+
import { relinka } from "@reliverse/relinka";
|
|
5
|
+
import { msg, symbols } from "../msg-fmt/messages.js";
|
|
6
|
+
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
7
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
8
|
+
function isSelectOption(option) {
|
|
9
|
+
return !("separator" in option);
|
|
10
|
+
}
|
|
11
|
+
function renderPromptUI(params) {
|
|
12
|
+
const {
|
|
13
|
+
title,
|
|
14
|
+
content,
|
|
15
|
+
options,
|
|
16
|
+
pointer,
|
|
17
|
+
selectedOptions,
|
|
18
|
+
errorMessage,
|
|
19
|
+
displayInstructions,
|
|
20
|
+
instructions,
|
|
21
|
+
allDisabled,
|
|
22
|
+
titleColor,
|
|
23
|
+
contentColor,
|
|
24
|
+
contentTypography,
|
|
25
|
+
debug,
|
|
26
|
+
titleVariant,
|
|
27
|
+
titleTypography,
|
|
28
|
+
isRerender = false
|
|
29
|
+
} = params;
|
|
30
|
+
if (!isRerender) {
|
|
31
|
+
msg({
|
|
32
|
+
type: "M_NULL",
|
|
33
|
+
title,
|
|
34
|
+
titleColor,
|
|
35
|
+
...titleTypography ? { titleTypography } : {},
|
|
36
|
+
...titleVariant ? { titleVariant } : {}
|
|
37
|
+
});
|
|
38
|
+
if (content) {
|
|
39
|
+
msg({
|
|
40
|
+
type: "M_NULL",
|
|
41
|
+
content,
|
|
42
|
+
contentColor,
|
|
43
|
+
contentTypography
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let uiLineCount = 0;
|
|
48
|
+
if (errorMessage) {
|
|
49
|
+
msg({
|
|
50
|
+
type: "M_NULL",
|
|
51
|
+
title: `${re.redBright(symbols.step_error)} ${re.redBright(errorMessage)}`
|
|
52
|
+
});
|
|
53
|
+
uiLineCount++;
|
|
54
|
+
} else if (allDisabled) {
|
|
55
|
+
msg({ type: "M_NULL", title: re.redBright("All options are disabled.") });
|
|
56
|
+
uiLineCount++;
|
|
57
|
+
} else if (displayInstructions && !isRerender) {
|
|
58
|
+
msg({ type: "M_NULL", title: re.blue(instructions) });
|
|
59
|
+
uiLineCount++;
|
|
60
|
+
}
|
|
61
|
+
for (let index = 0; index < options.length; index++) {
|
|
62
|
+
const option = options[index];
|
|
63
|
+
if (!option) continue;
|
|
64
|
+
if (!isSelectOption(option)) {
|
|
65
|
+
const width = option.width ?? 20;
|
|
66
|
+
const symbolKey = option.symbol ?? "line";
|
|
67
|
+
const lineSymbol = symbolKey in symbols ? symbols[symbolKey] : "\u2500";
|
|
68
|
+
msg({ type: "M_NULL", title: re.dim(lineSymbol.repeat(width)) });
|
|
69
|
+
uiLineCount++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const isSelected = selectedOptions.has(index);
|
|
73
|
+
const isHighlighted = index === pointer;
|
|
74
|
+
const isDisabled = option.disabled;
|
|
75
|
+
const checkbox = isSelected ? "[x]" : "[ ]";
|
|
76
|
+
const prefix = isHighlighted ? re.yellow(re.reset("> ")) : " ";
|
|
77
|
+
const labelColor = isDisabled ? re.dim(re.reset(option.label)) : isHighlighted ? re.reset(re.yellow(option.label)) : re.reset(option.label);
|
|
78
|
+
const hint = option.hint ? re.reset(` (${isDisabled ? re.dim(option.hint) : re.gray(option.hint)})`) : "";
|
|
79
|
+
const formattedCheckbox = isHighlighted ? re.yellow(checkbox) : checkbox;
|
|
80
|
+
msg({
|
|
81
|
+
type: "M_NULL",
|
|
82
|
+
title: `${prefix}${formattedCheckbox} ${labelColor}${hint}`
|
|
83
|
+
});
|
|
84
|
+
uiLineCount++;
|
|
85
|
+
}
|
|
86
|
+
if (debug) {
|
|
87
|
+
relinka("log", "", { optionsCount: options.length });
|
|
88
|
+
}
|
|
89
|
+
return uiLineCount;
|
|
90
|
+
}
|
|
91
|
+
export async function multiselectPrompt(params) {
|
|
92
|
+
const {
|
|
93
|
+
title = "",
|
|
94
|
+
message,
|
|
95
|
+
content = "",
|
|
96
|
+
options,
|
|
97
|
+
defaultValue = [],
|
|
98
|
+
initialValues,
|
|
99
|
+
borderColor = "dim",
|
|
100
|
+
titleColor = "cyan",
|
|
101
|
+
titleTypography = "none",
|
|
102
|
+
titleVariant,
|
|
103
|
+
contentColor = "dim",
|
|
104
|
+
contentTypography = "italic",
|
|
105
|
+
border = true,
|
|
106
|
+
endTitle = "",
|
|
107
|
+
endTitleColor = "dim",
|
|
108
|
+
debug = false,
|
|
109
|
+
terminalWidth: customTerminalWidth = 90,
|
|
110
|
+
displayInstructions = false,
|
|
111
|
+
required = false,
|
|
112
|
+
minSelect = 0,
|
|
113
|
+
maxSelect,
|
|
114
|
+
selectAll = false
|
|
115
|
+
} = params;
|
|
116
|
+
const finalTitle = message && title ? `${title}: ${message}` : message ?? title ?? "Select options";
|
|
117
|
+
const finalDefaultValue = defaultValue ?? initialValues;
|
|
118
|
+
const effectiveMinSelect = required ? Math.max(1, minSelect) : minSelect;
|
|
119
|
+
let pointer = finalDefaultValue.length > 0 ? options.findIndex(
|
|
120
|
+
(opt) => opt && isSelectOption(opt) && finalDefaultValue.includes(opt.value) && !opt.disabled
|
|
121
|
+
) : 0;
|
|
122
|
+
if (pointer === -1) {
|
|
123
|
+
pointer = options.findIndex((opt) => opt && isSelectOption(opt) && !opt.disabled);
|
|
124
|
+
if (pointer === -1) {
|
|
125
|
+
pointer = 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const selectedOptions = new Set(
|
|
129
|
+
selectAll ? options.map((opt, index) => opt && isSelectOption(opt) && !opt.disabled ? index : -1).filter((i) => i !== -1) : finalDefaultValue.map((val) => options.findIndex((o) => o && isSelectOption(o) && o.value === val)).filter(
|
|
130
|
+
(i) => i >= 0 && options[i] && isSelectOption(options[i]) && !options[i].disabled
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
const rl = readline.createInterface({ input, output });
|
|
134
|
+
readline.emitKeypressEvents(input, rl);
|
|
135
|
+
if (typeof input.setRawMode === "function") {
|
|
136
|
+
input.setRawMode(true);
|
|
137
|
+
}
|
|
138
|
+
let errorMessage = "";
|
|
139
|
+
const allDisabled = options.filter(isSelectOption).every((option) => option.disabled);
|
|
140
|
+
const instructions = "Use <\u2191/\u2193> to navigate, <Space> to toggle, <A> to toggle all";
|
|
141
|
+
function toggleSelectAll() {
|
|
142
|
+
const selectableIndexes = options.map((opt, i) => isSelectOption(opt) && !opt.disabled ? i : -1).filter((i) => i !== -1);
|
|
143
|
+
const allSelected = selectableIndexes.every((i) => selectedOptions.has(i));
|
|
144
|
+
if (allSelected) {
|
|
145
|
+
for (const i of selectableIndexes) {
|
|
146
|
+
selectedOptions.delete(i);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
for (const i of selectableIndexes) {
|
|
150
|
+
selectedOptions.add(i);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function movePointerUp() {
|
|
155
|
+
const originalPointer = pointer;
|
|
156
|
+
do {
|
|
157
|
+
pointer = (pointer - 1 + options.length) % options.length;
|
|
158
|
+
const currentOption = options[pointer];
|
|
159
|
+
if (currentOption && isSelectOption(currentOption) && !currentOption.disabled) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
} while (pointer !== originalPointer);
|
|
163
|
+
errorMessage = "";
|
|
164
|
+
}
|
|
165
|
+
function movePointerDown() {
|
|
166
|
+
const originalPointer = pointer;
|
|
167
|
+
do {
|
|
168
|
+
pointer = (pointer + 1) % options.length;
|
|
169
|
+
const currentOption = options[pointer];
|
|
170
|
+
if (currentOption && isSelectOption(currentOption) && !currentOption.disabled) {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
} while (pointer !== originalPointer);
|
|
174
|
+
errorMessage = "";
|
|
175
|
+
}
|
|
176
|
+
let lastUILineCount = 0;
|
|
177
|
+
function renderOptions() {
|
|
178
|
+
if (lastUILineCount > 0) {
|
|
179
|
+
for (let i = 0; i < lastUILineCount; i++) {
|
|
180
|
+
process.stdout.write("\x1B[1A\x1B[2K");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
lastUILineCount = renderPromptUI({
|
|
184
|
+
title: finalTitle,
|
|
185
|
+
content,
|
|
186
|
+
options,
|
|
187
|
+
pointer,
|
|
188
|
+
selectedOptions,
|
|
189
|
+
errorMessage,
|
|
190
|
+
displayInstructions,
|
|
191
|
+
instructions,
|
|
192
|
+
allDisabled,
|
|
193
|
+
titleColor,
|
|
194
|
+
contentColor,
|
|
195
|
+
contentTypography,
|
|
196
|
+
debug,
|
|
197
|
+
borderColor,
|
|
198
|
+
titleVariant,
|
|
199
|
+
titleTypography,
|
|
200
|
+
terminalWidth: customTerminalWidth,
|
|
201
|
+
resized: false,
|
|
202
|
+
isRerender: true
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
lastUILineCount = renderPromptUI({
|
|
206
|
+
title: finalTitle,
|
|
207
|
+
content,
|
|
208
|
+
options,
|
|
209
|
+
pointer,
|
|
210
|
+
selectedOptions,
|
|
211
|
+
errorMessage,
|
|
212
|
+
displayInstructions,
|
|
213
|
+
instructions,
|
|
214
|
+
allDisabled,
|
|
215
|
+
titleColor,
|
|
216
|
+
contentColor,
|
|
217
|
+
contentTypography,
|
|
218
|
+
debug,
|
|
219
|
+
borderColor,
|
|
220
|
+
titleVariant,
|
|
221
|
+
titleTypography,
|
|
222
|
+
terminalWidth: customTerminalWidth,
|
|
223
|
+
resized: false,
|
|
224
|
+
isRerender: false
|
|
225
|
+
});
|
|
226
|
+
return new Promise((resolve) => {
|
|
227
|
+
function cleanup(isCtrlC = false) {
|
|
228
|
+
if (typeof input.setRawMode === "function") {
|
|
229
|
+
input.setRawMode(false);
|
|
230
|
+
}
|
|
231
|
+
rl.close();
|
|
232
|
+
input.removeListener("keypress", handleKeypress);
|
|
233
|
+
if (isCtrlC) {
|
|
234
|
+
process.exit(0);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function endPrompt(isCtrlC = false) {
|
|
238
|
+
await completePrompt(
|
|
239
|
+
"multiselect",
|
|
240
|
+
isCtrlC,
|
|
241
|
+
endTitle,
|
|
242
|
+
endTitleColor,
|
|
243
|
+
titleTypography,
|
|
244
|
+
titleVariant ? titleVariant : void 0,
|
|
245
|
+
border,
|
|
246
|
+
borderColor,
|
|
247
|
+
void 0,
|
|
248
|
+
false
|
|
249
|
+
);
|
|
250
|
+
cleanup(isCtrlC);
|
|
251
|
+
}
|
|
252
|
+
async function confirmSelection() {
|
|
253
|
+
const selectedCount = selectedOptions.size;
|
|
254
|
+
if (selectedCount < effectiveMinSelect) {
|
|
255
|
+
deleteLastLine();
|
|
256
|
+
errorMessage = `You must select at least ${effectiveMinSelect} option${effectiveMinSelect !== 1 ? "s" : ""}.`;
|
|
257
|
+
renderOptions();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (maxSelect !== void 0 && selectedCount > maxSelect) {
|
|
261
|
+
deleteLastLine();
|
|
262
|
+
errorMessage = `You can select at most ${maxSelect} option${maxSelect !== 1 ? "s" : ""}.`;
|
|
263
|
+
renderOptions();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const selectedValues = Array.from(selectedOptions).filter((idx) => {
|
|
267
|
+
const opt = options[idx];
|
|
268
|
+
return opt && isSelectOption(opt) && !opt.disabled;
|
|
269
|
+
}).map((idx) => {
|
|
270
|
+
const opt = options[idx];
|
|
271
|
+
return opt && isSelectOption(opt) ? opt.value : null;
|
|
272
|
+
}).filter((val) => val !== null && val !== void 0);
|
|
273
|
+
cleanup();
|
|
274
|
+
resolve(selectedValues);
|
|
275
|
+
deleteLastLine();
|
|
276
|
+
await completePrompt(
|
|
277
|
+
"multiselect",
|
|
278
|
+
false,
|
|
279
|
+
endTitle,
|
|
280
|
+
endTitleColor,
|
|
281
|
+
titleTypography,
|
|
282
|
+
titleVariant ? titleVariant : void 0,
|
|
283
|
+
border,
|
|
284
|
+
borderColor,
|
|
285
|
+
void 0,
|
|
286
|
+
true
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
function handleKeypress(_str, key) {
|
|
290
|
+
if (allDisabled) {
|
|
291
|
+
if (key.name === "c" && key.ctrl) {
|
|
292
|
+
void endPrompt(true);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
switch (key.name) {
|
|
298
|
+
case "up":
|
|
299
|
+
case "k":
|
|
300
|
+
movePointerUp();
|
|
301
|
+
renderOptions();
|
|
302
|
+
break;
|
|
303
|
+
case "down":
|
|
304
|
+
case "j":
|
|
305
|
+
movePointerDown();
|
|
306
|
+
renderOptions();
|
|
307
|
+
break;
|
|
308
|
+
case "space": {
|
|
309
|
+
const currentOption = options[pointer];
|
|
310
|
+
if (!currentOption || !isSelectOption(currentOption) || currentOption.disabled) {
|
|
311
|
+
errorMessage = "This option is disabled";
|
|
312
|
+
} else {
|
|
313
|
+
if (selectedOptions.has(pointer)) {
|
|
314
|
+
selectedOptions.delete(pointer);
|
|
315
|
+
} else {
|
|
316
|
+
selectedOptions.add(pointer);
|
|
317
|
+
}
|
|
318
|
+
errorMessage = "";
|
|
319
|
+
}
|
|
320
|
+
renderOptions();
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case "return":
|
|
324
|
+
void confirmSelection();
|
|
325
|
+
break;
|
|
326
|
+
case "c":
|
|
327
|
+
if (key.ctrl) {
|
|
328
|
+
void endPrompt(true);
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
case "a":
|
|
332
|
+
toggleSelectAll();
|
|
333
|
+
errorMessage = "";
|
|
334
|
+
renderOptions();
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
input.on("keypress", handleKeypress);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ColorName, TypographyName, VariantName } from "../../types";
|
|
2
|
+
interface NextStepsPromptOptions {
|
|
3
|
+
title?: string;
|
|
4
|
+
titleColor?: ColorName;
|
|
5
|
+
titleVariant?: VariantName;
|
|
6
|
+
titleTypography?: TypographyName;
|
|
7
|
+
content: string[];
|
|
8
|
+
contentColor?: ColorName;
|
|
9
|
+
contentVariant?: VariantName;
|
|
10
|
+
contentTypography?: TypographyName;
|
|
11
|
+
}
|
|
12
|
+
export declare function nextStepsPrompt(options: NextStepsPromptOptions): Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
2
|
+
export async function nextStepsPrompt(options) {
|
|
3
|
+
const {
|
|
4
|
+
title = "",
|
|
5
|
+
titleColor = "cyan",
|
|
6
|
+
titleVariant,
|
|
7
|
+
titleTypography = "none",
|
|
8
|
+
content = [],
|
|
9
|
+
contentColor = "dim",
|
|
10
|
+
contentVariant,
|
|
11
|
+
contentTypography = "italic"
|
|
12
|
+
} = options;
|
|
13
|
+
msg({
|
|
14
|
+
type: "M_INFO",
|
|
15
|
+
title,
|
|
16
|
+
titleColor,
|
|
17
|
+
titleTypography,
|
|
18
|
+
...titleVariant ? { titleVariant } : {},
|
|
19
|
+
content: Array.isArray(content) ? content.join("\n") : content,
|
|
20
|
+
contentColor,
|
|
21
|
+
contentTypography,
|
|
22
|
+
...contentVariant ? { contentVariant } : {}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BorderColorName, ColorName, FmtMsgOptions, TypographyName } from "../../types";
|
|
2
|
+
type VariantName = FmtMsgOptions["titleVariant"];
|
|
3
|
+
interface NumberPromptOptions {
|
|
4
|
+
title: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
hintPlaceholderColor?: ColorName;
|
|
7
|
+
validate?: (value: number) => string | undefined | boolean | Promise<string | undefined | boolean>;
|
|
8
|
+
defaultValue?: string | number;
|
|
9
|
+
schema?: any;
|
|
10
|
+
titleColor?: ColorName;
|
|
11
|
+
titleTypography?: TypographyName;
|
|
12
|
+
titleVariant?: VariantName;
|
|
13
|
+
content?: string;
|
|
14
|
+
contentColor?: ColorName;
|
|
15
|
+
contentTypography?: TypographyName;
|
|
16
|
+
contentVariant?: VariantName;
|
|
17
|
+
borderColor?: BorderColorName;
|
|
18
|
+
variantOptions?: any;
|
|
19
|
+
endTitle?: string;
|
|
20
|
+
endTitleColor?: ColorName;
|
|
21
|
+
border?: boolean;
|
|
22
|
+
hardcoded?: {
|
|
23
|
+
userInput?: string;
|
|
24
|
+
errorMessage?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function numberPrompt(opts: NumberPromptOptions): Promise<number>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import readline from "node:readline/promises";
|
|
3
|
+
import { bar, msg } from "../msg-fmt/messages.js";
|
|
4
|
+
import { deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
5
|
+
function renderPromptUI(params) {
|
|
6
|
+
const {
|
|
7
|
+
title,
|
|
8
|
+
hint,
|
|
9
|
+
content,
|
|
10
|
+
contentColor = "dim",
|
|
11
|
+
contentTypography = "italic",
|
|
12
|
+
contentVariant,
|
|
13
|
+
titleColor = "cyan",
|
|
14
|
+
titleTypography = "none",
|
|
15
|
+
titleVariant,
|
|
16
|
+
borderColor = "dim",
|
|
17
|
+
userInput,
|
|
18
|
+
errorMessage
|
|
19
|
+
} = params;
|
|
20
|
+
let lineCount = 0;
|
|
21
|
+
const type = errorMessage !== "" ? "M_ERROR" : "M_GENERAL";
|
|
22
|
+
const msgParams = {
|
|
23
|
+
type,
|
|
24
|
+
title,
|
|
25
|
+
titleColor,
|
|
26
|
+
titleTypography,
|
|
27
|
+
titleVariant: titleVariant ?? "none",
|
|
28
|
+
content: content ?? "",
|
|
29
|
+
contentColor,
|
|
30
|
+
contentTypography,
|
|
31
|
+
contentVariant: contentVariant ?? "none",
|
|
32
|
+
borderColor,
|
|
33
|
+
hint: hint ?? "",
|
|
34
|
+
errorMessage
|
|
35
|
+
};
|
|
36
|
+
msg(msgParams);
|
|
37
|
+
lineCount++;
|
|
38
|
+
if (userInput !== "") {
|
|
39
|
+
msg({ type: "M_MIDDLE", title: ` ${userInput}` });
|
|
40
|
+
lineCount++;
|
|
41
|
+
}
|
|
42
|
+
return lineCount;
|
|
43
|
+
}
|
|
44
|
+
export async function numberPrompt(opts) {
|
|
45
|
+
const {
|
|
46
|
+
title = "",
|
|
47
|
+
hint,
|
|
48
|
+
hintPlaceholderColor = "blue",
|
|
49
|
+
validate,
|
|
50
|
+
defaultValue,
|
|
51
|
+
titleColor = "cyan",
|
|
52
|
+
titleTypography = "none",
|
|
53
|
+
titleVariant,
|
|
54
|
+
content,
|
|
55
|
+
contentColor = "dim",
|
|
56
|
+
contentTypography = "italic",
|
|
57
|
+
contentVariant,
|
|
58
|
+
borderColor = "dim",
|
|
59
|
+
hardcoded,
|
|
60
|
+
endTitle = "",
|
|
61
|
+
endTitleColor = "dim",
|
|
62
|
+
border = true
|
|
63
|
+
} = opts;
|
|
64
|
+
const rl = readline.createInterface({ input, output });
|
|
65
|
+
rl.on("SIGINT", () => {
|
|
66
|
+
if (endTitle !== "") {
|
|
67
|
+
msg({
|
|
68
|
+
type: "M_END",
|
|
69
|
+
title: endTitle,
|
|
70
|
+
titleColor: endTitleColor,
|
|
71
|
+
titleTypography,
|
|
72
|
+
border,
|
|
73
|
+
borderColor
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
rl.close();
|
|
77
|
+
process.exit(0);
|
|
78
|
+
});
|
|
79
|
+
let currentInput = hardcoded?.userInput || "";
|
|
80
|
+
let errorMessage = hardcoded?.errorMessage || "";
|
|
81
|
+
let isRerender = false;
|
|
82
|
+
let lastLineCount = 0;
|
|
83
|
+
const effectiveDefault = typeof defaultValue === "string" ? Number(defaultValue) : defaultValue;
|
|
84
|
+
if (hardcoded?.userInput !== void 0) {
|
|
85
|
+
renderPromptUI({
|
|
86
|
+
title,
|
|
87
|
+
hint,
|
|
88
|
+
hintPlaceholderColor,
|
|
89
|
+
content,
|
|
90
|
+
contentColor,
|
|
91
|
+
contentTypography,
|
|
92
|
+
contentVariant,
|
|
93
|
+
titleColor,
|
|
94
|
+
titleTypography,
|
|
95
|
+
titleVariant,
|
|
96
|
+
borderColor,
|
|
97
|
+
userInput: currentInput,
|
|
98
|
+
errorMessage,
|
|
99
|
+
border,
|
|
100
|
+
isRerender
|
|
101
|
+
});
|
|
102
|
+
const num = Number(currentInput);
|
|
103
|
+
if (Number.isNaN(num)) {
|
|
104
|
+
throw new Error("Please enter a valid number.");
|
|
105
|
+
}
|
|
106
|
+
const validated = await validateInput(num, validate);
|
|
107
|
+
if (validated.isValid) {
|
|
108
|
+
msg({ type: "M_MIDDLE", title: ` ${num}` });
|
|
109
|
+
msg({ type: "M_BAR", borderColor });
|
|
110
|
+
rl.close();
|
|
111
|
+
return num;
|
|
112
|
+
}
|
|
113
|
+
rl.close();
|
|
114
|
+
throw new Error(validated.errorMessage || "Invalid input.");
|
|
115
|
+
}
|
|
116
|
+
while (true) {
|
|
117
|
+
if (isRerender) {
|
|
118
|
+
deleteLastLines(lastLineCount + 1);
|
|
119
|
+
}
|
|
120
|
+
lastLineCount = renderPromptUI({
|
|
121
|
+
title,
|
|
122
|
+
hint,
|
|
123
|
+
hintPlaceholderColor,
|
|
124
|
+
content,
|
|
125
|
+
contentColor,
|
|
126
|
+
contentTypography,
|
|
127
|
+
contentVariant,
|
|
128
|
+
titleColor,
|
|
129
|
+
titleTypography,
|
|
130
|
+
titleVariant,
|
|
131
|
+
borderColor,
|
|
132
|
+
userInput: currentInput,
|
|
133
|
+
errorMessage,
|
|
134
|
+
border,
|
|
135
|
+
isRerender
|
|
136
|
+
});
|
|
137
|
+
const formattedBar = bar({ borderColor });
|
|
138
|
+
const answerInput = await rl.question(`${formattedBar} `);
|
|
139
|
+
isRerender = true;
|
|
140
|
+
if (answerInput === null) {
|
|
141
|
+
if (endTitle !== "") {
|
|
142
|
+
msg({
|
|
143
|
+
type: "M_END",
|
|
144
|
+
title: endTitle,
|
|
145
|
+
titleColor: endTitleColor,
|
|
146
|
+
titleTypography,
|
|
147
|
+
border,
|
|
148
|
+
borderColor
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
rl.close();
|
|
152
|
+
process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
currentInput = answerInput.trim();
|
|
155
|
+
if (!currentInput && effectiveDefault !== void 0) {
|
|
156
|
+
deleteLastLine();
|
|
157
|
+
msg({ type: "M_MIDDLE", title: ` ${effectiveDefault}` });
|
|
158
|
+
msg({ type: "M_BAR", borderColor });
|
|
159
|
+
rl.close();
|
|
160
|
+
return effectiveDefault;
|
|
161
|
+
}
|
|
162
|
+
const num = Number(currentInput);
|
|
163
|
+
if (Number.isNaN(num)) {
|
|
164
|
+
errorMessage = "Please enter a valid number.";
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const validated = await validateInput(num, validate);
|
|
168
|
+
if (validated.isValid) {
|
|
169
|
+
deleteLastLine();
|
|
170
|
+
msg({ type: "M_MIDDLE", title: ` ${num}` });
|
|
171
|
+
msg({ type: "M_BAR", borderColor });
|
|
172
|
+
rl.close();
|
|
173
|
+
return num;
|
|
174
|
+
}
|
|
175
|
+
errorMessage = validated.errorMessage;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function validateInput(input2, validate) {
|
|
179
|
+
let isValid = true;
|
|
180
|
+
let errorMessage = "";
|
|
181
|
+
if (validate && isValid) {
|
|
182
|
+
const validationResult = await validate(input2);
|
|
183
|
+
if (validationResult === true || validationResult === void 0) {
|
|
184
|
+
isValid = true;
|
|
185
|
+
} else if (typeof validationResult === "string") {
|
|
186
|
+
isValid = false;
|
|
187
|
+
errorMessage = validationResult;
|
|
188
|
+
} else {
|
|
189
|
+
isValid = false;
|
|
190
|
+
errorMessage = "Invalid input.";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { isValid, errorMessage };
|
|
194
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Fonts } from "figlet";
|
|
2
|
+
import type { PromptOptions } from "../../types";
|
|
3
|
+
type EndPromptOptions = PromptOptions & {
|
|
4
|
+
variant?: "footer" | "ascii-art";
|
|
5
|
+
asciiArtFont?: Fonts;
|
|
6
|
+
};
|
|
7
|
+
export declare function outroPrompt(optionsOrTitle: EndPromptOptions | string): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { animateText } from "../animate/animate-mod.js";
|
|
2
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
3
|
+
import { getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
4
|
+
import { createAsciiArt } from "../visual/visual-mod.js";
|
|
5
|
+
export async function outroPrompt(optionsOrTitle) {
|
|
6
|
+
const options = typeof optionsOrTitle === "string" ? { title: optionsOrTitle } : optionsOrTitle;
|
|
7
|
+
const {
|
|
8
|
+
title = "",
|
|
9
|
+
titleColor = "cyan",
|
|
10
|
+
titleTypography = "none",
|
|
11
|
+
titleVariant,
|
|
12
|
+
titleAnimation,
|
|
13
|
+
titleAnimationDelay,
|
|
14
|
+
border = true,
|
|
15
|
+
borderColor = "dim",
|
|
16
|
+
horizontalLineLength: initialHorizontalLineLength = 0,
|
|
17
|
+
variant = "footer",
|
|
18
|
+
asciiArtFont
|
|
19
|
+
} = options;
|
|
20
|
+
let horizontalLineLength = initialHorizontalLineLength;
|
|
21
|
+
if (variant === "ascii-art") {
|
|
22
|
+
await createAsciiArt({
|
|
23
|
+
message: title || " ",
|
|
24
|
+
font: asciiArtFont
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (horizontalLineLength === 0) {
|
|
29
|
+
horizontalLineLength = getExactTerminalWidth() - 3;
|
|
30
|
+
}
|
|
31
|
+
if (titleAnimation) {
|
|
32
|
+
await animateText({
|
|
33
|
+
title: title ? title : " ",
|
|
34
|
+
anim: titleAnimation,
|
|
35
|
+
delay: titleAnimationDelay,
|
|
36
|
+
type: "M_END",
|
|
37
|
+
titleColor,
|
|
38
|
+
titleTypography,
|
|
39
|
+
border,
|
|
40
|
+
borderColor,
|
|
41
|
+
horizontalLineLength
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
msg({
|
|
45
|
+
type: "M_END",
|
|
46
|
+
title: title ? title : " ",
|
|
47
|
+
titleColor,
|
|
48
|
+
titleTypography,
|
|
49
|
+
titleVariant,
|
|
50
|
+
border,
|
|
51
|
+
borderColor,
|
|
52
|
+
horizontalLineLength
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|