@reliverse/relinka 1.1.2 → 1.1.3

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 (80) hide show
  1. package/dist-npm/components/checkbox/index.js +8 -6
  2. package/dist-npm/components/confirm/index.js +7 -4
  3. package/dist-npm/components/core/Separator.d.ts +0 -4
  4. package/dist-npm/components/core/create-prompt.js +1 -1
  5. package/dist-npm/components/core/key.js +6 -6
  6. package/dist-npm/components/core/lines.d.ts +5 -17
  7. package/dist-npm/components/core/lines.js +6 -2
  8. package/dist-npm/components/core/make-theme.js +3 -1
  9. package/dist-npm/components/core/position.d.ts +0 -8
  10. package/dist-npm/components/core/position.js +9 -3
  11. package/dist-npm/components/core/promise-polyfill.js +2 -2
  12. package/dist-npm/components/core/screen-manager.js +2 -1
  13. package/dist-npm/components/core/theme.d.ts +12 -146
  14. package/dist-npm/components/core/theme.js +1 -1
  15. package/dist-npm/components/core/use-keypress.js +3 -1
  16. package/dist-npm/components/core/use-pagination.d.ts +4 -8
  17. package/dist-npm/components/core/use-prefix.js +1 -1
  18. package/dist-npm/components/core/useKeyPress.js +3 -1
  19. package/dist-npm/components/core/utils.d.ts +0 -11
  20. package/dist-npm/components/date/date.js +1 -1
  21. package/dist-npm/components/expand/index.js +4 -2
  22. package/dist-npm/components/figures/index.js +5 -5
  23. package/dist-npm/components/instance/basic.d.ts +0 -12
  24. package/dist-npm/components/instance/basic.js +1 -1
  25. package/dist-npm/components/instance/browser.d.ts +0 -14
  26. package/dist-npm/components/instance/reporter/browser.js +5 -5
  27. package/dist-npm/components/instance/reporter/fancy.d.ts +1 -1
  28. package/dist-npm/components/instance/reporter/fancy.js +1 -1
  29. package/dist-npm/components/mono/mono.js +9 -9
  30. package/dist-npm/components/mono/monoTwo.d.ts +13 -76
  31. package/dist-npm/components/password/password-main.js +1 -1
  32. package/dist-npm/components/progressbar/ProgressBar.d.ts +3 -14
  33. package/dist-npm/components/progressbar/ProgressBar.js +3 -14
  34. package/dist-npm/components/progressbar/helper.d.ts +2 -18
  35. package/dist-npm/components/prompts/create.d.ts +0 -13
  36. package/dist-npm/components/prompts/prompt.js +3 -3
  37. package/dist-npm/components/prompts/promptTwo.d.ts +34 -252
  38. package/dist-npm/components/prompts/promptTwo.js +6 -27
  39. package/dist-npm/components/prompts/relinka.d.ts +17 -114
  40. package/dist-npm/components/prompts/relinka.js +18 -103
  41. package/dist-npm/components/range/range.d.ts +12 -64
  42. package/dist-npm/components/range/range.js +36 -59
  43. package/dist-npm/components/rawlist/index.js +6 -4
  44. package/dist-npm/components/search/index.js +7 -5
  45. package/dist-npm/components/select/index.js +9 -3
  46. package/dist-npm/components/select/select-main.js +3 -1
  47. package/dist-npm/components/select/select-two.js +3 -1
  48. package/dist-npm/components/toggle/index.js +3 -1
  49. package/dist-npm/testing/index.js +1 -1
  50. package/dist-npm/types/general.d.ts +30 -141
  51. package/dist-npm/types/keypress.d.ts +0 -3
  52. package/dist-npm/types/keypress.js +1 -1
  53. package/dist-npm/types/readline.d.ts +1 -9
  54. package/dist-npm/types/relinka.d.ts +1 -9
  55. package/dist-npm/types/utils.d.ts +0 -12
  56. package/dist-npm/utils/box.d.ts +14 -104
  57. package/dist-npm/utils/color.d.ts +0 -20
  58. package/dist-npm/utils/colorize.js +2 -1
  59. package/dist-npm/utils/component.d.ts +5 -26
  60. package/dist-npm/utils/component.js +1 -2
  61. package/dist-npm/utils/constants.d.ts +0 -21
  62. package/dist-npm/utils/constants.js +8 -8
  63. package/dist-npm/utils/decoder.d.ts +2 -17
  64. package/dist-npm/utils/decoder.js +54 -25
  65. package/dist-npm/utils/error.d.ts +0 -5
  66. package/dist-npm/utils/errors.d.ts +1 -1
  67. package/dist-npm/utils/errors.js +8 -4
  68. package/dist-npm/utils/format.d.ts +0 -12
  69. package/dist-npm/utils/keypress.d.ts +0 -6
  70. package/dist-npm/utils/keypress.js +12 -23
  71. package/dist-npm/utils/log.d.ts +0 -11
  72. package/dist-npm/utils/prompt-tmp.js +2 -2
  73. package/dist-npm/utils/prompt-two.js +2 -2
  74. package/dist-npm/utils/skeleton.d.ts +0 -3
  75. package/dist-npm/utils/skeleton.js +66 -22
  76. package/dist-npm/utils/stream.d.ts +0 -13
  77. package/dist-npm/utils/string.d.ts +0 -45
  78. package/dist-npm/utils/tree.d.ts +5 -34
  79. package/dist-npm/utils/variants.js +9 -9
  80. package/package.json +9 -5
