@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,112 +1,144 @@
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";
1
+ import {Value} from '@sinclair/typebox/value';
6
2
  import {
7
- countLines,
8
- deleteLastLine,
9
- deleteLastLines
10
- } from "../../utils/terminal.js";
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
+ deleteLastLine,
16
+ deleteLastLines,
17
+ } from '../../utils/terminal.js';
18
+
11
19
  export async function numMultiSelectPrompt(options) {
12
- const {
13
- title,
14
- choices,
15
- schema,
16
- defaultValue,
17
- titleColor = "cyanBright",
18
- answerColor = "none",
19
- titleTypography = "bold",
20
- titleVariant,
21
- hint,
22
- content,
23
- contentColor = "dim",
24
- contentTypography,
25
- contentVariant,
26
- borderColor = "viceGradient",
27
- variantOptions
28
- } = options;
29
- if (!choices || choices.length === 0) {
30
- throw new Error("Choices are required for multiselect prompt.");
31
- }
32
- const rl = readline.createInterface({ input, output });
33
- const formattedBar = bar({ borderColor });
34
- let linesToDelete = 0;
35
- let errorMessage = "";
36
- try {
37
- while (true) {
38
- if (linesToDelete > 0) {
39
- deleteLastLines(linesToDelete);
40
- }
41
- const question = fmt({
42
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
43
- title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}]` : ""}`,
44
- titleColor,
45
- titleTypography,
20
+ const {
21
+ title,
22
+ choices,
23
+ schema,
24
+ defaultValue,
25
+ titleColor = 'cyanBright',
26
+ titleTypography = 'bold',
46
27
  titleVariant,
28
+ hint,
47
29
  content,
48
- contentColor,
30
+ contentColor = 'dim',
49
31
  contentTypography,
50
32
  contentVariant,
51
- borderColor,
52
- hint,
33
+ borderColor = 'viceGradient',
53
34
  variantOptions,
54
- errorMessage,
55
- addNewLineBefore: false,
56
- addNewLineAfter: false
57
- });
58
- const choicesText = choices.map(
59
- (choice, index) => `${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
60
- ).join("\n");
61
- const fullPrompt = `${question}
35
+ } = options;
36
+
37
+ if (!choices || !choices.length) {
38
+ throw Error('Choices are required for multiselect prompt.');
39
+ }
40
+
41
+ const rl = readline.createInterface({
42
+ input,
43
+ output,
44
+ });
45
+ const formattedBar = bar({
46
+ borderColor,
47
+ });
48
+ let linesToDelete = 0;
49
+ let errorMessage = '';
50
+
51
+ try {
52
+ while (true) {
53
+ if (linesToDelete > 0) {
54
+ deleteLastLines(linesToDelete);
55
+ }
56
+
57
+ const question = fmt({
58
+ type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
59
+ title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(', ') : defaultValue}]` : ''}`,
60
+ titleColor,
61
+ titleTypography,
62
+ titleVariant,
63
+ content,
64
+ contentColor,
65
+ contentTypography,
66
+ contentVariant,
67
+ borderColor,
68
+ hint,
69
+ variantOptions,
70
+ errorMessage,
71
+ addNewLineBefore: false,
72
+ addNewLineAfter: false,
73
+ });
74
+
75
+ const choicesText = choices
76
+ .map((choice, index) => `${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ''}`)
77
+ .join('\n');
78
+
79
+ const fullPrompt = `${question}
62
80
  ${choicesText}
63
81
  ${formattedBar} ${colorize(`Enter your choices (comma-separated numbers between 1-${choices.length})`, contentColor)}:
64
82
  ${formattedBar} `;
65
- const formattedPrompt = fmt({
66
- type: "M_NULL",
67
- title: fullPrompt
68
- });
69
- const questionLines = countLines(formattedPrompt);
70
- linesToDelete = questionLines + 1;
71
- const answer = (await rl.question(formattedPrompt)).trim();
72
- if (!answer && defaultValue !== void 0) {
73
- deleteLastLine();
74
- msg({
75
- type: "M_MIDDLE",
76
- title: ` ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}`,
77
- titleColor: answerColor
78
- });
79
- msg({ type: "M_NEWLINE" });
80
- return defaultValue;
81
- }
82
- const selections = answer.split(",").map((s) => s.trim());
83
- const invalidSelections = selections.filter((s) => {
84
- const num = Number(s);
85
- return isNaN(num) || num < 1 || num > choices.length;
86
- });
87
- if (invalidSelections.length > 0) {
88
- errorMessage = `Invalid selections: ${invalidSelections.join(
89
- ", "
90
- )}. Please enter numbers between 1 and ${choices.length}.`;
91
- continue;
92
- }
93
- const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
94
- let isValid = true;
95
- errorMessage = "";
96
- if (schema) {
97
- isValid = Value.Check(schema, selectedValues);
98
- if (!isValid) {
99
- const errors = [...Value.Errors(schema, selectedValues)];
100
- errorMessage = errors.length > 0 ? errors[0]?.message ?? "Invalid input." : "Invalid input.";
83
+
84
+ const formattedPrompt = fmt({
85
+ type: 'M_NULL',
86
+ title: fullPrompt,
87
+ });
88
+
89
+ const questionLines = countLines(formattedPrompt);
90
+
91
+ linesToDelete = questionLines + 1;
92
+ const answer = (await rl.question(formattedPrompt)).trim();
93
+
94
+ if (!answer && defaultValue !== void 0) {
95
+ deleteLastLine();
96
+ msg({
97
+ type: 'M_MIDDLE',
98
+ title: ` ${Array.isArray(defaultValue) ? defaultValue.join(', ') : defaultValue}`,
99
+ titleColor: 'none',
100
+ });
101
+ msg({
102
+ type: 'M_NEWLINE',
103
+ });
104
+ return defaultValue;
105
+ }
106
+
107
+ const selections = answer
108
+ .split(',')
109
+ .map((s) => s.trim());
110
+
111
+ const invalidSelections = selections.filter((s) => {
112
+ const num = Number(s);
113
+ return isNaN(num) || num < 1 || num > choices.length;
114
+ });
115
+
116
+ if (invalidSelections.length > 0) {
117
+ errorMessage = `Invalid selections: ${invalidSelections.join(', ')}. Please enter numbers between 1 and ${choices.length}.`;
118
+ continue;
119
+ }
120
+
121
+ const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
122
+ let isValid = true;
123
+
124
+ errorMessage = '';
125
+ if (schema) {
126
+ isValid = Value.Check(schema, selectedValues);
127
+ if (!isValid) {
128
+ const errors = Value.Errors(schema, selectedValues);
129
+ errorMessage = errors.length > 0 ? errors[0]?.message ?? 'Invalid input.' : 'Invalid input.';
130
+ }
131
+ }
132
+
133
+ if (isValid) {
134
+ msg({
135
+ type: 'M_NEWLINE',
136
+ });
137
+ rl.close();
138
+ return selectedValues;
139
+ }
101
140
  }
102
- }
103
- if (isValid) {
104
- msg({ type: "M_NEWLINE" });
141
+ } finally {
105
142
  rl.close();
106
- return selectedValues;
107
- }
108
143
  }
109
- } finally {
110
- rl.close();
111
- }
112
144
  }
