@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,14 @@
|
|
|
1
|
+
import { type Animation, type AnimationName } from "@figliolia/chalk-animation";
|
|
2
|
+
import type { BorderColorName, ColorName, MsgType, TypographyName } from "../../types";
|
|
3
|
+
export declare const animationMap: Record<AnimationName, (text: string) => Animation>;
|
|
4
|
+
export declare function animateText({ title, anim, delay, type, titleColor, titleTypography, border, borderColor, horizontalLineLength, }: {
|
|
5
|
+
title: string;
|
|
6
|
+
anim: AnimationName;
|
|
7
|
+
delay?: number;
|
|
8
|
+
type?: MsgType;
|
|
9
|
+
titleColor?: ColorName;
|
|
10
|
+
titleTypography?: TypographyName;
|
|
11
|
+
borderColor?: BorderColorName;
|
|
12
|
+
border?: boolean;
|
|
13
|
+
horizontalLineLength?: number;
|
|
14
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ChalkAnimation } from "@figliolia/chalk-animation";
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
4
|
+
import { deleteLastLine, getTerminalWidth } from "../msg-fmt/terminal.js";
|
|
5
|
+
export const animationMap = {
|
|
6
|
+
rainbow: ChalkAnimation.rainbow,
|
|
7
|
+
pulse: ChalkAnimation.pulse,
|
|
8
|
+
glitch: ChalkAnimation.glitch,
|
|
9
|
+
radar: ChalkAnimation.radar,
|
|
10
|
+
neon: ChalkAnimation.neon,
|
|
11
|
+
karaoke: ChalkAnimation.karaoke
|
|
12
|
+
};
|
|
13
|
+
function calculateDelay(text) {
|
|
14
|
+
const baseDelay = 1e3;
|
|
15
|
+
const delayPerCharacter = 50;
|
|
16
|
+
return baseDelay + text.length * delayPerCharacter;
|
|
17
|
+
}
|
|
18
|
+
export async function animateText({
|
|
19
|
+
title = "",
|
|
20
|
+
anim,
|
|
21
|
+
delay,
|
|
22
|
+
type = "M_INFO",
|
|
23
|
+
titleColor = "cyan",
|
|
24
|
+
titleTypography = "none",
|
|
25
|
+
border = true,
|
|
26
|
+
borderColor = "dim",
|
|
27
|
+
horizontalLineLength = 0
|
|
28
|
+
}) {
|
|
29
|
+
if (horizontalLineLength === 0) {
|
|
30
|
+
horizontalLineLength = getTerminalWidth() - 5;
|
|
31
|
+
}
|
|
32
|
+
const finalDelay = delay ?? calculateDelay(title);
|
|
33
|
+
const animation = animationMap[anim](title);
|
|
34
|
+
try {
|
|
35
|
+
await new Promise((resolve) => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
animation.stop();
|
|
38
|
+
deleteLastLine();
|
|
39
|
+
if (title.includes("\u2502 ")) {
|
|
40
|
+
title = title.replace("\u2502 ", "");
|
|
41
|
+
} else if (title.includes("\u2139 ")) {
|
|
42
|
+
title = title.replace("\u2139 ", "");
|
|
43
|
+
}
|
|
44
|
+
msg({
|
|
45
|
+
type,
|
|
46
|
+
title,
|
|
47
|
+
titleColor,
|
|
48
|
+
titleTypography,
|
|
49
|
+
content: "",
|
|
50
|
+
borderColor,
|
|
51
|
+
border,
|
|
52
|
+
horizontalLineLength
|
|
53
|
+
});
|
|
54
|
+
resolve();
|
|
55
|
+
}, finalDelay);
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
relinka("error", "Animation failed to complete.", error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ColorName } from "../../types";
|
|
2
|
+
interface Options {
|
|
3
|
+
ctrlC?: number | false | "reject";
|
|
4
|
+
preserveLog?: boolean;
|
|
5
|
+
hideMessage?: boolean;
|
|
6
|
+
shouldStream?: boolean;
|
|
7
|
+
streamDelay?: number;
|
|
8
|
+
color?: ColorName;
|
|
9
|
+
placeholderColor?: ColorName;
|
|
10
|
+
}
|
|
11
|
+
export declare function anykeyPrompt(message?: string, options?: Options): Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import logUpdate from "log-update";
|
|
2
|
+
import { cursor } from "sisteransi";
|
|
3
|
+
import { fmt } from "../msg-fmt/messages.js";
|
|
4
|
+
import { outroPrompt } from "../outro/outro-mod.js";
|
|
5
|
+
import { streamText } from "../utils/stream-text.js";
|
|
6
|
+
const DEFAULT_MESSAGE = "Press any key to continue...";
|
|
7
|
+
const CTRL_C_CODE = 3;
|
|
8
|
+
const terminal = {
|
|
9
|
+
/**
|
|
10
|
+
* Move cursor to start of line
|
|
11
|
+
*/
|
|
12
|
+
moveToStart: () => process.stdout.write("\r"),
|
|
13
|
+
/**
|
|
14
|
+
* Clear current line and move cursor up
|
|
15
|
+
*/
|
|
16
|
+
clearLineAndMoveUp: () => process.stdout.write("\x1B[1A\x1B[2K"),
|
|
17
|
+
/**
|
|
18
|
+
* Clear multiple lines above current position
|
|
19
|
+
*/
|
|
20
|
+
clearLines: (count) => {
|
|
21
|
+
terminal.moveToStart();
|
|
22
|
+
process.stdout.write("\x1B[2K");
|
|
23
|
+
for (let i = 0; i < count; i++) {
|
|
24
|
+
terminal.clearLineAndMoveUp();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export async function anykeyPrompt(message = DEFAULT_MESSAGE, options = {}) {
|
|
29
|
+
const {
|
|
30
|
+
ctrlC = 1,
|
|
31
|
+
preserveLog = false,
|
|
32
|
+
hideMessage = false,
|
|
33
|
+
shouldStream = false,
|
|
34
|
+
streamDelay = 20,
|
|
35
|
+
color = "dim",
|
|
36
|
+
placeholderColor = "gray"
|
|
37
|
+
} = options;
|
|
38
|
+
if (message) {
|
|
39
|
+
if (!shouldStream) {
|
|
40
|
+
const { text } = fmt({
|
|
41
|
+
hintPlaceholderColor: placeholderColor,
|
|
42
|
+
type: "M_GENERAL",
|
|
43
|
+
title: message,
|
|
44
|
+
titleColor: color,
|
|
45
|
+
dontRemoveBar: true
|
|
46
|
+
});
|
|
47
|
+
message = text;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (message && !hideMessage) {
|
|
51
|
+
if (shouldStream) {
|
|
52
|
+
await streamText({
|
|
53
|
+
text: `\u25C6 ${message}`,
|
|
54
|
+
delay: streamDelay,
|
|
55
|
+
newline: false,
|
|
56
|
+
clearLine: true,
|
|
57
|
+
color
|
|
58
|
+
});
|
|
59
|
+
const lineCount = message.split("\n").length;
|
|
60
|
+
terminal.clearLines(lineCount);
|
|
61
|
+
const { text } = fmt({
|
|
62
|
+
hintPlaceholderColor: placeholderColor,
|
|
63
|
+
type: "M_GENERAL",
|
|
64
|
+
title: message,
|
|
65
|
+
titleColor: color,
|
|
66
|
+
dontRemoveBar: true
|
|
67
|
+
});
|
|
68
|
+
terminal.moveToStart();
|
|
69
|
+
logUpdate(text);
|
|
70
|
+
} else {
|
|
71
|
+
logUpdate(message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const cleanup = () => {
|
|
76
|
+
process.stdin.removeListener("data", handler);
|
|
77
|
+
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
78
|
+
process.stdin.setRawMode(false);
|
|
79
|
+
}
|
|
80
|
+
process.stdin.pause();
|
|
81
|
+
process.stdout.write(cursor.show);
|
|
82
|
+
};
|
|
83
|
+
const handleCtrlC = () => {
|
|
84
|
+
cleanup();
|
|
85
|
+
void outroPrompt({
|
|
86
|
+
title: "\u270B User pressed Ctrl+C, exiting...",
|
|
87
|
+
titleAnimation: "pulse",
|
|
88
|
+
titleColor: "redBright",
|
|
89
|
+
titleTypography: "bold",
|
|
90
|
+
endTitleColor: "redBright",
|
|
91
|
+
titleAnimationDelay: 400
|
|
92
|
+
}).then(() => {
|
|
93
|
+
if (ctrlC === "reject") {
|
|
94
|
+
reject(new Error("User pressed CTRL+C"));
|
|
95
|
+
} else if (ctrlC === false) {
|
|
96
|
+
resolve();
|
|
97
|
+
} else if (typeof ctrlC === "number") {
|
|
98
|
+
process.exit(0);
|
|
99
|
+
} else {
|
|
100
|
+
throw new TypeError("Invalid ctrlC option");
|
|
101
|
+
}
|
|
102
|
+
}).catch(reject);
|
|
103
|
+
};
|
|
104
|
+
const handler = (buffer) => {
|
|
105
|
+
cleanup();
|
|
106
|
+
if (message && !preserveLog) {
|
|
107
|
+
logUpdate.clear();
|
|
108
|
+
} else {
|
|
109
|
+
logUpdate.done();
|
|
110
|
+
process.stdout.write("\n");
|
|
111
|
+
}
|
|
112
|
+
const [firstByte] = buffer;
|
|
113
|
+
if (firstByte === CTRL_C_CODE) {
|
|
114
|
+
handleCtrlC();
|
|
115
|
+
} else {
|
|
116
|
+
resolve();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
process.stdin.resume();
|
|
120
|
+
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
121
|
+
process.stdin.setRawMode(true);
|
|
122
|
+
}
|
|
123
|
+
process.stdin.once("data", handler);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* Special value that indicates a cancelled operation
|
|
4
|
+
*/
|
|
5
|
+
export declare const CANCEL: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Type for the cancel value
|
|
8
|
+
*/
|
|
9
|
+
export type CancelValue = typeof CANCEL;
|
|
10
|
+
export declare const isWindows: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Sets raw mode on input stream
|
|
13
|
+
*/
|
|
14
|
+
export declare function setRawMode(input: Readable, value: boolean): void;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the number of columns in the terminal
|
|
17
|
+
*/
|
|
18
|
+
export declare function getColumns(output: Writable): number;
|
|
19
|
+
interface BlockOptions {
|
|
20
|
+
input?: Readable;
|
|
21
|
+
output?: Writable;
|
|
22
|
+
overwrite?: boolean;
|
|
23
|
+
hideCursor?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a block for handling input with proper cursor and cleanup
|
|
27
|
+
*/
|
|
28
|
+
export declare function block({ input, output, overwrite, hideCursor, }?: BlockOptions): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a value represents a cancelled operation
|
|
31
|
+
* @param value - The value to check
|
|
32
|
+
* @returns true if the value represents a cancelled operation
|
|
33
|
+
*/
|
|
34
|
+
export declare function isCancel(value: unknown): value is CancelValue;
|
|
35
|
+
/**
|
|
36
|
+
* Handles cancellation of an operation
|
|
37
|
+
* @param message - Optional message to display before exiting
|
|
38
|
+
*/
|
|
39
|
+
export declare function cancel(message?: string): never;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a cancel value that can be returned from operations
|
|
42
|
+
* @returns The cancel value
|
|
43
|
+
*/
|
|
44
|
+
export declare function createCancel(): CancelValue;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { stdin, stdout } from "node:process";
|
|
2
|
+
import * as readline from "node:readline";
|
|
3
|
+
import { ReadStream, WriteStream } from "node:tty";
|
|
4
|
+
import { cursor } from "sisteransi";
|
|
5
|
+
export const CANCEL = Symbol("CANCEL");
|
|
6
|
+
export const isWindows = globalThis.process.platform.startsWith("win");
|
|
7
|
+
export function setRawMode(input, value) {
|
|
8
|
+
const i = input;
|
|
9
|
+
if (i.isTTY) i.setRawMode(value);
|
|
10
|
+
}
|
|
11
|
+
export function getColumns(output) {
|
|
12
|
+
if (output instanceof WriteStream && output.columns) {
|
|
13
|
+
return output.columns;
|
|
14
|
+
}
|
|
15
|
+
return 80;
|
|
16
|
+
}
|
|
17
|
+
export function block({
|
|
18
|
+
input = stdin,
|
|
19
|
+
output = stdout,
|
|
20
|
+
overwrite = true,
|
|
21
|
+
hideCursor = true
|
|
22
|
+
} = {}) {
|
|
23
|
+
const rl = readline.createInterface({
|
|
24
|
+
input,
|
|
25
|
+
output,
|
|
26
|
+
prompt: "",
|
|
27
|
+
tabSize: 1
|
|
28
|
+
});
|
|
29
|
+
readline.emitKeypressEvents(input, rl);
|
|
30
|
+
if (input instanceof ReadStream && input.isTTY) {
|
|
31
|
+
input.setRawMode(true);
|
|
32
|
+
}
|
|
33
|
+
const clear = (data, { name, sequence }) => {
|
|
34
|
+
const str = String(data);
|
|
35
|
+
if (str === "" || name === "c" && sequence === "") {
|
|
36
|
+
if (hideCursor) output.write(cursor.show);
|
|
37
|
+
process.exit(0);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!overwrite) return;
|
|
41
|
+
const dx = name === "return" ? 0 : -1;
|
|
42
|
+
const dy = name === "return" ? -1 : 0;
|
|
43
|
+
readline.moveCursor(output, dx, dy, () => {
|
|
44
|
+
readline.clearLine(output, 1, () => {
|
|
45
|
+
input.once("keypress", clear);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
if (hideCursor) output.write(cursor.hide);
|
|
50
|
+
input.once("keypress", clear);
|
|
51
|
+
return () => {
|
|
52
|
+
input.off("keypress", clear);
|
|
53
|
+
if (hideCursor) output.write(cursor.show);
|
|
54
|
+
if (input instanceof ReadStream && input.isTTY && !isWindows) {
|
|
55
|
+
input.setRawMode(false);
|
|
56
|
+
}
|
|
57
|
+
rl.terminal = false;
|
|
58
|
+
rl.close();
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function isCancel(value) {
|
|
62
|
+
return value === CANCEL;
|
|
63
|
+
}
|
|
64
|
+
export function cancel(message) {
|
|
65
|
+
if (message) {
|
|
66
|
+
console.log(message);
|
|
67
|
+
}
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
export function createCancel() {
|
|
71
|
+
return CANCEL;
|
|
72
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
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, msg } from "../msg-fmt/messages.js";
|
|
5
|
+
import { deleteLastLine } from "../msg-fmt/terminal.js";
|
|
6
|
+
import { completePrompt } from "../utils/prompt-end.js";
|
|
7
|
+
function renderPrompt(params) {
|
|
8
|
+
const {
|
|
9
|
+
title,
|
|
10
|
+
content,
|
|
11
|
+
borderColor,
|
|
12
|
+
titleColor,
|
|
13
|
+
titleTypography,
|
|
14
|
+
titleVariant,
|
|
15
|
+
contentColor,
|
|
16
|
+
contentTypography,
|
|
17
|
+
contentVariant,
|
|
18
|
+
hintPlaceholderColor,
|
|
19
|
+
border,
|
|
20
|
+
variantOptions,
|
|
21
|
+
errorMessage,
|
|
22
|
+
displayInstructions,
|
|
23
|
+
instructions,
|
|
24
|
+
isRerender = false
|
|
25
|
+
} = params;
|
|
26
|
+
let uiLineCount = 0;
|
|
27
|
+
if (!isRerender) {
|
|
28
|
+
msg({
|
|
29
|
+
hintPlaceholderColor,
|
|
30
|
+
type: errorMessage ? "M_ERROR" : "M_GENERAL",
|
|
31
|
+
title,
|
|
32
|
+
titleColor,
|
|
33
|
+
titleTypography,
|
|
34
|
+
...titleVariant ? { titleVariant } : {},
|
|
35
|
+
...content ? {
|
|
36
|
+
content: content.split("\n").map((line) => line.trim()).join("\n")
|
|
37
|
+
} : {},
|
|
38
|
+
contentColor,
|
|
39
|
+
contentTypography,
|
|
40
|
+
...contentVariant ? { contentVariant } : {},
|
|
41
|
+
borderColor,
|
|
42
|
+
variantOptions,
|
|
43
|
+
errorMessage,
|
|
44
|
+
border
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (displayInstructions && !isRerender) {
|
|
48
|
+
msg({
|
|
49
|
+
type: "M_NULL",
|
|
50
|
+
title: re.blue(instructions)
|
|
51
|
+
});
|
|
52
|
+
uiLineCount++;
|
|
53
|
+
}
|
|
54
|
+
if (errorMessage) {
|
|
55
|
+
msg({
|
|
56
|
+
type: "M_NULL",
|
|
57
|
+
title: re.redBright(errorMessage)
|
|
58
|
+
});
|
|
59
|
+
uiLineCount++;
|
|
60
|
+
}
|
|
61
|
+
return uiLineCount;
|
|
62
|
+
}
|
|
63
|
+
export async function confirmPrompt(options) {
|
|
64
|
+
const {
|
|
65
|
+
title = "",
|
|
66
|
+
message,
|
|
67
|
+
// Alias for title
|
|
68
|
+
defaultValue,
|
|
69
|
+
initialValue,
|
|
70
|
+
// Alias for defaultValue
|
|
71
|
+
content,
|
|
72
|
+
titleColor = "cyan",
|
|
73
|
+
titleTypography = "none",
|
|
74
|
+
titleVariant,
|
|
75
|
+
contentColor = "dim",
|
|
76
|
+
contentTypography = "italic",
|
|
77
|
+
contentVariant,
|
|
78
|
+
borderColor = "dim",
|
|
79
|
+
hintPlaceholderColor = "blue",
|
|
80
|
+
variantOptions,
|
|
81
|
+
action,
|
|
82
|
+
displayInstructions = false,
|
|
83
|
+
endTitle = "",
|
|
84
|
+
endTitleColor = "dim",
|
|
85
|
+
border = true
|
|
86
|
+
} = options;
|
|
87
|
+
const finalTitle = message && title ? `${title}: ${message}` : message ?? title ?? "Confirm";
|
|
88
|
+
const finalDefaultValue = defaultValue ?? initialValue;
|
|
89
|
+
const rl = readline.createInterface({ input, output });
|
|
90
|
+
let errorMessage = "";
|
|
91
|
+
const effectiveDefault = finalDefaultValue ?? true;
|
|
92
|
+
const defaultHint = effectiveDefault ? "[Y/n]" : "[y/N]";
|
|
93
|
+
const adjustedTitle = displayInstructions ? finalTitle : `${re.blue(defaultHint)} ${finalTitle}`;
|
|
94
|
+
const instructions = `Use <y/n> to confirm or deny, <Enter> for default (${effectiveDefault ? "Y" : "N"}), <Ctrl+C> to exit`;
|
|
95
|
+
let lastUILineCount = 0;
|
|
96
|
+
function endPrompt(isCtrlC = false) {
|
|
97
|
+
if (endTitle !== "") {
|
|
98
|
+
msg({
|
|
99
|
+
type: "M_END",
|
|
100
|
+
title: endTitle,
|
|
101
|
+
titleColor: endTitleColor,
|
|
102
|
+
titleTypography,
|
|
103
|
+
...titleVariant ? { titleVariant } : {},
|
|
104
|
+
border,
|
|
105
|
+
borderColor
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
rl.close();
|
|
109
|
+
if (isCtrlC) {
|
|
110
|
+
process.exit(0);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
rl.on("SIGINT", () => {
|
|
114
|
+
endPrompt(true);
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
while (true) {
|
|
118
|
+
if (lastUILineCount > 0) {
|
|
119
|
+
for (let i = 0; i < lastUILineCount; i++) {
|
|
120
|
+
process.stdout.write("\x1B[1A\x1B[2K");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
lastUILineCount = renderPrompt({
|
|
124
|
+
title: adjustedTitle,
|
|
125
|
+
...content ? { content } : {},
|
|
126
|
+
borderColor,
|
|
127
|
+
titleColor,
|
|
128
|
+
titleTypography,
|
|
129
|
+
...titleVariant ? { titleVariant } : {},
|
|
130
|
+
contentColor,
|
|
131
|
+
contentTypography,
|
|
132
|
+
...contentVariant ? { contentVariant } : {},
|
|
133
|
+
hintPlaceholderColor,
|
|
134
|
+
border,
|
|
135
|
+
variantOptions,
|
|
136
|
+
errorMessage,
|
|
137
|
+
effectiveDefault,
|
|
138
|
+
displayInstructions,
|
|
139
|
+
defaultHint,
|
|
140
|
+
instructions,
|
|
141
|
+
isRerender: errorMessage !== ""
|
|
142
|
+
// Only rerender if there's an error
|
|
143
|
+
});
|
|
144
|
+
const formattedBar = bar({ borderColor });
|
|
145
|
+
const answer = (await rl.question(`${formattedBar} `)).toLowerCase().trim();
|
|
146
|
+
let result;
|
|
147
|
+
if (!answer) {
|
|
148
|
+
deleteLastLine();
|
|
149
|
+
msg({
|
|
150
|
+
type: "M_NULL",
|
|
151
|
+
title: `${formattedBar} ${effectiveDefault ? "y" : "n"}`
|
|
152
|
+
});
|
|
153
|
+
result = effectiveDefault;
|
|
154
|
+
} else if (answer === "y" || answer === "yes") {
|
|
155
|
+
result = true;
|
|
156
|
+
} else if (answer === "n" || answer === "no") {
|
|
157
|
+
result = false;
|
|
158
|
+
} else {
|
|
159
|
+
errorMessage = 'Please answer with "y" or "n".';
|
|
160
|
+
deleteLastLine();
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
return await completePrompt(
|
|
164
|
+
"confirm",
|
|
165
|
+
false,
|
|
166
|
+
endTitle,
|
|
167
|
+
endTitleColor,
|
|
168
|
+
titleTypography,
|
|
169
|
+
titleVariant ? titleVariant : void 0,
|
|
170
|
+
border,
|
|
171
|
+
borderColor,
|
|
172
|
+
action,
|
|
173
|
+
result
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
} finally {
|
|
177
|
+
rl.close();
|
|
178
|
+
}
|
|
179
|
+
}
|