@reliverse/relinka 1.1.5 → 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 (115) 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 -85
  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 -167
  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 -97
  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 -97
  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 -97
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -23
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -95
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -119
  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 -124
  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 -94
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.js +26 -34
  77. package/dist-npm/components/st-end/start.js +15 -29
  78. package/dist-npm/components/toggle/index.js +137 -113
  79. package/dist-npm/components/visual/animate/animate.js +10 -53
  80. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  81. package/dist-npm/mod.js +2 -1
  82. package/dist-npm/testing/index.js +83 -58
  83. package/dist-npm/types/general.js +1 -0
  84. package/dist-npm/types/index.js +3 -2
  85. package/dist-npm/types/keypress.js +36 -35
  86. package/dist-npm/types/readline.js +1 -0
  87. package/dist-npm/types/relinka.js +1 -0
  88. package/dist-npm/types/utils.js +1 -0
  89. package/dist-npm/utils/box.js +137 -135
  90. package/dist-npm/utils/color.js +74 -65
  91. package/dist-npm/utils/colorize.js +156 -124
  92. package/dist-npm/utils/component.js +657 -532
  93. package/dist-npm/utils/constants.js +63 -64
  94. package/dist-npm/utils/core.js +3 -2
  95. package/dist-npm/utils/decoder.js +223 -244
  96. package/dist-npm/utils/error.js +9 -4
  97. package/dist-npm/utils/errors.js +4 -14
  98. package/dist-npm/utils/format.js +24 -19
  99. package/dist-npm/utils/keypress.js +414 -316
  100. package/dist-npm/utils/log.js +15 -11
  101. package/dist-npm/utils/mapping.js +52 -45
  102. package/dist-npm/utils/messages.js +183 -183
  103. package/dist-npm/utils/platforms.js +20 -16
  104. package/dist-npm/utils/prompt-tmp.js +286 -235
  105. package/dist-npm/utils/prompt-two.js +286 -235
  106. package/dist-npm/utils/readline.js +7 -5
  107. package/dist-npm/utils/skeleton.js +170 -130
  108. package/dist-npm/utils/stream.js +2 -2
  109. package/dist-npm/utils/string.js +58 -44
  110. package/dist-npm/utils/terminal.js +34 -23
  111. package/dist-npm/utils/tree.js +41 -30
  112. package/dist-npm/utils/types.js +1 -0
  113. package/dist-npm/utils/utils.js +8 -8
  114. package/dist-npm/utils/variants.js +44 -36
  115. package/package.json +20 -28
@@ -1,217 +1,250 @@
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
- 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";
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
+
22
+ const isString = (a) => typeof a === 'string';
23
+
21
24
  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"
25
+ icon: {
26
+ checked: colors.green(figures.circleFilled),
27
+ unchecked: figures.circle,
28
+ cursor: figures.pointer,
29
+ },
30
+ style: {
31
+ disabledChoice: (text) => colors.dim(`- ${text}`),
32
+ renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(', '),
33
+ description: (text) => colors.cyan(text),
34
+ },
35
+ helpMode: 'auto',
33
36
  };
37
+
34
38
  function isSelectable(item) {
35
- return !Separator.isSeparator(item) && !item.disabled;
39
+ return !Separator.isSeparator(item) && !item.disabled;
36
40
  }
41
+
37
42
  function isChecked(item) {
38
- return isSelectable(item) && Boolean(item.checked);
43
+ return isSelectable(item) && Boolean(item.checked);
39
44
  }
45
+
40
46
  function toggle(item) {
41
- return isSelectable(item) ? { ...item, checked: !item.checked } : item;
47
+ return isSelectable(item) ? { ...item,
48
+ checked: !item.checked} : item;
42
49
  }
50
+
43
51
  function check(checked) {
44
- return function(item) {
45
- return isSelectable(item) ? { ...item, checked } : item;
46
- };
52
+ return (item) => isSelectable(item) ? { ...item,
53
+ checked} : item;
47
54
  }
55
+
48
56
  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
- });
57
+ return choices.map((choice) => {
58
+ if (Separator.isSeparator(choice)) {
59
+ return choice;
60
+ }
61
+
62
+ if (isString(choice)) {
63
+ return {
64
+ value: choice,
65
+ name: choice,
66
+ short: choice,
67
+ disabled: false,
68
+ checked: false,
69
+ };
70
+ }
71
+
72
+ const name = choice.name ?? String(choice.value);
73
+
74
+ return {
75
+ value: choice.value,
76
+ name,
77
+
78
+ short: choice.short ?? name,
79
+
80
+ description: choice.description,
81
+
82
+ disabled: choice.disabled ?? false,
83
+
84
+ checked: choice.checked ?? false,
85
+ };
86
+ });
77
87
  }
