@reliverse/relinka 1.1.2 → 1.1.4

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 (85) hide show
  1. package/README.md +35 -28
  2. package/dist-npm/components/checkbox/index.js +8 -6
  3. package/dist-npm/components/confirm/index.js +7 -4
  4. package/dist-npm/components/core/Separator.d.ts +0 -4
  5. package/dist-npm/components/core/create-prompt.js +1 -1
  6. package/dist-npm/components/core/key.js +6 -6
  7. package/dist-npm/components/core/lines.d.ts +5 -17
  8. package/dist-npm/components/core/lines.js +6 -2
  9. package/dist-npm/components/core/make-theme.js +3 -1
  10. package/dist-npm/components/core/position.d.ts +0 -8
  11. package/dist-npm/components/core/position.js +9 -3
  12. package/dist-npm/components/core/promise-polyfill.js +2 -2
  13. package/dist-npm/components/core/screen-manager.js +2 -1
  14. package/dist-npm/components/core/theme.d.ts +12 -146
  15. package/dist-npm/components/core/theme.js +1 -1
  16. package/dist-npm/components/core/use-keypress.js +3 -1
  17. package/dist-npm/components/core/use-pagination.d.ts +4 -8
  18. package/dist-npm/components/core/use-prefix.js +1 -1
  19. package/dist-npm/components/core/useKeyPress.js +3 -1
  20. package/dist-npm/components/core/utils.d.ts +0 -11
  21. package/dist-npm/components/date/date.d.ts +1 -1
  22. package/dist-npm/components/date/date.js +74 -12
  23. package/dist-npm/components/expand/index.js +4 -2
  24. package/dist-npm/components/figures/index.js +5 -5
  25. package/dist-npm/components/instance/basic.d.ts +0 -12
  26. package/dist-npm/components/instance/basic.js +1 -1
  27. package/dist-npm/components/instance/browser.d.ts +0 -14
  28. package/dist-npm/components/instance/reporter/browser.js +5 -5
  29. package/dist-npm/components/instance/reporter/fancy.d.ts +1 -1
  30. package/dist-npm/components/instance/reporter/fancy.js +1 -1
  31. package/dist-npm/components/mono/mono.js +9 -9
  32. package/dist-npm/components/mono/monoTwo.d.ts +13 -76
  33. package/dist-npm/components/multiselect/multiselect-main.d.ts +4 -2
  34. package/dist-npm/components/multiselect/multiselect-main.js +12 -10
  35. package/dist-npm/components/password/password-main.js +1 -1
  36. package/dist-npm/components/progressbar/ProgressBar.d.ts +3 -14
  37. package/dist-npm/components/progressbar/ProgressBar.js +3 -14
  38. package/dist-npm/components/progressbar/helper.d.ts +2 -18
  39. package/dist-npm/components/prompts/create.d.ts +0 -13
  40. package/dist-npm/components/prompts/prompt.js +3 -3
  41. package/dist-npm/components/prompts/promptTwo.d.ts +34 -252
  42. package/dist-npm/components/prompts/promptTwo.js +6 -27
  43. package/dist-npm/components/prompts/relinka.d.ts +17 -114
  44. package/dist-npm/components/prompts/relinka.js +18 -103
  45. package/dist-npm/components/range/range.d.ts +12 -64
  46. package/dist-npm/components/range/range.js +36 -59
  47. package/dist-npm/components/rawlist/index.js +6 -4
  48. package/dist-npm/components/search/index.js +7 -5
  49. package/dist-npm/components/select/index.js +9 -3
  50. package/dist-npm/components/select/select-main.d.ts +1 -1
  51. package/dist-npm/components/select/select-main.js +4 -3
  52. package/dist-npm/components/select/select-two.js +3 -1
  53. package/dist-npm/components/toggle/index.js +3 -1
  54. package/dist-npm/testing/index.js +1 -1
  55. package/dist-npm/types/general.d.ts +30 -141
  56. package/dist-npm/types/keypress.d.ts +0 -3
  57. package/dist-npm/types/keypress.js +1 -1
  58. package/dist-npm/types/readline.d.ts +1 -9
  59. package/dist-npm/types/relinka.d.ts +1 -9
  60. package/dist-npm/types/utils.d.ts +0 -12
  61. package/dist-npm/utils/box.d.ts +14 -104
  62. package/dist-npm/utils/color.d.ts +0 -20
  63. package/dist-npm/utils/colorize.js +2 -1
  64. package/dist-npm/utils/component.d.ts +5 -26
  65. package/dist-npm/utils/component.js +1 -2
  66. package/dist-npm/utils/constants.d.ts +0 -21
  67. package/dist-npm/utils/constants.js +8 -8
  68. package/dist-npm/utils/decoder.d.ts +2 -17
  69. package/dist-npm/utils/decoder.js +54 -25
  70. package/dist-npm/utils/error.d.ts +0 -5
  71. package/dist-npm/utils/errors.d.ts +1 -1
  72. package/dist-npm/utils/errors.js +8 -4
  73. package/dist-npm/utils/format.d.ts +0 -12
  74. package/dist-npm/utils/keypress.d.ts +0 -6
  75. package/dist-npm/utils/keypress.js +12 -23
  76. package/dist-npm/utils/log.d.ts +0 -11
  77. package/dist-npm/utils/prompt-tmp.js +2 -2
  78. package/dist-npm/utils/prompt-two.js +2 -2
  79. package/dist-npm/utils/skeleton.d.ts +0 -3
  80. package/dist-npm/utils/skeleton.js +66 -22
  81. package/dist-npm/utils/stream.d.ts +0 -13
  82. package/dist-npm/utils/string.d.ts +0 -45
  83. package/dist-npm/utils/tree.d.ts +5 -34
  84. package/dist-npm/utils/variants.js +9 -9
  85. package/package.json +12 -5