@@ -1,28 +1,39 @@
1
- import { stdin as input, stdout as output } from "process";
2
- import readline from "readline/promises";
1
+ import {
2
+ stdin as input,
3
+ stdout as output,
4
+ } from 'node:process';
5
+ import readline from 'node:readline/promises';
6
+
3
7
  export async function multiselectPrompt(params) {
4
- const { message, options, required = false, initial = [] } = params;
5
- const rl = readline.createInterface({ input, output });
6
- while (true) {
7
- console.log(`
8
- ${message}`);
9
- options.forEach((option, index) => {
10
- const isSelected = initial.includes(option) ? "[x]" : "[ ]";
11
- console.log(`${index + 1}. ${isSelected} ${option}`);
8
+ const {
9
+ options,
10
+ required = false,
11
+ initial = [],
12
+ } = params;
13
+ const rl = readline.createInterface({
14
+ input,
15
+ output,
12
16
  });
13
- const promptMessage = initial.length > 0 ? `Please select options by number (separated by commas, default ${initial.map((opt) => options.indexOf(opt) + 1).join(", ")}): ` : "Please select options by number (separated by commas): ";
14
- const response = await rl.question(promptMessage);
15
- let indices;
16
- if (response.trim() === "" && initial.length > 0) {
17
- indices = initial.map((opt) => options.indexOf(opt));
18
- } else {
19
- indices = response.split(",").map((num) => parseInt(num.trim(), 10) - 1).filter((index) => index >= 0 && index < options.length);
17
+
18
+ while (true) {
19
+ const promptMessage = initial.length > 0 ? `Please select options by number (separated by commas, default ${initial
20
+ .map((opt) => options.indexOf(opt) + 1)
21
+ .join(', ')}): ` : 'Please select options by number (separated by commas): ';
22
+ const response = await rl.question(promptMessage);
23
+ let indices;
24
+
25
+ if (response.trim() === '' && initial.length > 0) {
26
+ indices = initial.map((opt) => options.indexOf(opt));
27
+ } else {
28
+ indices = response
29
+ .split(',')
30
+ .map((num) => parseInt(num.trim(), 10) - 1)
31
+ .filter((index) => index >= 0 && index < options.length);
32
+ }
33
+
34
+ if (indices.length > 0 || !required && !indices.length) {
35
+ rl.close();
36
+ return indices.map((index) => options[index]);
37
+ }
20
38
  }
21
- if (indices.length > 0 || !required && indices.length === 0) {
22
- rl.close();
23
- return indices.map((index) => options[index]);
24
- } else {
25
- console.log("Invalid selection. Please try again.");
26
- }
27
- }
28
39
  }
@@ -1,25 +1,26 @@
1
- import { msg } from "../../utils/messages.js";
2
- export async function nextStepsPrompt(options) {
3
- const {
4
- title,
5
- titleColor = "cyanBright",
6
- answerColor = "none",
7
- titleVariant,
8
- titleTypography = "bold",
9
- content,
10
- contentColor,
11
- contentVariant,
12
- contentTypography
13
- } = options;
14
- msg({
15
- type: "M_INFO",
16
- title,
17
- titleColor,
18
- titleVariant,
19
- titleTypography,
20
- content,
21
- contentColor,
22
- contentVariant,
23
- contentTypography
24
- });
1
+ import {msg} from '../../utils/messages.js';
2
+
3
+ export function nextStepsPrompt(options) {
4
+ const {
5
+ title,
6
+ titleColor = 'cyanBright',
7
+ titleVariant,
8
+ titleTypography = 'bold',
9
+ content,
10
+ contentColor,
11
+ contentVariant,
12
+ contentTypography,
13
+ } = options;
14
+
15
+ msg({
16
+ type: 'M_INFO',
17
+ title,
18
+ titleColor,
19
+ titleVariant,
20
+ titleTypography,
21
+ content,
22
+ contentColor,
23
+ contentVariant,
24
+ contentTypography,
25
+ });
25
26
  }
@@ -1,100 +1,134 @@
1
1
  import {
2
- createPrompt,
3
- useState,
4
- useKeypress,
5
- usePrefix,
6
- isEnterKey,
7
- isBackspaceKey,
8
- makeTheme
9
- } from "../../components/core/index.js";
2
+ createPrompt,
3
+ useState,
4
+ useKeypress,
5
+ usePrefix,
6
+ isEnterKey,
7
+ isBackspaceKey,
8
+ makeTheme,
9
+ } from '../../components/core/index.js';
10
+
10
11
  function isStepOf(value, step, min) {
11
- const valuePow = value * Math.pow(10, 6);
12
- const stepPow = step * Math.pow(10, 6);
13
- const minPow = min * Math.pow(10, 6);
14
- return (valuePow - (Number.isFinite(min) ? minPow : 0)) % stepPow === 0;
12
+ const valuePow = value * 10 ** 6;
13
+ const stepPow = step * 10 ** 6;
14
+ const minPow = min * 10 ** 6;
15
+
16
+ return !((valuePow - (Number.isFinite(min) ? minPow : 0)) % stepPow);
15
17
  }
16
- function validateNumber(value, {
17
- min,
18
- max,
19
- step
20
- }) {
21
- if (value == null || Number.isNaN(value)) {
22
- return false;
23
- } else if (value < min || value > max) {
24
- return `Value must be between ${min} and ${max}`;
25
- } else if (step !== "any" && !isStepOf(value, step, min)) {
26
- return `Value must be a multiple of ${step}${Number.isFinite(min) ? ` starting from ${min}` : ""}`;
27
- }
28
- return true;
18
+
19
+ function validateNumber(value, {min, max, step}) {
20
+ if (value == null || Number.isNaN(value)) {
21
+ return false;
22
+ }
23
+
24
+ if (value < min || value > max) {
25
+ return `Value must be between ${min} and ${max}`;
26
+ }
27
+
28
+ if (step !== 'any' && !isStepOf(value, step, min)) {
29
+ return `Value must be a multiple of ${step}${Number.isFinite(min) ? ` starting from ${min}` : ''}`;
30
+ }
31
+
32
+ return true;
29
33
  }
30
- export default createPrompt(
31
- (config, done) => {
34
+
35
+ export default createPrompt((config, done) => {
32
36
  const {
33
- validate = () => true,
34
- min = -Infinity,
35
- max = Infinity,
36
- step = 1,
37
- required = false
37
+ validate = () => true,
38
+ min = -Infinity,
39
+ max = Infinity,
40
+ step = 1,
41
+ required = false,
38
42
  } = config;
43
+
39
44
  const theme = makeTheme(config.theme);
40
- const [status, setStatus] = useState("idle");
41
- const [value, setValue] = useState("");
42
- const validDefault = validateNumber(config.default, { min, max, step }) === true ? config.default?.toString() : void 0;
43
- const [defaultValue = "", setDefaultValue] = useState(validDefault);
45
+ const [status, setStatus] = useState('idle');
46
+ const [value, setValue] = useState('');
47
+ const validDefault = validateNumber(config.default, {
48
+ min,
49
+ max,
50
+ step,
51
+ }) ? config.default?.toString() : void 0;
52
+ const [defaultValue = '', setDefaultValue] = useState(validDefault);
44
53
  const [errorMsg, setError] = useState();
45
- const prefix = usePrefix({ status, theme });
54
+ const prefix = usePrefix({
55
+ status,
56
+ theme,
57
+ });
58
+
46
59
  useKeypress(async (key, rl) => {
47
- if (status !== "idle") {
48
- return;
49
- }
50
- if (isEnterKey(key)) {
51
- const input = value || defaultValue;
52
- const answer = input === "" ? void 0 : Number(input);
53
- setStatus("loading");
54
- let isValid = true;
55
- if (required || answer != null) {
56
- isValid = validateNumber(answer, { min, max, step });
57
- }
58
- if (isValid === true) {
59
- isValid = await validate(answer);
60
+ if (status !== 'idle') {
61
+ return;
60
62
  }
61
- if (isValid === true) {
62
- setValue(String(answer ?? ""));
63
- setStatus("done");
64
- done(answer);
63
+
64
+ if (isEnterKey(key)) {
65
+ const input = value || defaultValue;
66
+ const answer = input === '' ? void 0 : Number(input);
67
+ setStatus('loading');
68
+ let isValid = true;
69
+
70
+ if (required || answer != null) {
71
+ isValid = validateNumber(answer, {
72
+ min,
73
+ max,
74
+ step,
75
+ });
76
+ }
77
+
78
+ if (isValid) {
79
+ isValid = await validate(answer);
80
+ }
81
+
82
+ if (isValid) {
83
+ setValue(String(answer ?? ''));
84
+ setStatus('done');
85
+ done(answer);
86
+ } else {
87
+ rl.write(value);
88
+ setError(isValid || 'You must provide a valid numeric value');
89
+ setStatus('idle');
90
+ }
91
+ } else if (isBackspaceKey(key) && !value) {
92
+ setDefaultValue(void 0);
93
+ } else if (key.name === 'tab' && !value) {
94
+ setDefaultValue(void 0);
95
+ rl.clearLine(0);
96
+ rl.write(defaultValue);
97
+ setValue(defaultValue);
65
98
  } else {
66
- rl.write(value);
67
- setError(isValid || "You must provide a valid numeric value");
68
- setStatus("idle");
99
+ setValue(rl.line);
100
+ setError(void 0);
69
101
  }
70
- } else if (isBackspaceKey(key) && !value) {
71
- setDefaultValue(void 0);
72
- } else if (key.name === "tab" && !value) {
73
- setDefaultValue(void 0);
74
- rl.clearLine(0);
75
- rl.write(defaultValue);
76
- setValue(defaultValue);
77
- } else {
78
- setValue(rl.line);
79
- setError(void 0);
80
- }
102
+
81
103
  });
82
104
  const message = theme.style.message(config.message, status);
83
105
  let formattedValue = value;
84
- if (status === "done") {
85
- formattedValue = theme.style.answer(value);
106
+
107
+ if (status === 'done') {
108
+ formattedValue = theme.style.answer(value);
86
109
  }
110
+
87
111
  let defaultStr;
88
- if (defaultValue && status !== "done" && !value) {
89
- defaultStr = theme.style.defaultAnswer(defaultValue);
112
+
113
+ if (defaultValue && status !== 'done' && !value) {
114
+ defaultStr = theme.style.defaultAnswer(defaultValue);
90
115
  }
91
- let error = "";
116
+
117
+ let error = '';
118
+
92
119
  if (errorMsg) {
93
- error = theme.style.error(errorMsg);
120
+ error = theme.style.error(errorMsg);
94
121
  }
122
+
95
123
  return [
96
- [prefix, message, defaultStr, formattedValue].filter((v) => v !== void 0).join(" "),
97
- error
124
+ [
125
+ prefix,
126
+ message,
127
+ defaultStr,
128
+ formattedValue,
129
+ ]
130
+ .filter((v) => v !== void 0)
131
+ .join(' '),
132
+ error,
98
133
  ];
99
- }
100
- );
134
+ });
@@ -1,96 +1,2 @@
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 { fmt, msg } from "../../utils/messages.js";
5
- import {
6
- countLines,
7
- deleteLastLine,
8
- deleteLastLines
9
- } from "../../utils/terminal.js";
10
- export async function numberPrompt(options) {
11
- const {
12
- title,
13
- hint,
14
- validate,
15
- defaultValue,
16
- schema,
17
- titleColor = "cyanBright",
18
- answerColor = "none",
19
- titleTypography = "bold",
20
- titleVariant,
21
- content,
22
- contentColor,
23
- contentTypography,
24
- contentVariant,
25
- borderColor = "viceGradient",
26
- variantOptions
27
- } = options;
28
- const rl = readline.createInterface({ input, output });
29
- let linesToDelete = 0;
30
- let errorMessage = "";
31
- while (true) {
32
- if (linesToDelete > 0) {
33
- deleteLastLines(linesToDelete);
34
- }
35
- const question = fmt({
36
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
37
- title,
38
- titleColor,
39
- titleTypography,
40
- titleVariant,
41
- content,
42
- contentColor,
43
- contentTypography,
44
- contentVariant,
45
- borderColor,
46
- hint,
47
- variantOptions,
48
- errorMessage
49
- });
50
- const questionLines = countLines(question);
51
- const prompt = await rl.question(question);
52
- linesToDelete = questionLines + 1;
53
- const answer = prompt.trim() || defaultValue;
54
- if (prompt.trim() === "" && defaultValue !== void 0) {
55
- deleteLastLine();
56
- const defaultMsg = fmt({
57
- type: "M_MIDDLE",
58
- title: ` ${defaultValue}`,
59
- borderColor
60
- });
61
- console.log(defaultMsg);
62
- linesToDelete += countLines(defaultMsg);
63
- }
64
- const num = Number(answer);
65
- if (isNaN(num)) {
66
- errorMessage = "Please enter a valid number.";
67
- continue;
68
- }
69
- let isValid = true;
70
- errorMessage = "";
71
- if (schema) {
72
- isValid = Value.Check(schema, num);
73
- if (!isValid) {
74
- const errors = [...Value.Errors(schema, num)];
75
- if (errors.length > 0) {
76
- errorMessage = errors[0]?.message ?? "Invalid input.";
77
- } else {
78
- errorMessage = "Invalid input.";
79
- }
80
- }
81
- }
82
- if (validate && isValid) {
83
- const validation = await validate(num);
84
- if (validation !== true) {
85
- isValid = false;
86
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
87
- }
88
- }
89
- if (isValid) {
90
- msg({ type: "M_NEWLINE" });
91
- rl.close();
92
- return num;
93
- } else {
94
- }
95
- }
96
- }
1
+ export function numberPrompt() {
2
+ while (true) {}}