78
- const checkbox = createPrompt(
79
- (config, done) => {
88
+
89
+ const checkbox = createPrompt((config, done) => {
80
90
  const {
81
- instructions,
82
- pageSize = 7,
83
- loop = true,
84
- required,
85
- validate = () => true
91
+ instructions,
92
+ pageSize = 7,
93
+ loop = true,
94
+ required,
95
+ validate = () => true,
86
96
  } = config;
97
+
87
98
  const theme = makeTheme(checkboxTheme, config.theme);
88
99
  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
- );
100
+ const [status, setStatus] = useState('idle');
101
+ const prefix = usePrefix({
102
+ status,
103
+ theme,
104
+ });
105
+
106
+ const [items, setItems] = useState(normalizeChoices(config.choices));
107
+
94
108
  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 };
109
+ const first = items.findIndex(isSelectable);
110
+ const last = items.findLastIndex(isSelectable);
111
+
112
+ if (first === -1) {
113
+ throw new ValidationError('[checkbox prompt] No selectable choices. All choices are disabled.');
114
+ }
115
+
116
+ return {
117
+ first,
118
+ last,
119
+ };
103
120
  }, [items]);
121
+
104
122
  const [active, setActive] = useState(bounds.first);
105
123
  const [showHelpTip, setShowHelpTip] = useState(true);
106
124
  const [errorMsg, setError] = useState();
125
+
107
126
  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");
127
+ if (isEnterKey(key)) {
128
+ const selection = items.filter(isChecked);
129
+ const isValid = await validate(selection.slice());
130
+
131
+ if (required && !items.some(isChecked)) {
132
+ setError('At least one choice must be selected');
133
+ } else if (isValid) {
134
+ setStatus('done');
135
+ done(selection.map((choice) => choice.value));
136
+ } else {
137
+ setError(isValid || 'You must select a valid value');
138
+ }
139
+ } else if (isUpKey(key) || isDownKey(key)) {
140
+ if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
141
+ const offset = isUpKey(key) ? -1 : 1;
142
+ let next = active;
143
+
144
+ do {
145
+ next = (next + offset + items.length) % items.length;
146
+ } while (!isSelectable(items[next]))
147
+ setActive(next);
148
+ }
149
+ } else if (isSpaceKey(key)) {
150
+ setError(void 0);
151
+ setShowHelpTip(false);
152
+ setItems(items.map((choice, i) => i === active ? toggle(choice) : choice));
153
+ } else if (key.name === 'a') {
154
+ const selectAll = items.some((choice) => isSelectable(choice) && !choice.checked);
155
+
156
+ setItems(items.map(check(selectAll)));
157
+ } else if (key.name === 'i') {
158
+ setItems(items.map(toggle));
159
+ } else if (isNumberKey(key)) {
160
+ const position = Number(key.name) - 1;
161
+ const item = items[position];
162
+
163
+ if (item != null && isSelectable(item)) {
164
+ setActive(position);
165
+ setItems(items.map((choice, i) => i === position ? toggle(choice) : choice));
166
+ }
118
167
  }
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
- }
168
+
169
+
170
+
171
+
153
172
  });
154
173
  const message = theme.style.message(config.message, status);
155
174
  let description;
175
+
156
176
  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
+ items,
178
+ active,
179
+ renderItem({item, isActive}) {
180
+ if (Separator.isSeparator(item)) {
181
+ return ` ${item.separator}`;
182
+ }
183
+
184
+ if (item.disabled) {
185
+ const disabledLabel = isString(item.disabled) ? item.disabled : '(disabled)';
186
+ return theme.style.disabledChoice(`${item.name} ${disabledLabel}`);
187
+ }
188
+
189
+ if (isActive) {
190
+ description = item.description;
191
+ }
192
+
193
+ const checkbox2 = item.checked ? theme.icon.checked : theme.icon.unchecked;
194
+ const color = isActive ? theme.style.highlight : (x) => x;
195
+ const cursor = isActive ? theme.icon.cursor : ' ';
196
+
197
+ return color(`${cursor}${checkbox2} ${item.name}`);
198
+ },
199
+ pageSize,
200
+ loop,
177
201
  });
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}`;
202
+
203
+ if (status === 'done') {
204
+ const selection = items.filter(isChecked);
205
+ const answer = theme.style.answer(theme.style.renderSelectedChoices(selection, items));
206
+
207
+ return `${prefix} ${message} ${answer}`;
184
208
  }
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
- }
209
+
210
+ let helpTipTop = '';
211
+ let helpTipBottom = '';
212
+
213
+ if (theme.helpMode === 'always' || theme.helpMode === 'auto' && showHelpTip && (instructions === void 0 || instructions)) {
214
+ if (isString(instructions)) {
215
+ helpTipTop = instructions;
216
+ } else {
217
+ const keys = [
218
+ `${theme.style.key('space')} to select`,
219
+ `${theme.style.key('a')} to toggle all`,
220
+ `${theme.style.key('i')} to invert selection`,
221
+ `and ${theme.style.key('enter')} to proceed`,
222
+ ];
223
+
224
+ helpTipTop = ` (Press ${keys.join(', ')})`;
225
+ }
226
+
227
+ if (items.length > pageSize && (theme.helpMode === 'always' || theme.helpMode === 'auto' && firstRender.current)) {
228
+ helpTipBottom = `
229
+ ${theme.style.help('(Use arrow keys to reveal more choices)')}`;
230
+ firstRender.current = false;
231
+ }
204
232
  }
233
+
205
234
  const choiceDescription = description ? `
