@reliverse/relinka 1.1.4 → 1.1.6

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.
Files changed (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,176 +1,214 @@
1
- import ansiEscapes from "ansi-escapes";
2
- import colors from "picocolors";
1
+ import ansiEscapes from 'ansi-escapes';
2
+ import colors from 'picocolors';
3
3
  import {
4
- createPrompt,
5
- useState,
6
- useKeypress,
7
- usePrefix,
8
- usePagination,
9
- useRef,
10
- useMemo,
11
- useEffect,
12
- isBackspaceKey,
13
- isEnterKey,
14
- isUpKey,
15
- isDownKey,
16
- isNumberKey,
17
- Separator,
18
- ValidationError,
19
- makeTheme
20
- } from "../../components/core/index.js";
21
- import figures from "../../components/figures/index.js";
4
+ createPrompt,
5
+ useState,
6
+ useKeypress,
7
+ usePrefix,
8
+ usePagination,
9
+ useRef,
10
+ useMemo,
11
+ useEffect,
12
+ isBackspaceKey,
13
+ isEnterKey,
14
+ isUpKey,
15
+ isDownKey,
16
+ isNumberKey,
17
+ Separator,
18
+ ValidationError,
19
+ makeTheme,
20
+ } from '../../components/core/index.js';
21
+ import figures from '../../components/figures/index.js';
22
+
23
+ const isString = (a) => typeof a === 'string';
24
+
22
25
  const selectTheme = {
23
- icon: { cursor: figures.pointer },
24
- style: {
25
- disabled: (text) => colors.dim(`- ${text}`),
26
- description: (text) => colors.cyan(text)
27
- },
28
- helpMode: "auto"
26
+ icon: {
27
+ cursor: figures.pointer,
28
+ },
29
+ style: {
30
+ disabled: (text) => colors.dim(`- ${text}`),
31
+ description: (text) => colors.cyan(text),
32
+ },
33
+ helpMode: 'auto',
29
34
  };
35
+
30
36
  function isSelectable(item) {
31
- return !Separator.isSeparator(item) && !item.disabled;
37
+ return !Separator.isSeparator(item) && !item.disabled;
32
38
  }
39
+
33
40
  function normalizeChoices(choices) {
34
- return choices.map((choice) => {
35
- if (Separator.isSeparator(choice)) {
36
- return choice;
37
- }
38
- if (typeof choice === "string") {
39
- return {
40
- value: choice,
41
- name: choice,
42
- short: choice,
43
- disabled: false
44
- };
45
- }
46
- const name = choice.name ?? String(choice.value);
47
- return {
48
- value: choice.value,
49
- name,
50
- description: choice.description,
51
- short: choice.short ?? name,
52
- disabled: choice.disabled ?? false
53
- };
54
- });
41
+ return choices.map((choice) => {
42
+ if (Separator.isSeparator(choice)) {
43
+ return choice;
44
+ }
45
+
46
+ if (isString(choice)) {
47
+ return {
48
+ value: choice,
49
+ name: choice,
50
+ short: choice,
51
+ disabled: false,
52
+ };
53
+ }
54
+
55
+ const name = choice.name ?? String(choice.value);
56
+
57
+ return {
58
+ value: choice.value,
59
+ name,
60
+ description: choice.description,
61
+ short: choice.short ?? name,
62
+ disabled: choice.disabled ?? false,
63
+ };
64
+ });
55
65
  }
