@reliverse/relinka 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -41
- package/dist-npm/components/core/core.d.ts +2 -0
- package/dist-npm/components/core/core.js +2 -0
- package/dist-npm/{utils/constants.d.ts → components/levels/levels.d.ts} +1 -1
- package/dist-npm/components/{prompts/create.d.ts → modes/basic.d.ts} +3 -3
- package/dist-npm/components/{instance → modes}/basic.js +4 -4
- package/dist-npm/components/{instance → modes}/browser.d.ts +2 -2
- package/dist-npm/components/modes/browser.js +12 -0
- package/dist-npm/components/modes/shared.d.ts +5 -0
- package/dist-npm/components/modes/shared.js +2 -0
- package/dist-npm/components/{prompts → relinka}/relinka.d.ts +2 -4
- package/dist-npm/components/{prompts → relinka}/relinka.js +1 -7
- package/dist-npm/components/{instance/reporter → reporters}/basic.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/basic.js +2 -2
- package/dist-npm/components/{instance/reporter → reporters}/browser.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/fancy.d.ts +3 -3
- package/dist-npm/components/{instance/reporter → reporters}/fancy.js +5 -7
- package/dist-npm/main.d.ts +8 -1
- package/dist-npm/main.js +34 -1
- package/dist-npm/types/mod.d.ts +42 -0
- package/dist-npm/utils/color.js +4 -1
- package/dist-npm/utils/mod.d.ts +3 -0
- package/dist-npm/utils/mod.js +9 -0
- package/package.json +1 -1
- package/dist-npm/components/anykey/index.d.ts +0 -7
- package/dist-npm/components/anykey/index.js +0 -61
- package/dist-npm/components/block/block.d.ts +0 -10
- package/dist-npm/components/block/block.js +0 -52
- package/dist-npm/components/checkbox/index.d.ts +0 -3
- package/dist-npm/components/checkbox/index.js +0 -217
- package/dist-npm/components/confirm/confirm-main.d.ts +0 -3
- package/dist-npm/components/confirm/confirm-main.js +0 -98
- package/dist-npm/components/confirm/confirm-three.d.ts +0 -13
- package/dist-npm/components/confirm/confirm-three.js +0 -26
- package/dist-npm/components/confirm/index.d.ts +0 -2
- package/dist-npm/components/confirm/index.js +0 -41
- package/dist-npm/components/core/Separator.d.ts +0 -6
- package/dist-npm/components/core/Separator.js +0 -18
- package/dist-npm/components/core/create-prompt.d.ts +0 -4
- package/dist-npm/components/core/create-prompt.js +0 -107
- package/dist-npm/components/core/errors.d.ts +0 -20
- package/dist-npm/components/core/errors.js +0 -21
- package/dist-npm/components/core/hook-engine.d.ts +0 -23
- package/dist-npm/components/core/hook-engine.js +0 -109
- package/dist-npm/components/core/index.d.ts +0 -13
- package/dist-npm/components/core/index.js +0 -12
- package/dist-npm/components/core/key.d.ts +0 -10
- package/dist-npm/components/core/key.js +0 -16
- package/dist-npm/components/core/lines.d.ts +0 -14
- package/dist-npm/components/core/lines.js +0 -52
- package/dist-npm/components/core/make-theme.d.ts +0 -3
- package/dist-npm/components/core/make-theme.js +0 -28
- package/dist-npm/components/core/position.d.ts +0 -12
- package/dist-npm/components/core/position.js +0 -29
- package/dist-npm/components/core/promise-polyfill.d.ts +0 -7
- package/dist-npm/components/core/promise-polyfill.js +0 -13
- package/dist-npm/components/core/screen-manager.d.ts +0 -14
- package/dist-npm/components/core/screen-manager.js +0 -67
- package/dist-npm/components/core/theme.d.ts +0 -21
- package/dist-npm/components/core/theme.js +0 -24
- package/dist-npm/components/core/use-effect.d.ts +0 -2
- package/dist-npm/components/core/use-effect.js +0 -11
- package/dist-npm/components/core/use-keypress.d.ts +0 -3
- package/dist-npm/components/core/use-keypress.js +0 -21
- package/dist-npm/components/core/use-memo.d.ts +0 -1
- package/dist-npm/components/core/use-memo.js +0 -12
- package/dist-npm/components/core/use-pagination.d.ts +0 -11
- package/dist-npm/components/core/use-pagination.js +0 -34
- package/dist-npm/components/core/use-prefix.d.ts +0 -5
- package/dist-npm/components/core/use-prefix.js +0 -42
- package/dist-npm/components/core/use-ref.d.ts +0 -6
- package/dist-npm/components/core/use-ref.js +0 -4
- package/dist-npm/components/core/use-state.d.ts +0 -4
- package/dist-npm/components/core/use-state.js +0 -17
- package/dist-npm/components/core/useKeyPress.d.ts +0 -4
- package/dist-npm/components/core/useKeyPress.js +0 -16
- package/dist-npm/components/core/usePromptState.d.ts +0 -6
- package/dist-npm/components/core/usePromptState.js +0 -10
- package/dist-npm/components/core/utils.d.ts +0 -2
- package/dist-npm/components/core/utils.js +0 -11
- package/dist-npm/components/date/date.d.ts +0 -6
- package/dist-npm/components/date/date.js +0 -210
- package/dist-npm/components/editor/index.d.ts +0 -2
- package/dist-npm/components/editor/index.js +0 -78
- package/dist-npm/components/expand/index.d.ts +0 -3
- package/dist-npm/components/expand/index.js +0 -119
- package/dist-npm/components/figures/index.d.ts +0 -465
- package/dist-npm/components/figures/index.js +0 -299
- package/dist-npm/components/input/index.d.ts +0 -2
- package/dist-npm/components/input/index.js +0 -66
- package/dist-npm/components/input/text-main.d.ts +0 -3
- package/dist-npm/components/input/text-main.js +0 -103
- package/dist-npm/components/input/text.d.ts +0 -11
- package/dist-npm/components/input/text.js +0 -26
- package/dist-npm/components/instance/basic.d.ts +0 -8
- package/dist-npm/components/instance/browser.js +0 -18
- package/dist-npm/components/instance/shared.d.ts +0 -6
- package/dist-npm/components/instance/shared.js +0 -2
- package/dist-npm/components/mono/mono.d.ts +0 -5
- package/dist-npm/components/mono/mono.js +0 -64
- package/dist-npm/components/mono/monoTwo.d.ts +0 -30
- package/dist-npm/components/mono/monoTwo.js +0 -37
- package/dist-npm/components/multiselect/group-multiselect.d.ts +0 -23
- package/dist-npm/components/multiselect/group-multiselect.js +0 -58
- package/dist-npm/components/multiselect/multi-select-two.d.ts +0 -3
- package/dist-npm/components/multiselect/multi-select-two.js +0 -111
- package/dist-npm/components/multiselect/multi-select.d.ts +0 -21
- package/dist-npm/components/multiselect/multi-select.js +0 -45
- package/dist-npm/components/multiselect/multiselect-main.d.ts +0 -18
- package/dist-npm/components/multiselect/multiselect-main.js +0 -166
- package/dist-npm/components/multiselect/num-multi-select.d.ts +0 -3
- package/dist-npm/components/multiselect/num-multi-select.js +0 -111
- package/dist-npm/components/multiselect/num-multiselect-main.d.ts +0 -6
- package/dist-npm/components/multiselect/num-multiselect-main.js +0 -28
- package/dist-npm/components/next-steps/next-steps.d.ts +0 -2
- package/dist-npm/components/next-steps/next-steps.js +0 -24
- package/dist-npm/components/number/index.d.ts +0 -2
- package/dist-npm/components/number/index.js +0 -100
- package/dist-npm/components/number/number-main.d.ts +0 -3
- package/dist-npm/components/number/number-main.js +0 -95
- package/dist-npm/components/password/index.d.ts +0 -2
- package/dist-npm/components/password/index.js +0 -59
- package/dist-npm/components/password/password-main.d.ts +0 -3
- package/dist-npm/components/password/password-main.js +0 -119
- package/dist-npm/components/password/password-three.d.ts +0 -13
- package/dist-npm/components/password/password-three.js +0 -28
- package/dist-npm/components/progressbar/ProgressBar.d.ts +0 -22
- package/dist-npm/components/progressbar/ProgressBar.js +0 -53
- package/dist-npm/components/progressbar/helper.d.ts +0 -6
- package/dist-npm/components/progressbar/helper.js +0 -38
- package/dist-npm/components/progressbar/index.d.ts +0 -2
- package/dist-npm/components/progressbar/index.js +0 -1
- package/dist-npm/components/prompts/create.js +0 -35
- package/dist-npm/components/prompts/index.d.ts +0 -49
- package/dist-npm/components/prompts/index.js +0 -46
- package/dist-npm/components/prompts/prompt.d.ts +0 -36
- package/dist-npm/components/prompts/prompt.js +0 -232
- package/dist-npm/components/prompts/promptTwo.d.ts +0 -92
- package/dist-npm/components/prompts/promptTwo.js +0 -653
- package/dist-npm/components/range/range.d.ts +0 -62
- package/dist-npm/components/range/range.js +0 -270
- package/dist-npm/components/rawlist/index.d.ts +0 -3
- package/dist-npm/components/rawlist/index.js +0 -104
- package/dist-npm/components/results/results.d.ts +0 -10
- package/dist-npm/components/results/results.js +0 -34
- package/dist-npm/components/search/index.d.ts +0 -3
- package/dist-npm/components/search/index.js +0 -186
- package/dist-npm/components/select/index.d.ts +0 -3
- package/dist-npm/components/select/index.js +0 -176
- package/dist-npm/components/select/num-select-main.d.ts +0 -8
- package/dist-npm/components/select/num-select-main.js +0 -30
- package/dist-npm/components/select/num-select.d.ts +0 -5
- package/dist-npm/components/select/num-select.js +0 -125
- package/dist-npm/components/select/select-key.d.ts +0 -15
- package/dist-npm/components/select/select-key.js +0 -26
- package/dist-npm/components/select/select-main.d.ts +0 -19
- package/dist-npm/components/select/select-main.js +0 -151
- package/dist-npm/components/select/select-three.d.ts +0 -18
- package/dist-npm/components/select/select-three.js +0 -35
- package/dist-npm/components/select/select-two.d.ts +0 -2
- package/dist-npm/components/select/select-two.js +0 -98
- package/dist-npm/components/spinner/index.d.ts +0 -15
- package/dist-npm/components/spinner/index.js +0 -110
- package/dist-npm/components/st-end/end.d.ts +0 -2
- package/dist-npm/components/st-end/end.js +0 -35
- package/dist-npm/components/st-end/start.d.ts +0 -2
- package/dist-npm/components/st-end/start.js +0 -32
- package/dist-npm/components/toggle/index.d.ts +0 -13
- package/dist-npm/components/toggle/index.js +0 -121
- package/dist-npm/components/visual/animate/animate.d.ts +0 -13
- package/dist-npm/components/visual/animate/animate.js +0 -55
- package/dist-npm/components/visual/ascii-art/ascii-art.d.ts +0 -6
- package/dist-npm/components/visual/ascii-art/ascii-art.js +0 -12
- package/dist-npm/testing/index.d.ts +0 -18
- package/dist-npm/testing/index.js +0 -64
- package/dist-npm/types/general.d.ts +0 -134
- package/dist-npm/types/index.d.ts +0 -2
- package/dist-npm/types/index.js +0 -2
- package/dist-npm/types/keypress.d.ts +0 -52
- package/dist-npm/types/keypress.js +0 -37
- package/dist-npm/types/readline.d.ts +0 -30
- package/dist-npm/types/readline.js +0 -0
- package/dist-npm/types/relinka.d.ts +0 -30
- package/dist-npm/types/relinka.js +0 -0
- package/dist-npm/types/utils.d.ts +0 -17
- package/dist-npm/types/utils.js +0 -0
- package/dist-npm/utils/colorize.d.ts +0 -2
- package/dist-npm/utils/colorize.js +0 -130
- package/dist-npm/utils/component.d.ts +0 -101
- package/dist-npm/utils/component.js +0 -630
- package/dist-npm/utils/core.d.ts +0 -2
- package/dist-npm/utils/core.js +0 -2
- package/dist-npm/utils/decoder.d.ts +0 -14
- package/dist-npm/utils/decoder.js +0 -281
- package/dist-npm/utils/errors.d.ts +0 -1
- package/dist-npm/utils/errors.js +0 -15
- package/dist-npm/utils/keypress.d.ts +0 -7
- package/dist-npm/utils/keypress.js +0 -327
- package/dist-npm/utils/mapping.d.ts +0 -4
- package/dist-npm/utils/mapping.js +0 -49
- package/dist-npm/utils/messages.d.ts +0 -17
- package/dist-npm/utils/messages.js +0 -213
- package/dist-npm/utils/platforms.d.ts +0 -1
- package/dist-npm/utils/platforms.js +0 -22
- package/dist-npm/utils/prompt-tmp.d.ts +0 -13
- package/dist-npm/utils/prompt-tmp.js +0 -254
- package/dist-npm/utils/prompt-two.d.ts +0 -13
- package/dist-npm/utils/prompt-two.js +0 -254
- package/dist-npm/utils/readline.d.ts +0 -2
- package/dist-npm/utils/readline.js +0 -9
- package/dist-npm/utils/skeleton.d.ts +0 -7
- package/dist-npm/utils/skeleton.js +0 -145
- package/dist-npm/utils/terminal.d.ts +0 -5
- package/dist-npm/utils/terminal.js +0 -33
- package/dist-npm/utils/types.d.ts +0 -0
- package/dist-npm/utils/types.js +0 -0
- package/dist-npm/utils/utils.d.ts +0 -3
- package/dist-npm/utils/utils.js +0 -9
- package/dist-npm/utils/variants.d.ts +0 -9
- package/dist-npm/utils/variants.js +0 -49
- /package/dist-npm/{utils/constants.js → components/levels/levels.js} +0 -0
- /package/dist-npm/components/{instance/reporter → reporters}/browser.js +0 -0
- /package/dist-npm/types/{general.js → mod.js} +0 -0
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Value } from "@sinclair/typebox/value";
|
|
2
|
-
import { stdout } from "node:process";
|
|
3
|
-
import color from "picocolors";
|
|
4
|
-
import { useKeyPress } from "../../components/core/useKeyPress.js";
|
|
5
|
-
import { colorize } from "../../utils/colorize.js";
|
|
6
|
-
import { resetCursorAndClear, moveCursorAndClear } from "../../utils/readline.js";
|
|
7
|
-
export async function selectPrompt(options) {
|
|
8
|
-
const {
|
|
9
|
-
title,
|
|
10
|
-
choices,
|
|
11
|
-
defaultValue,
|
|
12
|
-
schema,
|
|
13
|
-
titleColor = "cyanBright",
|
|
14
|
-
titleTypography = "bold"
|
|
15
|
-
} = options;
|
|
16
|
-
if (schema) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
"Schema providing is currently not supported for selectPrompt().\n\u2502 But don't worry, we're already handling some validations for you."
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
if (!choices || choices.length === 0) {
|
|
22
|
-
throw new Error("Choices are required for select prompt.");
|
|
23
|
-
}
|
|
24
|
-
const coloredTitle = colorize(title, titleColor, titleTypography);
|
|
25
|
-
let selectedIndex = defaultValue !== void 0 ? choices.findIndex(
|
|
26
|
-
(choice, index) => choice.id === defaultValue || index + 1 === Number(defaultValue)
|
|
27
|
-
) : 0;
|
|
28
|
-
if (selectedIndex === -1) {
|
|
29
|
-
selectedIndex = 0;
|
|
30
|
-
}
|
|
31
|
-
function renderChoices() {
|
|
32
|
-
if (!choices) {
|
|
33
|
-
throw new Error("Choices are required for select prompt.");
|
|
34
|
-
}
|
|
35
|
-
resetCursorAndClear(stdout, 0, 0);
|
|
36
|
-
console.log(color.cyanBright(color.bold(coloredTitle)));
|
|
37
|
-
choices.forEach((choice, index) => {
|
|
38
|
-
const isSelected = index === selectedIndex;
|
|
39
|
-
const prefix = isSelected ? color.greenBright(">") : " ";
|
|
40
|
-
const choiceText = isSelected ? color.bgGreen(color.black(choice.title)) : choice.title;
|
|
41
|
-
console.log(`${prefix} ${choiceText}`);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
renderChoices();
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
const finalizeSelection = () => {
|
|
47
|
-
cleanupKeyPress();
|
|
48
|
-
moveCursorAndClear(stdout, 0, choices.length + 2);
|
|
49
|
-
const selectedChoice = choices[selectedIndex];
|
|
50
|
-
const selectedValue = selectedChoice?.id;
|
|
51
|
-
let isValid = true;
|
|
52
|
-
let errorMessage = "Invalid input.";
|
|
53
|
-
if (schema) {
|
|
54
|
-
try {
|
|
55
|
-
isValid = Value.Check(schema, selectedValue);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
isValid = false;
|
|
58
|
-
errorMessage = "Validation error.";
|
|
59
|
-
console.error(error);
|
|
60
|
-
}
|
|
61
|
-
if (!isValid) {
|
|
62
|
-
const errors = [...Value.Errors(schema, selectedValue)];
|
|
63
|
-
if (errors.length > 0) {
|
|
64
|
-
errorMessage = errors[0]?.message ?? "Invalid input.";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (isValid) {
|
|
69
|
-
if (selectedChoice?.action) {
|
|
70
|
-
selectedChoice.action().then(() => resolve(selectedValue ?? "")).catch(reject);
|
|
71
|
-
} else {
|
|
72
|
-
resolve(selectedValue ?? "");
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
console.log(errorMessage);
|
|
76
|
-
renderChoices();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const handleKeyPress = (str, key) => {
|
|
80
|
-
if (key.name === "up") {
|
|
81
|
-
selectedIndex = (selectedIndex - 1 + choices.length) % choices.length;
|
|
82
|
-
renderChoices();
|
|
83
|
-
} else if (key.name === "down") {
|
|
84
|
-
selectedIndex = (selectedIndex + 1) % choices.length;
|
|
85
|
-
renderChoices();
|
|
86
|
-
} else if (key.name === "return") {
|
|
87
|
-
finalizeSelection();
|
|
88
|
-
} else if (key.ctrl && key.name === "c") {
|
|
89
|
-
cleanupKeyPress();
|
|
90
|
-
process.exit();
|
|
91
|
-
} else if (!isNaN(Number(str)) && Number(str) >= 1 && Number(str) <= choices.length) {
|
|
92
|
-
selectedIndex = Number(str) - 1;
|
|
93
|
-
finalizeSelection();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const cleanupKeyPress = useKeyPress(handleKeyPress);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type SpinnerName } from "cli-spinners";
|
|
2
|
-
type SimpleSpinnerType = "default" | "dottedCircle" | "boxSpinner";
|
|
3
|
-
type OraAllowedSpinners = "dots" | "bouncingBar" | "arc";
|
|
4
|
-
type OraSpinnerType = Extract<SpinnerName, OraAllowedSpinners>;
|
|
5
|
-
type CreateSpinnerOptions<T extends "simple" | "ora"> = {
|
|
6
|
-
initialMessage: string;
|
|
7
|
-
successMessage?: string;
|
|
8
|
-
errorMessage?: string;
|
|
9
|
-
delay?: number;
|
|
10
|
-
spinnerSolution: T;
|
|
11
|
-
spinnerType?: T extends "simple" ? SimpleSpinnerType : OraSpinnerType;
|
|
12
|
-
action: (updateMessage: (message: string) => void) => Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
export declare function spinner<T extends "simple" | "ora">(options: CreateSpinnerOptions<T>): Promise<void>;
|
|
15
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import color from "picocolors";
|
|
4
|
-
import { cursor, erase } from "sisteransi";
|
|
5
|
-
import { msg } from "../../utils/messages.js";
|
|
6
|
-
export async function spinner(options) {
|
|
7
|
-
const {
|
|
8
|
-
initialMessage,
|
|
9
|
-
successMessage = "Task completed successfully.",
|
|
10
|
-
errorMessage = "An error occurred during the task.",
|
|
11
|
-
delay = 100,
|
|
12
|
-
spinnerSolution,
|
|
13
|
-
spinnerType,
|
|
14
|
-
action
|
|
15
|
-
} = options;
|
|
16
|
-
let message = initialMessage;
|
|
17
|
-
let interval = null;
|
|
18
|
-
let frameIndex = 0;
|
|
19
|
-
if (spinnerSolution === "ora") {
|
|
20
|
-
const oraSpinner = ora({
|
|
21
|
-
text: initialMessage,
|
|
22
|
-
spinner: spinnerType
|
|
23
|
-
});
|
|
24
|
-
try {
|
|
25
|
-
oraSpinner.start();
|
|
26
|
-
await action((newMessage) => {
|
|
27
|
-
message = newMessage;
|
|
28
|
-
oraSpinner.text = newMessage;
|
|
29
|
-
});
|
|
30
|
-
oraSpinner.stop();
|
|
31
|
-
msg({
|
|
32
|
-
type: "M_INFO",
|
|
33
|
-
title: successMessage,
|
|
34
|
-
titleColor: "green"
|
|
35
|
-
});
|
|
36
|
-
} catch (error) {
|
|
37
|
-
oraSpinner.stopAndPersist({
|
|
38
|
-
symbol: color.red("\u2716"),
|
|
39
|
-
text: errorMessage
|
|
40
|
-
});
|
|
41
|
-
msg({
|
|
42
|
-
type: "M_ERROR",
|
|
43
|
-
title: error instanceof Error ? error.message : "An unknown error occurred.",
|
|
44
|
-
titleColor: "red"
|
|
45
|
-
});
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
const simpleSpinners = {
|
|
50
|
-
default: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
|
|
51
|
-
dottedCircle: ["\u25CB", "\u25D4", "\u25D1", "\u25D5", "\u25CF"],
|
|
52
|
-
boxSpinner: ["\u2596", "\u2598", "\u259D", "\u2597"]
|
|
53
|
-
};
|
|
54
|
-
const frames = spinnerType && spinnerType in simpleSpinners ? simpleSpinners[spinnerType] : simpleSpinners.default;
|
|
55
|
-
const handleInput = (data) => {
|
|
56
|
-
const key = data.toString();
|
|
57
|
-
if (key === "\r" || key === "\n") {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
try {
|
|
62
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
63
|
-
process.stdin.setRawMode(true);
|
|
64
|
-
process.stdin.resume();
|
|
65
|
-
process.stdin.on("data", handleInput);
|
|
66
|
-
}
|
|
67
|
-
interval = setInterval(() => {
|
|
68
|
-
const frame = color.magenta(frames[frameIndex]);
|
|
69
|
-
process.stdout.write(
|
|
70
|
-
`${cursor.move(-999, 0)}${erase.line}${frame} ${color.cyan(message)}`
|
|
71
|
-
);
|
|
72
|
-
frameIndex = (frameIndex + 1) % frames.length;
|
|
73
|
-
}, delay);
|
|
74
|
-
await action((newMessage) => {
|
|
75
|
-
message = newMessage;
|
|
76
|
-
});
|
|
77
|
-
clearInterval(interval);
|
|
78
|
-
interval = null;
|
|
79
|
-
process.stdout.write(
|
|
80
|
-
`\r${erase.line}${color.green("\u2714")} ${successMessage}
|
|
81
|
-
`
|
|
82
|
-
);
|
|
83
|
-
msg({
|
|
84
|
-
type: "M_INFO",
|
|
85
|
-
title: successMessage,
|
|
86
|
-
titleColor: "green"
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
if (interval) {
|
|
90
|
-
clearInterval(interval);
|
|
91
|
-
}
|
|
92
|
-
process.stdout.write(
|
|
93
|
-
`\r${erase.line}${color.red("\u2716")} ${error instanceof Error ? errorMessage : "An unknown error occurred."}
|
|
94
|
-
`
|
|
95
|
-
);
|
|
96
|
-
msg({
|
|
97
|
-
type: "M_ERROR",
|
|
98
|
-
title: error instanceof Error ? error.message : "An unknown error occurred.",
|
|
99
|
-
titleColor: "red"
|
|
100
|
-
});
|
|
101
|
-
process.exit(1);
|
|
102
|
-
} finally {
|
|
103
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
104
|
-
process.stdin.setRawMode(false);
|
|
105
|
-
process.stdin.pause();
|
|
106
|
-
process.stdin.removeListener("data", handleInput);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { animateText } from "../../components/visual/animate/animate.js";
|
|
2
|
-
import { msg } from "../../utils/messages.js";
|
|
3
|
-
export async function endPrompt({
|
|
4
|
-
title,
|
|
5
|
-
titleColor = "cyanBright",
|
|
6
|
-
titleTypography = "bold",
|
|
7
|
-
titleVariant,
|
|
8
|
-
titleAnimation,
|
|
9
|
-
titleAnimationDelay,
|
|
10
|
-
border = true,
|
|
11
|
-
borderColor = "viceGradient"
|
|
12
|
-
}) {
|
|
13
|
-
if (titleAnimation) {
|
|
14
|
-
await animateText({
|
|
15
|
-
title,
|
|
16
|
-
anim: titleAnimation,
|
|
17
|
-
delay: titleAnimationDelay,
|
|
18
|
-
type: "M_END",
|
|
19
|
-
titleColor,
|
|
20
|
-
titleTypography,
|
|
21
|
-
border,
|
|
22
|
-
borderColor
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
msg({
|
|
26
|
-
type: "M_END",
|
|
27
|
-
title,
|
|
28
|
-
titleColor,
|
|
29
|
-
titleTypography,
|
|
30
|
-
titleVariant,
|
|
31
|
-
border,
|
|
32
|
-
borderColor
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { msg } from "../../utils/messages.js";
|
|
2
|
-
export async function startPrompt({
|
|
3
|
-
title,
|
|
4
|
-
titleColor = "cyanBright",
|
|
5
|
-
titleTypography = "bold",
|
|
6
|
-
titleVariant,
|
|
7
|
-
borderColor = "viceGradient",
|
|
8
|
-
clearConsole = true
|
|
9
|
-
}) {
|
|
10
|
-
if (clearConsole) {
|
|
11
|
-
console.clear();
|
|
12
|
-
console.log();
|
|
13
|
-
} else {
|
|
14
|
-
console.log();
|
|
15
|
-
}
|
|
16
|
-
msg({
|
|
17
|
-
type: "M_START",
|
|
18
|
-
title: ` ${title} `,
|
|
19
|
-
titleColor,
|
|
20
|
-
titleTypography,
|
|
21
|
-
titleVariant,
|
|
22
|
-
borderColor
|
|
23
|
-
});
|
|
24
|
-
if (!process.stdout.isTTY) {
|
|
25
|
-
console.error(
|
|
26
|
-
"\u2502 Your terminal does not support cursor manipulations.\n\u2502 It's recommended to use a terminal which supports TTY."
|
|
27
|
-
);
|
|
28
|
-
msg({
|
|
29
|
-
type: "M_NEWLINE"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ColorName, Variant, TypographyName } from "../../types/general.js";
|
|
2
|
-
export declare function togglePrompt<T extends string>(params: {
|
|
3
|
-
title: string;
|
|
4
|
-
options: [T, T];
|
|
5
|
-
initial?: T;
|
|
6
|
-
borderColor?: ColorName;
|
|
7
|
-
titleColor?: ColorName;
|
|
8
|
-
titleTypography?: TypographyName;
|
|
9
|
-
titleVariant?: Variant;
|
|
10
|
-
border?: boolean;
|
|
11
|
-
endTitle?: string;
|
|
12
|
-
endTitleColor?: ColorName;
|
|
13
|
-
}): Promise<T>;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { cyanBright, dim, greenBright, redBright } from "picocolors";
|
|
2
|
-
import { stdin as input, stdout as output } from "process";
|
|
3
|
-
import readline from "readline";
|
|
4
|
-
import { bar, fmt, msg, symbols } from "../../utils/messages.js";
|
|
5
|
-
import { deleteLastLine } from "../../utils/terminal.js";
|
|
6
|
-
export async function togglePrompt(params) {
|
|
7
|
-
const {
|
|
8
|
-
title,
|
|
9
|
-
options,
|
|
10
|
-
initial,
|
|
11
|
-
borderColor = "viceGradient",
|
|
12
|
-
titleColor = "cyanBright",
|
|
13
|
-
titleTypography = "bold",
|
|
14
|
-
titleVariant,
|
|
15
|
-
border = true,
|
|
16
|
-
endTitle = "\u{1F44B}",
|
|
17
|
-
endTitleColor = "passionGradient"
|
|
18
|
-
} = params;
|
|
19
|
-
let selectedIndex = initial ? options.findIndex((option) => option === initial) : 0;
|
|
20
|
-
if (selectedIndex === -1) {
|
|
21
|
-
selectedIndex = 0;
|
|
22
|
-
}
|
|
23
|
-
const rl = readline.createInterface({ input, output });
|
|
24
|
-
readline.emitKeypressEvents(input, rl);
|
|
25
|
-
if (typeof input.setRawMode === "function") {
|
|
26
|
-
input.setRawMode(true);
|
|
27
|
-
}
|
|
28
|
-
const formattedBar = bar({ borderColor });
|
|
29
|
-
let linesRendered = 0;
|
|
30
|
-
const instructions = `Use <\u2190/\u2192> or <h/l> to navigate, <Enter> to select, <Ctrl+C> to exit`;
|
|
31
|
-
let errorMessage = "";
|
|
32
|
-
function renderOption() {
|
|
33
|
-
if (linesRendered > 0) {
|
|
34
|
-
process.stdout.write(`\x1B[${linesRendered}A`);
|
|
35
|
-
}
|
|
36
|
-
let outputStr = `${greenBright(symbols.step_active)} ${fmt({
|
|
37
|
-
type: "M_NULL",
|
|
38
|
-
title,
|
|
39
|
-
titleColor,
|
|
40
|
-
titleTypography,
|
|
41
|
-
titleVariant
|
|
42
|
-
})}
|
|
43
|
-
`;
|
|
44
|
-
if (errorMessage) {
|
|
45
|
-
outputStr += `${redBright(symbols.step_error)} ${errorMessage}
|
|
46
|
-
`;
|
|
47
|
-
} else {
|
|
48
|
-
outputStr += `${formattedBar} ${dim(instructions)}
|
|
49
|
-
`;
|
|
50
|
-
}
|
|
51
|
-
const [leftOption, rightOption] = options;
|
|
52
|
-
const displayOptions = options.map((option, index) => {
|
|
53
|
-
if (index === selectedIndex) {
|
|
54
|
-
return cyanBright(option);
|
|
55
|
-
}
|
|
56
|
-
return option;
|
|
57
|
-
});
|
|
58
|
-
const displayString = displayOptions.join(" / ");
|
|
59
|
-
outputStr += `${formattedBar} ${displayString}
|
|
60
|
-
`;
|
|
61
|
-
process.stdout.write(outputStr);
|
|
62
|
-
linesRendered = 1 + 1 + 1;
|
|
63
|
-
}
|
|
64
|
-
renderOption();
|
|
65
|
-
return new Promise((resolve) => {
|
|
66
|
-
function onKeyPress(str, key) {
|
|
67
|
-
if (key.name === "left" || key.name === "h") {
|
|
68
|
-
selectedIndex = (selectedIndex - 1 + options.length) % options.length;
|
|
69
|
-
errorMessage = "";
|
|
70
|
-
renderOption();
|
|
71
|
-
} else if (key.name === "right" || key.name === "l") {
|
|
72
|
-
selectedIndex = (selectedIndex + 1) % options.length;
|
|
73
|
-
errorMessage = "";
|
|
74
|
-
renderOption();
|
|
75
|
-
} else if (key.name === "return") {
|
|
76
|
-
if (!options[selectedIndex]) {
|
|
77
|
-
deleteLastLine();
|
|
78
|
-
errorMessage = "You must select an option.";
|
|
79
|
-
renderOption();
|
|
80
|
-
} else {
|
|
81
|
-
cleanup();
|
|
82
|
-
resolve(options[selectedIndex]);
|
|
83
|
-
deleteLastLine();
|
|
84
|
-
deleteLastLine();
|
|
85
|
-
msg({
|
|
86
|
-
type: "M_MIDDLE"
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
} else if (key.name === "c" && key.ctrl) {
|
|
90
|
-
msg({
|
|
91
|
-
type: "M_NEWLINE"
|
|
92
|
-
});
|
|
93
|
-
msg({
|
|
94
|
-
type: "M_END",
|
|
95
|
-
title: endTitle,
|
|
96
|
-
titleColor: endTitleColor,
|
|
97
|
-
titleTypography,
|
|
98
|
-
titleVariant,
|
|
99
|
-
border,
|
|
100
|
-
borderColor,
|
|
101
|
-
addNewLineBefore: true
|
|
102
|
-
});
|
|
103
|
-
cleanup(true);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function cleanup(isCtrlC = false) {
|
|
107
|
-
if (typeof input.setRawMode === "function") {
|
|
108
|
-
input.setRawMode(false);
|
|
109
|
-
}
|
|
110
|
-
rl.close();
|
|
111
|
-
input.removeListener("keypress", onKeyPress);
|
|
112
|
-
process.stdout.write(`\x1B[${linesRendered}B`);
|
|
113
|
-
if (isCtrlC) {
|
|
114
|
-
process.exit();
|
|
115
|
-
} else {
|
|
116
|
-
console.log();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
input.on("keypress", onKeyPress);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type Animation, type AnimationName } from "@figliolia/chalk-animation";
|
|
2
|
-
import type { ColorName, MsgType, TypographyName } from "../../../types/general.js";
|
|
3
|
-
export declare const animationMap: Record<AnimationName, (text: string) => Animation>;
|
|
4
|
-
export declare function animateText({ title, anim, delay, type, titleColor, titleTypography, border, borderColor, }: {
|
|
5
|
-
title: string;
|
|
6
|
-
anim: AnimationName;
|
|
7
|
-
delay?: number;
|
|
8
|
-
type?: MsgType;
|
|
9
|
-
titleColor?: ColorName;
|
|
10
|
-
titleTypography?: TypographyName;
|
|
11
|
-
borderColor?: ColorName;
|
|
12
|
-
border?: boolean;
|
|
13
|
-
}): Promise<void>;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChalkAnimation
|
|
3
|
-
} from "@figliolia/chalk-animation";
|
|
4
|
-
import { msg } from "../../../utils/messages.js";
|
|
5
|
-
import { deleteLastLine } from "../../../utils/terminal.js";
|
|
6
|
-
export const animationMap = {
|
|
7
|
-
rainbow: ChalkAnimation.rainbow,
|
|
8
|
-
pulse: ChalkAnimation.pulse,
|
|
9
|
-
glitch: ChalkAnimation.glitch,
|
|
10
|
-
radar: ChalkAnimation.radar,
|
|
11
|
-
neon: ChalkAnimation.neon,
|
|
12
|
-
karaoke: ChalkAnimation.karaoke
|
|
13
|
-
};
|
|
14
|
-
function calculateDelay(text) {
|
|
15
|
-
const baseDelay = 1e3;
|
|
16
|
-
const delayPerCharacter = 50;
|
|
17
|
-
return baseDelay + text.length * delayPerCharacter;
|
|
18
|
-
}
|
|
19
|
-
export async function animateText({
|
|
20
|
-
title,
|
|
21
|
-
anim,
|
|
22
|
-
delay,
|
|
23
|
-
type = "M_INFO",
|
|
24
|
-
titleColor = "cyanBright",
|
|
25
|
-
titleTypography = "bold",
|
|
26
|
-
border = true,
|
|
27
|
-
borderColor = "viceGradient"
|
|
28
|
-
}) {
|
|
29
|
-
const finalDelay = delay ?? calculateDelay(title);
|
|
30
|
-
const animation = animationMap[anim](title);
|
|
31
|
-
try {
|
|
32
|
-
await new Promise((resolve) => {
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
animation.stop();
|
|
35
|
-
deleteLastLine();
|
|
36
|
-
if (title.includes("\u2502 ")) {
|
|
37
|
-
title = title.replace("\u2502 ", "");
|
|
38
|
-
} else if (title.includes("\u2139 ")) {
|
|
39
|
-
title = title.replace("\u2139 ", "");
|
|
40
|
-
}
|
|
41
|
-
msg({
|
|
42
|
-
type,
|
|
43
|
-
title,
|
|
44
|
-
titleColor,
|
|
45
|
-
titleTypography,
|
|
46
|
-
borderColor,
|
|
47
|
-
border
|
|
48
|
-
});
|
|
49
|
-
resolve();
|
|
50
|
-
}, finalDelay);
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("Animation failed to complete.", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { textSync } from "figlet";
|
|
2
|
-
export async function createAsciiArt({
|
|
3
|
-
message,
|
|
4
|
-
font = "Standard",
|
|
5
|
-
clearConsole = false
|
|
6
|
-
}) {
|
|
7
|
-
if (clearConsole) {
|
|
8
|
-
console.clear();
|
|
9
|
-
}
|
|
10
|
-
const asciiArt = textSync(message, { font });
|
|
11
|
-
console.log(asciiArt);
|
|
12
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Prompt, Context } from "../types/index.js";
|
|
2
|
-
export declare function render<const Props, const Value, const TestedPrompt extends Prompt<Value, Props>>(prompt: TestedPrompt, props: Props, options?: Context): Promise<{
|
|
3
|
-
answer: any;
|
|
4
|
-
input: any;
|
|
5
|
-
events: {
|
|
6
|
-
keypress(key: string | {
|
|
7
|
-
name?: string | undefined;
|
|
8
|
-
ctrl?: boolean | undefined;
|
|
9
|
-
meta?: boolean | undefined;
|
|
10
|
-
shift?: boolean | undefined;
|
|
11
|
-
}): void;
|
|
12
|
-
type(text: string): void;
|
|
13
|
-
};
|
|
14
|
-
getScreen: ({ raw }?: {
|
|
15
|
-
raw?: boolean;
|
|
16
|
-
}) => string;
|
|
17
|
-
getFullOutput: () => string;
|
|
18
|
-
}>;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import ansiEscapes from "ansi-escapes";
|
|
2
|
-
import MuteStream from "mute-stream";
|
|
3
|
-
import { Stream } from "node:stream";
|
|
4
|
-
import stripAnsi from "strip-ansi";
|
|
5
|
-
const ignoredAnsi = new Set([ansiEscapes.cursorHide, ansiEscapes.cursorShow]);
|
|
6
|
-
class BufferedStream extends Stream.Writable {
|
|
7
|
-
#_fullOutput = "";
|
|
8
|
-
#_chunks = [];
|
|
9
|
-
#_rawChunks = [];
|
|
10
|
-
_write(chunk, _encoding, callback) {
|
|
11
|
-
const str = chunk.toString();
|
|
12
|
-
this.#_fullOutput += str;
|
|
13
|
-
if (!ignoredAnsi.has(str)) {
|
|
14
|
-
this.#_rawChunks.push(str);
|
|
15
|
-
}
|
|
16
|
-
if (stripAnsi(str).trim().length > 0) {
|
|
17
|
-
this.#_chunks.push(str);
|
|
18
|
-
}
|
|
19
|
-
callback();
|
|
20
|
-
}
|
|
21
|
-
getLastChunk({ raw }) {
|
|
22
|
-
const chunks = raw ? this.#_rawChunks : this.#_chunks;
|
|
23
|
-
const lastChunk = chunks.at(-1);
|
|
24
|
-
return lastChunk ?? "";
|
|
25
|
-
}
|
|
26
|
-
getFullOutput() {
|
|
27
|
-
return this.#_fullOutput;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export async function render(prompt, props, options) {
|
|
31
|
-
const input = new MuteStream();
|
|
32
|
-
input.unmute();
|
|
33
|
-
const output = new BufferedStream();
|
|
34
|
-
const answer = prompt(props, { input, output, ...options });
|
|
35
|
-
await Promise.resolve();
|
|
36
|
-
await Promise.resolve();
|
|
37
|
-
const events = {
|
|
38
|
-
keypress(key) {
|
|
39
|
-
if (typeof key === "string") {
|
|
40
|
-
input.emit("keypress", null, { name: key });
|
|
41
|
-
} else {
|
|
42
|
-
input.emit("keypress", null, key);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
type(text) {
|
|
46
|
-
input.write(text);
|
|
47
|
-
for (const char of text) {
|
|
48
|
-
input.emit("keypress", null, { name: char });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
answer,
|
|
54
|
-
input,
|
|
55
|
-
events,
|
|
56
|
-
getScreen: ({ raw } = {}) => {
|
|
57
|
-
const lastScreen = output.getLastChunk({ raw });
|
|
58
|
-
return raw ? lastScreen : stripAnsi(lastScreen).trim();
|
|
59
|
-
},
|
|
60
|
-
getFullOutput: () => {
|
|
61
|
-
return output.getFullOutput();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|