206
235
  ${theme.style.description(description)}` : ``;
207
- let error = "";
236
+
237
+ let error = '';
238
+
208
239
  if (errorMsg) {
209
- error = `
240
+ error = `
210
241
  ${theme.style.error(errorMsg)}`;
211
242
  }
243
+
212
244
  return `${prefix} ${message}${helpTipTop}
213
245
  ${page}${helpTipBottom}${choiceDescription}${error}${ansiEscapes.cursorHide}`;
214
- }
215
- );
246
+ });
247
+
216
248
  export default checkbox;
217
- export { Separator } from "../../components/core/index.js";
249
+
250
+ export {Separator} from '../../components/core/index.js';
@@ -1,98 +1,135 @@
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";
1
+ import {Value} from '@sinclair/typebox/value';
2
+ import process, {
3
+ stdin as input,
4
+ stdout as output,
5
+ } from 'node:process';
6
+ import readline from 'node:readline/promises';
7
+ import {colorize} from '../../utils/colorize.js';
8
+ import {
9
+ bar,
10
+ fmt,
11
+ msg,
12
+ } from '../../utils/messages.js';
13
+ import {
14
+ countLines,
15
+ deleteLastLines,
16
+ } from '../../utils/terminal.js';
17
+
7
18
  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",
19
+ const {
34
20
  title,
35
- titleColor,
36
- titleTypography,
21
+ defaultValue,
22
+ schema,
23
+ titleColor = 'cyanBright',
24
+ titleTypography = 'bold',
37
25
  titleVariant,
38
26
  content,
39
27
  contentColor,
40
28
  contentTypography,
41
29
  contentVariant,
42
- borderColor,
30
+ borderColor = 'viceGradient',
31
+ hintColor = 'dim',
43
32
  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}
33
+ action,
34
+ } = options;
35
+
36
+ const rl = readline.createInterface({
37
+ input,
38
+ output,
39
+ });
40
+ let linesToDelete = 0;
41
+ let errorMessage = '';
42
+
43
+ try {
44
+ while (true) {
45
+ if (linesToDelete > 0) {
46
+ deleteLastLines(linesToDelete);
47
+ }
48
+
49
+ const question = fmt({
50
+ type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
51
+ title,
52
+ titleColor,
53
+ titleTypography,
54
+ titleVariant,
55
+ content,
56
+ contentColor,
57
+ contentTypography,
58
+ contentVariant,
59
+ borderColor,
60
+ variantOptions,
61
+ errorMessage,
62
+ });
63
+
64
+ let defaultHint = '';
65
+
66
+ if (defaultValue) {
67
+ defaultHint = '[Y/n]';
68
+ } else if (!defaultValue) {
69
+ defaultHint = '[y/N]';
70
+ } else {
71
+ defaultHint = '[y/n]';
72
+ }
73
+
74
+
75
+ const fullPrompt = `${question}${colorize(defaultHint, hintColor)}: `;
76
+
77
+ const formattedPrompt = fmt({
78
+ type: 'M_NULL',
79
+ title: fullPrompt,
80
+ });
81
+
82
+ const questionLines = countLines(formattedPrompt);
83
+
84
+ linesToDelete = questionLines + 1;
85
+ const answer = (await rl.question(formattedPrompt))
86
+ .toLowerCase()
87
+ .trim();
88
+ let value;
89
+ const formattedBar = bar({
90
+ borderColor,
91
+ });
92
+
93
+ if (!answer && defaultValue !== void 0) {
94
+ const injectedAnswer = defaultValue ? 'y' : 'n';
95
+
96
+ process.stdout.write(`${formattedBar} ${injectedAnswer}
67
97
  `);
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.";
98
+ value = defaultValue;
99
+ } else if (answer === 'y' || answer === 'yes') {
100
+ value = true;
101
+ } else if (answer === 'n' || answer === 'no') {
102
+ value = false;
103
+ } else {
104
+ errorMessage = 'Please answer with "y" or "n".';
105
+ continue;
106
+ }
107
+
108
+
109
+ let isValid = true;
110
+
111
+ errorMessage = '';
112
+ if (schema) {
113
+ isValid = Value.Check(schema, value);
114
+ if (!isValid) {
115
+ const errors = Value.Errors(schema, value);
116
+ errorMessage = errors.length > 0 ? errors[0]?.message ?? 'Invalid input.' : 'Invalid input.';
117
+ }
118
+ }
119
+
120
+ if (isValid) {
121
+ msg({
122
+ type: 'M_NEWLINE',
123
+ });
124
+ rl.close();
125
+ if (action && value) {
126
+ await action();
127
+ }
128
+
129
+ return value;
130
+ }
84
131
  }
85
- }
86
- if (isValid) {
87
- msg({ type: "M_NEWLINE" });
132
+ } finally {
88
133
  rl.close();
89
- if (action && value) {
90
- await action();
91
- }
92
- return value;
93
- }
94
134
  }
95
- } finally {
96
- rl.close();
97
- }
98
135
  }