@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.
- package/README.md +35 -28
- package/dist-npm/components/checkbox/index.js +8 -6
- package/dist-npm/components/confirm/index.js +7 -4
- package/dist-npm/components/core/Separator.d.ts +0 -4
- package/dist-npm/components/core/create-prompt.js +1 -1
- package/dist-npm/components/core/key.js +6 -6
- package/dist-npm/components/core/lines.d.ts +5 -17
- package/dist-npm/components/core/lines.js +6 -2
- package/dist-npm/components/core/make-theme.js +3 -1
- package/dist-npm/components/core/position.d.ts +0 -8
- package/dist-npm/components/core/position.js +9 -3
- package/dist-npm/components/core/promise-polyfill.js +2 -2
- package/dist-npm/components/core/screen-manager.js +2 -1
- package/dist-npm/components/core/theme.d.ts +12 -146
- package/dist-npm/components/core/theme.js +1 -1
- package/dist-npm/components/core/use-keypress.js +3 -1
- package/dist-npm/components/core/use-pagination.d.ts +4 -8
- package/dist-npm/components/core/use-prefix.js +1 -1
- package/dist-npm/components/core/useKeyPress.js +3 -1
- package/dist-npm/components/core/utils.d.ts +0 -11
- package/dist-npm/components/date/date.d.ts +1 -1
- package/dist-npm/components/date/date.js +74 -12
- package/dist-npm/components/expand/index.js +4 -2
- package/dist-npm/components/figures/index.js +5 -5
- package/dist-npm/components/instance/basic.d.ts +0 -12
- package/dist-npm/components/instance/basic.js +1 -1
- package/dist-npm/components/instance/browser.d.ts +0 -14
- package/dist-npm/components/instance/reporter/browser.js +5 -5
- package/dist-npm/components/instance/reporter/fancy.d.ts +1 -1
- package/dist-npm/components/instance/reporter/fancy.js +1 -1
- package/dist-npm/components/mono/mono.js +9 -9
- package/dist-npm/components/mono/monoTwo.d.ts +13 -76
- package/dist-npm/components/multiselect/multiselect-main.d.ts +4 -2
- package/dist-npm/components/multiselect/multiselect-main.js +12 -10
- package/dist-npm/components/password/password-main.js +1 -1
- package/dist-npm/components/progressbar/ProgressBar.d.ts +3 -14
- package/dist-npm/components/progressbar/ProgressBar.js +3 -14
- package/dist-npm/components/progressbar/helper.d.ts +2 -18
- package/dist-npm/components/prompts/create.d.ts +0 -13
- package/dist-npm/components/prompts/prompt.js +3 -3
- package/dist-npm/components/prompts/promptTwo.d.ts +34 -252
- package/dist-npm/components/prompts/promptTwo.js +6 -27
- package/dist-npm/components/prompts/relinka.d.ts +17 -114
- package/dist-npm/components/prompts/relinka.js +18 -103
- package/dist-npm/components/range/range.d.ts +12 -64
- package/dist-npm/components/range/range.js +36 -59
- package/dist-npm/components/rawlist/index.js +6 -4
- package/dist-npm/components/search/index.js +7 -5
- package/dist-npm/components/select/index.js +9 -3
- package/dist-npm/components/select/select-main.d.ts +1 -1
- package/dist-npm/components/select/select-main.js +4 -3
- package/dist-npm/components/select/select-two.js +3 -1
- package/dist-npm/components/toggle/index.js +3 -1
- package/dist-npm/testing/index.js +1 -1
- package/dist-npm/types/general.d.ts +30 -141
- package/dist-npm/types/keypress.d.ts +0 -3
- package/dist-npm/types/keypress.js +1 -1
- package/dist-npm/types/readline.d.ts +1 -9
- package/dist-npm/types/relinka.d.ts +1 -9
- package/dist-npm/types/utils.d.ts +0 -12
- package/dist-npm/utils/box.d.ts +14 -104
- package/dist-npm/utils/color.d.ts +0 -20
- package/dist-npm/utils/colorize.js +2 -1
- package/dist-npm/utils/component.d.ts +5 -26
- package/dist-npm/utils/component.js +1 -2
- package/dist-npm/utils/constants.d.ts +0 -21
- package/dist-npm/utils/constants.js +8 -8
- package/dist-npm/utils/decoder.d.ts +2 -17
- package/dist-npm/utils/decoder.js +54 -25
- package/dist-npm/utils/error.d.ts +0 -5
- package/dist-npm/utils/errors.d.ts +1 -1
- package/dist-npm/utils/errors.js +8 -4
- package/dist-npm/utils/format.d.ts +0 -12
- package/dist-npm/utils/keypress.d.ts +0 -6
- package/dist-npm/utils/keypress.js +12 -23
- package/dist-npm/utils/log.d.ts +0 -11
- package/dist-npm/utils/prompt-tmp.js +2 -2
- package/dist-npm/utils/prompt-two.js +2 -2
- package/dist-npm/utils/skeleton.d.ts +0 -3
- package/dist-npm/utils/skeleton.js +66 -22
- package/dist-npm/utils/stream.d.ts +0 -13
- package/dist-npm/utils/string.d.ts +0 -45
- package/dist-npm/utils/tree.d.ts +5 -34
- package/dist-npm/utils/variants.js +9 -9
- package/package.json +12 -5
|
@@ -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:
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
229
|
-
|
|
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
|
-
|
|
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")
|
|
289
|
-
|
|
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))
|
|
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
|
-
|
|
33
|
+
|
|
32
34
|
value: choice.value,
|
|
33
35
|
name,
|
|
34
|
-
|
|
36
|
+
|
|
35
37
|
short: choice.short ?? name,
|
|
36
|
-
|
|
38
|
+
|
|
37
39
|
key: choice.key ?? String(index)
|
|
38
40
|
};
|
|
39
41
|
});
|
|
@@ -27,7 +27,9 @@ function isSelectable(item) {
|
|
|
27
27
|
}
|
|
28
28
|
function normalizeChoices(choices) {
|
|
29
29
|
return choices.map((choice) => {
|
|
30
|
-
if (Separator.isSeparator(choice))
|
|
30
|
+
if (Separator.isSeparator(choice)) {
|
|
31
|
+
return choice;
|
|
32
|
+
}
|
|
31
33
|
if (typeof choice === "string") {
|
|
32
34
|
return {
|
|
33
35
|
value: choice,
|
|
@@ -38,14 +40,14 @@ function normalizeChoices(choices) {
|
|
|
38
40
|
}
|
|
39
41
|
const name = choice.name ?? String(choice.value);
|
|
40
42
|
return {
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
value: choice.value,
|
|
43
45
|
name,
|
|
44
|
-
|
|
46
|
+
|
|
45
47
|
description: choice.description,
|
|
46
|
-
|
|
48
|
+
|
|
47
49
|
short: choice.short ?? name,
|
|
48
|
-
|
|
50
|
+
|
|
49
51
|
disabled: choice.disabled ?? false
|
|
50
52
|
};
|
|
51
53
|
});
|
|
@@ -32,7 +32,9 @@ function isSelectable(item) {
|
|
|
32
32
|
}
|
|
33
33
|
function normalizeChoices(choices) {
|
|
34
34
|
return choices.map((choice) => {
|
|
35
|
-
if (Separator.isSeparator(choice))
|
|
35
|
+
if (Separator.isSeparator(choice)) {
|
|
36
|
+
return choice;
|
|
37
|
+
}
|
|
36
38
|
if (typeof choice === "string") {
|
|
37
39
|
return {
|
|
38
40
|
value: choice,
|
|
@@ -74,7 +76,9 @@ const select = createPrompt(
|
|
|
74
76
|
return { first, last };
|
|
75
77
|
}, [items]);
|
|
76
78
|
const defaultItemIndex = useMemo(() => {
|
|
77
|
-
if (!("default" in config))
|
|
79
|
+
if (!("default" in config)) {
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
78
82
|
return items.findIndex(
|
|
79
83
|
(item) => isSelectable(item) && item.value === config.default
|
|
80
84
|
);
|
|
@@ -110,7 +114,9 @@ const select = createPrompt(
|
|
|
110
114
|
} else {
|
|
111
115
|
const searchTerm = rl.line.toLowerCase();
|
|
112
116
|
const matchIndex = items.findIndex((item) => {
|
|
113
|
-
if (Separator.isSeparator(item) || !isSelectable(item))
|
|
117
|
+
if (Separator.isSeparator(item) || !isSelectable(item)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
114
120
|
return item.name.toLowerCase().startsWith(searchTerm);
|
|
115
121
|
});
|
|
116
122
|
if (matchIndex !== -1) {
|
|
@@ -7,7 +7,6 @@ export async function selectPrompt(params) {
|
|
|
7
7
|
const {
|
|
8
8
|
title,
|
|
9
9
|
options,
|
|
10
|
-
hints = [],
|
|
11
10
|
initial,
|
|
12
11
|
required = false,
|
|
13
12
|
borderColor = "viceGradient",
|
|
@@ -19,7 +18,9 @@ export async function selectPrompt(params) {
|
|
|
19
18
|
endTitleColor = "passionGradient"
|
|
20
19
|
} = params;
|
|
21
20
|
let selectedIndex = initial ? options.findIndex((option) => option.value === initial) : 0;
|
|
22
|
-
if (selectedIndex === -1)
|
|
21
|
+
if (selectedIndex === -1) {
|
|
22
|
+
selectedIndex = 0;
|
|
23
|
+
}
|
|
23
24
|
const rl = readline.createInterface({ input, output });
|
|
24
25
|
readline.emitKeypressEvents(input, rl);
|
|
25
26
|
if (typeof input.setRawMode === "function") {
|
|
@@ -50,7 +51,7 @@ export async function selectPrompt(params) {
|
|
|
50
51
|
const isSelected = index === selectedIndex;
|
|
51
52
|
const prefix = isSelected ? "> " : " ";
|
|
52
53
|
const optionLabel = isSelected ? cyanBright(option.label) : option.label;
|
|
53
|
-
const hint =
|
|
54
|
+
const hint = option.hint ? ` (${option.hint})` : "";
|
|
54
55
|
outputStr += `${formattedBar} ${prefix}${optionLabel}${dim(hint)}
|
|
55
56
|
`;
|
|
56
57
|
});
|
|
@@ -26,7 +26,9 @@ export async function selectPrompt(options) {
|
|
|
26
26
|
let selectedIndex = defaultValue !== void 0 ? choices.findIndex(
|
|
27
27
|
(choice, index) => choice.id === defaultValue || index + 1 === Number(defaultValue)
|
|
28
28
|
) : 0;
|
|
29
|
-
if (selectedIndex === -1)
|
|
29
|
+
if (selectedIndex === -1) {
|
|
30
|
+
selectedIndex = 0;
|
|
31
|
+
}
|
|
30
32
|
function renderChoices() {
|
|
31
33
|
if (!choices) {
|
|
32
34
|
throw new Error("Choices are required for select prompt.");
|
|
@@ -17,7 +17,9 @@ export async function togglePrompt(params) {
|
|
|
17
17
|
endTitleColor = "passionGradient"
|
|
18
18
|
} = params;
|
|
19
19
|
let selectedIndex = initial ? options.findIndex((option) => option === initial) : 0;
|
|
20
|
-
if (selectedIndex === -1)
|
|
20
|
+
if (selectedIndex === -1) {
|
|
21
|
+
selectedIndex = 0;
|
|
22
|
+
}
|
|
21
23
|
const rl = readline.createInterface({ input, output });
|
|
22
24
|
readline.emitKeypressEvents(input, rl);
|
|
23
25
|
if (typeof input.setRawMode === "function") {
|
|
@@ -2,7 +2,7 @@ import ansiEscapes from "ansi-escapes";
|
|
|
2
2
|
import MuteStream from "mute-stream";
|
|
3
3
|
import { Stream } from "node:stream";
|
|
4
4
|
import stripAnsi from "strip-ansi";
|
|
5
|
-
const ignoredAnsi =
|
|
5
|
+
const ignoredAnsi = new Set([ansiEscapes.cursorHide, ansiEscapes.cursorShow]);
|
|
6
6
|
class BufferedStream extends Stream.Writable {
|
|
7
7
|
#_fullOutput = "";
|
|
8
8
|
#_chunks = [];
|