@@ -2,16 +2,63 @@ import { Type } from "@sinclair/typebox";
2
2
  import { Value } from "@sinclair/typebox/value";
3
3
  import { stdin as input, stdout as output } from "node:process";
4
4
  import readline from "node:readline/promises";
5
+ import {
6
+ buildRegExp,
7
+ digit,
8
+ endOfString,
9
+ repeat,
10
+ startOfString
11
+ } from "ts-regex-builder";
5
12
  import { fmt, msg } from "../../utils/messages.js";
6
13
  import {
7
14
  countLines,
8
15
  deleteLastLine,
9
16
  deleteLastLines
10
17
  } from "../../utils/terminal.js";
18
+ const twoDigits = repeat(digit, 2);
19
+ const fourDigits = repeat(digit, 4);
20
+ const separatorDot = ".";
21
+ const separatorSlash = "/";
22
+ const regexDDMMYYYY = buildRegExp([
23
+ startOfString,
24
+ twoDigits,
25
+
26
+ separatorDot,
27
+ twoDigits,
28
+
29
+ separatorDot,
30
+ fourDigits,
31
+
32
+ endOfString
33
+ ]);
34
+ const regexMMDDYYYY = buildRegExp([
35
+ startOfString,
36
+ twoDigits,
37
+
38
+ separatorSlash,
39
+ twoDigits,
40
+
41
+ separatorSlash,
42
+ fourDigits,
43
+
44
+ endOfString
45
+ ]);
46
+ const regexYYYYMMDD = buildRegExp([
47
+ startOfString,
48
+ fourDigits,
49
+
50
+ separatorDot,
51
+ twoDigits,
52
+
53
+ separatorDot,
54
+ twoDigits,
55
+
56
+ endOfString
57
+ ]);
11
58
  const dateFormatSchema = Type.Union([
12
- Type.RegExp(/^(\d{2})\.(\d{2})\.(\d{4})$/, { description: "DD.MM.YYYY" }),
13
- Type.RegExp(/^(\d{2})\/(\d{2})\/(\d{4})$/, { description: "MM/DD/YYYY" }),
14
- Type.RegExp(/^(\d{4})\.(\d{2})\.(\d{2})$/, { description: "YYYY.MM.DD" })
59
+ Type.RegExp(regexDDMMYYYY, { description: "DD.MM.YYYY" }),
60
+ Type.RegExp(regexMMDDYYYY, { description: "MM/DD/YYYY" }),
61
+ Type.RegExp(regexYYYYMMDD, { description: "YYYY.MM.DD" })
15
62
  ]);
