@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.
Files changed (224) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -42
  3. package/dist-npm/components/core/core.d.ts +2 -0
  4. package/dist-npm/components/core/core.js +2 -0
  5. package/dist-npm/{utils/constants.d.ts → components/levels/levels.d.ts} +1 -1
  6. package/dist-npm/components/{prompts/create.d.ts → modes/basic.d.ts} +3 -3
  7. package/dist-npm/components/{instance → modes}/basic.js +4 -4
  8. package/dist-npm/components/{instance → modes}/browser.d.ts +2 -2
  9. package/dist-npm/components/modes/browser.js +12 -0
  10. package/dist-npm/components/modes/shared.d.ts +5 -0
  11. package/dist-npm/components/modes/shared.js +2 -0
  12. package/dist-npm/components/{prompts → relinka}/relinka.d.ts +2 -4
  13. package/dist-npm/components/{prompts → relinka}/relinka.js +1 -7
  14. package/dist-npm/components/{instance/reporter → reporters}/basic.d.ts +1 -1
  15. package/dist-npm/components/{instance/reporter → reporters}/basic.js +2 -2
  16. package/dist-npm/components/{instance/reporter → reporters}/browser.d.ts +1 -1
  17. package/dist-npm/components/{instance/reporter → reporters}/fancy.d.ts +3 -3
  18. package/dist-npm/components/{instance/reporter → reporters}/fancy.js +5 -7
  19. package/dist-npm/main.d.ts +8 -1
  20. package/dist-npm/main.js +34 -1
  21. package/dist-npm/types/mod.d.ts +42 -0
  22. package/dist-npm/utils/color.js +4 -1
  23. package/dist-npm/utils/mod.d.ts +3 -0
  24. package/dist-npm/utils/mod.js +9 -0
  25. package/package.json +3 -2
  26. package/dist-npm/components/anykey/index.d.ts +0 -7
  27. package/dist-npm/components/anykey/index.js +0 -61
  28. package/dist-npm/components/block/block.d.ts +0 -10
  29. package/dist-npm/components/block/block.js +0 -52
  30. package/dist-npm/components/checkbox/index.d.ts +0 -3
  31. package/dist-npm/components/checkbox/index.js +0 -217
  32. package/dist-npm/components/confirm/confirm-main.d.ts +0 -3
  33. package/dist-npm/components/confirm/confirm-main.js +0 -98
  34. package/dist-npm/components/confirm/confirm-three.d.ts +0 -13
  35. package/dist-npm/components/confirm/confirm-three.js +0 -26
  36. package/dist-npm/components/confirm/index.d.ts +0 -2
  37. package/dist-npm/components/confirm/index.js +0 -41
  38. package/dist-npm/components/core/Separator.d.ts +0 -6
  39. package/dist-npm/components/core/Separator.js +0 -18
  40. package/dist-npm/components/core/create-prompt.d.ts +0 -4
  41. package/dist-npm/components/core/create-prompt.js +0 -107
  42. package/dist-npm/components/core/errors.d.ts +0 -20
  43. package/dist-npm/components/core/errors.js +0 -21
  44. package/dist-npm/components/core/hook-engine.d.ts +0 -23
  45. package/dist-npm/components/core/hook-engine.js +0 -109
  46. package/dist-npm/components/core/index.d.ts +0 -13
  47. package/dist-npm/components/core/index.js +0 -12
  48. package/dist-npm/components/core/key.d.ts +0 -10
  49. package/dist-npm/components/core/key.js +0 -16
  50. package/dist-npm/components/core/lines.d.ts +0 -14
  51. package/dist-npm/components/core/lines.js +0 -52
  52. package/dist-npm/components/core/make-theme.d.ts +0 -3
  53. package/dist-npm/components/core/make-theme.js +0 -28
  54. package/dist-npm/components/core/position.d.ts +0 -12
  55. package/dist-npm/components/core/position.js +0 -29
  56. package/dist-npm/components/core/promise-polyfill.d.ts +0 -7
  57. package/dist-npm/components/core/promise-polyfill.js +0 -13
  58. package/dist-npm/components/core/screen-manager.d.ts +0 -14
  59. package/dist-npm/components/core/screen-manager.js +0 -67
  60. package/dist-npm/components/core/theme.d.ts +0 -21
  61. package/dist-npm/components/core/theme.js +0 -24
  62. package/dist-npm/components/core/use-effect.d.ts +0 -2
  63. package/dist-npm/components/core/use-effect.js +0 -11
  64. package/dist-npm/components/core/use-keypress.d.ts +0 -3
  65. package/dist-npm/components/core/use-keypress.js +0 -21
  66. package/dist-npm/components/core/use-memo.d.ts +0 -1
  67. package/dist-npm/components/core/use-memo.js +0 -12
  68. package/dist-npm/components/core/use-pagination.d.ts +0 -11
  69. package/dist-npm/components/core/use-pagination.js +0 -34
  70. package/dist-npm/components/core/use-prefix.d.ts +0 -5
  71. package/dist-npm/components/core/use-prefix.js +0 -42
  72. package/dist-npm/components/core/use-ref.d.ts +0 -6
  73. package/dist-npm/components/core/use-ref.js +0 -4
  74. package/dist-npm/components/core/use-state.d.ts +0 -4
  75. package/dist-npm/components/core/use-state.js +0 -17
  76. package/dist-npm/components/core/useKeyPress.d.ts +0 -4
  77. package/dist-npm/components/core/useKeyPress.js +0 -16
  78. package/dist-npm/components/core/usePromptState.d.ts +0 -6
  79. package/dist-npm/components/core/usePromptState.js +0 -10
  80. package/dist-npm/components/core/utils.d.ts +0 -2
  81. package/dist-npm/components/core/utils.js +0 -11
  82. package/dist-npm/components/date/date.d.ts +0 -6
  83. package/dist-npm/components/date/date.js +0 -210
  84. package/dist-npm/components/editor/index.d.ts +0 -2
  85. package/dist-npm/components/editor/index.js +0 -78
  86. package/dist-npm/components/expand/index.d.ts +0 -3
  87. package/dist-npm/components/expand/index.js +0 -119
  88. package/dist-npm/components/figures/index.d.ts +0 -465
  89. package/dist-npm/components/figures/index.js +0 -299
  90. package/dist-npm/components/input/index.d.ts +0 -2
  91. package/dist-npm/components/input/index.js +0 -66
  92. package/dist-npm/components/input/text-main.d.ts +0 -3
  93. package/dist-npm/components/input/text-main.js +0 -103
  94. package/dist-npm/components/input/text.d.ts +0 -11
  95. package/dist-npm/components/input/text.js +0 -26
  96. package/dist-npm/components/instance/basic.d.ts +0 -8
  97. package/dist-npm/components/instance/browser.js +0 -18
  98. package/dist-npm/components/instance/shared.d.ts +0 -6
  99. package/dist-npm/components/instance/shared.js +0 -2
  100. package/dist-npm/components/mono/mono.d.ts +0 -5
  101. package/dist-npm/components/mono/mono.js +0 -64
  102. package/dist-npm/components/mono/monoTwo.d.ts +0 -30
  103. package/dist-npm/components/mono/monoTwo.js +0 -37
  104. package/dist-npm/components/multiselect/group-multiselect.d.ts +0 -23
  105. package/dist-npm/components/multiselect/group-multiselect.js +0 -58
  106. package/dist-npm/components/multiselect/multi-select-two.d.ts +0 -3
  107. package/dist-npm/components/multiselect/multi-select-two.js +0 -111
  108. package/dist-npm/components/multiselect/multi-select.d.ts +0 -21
  109. package/dist-npm/components/multiselect/multi-select.js +0 -45
  110. package/dist-npm/components/multiselect/multiselect-main.d.ts +0 -18
  111. package/dist-npm/components/multiselect/multiselect-main.js +0 -166
  112. package/dist-npm/components/multiselect/num-multi-select.d.ts +0 -3
  113. package/dist-npm/components/multiselect/num-multi-select.js +0 -111
  114. package/dist-npm/components/multiselect/num-multiselect-main.d.ts +0 -6
  115. package/dist-npm/components/multiselect/num-multiselect-main.js +0 -28
  116. package/dist-npm/components/next-steps/next-steps.d.ts +0 -2
  117. package/dist-npm/components/next-steps/next-steps.js +0 -24
  118. package/dist-npm/components/number/index.d.ts +0 -2
  119. package/dist-npm/components/number/index.js +0 -100
  120. package/dist-npm/components/number/number-main.d.ts +0 -3
  121. package/dist-npm/components/number/number-main.js +0 -95
  122. package/dist-npm/components/password/index.d.ts +0 -2
  123. package/dist-npm/components/password/index.js +0 -59
  124. package/dist-npm/components/password/password-main.d.ts +0 -3
  125. package/dist-npm/components/password/password-main.js +0 -119
  126. package/dist-npm/components/password/password-three.d.ts +0 -13
  127. package/dist-npm/components/password/password-three.js +0 -28
  128. package/dist-npm/components/progressbar/ProgressBar.d.ts +0 -22
  129. package/dist-npm/components/progressbar/ProgressBar.js +0 -53
  130. package/dist-npm/components/progressbar/helper.d.ts +0 -6
  131. package/dist-npm/components/progressbar/helper.js +0 -38
  132. package/dist-npm/components/progressbar/index.d.ts +0 -2
  133. package/dist-npm/components/progressbar/index.js +0 -1
  134. package/dist-npm/components/prompts/create.js +0 -35
  135. package/dist-npm/components/prompts/index.d.ts +0 -49
  136. package/dist-npm/components/prompts/index.js +0 -46
  137. package/dist-npm/components/prompts/prompt.d.ts +0 -36
  138. package/dist-npm/components/prompts/prompt.js +0 -232
  139. package/dist-npm/components/prompts/promptTwo.d.ts +0 -92
  140. package/dist-npm/components/prompts/promptTwo.js +0 -653
  141. package/dist-npm/components/range/range.d.ts +0 -62
  142. package/dist-npm/components/range/range.js +0 -270
  143. package/dist-npm/components/rawlist/index.d.ts +0 -3
  144. package/dist-npm/components/rawlist/index.js +0 -104
  145. package/dist-npm/components/results/results.d.ts +0 -10
  146. package/dist-npm/components/results/results.js +0 -34
  147. package/dist-npm/components/search/index.d.ts +0 -3
  148. package/dist-npm/components/search/index.js +0 -186
  149. package/dist-npm/components/select/index.d.ts +0 -3
  150. package/dist-npm/components/select/index.js +0 -176
  151. package/dist-npm/components/select/num-select-main.d.ts +0 -8
  152. package/dist-npm/components/select/num-select-main.js +0 -30
  153. package/dist-npm/components/select/num-select.d.ts +0 -5
  154. package/dist-npm/components/select/num-select.js +0 -125
  155. package/dist-npm/components/select/select-key.d.ts +0 -15
  156. package/dist-npm/components/select/select-key.js +0 -26
  157. package/dist-npm/components/select/select-main.d.ts +0 -19
  158. package/dist-npm/components/select/select-main.js +0 -151
  159. package/dist-npm/components/select/select-three.d.ts +0 -18
  160. package/dist-npm/components/select/select-three.js +0 -35
  161. package/dist-npm/components/select/select-two.d.ts +0 -2
  162. package/dist-npm/components/select/select-two.js +0 -98
  163. package/dist-npm/components/spinner/index.d.ts +0 -15
  164. package/dist-npm/components/spinner/index.js +0 -110
  165. package/dist-npm/components/st-end/end.d.ts +0 -2
  166. package/dist-npm/components/st-end/end.js +0 -35
  167. package/dist-npm/components/st-end/start.d.ts +0 -2
  168. package/dist-npm/components/st-end/start.js +0 -32
  169. package/dist-npm/components/toggle/index.d.ts +0 -13
  170. package/dist-npm/components/toggle/index.js +0 -121
  171. package/dist-npm/components/visual/animate/animate.d.ts +0 -13
  172. package/dist-npm/components/visual/animate/animate.js +0 -55
  173. package/dist-npm/components/visual/ascii-art/ascii-art.d.ts +0 -6
  174. package/dist-npm/components/visual/ascii-art/ascii-art.js +0 -12
  175. package/dist-npm/testing/index.d.ts +0 -18
  176. package/dist-npm/testing/index.js +0 -64
  177. package/dist-npm/types/general.d.ts +0 -134
  178. package/dist-npm/types/index.d.ts +0 -2
  179. package/dist-npm/types/index.js +0 -2
  180. package/dist-npm/types/keypress.d.ts +0 -52
  181. package/dist-npm/types/keypress.js +0 -37
  182. package/dist-npm/types/readline.d.ts +0 -30
  183. package/dist-npm/types/readline.js +0 -0
  184. package/dist-npm/types/relinka.d.ts +0 -30
  185. package/dist-npm/types/relinka.js +0 -0
  186. package/dist-npm/types/utils.d.ts +0 -17
  187. package/dist-npm/types/utils.js +0 -0
  188. package/dist-npm/utils/colorize.d.ts +0 -2
  189. package/dist-npm/utils/colorize.js +0 -130
  190. package/dist-npm/utils/component.d.ts +0 -101
  191. package/dist-npm/utils/component.js +0 -630
  192. package/dist-npm/utils/core.d.ts +0 -2
  193. package/dist-npm/utils/core.js +0 -2
  194. package/dist-npm/utils/decoder.d.ts +0 -14
  195. package/dist-npm/utils/decoder.js +0 -281
  196. package/dist-npm/utils/errors.d.ts +0 -1
  197. package/dist-npm/utils/errors.js +0 -15
  198. package/dist-npm/utils/keypress.d.ts +0 -7
  199. package/dist-npm/utils/keypress.js +0 -327
  200. package/dist-npm/utils/mapping.d.ts +0 -4
  201. package/dist-npm/utils/mapping.js +0 -49
  202. package/dist-npm/utils/messages.d.ts +0 -17
  203. package/dist-npm/utils/messages.js +0 -213
  204. package/dist-npm/utils/platforms.d.ts +0 -1
  205. package/dist-npm/utils/platforms.js +0 -22
  206. package/dist-npm/utils/prompt-tmp.d.ts +0 -13
  207. package/dist-npm/utils/prompt-tmp.js +0 -254
  208. package/dist-npm/utils/prompt-two.d.ts +0 -13
  209. package/dist-npm/utils/prompt-two.js +0 -254
  210. package/dist-npm/utils/readline.d.ts +0 -2
  211. package/dist-npm/utils/readline.js +0 -9
  212. package/dist-npm/utils/skeleton.d.ts +0 -7
  213. package/dist-npm/utils/skeleton.js +0 -145
  214. package/dist-npm/utils/terminal.d.ts +0 -5
  215. package/dist-npm/utils/terminal.js +0 -33
  216. package/dist-npm/utils/types.d.ts +0 -0
  217. package/dist-npm/utils/types.js +0 -0
  218. package/dist-npm/utils/utils.d.ts +0 -3
  219. package/dist-npm/utils/utils.js +0 -9
  220. package/dist-npm/utils/variants.d.ts +0 -9
  221. package/dist-npm/utils/variants.js +0 -49
  222. /package/dist-npm/{utils/constants.js → components/levels/levels.js} +0 -0
  223. /package/dist-npm/components/{instance/reporter → reporters}/browser.js +0 -0
  224. /package/dist-npm/types/{general.js → mod.js} +0 -0
