@reliverse/relinka 1.1.10 → 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/LICENSE +21 -0
- package/README.md +38 -42
- 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 +3 -2
- 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,52 +0,0 @@
|
|
|
1
|
-
import { stdin, stdout } from "node:process";
|
|
2
|
-
import * as readline from "node:readline";
|
|
3
|
-
import { removeCursor, restoreCursor } from "../../utils/terminal.js";
|
|
4
|
-
const isWindows = globalThis.process.platform.startsWith("win");
|
|
5
|
-
export default function block({
|
|
6
|
-
input = stdin,
|
|
7
|
-
output = stdout,
|
|
8
|
-
overwrite = true,
|
|
9
|
-
hideCursor = true
|
|
10
|
-
} = {}) {
|
|
11
|
-
const rl = readline.createInterface({
|
|
12
|
-
input,
|
|
13
|
-
output,
|
|
14
|
-
prompt: "",
|
|
15
|
-
tabSize: 1
|
|
16
|
-
});
|
|
17
|
-
readline.emitKeypressEvents(input, rl);
|
|
18
|
-
if (input.isTTY) {
|
|
19
|
-
input.setRawMode(true);
|
|
20
|
-
}
|
|
21
|
-
const clear = (data, { name }) => {
|
|
22
|
-
const str = String(data);
|
|
23
|
-
if (str === "") {
|
|
24
|
-
process.exit(0);
|
|
25
|
-
}
|
|
26
|
-
if (!overwrite) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const dx = name === "return" ? 0 : -1;
|
|
30
|
-
const dy = name === "return" ? -1 : 0;
|
|
31
|
-
readline.moveCursor(output, dx, dy, () => {
|
|
32
|
-
readline.clearLine(output, 1, () => {
|
|
33
|
-
input.once("keypress", clear);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
if (hideCursor) {
|
|
38
|
-
removeCursor();
|
|
39
|
-
}
|
|
40
|
-
input.once("keypress", clear);
|
|
41
|
-
return () => {
|
|
42
|
-
input.off("keypress", clear);
|
|
43
|
-
if (hideCursor) {
|
|
44
|
-
restoreCursor();
|
|
45
|
-
}
|
|
46
|
-
if (input.isTTY && !isWindows) {
|
|
47
|
-
input.setRawMode(false);
|
|
48
|
-
}
|
|
49
|
-
rl.terminal = false;
|
|
50
|
-
rl.close();
|
|
51
|
-
};
|
|
52
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import ansiEscapes from "ansi-escapes";
|
|
2
|
-
import colors from "picocolors";
|
|
3
|
-
import {
|
|
4
|
-
createPrompt,
|
|
5
|
-
useState,
|
|
6
|
-
useKeypress,
|
|
7
|
-
usePrefix,
|
|
8
|
-
usePagination,
|
|
9
|
-
useRef,
|
|
10
|
-
useMemo,
|
|
11
|
-
makeTheme,
|
|
12
|
-
isUpKey,
|
|
13
|
-
isDownKey,
|
|
14
|
-
isSpaceKey,
|
|
15
|
-
isNumberKey,
|
|
16
|
-
isEnterKey,
|
|
17
|
-
ValidationError,
|
|
18
|
-
Separator
|
|
19
|
-
} from "../../components/core/index.js";
|
|
20
|
-
import figures from "../../components/figures/index.js";
|
|
21
|
-
const checkboxTheme = {
|
|
22
|
-
icon: {
|
|
23
|
-
checked: colors.green(figures.circleFilled),
|
|
24
|
-
unchecked: figures.circle,
|
|
25
|
-
cursor: figures.pointer
|
|
26
|
-
},
|
|
27
|
-
style: {
|
|
28
|
-
disabledChoice: (text) => colors.dim(`- ${text}`),
|
|
29
|
-
renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(", "),
|
|
30
|
-
description: (text) => colors.cyan(text)
|
|
31
|
-
},
|
|
32
|
-
helpMode: "auto"
|
|
33
|
-
};
|
|
34
|
-
function isSelectable(item) {
|
|
35
|
-
return !Separator.isSeparator(item) && !item.disabled;
|
|
36
|
-
}
|
|
37
|
-
function isChecked(item) {
|
|
38
|
-
return isSelectable(item) && Boolean(item.checked);
|
|
39
|
-
}
|
|
40
|
-
function toggle(item) {
|
|
41
|
-
return isSelectable(item) ? { ...item, checked: !item.checked } : item;
|
|
42
|
-
}
|
|
43
|
-
function check(checked) {
|
|
44
|
-
return function(item) {
|
|
45
|
-
return isSelectable(item) ? { ...item, checked } : item;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function normalizeChoices(choices) {
|
|
49
|
-
return choices.map((choice) => {
|
|
50
|
-
if (Separator.isSeparator(choice)) {
|
|
51
|
-
return choice;
|
|
52
|
-
}
|
|
53
|
-
if (typeof choice === "string") {
|
|
54
|
-
return {
|
|
55
|
-
value: choice,
|
|
56
|
-
name: choice,
|
|
57
|
-
short: choice,
|
|
58
|
-
disabled: false,
|
|
59
|
-
checked: false
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const name = choice.name ?? String(choice.value);
|
|
63
|
-
return {
|
|
64
|
-
|
|
65
|
-
value: choice.value,
|
|
66
|
-
name,
|
|
67
|
-
|
|
68
|
-
short: choice.short ?? name,
|
|
69
|
-
|
|
70
|
-
description: choice.description,
|
|
71
|
-
|
|
72
|
-
disabled: choice.disabled ?? false,
|
|
73
|
-
|
|
74
|
-
checked: choice.checked ?? false
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const checkbox = createPrompt(
|
|
79
|
-
(config, done) => {
|
|
80
|
-
const {
|
|
81
|
-
instructions,
|
|
82
|
-
pageSize = 7,
|
|
83
|
-
loop = true,
|
|
84
|
-
required,
|
|
85
|
-
validate = () => true
|
|
86
|
-
} = config;
|
|
87
|
-
const theme = makeTheme(checkboxTheme, config.theme);
|
|
88
|
-
const firstRender = useRef(true);
|
|
89
|
-
const [status, setStatus] = useState("idle");
|
|
90
|
-
const prefix = usePrefix({ status, theme });
|
|
91
|
-
const [items, setItems] = useState(
|
|
92
|
-
normalizeChoices(config.choices)
|
|
93
|
-
);
|
|
94
|
-
const bounds = useMemo(() => {
|
|
95
|
-
const first = items.findIndex(isSelectable);
|
|
96
|
-
const last = items.findLastIndex(isSelectable);
|
|
97
|
-
if (first === -1) {
|
|
98
|
-
throw new ValidationError(
|
|
99
|
-
"[checkbox prompt] No selectable choices. All choices are disabled."
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
return { first, last };
|
|
103
|
-
}, [items]);
|
|
104
|
-
const [active, setActive] = useState(bounds.first);
|
|
105
|
-
const [showHelpTip, setShowHelpTip] = useState(true);
|
|
106
|
-
const [errorMsg, setError] = useState();
|
|
107
|
-
useKeypress(async (key) => {
|
|
108
|
-
if (isEnterKey(key)) {
|
|
109
|
-
const selection = items.filter(isChecked);
|
|
110
|
-
const isValid = await validate([...selection]);
|
|
111
|
-
if (required && !items.some(isChecked)) {
|
|
112
|
-
setError("At least one choice must be selected");
|
|
113
|
-
} else if (isValid === true) {
|
|
114
|
-
setStatus("done");
|
|
115
|
-
done(selection.map((choice) => choice.value));
|
|
116
|
-
} else {
|
|
117
|
-
setError(isValid || "You must select a valid value");
|
|
118
|
-
}
|
|
119
|
-
} else if (isUpKey(key) || isDownKey(key)) {
|
|
120
|
-
if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
|
|
121
|
-
const offset = isUpKey(key) ? -1 : 1;
|
|
122
|
-
let next = active;
|
|
123
|
-
do {
|
|
124
|
-
next = (next + offset + items.length) % items.length;
|
|
125
|
-
} while (!isSelectable(items[next]));
|
|
126
|
-
setActive(next);
|
|
127
|
-
}
|
|
128
|
-
} else if (isSpaceKey(key)) {
|
|
129
|
-
setError(void 0);
|
|
130
|
-
setShowHelpTip(false);
|
|
131
|
-
setItems(
|
|
132
|
-
items.map((choice, i) => i === active ? toggle(choice) : choice)
|
|
133
|
-
);
|
|
134
|
-
} else if (key.name === "a") {
|
|
135
|
-
const selectAll = items.some(
|
|
136
|
-
(choice) => isSelectable(choice) && !choice.checked
|
|
137
|
-
);
|
|
138
|
-
setItems(items.map(check(selectAll)));
|
|
139
|
-
} else if (key.name === "i") {
|
|
140
|
-
setItems(items.map(toggle));
|
|
141
|
-
} else if (isNumberKey(key)) {
|
|
142
|
-
const position = Number(key.name) - 1;
|
|
143
|
-
const item = items[position];
|
|
144
|
-
if (item != null && isSelectable(item)) {
|
|
145
|
-
setActive(position);
|
|
146
|
-
setItems(
|
|
147
|
-
items.map(
|
|
148
|
-
(choice, i) => i === position ? toggle(choice) : choice
|
|
149
|
-
)
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
const message = theme.style.message(config.message, status);
|
|
155
|
-
let description;
|
|
156
|
-
const page = usePagination({
|
|
157
|
-
items,
|
|
158
|
-
active,
|
|
159
|
-
renderItem({ item, isActive }) {
|
|
160
|
-
if (Separator.isSeparator(item)) {
|
|
161
|
-
return ` ${item.separator}`;
|
|
162
|
-
}
|
|
163
|
-
if (item.disabled) {
|
|
164
|
-
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
165
|
-
return theme.style.disabledChoice(`${item.name} ${disabledLabel}`);
|
|
166
|
-
}
|
|
167
|
-
if (isActive) {
|
|
168
|
-
description = item.description;
|
|
169
|
-
}
|
|
170
|
-
const checkbox2 = item.checked ? theme.icon.checked : theme.icon.unchecked;
|
|
171
|
-
const color = isActive ? theme.style.highlight : (x) => x;
|
|
172
|
-
const cursor = isActive ? theme.icon.cursor : " ";
|
|
173
|
-
return color(`${cursor}${checkbox2} ${item.name}`);
|
|
174
|
-
},
|
|
175
|
-
pageSize,
|
|
176
|
-
loop
|
|
177
|
-
});
|
|
178
|
-
if (status === "done") {
|
|
179
|
-
const selection = items.filter(isChecked);
|
|
180
|
-
const answer = theme.style.answer(
|
|
181
|
-
theme.style.renderSelectedChoices(selection, items)
|
|
182
|
-
);
|
|
183
|
-
return `${prefix} ${message} ${answer}`;
|
|
184
|
-
}
|
|
185
|
-
let helpTipTop = "";
|
|
186
|
-
let helpTipBottom = "";
|
|
187
|
-
if (theme.helpMode === "always" || theme.helpMode === "auto" && showHelpTip && (instructions === void 0 || instructions)) {
|
|
188
|
-
if (typeof instructions === "string") {
|
|
189
|
-
helpTipTop = instructions;
|
|
190
|
-
} else {
|
|
191
|
-
const keys = [
|
|
192
|
-
`${theme.style.key("space")} to select`,
|
|
193
|
-
`${theme.style.key("a")} to toggle all`,
|
|
194
|
-
`${theme.style.key("i")} to invert selection`,
|
|
195
|
-
`and ${theme.style.key("enter")} to proceed`
|
|
196
|
-
];
|
|
197
|
-
helpTipTop = ` (Press ${keys.join(", ")})`;
|
|
198
|
-
}
|
|
199
|
-
if (items.length > pageSize && (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current)) {
|
|
200
|
-
helpTipBottom = `
|
|
201
|
-
${theme.style.help("(Use arrow keys to reveal more choices)")}`;
|
|
202
|
-
firstRender.current = false;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const choiceDescription = description ? `
|
|
206
|
-
${theme.style.description(description)}` : ``;
|
|
207
|
-
let error = "";
|
|
208
|
-
if (errorMsg) {
|
|
209
|
-
error = `
|
|
210
|
-
${theme.style.error(errorMsg)}`;
|
|
211
|
-
}
|
|
212
|
-
return `${prefix} ${message}${helpTipTop}
|
|
213
|
-
${page}${helpTipBottom}${choiceDescription}${error}${ansiEscapes.cursorHide}`;
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
export default checkbox;
|
|
217
|
-
export { Separator } from "../../components/core/index.js";
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Value } from "@sinclair/typebox/value";
|
|
2
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
3
|
-
import readline from "node:readline/promises";
|
|
4
|
-
import { colorize } from "../../utils/colorize.js";
|
|
5
|
-
import { bar, fmt, msg } from "../../utils/messages.js";
|
|
6
|
-
import { countLines, deleteLastLines } from "../../utils/terminal.js";
|
|
7
|
-
export async function confirmPrompt(options) {
|
|
8
|
-
const {
|
|
9
|
-
title,
|
|
10
|
-
defaultValue,
|
|
11
|
-
schema,
|
|
12
|
-
titleColor = "cyanBright",
|
|
13
|
-
titleTypography = "bold",
|
|
14
|
-
titleVariant,
|
|
15
|
-
content,
|
|
16
|
-
contentColor,
|
|
17
|
-
contentTypography,
|
|
18
|
-
contentVariant,
|
|
19
|
-
borderColor = "viceGradient",
|
|
20
|
-
hintColor = "dim",
|
|
21
|
-
variantOptions,
|
|
22
|
-
action
|
|
23
|
-
} = options;
|
|
24
|
-
const rl = readline.createInterface({ input, output });
|
|
25
|
-
let linesToDelete = 0;
|
|
26
|
-
let errorMessage = "";
|
|
27
|
-
try {
|
|
28
|
-
while (true) {
|
|
29
|
-
if (linesToDelete > 0) {
|
|
30
|
-
deleteLastLines(linesToDelete);
|
|
31
|
-
}
|
|
32
|
-
const question = fmt({
|
|
33
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
34
|
-
title,
|
|
35
|
-
titleColor,
|
|
36
|
-
titleTypography,
|
|
37
|
-
titleVariant,
|
|
38
|
-
content,
|
|
39
|
-
contentColor,
|
|
40
|
-
contentTypography,
|
|
41
|
-
contentVariant,
|
|
42
|
-
borderColor,
|
|
43
|
-
variantOptions,
|
|
44
|
-
errorMessage
|
|
45
|
-
});
|
|
46
|
-
let defaultHint = "";
|
|
47
|
-
if (defaultValue === true) {
|
|
48
|
-
defaultHint = "[Y/n]";
|
|
49
|
-
} else if (defaultValue === false) {
|
|
50
|
-
defaultHint = "[y/N]";
|
|
51
|
-
} else {
|
|
52
|
-
defaultHint = "[y/n]";
|
|
53
|
-
}
|
|
54
|
-
const fullPrompt = `${question}${colorize(defaultHint, hintColor)}: `;
|
|
55
|
-
const formattedPrompt = fmt({
|
|
56
|
-
type: "M_NULL",
|
|
57
|
-
title: fullPrompt
|
|
58
|
-
});
|
|
59
|
-
const questionLines = countLines(formattedPrompt);
|
|
60
|
-
linesToDelete = questionLines + 1;
|
|
61
|
-
const answer = (await rl.question(formattedPrompt)).toLowerCase().trim();
|
|
62
|
-
let value;
|
|
63
|
-
const formattedBar = bar({ borderColor });
|
|
64
|
-
if (!answer && defaultValue !== void 0) {
|
|
65
|
-
const injectedAnswer = defaultValue === true ? "y" : "n";
|
|
66
|
-
process.stdout.write(`${formattedBar} ${injectedAnswer}
|
|
67
|
-
`);
|
|
68
|
-
value = defaultValue;
|
|
69
|
-
} else if (answer === "y" || answer === "yes") {
|
|
70
|
-
value = true;
|
|
71
|
-
} else if (answer === "n" || answer === "no") {
|
|
72
|
-
value = false;
|
|
73
|
-
} else {
|
|
74
|
-
errorMessage = 'Please answer with "y" or "n".';
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
let isValid = true;
|
|
78
|
-
errorMessage = "";
|
|
79
|
-
if (schema) {
|
|
80
|
-
isValid = Value.Check(schema, value);
|
|
81
|
-
if (!isValid) {
|
|
82
|
-
const errors = [...Value.Errors(schema, value)];
|
|
83
|
-
errorMessage = errors.length > 0 ? errors[0]?.message ?? "Invalid input." : "Invalid input.";
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (isValid) {
|
|
87
|
-
msg({ type: "M_NEWLINE" });
|
|
88
|
-
rl.close();
|
|
89
|
-
if (action && value) {
|
|
90
|
-
await action();
|
|
91
|
-
}
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
} finally {
|
|
96
|
-
rl.close();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { PromptOptions } from "../prompts/prompt.js";
|
|
2
|
-
import Prompt from "../prompts/prompt.js";
|
|
3
|
-
type ConfirmOptions = {
|
|
4
|
-
active: string;
|
|
5
|
-
inactive: string;
|
|
6
|
-
initialValue?: boolean;
|
|
7
|
-
} & PromptOptions<ConfirmPrompt>;
|
|
8
|
-
export default class ConfirmPrompt extends Prompt {
|
|
9
|
-
get cursor(): 0 | 1;
|
|
10
|
-
private get _value();
|
|
11
|
-
constructor(opts: ConfirmOptions);
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { cursor } from "sisteransi";
|
|
2
|
-
import Prompt from "../prompts/prompt.js";
|
|
3
|
-
export default class ConfirmPrompt extends Prompt {
|
|
4
|
-
get cursor() {
|
|
5
|
-
return this.value ? 0 : 1;
|
|
6
|
-
}
|
|
7
|
-
get _value() {
|
|
8
|
-
return this.cursor === 0;
|
|
9
|
-
}
|
|
10
|
-
constructor(opts) {
|
|
11
|
-
super(opts, false);
|
|
12
|
-
this.value = !!opts.initialValue;
|
|
13
|
-
this.on("value", () => {
|
|
14
|
-
this.value = this._value;
|
|
15
|
-
});
|
|
16
|
-
this.on("confirm", (confirm) => {
|
|
17
|
-
this.output.write(cursor.move(0, -1));
|
|
18
|
-
this.value = confirm;
|
|
19
|
-
this.state = "submit";
|
|
20
|
-
this.close();
|
|
21
|
-
});
|
|
22
|
-
this.on("cursor", () => {
|
|
23
|
-
this.value = !this.value;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createPrompt,
|
|
3
|
-
useState,
|
|
4
|
-
useKeypress,
|
|
5
|
-
isEnterKey,
|
|
6
|
-
usePrefix,
|
|
7
|
-
makeTheme
|
|
8
|
-
} from "../../components/core/index.js";
|
|
9
|
-
export default createPrompt((config, done) => {
|
|
10
|
-
const { transformer = (answer) => answer ? "yes" : "no" } = config;
|
|
11
|
-
const [status, setStatus] = useState("idle");
|
|
12
|
-
const [value, setValue] = useState("");
|
|
13
|
-
const theme = makeTheme(config.theme);
|
|
14
|
-
const prefix = usePrefix({ status, theme });
|
|
15
|
-
useKeypress((key, rl) => {
|
|
16
|
-
if (isEnterKey(key)) {
|
|
17
|
-
let answer = config.default;
|
|
18
|
-
if (/^(y|yes)/i.test(value)) {
|
|
19
|
-
answer = true;
|
|
20
|
-
} else if (/^(n|no)/i.test(value)) {
|
|
21
|
-
answer = false;
|
|
22
|
-
}
|
|
23
|
-
setValue(transformer(answer));
|
|
24
|
-
setStatus("done");
|
|
25
|
-
done(answer);
|
|
26
|
-
} else {
|
|
27
|
-
setValue(rl.line);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
let formattedValue = value;
|
|
31
|
-
let defaultValue = "";
|
|
32
|
-
if (status === "done") {
|
|
33
|
-
formattedValue = theme.style.answer(value);
|
|
34
|
-
} else {
|
|
35
|
-
defaultValue = ` ${theme.style.defaultAnswer(
|
|
36
|
-
!config.default ? "y/N" : "Y/n"
|
|
37
|
-
)}`;
|
|
38
|
-
}
|
|
39
|
-
const message = theme.style.message(config.message, status);
|
|
40
|
-
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
41
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import colors from "picocolors";
|
|
2
|
-
import figures from "../../components/figures/index.js";
|
|
3
|
-
export class Separator {
|
|
4
|
-
separator = colors.dim(
|
|
5
|
-
Array.from({ length: 15 }).join(figures.line)
|
|
6
|
-
);
|
|
7
|
-
type = "separator";
|
|
8
|
-
constructor(separator) {
|
|
9
|
-
if (separator) {
|
|
10
|
-
this.separator = separator;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
static isSeparator(choice) {
|
|
14
|
-
return Boolean(
|
|
15
|
-
choice && typeof choice === "object" && "type" in choice && choice.type === "separator"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Prettify } from "../../types/index.js";
|
|
2
|
-
type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
|
|
3
|
-
export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
|
|
4
|
-
export {};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import MuteStream from "mute-stream";
|
|
2
|
-
import { AsyncResource } from "node:async_hooks";
|
|
3
|
-
import * as readline from "node:readline";
|
|
4
|
-
import { onExit as onSignalExit } from "signal-exit";
|
|
5
|
-
import {
|
|
6
|
-
AbortPromptError,
|
|
7
|
-
CancelPromptError,
|
|
8
|
-
ExitPromptError
|
|
9
|
-
} from "./errors.js";
|
|
10
|
-
import { withHooks, effectScheduler } from "./hook-engine.js";
|
|
11
|
-
import { PromisePolyfill } from "./promise-polyfill.js";
|
|
12
|
-
import ScreenManager from "./screen-manager.js";
|
|
13
|
-
function getCallSites() {
|
|
14
|
-
const _prepareStackTrace = Error.prepareStackTrace;
|
|
15
|
-
try {
|
|
16
|
-
let result = [];
|
|
17
|
-
Error.prepareStackTrace = (_, callSites) => {
|
|
18
|
-
const callSitesWithoutCurrent = callSites.slice(1);
|
|
19
|
-
result = callSitesWithoutCurrent;
|
|
20
|
-
return callSitesWithoutCurrent;
|
|
21
|
-
};
|
|
22
|
-
new Error().stack;
|
|
23
|
-
return result;
|
|
24
|
-
} finally {
|
|
25
|
-
Error.prepareStackTrace = _prepareStackTrace;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function createPrompt(view) {
|
|
29
|
-
const callSites = getCallSites();
|
|
30
|
-
const callerFilename = callSites[1]?.getFileName?.();
|
|
31
|
-
const prompt = (config, context = {}) => {
|
|
32
|
-
const { input = process.stdin, signal } = context;
|
|
33
|
-
const cleanups = new Set();
|
|
34
|
-
const output = new MuteStream();
|
|
35
|
-
output.pipe(context.output ?? process.stdout);
|
|
36
|
-
const rl = readline.createInterface({
|
|
37
|
-
terminal: true,
|
|
38
|
-
input,
|
|
39
|
-
output
|
|
40
|
-
});
|
|
41
|
-
const screen = new ScreenManager(rl);
|
|
42
|
-
const { promise, resolve, reject } = PromisePolyfill.withResolver();
|
|
43
|
-
const cancel = () => reject(new CancelPromptError());
|
|
44
|
-
if (signal) {
|
|
45
|
-
const abort = () => reject(new AbortPromptError({ cause: signal.reason }));
|
|
46
|
-
if (signal.aborted) {
|
|
47
|
-
abort();
|
|
48
|
-
return Object.assign(promise, { cancel });
|
|
49
|
-
}
|
|
50
|
-
signal.addEventListener("abort", abort);
|
|
51
|
-
cleanups.add(() => signal.removeEventListener("abort", abort));
|
|
52
|
-
}
|
|
53
|
-
cleanups.add(
|
|
54
|
-
onSignalExit((code, signal2) => {
|
|
55
|
-
reject(
|
|
56
|
-
new ExitPromptError(
|
|
57
|
-
`User force closed the prompt with ${code} ${signal2}`
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
const checkCursorPos = () => screen.checkCursorPos();
|
|
63
|
-
rl.input.on("keypress", checkCursorPos);
|
|
64
|
-
cleanups.add(() => rl.input.removeListener("keypress", checkCursorPos));
|
|
65
|
-
return withHooks(rl, (cycle) => {
|
|
66
|
-
const hooksCleanup = AsyncResource.bind(() => effectScheduler.clearAll());
|
|
67
|
-
rl.on("close", hooksCleanup);
|
|
68
|
-
cleanups.add(() => rl.removeListener("close", hooksCleanup));
|
|
69
|
-
cycle(() => {
|
|
70
|
-
try {
|
|
71
|
-
const nextView = view(config, (value) => {
|
|
72
|
-
setImmediate(() => resolve(value));
|
|
73
|
-
});
|
|
74
|
-
if (nextView === void 0) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Prompt functions must return a string.
|
|
77
|
-
at ${callerFilename}`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
const [content, bottomContent] = typeof nextView === "string" ? [nextView] : nextView;
|
|
81
|
-
screen.render(content, bottomContent);
|
|
82
|
-
effectScheduler.run();
|
|
83
|
-
} catch (error) {
|
|
84
|
-
reject(error);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return Object.assign(
|
|
88
|
-
promise.then(
|
|
89
|
-
(answer) => {
|
|
90
|
-
effectScheduler.clearAll();
|
|
91
|
-
return answer;
|
|
92
|
-
},
|
|
93
|
-
(error) => {
|
|
94
|
-
effectScheduler.clearAll();
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
).finally(() => {
|
|
98
|
-
cleanups.forEach((cleanup) => cleanup());
|
|
99
|
-
screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
|
|
100
|
-
output.end();
|
|
101
|
-
}).then(() => promise),
|
|
102
|
-
{ cancel }
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
return prompt;
|
|
107
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare class AbortPromptError extends Error {
|
|
2
|
-
name: string;
|
|
3
|
-
message: string;
|
|
4
|
-
constructor(options?: {
|
|
5
|
-
cause?: unknown;
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
export declare class CancelPromptError extends Error {
|
|
9
|
-
name: string;
|
|
10
|
-
message: string;
|
|
11
|
-
}
|
|
12
|
-
export declare class ExitPromptError extends Error {
|
|
13
|
-
name: string;
|
|
14
|
-
}
|
|
15
|
-
export declare class HookError extends Error {
|
|
16
|
-
name: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class ValidationError extends Error {
|
|
19
|
-
name: string;
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export class AbortPromptError extends Error {
|
|
2
|
-
name = "AbortPromptError";
|
|
3
|
-
message = "Prompt was aborted";
|
|
4
|
-
constructor(options) {
|
|
5
|
-
super();
|
|
6
|
-
this.cause = options?.cause;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class CancelPromptError extends Error {
|
|
10
|
-
name = "CancelPromptError";
|
|
11
|
-
message = "Prompt was canceled";
|
|
12
|
-
}
|
|
13
|
-
export class ExitPromptError extends Error {
|
|
14
|
-
name = "ExitPromptError";
|
|
15
|
-
}
|
|
16
|
-
export class HookError extends Error {
|
|
17
|
-
name = "HookError";
|
|
18
|
-
}
|
|
19
|
-
export class ValidationError extends Error {
|
|
20
|
-
name = "ValidationError";
|
|
21
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { RelinkaReadline } from "../../types/index.js";
|
|
2
|
-
export declare function withHooks<T>(rl: RelinkaReadline, cb: (cycle: (render: () => void) => void) => T): T;
|
|
3
|
-
export declare function readline(): RelinkaReadline;
|
|
4
|
-
export declare function withUpdates<R, T extends (...args: any[]) => R>(fn: T): (...args: Parameters<T>) => R;
|
|
5
|
-
type SetPointer<Value> = {
|
|
6
|
-
get(): Value;
|
|
7
|
-
set(value: Value): void;
|
|
8
|
-
initialized: true;
|
|
9
|
-
};
|
|
10
|
-
type UnsetPointer<Value> = {
|
|
11
|
-
get(): void;
|
|
12
|
-
set(value: Value): void;
|
|
13
|
-
initialized: false;
|
|
14
|
-
};
|
|
15
|
-
type Pointer<Value> = SetPointer<Value> | UnsetPointer<Value>;
|
|
16
|
-
export declare function withPointer<Value, ReturnValue>(cb: (pointer: Pointer<Value>) => ReturnValue): ReturnValue;
|
|
17
|
-
export declare function handleChange(): void;
|
|
18
|
-
export declare const effectScheduler: {
|
|
19
|
-
queue(cb: (readline: RelinkaReadline) => void | (() => void)): void;
|
|
20
|
-
run(): void;
|
|
21
|
-
clearAll(): void;
|
|
22
|
-
};
|
|
23
|
-
export {};
|