56
- const select = createPrompt(
57
- (config, done) => {
58
- const { loop = true, pageSize = 7 } = config;
66
+
67
+ const select = createPrompt((config, done) => {
68
+ const {loop = true, pageSize = 7} = config;
59
69
  const firstRender = useRef(true);
60
70
  const theme = makeTheme(selectTheme, config.theme);
61
- const [status, setStatus] = useState("idle");
62
- const prefix = usePrefix({ status, theme });
71
+ const [status, setStatus] = useState('idle');
72
+ const prefix = usePrefix({
73
+ status,
74
+ theme,
75
+ });
63
76
  const searchTimeoutRef = useRef();
64
- const items = useMemo(
65
- () => normalizeChoices(config.choices),
66
- [config.choices]
67
- );
77
+
78
+ const items = useMemo(() => normalizeChoices(config.choices), [config.choices]);
79
+
68
80
  const bounds = useMemo(() => {
69
- const first = items.findIndex(isSelectable);
70
- const last = items.findLastIndex(isSelectable);
71
- if (first === -1) {
72
- throw new ValidationError(
73
- "[select prompt] No selectable choices. All choices are disabled."
74
- );
75
- }
76
- return { first, last };
81
+ const first = items.findIndex(isSelectable);
82
+ const last = items.findLastIndex(isSelectable);
83
+
84
+ if (first === -1) {
85
+ throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
86
+ }
87
+
88
+ return {
89
+ first,
90
+ last,
91
+ };
77
92
  }, [items]);
93
+
78
94
  const defaultItemIndex = useMemo(() => {
79
- if (!("default" in config)) {
80
- return -1;
81
- }
82
- return items.findIndex(
83
- (item) => isSelectable(item) && item.value === config.default
84
- );
95
+ if (!('default' in config)) {
96
+ return -1;
97
+ }
98
+
99
+ return items.findIndex((item) => isSelectable(item) && item.value === config.default);
85
100
  }, [config.default, items]);
86
- const [active, setActive] = useState(
87
- defaultItemIndex === -1 ? bounds.first : defaultItemIndex
88
- );
101
+
102
+ const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
103
+
89
104
  const selectedChoice = items[active];
105
+
90
106
  useKeypress((key, rl) => {
91
- clearTimeout(searchTimeoutRef.current);
92
- if (isEnterKey(key)) {
93
- setStatus("done");
94
- done(selectedChoice.value);
95
- } else if (isUpKey(key) || isDownKey(key)) {
96
- rl.clearLine(0);
97
- if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
98
- const offset = isUpKey(key) ? -1 : 1;
99
- let next = active;
100
- do {
101
- next = (next + offset + items.length) % items.length;
102
- } while (!isSelectable(items[next]));
103
- setActive(next);
104
- }
105
- } else if (isNumberKey(key)) {
106
- rl.clearLine(0);
107
- const position = Number(key.name) - 1;
108
- const item = items[position];
109
- if (item != null && isSelectable(item)) {
110
- setActive(position);
111
- }
112
- } else if (isBackspaceKey(key)) {
113
- rl.clearLine(0);
114
- } else {
115
- const searchTerm = rl.line.toLowerCase();
116
- const matchIndex = items.findIndex((item) => {
117
- if (Separator.isSeparator(item) || !isSelectable(item)) {
118
- return false;
119
- }
120
- return item.name.toLowerCase().startsWith(searchTerm);
121
- });
122
- if (matchIndex !== -1) {
123
- setActive(matchIndex);
107
+ clearTimeout(searchTimeoutRef.current);
108
+ if (isEnterKey(key)) {
109
+ setStatus('done');
110
+ done(selectedChoice.value);
111
+ } else if (isUpKey(key) || isDownKey(key)) {
112
+ rl.clearLine(0);
113
+ if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
114
+ const offset = isUpKey(key) ? -1 : 1;
115
+ let next = active;
116
+
117
+ do {
118
+ next = (next + offset + items.length) % items.length;
119
+ } while (!isSelectable(items[next]))
120
+ setActive(next);
121
+ }
122
+ } else if (isNumberKey(key)) {
123
+ rl.clearLine(0);
124
+ const position = Number(key.name) - 1;
125
+ const item = items[position];
126
+
127
+ if (item != null && isSelectable(item)) {
128
+ setActive(position);
129
+ }
130
+ } else if (isBackspaceKey(key)) {
131
+ rl.clearLine(0);
132
+ } else {
133
+ const searchTerm = rl.line.toLowerCase();
134
+ const matchIndex = items.findIndex((item) => {
135
+ if (Separator.isSeparator(item) || !isSelectable(item)) {
136
+ return false;
137
+ }
138
+
139
+ return item
140
+ .name
141
+ .toLowerCase()
142
+ .startsWith(searchTerm);
143
+ });
144
+
145
+ if (matchIndex !== -1) {
146
+ setActive(matchIndex);
147
+ }
148
+
149
+ searchTimeoutRef.current = setTimeout(() => {
150
+ rl.clearLine(0);
151
+ }, 700);
124
152
  }
125
- searchTimeoutRef.current = setTimeout(() => {
126
- rl.clearLine(0);
127
- }, 700);
128
- }
153
+
154
+
129
155
  });
130
- useEffect(
131
- () => () => {
156
+ useEffect(() => () => {
132
157
  clearTimeout(searchTimeoutRef.current);
133
- },
134
- []
135
- );
158
+ }, []);
136
159
  const message = theme.style.message(config.message, status);
137
- let helpTipTop = "";
138
- let helpTipBottom = "";
139
- if (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current) {
140
- firstRender.current = false;
141
- if (items.length > pageSize) {
142
- helpTipBottom = `
143
- ${theme.style.help("(Use arrow keys to reveal more choices)")}`;
144
- } else {
145
- helpTipTop = theme.style.help("(Use arrow keys)");
146
- }
160
+ let helpTipTop = '';
161
+ let helpTipBottom = '';
162
+
163
+ if (theme.helpMode === 'always' || theme.helpMode === 'auto' && firstRender.current) {
164
+ firstRender.current = false;
165
+ if (items.length > pageSize) {
166
+ helpTipBottom = `
167
+ ${theme.style.help('(Use arrow keys to reveal more choices)')}`;
168
+ } else {
169
+ helpTipTop = theme.style.help('(Use arrow keys)');
170
+ }
147
171
  }
172
+
148
173
  const page = usePagination({
149
- items,
150
- active,
151
- renderItem({ item, isActive }) {
152
- if (Separator.isSeparator(item)) {
153
- return ` ${item.separator}`;
154
- }
155
- if (item.disabled) {
156
- const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
157
- return theme.style.disabled(`${item.name} ${disabledLabel}`);
158
- }
159
- const color = isActive ? theme.style.highlight : (x) => x;
160
- const cursor = isActive ? theme.icon.cursor : ` `;
161
- return color(`${cursor} ${item.name}`);
162
- },
163
- pageSize,
164
- loop
174
+ items,
175
+ active,
176
+ renderItem({item, isActive}) {
177
+ if (Separator.isSeparator(item)) {
178
+ return ` ${item.separator}`;
179
+ }
180
+
181
+ if (item.disabled) {
182
+ const disabledLabel = isString(item.disabled) ? item.disabled : '(disabled)';
183
+ return theme.style.disabled(`${item.name} ${disabledLabel}`);
184
+ }
185
+
186
+ const color = isActive ? theme.style.highlight : (x) => x;
187
+ const cursor = isActive ? theme.icon.cursor : ` `;
188
+
189
+ return color(`${cursor} ${item.name}`);
190
+ },
191
+ pageSize,
192
+ loop,
165
193
  });
166
- if (status === "done") {
167
- return `${prefix} ${message} ${theme.style.answer(selectedChoice.short)}`;
194
+
195
+ if (status === 'done') {
196
+ return `${prefix} ${message} ${theme.style.answer(selectedChoice.short)}`;
168
197
  }
198
+
169
199
  const choiceDescription = selectedChoice.description ? `
170
200
  ${theme.style.description(selectedChoice.description)}` : ``;
171
- return `${[prefix, message, helpTipTop].filter(Boolean).join(" ")}
201
+
202
+ return `${[
203
+ prefix,
204
+ message,
205
+ helpTipTop,
206
+ ]
207
+ .filter(Boolean)
208
+ .join(' ')}
172
209
  ${page}${helpTipBottom}${choiceDescription}${ansiEscapes.cursorHide}`;
173
- }
174
- );
210
+ });
211
+
175
212
  export default select;
176
- export { Separator } from "../../components/core/index.js";
213
+
214
+ export {Separator} from '../../components/core/index.js';
@@ -1,30 +1,30 @@
1
- import { stdin as input, stdout as output } from "process";
2
- import readline from "readline/promises";
3
- export async function selectPrompt(params) {
4
- const { message, options, initial } = params;
5
- const selectedIndex = initial ? options.findIndex((option) => option.value === initial) : 0;
6
- const rl = readline.createInterface({ input, output });
7
- while (true) {
8
- console.log(`
9
- ${message}`);
10
- options.forEach((option, index2) => {
11
- const prefix = index2 === selectedIndex ? "->" : " ";
12
- const isDefault = option.value === initial ? "(default)" : "";
13
- console.log(`${prefix} [${index2 + 1}] ${option.label} ${isDefault}`);
1
+ import {
2
+ stdin as input,
3
+ stdout as output,
4
+ } from 'node:process';
5
+ import readline from 'node:readline/promises';
6
+
7
+ export async function selectPrompt({options, initial}) {
8
+ const selectedIndex = initial ? options.findIndex((option) => option.value === initial) : 0;
9
+ const rl = readline.createInterface({
10
+ input,
11
+ output,
14
12
  });
15
- const promptMessage = initial !== void 0 ? `Please select an option by number (default ${selectedIndex + 1}): ` : "Please select an option by number: ";
16
- const response = await rl.question(promptMessage);
17
- let index;
18
- if (response.trim() === "" && initial !== void 0) {
19
- index = selectedIndex;
20
- } else {
21
- index = parseInt(response.trim(), 10) - 1;
13
+
14
+ while (true) {
15
+ const promptMessage = initial !== void 0 ? `Please select an option by number (default ${selectedIndex + 1}): ` : 'Please select an option by number: ';
16
+ const response = await rl.question(promptMessage);
17
+ let index;
18
+
19
+ if (response.trim() === '' && initial !== void 0) {
20
+ index = selectedIndex;
21
+ } else {
22
+ index = parseInt(response.trim(), 10) - 1;
23
+ }
24
+
25
+ if (index >= 0 && index < options.length) {
26
+ rl.close();
27
+ return options[index].value;
28
+ }
22
29
  }
23
- if (index >= 0 && index < options.length) {
24
- rl.close();
25
- return options[index].value;
26
- } else {
27
- console.log("Invalid selection. Please try again.");
28
- }
29
- }
30
30
  }
@@ -1,126 +1,6 @@
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 { fmt, msg, bar } from "../../utils/messages.js";
6
- import {
7
- countLines,
8
- deleteLastLine,
9
- deleteLastLines
10
- } from "../../utils/terminal.js";
11
- export async function numSelectPrompt(options) {
12
- const {
13
- title,
14
- hint,
15
- validate,
16
- defaultValue,
17
- schema,
18
- titleColor = "cyanBright",
19
- answerColor = "none",
20
- titleTypography = "bold",
21
- titleVariant,
22
- content,
23
- contentColor,
24
- contentTypography,
25
- contentVariant,
26
- borderColor = "viceGradient",
27
- variantOptions,
28
- inline = true,
29
- choices
30
- } = options;
31
- if (!choices || choices.length === 0) {
32
- throw new Error("Choices are required for select prompt.");
33
- }
34
- const rl = readline.createInterface({ input, output });
35
- const formattedBar = bar({ borderColor });
36
- let linesToDelete = 0;
37
- let errorMessage = "";
38
- while (true) {
39
- if (linesToDelete > 0) {
40
- deleteLastLines(linesToDelete);
1
+ export async function numSelectPrompt({choices}) {
2
+ if (!choices || !choices.length) {
3
+ throw Error('Choices are required for select prompt.');
41
4
  }
42
- const question = fmt({
43
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
44
- title,
45
- titleColor,
46
- titleTypography,
47
- titleVariant,
48
- content,
49
- contentColor,
50
- contentTypography,
51
- contentVariant,
52
- borderColor,
53
- hint,
54
- variantOptions,
55
- errorMessage
56
- });
57
- let choicesText = "";
58
- if (inline) {
59
- choicesText = choices.map(
60
- (choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` (${choice.description})` : ""}`
61
- ).join(" / ");
62
- } else {
63
- choicesText = choices.map(
64
- (choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
65
- ).join(`
66
- ${formattedBar} `);
67
- }
68
- const formattedPrompt = fmt({
69
- type: "M_NULL",
70
- title: `${question}${choicesText}
71
- ${formattedBar} ${colorize(
72
- `Enter your choice:`,
73
- contentColor
74
- )}
75
- ${formattedBar} `
76
- });
77
- const questionLines = countLines(formattedPrompt);
78
- linesToDelete = questionLines + 1;
79
- const prompt = await rl.question(formattedPrompt);
80
- const answer = prompt.trim() || defaultValue;
81
- if (!prompt.trim() && defaultValue !== void 0) {
82
- deleteLastLine();
83
- msg({
84
- type: "M_MIDDLE",
85
- title: ` ${defaultValue}`,
86
- titleColor: answerColor
87
- });
88
- }
89
- const num = Number(answer);
90
- if (isNaN(num) || num < 1 || num > choices.length) {
91
- errorMessage = `Please enter a number between 1 and ${choices.length}.`;
92
- continue;
93
- }
94
- const selectedChoice = choices[num - 1];
95
- const selectedValue = selectedChoice?.id ?? num;
96
- let isValid = true;
97
- errorMessage = "";
98
- if (schema) {
99
- isValid = Value.Check(schema, selectedValue);
100
- if (!isValid) {
101
- const errors = [...Value.Errors(schema, selectedValue)];
102
- if (errors.length > 0) {
103
- errorMessage = errors[0]?.message ?? "Invalid input.";
104
- } else {
105
- errorMessage = "Invalid input.";
106
- }
107
- }
108
- }
109
- if (validate && isValid) {
110
- const validation = await validate(selectedValue);
111
- if (validation !== true) {
112
- isValid = false;
113
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
114
- }
115
- }
116
- if (isValid) {
117
- msg({ type: "M_NEWLINE" });
118
- rl.close();
119
- if (selectedChoice?.action) {
120
- await selectedChoice.action();
121
- }
122
- return selectedValue;
123
- } else {
124
- }
125
- }
126
- }
5
+
6
+ while (true) {}}
@@ -1,26 +1,27 @@
1
- import Prompt from "../prompts/prompt.js";
1
+ import Prompt from '../prompts/prompt.js';
2
+
2
3
  export default class SelectKeyPrompt extends Prompt {
3
- options;
4
- cursor = 0;
5
- constructor(opts) {
6
- super(opts, false);
7
- this.options = opts.options;
8
- const keys = this.options.map(
9
- ({ value: [initial] }) => initial?.toLowerCase()
10
- );
11
- this.cursor = Math.max(keys.indexOf(opts.initialValue), 0);
12
- this.on("key", (key) => {
13
- if (!keys.includes(key)) {
14
- return;
15
- }
16
- const value = this.options.find(
17
- ({ value: [initial] }) => initial?.toLowerCase() === key
18
- );
19
- if (value) {
20
- this.value = value.value;
21
- this.state = "submit";
22
- this.emit("submit");
23
- }
24
- });
25
- }
4
+ options;
5
+ cursor = 0;
6
+ constructor(opts) {
7
+ super(opts, false);
8
+ this.options = opts.options;
9
+
10
+ const keys = this.options.map(({value: [initial]}) => initial?.toLowerCase());
11
+
12
+ this.cursor = Math.max(keys.indexOf(opts.initialValue), 0);
13
+ this.on('key', (key) => {
14
+ if (!keys.includes(key)) {
15
+ return;
16
+ }
17
+
18
+ const value = this.options.find(({value: [initial]}) => key === initial?.toLowerCase());
19
+
20
+ if (value) {
21
+ this.value = value.value;
22
+ this.state = 'submit';
23
+ this.emit('submit');
24
+ }
25
+ });
26
+ }
26
27
  }