@@ -1,100 +0,0 @@
1
- import {
2
- createPrompt,
3
- useState,
4
- useKeypress,
5
- usePrefix,
6
- isEnterKey,
7
- isBackspaceKey,
8
- makeTheme
9
- } from "../../components/core/index.js";
10
- 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;
15
- }
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;
29
- }
30
- export default createPrompt(
31
- (config, done) => {
32
- const {
33
- validate = () => true,
34
- min = -Infinity,
35
- max = Infinity,
36
- step = 1,
37
- required = false
38
- } = config;
39
- 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);
44
- const [errorMsg, setError] = useState();
45
- const prefix = usePrefix({ status, theme });
46
- 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
- }
61
- if (isValid === true) {
62
- setValue(String(answer ?? ""));
63
- setStatus("done");
64
- done(answer);
65
- } else {
66
- rl.write(value);
67
- setError(isValid || "You must provide a valid numeric value");
68
- setStatus("idle");
69
- }
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
- }
81
- });
82
- const message = theme.style.message(config.message, status);
83
- let formattedValue = value;
84
- if (status === "done") {
85
- formattedValue = theme.style.answer(value);
86
- }
87
- let defaultStr;
88
- if (defaultValue && status !== "done" && !value) {
89
- defaultStr = theme.style.defaultAnswer(defaultValue);
90
- }
91
- let error = "";
92
- if (errorMsg) {
93
- error = theme.style.error(errorMsg);
94
- }
95
- return [
96
- [prefix, message, defaultStr, formattedValue].filter((v) => v !== void 0).join(" "),
97
- error
98
- ];
99
- }
100
- );
@@ -1,3 +0,0 @@
1
- import type { TSchema, Static } from "@sinclair/typebox";
2
- import type { PromptOptions } from "../../types/general.js";
3
- export declare function numberPrompt<T extends TSchema>(options: PromptOptions<T>): Promise<Static<T>>;
@@ -1,95 +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 { 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
- titleTypography = "bold",
19
- titleVariant,
20
- content,
21
- contentColor,
22
- contentTypography,
23
- contentVariant,
24
- borderColor = "viceGradient",
25
- variantOptions
26
- } = options;
27
- const rl = readline.createInterface({ input, output });
28
- let linesToDelete = 0;
29
- let errorMessage = "";
30
- while (true) {
31
- if (linesToDelete > 0) {
32
- deleteLastLines(linesToDelete);
33
- }
34
- const question = fmt({
35
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
36
- title,
37
- titleColor,
38
- titleTypography,
39
- titleVariant,
40
- content,
41
- contentColor,
42
- contentTypography,
43
- contentVariant,
44
- borderColor,
45
- hint,
46
- variantOptions,
47
- errorMessage
48
- });
49
- const questionLines = countLines(question);
50
- const prompt = await rl.question(question);
51
- linesToDelete = questionLines + 1;
52
- const answer = prompt.trim() || defaultValue;
53
- if (prompt.trim() === "" && defaultValue !== void 0) {
54
- deleteLastLine();
55
- const defaultMsg = fmt({
56
- type: "M_MIDDLE",
57
- title: ` ${defaultValue}`,
58
- borderColor
59
- });
60
- console.log(defaultMsg);
61
- linesToDelete += countLines(defaultMsg);
62
- }
63
- const num = Number(answer);
64
- if (isNaN(num)) {
65
- errorMessage = "Please enter a valid number.";
66
- continue;
67
- }
68
- let isValid = true;
69
- errorMessage = "";
70
- if (schema) {
71
- isValid = Value.Check(schema, num);
72
- if (!isValid) {
73
- const errors = [...Value.Errors(schema, num)];
74
- if (errors.length > 0) {
75
- errorMessage = errors[0]?.message ?? "Invalid input.";
76
- } else {
77
- errorMessage = "Invalid input.";
78
- }
79
- }
80
- }
81
- if (validate && isValid) {
82
- const validation = await validate(num);
83
- if (validation !== true) {
84
- isValid = false;
85
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
86
- }
87
- }
88
- if (isValid) {
89
- msg({ type: "M_NEWLINE" });
90
- rl.close();
91
- return num;
92
- } else {
93
- }
94
- }
95
- }
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,59 +0,0 @@
1
- import ansiEscapes from "ansi-escapes";
2
- import {
3
- createPrompt,
4
- useState,
5
- useKeypress,
6
- usePrefix,
7
- isEnterKey,
8
- makeTheme
9
- } from "../../components/core/index.js";
10
- export default createPrompt((config, done) => {
11
- const { validate = () => true } = config;
12
- const theme = makeTheme(config.theme);
13
- const [status, setStatus] = useState("idle");
14
- const [errorMsg, setError] = useState();
15
- const [value, setValue] = useState("");
16
- const prefix = usePrefix({ status, theme });
17
- useKeypress(async (key, rl) => {
18
- if (status !== "idle") {
19
- return;
20
- }
21
- if (isEnterKey(key)) {
22
- const answer = value;
23
- setStatus("loading");
24
- const isValid = await validate(answer);
25
- if (isValid === true) {
26
- setValue(answer);
27
- setStatus("done");
28
- done(answer);
29
- } else {
30
- rl.write(value);
31
- setError(isValid || "You must provide a valid value");
32
- setStatus("idle");
33
- }
34
- } else {
35
- setValue(rl.line);
36
- setError(void 0);
37
- }
38
- });
39
- const message = theme.style.message(config.message, status);
40
- let formattedValue = "";
41
- let helpTip;
42
- if (config.mask) {
43
- const maskChar = typeof config.mask === "string" ? config.mask : "*";
44
- formattedValue = maskChar.repeat(value.length);
45
- } else if (status !== "done") {
46
- helpTip = `${theme.style.help("[input is masked]")}${ansiEscapes.cursorHide}`;
47
- }
48
- if (status === "done") {
49
- formattedValue = theme.style.answer(formattedValue);
50
- }
51
- let error = "";
52
- if (errorMsg) {
53
- error = theme.style.error(errorMsg);
54
- }
55
- return [
56
- [prefix, message, config.mask ? formattedValue : helpTip].join(" "),
57
- error
58
- ];
59
- });
@@ -1,3 +0,0 @@
1
- import type { Static, TSchema } from "@sinclair/typebox";
2
- import type { PromptOptions } from "../../types/general.js";
3
- export declare function passwordPrompt<T extends TSchema>(options: PromptOptions<T>): Promise<Static<T>>;
@@ -1,119 +0,0 @@
1
- import { Value } from "@sinclair/typebox/value";
2
- import { bar, fmt } from "../../utils/messages.js";
3
- import {
4
- countLines,
5
- deleteLastLines
6
- } from "../../utils/terminal.js";
7
- export async function passwordPrompt(options) {
8
- const {
9
- title,
10
- hint,
11
- validate,
12
- schema,
13
- defaultValue,
14
- titleColor = "cyanBright",
15
- titleTypography = "bold",
16
- titleVariant,
17
- content,
18
- contentColor,
19
- contentTypography,
20
- contentVariant,
21
- borderColor = "viceGradient",
22
- variantOptions
23
- } = options;
24
- let linesToDelete = 0;
25
- let errorMessage = "";
26
- while (true) {
27
- const question = fmt({
28
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
29
- title: `${title}${defaultValue ? ` [Default: ****]` : ""}`,
30
- titleColor,
31
- titleTypography,
32
- titleVariant,
33
- content,
34
- contentColor,
35
- contentTypography,
36
- contentVariant,
37
- borderColor,
38
- hint,
39
- variantOptions,
40
- errorMessage
41
- });
42
- const questionLines = countLines(question);
43
- if (linesToDelete > 0) {
44
- deleteLastLines(linesToDelete);
45
- }
46
- process.stdout.write(question);
47
- const password = await readPassword(borderColor);
48
- linesToDelete = questionLines + 1;
49
- const formattedBar = bar({ borderColor });
50
- if (!password.trim() && defaultValue !== void 0) {
51
- deleteLastLines(2);
52
- process.stdout.write(`${formattedBar} ****`);
53
- console.log(`
54
- ${formattedBar}`);
55
- return defaultValue;
56
- }
57
- let isValid = true;
58
- errorMessage = "";
59
- if (schema) {
60
- isValid = Value.Check(schema, password);
61
- if (!isValid) {
62
- const errors = [...Value.Errors(schema, password)];
63
- if (errors.length > 0) {
64
- errorMessage = errors[0]?.message ?? "Invalid input.";
65
- } else {
66
- errorMessage = "Invalid input.";
67
- }
68
- }
69
- }
70
- if (validate && isValid) {
71
- const validation = await validate(password);
72
- if (validation !== true) {
73
- isValid = false;
74
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
75
- }
76
- }
77
- if (isValid) {
78
- process.stdout.write("\n");
79
- return password;
80
- } else {
81
- }
82
- }
83
- }
84
- function readPassword(borderColor) {
85
- return new Promise((resolve, reject) => {
86
- const stdin = process.stdin;
87
- let password = "";
88
- const formattedBar = bar({ borderColor });
89
- stdin.setRawMode(true);
90
- stdin.resume();
91
- stdin.setEncoding("utf8");
92
- const onData = function(char) {
93
- char = char.toString();
94
- if (char === "\n" || char === "\r" || char === "") {
95
- stdin.setRawMode(false);
96
- stdin.pause();
97
- stdin.removeListener("data", onData);
98
- process.stdout.write(`
99
- ${formattedBar}`);
100
- resolve(password.trim());
101
- } else if (char === "") {
102
- stdin.setRawMode(false);
103
- stdin.pause();
104
- stdin.removeListener("data", onData);
105
- reject(new Error("User aborted."));
106
- } else if (char === "\x7F" ||
107
- char === "\b" || char === "\x7F" || char === "\b") {
108
- if (password.length > 0) {
109
- password = password.slice(0, -1);
110
- process.stdout.write("\b \b");
111
- }
112
- } else {
113
- password += char;
114
- process.stdout.write("*");
115
- }
116
- };
117
- stdin.on("data", onData);
118
- });
119
- }
@@ -1,13 +0,0 @@
1
- import type { PromptOptions } from "../../components/prompts/prompt.js";
2
- import Prompt from "../../components/prompts/prompt.js";
3
- type PasswordOptions = {
4
- mask?: string;
5
- } & PromptOptions<PasswordPrompt>;
6
- export default class PasswordPrompt extends Prompt {
7
- valueWithCursor: string;
8
- private _mask;
9
- get cursor(): any;
10
- get masked(): any;
11
- constructor({ mask, ...opts }: PasswordOptions);
12
- }
13
- export {};
@@ -1,28 +0,0 @@
1
- import color from "picocolors";
2
- import Prompt from "../../components/prompts/prompt.js";
3
- export default class PasswordPrompt extends Prompt {
4
- valueWithCursor = "";
5
- _mask = "\u2022";
6
- get cursor() {
7
- return this._cursor;
8
- }
9
- get masked() {
10
- return this.value.replaceAll(/./g, this._mask);
11
- }
12
- constructor({ mask, ...opts }) {
13
- super(opts);
14
- this._mask = mask ?? "\u2022";
15
- this.on("finalize", () => {
16
- this.valueWithCursor = this.masked;
17
- });
18
- this.on("value", () => {
19
- if (this.cursor >= this.value.length) {
20
- this.valueWithCursor = `${this.masked}${color.inverse(color.hidden("_"))}`;
21
- } else {
22
- const s1 = this.masked.slice(0, this.cursor);
23
- const s2 = this.masked.slice(this.cursor);
24
- this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`;
25
- }
26
- });
27
- }
28
- }
@@ -1,22 +0,0 @@
1
- export type ProgressBarOptions = {
2
- total: number;
3
- width?: number;
4
- completeChar?: string;
5
- incompleteChar?: string;
6
- format?: string;
7
- colorize?: boolean;
8
- };
9
- export declare class ProgressBar {
10
- private total;
11
- private current;
12
- private width;
13
- private completeChar;
14
- private incompleteChar;
15
- private startTime;
16
- private format;
17
- private colorize;
18
- constructor(options: ProgressBarOptions);
19
- update(value: number): void;
20
- increment(amount?: number): void;
21
- private render;
22
- }
@@ -1,53 +0,0 @@
1
- import { green, greenBright, red } from "picocolors";
2
- export class ProgressBar {
3
- total;
4
- current;
5
- width;
6
- completeChar;
7
- incompleteChar;
8
- startTime;
9
- format;
10
- colorize;
11
- constructor(options) {
12
- if (options.total <= 0) {
13
- throw new Error("Total must be a positive number");
14
- }
15
- this.total = options.total;
16
- this.current = 0;
17
- this.width = options.width || 40;
18
- this.completeChar = options.completeChar || "\u2588";
19
- this.incompleteChar = options.incompleteChar || "\u2591";
20
- this.startTime = Date.now();
21
- this.format = options.format || "Progress: [:bar] :percent% | Elapsed: :elapsed s";
22
- this.colorize = options.colorize || false;
23
- }
24
- update(value) {
25
- const newValue = Math.min(value, this.total);
26
- if (newValue !== this.current) {
27
- this.current = newValue;
28
- this.render();
29
- }
30
- }
31
- increment(amount = 1) {
32
- this.update(this.current + amount);
33
- }
34
- render() {
35
- const percent = this.current / this.total;
36
- const filledLength = Math.round(this.width * percent);
37
- const emptyLength = this.width - filledLength;
38
- let bar = this.completeChar.repeat(filledLength) + this.incompleteChar.repeat(emptyLength);
39
- if (this.colorize) {
40
- bar = green(this.completeChar.repeat(filledLength)) + red(this.incompleteChar.repeat(emptyLength));
41
- }
42
- const percentage = (percent * 100).toFixed(2);
43
- const elapsed = ((Date.now() - this.startTime) / 1e3).toFixed(2);
44
- const eta = percent > 0 ? ((Date.now() - this.startTime) / percent / 1e3).toFixed(2) : "N/A";
45
- const output = this.format.replace(":bar", bar).replace(":percent", percentage).replace(":elapsed", elapsed).replace(":eta", eta);
46
- process.stdout.clearLine(0);
47
- process.stdout.cursorTo(0);
48
- process.stdout.write(greenBright("\u25C6") + " " + output);
49
- if (this.current >= this.total) {
50
- process.stdout.write("\n");
51
- }
52
- }
53
- }
@@ -1,6 +0,0 @@
1
- import type { ProgressBarOptions } from "./ProgressBar.js";
2
- export type ProgressBarTaskOptions = ProgressBarOptions & {
3
- increment?: number;
4
- desiredTotalTime?: number;
5
- };
6
- export declare function progressbar(options: ProgressBarTaskOptions): Promise<void>;
@@ -1,38 +0,0 @@
1
- import { msg } from "../../utils/messages.js";
2
- import { ProgressBar } from "./ProgressBar.js";
3
- export async function progressbar(options) {
4
- const {
5
- total,
6
- increment = 1,
7
- desiredTotalTime = 3e3,
8
- ...progressBarOptions
9
- } = options;
10
- if (increment <= 0) {
11
- throw new Error("Increment must be a positive number");
12
- }
13
- const iterations = Math.ceil(total / increment) + 1;
14
- const delay = desiredTotalTime / iterations;
15
- const progressBar = new ProgressBar({
16
- total,
17
- ...progressBarOptions
18
- });
19
- try {
20
- for (let i = 0; i <= total; i += increment) {
21
- progressBar.update(i);
22
- await sleep(delay);
23
- }
24
- if (total % increment !== 0) {
25
- progressBar.update(total);
26
- }
27
- } catch (error) {
28
- console.error("Progress bar encountered an error:", error);
29
- }
30
- msg({
31
- type: "M_MIDDLE",
32
- title: "",
33
- borderColor: "viceGradient"
34
- });
35
- }
36
- function sleep(ms) {
37
- return new Promise((resolve) => setTimeout(resolve, ms));
38
- }
@@ -1,2 +0,0 @@
1
- export { progressbar } from "./helper.js";
2
- export type { ProgressBarOptions } from "./ProgressBar.js";
@@ -1 +0,0 @@
1
- export { progressbar } from "./helper.js";
@@ -1,35 +0,0 @@
1
- import { isDebug, isTest, isCI } from "std-env";
2
- import { LogLevels } from "../../utils/constants.js";
3
- import { BasicReporter } from "../instance/reporter/basic.js";
4
- import { FancyReporter } from "../instance/reporter/fancy.js";
5
- import { createRelinka as _createRelinka } from "./relinka.js";
6
- export * from "../instance/shared.js";
7
- export function createRelinka(options = {}) {
8
- let level = _getDefaultLogLevel();
9
- if (process.env.RELINKA_LEVEL) {
10
- level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
11
- }
12
- const relinka2 = _createRelinka({
13
- level,
14
- defaults: { level },
15
- stdout: process.stdout,
16
- stderr: process.stderr,
17
- prompt: (...args) => import("../../components/mono/monoTwo.js").then((m) => m.prompt(...args)),
18
- reporters: options.reporters || [
19
- options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()
20
- ],
21
- ...options
22
- });
23
- return relinka2;
24
- }
25
- function _getDefaultLogLevel() {
26
- if (isDebug) {
27
- return LogLevels.debug;
28
- }
29
- if (isTest) {
30
- return LogLevels.warn;
31
- }
32
- return LogLevels.info;
33
- }
34
- export const relinka = createRelinka();
35
- export default relinka;
@@ -1,49 +0,0 @@
1
- export type { ColorName } from "../../types/general.js";
2
- export type { ChoiceOptions } from "../../types/general.js";
3
- export type { OptionalPromptOptions } from "../../types/general.js";
4
- export { deleteLastLine, deleteLastLines, countLines, removeCursor, restoreCursor } from "../../utils/terminal.js";
5
- export { colorize } from "../../utils/colorize.js";
6
- export { fmt, msg } from "../../utils/messages.js";
7
- export { errorHandler } from "../../utils/errors.js";
8
- export { colorMap } from "../../utils/mapping.js";
9
- export { animateText } from "../../components/visual/animate/animate.js";
10
- export { createAsciiArt } from "../../components/visual/ascii-art/ascii-art.js";
11
- export { startPrompt } from "../../components/st-end/start.js";
12
- export { anykeyPrompt } from "../../components/anykey/index.js";
13
- export { textPrompt } from "../../components/input/text-main.js";
14
- export { confirmPrompt } from "../../components/confirm/confirm-main.js";
15
- export { togglePrompt } from "../../components/toggle/index.js";
16
- export { datePrompt } from "../../components/date/date.js";
17
- export { selectPrompt } from "../../components/select/select-main.js";
18
- export { multiselectPrompt } from "../../components/multiselect/multiselect-main.js";
19
- export { numSelectPrompt } from "../../components/select/num-select.js";
20
- export { numMultiSelectPrompt } from "../../components/multiselect/num-multi-select.js";
21
- export { nextStepsPrompt } from "../../components/next-steps/next-steps.js";
22
- export { numberPrompt } from "../../components/number/number-main.js";
23
- export { passwordPrompt } from "../../components/password/password-main.js";
24
- export { endPrompt } from "../../components/st-end/end.js";
25
- export { progressbar } from "../../components/progressbar/index.js";
26
- export { promptsDisplayResults } from "../../components/results/results.js";
27
- export { prompt } from "../../components/mono/mono.js";
28
- export { default as block } from "../../components/block/block.js";
29
- export { spinner } from "../../components/spinner/index.js";
30
- export { default as checkbox, Separator } from "../../components/checkbox/index.js";
31
- export { default as expand } from "../../components/expand/index.js";
32
- export { default as rawlist } from "../../components/rawlist/index.js";
33
- export { default as search } from "../../components/search/index.js";
34
- export { default as select } from "../../components/select/index.js";
35
- export { default as editor } from "../../components/editor/index.js";
36
- export { default as confirm } from "../../components/confirm/index.js";
37
- export { default as input } from "../../components/input/index.js";
38
- export { default as number } from "../../components/number/index.js";
39
- export { default as password } from "../../components/password/index.js";
40
- export { default as ConfirmPrompt } from "../../components/confirm/confirm-three.js";
41
- export { default as GroupMultiSelectPrompt } from "../../components/multiselect/group-multiselect.js";
42
- export { default as MultiSelectPrompt } from "../../components/multiselect/multi-select.js";
43
- export { default as PasswordPrompt } from "../../components/password/password-three.js";
44
- export { default as Prompt, isCancel } from "../../components/prompts/prompt.js";
45
- export { default as SelectPrompt } from "../../components/select/select-three.js";
46
- export { default as SelectKeyPrompt } from "../../components/select/select-key.js";
47
- export { default as TextPrompt } from "../../components/input/text.js";
48
- export { multiselect } from "../../components/prompts/promptTwo.js";
49
- export { relinka } from "../../components/prompts/create.js";