16
63
  export async function datePrompt(options) {
17
64
  const {
@@ -41,7 +88,7 @@ export async function datePrompt(options) {
41
88
  if (linesToDelete > 0) {
42
89
  deleteLastLines(linesToDelete);
43
90
  }
44
- const question = fmt({
91
+ const questionText = fmt({
45
92
  type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
46
93
  title: `${title} [Format: ${dateFormat}]`,
47
94
  titleColor,
@@ -57,9 +104,10 @@ export async function datePrompt(options) {
57
104
  errorMessage,
58
105
  addNewLineBefore: false
59
106
  });
60
- const questionLines = countLines(question);
107
+ const questionLines = countLines(questionText);
61
108
  linesToDelete = questionLines + 1;
62
- const answer = (await rl.question(question)).trim() || defaultValue;
109
+ msg({ type: "M_GENERAL", title: questionText });
110
+ const answer = (await rl.question("> ")).trim() || defaultValue;
63
111
  if (answer === defaultValue && defaultValue) {
64
112
  deleteLastLine();
65
113
  msg({
@@ -70,24 +118,33 @@ export async function datePrompt(options) {
70
118
  }
71
119
  if (!Value.Check(dateFormatSchema, answer)) {
72
120
  errorMessage = `Please enter a valid date in ${dateFormat} format.`;
121
+ msg({ type: "M_ERROR", title: errorMessage });
73
122
  continue;
74
123
  }
75
- if (dateKind === "birthday") {
124
+ let matchedFormat = null;
125
+ if (regexDDMMYYYY.test(answer)) {
126
+ matchedFormat = "DD.MM.YYYY";
127
+ } else if (regexMMDDYYYY.test(answer)) {
128
+ matchedFormat = "MM/DD/YYYY";
129
+ } else if (regexYYYYMMDD.test(answer)) {
130
+ matchedFormat = "YYYY.MM.DD";
131
+ }
132
+ if (dateKind === "birthday" && matchedFormat) {
76
133
  const parts = answer.split(/[./-]/);
77
134
  let date;
78
- if (dateFormat === "DD.MM.YYYY") {
135
+ if (matchedFormat === "DD.MM.YYYY") {
79
136
  date = new Date(
80
137
  Number(parts[2]),
81
138
  Number(parts[1]) - 1,
82
139
  Number(parts[0])
83
140
  );
84
- } else if (dateFormat === "MM/DD/YYYY") {
141
+ } else if (matchedFormat === "MM/DD/YYYY") {
85
142
  date = new Date(
86
143
  Number(parts[2]),
87
144
  Number(parts[0]) - 1,
88
145
  Number(parts[1])
89
146
  );
90
- } else if (dateFormat === "YYYY.MM.DD") {
147
+ } else if (matchedFormat === "YYYY.MM.DD") {
91
148
  date = new Date(
92
149
  Number(parts[0]),
93
150
  Number(parts[1]) - 1,
@@ -96,8 +153,9 @@ export async function datePrompt(options) {
96
153
  } else {
97
154
  date = new Date(answer);
98
155
  }
99
- if (isNaN(date.getTime()) || date.getFullYear() < 1900 || date > /* @__PURE__ */ new Date()) {
156
+ if (isNaN(date.getTime()) || date.getFullYear() < 1900 || date > new Date()) {
100
157
  errorMessage = "Please enter a valid birthday date (e.g., 14.09.1999).";
158
+ msg({ type: "M_ERROR", title: errorMessage });
101
159
  continue;
102
160
  }
103
161
  }
@@ -108,6 +166,8 @@ export async function datePrompt(options) {
108
166
  if (!isValid) {
109
167
  const errors = [...Value.Errors(schema, answer)];
110
168
  errorMessage = errors[0]?.message ?? "Invalid input.";
169
+ msg({ type: "M_ERROR", title: errorMessage });
170
+ continue;
111
171
  }
112
172
  }
113
173
  if (validate && isValid) {
@@ -115,10 +175,12 @@ export async function datePrompt(options) {
115
175
  if (validation !== true) {
116
176
  isValid = false;
117
177
  errorMessage = typeof validation === "string" ? validation : "Invalid input.";
178
+ msg({ type: "M_ERROR", title: errorMessage });
179
+ continue;
118
180
  }
119
181
  }
120
182
  if (isValid) {
121
- msg({ type: "M_NEWLINE" });
183
+ msg({ type: "M_NEWLINE", title: "" });
122
184
  rl.close();
123
185
  return answer;
124
186
  }
@@ -32,7 +32,7 @@ const expand = createPrompt(
32
32
  (config, done) => {
33
33
  const { default: defaultKey = "h" } = config;
34
34
  const choices = useMemo(
35
- // @ts-expect-error - TODO: fix ts
35
+
36
36
  () => normalizeChoices(config.choices),
37
37
  [config.choices]
38
38
  );
@@ -76,7 +76,9 @@ const expand = createPrompt(
76
76
  const allChoices = expanded ? choices : [...choices, helpChoice];
77
77
  let longChoices = "";
78
78
  let shortChoices = allChoices.map((choice) => {
79
- if (Separator.isSeparator(choice)) return "";
79
+ if (Separator.isSeparator(choice)) {
80
+ return "";
81
+ }
80
82
  if (choice.key === defaultKey) {
81
83
  return choice.key.toUpperCase();
82
84
  }
@@ -1,12 +1,12 @@
1
1
  import process from "node:process";
2
2
  function isUnicodeSupported() {
3
3
  if (process.platform !== "win32") {
4
- return process.env["TERM"] !== "linux";
4
+ return process.env.TERM !== "linux";
5
5
  }
6
- return Boolean(process.env["WT_SESSION"]) || // Windows Terminal
7
- Boolean(process.env["TERMINUS_SUBLIME"]) || // Terminus (<0.2.27)
8
- process.env["ConEmuTask"] === "{cmd::Cmder}" || // ConEmu and cmder
9
- process.env["TERM_PROGRAM"] === "Terminus-Sublime" || process.env["TERM_PROGRAM"] === "vscode" || process.env["TERM"] === "xterm-256color" || process.env["TERM"] === "alacritty" || process.env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
6
+ return Boolean(process.env.WT_SESSION) ||
7
+ Boolean(process.env.TERMINUS_SUBLIME) ||
8
+ process.env.ConEmuTask === "{cmd::Cmder}" ||
9
+ process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
10
10
  }
11
11
  const common = {
12
12
  circleQuestionMark: "(?)",
@@ -1,20 +1,8 @@
1
1
  import type { RelinkaInstance } from "../../components/prompts/relinka.js";
2
2
  import type { RelinkaOptions } from "../../types/general.js";
3
3
  export * from "../../components/instance/shared.js";
4
- /**
5
- * Factory function to create a new Relinka instance
6
- *
7
- * @param {Partial<RelinkaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link RelinkaOptions}.
8
- * @returns {RelinkaInstance} A new Relinka instance configured with the given options.
9
- */
10
4
  export declare function createRelinka(options?: Partial<RelinkaOptions & {
11
5
  fancy: boolean;
12
6
  }>): RelinkaInstance;
13
- /**
14
- * Creates and exports a standard instance of Relinka with the default configuration.
15
- * This instance can be used directly for logging throughout the application.
16
- *
17
- * @type {RelinkaInstance} relinka - The default instance of Relinka.
18
- */
19
7
  export declare const relinka: RelinkaInstance;
20
8
  export default relinka;
@@ -1,6 +1,6 @@
1
1
  import { BasicReporter } from "../../components/instance/reporter/basic.js";
2
- import { LogLevels } from "../../utils/constants.js";
3
2
  import { createRelinka as _createRelinka } from "../../components/prompts/relinka.js";
3
+ import { LogLevels } from "../../utils/constants.js";
4
4
  export * from "../../components/instance/shared.js";
5
5
  export function createRelinka(options = {}) {
6
6
  let level = LogLevels.info;
@@ -1,19 +1,5 @@
1
1
  import type { RelinkaOptions } from "../../types/general.js";
2
2
  export * from "../../components/instance/shared.js";
3
- /**
4
- * Creates a new Relinka instance configured specifically for browser environments.
5
- * This function sets up default reporters and a prompt method tailored to the browser's dialogue APIs.
6
- *
7
- * @param {Partial<RelinkaOptions>} [options={}] - Optional configuration options.
8
- * The options can override the default reporter and prompt behavior. See {@link RelinkaOptions}.
9
- * @returns {RelinkaInstance} A new Relinka instance optimized for use in browser environments.
10
- */
11
3
  export declare function createRelinka(options?: Partial<RelinkaOptions>): any;
12
- /**
13
- * A standard Relinka instance created with browser-specific configurations.
14
- * This instance can be used throughout a browser-based project.
15
- *
16
- * @type {RelinkaInstance} relinka - The default browser-configured Relinka instance.
17
- */
18
4
  export declare const relinka: any;
19
5
  export default relinka;
@@ -8,15 +8,15 @@ export class BrowserReporter {
8
8
  this.defaultColor = "#7f8c8d";
9
9
  this.levelColorMap = {
10
10
  0: "#c0392b",
11
- // Red
11
+
12
12
  1: "#f39c12",
13
- // Yellow
13
+
14
14
  3: "#00BCD4"
15
- // Cyan
15
+
16
16
  };
17
17
  this.typeColorMap = {
18
18
  success: "#2ecc71"
19
- // Green
19
+
20
20
  };
21
21
  }
22
22
  _getLogFn(level) {
@@ -45,7 +45,7 @@ export class BrowserReporter {
45
45
  consoleLogFn(
46
46
  `${badge}%c ${logObj.args[0]}`,
47
47
  style,
48
- // Empty string as style resets to default console style
48
+
49
49
  "",
50
50
  ...logObj.args.slice(1)
51
51
  );
@@ -1,5 +1,5 @@
1
- import type { LogLevel, LogType } from "../../../utils/constants.js";
2
1
  import type { FormatOptions, LogObject } from "../../../types/general.js";
2
+ import type { LogLevel, LogType } from "../../../utils/constants.js";
3
3
  import { BasicReporter } from "./basic.js";
4
4
  export declare const TYPE_COLOR_MAP: Partial<Record<LogType, string>>;
5
5
  export declare const LEVEL_COLOR_MAP: Partial<Record<LogLevel, string>>;
@@ -1,9 +1,9 @@
1
1
  import isUnicodeSupported from "is-unicode-supported";
2
2
  import _stringWidth from "string-width";
3
- import { stripAnsi } from "../../../utils/utils.js";
4
3
  import { box } from "../../../utils/box.js";
5
4
  import { colors } from "../../../utils/color.js";
6
5
  import { parseStack } from "../../../utils/error.js";
6
+ import { stripAnsi } from "../../../utils/utils.js";
7
7
  import { BasicReporter } from "./basic.js";
8
8
  export const TYPE_COLOR_MAP = {
9
9
  info: "cyan",
@@ -27,15 +27,15 @@ export async function prompt(options) {
27
27
  case "numSelect":
28
28
  value = await numSelectPrompt(options);
29
29
  break;
30
- // case "select":
31
- // value = await selectPrompt(options);
32
- // break;
33
- // case "multiSelect":
34
- // value = await multiSelectPrompt(options);
35
- // break;
36
- // case "numMultiSelect":
37
- // value = await numMultiSelectPrompt(options);
38
- // break;
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
39
  case "password":
40
40
  value = await passwordPrompt(options);
41
41
  break;
@@ -4,90 +4,27 @@ type SelectOption = {
4
4
  hint?: string;
5
5
  };
6
6
  export type TextPromptOptions = {
7
- /**
8
- * Specifies the prompt type as text.
9
- * @optional
10
- * @default "text"
11
- */
12
- type?: "text";
13
- /**
14
- * The default text value.
15
- * @optional
16
- */
17
- default?: string;
18
- /**
19
- * A placeholder text displayed in the prompt.
20
- * @optional
21
- */
22
- placeholder?: string;
23
- /**
24
- * The initial text value.
25
- * @optional
26
- */
27
- initial?: string;
7
+ type?: "text";
8
+ default?: string;
9
+ placeholder?: string;
10
+ initial?: string;
28
11
  };
29
12
  export type ConfirmPromptOptions = {
30
- /**
31
- * Specifies the prompt type as confirm.
32
- */
33
- type: "confirm";
34
- /**
35
- * The initial value for the confirm prompt.
36
- * @optional
37
- */
38
- initial?: boolean;
13
+ type: "confirm";
14
+ initial?: boolean;
39
15
  };
40
16
  export type SelectPromptOptions = {
41
- /**
42
- * Specifies the prompt type as select.
43
- */
44
- type: "select";
45
- /**
46
- * The initial value for the select prompt.
47
- * @optional
48
- */
49
- initial?: string;
50
- /**
51
- * The options to select from. See {@link SelectOption}.
52
- */
53
- options: (string | SelectOption)[];
17
+ type: "select";
18
+ initial?: string;
19
+ options: (string | SelectOption)[];
54
20
  };
55
21
  export type MultiSelectOptions = {
56
- /**
57
- * Specifies the prompt type as multiselect.
58
- */
59
- type: "multiselect";
60
- /**
61
- * The options to select from. See {@link SelectOption}.
62
- */
63
- initial?: string[];
64
- /**
65
- * The options to select from. See {@link SelectOption}.
66
- */
67
- options: (string | SelectOption)[];
68
- /**
69
- * Whether the prompt requires at least one selection.
70
- */
71
- required?: boolean;
22
+ type: "multiselect";
23
+ initial?: string[];
24
+ options: (string | SelectOption)[];
25
+ required?: boolean;
72
26
  };
73
- /**
74
- * Defines a combined type for all prompt options.
75
- */
76
27
  export type PromptOptions = TextPromptOptions | ConfirmPromptOptions | SelectPromptOptions | MultiSelectOptions;
77
28
  type inferPromptReturnType<T extends PromptOptions> = T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends SelectOption ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown;
78
- /**
79
- * Asynchronously prompts the user for input based on specified options.
80
- * Supports text, confirm, select and multi-select prompts.
81
- *
82
- * @param {string} message - The message to display in the prompt.
83
- * @param {PromptOptions} [opts={}] - The prompt options. See {@link PromptOptions}.
84
- * @returns {Promise<inferPromptReturnType<T>>} - A promise that resolves with the user's response, the type of which is inferred from the options. See {@link inferPromptReturnType}.
85
- */
86
29
  export declare function prompt<_ = any, __ = any, T extends PromptOptions = TextPromptOptions>(message: string, opts?: PromptOptions): Promise<inferPromptReturnType<T>>;
87
30
  export {};
88
- /**
89
- * Asynchronously prompts the user for a multi-select input.
90
- *
91
- * @param {MultiselectPromptOptionsSeparate} opts - The options for the multi-select prompt.
92
- * @returns {Promise<string[] | symbol>} - A promise that resolves with an array of selected options or a symbol.
93
- */
@@ -1,8 +1,10 @@
1
1
  import type { ColorName, Variant, TypographyName } from "../../types/general.js";
2
2
  export declare function multiselectPrompt<T extends string>(params: {
3
3
  title: string;
4
- options: T[];
5
- hints?: string[];
4
+ options: {
5
+ value: T;
6
+ hint?: string;
7
+ }[];
6
8
  required?: boolean;
7
9
  initial?: T[];
8
10
  borderColor?: ColorName;
@@ -8,7 +8,6 @@ export async function multiselectPrompt(params) {
8
8
  const {
9
9
  title,
10
10
  options,
11
- hints = [],
12
11
  required = false,
13
12
  initial = [],
14
13
  borderColor = "viceGradient",
@@ -21,7 +20,7 @@ export async function multiselectPrompt(params) {
21
20
  } = params;
22
21
  let pointer = 0;
23
22
  const selectedOptions = new Set(
24
- initial.map((opt) => options.indexOf(opt)).filter((i) => i >= 0)
23
+ initial.map((opt) => options.findIndex((o) => o.value === opt)).filter((i) => i >= 0)
25
24
  );
26
25
  const rl = readline.createInterface({ input, output });
27
26
  readline.emitKeypressEvents(input, rl);
@@ -50,8 +49,8 @@ export async function multiselectPrompt(params) {
50
49
  const isHighlighted = index === pointer;
51
50
  const checkbox = isSelected ? "[x]" : "[ ]";
52
51
  const prefix = isHighlighted ? "> " : " ";
53
- const optionLabel = isHighlighted ? cyanBright(option) : option;
54
- const hint = hints[index] ? ` (${hints[index]})` : "";
52
+ const optionLabel = isHighlighted ? cyanBright(option.value) : option.value;
53
+ const hint = option.hint ? ` (${option.hint})` : "";
55
54
  outputStr += `${formattedBar} ${prefix}${checkbox} ${optionLabel}${dim(hint)}
56
55
  `;
57
56
  });
@@ -78,18 +77,21 @@ export async function multiselectPrompt(params) {
78
77
  errorMessage = "";
79
78
  renderOptions();
80
79
  } else if (key.name === "return") {
81
- if (required && selectedOptions.size === 0) {
82
- deleteLastLine();
83
- errorMessage = "You must select at least one option.\x1B[K";
84
- renderOptions();
85
- } else {
80
+ if (!required || selectedOptions.size > 0) {
81
+ const selectedValues = Array.from(selectedOptions).map(
82
+ (index) => options[index].value
83
+ );
86
84
  cleanup();
87
- resolve(Array.from(selectedOptions).map((i) => options[i]));
85
+ resolve(selectedValues);
88
86
  deleteLastLine();
89
87
  deleteLastLine();
90
88
  msg({
91
89
  type: "M_MIDDLE"
92
90
  });
91
+ } else {
92
+ deleteLastLine();
93
+ errorMessage = "You must select at least one option.\x1B[K";
94
+ renderOptions();
93
95
  }
94
96
  } else if (key.name === "c" && key.ctrl) {
95
97
  msg({
@@ -104,7 +104,7 @@ ${formattedBar}`);
104
104
  stdin.pause();
105
105
  stdin.removeListener("data", onData);
106
106
  reject(new Error("User aborted."));
107
- } else if (char === "\x7F" || // Backspace
107
+ } else if (char === "\x7F" ||
108
108
  char === "\b" || char === "\x7F" || char === "\b") {
109
109
  if (password.length > 0) {
110
110
  password = password.slice(0, -1);
@@ -16,18 +16,7 @@ export declare class ProgressBar {
16
16
  private format;
17
17
  private colorize;
18
18
  constructor(options: ProgressBarOptions);
19
- /**
20
- * Update the progress bar to a specific value.
21
- * @param value - The current progress value.
22
- */
23
- update(value: number): void;
24
- /**
25
- * Increment the progress bar by a specific amount.
26
- * @param amount - The amount to increment.
27
- */
28
- increment(amount?: number): void;
29
- /**
30
- * Render the progress bar in the console.
31
- */
32
- private render;
19
+ update(value: number): void;
20
+ increment(amount?: number): void;
21
+ private render;
33
22
  }
@@ -21,28 +21,17 @@ export class ProgressBar {
21
21
  this.format = options.format || "Progress: [:bar] :percent% | Elapsed: :elapsed s";
22
22
  this.colorize = options.colorize || false;
23
23
  }
24
- /**
25
- * Update the progress bar to a specific value.
26
- * @param value - The current progress value.
27
- */
28
- update(value) {
24
+ update(value) {
29
25
  const newValue = Math.min(value, this.total);
30
26
  if (newValue !== this.current) {
31
27
  this.current = newValue;
32
28
  this.render();
33
29
  }
34
30
  }
35
- /**
36
- * Increment the progress bar by a specific amount.
37
- * @param amount - The amount to increment.
38
- */
39
- increment(amount = 1) {
31
+ increment(amount = 1) {
40
32
  this.update(this.current + amount);
41
33
  }
42
- /**
43
- * Render the progress bar in the console.
44
- */
45
- render() {
34
+ render() {
46
35
  const percent = this.current / this.total;
47
36
  const filledLength = Math.round(this.width * percent);
48
37
  const emptyLength = this.width - filledLength;
@@ -1,22 +1,6 @@
1
1
  import type { ProgressBarOptions } from "./ProgressBar.js";
2
- /**
3
- * Options for the progressbar helper function.
4
- */
5
2
  export type ProgressBarTaskOptions = ProgressBarOptions & {
6
- /**
7
- * The amount to increment the progress bar each step.
8
- * @default 1
9
- */
10
- increment?: number;
11
- /**
12
- * Desired total time for the progress bar to complete in milliseconds.
13
- * @default 3000
14
- */
15
- desiredTotalTime?: number;
3
+ increment?: number;
4
+ desiredTotalTime?: number;
16
5
  };
17
- /**
18
- * Displays a progress bar that completes based on the provided options.
19
- * @param options - Configuration options for the progress bar.
20
- * @returns A promise that resolves when the progress bar completes.
21
- */
22
6
  export declare function progressbar(options: ProgressBarTaskOptions): Promise<void>;
@@ -1,21 +1,8 @@
1
1
  import type { RelinkaOptions } from "../../types/general.js";
2
2
  import type { RelinkaInstance } from "./relinka.js";
3
3
  export * from "../instance/shared.js";
4
- /**
5
- * Factory function to create a new Relinka instance tailored for use in different environments.
6
- * It automatically adjusts logging levels based on environment variables and execution context.
7
- *
8
- * @param {Partial<RelinkaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link RelinkaOptions}.
9
- * @returns {RelinkaInstance} A new Relinka instance with configurations based on the given options and the execution environment.
10
- */
11
4
  export declare function createRelinka(options?: Partial<RelinkaOptions & {
12
5
  fancy: boolean;
13
6
  }>): RelinkaInstance;
14
- /**
15
- * A default instance of Relinka, created and configured for immediate use.
16
- * This instance is configured based on the execution environment and the options provided.
17
- *
18
- * @type {RelinkaInstance} relinka - The default Relinka instance, ready to use.
19
- */
20
7
  export declare const relinka: RelinkaInstance;
21
8
  export default relinka;
@@ -26,13 +26,13 @@ function setRawMode(input, value) {
26
26
  input.setRawMode(value);
27
27
  }
28
28
  }
29
- const aliases = /* @__PURE__ */ new Map([
29
+ const aliases = new Map([
30
30
  ["k", "up"],
31
31
  ["j", "down"],
32
32
  ["h", "left"],
33
33
  ["l", "right"]
34
34
  ]);
35
- const keys = /* @__PURE__ */ new Set(["up", "down", "left", "right", "space", "enter"]);
35
+ const keys = new Set(["up", "down", "left", "right", "space", "enter"]);
36
36
  export default class Prompt {
37
37
  input;
38
38
  output;
@@ -103,7 +103,7 @@ export default class Prompt {
103
103
  });
104
104
  });
105
105
  }
106
- subscribers = /* @__PURE__ */ new Map();
106
+ subscribers = new Map();
107
107
  on(event, cb) {
108
108
  const arr = this.subscribers.get(event) ?? [];
109
109
  arr.push({ cb });