@reliverse/rempts 1.7.65 → 2.2.7
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/LICENSE +21 -21
- package/README.md +1534 -1431
- package/cleanup.mjs +33 -0
- package/dist/cancel.d.ts +31 -0
- package/dist/cancel.js +28 -0
- package/dist/ffi.d.ts +1 -0
- package/dist/ffi.js +165 -0
- package/dist/group.d.ts +16 -0
- package/dist/group.js +22 -0
- package/dist/launcher/command.d.ts +8 -0
- package/dist/launcher/command.js +10 -0
- package/dist/launcher/discovery.d.ts +3 -0
- package/dist/launcher/discovery.js +207 -0
- package/dist/launcher/errors.d.ts +15 -0
- package/dist/launcher/errors.js +31 -0
- package/dist/launcher/help.d.ts +3 -0
- package/dist/launcher/help.js +145 -0
- package/dist/launcher/mod.d.ts +12 -0
- package/dist/launcher/mod.js +222 -0
- package/dist/launcher/parser.d.ts +14 -0
- package/dist/launcher/parser.js +255 -0
- package/dist/launcher/registry.d.ts +10 -0
- package/dist/launcher/registry.js +42 -0
- package/dist/launcher/types.d.ts +78 -0
- package/dist/launcher/validator.d.ts +3 -0
- package/dist/launcher/validator.js +39 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +6 -0
- package/dist/prompt.d.ts +13 -0
- package/dist/prompt.js +53 -0
- package/dist/selection.d.ts +92 -0
- package/dist/selection.js +191 -0
- package/dist/spinner.d.ts +26 -0
- package/dist/spinner.js +141 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +11 -0
- package/package.json +41 -47
- package/bin/libs/animate/animate-mod.ts.txt +0 -78
- package/bin/libs/anykey/anykey-mod.d.ts +0 -12
- package/bin/libs/anykey/anykey-mod.js +0 -125
- package/bin/libs/cancel/cancel.d.ts +0 -45
- package/bin/libs/cancel/cancel.js +0 -72
- package/bin/libs/confirm/confirm-alias.d.ts +0 -2
- package/bin/libs/confirm/confirm-alias.js +0 -2
- package/bin/libs/confirm/confirm-mod.d.ts +0 -5
- package/bin/libs/confirm/confirm-mod.js +0 -179
- package/bin/libs/date/date.d.ts +0 -2
- package/bin/libs/date/date.js +0 -254
- package/bin/libs/editor/editor-mod.d.ts +0 -25
- package/bin/libs/editor/editor-mod.js +0 -1133
- package/bin/libs/figures/figures-mod.d.ts +0 -461
- package/bin/libs/figures/figures-mod.js +0 -285
- package/bin/libs/group/group-mod.d.ts +0 -33
- package/bin/libs/group/group-mod.js +0 -89
- package/bin/libs/input/input-alias.d.ts +0 -5
- package/bin/libs/input/input-alias.js +0 -4
- package/bin/libs/input/input-mod.d.ts +0 -16
- package/bin/libs/input/input-mod.js +0 -370
- package/bin/libs/intro/intro-alias.d.ts +0 -3
- package/bin/libs/intro/intro-alias.js +0 -3
- package/bin/libs/intro/intro-mod.d.ts +0 -19
- package/bin/libs/intro/intro-mod.js +0 -71
- package/bin/libs/launcher/command-runner.d.ts +0 -31
- package/bin/libs/launcher/command-runner.js +0 -229
- package/bin/libs/launcher/launcher-alias.d.ts +0 -2
- package/bin/libs/launcher/launcher-alias.js +0 -2
- package/bin/libs/launcher/launcher-mod.d.ts +0 -66
- package/bin/libs/launcher/launcher-mod.js +0 -1037
- package/bin/libs/launcher/launcher-types.d.ts +0 -176
- package/bin/libs/launcher/launcher-types.js +0 -0
- package/bin/libs/log/log-alias.d.ts +0 -1
- package/bin/libs/log/log-alias.js +0 -2
- package/bin/libs/msg-fmt/colors.d.ts +0 -30
- package/bin/libs/msg-fmt/colors.js +0 -42
- package/bin/libs/msg-fmt/mapping.d.ts +0 -3
- package/bin/libs/msg-fmt/mapping.js +0 -41
- package/bin/libs/msg-fmt/messages.d.ts +0 -35
- package/bin/libs/msg-fmt/messages.js +0 -305
- package/bin/libs/msg-fmt/terminal.d.ts +0 -15
- package/bin/libs/msg-fmt/terminal.js +0 -60
- package/bin/libs/msg-fmt/variants.d.ts +0 -11
- package/bin/libs/msg-fmt/variants.js +0 -52
- package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
- package/bin/libs/multiselect/multiselect-alias.js +0 -2
- package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
- package/bin/libs/multiselect/multiselect-prompt.js +0 -340
- package/bin/libs/next-steps/next-steps.d.ts +0 -13
- package/bin/libs/next-steps/next-steps.js +0 -24
- package/bin/libs/number/number-mod.d.ts +0 -28
- package/bin/libs/number/number-mod.js +0 -234
- package/bin/libs/outro/outro-alias.d.ts +0 -3
- package/bin/libs/outro/outro-alias.js +0 -3
- package/bin/libs/outro/outro-mod.d.ts +0 -7
- package/bin/libs/outro/outro-mod.js +0 -49
- package/bin/libs/reliarg/reliarg-mod.d.ts +0 -76
- package/bin/libs/reliarg/reliarg-mod.js +0 -276
- package/bin/libs/results/results.d.ts +0 -7
- package/bin/libs/results/results.js +0 -27
- package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
- package/bin/libs/select/nummultiselect-prompt.js +0 -141
- package/bin/libs/select/numselect-prompt.d.ts +0 -7
- package/bin/libs/select/numselect-prompt.js +0 -111
- package/bin/libs/select/select-alias.d.ts +0 -9
- package/bin/libs/select/select-alias.js +0 -9
- package/bin/libs/select/select-prompt.d.ts +0 -5
- package/bin/libs/select/select-prompt.js +0 -311
- package/bin/libs/select/toggle-prompt.d.ts +0 -5
- package/bin/libs/select/toggle-prompt.js +0 -207
- package/bin/libs/spinner/spinner-impl.d.ts +0 -70
- package/bin/libs/spinner/spinner-impl.js +0 -336
- package/bin/libs/spinner/spinner-mod.d.ts +0 -167
- package/bin/libs/spinner/spinner-mod.js +0 -447
- package/bin/libs/utils/colorize.d.ts +0 -2
- package/bin/libs/utils/colorize.js +0 -122
- package/bin/libs/utils/errors.d.ts +0 -1
- package/bin/libs/utils/errors.js +0 -17
- package/bin/libs/utils/prevent.d.ts +0 -8
- package/bin/libs/utils/prevent.js +0 -62
- package/bin/libs/utils/prompt-end.d.ts +0 -8
- package/bin/libs/utils/prompt-end.js +0 -36
- package/bin/libs/utils/stream-text.d.ts +0 -18
- package/bin/libs/utils/stream-text.js +0 -138
- package/bin/libs/utils/system.d.ts +0 -6
- package/bin/libs/utils/system.js +0 -7
- package/bin/libs/utils/validate.d.ts +0 -21
- package/bin/libs/utils/validate.js +0 -17
- package/bin/libs/visual/visual-mod.ts.txt +0 -19
- package/bin/mod.d.ts +0 -50
- package/bin/mod.js +0 -127
- package/bin/types.d.ts +0 -372
- /package/{bin → dist/launcher}/types.js +0 -0
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
-
import readline from "node:readline/promises";
|
|
3
|
-
import { re } from "@reliverse/relico";
|
|
4
|
-
import { bar, fmt, msg } from "../msg-fmt/messages.js";
|
|
5
|
-
import { countLines, deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
6
|
-
async function askForInput(prompt) {
|
|
7
|
-
return new Promise((resolve) => {
|
|
8
|
-
let buffer = "";
|
|
9
|
-
process.stdout.write(prompt);
|
|
10
|
-
const onData = (data) => {
|
|
11
|
-
const str = data.toString("utf-8");
|
|
12
|
-
for (const char of str) {
|
|
13
|
-
if (char === "\n" || char === "\r") {
|
|
14
|
-
process.stdout.write("\n");
|
|
15
|
-
cleanup();
|
|
16
|
-
resolve(buffer);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (char === "") {
|
|
20
|
-
cleanup();
|
|
21
|
-
resolve(null);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (char === "\x7F" || char === "\b") {
|
|
25
|
-
if (buffer.length > 0) {
|
|
26
|
-
buffer = buffer.slice(0, -1);
|
|
27
|
-
}
|
|
28
|
-
redrawPrompt(buffer, prompt);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
buffer += char;
|
|
32
|
-
redrawPrompt(buffer, prompt);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
process.stdin.on("data", onData);
|
|
36
|
-
const cleanup = () => {
|
|
37
|
-
process.stdin.removeListener("data", onData);
|
|
38
|
-
};
|
|
39
|
-
const redrawPrompt = (inputBuffer, textPrompt) => {
|
|
40
|
-
process.stdout.clearLine(0);
|
|
41
|
-
process.stdout.cursorTo(0);
|
|
42
|
-
process.stdout.write(textPrompt + inputBuffer);
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export async function numMultiSelectPrompt(opts) {
|
|
47
|
-
const {
|
|
48
|
-
title = "",
|
|
49
|
-
choices,
|
|
50
|
-
defaultValue,
|
|
51
|
-
titleColor = "cyan",
|
|
52
|
-
titleTypography = "none",
|
|
53
|
-
titleVariant,
|
|
54
|
-
hint,
|
|
55
|
-
hintPlaceholderColor = "blue",
|
|
56
|
-
content,
|
|
57
|
-
contentColor = "dim",
|
|
58
|
-
contentTypography = "italic",
|
|
59
|
-
contentVariant,
|
|
60
|
-
borderColor = "dim",
|
|
61
|
-
variantOptions
|
|
62
|
-
} = opts;
|
|
63
|
-
if (!choices || choices.length === 0) {
|
|
64
|
-
throw new Error("Choices are required for multiselect prompt.");
|
|
65
|
-
}
|
|
66
|
-
const rl = readline.createInterface({ input, output });
|
|
67
|
-
const formattedBar = bar({ borderColor });
|
|
68
|
-
let linesToDelete = 0;
|
|
69
|
-
let errorMessage = "";
|
|
70
|
-
try {
|
|
71
|
-
while (true) {
|
|
72
|
-
if (linesToDelete > 0) {
|
|
73
|
-
deleteLastLines(linesToDelete);
|
|
74
|
-
}
|
|
75
|
-
const { text: question } = fmt({
|
|
76
|
-
hintPlaceholderColor,
|
|
77
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
78
|
-
title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}]` : ""}`,
|
|
79
|
-
titleColor,
|
|
80
|
-
titleTypography,
|
|
81
|
-
titleVariant: titleVariant ?? "none",
|
|
82
|
-
content: content ?? "",
|
|
83
|
-
contentColor: contentColor ?? "dim",
|
|
84
|
-
contentTypography: contentTypography ?? "none",
|
|
85
|
-
contentVariant: contentVariant ?? "none",
|
|
86
|
-
borderColor,
|
|
87
|
-
hint: hint ?? "",
|
|
88
|
-
variantOptions: variantOptions ?? {},
|
|
89
|
-
errorMessage
|
|
90
|
-
});
|
|
91
|
-
const choicesText = choices.map(
|
|
92
|
-
(choice, index) => re.dim(
|
|
93
|
-
`${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
|
|
94
|
-
)
|
|
95
|
-
).join("\n");
|
|
96
|
-
const fullPrompt = `${question}
|
|
97
|
-
${choicesText}
|
|
98
|
-
${formattedBar} ${re.bold(re.blue(`Enter your choices (comma-separated numbers between 1-${choices.length})`))}:
|
|
99
|
-
${formattedBar} `;
|
|
100
|
-
const { text: formattedPrompt } = fmt({
|
|
101
|
-
hintPlaceholderColor,
|
|
102
|
-
type: "M_NULL",
|
|
103
|
-
title: fullPrompt
|
|
104
|
-
});
|
|
105
|
-
const questionLines = countLines(formattedPrompt);
|
|
106
|
-
linesToDelete = questionLines + 1;
|
|
107
|
-
const answer = (await askForInput(`${formattedPrompt} `))?.trim() || "";
|
|
108
|
-
if (!answer && defaultValue !== void 0) {
|
|
109
|
-
deleteLastLine();
|
|
110
|
-
msg({
|
|
111
|
-
type: "M_MIDDLE",
|
|
112
|
-
title: ` ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}`,
|
|
113
|
-
titleColor: "none"
|
|
114
|
-
});
|
|
115
|
-
msg({ type: "M_BAR", borderColor });
|
|
116
|
-
return defaultValue;
|
|
117
|
-
}
|
|
118
|
-
const selections = answer.split(",").map((s) => s.trim());
|
|
119
|
-
const invalidSelections = selections.filter((s) => {
|
|
120
|
-
const num = Number(s);
|
|
121
|
-
return Number.isNaN(num) || num < 1 || num > choices.length;
|
|
122
|
-
});
|
|
123
|
-
if (invalidSelections.length > 0) {
|
|
124
|
-
errorMessage = `Invalid selections: ${invalidSelections.join(
|
|
125
|
-
", "
|
|
126
|
-
)}. Please enter numbers between 1 and ${choices.length}.`;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
|
|
130
|
-
const isValid = true;
|
|
131
|
-
errorMessage = "";
|
|
132
|
-
if (isValid) {
|
|
133
|
-
rl.close();
|
|
134
|
-
msg({ type: "M_BAR", borderColor });
|
|
135
|
-
return selectedValues;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} finally {
|
|
139
|
-
rl.close();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
-
import readline from "node:readline/promises";
|
|
3
|
-
import { bar, fmt, msg } from "../msg-fmt/messages.js";
|
|
4
|
-
import { countLines, deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
5
|
-
import { colorize } from "../utils/colorize.js";
|
|
6
|
-
export async function numSelectPrompt(opts) {
|
|
7
|
-
const {
|
|
8
|
-
title = "",
|
|
9
|
-
hint,
|
|
10
|
-
hintPlaceholderColor = "blue",
|
|
11
|
-
validate,
|
|
12
|
-
defaultValue,
|
|
13
|
-
titleColor = "cyan",
|
|
14
|
-
titleTypography = "none",
|
|
15
|
-
titleVariant,
|
|
16
|
-
content,
|
|
17
|
-
contentColor = "dim",
|
|
18
|
-
contentTypography = "italic",
|
|
19
|
-
contentVariant,
|
|
20
|
-
borderColor = "dim",
|
|
21
|
-
variantOptions,
|
|
22
|
-
inline = true,
|
|
23
|
-
choices
|
|
24
|
-
} = opts;
|
|
25
|
-
if (!choices || choices.length === 0) {
|
|
26
|
-
throw new Error("Choices are required for select prompt.");
|
|
27
|
-
}
|
|
28
|
-
const rl = readline.createInterface({ input, output });
|
|
29
|
-
const formattedBar = bar({ borderColor });
|
|
30
|
-
let linesToDelete = 0;
|
|
31
|
-
let errorMessage = "";
|
|
32
|
-
while (true) {
|
|
33
|
-
if (linesToDelete > 0) {
|
|
34
|
-
deleteLastLines(linesToDelete);
|
|
35
|
-
}
|
|
36
|
-
const { text: question } = fmt({
|
|
37
|
-
hintPlaceholderColor,
|
|
38
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
39
|
-
title,
|
|
40
|
-
titleColor,
|
|
41
|
-
titleTypography,
|
|
42
|
-
...titleVariant !== void 0 && { titleVariant },
|
|
43
|
-
content,
|
|
44
|
-
contentColor,
|
|
45
|
-
contentTypography,
|
|
46
|
-
...contentVariant !== void 0 && { contentVariant },
|
|
47
|
-
borderColor,
|
|
48
|
-
...hint !== void 0 && { hint },
|
|
49
|
-
...variantOptions !== void 0 && { variantOptions },
|
|
50
|
-
errorMessage
|
|
51
|
-
});
|
|
52
|
-
let choicesText = "";
|
|
53
|
-
if (inline) {
|
|
54
|
-
choicesText = choices.map(
|
|
55
|
-
(choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` (${choice.description})` : ""}`
|
|
56
|
-
).join(" / ");
|
|
57
|
-
} else {
|
|
58
|
-
choicesText = choices.map(
|
|
59
|
-
(choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
|
|
60
|
-
).join(`
|
|
61
|
-
${formattedBar} `);
|
|
62
|
-
}
|
|
63
|
-
const { text: formattedPrompt } = fmt({
|
|
64
|
-
hintPlaceholderColor,
|
|
65
|
-
type: "M_NULL",
|
|
66
|
-
title: `${question}
|
|
67
|
-
${choicesText}
|
|
68
|
-
${formattedBar} ${colorize(
|
|
69
|
-
"Enter your choice:",
|
|
70
|
-
contentColor
|
|
71
|
-
)}
|
|
72
|
-
${formattedBar} `
|
|
73
|
-
});
|
|
74
|
-
const questionLines = countLines(formattedPrompt);
|
|
75
|
-
linesToDelete = questionLines + 1;
|
|
76
|
-
const prompt = await rl.question(formattedPrompt);
|
|
77
|
-
const answer = prompt.trim() || defaultValue;
|
|
78
|
-
if (!prompt.trim() && defaultValue !== void 0) {
|
|
79
|
-
deleteLastLine();
|
|
80
|
-
msg({
|
|
81
|
-
type: "M_MIDDLE",
|
|
82
|
-
title: ` ${defaultValue}`,
|
|
83
|
-
titleColor: "none"
|
|
84
|
-
});
|
|
85
|
-
msg({ type: "M_BAR", borderColor });
|
|
86
|
-
}
|
|
87
|
-
const num = Number(answer);
|
|
88
|
-
if (Number.isNaN(num) || num < 1 || num > choices.length) {
|
|
89
|
-
errorMessage = `Please enter a number between 1 and ${choices.length}.`;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const selectedChoice = choices[num - 1];
|
|
93
|
-
const selectedValue = selectedChoice?.id ?? num;
|
|
94
|
-
let isValid = true;
|
|
95
|
-
errorMessage = "";
|
|
96
|
-
if (validate && isValid) {
|
|
97
|
-
const validation = await validate(selectedValue);
|
|
98
|
-
if (validation !== true) {
|
|
99
|
-
isValid = false;
|
|
100
|
-
errorMessage = typeof validation === "string" ? validation : "Invalid input.";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (isValid) {
|
|
104
|
-
rl.close();
|
|
105
|
-
if (selectedChoice?.action) {
|
|
106
|
-
await selectedChoice.action();
|
|
107
|
-
}
|
|
108
|
-
return selectedValue;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { SelectPromptParams } from "../../types";
|
|
2
|
-
export declare const select: <T extends string>(params: SelectPromptParams<T>) => Promise<T>;
|
|
3
|
-
export declare const selectSimple: <T extends string>(params: Omit<SelectPromptParams<T>, "options"> & {
|
|
4
|
-
options: {
|
|
5
|
-
value: T;
|
|
6
|
-
label?: string;
|
|
7
|
-
hint?: string;
|
|
8
|
-
}[];
|
|
9
|
-
}) => Promise<T>;
|
|
@@ -1,311 +0,0 @@
|
|
|
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
|
-
import { streamText } from "../utils/stream-text.js";
|
|
9
|
-
function isSelectOption(option) {
|
|
10
|
-
return !("separator" in option);
|
|
11
|
-
}
|
|
12
|
-
async function renderPromptUI(params) {
|
|
13
|
-
const {
|
|
14
|
-
title,
|
|
15
|
-
content,
|
|
16
|
-
options,
|
|
17
|
-
selectedIndex,
|
|
18
|
-
errorMessage,
|
|
19
|
-
displayInstructions,
|
|
20
|
-
allDisabled,
|
|
21
|
-
instructions,
|
|
22
|
-
titleColor,
|
|
23
|
-
contentColor,
|
|
24
|
-
contentTypography,
|
|
25
|
-
debug,
|
|
26
|
-
titleVariant,
|
|
27
|
-
titleTypography,
|
|
28
|
-
isRerender = false,
|
|
29
|
-
shouldStream = false,
|
|
30
|
-
streamDelay = 20
|
|
31
|
-
} = params;
|
|
32
|
-
if (!isRerender) {
|
|
33
|
-
if (shouldStream) {
|
|
34
|
-
deleteLastLine();
|
|
35
|
-
msg({ type: "M_BAR", title: "" });
|
|
36
|
-
await streamText({
|
|
37
|
-
text: title,
|
|
38
|
-
delay: streamDelay,
|
|
39
|
-
color: titleColor,
|
|
40
|
-
newline: false,
|
|
41
|
-
clearLine: true
|
|
42
|
-
});
|
|
43
|
-
process.stdout.write("\r");
|
|
44
|
-
msg({
|
|
45
|
-
type: "M_GENERAL",
|
|
46
|
-
title,
|
|
47
|
-
titleColor,
|
|
48
|
-
...titleVariant !== void 0 && { titleVariant },
|
|
49
|
-
...titleTypography !== void 0 && { titleTypography }
|
|
50
|
-
});
|
|
51
|
-
if (content) {
|
|
52
|
-
msg({
|
|
53
|
-
type: "M_NULL",
|
|
54
|
-
content,
|
|
55
|
-
contentColor,
|
|
56
|
-
contentTypography
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
msg({ type: "M_GENERAL", title, titleColor });
|
|
61
|
-
if (content) {
|
|
62
|
-
msg({
|
|
63
|
-
type: "M_NULL",
|
|
64
|
-
content,
|
|
65
|
-
contentColor,
|
|
66
|
-
contentTypography
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
let uiLineCount = 0;
|
|
72
|
-
if (errorMessage) {
|
|
73
|
-
msg({
|
|
74
|
-
type: "M_ERROR",
|
|
75
|
-
title: `${re.redBright(symbols.step_error)} ${re.redBright(errorMessage)}`
|
|
76
|
-
});
|
|
77
|
-
uiLineCount++;
|
|
78
|
-
} else if (allDisabled) {
|
|
79
|
-
msg({ type: "M_ERROR", title: re.redBright("All options are disabled.") });
|
|
80
|
-
uiLineCount++;
|
|
81
|
-
} else if (displayInstructions && !isRerender) {
|
|
82
|
-
msg({ type: "M_NULL", title: re.blue(instructions) });
|
|
83
|
-
uiLineCount++;
|
|
84
|
-
}
|
|
85
|
-
for (let index = 0; index < options.length; index++) {
|
|
86
|
-
const option = options[index];
|
|
87
|
-
if (!option) continue;
|
|
88
|
-
if (!isSelectOption(option)) {
|
|
89
|
-
const width = option.width ?? 20;
|
|
90
|
-
const symbolKey = option.symbol ?? "line";
|
|
91
|
-
const lineSymbol = symbolKey in symbols ? symbols[symbolKey] : "\u2500";
|
|
92
|
-
msg({ type: "M_NULL", title: re.dim(lineSymbol.repeat(width)) });
|
|
93
|
-
uiLineCount++;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const isSelected = index === selectedIndex;
|
|
97
|
-
const isDisabled = option.disabled;
|
|
98
|
-
const prefix = isSelected ? re.dim(re.reset("> ")) : " ";
|
|
99
|
-
const labelColor = isDisabled ? re.dim(re.reset(option.label)) : isSelected ? re.reset(re.yellow(option.label)) : re.reset(option.label);
|
|
100
|
-
const hint = option.hint ? re.reset(` (${isDisabled ? re.dim(option.hint) : re.italic(re.dim(option.hint))})`) : "";
|
|
101
|
-
msg({ type: "M_NULL", title: `${prefix}${labelColor}${hint}` });
|
|
102
|
-
uiLineCount++;
|
|
103
|
-
}
|
|
104
|
-
if (debug) {
|
|
105
|
-
relinka("log", "", { optionsCount: options.length });
|
|
106
|
-
}
|
|
107
|
-
return uiLineCount;
|
|
108
|
-
}
|
|
109
|
-
export async function selectPrompt(params) {
|
|
110
|
-
const {
|
|
111
|
-
title = "",
|
|
112
|
-
message,
|
|
113
|
-
content = "",
|
|
114
|
-
options,
|
|
115
|
-
optionsArray,
|
|
116
|
-
defaultValue,
|
|
117
|
-
initialValue,
|
|
118
|
-
required = false,
|
|
119
|
-
borderColor = "dim",
|
|
120
|
-
titleColor = "cyan",
|
|
121
|
-
titleTypography = "none",
|
|
122
|
-
titleVariant,
|
|
123
|
-
contentColor = "dim",
|
|
124
|
-
contentTypography = "italic",
|
|
125
|
-
border = true,
|
|
126
|
-
endTitle = "",
|
|
127
|
-
endTitleColor = "dim",
|
|
128
|
-
debug = false,
|
|
129
|
-
terminalWidth: customTerminalWidth = 90,
|
|
130
|
-
displayInstructions = false,
|
|
131
|
-
shouldStream = false,
|
|
132
|
-
streamDelay = 20
|
|
133
|
-
} = params;
|
|
134
|
-
const finalTitle = message && title ? `${title}: ${message}` : message ?? title ?? "Select option";
|
|
135
|
-
const finalDefaultValue = defaultValue ?? initialValue;
|
|
136
|
-
const finalOptions = options ?? optionsArray?.map((opt) => ({
|
|
137
|
-
value: opt.value,
|
|
138
|
-
label: opt.label ?? opt.value,
|
|
139
|
-
...opt.hint !== void 0 && { hint: opt.hint },
|
|
140
|
-
disabled: false
|
|
141
|
-
})) ?? [];
|
|
142
|
-
let selectedIndex = finalDefaultValue ? finalOptions.findIndex(
|
|
143
|
-
(option) => isSelectOption(option) && option.value === finalDefaultValue && !option.disabled
|
|
144
|
-
) : -1;
|
|
145
|
-
if (selectedIndex === -1) {
|
|
146
|
-
selectedIndex = finalOptions.findIndex((option) => isSelectOption(option) && !option.disabled);
|
|
147
|
-
}
|
|
148
|
-
if (selectedIndex === -1) {
|
|
149
|
-
selectedIndex = 0;
|
|
150
|
-
}
|
|
151
|
-
const rl = readline.createInterface({ input, output });
|
|
152
|
-
readline.emitKeypressEvents(input, rl);
|
|
153
|
-
if (typeof input.setRawMode === "function") {
|
|
154
|
-
input.setRawMode(true);
|
|
155
|
-
}
|
|
156
|
-
const instructions = "Use <\u2191/\u2193> or <k/j> to navigate, <Enter> to select, <Ctrl+C> to exit";
|
|
157
|
-
let errorMessage = "";
|
|
158
|
-
const allDisabled = finalOptions.every((option) => isSelectOption(option) && option.disabled);
|
|
159
|
-
let lastUILineCount = 0;
|
|
160
|
-
function renderOptions() {
|
|
161
|
-
if (lastUILineCount > 0) {
|
|
162
|
-
for (let i = 0; i < lastUILineCount; i++) {
|
|
163
|
-
process.stdout.write("\x1B[1A\x1B[2K");
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
void renderPromptUI({
|
|
167
|
-
title: finalTitle,
|
|
168
|
-
content,
|
|
169
|
-
options: finalOptions,
|
|
170
|
-
selectedIndex,
|
|
171
|
-
errorMessage,
|
|
172
|
-
displayInstructions,
|
|
173
|
-
allDisabled,
|
|
174
|
-
instructions,
|
|
175
|
-
borderColor,
|
|
176
|
-
titleColor,
|
|
177
|
-
contentColor,
|
|
178
|
-
contentTypography,
|
|
179
|
-
debug,
|
|
180
|
-
...titleVariant !== void 0 && { titleVariant },
|
|
181
|
-
...titleTypography !== void 0 && { titleTypography },
|
|
182
|
-
terminalWidth: customTerminalWidth,
|
|
183
|
-
isRerender: true,
|
|
184
|
-
shouldStream,
|
|
185
|
-
streamDelay
|
|
186
|
-
}).then((count) => {
|
|
187
|
-
lastUILineCount = count;
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
lastUILineCount = await renderPromptUI({
|
|
191
|
-
title: finalTitle,
|
|
192
|
-
content,
|
|
193
|
-
options: finalOptions,
|
|
194
|
-
selectedIndex,
|
|
195
|
-
errorMessage,
|
|
196
|
-
displayInstructions,
|
|
197
|
-
allDisabled,
|
|
198
|
-
instructions,
|
|
199
|
-
borderColor,
|
|
200
|
-
titleColor,
|
|
201
|
-
contentColor,
|
|
202
|
-
contentTypography,
|
|
203
|
-
debug,
|
|
204
|
-
...titleVariant !== void 0 && { titleVariant },
|
|
205
|
-
...titleTypography !== void 0 && { titleTypography },
|
|
206
|
-
terminalWidth: customTerminalWidth,
|
|
207
|
-
isRerender: false,
|
|
208
|
-
shouldStream,
|
|
209
|
-
streamDelay
|
|
210
|
-
});
|
|
211
|
-
return new Promise((resolve) => {
|
|
212
|
-
function handleKeypress(_str, key) {
|
|
213
|
-
if (allDisabled) {
|
|
214
|
-
if (key.name === "c" && key.ctrl) {
|
|
215
|
-
void endPrompt(true);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (key.name === "up" || key.name === "k") {
|
|
221
|
-
moveSelectionUp();
|
|
222
|
-
} else if (key.name === "down" || key.name === "j") {
|
|
223
|
-
moveSelectionDown();
|
|
224
|
-
} else if (key.name === "return") {
|
|
225
|
-
void confirmSelection();
|
|
226
|
-
} else if (key.name === "c" && key.ctrl) {
|
|
227
|
-
void endPrompt(true);
|
|
228
|
-
} else {
|
|
229
|
-
void endPrompt(true);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
function moveSelectionUp() {
|
|
233
|
-
const originalPointer = selectedIndex;
|
|
234
|
-
do {
|
|
235
|
-
selectedIndex = (selectedIndex - 1 + finalOptions.length) % finalOptions.length;
|
|
236
|
-
const option = finalOptions[selectedIndex];
|
|
237
|
-
if (option && isSelectOption(option) && !option.disabled) break;
|
|
238
|
-
} while (selectedIndex !== originalPointer);
|
|
239
|
-
renderOptions();
|
|
240
|
-
}
|
|
241
|
-
function moveSelectionDown() {
|
|
242
|
-
const originalPointer = selectedIndex;
|
|
243
|
-
do {
|
|
244
|
-
selectedIndex = (selectedIndex + 1) % finalOptions.length;
|
|
245
|
-
const option = finalOptions[selectedIndex];
|
|
246
|
-
if (option && isSelectOption(option) && !option.disabled) break;
|
|
247
|
-
} while (selectedIndex !== originalPointer);
|
|
248
|
-
renderOptions();
|
|
249
|
-
}
|
|
250
|
-
async function confirmSelection() {
|
|
251
|
-
const option = finalOptions[selectedIndex];
|
|
252
|
-
if (!option || !isSelectOption(option)) {
|
|
253
|
-
errorMessage = "This option is not selectable.";
|
|
254
|
-
renderOptions();
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (option.disabled) {
|
|
258
|
-
errorMessage = "This option is disabled";
|
|
259
|
-
renderOptions();
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (required && (!option.value || option.value === "")) {
|
|
263
|
-
errorMessage = "You must select a valid option.";
|
|
264
|
-
renderOptions();
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
cleanup();
|
|
268
|
-
resolve(option.value);
|
|
269
|
-
deleteLastLine();
|
|
270
|
-
await completePrompt(
|
|
271
|
-
"select",
|
|
272
|
-
false,
|
|
273
|
-
endTitle,
|
|
274
|
-
endTitleColor,
|
|
275
|
-
titleTypography,
|
|
276
|
-
titleVariant ? titleVariant : void 0,
|
|
277
|
-
border,
|
|
278
|
-
borderColor,
|
|
279
|
-
void 0,
|
|
280
|
-
true
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
async function endPrompt(isCtrlC = false) {
|
|
284
|
-
deleteLastLine();
|
|
285
|
-
await completePrompt(
|
|
286
|
-
"select",
|
|
287
|
-
isCtrlC,
|
|
288
|
-
endTitle,
|
|
289
|
-
endTitleColor,
|
|
290
|
-
titleTypography,
|
|
291
|
-
titleVariant ? titleVariant : void 0,
|
|
292
|
-
border,
|
|
293
|
-
borderColor,
|
|
294
|
-
void 0,
|
|
295
|
-
false
|
|
296
|
-
);
|
|
297
|
-
cleanup(isCtrlC);
|
|
298
|
-
}
|
|
299
|
-
function cleanup(isCtrlC = false) {
|
|
300
|
-
if (typeof input.setRawMode === "function") {
|
|
301
|
-
input.setRawMode(false);
|
|
302
|
-
}
|
|
303
|
-
rl.close();
|
|
304
|
-
input.removeListener("keypress", handleKeypress);
|
|
305
|
-
if (isCtrlC) {
|
|
306
|
-
process.exit(0);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
input.on("keypress", handleKeypress);
|
|
310
|
-
});
|
|
311
|
-
}
|