@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,16 +0,0 @@
|
|
|
1
|
-
import { stdin } from "node:process";
|
|
2
|
-
import readline from "node:readline";
|
|
3
|
-
export function useKeyPress(callback) {
|
|
4
|
-
readline.emitKeypressEvents(stdin);
|
|
5
|
-
if (stdin.isTTY) {
|
|
6
|
-
stdin.setRawMode(true);
|
|
7
|
-
}
|
|
8
|
-
const onKeypress = (str, key) => {
|
|
9
|
-
callback(str, key);
|
|
10
|
-
};
|
|
11
|
-
stdin.on("keypress", onKeypress);
|
|
12
|
-
return () => {
|
|
13
|
-
stdin.setRawMode(false);
|
|
14
|
-
stdin.off("keypress", onKeypress);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "../../components/core/use-effect.js";
|
|
2
|
-
import { useState } from "../../components/core/use-state.js";
|
|
3
|
-
export function usePromptState(initialState) {
|
|
4
|
-
const [state, setState] = useState(initialState);
|
|
5
|
-
const [figure, setFigure] = useState("\u{1F7E2}");
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
setFigure("\u{1F7E2}");
|
|
8
|
-
}, [state]);
|
|
9
|
-
return { state, setState, figure };
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import cliWidth from "cli-width";
|
|
2
|
-
import wrapAnsi from "wrap-ansi";
|
|
3
|
-
import { readline } from "./hook-engine.js";
|
|
4
|
-
export function breakLines(content, width) {
|
|
5
|
-
return content.split("\n").flatMap(
|
|
6
|
-
(line) => wrapAnsi(line, width, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
|
|
7
|
-
).join("\n");
|
|
8
|
-
}
|
|
9
|
-
export function readlineWidth() {
|
|
10
|
-
return cliWidth({ defaultWidth: 80, output: readline().output });
|
|
11
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { TSchema } from "@sinclair/typebox";
|
|
2
|
-
import type { PromptOptions } from "../../types/general.js";
|
|
3
|
-
export declare function datePrompt<T extends TSchema>(options: PromptOptions<T> & {
|
|
4
|
-
dateFormat: string;
|
|
5
|
-
dateKind: "birthday" | "other";
|
|
6
|
-
}): Promise<string>;
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
4
|
-
import readline from "node:readline/promises";
|
|
5
|
-
import { cyanBright } from "picocolors";
|
|
6
|
-
import {
|
|
7
|
-
buildRegExp,
|
|
8
|
-
digit,
|
|
9
|
-
endOfString,
|
|
10
|
-
repeat,
|
|
11
|
-
startOfString
|
|
12
|
-
} from "ts-regex-builder";
|
|
13
|
-
import { bar, fmt, msg } from "../../utils/messages.js";
|
|
14
|
-
import {
|
|
15
|
-
countLines,
|
|
16
|
-
deleteLastLine,
|
|
17
|
-
deleteLastLines
|
|
18
|
-
} from "../../utils/terminal.js";
|
|
19
|
-
const twoDigits = repeat(digit, 2);
|
|
20
|
-
const fourDigits = repeat(digit, 4);
|
|
21
|
-
const separatorDot = ".";
|
|
22
|
-
const separatorSlash = "/";
|
|
23
|
-
const regexDDMMYYYY = buildRegExp([
|
|
24
|
-
startOfString,
|
|
25
|
-
twoDigits,
|
|
26
|
-
|
|
27
|
-
separatorDot,
|
|
28
|
-
twoDigits,
|
|
29
|
-
|
|
30
|
-
separatorDot,
|
|
31
|
-
fourDigits,
|
|
32
|
-
|
|
33
|
-
endOfString
|
|
34
|
-
]);
|
|
35
|
-
const regexMMDDYYYY = buildRegExp([
|
|
36
|
-
startOfString,
|
|
37
|
-
twoDigits,
|
|
38
|
-
|
|
39
|
-
separatorSlash,
|
|
40
|
-
twoDigits,
|
|
41
|
-
|
|
42
|
-
separatorSlash,
|
|
43
|
-
fourDigits,
|
|
44
|
-
|
|
45
|
-
endOfString
|
|
46
|
-
]);
|
|
47
|
-
const regexYYYYMMDD = buildRegExp([
|
|
48
|
-
startOfString,
|
|
49
|
-
fourDigits,
|
|
50
|
-
|
|
51
|
-
separatorDot,
|
|
52
|
-
twoDigits,
|
|
53
|
-
|
|
54
|
-
separatorDot,
|
|
55
|
-
twoDigits,
|
|
56
|
-
|
|
57
|
-
endOfString
|
|
58
|
-
]);
|
|
59
|
-
const dateFormatSchema = Type.Union([
|
|
60
|
-
Type.RegExp(regexDDMMYYYY, { description: "DD.MM.YYYY" }),
|
|
61
|
-
Type.RegExp(regexMMDDYYYY, { description: "MM/DD/YYYY" }),
|
|
62
|
-
Type.RegExp(regexYYYYMMDD, { description: "YYYY.MM.DD" })
|
|
63
|
-
]);
|
|
64
|
-
export async function datePrompt(options) {
|
|
65
|
-
const {
|
|
66
|
-
title,
|
|
67
|
-
dateFormat,
|
|
68
|
-
dateKind,
|
|
69
|
-
hint,
|
|
70
|
-
validate,
|
|
71
|
-
defaultValue,
|
|
72
|
-
schema,
|
|
73
|
-
titleColor = "cyanBright",
|
|
74
|
-
titleTypography = "bold",
|
|
75
|
-
titleVariant,
|
|
76
|
-
content,
|
|
77
|
-
contentColor,
|
|
78
|
-
contentTypography,
|
|
79
|
-
contentVariant,
|
|
80
|
-
borderColor = "viceGradient",
|
|
81
|
-
variantOptions
|
|
82
|
-
} = options;
|
|
83
|
-
const rl = readline.createInterface({ input, output });
|
|
84
|
-
const formattedBar = bar({ borderColor });
|
|
85
|
-
let linesToDelete = 0;
|
|
86
|
-
let errorMessage = "";
|
|
87
|
-
try {
|
|
88
|
-
while (true) {
|
|
89
|
-
if (linesToDelete > 0) {
|
|
90
|
-
deleteLastLines(linesToDelete);
|
|
91
|
-
}
|
|
92
|
-
const questionText = fmt({
|
|
93
|
-
type: errorMessage !== "" ? "M_ERROR_NULL" : "M_GENERAL_NULL",
|
|
94
|
-
title: `${title} [Format: ${dateFormat}]`,
|
|
95
|
-
titleColor,
|
|
96
|
-
titleTypography,
|
|
97
|
-
titleVariant,
|
|
98
|
-
content,
|
|
99
|
-
contentColor,
|
|
100
|
-
contentTypography,
|
|
101
|
-
contentVariant,
|
|
102
|
-
borderColor,
|
|
103
|
-
hint,
|
|
104
|
-
variantOptions,
|
|
105
|
-
errorMessage,
|
|
106
|
-
addNewLineBefore: false
|
|
107
|
-
});
|
|
108
|
-
const questionLines = countLines(questionText);
|
|
109
|
-
linesToDelete = questionLines + 1;
|
|
110
|
-
msg({
|
|
111
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
112
|
-
title: questionText
|
|
113
|
-
});
|
|
114
|
-
deleteLastLine();
|
|
115
|
-
deleteLastLine();
|
|
116
|
-
const answer = (await rl.question(`${cyanBright(">")} `)).trim() || defaultValue;
|
|
117
|
-
if (answer === defaultValue && defaultValue) {
|
|
118
|
-
deleteLastLine();
|
|
119
|
-
msg({
|
|
120
|
-
type: "M_MIDDLE",
|
|
121
|
-
title: ` ${defaultValue}`,
|
|
122
|
-
titleColor: "none"
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (!Value.Check(dateFormatSchema, answer)) {
|
|
126
|
-
deleteLastLine();
|
|
127
|
-
deleteLastLine();
|
|
128
|
-
errorMessage = `Please enter a valid date in ${dateFormat} format.`;
|
|
129
|
-
msg({ type: "M_ERROR", title: errorMessage });
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
let matchedFormat = null;
|
|
133
|
-
if (regexDDMMYYYY.test(answer)) {
|
|
134
|
-
matchedFormat = "DD.MM.YYYY";
|
|
135
|
-
} else if (regexMMDDYYYY.test(answer)) {
|
|
136
|
-
matchedFormat = "MM/DD/YYYY";
|
|
137
|
-
} else if (regexYYYYMMDD.test(answer)) {
|
|
138
|
-
matchedFormat = "YYYY.MM.DD";
|
|
139
|
-
}
|
|
140
|
-
if (dateKind === "birthday" && matchedFormat) {
|
|
141
|
-
const parts = answer.split(/[./-]/);
|
|
142
|
-
let date;
|
|
143
|
-
if (matchedFormat === "DD.MM.YYYY") {
|
|
144
|
-
date = new Date(
|
|
145
|
-
Number(parts[2]),
|
|
146
|
-
Number(parts[1]) - 1,
|
|
147
|
-
Number(parts[0])
|
|
148
|
-
);
|
|
149
|
-
} else if (matchedFormat === "MM/DD/YYYY") {
|
|
150
|
-
date = new Date(
|
|
151
|
-
Number(parts[2]),
|
|
152
|
-
Number(parts[0]) - 1,
|
|
153
|
-
Number(parts[1])
|
|
154
|
-
);
|
|
155
|
-
} else if (matchedFormat === "YYYY.MM.DD") {
|
|
156
|
-
date = new Date(
|
|
157
|
-
Number(parts[0]),
|
|
158
|
-
Number(parts[1]) - 1,
|
|
159
|
-
Number(parts[2])
|
|
160
|
-
);
|
|
161
|
-
} else {
|
|
162
|
-
date = new Date(answer);
|
|
163
|
-
}
|
|
164
|
-
if (isNaN(date.getTime()) || date.getFullYear() < 1900 || date > new Date()) {
|
|
165
|
-
errorMessage = "Please enter a valid birthday date (e.g., 14.09.1999).";
|
|
166
|
-
msg({ type: "M_ERROR", title: errorMessage });
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
let isValid = true;
|
|
171
|
-
let gotError = false;
|
|
172
|
-
if (errorMessage !== "") {
|
|
173
|
-
gotError = true;
|
|
174
|
-
}
|
|
175
|
-
errorMessage = "";
|
|
176
|
-
if (schema) {
|
|
177
|
-
isValid = Value.Check(schema, answer);
|
|
178
|
-
if (!isValid) {
|
|
179
|
-
const errors = [...Value.Errors(schema, answer)];
|
|
180
|
-
errorMessage = errors[0]?.message ?? "Invalid input.";
|
|
181
|
-
msg({ type: "M_ERROR", title: errorMessage });
|
|
182
|
-
gotError = true;
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (validate && isValid) {
|
|
187
|
-
const validation = await validate(answer);
|
|
188
|
-
if (validation !== true) {
|
|
189
|
-
isValid = false;
|
|
190
|
-
errorMessage = typeof validation === "string" ? validation : "Invalid input.";
|
|
191
|
-
msg({ type: "M_ERROR", title: errorMessage });
|
|
192
|
-
gotError = true;
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (isValid) {
|
|
197
|
-
if (gotError) {
|
|
198
|
-
deleteLastLine();
|
|
199
|
-
deleteLastLine();
|
|
200
|
-
msg({ type: "M_MIDDLE", title: ` ${answer}` });
|
|
201
|
-
}
|
|
202
|
-
msg({ type: "M_NEWLINE", title: "" });
|
|
203
|
-
rl.close();
|
|
204
|
-
return answer;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
} finally {
|
|
208
|
-
rl.close();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { editAsync } from "external-editor";
|
|
2
|
-
import { AsyncResource } from "node:async_hooks";
|
|
3
|
-
import {
|
|
4
|
-
createPrompt,
|
|
5
|
-
useEffect,
|
|
6
|
-
useState,
|
|
7
|
-
useKeypress,
|
|
8
|
-
usePrefix,
|
|
9
|
-
isEnterKey,
|
|
10
|
-
makeTheme
|
|
11
|
-
} from "../../components/core/index.js";
|
|
12
|
-
export default createPrompt((config, done) => {
|
|
13
|
-
const {
|
|
14
|
-
waitForUseInput = true,
|
|
15
|
-
file: { postfix = config.postfix ?? ".txt", ...fileProps } = {},
|
|
16
|
-
validate = () => true
|
|
17
|
-
} = config;
|
|
18
|
-
const theme = makeTheme(config.theme);
|
|
19
|
-
const [status, setStatus] = useState("idle");
|
|
20
|
-
const [value, setValue] = useState(config.default || "");
|
|
21
|
-
const [errorMsg, setError] = useState();
|
|
22
|
-
const prefix = usePrefix({ status, theme });
|
|
23
|
-
function startEditor(rl) {
|
|
24
|
-
rl.pause();
|
|
25
|
-
const editCallback = AsyncResource.bind(
|
|
26
|
-
async (error2, answer) => {
|
|
27
|
-
rl.resume();
|
|
28
|
-
if (error2) {
|
|
29
|
-
setError(error2.toString());
|
|
30
|
-
} else {
|
|
31
|
-
setStatus("loading");
|
|
32
|
-
const isValid = await validate(answer);
|
|
33
|
-
if (isValid === true) {
|
|
34
|
-
setError(void 0);
|
|
35
|
-
setStatus("done");
|
|
36
|
-
done(answer);
|
|
37
|
-
} else {
|
|
38
|
-
setValue(answer);
|
|
39
|
-
setError(isValid || "You must provide a valid value");
|
|
40
|
-
setStatus("idle");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
editAsync(value, (error2, answer) => void editCallback(error2, answer), {
|
|
46
|
-
postfix,
|
|
47
|
-
...fileProps
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
useEffect((rl) => {
|
|
51
|
-
if (!waitForUseInput) {
|
|
52
|
-
startEditor(rl);
|
|
53
|
-
}
|
|
54
|
-
}, []);
|
|
55
|
-
useKeypress((key, rl) => {
|
|
56
|
-
if (status !== "idle") {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (isEnterKey(key)) {
|
|
60
|
-
startEditor(rl);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const message = theme.style.message(config.message, status);
|
|
64
|
-
let helpTip = "";
|
|
65
|
-
if (status === "loading") {
|
|
66
|
-
helpTip = theme.style.help("Received");
|
|
67
|
-
} else if (status === "idle") {
|
|
68
|
-
const enterKey = theme.style.key("enter");
|
|
69
|
-
helpTip = theme.style.help(
|
|
70
|
-
`Press ${enterKey} to launch your preferred editor.`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
let error = "";
|
|
74
|
-
if (errorMsg) {
|
|
75
|
-
error = theme.style.error(errorMsg);
|
|
76
|
-
}
|
|
77
|
-
return [[prefix, message, helpTip].filter(Boolean).join(" "), error];
|
|
78
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import colors from "picocolors";
|
|
2
|
-
import {
|
|
3
|
-
createPrompt,
|
|
4
|
-
useMemo,
|
|
5
|
-
useState,
|
|
6
|
-
useKeypress,
|
|
7
|
-
usePrefix,
|
|
8
|
-
isEnterKey,
|
|
9
|
-
makeTheme,
|
|
10
|
-
Separator
|
|
11
|
-
} from "../../components/core/index.js";
|
|
12
|
-
function normalizeChoices(choices) {
|
|
13
|
-
return choices.map((choice) => {
|
|
14
|
-
if (Separator.isSeparator(choice)) {
|
|
15
|
-
return choice;
|
|
16
|
-
}
|
|
17
|
-
const name = "name" in choice ? choice.name : String(choice.value);
|
|
18
|
-
const value = "value" in choice ? choice.value : name;
|
|
19
|
-
return {
|
|
20
|
-
value,
|
|
21
|
-
name,
|
|
22
|
-
key: choice.key.toLowerCase()
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const helpChoice = {
|
|
27
|
-
key: "h",
|
|
28
|
-
name: "Help, list all options",
|
|
29
|
-
value: void 0
|
|
30
|
-
};
|
|
31
|
-
const expand = createPrompt(
|
|
32
|
-
(config, done) => {
|
|
33
|
-
const { default: defaultKey = "h" } = config;
|
|
34
|
-
const choices = useMemo(
|
|
35
|
-
|
|
36
|
-
() => normalizeChoices(config.choices),
|
|
37
|
-
[config.choices]
|
|
38
|
-
);
|
|
39
|
-
const [status, setStatus] = useState("idle");
|
|
40
|
-
const [value, setValue] = useState("");
|
|
41
|
-
const [expanded, setExpanded] = useState(config.expanded ?? false);
|
|
42
|
-
const [errorMsg, setError] = useState();
|
|
43
|
-
const theme = makeTheme(config.theme);
|
|
44
|
-
const prefix = usePrefix({ theme, status });
|
|
45
|
-
useKeypress((event, rl) => {
|
|
46
|
-
if (isEnterKey(event)) {
|
|
47
|
-
const answer = (value || defaultKey).toLowerCase();
|
|
48
|
-
if (answer === "h" && !expanded) {
|
|
49
|
-
setExpanded(true);
|
|
50
|
-
} else {
|
|
51
|
-
const selectedChoice = choices.find(
|
|
52
|
-
(choice) => !Separator.isSeparator(choice) && choice.key === answer
|
|
53
|
-
);
|
|
54
|
-
if (selectedChoice) {
|
|
55
|
-
setStatus("done");
|
|
56
|
-
setValue(answer);
|
|
57
|
-
done(selectedChoice.value);
|
|
58
|
-
} else if (value === "") {
|
|
59
|
-
setError("Please input a value");
|
|
60
|
-
} else {
|
|
61
|
-
setError(`"${colors.red(value)}" isn't an available option`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
setValue(rl.line);
|
|
66
|
-
setError(void 0);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
const message = theme.style.message(config.message, status);
|
|
70
|
-
if (status === "done") {
|
|
71
|
-
const selectedChoice = choices.find(
|
|
72
|
-
(choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase()
|
|
73
|
-
);
|
|
74
|
-
return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
|
|
75
|
-
}
|
|
76
|
-
const allChoices = expanded ? choices : [...choices, helpChoice];
|
|
77
|
-
let longChoices = "";
|
|
78
|
-
let shortChoices = allChoices.map((choice) => {
|
|
79
|
-
if (Separator.isSeparator(choice)) {
|
|
80
|
-
return "";
|
|
81
|
-
}
|
|
82
|
-
if (choice.key === defaultKey) {
|
|
83
|
-
return choice.key.toUpperCase();
|
|
84
|
-
}
|
|
85
|
-
return choice.key;
|
|
86
|
-
}).join("");
|
|
87
|
-
shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
|
|
88
|
-
if (expanded) {
|
|
89
|
-
shortChoices = "";
|
|
90
|
-
longChoices = allChoices.map((choice) => {
|
|
91
|
-
if (Separator.isSeparator(choice)) {
|
|
92
|
-
return ` ${choice.separator}`;
|
|
93
|
-
}
|
|
94
|
-
const line = ` ${choice.key}) ${choice.name}`;
|
|
95
|
-
if (choice.key === value.toLowerCase()) {
|
|
96
|
-
return theme.style.highlight(line);
|
|
97
|
-
}
|
|
98
|
-
return line;
|
|
99
|
-
}).join("\n");
|
|
100
|
-
}
|
|
101
|
-
let helpTip = "";
|
|
102
|
-
const currentOption = choices.find(
|
|
103
|
-
(choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase()
|
|
104
|
-
);
|
|
105
|
-
if (currentOption) {
|
|
106
|
-
helpTip = `${colors.cyan(">>")} ${currentOption.name}`;
|
|
107
|
-
}
|
|
108
|
-
let error = "";
|
|
109
|
-
if (errorMsg) {
|
|
110
|
-
error = theme.style.error(errorMsg);
|
|
111
|
-
}
|
|
112
|
-
return [
|
|
113
|
-
`${prefix} ${message}${shortChoices} ${value}`,
|
|
114
|
-
[longChoices, helpTip, error].filter(Boolean).join("\n")
|
|
115
|
-
];
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
export default expand;
|
|
119
|
-
export { Separator } from "../../components/core/index.js";
|