@@ -1,12 +1,6 @@
1
1
  import type { PromptOptions } from "../../components/mono/monoTwo.js";
2
2
  import type { RelinkaReporter, InputLogObject, LogObject, RelinkaOptions } from "../../types/general.js";
3
3
  import type { LogType } from "../../utils/constants.js";
4
- /**
5
- * Relinka class for logging management with support for pause/resume, mocking and customizable reporting.
6
- * Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
7
- *
8
- * @class Relinka
9
- */
10
4
  export declare class Relinka {
11
5
  options: RelinkaOptions;
12
6
  _lastLog: {
@@ -17,112 +11,27 @@ export declare class Relinka {
17
11
  timeout?: ReturnType<typeof setTimeout>;
18
12
  };
19
13
  _mockFn?: RelinkaOptions["mockFn"];
20
- /**
21
- * Creates an instance of Relinka with specified options or defaults.
22
- *
23
- * @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
24
- */
25
- constructor(options?: Partial<RelinkaOptions>);
26
- /**
27
- * Gets the current log level of the Relinka instance.
28
- *
29
- * @returns {number} The current log level.
30
- */
31
- get level(): any;
32
- /**
33
- * Sets the minimum log level that will be output by the instance.
34
- *
35
- * @param {number} level - The new log level to set.
36
- */
37
- set level(level: any);
38
- /**
39
- * Displays a prompt to the user and returns the response.
40
- * Throw an error if `prompt` is not supported by the current configuration.
41
- *
42
- * @template T
43
- * @param {string} message - The message to display in the prompt.
44
- * @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
45
- * @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
46
- */
47
- prompt<T extends PromptOptions>(message: string, opts?: T): any;
48
- /**
49
- * Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
50
- *
51
- * @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
52
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
53
- */
54
- create(options: Partial<RelinkaOptions>): RelinkaInstance;
55
- /**
56
- * Creates a new Relinka instance with the specified default log object properties.
57
- *
58
- * @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
59
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
60
- */
61
- withDefaults(defaults: InputLogObject): RelinkaInstance;
62
- /**
63
- * Creates a new Relinka instance with a specified tag, which will be included in every log.
64
- *
65
- * @param {string} tag - The tag to include in each log of the new instance.
66
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
67
- */
68
- withTag(tag: string): RelinkaInstance;
69
- /**
70
- * Adds a custom reporter to the Relinka instance.
71
- * Reporters will be called for each log message, depending on their implementation and log level.
72
- *
73
- * @param {RelinkaReporter} reporter - The reporter to add. See {@link RelinkaReporter}.
74
- * @returns {Relinka} The current Relinka instance.
75
- */
76
- addReporter(reporter: RelinkaReporter): this;
77
- /**
78
- * Removes a custom reporter from the Relinka instance.
79
- * If no reporter is specified, all reporters will be removed.
80
- *
81
- * @param {RelinkaReporter} reporter - The reporter to remove. See {@link RelinkaReporter}.
82
- * @returns {Relinka} The current Relinka instance.
83
- */
84
- removeReporter(reporter: RelinkaReporter): any;
85
- /**
86
- * Replaces all reporters of the Relinka instance with the specified array of reporters.
87
- *
88
- * @param {RelinkaReporter[]} reporters - The new reporters to set. See {@link RelinkaReporter}.
89
- * @returns {Relinka} The current Relinka instance.
90
- */
91
- setReporters(reporters: RelinkaReporter[]): this;
14
+ constructor(options?: Partial<RelinkaOptions>);
15
+ get level(): any;
16
+ set level(level: any);
17
+ prompt<T extends PromptOptions>(message: string, opts?: T): any;
18
+ create(options: Partial<RelinkaOptions>): RelinkaInstance;
19
+ withDefaults(defaults: InputLogObject): RelinkaInstance;
20
+ withTag(tag: string): RelinkaInstance;
21
+ addReporter(reporter: RelinkaReporter): this;
22
+ removeReporter(reporter: RelinkaReporter): any;
23
+ setReporters(reporters: RelinkaReporter[]): this;
92
24
  wrapAll(): void;
93
25
  restoreAll(): void;
94
- /**
95
- * Overrides console methods with Relinka logging methods for consistent logging.
96
- */
97
- wrapConsole(): void;
98
- /**
99
- * Restores the original console methods, removing Relinka overrides.
100
- */
101
- restoreConsole(): void;
102
- /**
103
- * Overrides standard output and error streams to redirect them through Relinka.
104
- */
105
- wrapStd(): void;
26
+ wrapConsole(): void;
27
+ restoreConsole(): void;
28
+ wrapStd(): void;
106
29
  _wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
107
- /**
108
- * Restores the original standard output and error streams, removing the Relinka redirection.
109
- */
110
- restoreStd(): void;
30
+ restoreStd(): void;
111
31
  _restoreStream(stream?: NodeJS.WriteStream): void;
112
- /**
113
- * Pauses logging, queues incoming logs until resumed.
114
- */
115
- pauseLogs(): void;
116
- /**
117
- * Resumes logging, processing any queued logs.
118
- */
119
- resumeLogs(): void;
120
- /**
121
- * Replaces logging methods with mocks if a mock function is provided.
122
- *
123
- * @param {RelinkaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptions["mockFn"]}.
124
- */
125
- mockTypes(mockFn?: RelinkaOptions["mockFn"]): void;
32
+ pauseLogs(): void;
33
+ resumeLogs(): void;
34
+ mockTypes(mockFn?: RelinkaOptions["mockFn"]): void;
126
35
  _wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
127
36
  _logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
128
37
  _log(logObj: LogObject): void;
@@ -132,10 +41,4 @@ export type LogFn = {
132
41
  raw: (...args: any[]) => void;
133
42
  };
134
43
  export type RelinkaInstance = Relinka & Record<LogType, LogFn>;
135
- /**
136
- * Utility for creating a new Relinka instance with optional configuration.
137
- *
138
- * @param {Partial<RelinkaOptions>} [options={}] - Optional configuration options for the new Relinka instance. See {@link RelinkaOptions}.
139
- * @returns {RelinkaInstance} A new instance of Relinka. See {@link RelinkaInstance}.
140
- */
141
44
  export declare function createRelinka(options?: Partial<RelinkaOptions>): RelinkaInstance;
@@ -7,12 +7,7 @@ export class Relinka {
7
7
  options;
8
8
  _lastLog;
9
9
  _mockFn;
10
- /**
11
- * Creates an instance of Relinka with specified options or defaults.
12
- *
13
- * @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
14
- */
15
- constructor(options = {}) {
10
+ constructor(options = {}) {
16
11
  const types = options.types || LogTypes;
17
12
  this.options = defu(
18
13
  {
@@ -49,48 +44,23 @@ export class Relinka {
49
44
  }
50
45
  this._lastLog = {};
51
46
  }
52
- /**
53
- * Gets the current log level of the Relinka instance.
54
- *
55
- * @returns {number} The current log level.
56
- */
57
- get level() {
47
+ get level() {
58
48
  return this.options.level;
59
49
  }
60
- /**
61
- * Sets the minimum log level that will be output by the instance.
62
- *
63
- * @param {number} level - The new log level to set.
64
- */
65
- set level(level) {
50
+ set level(level) {
66
51
  this.options.level = _normalizeLogLevel(
67
52
  level,
68
53
  this.options.types,
69
54
  this.options.level
70
55
  );
71
56
  }
72
- /**
73
- * Displays a prompt to the user and returns the response.
74
- * Throw an error if `prompt` is not supported by the current configuration.
75
- *
76
- * @template T
77
- * @param {string} message - The message to display in the prompt.
78
- * @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
79
- * @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
80
- */
81
- prompt(message, opts) {
57
+ prompt(message, opts) {
82
58
  if (!this.options.prompt) {
83
59
  throw new Error("prompt is not supported!");
84
60
  }
85
61
  return this.options.prompt(message, opts);
86
62
  }
87
- /**
88
- * Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
89
- *
90
- * @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
91
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
92
- */
93
- create(options) {
63
+ create(options) {
94
64
  const instance = new Relinka({
95
65
  ...this.options,
96
66
  ...options
@@ -100,13 +70,7 @@ export class Relinka {
100
70
  }
101
71
  return instance;
102
72
  }
103
- /**
104
- * Creates a new Relinka instance with the specified default log object properties.
105
- *
106
- * @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
107
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
108
- */
109
- withDefaults(defaults) {
73
+ withDefaults(defaults) {
110
74
  return this.create({
111
75
  ...this.options,
112
76
  defaults: {
@@ -115,36 +79,16 @@ export class Relinka {
115
79
  }
116
80
  });
117
81
  }
118
- /**
119
- * Creates a new Relinka instance with a specified tag, which will be included in every log.
120
- *
121
- * @param {string} tag - The tag to include in each log of the new instance.
122
- * @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
123
- */
124
- withTag(tag) {
82
+ withTag(tag) {
125
83
  return this.withDefaults({
126
84
  tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
127
85
  });
128
86
  }
129
- /**
130
- * Adds a custom reporter to the Relinka instance.
131
- * Reporters will be called for each log message, depending on their implementation and log level.
132
- *
133
- * @param {RelinkaReporter} reporter - The reporter to add. See {@link RelinkaReporter}.
134
- * @returns {Relinka} The current Relinka instance.
135
- */
136
- addReporter(reporter) {
87
+ addReporter(reporter) {
137
88
  this.options.reporters.push(reporter);
138
89
  return this;
139
90
  }
140
- /**
141
- * Removes a custom reporter from the Relinka instance.
142
- * If no reporter is specified, all reporters will be removed.
143
- *
144
- * @param {RelinkaReporter} reporter - The reporter to remove. See {@link RelinkaReporter}.
145
- * @returns {Relinka} The current Relinka instance.
146
- */
147
- removeReporter(reporter) {
91
+ removeReporter(reporter) {
148
92
  if (reporter) {
149
93
  const i = this.options.reporters.indexOf(reporter);
150
94
  if (i >= 0) {
@@ -155,13 +99,7 @@ export class Relinka {
155
99
  }
156
100
  return this;
157
101
  }
158
- /**
159
- * Replaces all reporters of the Relinka instance with the specified array of reporters.
160
- *
161
- * @param {RelinkaReporter[]} reporters - The new reporters to set. See {@link RelinkaReporter}.
162
- * @returns {Relinka} The current Relinka instance.
163
- */
164
- setReporters(reporters) {
102
+ setReporters(reporters) {
165
103
  this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
166
104
  return this;
167
105
  }
@@ -173,10 +111,7 @@ export class Relinka {
173
111
  this.restoreConsole();
174
112
  this.restoreStd();
175
113
  }
176
- /**
177
- * Overrides console methods with Relinka logging methods for consistent logging.
178
- */
179
- wrapConsole() {
114
+ wrapConsole() {
180
115
  for (const type in this.options.types) {
181
116
  if (!console["__" + type]) {
182
117
  console["__" + type] = console[type];
@@ -184,10 +119,7 @@ export class Relinka {
184
119
  console[type] = this[type].raw;
185
120
  }
186
121
  }
187
- /**
188
- * Restores the original console methods, removing Relinka overrides.
189
- */
190
- restoreConsole() {
122
+ restoreConsole() {
191
123
  for (const type in this.options.types) {
192
124
  if (console["__" + type]) {
193
125
  console[type] = console["__" + type];
@@ -195,10 +127,7 @@ export class Relinka {
195
127
  }
196
128
  }
197
129
  }
198
- /**
199
- * Overrides standard output and error streams to redirect them through Relinka.
200
- */
201
- wrapStd() {
130
+ wrapStd() {
202
131
  this._wrapStream(this.options.stdout, "log");
203
132
  this._wrapStream(this.options.stderr, "log");
204
133
  }
@@ -213,10 +142,7 @@ export class Relinka {
213
142
  this[type].raw(String(data).trim());
214
143
  };
215
144
  }
216
- /**
217
- * Restores the original standard output and error streams, removing the Relinka redirection.
218
- */
219
- restoreStd() {
145
+ restoreStd() {
220
146
  this._restoreStream(this.options.stdout);
221
147
  this._restoreStream(this.options.stderr);
222
148
  }
@@ -229,28 +155,17 @@ export class Relinka {
229
155
  delete stream.__write;
230
156
  }
231
157
  }
232
- /**
233
- * Pauses logging, queues incoming logs until resumed.
234
- */
235
- pauseLogs() {
158
+ pauseLogs() {
236
159
  paused = true;
237
160
  }
238
- /**
239
- * Resumes logging, processing any queued logs.
240
- */
241
- resumeLogs() {
161
+ resumeLogs() {
242
162
  paused = false;
243
163
  const _queue = queue.splice(0);
244
164
  for (const item of _queue) {
245
165
  item[0]._logFn(item[1], item[2]);
246
166
  }
247
167
  }
248
- /**
249
- * Replaces logging methods with mocks if a mock function is provided.
250
- *
251
- * @param {RelinkaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptions["mockFn"]}.
252
- */
253
- mockTypes(mockFn) {
168
+ mockTypes(mockFn) {
254
169
  const _mockFn = mockFn || this.options.mockFn;
255
170
  this._mockFn = _mockFn;
256
171
  if (typeof _mockFn !== "function") {
@@ -275,7 +190,7 @@ export class Relinka {
275
190
  return false;
276
191
  }
277
192
  const logObj = {
278
- date: /* @__PURE__ */ new Date(),
193
+ date: new Date(),
279
194
  args: [],
280
195
  ...defaults,
281
196
  level: _normalizeLogLevel(defaults.level, this.options.types)
@@ -1,8 +1,5 @@
1
1
  import type { Writable } from "stream";
2
2
  import { EventEmitter } from "events";
3
- /**
4
- * Interface for RangePrompt options
5
- */
6
3
  type RangePromptOptions = {
7
4
  hint?: string;
8
5
  marker?: string;
@@ -17,9 +14,6 @@ type RangePromptOptions = {
17
14
  step?: number;
18
15
  size?: number;
19
16
  };
20
- /**
21
- * RangePrompt class extends EventEmitter to handle events
22
- */
23
17
  export declare class RangePrompt extends EventEmitter {
24
18
  hint: string;
25
19
  marker: string;
@@ -46,67 +40,21 @@ export declare class RangePrompt extends EventEmitter {
46
40
  private keyListener;
47
41
  private cursorHidden;
48
42
  constructor(msg: string, options?: RangePromptOptions);
49
- /**
50
- * Initializes the prompt by setting up listeners and terminal settings
51
- */
52
- private initialize;
53
- /**
54
- * Closes the prompt, restoring terminal settings and cleaning up
55
- */
56
- private _close;
57
- /**
58
- * Handles keypress events
59
- * @param chunk - The input buffer
60
- */
61
- private onKeyPress;
62
- /**
63
- * Resets the prompt to its initial state
64
- */
65
- reset(): void;
66
- /**
67
- * Aborts the prompt
68
- */
69
- abort(): void;
70
- /**
71
- * Submits the current value
72
- */
73
- submit(): void;
74
- /**
75
- * Increases the value by the step
76
- */
77
- up(): void;
78
- /**
79
- * Decreases the value by the step
80
- */
81
- down(): void;
82
- /**
83
- * Handles numeric input
84
- * @param n - The input character
85
- */
86
- handleNumericInput(n: string): void;
87
- /**
88
- * Handles unknown input
89
- * @param input - The input string
90
- */
91
- handleUnknownInput(input: string): void;
92
- /**
93
- * Renders the prompt to the output
94
- * @param first - Indicates if this is the first render
95
- */
96
- render(first?: boolean): void;
97
- /**
98
- * Emits a bell sound to indicate an error or invalid action
99
- */
100
- bell(): void;
43
+ private initialize;
44
+ private _close;
45
+ private onKeyPress;
46
+ reset(): void;
47
+ abort(): void;
48
+ submit(): void;
49
+ up(): void;
50
+ down(): void;
51
+ handleNumericInput(n: string): void;
52
+ handleUnknownInput(input: string): void;
53
+ render(first?: boolean): void;
54
+ bell(): void;
101
55
  left: () => void;
102
56
  right: () => void;
103
57
  }
104
- /**
105
- * Function to create a new RangePrompt instance
106
- * @param msg - The message to display
107
- * @param opt - Optional configuration options
108
- * @returns Wrapped RangePrompt instance
109
- */
110
58
  export declare const rangePrompt: (msg: string, opt?: RangePromptOptions) => any;
111
59
  declare const _default: ((msg: string, opt?: RangePromptOptions) => any) & {
112
60
  RangePrompt: typeof RangePrompt;
@@ -8,7 +8,7 @@ import stringWidth from "string-width";
8
8
  import windowSize from "window-size";
9
9
  import wrap from "../../utils/skeleton.js";
10
10
  export class RangePrompt extends EventEmitter {
11
- // Prompt properties
11
+
12
12
  hint;
13
13
  marker;
14
14
  bar;
@@ -30,8 +30,8 @@ export class RangePrompt extends EventEmitter {
30
30
  pause;
31
31
  resume;
32
32
  _;
33
- // Property for handling unknown input
34
- // Internal properties for managing listeners and state
33
+
34
+
35
35
  stdin;
36
36
  keyListener;
37
37
  cursorHidden;
@@ -99,10 +99,7 @@ export class RangePrompt extends EventEmitter {
99
99
  this.stdin.on("data", this.keyListener);
100
100
  this.render(true);
101
101
  }
102
- /**
103
- * Closes the prompt, restoring terminal settings and cleaning up
104
- */
105
- _close() {
102
+ _close() {
106
103
  this.stdin.removeListener("data", this.keyListener);
107
104
  if (this.stdin.isTTY) {
108
105
  this.stdin.setRawMode(false);
@@ -117,11 +114,7 @@ export class RangePrompt extends EventEmitter {
117
114
  }
118
115
  this.emit("close");
119
116
  }
120
- /**
121
- * Handles keypress events
122
- * @param chunk - The input buffer
123
- */
124
- onKeyPress(chunk) {
117
+ onKeyPress(chunk) {
125
118
  const key = chunk.toString();
126
119
  if (key === "") {
127
120
  this.abort();
@@ -143,19 +136,13 @@ export class RangePrompt extends EventEmitter {
143
136
  this.handleUnknownInput(key);
144
137
  }
145
138
  }
146
- /**
147
- * Resets the prompt to its initial state
148
- */
149
- reset() {
139
+ reset() {
150
140
  this.typed = "";
151
141
  this.value = this.initialValue;
152
142
  this.emit("change");
153
143
  this.render();
154
144
  }
155
- /**
156
- * Aborts the prompt
157
- */
158
- abort() {
145
+ abort() {
159
146
  this.done = true;
160
147
  this.aborted = true;
161
148
  this.emit("abort");
@@ -163,10 +150,7 @@ export class RangePrompt extends EventEmitter {
163
150
  this.out.write("\n");
164
151
  this.close();
165
152
  }
166
- /**
167
- * Submits the current value
168
- */
169
- submit() {
153
+ submit() {
170
154
  this.done = true;
171
155
  this.aborted = false;
172
156
  this.emit("submit");
@@ -174,10 +158,7 @@ export class RangePrompt extends EventEmitter {
174
158
  this.out.write("\n");
175
159
  this.close();
176
160
  }
177
- /**
178
- * Increases the value by the step
179
- */
180
- up() {
161
+ up() {
181
162
  this.typed = "";
182
163
  if (this.value !== null && this.value >= this.max) {
183
164
  this.bell();
@@ -185,15 +166,14 @@ export class RangePrompt extends EventEmitter {
185
166
  }
186
167
  if (this.value !== null) {
187
168
  this.value = +(this.value + this.step).toFixed(precision(this.step));
188
- if (this.value > this.max) this.value = this.max;
169
+ if (this.value > this.max) {
170
+ this.value = this.max;
171
+ }
189
172
  }
190
173
  this.emit("change");
191
174
  this.render();
192
175
  }
193
- /**
194
- * Decreases the value by the step
195
- */
196
- down() {
176
+ down() {
197
177
  this.typed = "";
198
178
  if (this.value !== null && this.value <= this.min) {
199
179
  this.bell();
@@ -201,22 +181,22 @@ export class RangePrompt extends EventEmitter {
201
181
  }
202
182
  if (this.value !== null) {
203
183
  this.value = +(this.value - this.step).toFixed(precision(this.step));
204
- if (this.value < this.min) this.value = this.min;
184
+ if (this.value < this.min) {
185
+ this.value = this.min;
186
+ }
205
187
  }
206
188
  this.emit("change");
207
189
  this.render();
208
190
  }
209
- /**
210
- * Handles numeric input
211
- * @param n - The input character
212
- */
213
- handleNumericInput(n) {
191
+ handleNumericInput(n) {
214
192
  if (!isFloat.test(n)) {
215
193
  this.bell();
216
194
  return;
217
195
  }
218
196
  const now = Date.now();
219
- if (now - this.lastHit > 1e3) this.typed = "";
197
+ if (now - this.lastHit > 1e3) {
198
+ this.typed = "";
199
+ }
220
200
  this.typed += n;
221
201
  this.lastHit = now;
222
202
  const v = parseFloat(this.typed);
@@ -225,24 +205,20 @@ export class RangePrompt extends EventEmitter {
225
205
  return;
226
206
  }
227
207
  let newValue = v;
228
- if (newValue > this.max) newValue = this.max;
229
- if (newValue < this.min) newValue = this.min;
208
+ if (newValue > this.max) {
209
+ newValue = this.max;
210
+ }
211
+ if (newValue < this.min) {
212
+ newValue = this.min;
213
+ }
230
214
  this.value = newValue;
231
215
  this.emit("change");
232
216
  this.render();
233
217
  }
234
- /**
235
- * Handles unknown input
236
- * @param input - The input string
237
- */
238
- handleUnknownInput(input) {
218
+ handleUnknownInput(input) {
239
219
  this.bell();
240
220
  }
241
- /**
242
- * Renders the prompt to the output
243
- * @param first - Indicates if this is the first render
244
- */
245
- render(first = false) {
221
+ render(first = false) {
246
222
  let out = "";
247
223
  if (first) {
248
224
  out += esc.cursorHide;
@@ -273,20 +249,21 @@ export class RangePrompt extends EventEmitter {
273
249
  ].join(" ") + "\n";
274
250
  this.out.write(out);
275
251
  }
276
- /**
277
- * Emits a bell sound to indicate an error or invalid action
278
- */
279
- bell() {
252
+ bell() {
280
253
  this.out.write("\x07");
281
254
  }
282
- // Left and Right bindings
255
+
283
256
  left;
284
257
  right;
285
258
  }
286
259
  const isFloat = /^[0-9.]+$/;
287
260
  export const rangePrompt = (msg, opt) => {
288
- if (typeof msg !== "string") throw new Error("Message must be string.");
289
- if (Array.isArray(opt) || typeof opt !== "object") opt = {};
261
+ if (typeof msg !== "string") {
262
+ throw new Error("Message must be string.");
263
+ }
264
+ if (Array.isArray(opt) || typeof opt !== "object") {
265
+ opt = {};
266
+ }
290
267
  const prompt = new RangePrompt(msg, opt);
291
268
  return wrap(prompt);
292
269
  };
@@ -16,7 +16,9 @@ function isSelectableChoice(choice) {
16
16
  function normalizeChoices(choices) {
17
17
  let index = 0;
18
18
  return choices.map((choice) => {
19
- if (Separator.isSeparator(choice)) return choice;
19
+ if (Separator.isSeparator(choice)) {
20
+ return choice;
21
+ }
20
22
  index += 1;
21
23
  if (typeof choice === "string") {
22
24
  return {
@@ -28,12 +30,12 @@ function normalizeChoices(choices) {
28
30
  }
29
31
  const name = choice.name ?? String(choice.value);
30
32
  return {
31
- // @ts-expect-error - TODO: fix ts
33
+
32
34
  value: choice.value,
33
35
  name,
34
- // @ts-expect-error - TODO: fix ts
36
+
35
37
  short: choice.short ?? name,
36
- // @ts-expect-error - TODO: fix ts
38
+
37
39
  key: choice.key ?? String(index)
38
40
  };
39
41
  });