@reliverse/relinka 1.1.7 → 1.1.8
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/dist-npm/components/anykey/index.js +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +173 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1,139 +1,110 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import ora from
|
|
3
|
-
import color from
|
|
4
|
-
import {cursor, erase} from
|
|
5
|
-
import {msg} from
|
|
6
|
-
|
|
7
|
-
const isFn = (a) => typeof a === 'function';
|
|
8
|
-
|
|
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";
|
|
9
6
|
export async function spinner(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
titleColor: 'red',
|
|
51
|
-
});
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
const simpleSpinners = {
|
|
56
|
-
default: [
|
|
57
|
-
'\u280B',
|
|
58
|
-
'\u2819',
|
|
59
|
-
'\u2839',
|
|
60
|
-
'\u2838',
|
|
61
|
-
'\u283C',
|
|
62
|
-
'\u2834',
|
|
63
|
-
'\u2826',
|
|
64
|
-
'\u2827',
|
|
65
|
-
'\u2807',
|
|
66
|
-
'\u280F',
|
|
67
|
-
],
|
|
68
|
-
dottedCircle: [
|
|
69
|
-
'\u25CB',
|
|
70
|
-
'\u25D4',
|
|
71
|
-
'\u25D1',
|
|
72
|
-
'\u25D5',
|
|
73
|
-
'\u25CF',
|
|
74
|
-
],
|
|
75
|
-
boxSpinner: [
|
|
76
|
-
'\u2596',
|
|
77
|
-
'\u2598',
|
|
78
|
-
'\u259D',
|
|
79
|
-
'\u2597',
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const frames = spinnerType && spinnerType in simpleSpinners ? simpleSpinners[spinnerType] : simpleSpinners.default;
|
|
84
|
-
const handleInput = (data) => {
|
|
85
|
-
const key = data.toString();
|
|
86
|
-
|
|
87
|
-
if (key === '\r' || key === '\n') {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
|
|
94
|
-
process.stdin.setRawMode(true);
|
|
95
|
-
process.stdin.resume();
|
|
96
|
-
process.stdin.on('data', handleInput);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
interval = setInterval(() => {
|
|
100
|
-
const frame = color.magenta(frames[frameIndex]);
|
|
101
|
-
|
|
102
|
-
process.stdout.write(`${cursor.move(-999, 0)}${erase.line}${frame} ${color.cyan(message)}`);
|
|
103
|
-
frameIndex = (frameIndex + 1) % frames.length;
|
|
104
|
-
}, delay);
|
|
105
|
-
await action((newMessage) => {
|
|
106
|
-
message = newMessage;
|
|
107
|
-
});
|
|
108
|
-
clearInterval(interval);
|
|
109
|
-
interval = null;
|
|
110
|
-
process.stdout.write(`\r${erase.line}${color.green('\u2714')} ${successMessage}
|
|
111
|
-
`);
|
|
112
|
-
msg({
|
|
113
|
-
type: 'M_INFO',
|
|
114
|
-
title: successMessage,
|
|
115
|
-
titleColor: 'green',
|
|
116
|
-
});
|
|
117
|
-
} catch(error) {
|
|
118
|
-
if (interval) {
|
|
119
|
-
clearInterval(interval);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
process.stdout.write(`\r${erase.line}${color.red('\u2716')} ${error instanceof Error ? errorMessage : 'An unknown error occurred.'}
|
|
123
|
-
`);
|
|
124
|
-
msg({
|
|
125
|
-
type: 'M_ERROR',
|
|
126
|
-
title: error instanceof Error ? error.message : 'An unknown error occurred.',
|
|
127
|
-
titleColor: 'red',
|
|
128
|
-
});
|
|
129
|
-
process.exit(1);
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
|
|
133
|
-
process.stdin.setRawMode(false);
|
|
134
|
-
process.stdin.pause();
|
|
135
|
-
process.stdin.removeListener('data', handleInput);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
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);
|
|
138
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
|
+
}
|
|
139
110
|
}
|
|
@@ -1,27 +1,35 @@
|
|
|
1
|
-
import {animateText} from
|
|
2
|
-
import {msg} from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
35
|
}
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
);
|
|
5
28
|
msg({
|
|
6
|
-
|
|
7
|
-
title: ` ${title} `,
|
|
8
|
-
titleColor,
|
|
9
|
-
titleTypography,
|
|
10
|
-
titleVariant,
|
|
11
|
-
borderColor,
|
|
29
|
+
type: "M_NEWLINE"
|
|
12
30
|
});
|
|
13
|
-
|
|
14
|
-
msg({
|
|
15
|
-
type: 'M_NEWLINE',
|
|
16
|
-
});
|
|
17
|
-
}
|
|
31
|
+
}
|
|
18
32
|
}
|
|
@@ -1,145 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (selectedIndex === -1) {
|
|
37
|
-
selectedIndex = 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`);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const formattedBar = bar({
|
|
47
|
-
borderColor,
|
|
48
|
-
});
|
|
49
|
-
let linesRendered = 0;
|
|
50
|
-
const instructions = `Use <\u2190/\u2192> or <h/l> to navigate, <Enter> to select, <Ctrl+C> to exit`;
|
|
51
|
-
let errorMessage = '';
|
|
52
|
-
|
|
53
|
-
function renderOption() {
|
|
54
|
-
if (linesRendered > 0) {
|
|
55
|
-
process.stdout.write(`\x1B[${linesRendered}A`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let outputStr = `${greenBright(symbols.step_active)} ${fmt({
|
|
59
|
-
type: 'M_NULL',
|
|
60
|
-
title,
|
|
61
|
-
titleColor,
|
|
62
|
-
titleTypography,
|
|
63
|
-
titleVariant,
|
|
64
|
-
})}
|
|
36
|
+
let outputStr = `${greenBright(symbols.step_active)} ${fmt({
|
|
37
|
+
type: "M_NULL",
|
|
38
|
+
title,
|
|
39
|
+
titleColor,
|
|
40
|
+
titleTypography,
|
|
41
|
+
titleVariant
|
|
42
|
+
})}
|
|
65
43
|
`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
outputStr += `${redBright(symbols.step_error)} ${errorMessage}
|
|
44
|
+
if (errorMessage) {
|
|
45
|
+
outputStr += `${redBright(symbols.step_error)} ${errorMessage}
|
|
69
46
|
`;
|
|
70
|
-
|
|
71
|
-
|
|
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}
|
|
72
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
|
+
});
|
|
73
88
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return cyanBright(option);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return option;
|
|
89
|
+
} else if (key.name === "c" && key.ctrl) {
|
|
90
|
+
msg({
|
|
91
|
+
type: "M_NEWLINE"
|
|
81
92
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}
|
|
89
105
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
errorMessage = 'You must select an option.';
|
|
106
|
-
renderOption();
|
|
107
|
-
} else {
|
|
108
|
-
cleanup();
|
|
109
|
-
resolve(options[selectedIndex]);
|
|
110
|
-
deleteLastLine();
|
|
111
|
-
deleteLastLine();
|
|
112
|
-
msg({
|
|
113
|
-
type: 'M_MIDDLE',
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
} else if (key.name === 'c' && key.ctrl) {
|
|
117
|
-
msg({
|
|
118
|
-
type: 'M_NEWLINE',
|
|
119
|
-
});
|
|
120
|
-
msg({
|
|
121
|
-
type: 'M_END',
|
|
122
|
-
title: endTitle,
|
|
123
|
-
titleColor: endTitleColor,
|
|
124
|
-
titleTypography,
|
|
125
|
-
titleVariant,
|
|
126
|
-
border,
|
|
127
|
-
borderColor,
|
|
128
|
-
addNewLineBefore: true,
|
|
129
|
-
});
|
|
130
|
-
cleanup();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function cleanup() {
|
|
137
|
-
input.setRawMode?.(false);
|
|
138
|
-
rl.close();
|
|
139
|
-
input.removeListener('keypress', onKeyPress);
|
|
140
|
-
process.stdout.write(`\x1B[${linesRendered}B`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
input.on('keypress', onKeyPress);
|
|
144
|
-
});
|
|
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
|
+
});
|
|
145
121
|
}
|
|
@@ -1,12 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChalkAnimation
|
|
3
|
+
} from "@figliolia/chalk-animation";
|
|
4
|
+
import { msg } from "../../../utils/messages.js";
|
|
5
|
+
import { deleteLastLine } from "../../../utils/terminal.js";
|
|
3
6
|
export const animationMap = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
rainbow: ChalkAnimation.rainbow,
|
|
8
|
+
pulse: ChalkAnimation.pulse,
|
|
9
|
+
glitch: ChalkAnimation.glitch,
|
|
10
|
+
radar: ChalkAnimation.radar,
|
|
11
|
+
neon: ChalkAnimation.neon,
|
|
12
|
+
karaoke: ChalkAnimation.karaoke
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|