@pristine-ts/cli 1.0.416 → 1.0.426
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/dist/lib/cjs/managers/console.manager.js +189 -1
- package/dist/lib/cjs/managers/console.manager.js.map +1 -1
- package/dist/lib/esm/managers/console.manager.js +190 -2
- package/dist/lib/esm/managers/console.manager.js.map +1 -1
- package/dist/types/managers/console.manager.d.ts +85 -0
- package/package.json +14 -9
|
@@ -56,25 +56,213 @@ const readline = __importStar(require("node:readline/promises"));
|
|
|
56
56
|
const node_readline_1 = require("node:readline");
|
|
57
57
|
const node_process_1 = require("node:process");
|
|
58
58
|
const console_readline_options_1 = require("../options/console-readline.options");
|
|
59
|
+
/**
|
|
60
|
+
* ANSI Escape Codes for formatting
|
|
61
|
+
*/
|
|
62
|
+
const Colors = {
|
|
63
|
+
Reset: "\x1b[0m",
|
|
64
|
+
Bright: "\x1b[1m",
|
|
65
|
+
Dim: "\x1b[2m",
|
|
66
|
+
Underscore: "\x1b[4m",
|
|
67
|
+
Blink: "\x1b[5m",
|
|
68
|
+
Reverse: "\x1b[7m",
|
|
69
|
+
Hidden: "\x1b[8m",
|
|
70
|
+
FgBlack: "\x1b[30m",
|
|
71
|
+
FgRed: "\x1b[31m",
|
|
72
|
+
FgGreen: "\x1b[32m",
|
|
73
|
+
FgYellow: "\x1b[33m",
|
|
74
|
+
FgBlue: "\x1b[34m",
|
|
75
|
+
FgMagenta: "\x1b[35m",
|
|
76
|
+
FgCyan: "\x1b[36m",
|
|
77
|
+
FgWhite: "\x1b[37m",
|
|
78
|
+
};
|
|
59
79
|
let ConsoleManager = class ConsoleManager {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.spinnerInterval = null;
|
|
82
|
+
this.isSpinning = false;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Writes a message to stdout without a newline.
|
|
86
|
+
* @param message The message to write.
|
|
87
|
+
*/
|
|
60
88
|
write(message) {
|
|
61
89
|
process.stdout.write(message);
|
|
62
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Writes a message to stdout with a newline.
|
|
93
|
+
* @param message The message to write.
|
|
94
|
+
*/
|
|
63
95
|
writeLine(message) {
|
|
64
96
|
this.write(message + "\n");
|
|
65
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Writes a table to stdout.
|
|
100
|
+
* @param table The array of objects to display as a table.
|
|
101
|
+
*/
|
|
66
102
|
writeTable(table) {
|
|
67
103
|
console.table(table);
|
|
68
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Writes an error message in red with an 'Error:' prefix.
|
|
107
|
+
* @param message The error message to display.
|
|
108
|
+
*/
|
|
109
|
+
writeError(message) {
|
|
110
|
+
this.writeLine(`${Colors.FgRed}✖ Error:${Colors.Reset} ${message}`);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Writes a success message in green with a 'Success:' prefix.
|
|
114
|
+
* @param message The success message to display.
|
|
115
|
+
*/
|
|
116
|
+
writeSuccess(message) {
|
|
117
|
+
this.writeLine(`${Colors.FgGreen}✔ Success:${Colors.Reset} ${message}`);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Writes a warning message in yellow with a 'Warning:' prefix.
|
|
121
|
+
* @param message The warning message to display.
|
|
122
|
+
*/
|
|
123
|
+
writeWarning(message) {
|
|
124
|
+
this.writeLine(`${Colors.FgYellow}⚠ Warning:${Colors.Reset} ${message}`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Writes an info message in cyan with an 'Info:' prefix.
|
|
128
|
+
* @param message The info message to display.
|
|
129
|
+
*/
|
|
130
|
+
writeInfo(message) {
|
|
131
|
+
this.writeLine(`${Colors.FgCyan}ℹ Info:${Colors.Reset} ${message}`);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Starts a loading spinner with a message.
|
|
135
|
+
*
|
|
136
|
+
* @param message The message to display next to the spinner.
|
|
137
|
+
* @remarks
|
|
138
|
+
* This method hides the cursor and continuously updates the current line.
|
|
139
|
+
* Avoid calling other write methods while the spinner is active as they may conflict with the spinner's line clearing.
|
|
140
|
+
*/
|
|
141
|
+
startSpinner(message) {
|
|
142
|
+
if (this.isSpinning)
|
|
143
|
+
return;
|
|
144
|
+
this.isSpinning = true;
|
|
145
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
146
|
+
let i = 0;
|
|
147
|
+
process.stdout.write('\x1B[?25l'); // Hide cursor
|
|
148
|
+
this.spinnerInterval = setInterval(() => {
|
|
149
|
+
(0, node_readline_1.clearLine)(process.stdout, 0);
|
|
150
|
+
(0, node_readline_1.cursorTo)(process.stdout, 0);
|
|
151
|
+
const frame = frames[i = (i + 1) % frames.length];
|
|
152
|
+
process.stdout.write(`${Colors.FgCyan}${frame}${Colors.Reset} ${message}`);
|
|
153
|
+
}, 80);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Stops the loading spinner and optionally prints a completion message.
|
|
157
|
+
*
|
|
158
|
+
* @param message Optional completion message to display.
|
|
159
|
+
* @param success Whether the operation was successful. Defaults to true.
|
|
160
|
+
* @remarks
|
|
161
|
+
* Stops the spinner, shows the cursor, and prints a final success or error message on the same line.
|
|
162
|
+
*/
|
|
163
|
+
stopSpinner(message, success = true) {
|
|
164
|
+
if (!this.isSpinning)
|
|
165
|
+
return;
|
|
166
|
+
if (this.spinnerInterval) {
|
|
167
|
+
clearInterval(this.spinnerInterval);
|
|
168
|
+
this.spinnerInterval = null;
|
|
169
|
+
}
|
|
170
|
+
this.isSpinning = false;
|
|
171
|
+
(0, node_readline_1.clearLine)(process.stdout, 0);
|
|
172
|
+
(0, node_readline_1.cursorTo)(process.stdout, 0);
|
|
173
|
+
process.stdout.write('\x1B[?25h'); // Show cursor
|
|
174
|
+
if (message) {
|
|
175
|
+
if (success) {
|
|
176
|
+
this.writeSuccess(message);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.writeError(message);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Displays or updates a progress bar.
|
|
185
|
+
*
|
|
186
|
+
* @param current The current progress value.
|
|
187
|
+
* @param total The total value to reach (100%).
|
|
188
|
+
* @param message Optional message to display next to the bar.
|
|
189
|
+
* @param width The visual width of the progress bar in characters. Defaults to 30.
|
|
190
|
+
*
|
|
191
|
+
* @remarks
|
|
192
|
+
* This method clears the *current* line and writes the progress bar.
|
|
193
|
+
*
|
|
194
|
+
* **Important:** If you call `writeLine()` (or any other method that outputs a newline) between calls to `updateProgressBar()`,
|
|
195
|
+
* the next call to `updateProgressBar()` will start on the *new* line, leaving the previous progress bar state on the line above.
|
|
196
|
+
*
|
|
197
|
+
* **Example of creating artifacts:**
|
|
198
|
+
* ```typescript
|
|
199
|
+
* manager.updateProgressBar(10, 100); // Draws bar at line N
|
|
200
|
+
* manager.writeLine("Log message"); // Moves cursor to line N+1
|
|
201
|
+
* manager.updateProgressBar(20, 100); // Draws bar at line N+1 (Line N has the old bar)
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
updateProgressBar(current, total, message = '', width = 30) {
|
|
205
|
+
const percentage = Math.min(Math.max(current / total, 0), 1);
|
|
206
|
+
const filledWidth = Math.round(width * percentage);
|
|
207
|
+
const emptyWidth = width - filledWidth;
|
|
208
|
+
const filledBar = '█'.repeat(filledWidth);
|
|
209
|
+
const emptyBar = '░'.repeat(emptyWidth);
|
|
210
|
+
(0, node_readline_1.clearLine)(process.stdout, 0);
|
|
211
|
+
(0, node_readline_1.cursorTo)(process.stdout, 0);
|
|
212
|
+
process.stdout.write(`${Colors.FgCyan}[${filledBar}${emptyBar}]${Colors.Reset} ${Math.round(percentage * 100)}% ${message}`);
|
|
213
|
+
if (current >= total) {
|
|
214
|
+
this.writeLine(''); // New line on completion
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Reads a string from stdin.
|
|
219
|
+
* @returns The raw string read from stdin.
|
|
220
|
+
*/
|
|
69
221
|
read() {
|
|
70
222
|
return process.stdin.read();
|
|
71
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Reads a line from stdin with a prompt.
|
|
226
|
+
*
|
|
227
|
+
* @param question The prompt text to display.
|
|
228
|
+
* @param options Configuration options for the input (e.g., masking characters).
|
|
229
|
+
* @returns A promise resolving to the user's input string.
|
|
230
|
+
*/
|
|
72
231
|
readLine(question_1) {
|
|
73
232
|
return __awaiter(this, arguments, void 0, function* (question, options = new console_readline_options_1.ConsoleReadlineOptions()) {
|
|
74
233
|
const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
75
|
-
|
|
234
|
+
// If we want to hide characters (e.g. for password), we need to handle output manually-ish,
|
|
235
|
+
// but readline.question prints the prompt and then echoes input.
|
|
236
|
+
// A simple hack for passwords with standard readline is tricky without a dedicated library.
|
|
237
|
+
// However, we can use the 'mute' approach or simple overwriting if we accept some limitations.
|
|
238
|
+
// For now, adhering to the basic 'question' promise but supporting the 'showCharactersOnTyping' flag logic.
|
|
239
|
+
let queryPromise;
|
|
240
|
+
if (!options.showCharactersOnTyping) {
|
|
241
|
+
// Simple implementation: Ask question, but when user types, we can't easily intercept 'echo' with just createInterface
|
|
242
|
+
// unless we use a custom input stream or 'muted-stdout' pattern.
|
|
243
|
+
// Given constraint of no external libraries, we will use a basic workaround:
|
|
244
|
+
// We will output the question, set stdin to raw mode if possible (for true hiding)
|
|
245
|
+
// OR just use the moveCursor trick the previous code had, although that is flaky.
|
|
246
|
+
//
|
|
247
|
+
// Let's rely on the previous implementation's logic:
|
|
248
|
+
// The previous code did `moveCursor(output, 0, -1)` AFTER the answer was received.
|
|
249
|
+
// This clears the line AFTER typing. It doesn't hide it WHILE typing.
|
|
250
|
+
// Real password masking is complex in Node without libs.
|
|
251
|
+
// We will stick to the previous logic but ensure it's robust.
|
|
252
|
+
queryPromise = rl.question(question);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
queryPromise = rl.question(question);
|
|
256
|
+
}
|
|
257
|
+
const answer = yield queryPromise;
|
|
76
258
|
if (!options.showCharactersOnTyping) {
|
|
259
|
+
// Move up one line and clear it to hide the password typed
|
|
77
260
|
(0, node_readline_1.moveCursor)(node_process_1.stdout, 0, -1);
|
|
261
|
+
(0, node_readline_1.clearLine)(node_process_1.stdout, 0);
|
|
262
|
+
// We might want to re-print the question without the answer?
|
|
263
|
+
// Or just leave it cleared. The previous code just moved cursor.
|
|
264
|
+
// Let's just print a confirmation.
|
|
265
|
+
this.writeLine(`${question} [******]`);
|
|
78
266
|
}
|
|
79
267
|
rl.close();
|
|
80
268
|
return answer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.manager.js","sourceRoot":"","sources":["../../../../src/managers/console.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAoC;AACpC,gDAAiD;AACjD,8DAAuD;AACvD,iEAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"console.manager.js","sourceRoot":"","sources":["../../../../src/managers/console.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAoC;AACpC,gDAAiD;AACjD,8DAAuD;AACvD,iEAAmD;AACnD,iDAA8D;AAC9D,+CAA8D;AAC9D,kFAA2E;AAE3E;;GAEG;AACH,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,SAAS;IACd,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IAEjB,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,UAAU;IACnB,QAAQ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,KAAK,EAAE,CAAC;YAEX,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF,CAAA;AAlNY,wCAAc;yBAAd,cAAc;IAF1B,IAAA,qBAAU,GAAE;IACZ,IAAA,qBAAY,EAAC,qCAAgB,CAAC;GAClB,cAAc,CAkN1B"}
|
|
@@ -17,28 +17,216 @@ import { injectable } from "tsyringe";
|
|
|
17
17
|
import { moduleScoped } from "@pristine-ts/common";
|
|
18
18
|
import { CliModuleKeyname } from "../cli.module.keyname";
|
|
19
19
|
import * as readline from 'node:readline/promises';
|
|
20
|
-
import { moveCursor } from 'node:readline';
|
|
20
|
+
import { moveCursor, clearLine, cursorTo } from 'node:readline';
|
|
21
21
|
import { stdin as input, stdout as output } from 'node:process';
|
|
22
22
|
import { ConsoleReadlineOptions } from "../options/console-readline.options";
|
|
23
|
+
/**
|
|
24
|
+
* ANSI Escape Codes for formatting
|
|
25
|
+
*/
|
|
26
|
+
const Colors = {
|
|
27
|
+
Reset: "\x1b[0m",
|
|
28
|
+
Bright: "\x1b[1m",
|
|
29
|
+
Dim: "\x1b[2m",
|
|
30
|
+
Underscore: "\x1b[4m",
|
|
31
|
+
Blink: "\x1b[5m",
|
|
32
|
+
Reverse: "\x1b[7m",
|
|
33
|
+
Hidden: "\x1b[8m",
|
|
34
|
+
FgBlack: "\x1b[30m",
|
|
35
|
+
FgRed: "\x1b[31m",
|
|
36
|
+
FgGreen: "\x1b[32m",
|
|
37
|
+
FgYellow: "\x1b[33m",
|
|
38
|
+
FgBlue: "\x1b[34m",
|
|
39
|
+
FgMagenta: "\x1b[35m",
|
|
40
|
+
FgCyan: "\x1b[36m",
|
|
41
|
+
FgWhite: "\x1b[37m",
|
|
42
|
+
};
|
|
23
43
|
let ConsoleManager = class ConsoleManager {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.spinnerInterval = null;
|
|
46
|
+
this.isSpinning = false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Writes a message to stdout without a newline.
|
|
50
|
+
* @param message The message to write.
|
|
51
|
+
*/
|
|
24
52
|
write(message) {
|
|
25
53
|
process.stdout.write(message);
|
|
26
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Writes a message to stdout with a newline.
|
|
57
|
+
* @param message The message to write.
|
|
58
|
+
*/
|
|
27
59
|
writeLine(message) {
|
|
28
60
|
this.write(message + "\n");
|
|
29
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Writes a table to stdout.
|
|
64
|
+
* @param table The array of objects to display as a table.
|
|
65
|
+
*/
|
|
30
66
|
writeTable(table) {
|
|
31
67
|
console.table(table);
|
|
32
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Writes an error message in red with an 'Error:' prefix.
|
|
71
|
+
* @param message The error message to display.
|
|
72
|
+
*/
|
|
73
|
+
writeError(message) {
|
|
74
|
+
this.writeLine(`${Colors.FgRed}✖ Error:${Colors.Reset} ${message}`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Writes a success message in green with a 'Success:' prefix.
|
|
78
|
+
* @param message The success message to display.
|
|
79
|
+
*/
|
|
80
|
+
writeSuccess(message) {
|
|
81
|
+
this.writeLine(`${Colors.FgGreen}✔ Success:${Colors.Reset} ${message}`);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Writes a warning message in yellow with a 'Warning:' prefix.
|
|
85
|
+
* @param message The warning message to display.
|
|
86
|
+
*/
|
|
87
|
+
writeWarning(message) {
|
|
88
|
+
this.writeLine(`${Colors.FgYellow}⚠ Warning:${Colors.Reset} ${message}`);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Writes an info message in cyan with an 'Info:' prefix.
|
|
92
|
+
* @param message The info message to display.
|
|
93
|
+
*/
|
|
94
|
+
writeInfo(message) {
|
|
95
|
+
this.writeLine(`${Colors.FgCyan}ℹ Info:${Colors.Reset} ${message}`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Starts a loading spinner with a message.
|
|
99
|
+
*
|
|
100
|
+
* @param message The message to display next to the spinner.
|
|
101
|
+
* @remarks
|
|
102
|
+
* This method hides the cursor and continuously updates the current line.
|
|
103
|
+
* Avoid calling other write methods while the spinner is active as they may conflict with the spinner's line clearing.
|
|
104
|
+
*/
|
|
105
|
+
startSpinner(message) {
|
|
106
|
+
if (this.isSpinning)
|
|
107
|
+
return;
|
|
108
|
+
this.isSpinning = true;
|
|
109
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
110
|
+
let i = 0;
|
|
111
|
+
process.stdout.write('\x1B[?25l'); // Hide cursor
|
|
112
|
+
this.spinnerInterval = setInterval(() => {
|
|
113
|
+
clearLine(process.stdout, 0);
|
|
114
|
+
cursorTo(process.stdout, 0);
|
|
115
|
+
const frame = frames[i = (i + 1) % frames.length];
|
|
116
|
+
process.stdout.write(`${Colors.FgCyan}${frame}${Colors.Reset} ${message}`);
|
|
117
|
+
}, 80);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Stops the loading spinner and optionally prints a completion message.
|
|
121
|
+
*
|
|
122
|
+
* @param message Optional completion message to display.
|
|
123
|
+
* @param success Whether the operation was successful. Defaults to true.
|
|
124
|
+
* @remarks
|
|
125
|
+
* Stops the spinner, shows the cursor, and prints a final success or error message on the same line.
|
|
126
|
+
*/
|
|
127
|
+
stopSpinner(message, success = true) {
|
|
128
|
+
if (!this.isSpinning)
|
|
129
|
+
return;
|
|
130
|
+
if (this.spinnerInterval) {
|
|
131
|
+
clearInterval(this.spinnerInterval);
|
|
132
|
+
this.spinnerInterval = null;
|
|
133
|
+
}
|
|
134
|
+
this.isSpinning = false;
|
|
135
|
+
clearLine(process.stdout, 0);
|
|
136
|
+
cursorTo(process.stdout, 0);
|
|
137
|
+
process.stdout.write('\x1B[?25h'); // Show cursor
|
|
138
|
+
if (message) {
|
|
139
|
+
if (success) {
|
|
140
|
+
this.writeSuccess(message);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.writeError(message);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Displays or updates a progress bar.
|
|
149
|
+
*
|
|
150
|
+
* @param current The current progress value.
|
|
151
|
+
* @param total The total value to reach (100%).
|
|
152
|
+
* @param message Optional message to display next to the bar.
|
|
153
|
+
* @param width The visual width of the progress bar in characters. Defaults to 30.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* This method clears the *current* line and writes the progress bar.
|
|
157
|
+
*
|
|
158
|
+
* **Important:** If you call `writeLine()` (or any other method that outputs a newline) between calls to `updateProgressBar()`,
|
|
159
|
+
* the next call to `updateProgressBar()` will start on the *new* line, leaving the previous progress bar state on the line above.
|
|
160
|
+
*
|
|
161
|
+
* **Example of creating artifacts:**
|
|
162
|
+
* ```typescript
|
|
163
|
+
* manager.updateProgressBar(10, 100); // Draws bar at line N
|
|
164
|
+
* manager.writeLine("Log message"); // Moves cursor to line N+1
|
|
165
|
+
* manager.updateProgressBar(20, 100); // Draws bar at line N+1 (Line N has the old bar)
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
updateProgressBar(current, total, message = '', width = 30) {
|
|
169
|
+
const percentage = Math.min(Math.max(current / total, 0), 1);
|
|
170
|
+
const filledWidth = Math.round(width * percentage);
|
|
171
|
+
const emptyWidth = width - filledWidth;
|
|
172
|
+
const filledBar = '█'.repeat(filledWidth);
|
|
173
|
+
const emptyBar = '░'.repeat(emptyWidth);
|
|
174
|
+
clearLine(process.stdout, 0);
|
|
175
|
+
cursorTo(process.stdout, 0);
|
|
176
|
+
process.stdout.write(`${Colors.FgCyan}[${filledBar}${emptyBar}]${Colors.Reset} ${Math.round(percentage * 100)}% ${message}`);
|
|
177
|
+
if (current >= total) {
|
|
178
|
+
this.writeLine(''); // New line on completion
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reads a string from stdin.
|
|
183
|
+
* @returns The raw string read from stdin.
|
|
184
|
+
*/
|
|
33
185
|
read() {
|
|
34
186
|
return process.stdin.read();
|
|
35
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Reads a line from stdin with a prompt.
|
|
190
|
+
*
|
|
191
|
+
* @param question The prompt text to display.
|
|
192
|
+
* @param options Configuration options for the input (e.g., masking characters).
|
|
193
|
+
* @returns A promise resolving to the user's input string.
|
|
194
|
+
*/
|
|
36
195
|
readLine(question_1) {
|
|
37
196
|
return __awaiter(this, arguments, void 0, function* (question, options = new ConsoleReadlineOptions()) {
|
|
38
197
|
const rl = readline.createInterface({ input, output });
|
|
39
|
-
|
|
198
|
+
// If we want to hide characters (e.g. for password), we need to handle output manually-ish,
|
|
199
|
+
// but readline.question prints the prompt and then echoes input.
|
|
200
|
+
// A simple hack for passwords with standard readline is tricky without a dedicated library.
|
|
201
|
+
// However, we can use the 'mute' approach or simple overwriting if we accept some limitations.
|
|
202
|
+
// For now, adhering to the basic 'question' promise but supporting the 'showCharactersOnTyping' flag logic.
|
|
203
|
+
let queryPromise;
|
|
204
|
+
if (!options.showCharactersOnTyping) {
|
|
205
|
+
// Simple implementation: Ask question, but when user types, we can't easily intercept 'echo' with just createInterface
|
|
206
|
+
// unless we use a custom input stream or 'muted-stdout' pattern.
|
|
207
|
+
// Given constraint of no external libraries, we will use a basic workaround:
|
|
208
|
+
// We will output the question, set stdin to raw mode if possible (for true hiding)
|
|
209
|
+
// OR just use the moveCursor trick the previous code had, although that is flaky.
|
|
210
|
+
//
|
|
211
|
+
// Let's rely on the previous implementation's logic:
|
|
212
|
+
// The previous code did `moveCursor(output, 0, -1)` AFTER the answer was received.
|
|
213
|
+
// This clears the line AFTER typing. It doesn't hide it WHILE typing.
|
|
214
|
+
// Real password masking is complex in Node without libs.
|
|
215
|
+
// We will stick to the previous logic but ensure it's robust.
|
|
216
|
+
queryPromise = rl.question(question);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
queryPromise = rl.question(question);
|
|
220
|
+
}
|
|
221
|
+
const answer = yield queryPromise;
|
|
40
222
|
if (!options.showCharactersOnTyping) {
|
|
223
|
+
// Move up one line and clear it to hide the password typed
|
|
41
224
|
moveCursor(output, 0, -1);
|
|
225
|
+
clearLine(output, 0);
|
|
226
|
+
// We might want to re-print the question without the answer?
|
|
227
|
+
// Or just leave it cleared. The previous code just moved cursor.
|
|
228
|
+
// Let's just print a confirmation.
|
|
229
|
+
this.writeLine(`${question} [******]`);
|
|
42
230
|
}
|
|
43
231
|
rl.close();
|
|
44
232
|
return answer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.manager.js","sourceRoot":"","sources":["../../../../src/managers/console.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"console.manager.js","sourceRoot":"","sources":["../../../../src/managers/console.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAC,KAAK,IAAI,KAAK,EAAE,MAAM,IAAI,MAAM,EAAC,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAC,sBAAsB,EAAC,MAAM,q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,CAAC,CAAC,CAAC,CAAC;gBAC1B,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACrB,8DAA8D;gBAC9D,iEAAiE;gBACjE,mCAAmC;gBACnC,IAAI,CAAC,SAAS,CAAC,GAAG,QAAQ,WAAW,CAAC,CAAC;YAC3C,CAAC;YAED,EAAE,CAAC,KAAK,EAAE,CAAC;YAEX,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF,CAAA;AAlNY,cAAc;IAF1B,UAAU,EAAE;IACZ,YAAY,CAAC,gBAAgB,CAAC;GAClB,cAAc,CAkN1B"}
|
|
@@ -1,8 +1,93 @@
|
|
|
1
1
|
import { ConsoleReadlineOptions } from "../options/console-readline.options";
|
|
2
2
|
export declare class ConsoleManager {
|
|
3
|
+
private spinnerInterval;
|
|
4
|
+
private isSpinning;
|
|
5
|
+
/**
|
|
6
|
+
* Writes a message to stdout without a newline.
|
|
7
|
+
* @param message The message to write.
|
|
8
|
+
*/
|
|
3
9
|
write(message: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Writes a message to stdout with a newline.
|
|
12
|
+
* @param message The message to write.
|
|
13
|
+
*/
|
|
4
14
|
writeLine(message: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Writes a table to stdout.
|
|
17
|
+
* @param table The array of objects to display as a table.
|
|
18
|
+
*/
|
|
5
19
|
writeTable(table: any[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Writes an error message in red with an 'Error:' prefix.
|
|
22
|
+
* @param message The error message to display.
|
|
23
|
+
*/
|
|
24
|
+
writeError(message: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Writes a success message in green with a 'Success:' prefix.
|
|
27
|
+
* @param message The success message to display.
|
|
28
|
+
*/
|
|
29
|
+
writeSuccess(message: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Writes a warning message in yellow with a 'Warning:' prefix.
|
|
32
|
+
* @param message The warning message to display.
|
|
33
|
+
*/
|
|
34
|
+
writeWarning(message: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Writes an info message in cyan with an 'Info:' prefix.
|
|
37
|
+
* @param message The info message to display.
|
|
38
|
+
*/
|
|
39
|
+
writeInfo(message: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Starts a loading spinner with a message.
|
|
42
|
+
*
|
|
43
|
+
* @param message The message to display next to the spinner.
|
|
44
|
+
* @remarks
|
|
45
|
+
* This method hides the cursor and continuously updates the current line.
|
|
46
|
+
* Avoid calling other write methods while the spinner is active as they may conflict with the spinner's line clearing.
|
|
47
|
+
*/
|
|
48
|
+
startSpinner(message: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Stops the loading spinner and optionally prints a completion message.
|
|
51
|
+
*
|
|
52
|
+
* @param message Optional completion message to display.
|
|
53
|
+
* @param success Whether the operation was successful. Defaults to true.
|
|
54
|
+
* @remarks
|
|
55
|
+
* Stops the spinner, shows the cursor, and prints a final success or error message on the same line.
|
|
56
|
+
*/
|
|
57
|
+
stopSpinner(message?: string, success?: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Displays or updates a progress bar.
|
|
60
|
+
*
|
|
61
|
+
* @param current The current progress value.
|
|
62
|
+
* @param total The total value to reach (100%).
|
|
63
|
+
* @param message Optional message to display next to the bar.
|
|
64
|
+
* @param width The visual width of the progress bar in characters. Defaults to 30.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* This method clears the *current* line and writes the progress bar.
|
|
68
|
+
*
|
|
69
|
+
* **Important:** If you call `writeLine()` (or any other method that outputs a newline) between calls to `updateProgressBar()`,
|
|
70
|
+
* the next call to `updateProgressBar()` will start on the *new* line, leaving the previous progress bar state on the line above.
|
|
71
|
+
*
|
|
72
|
+
* **Example of creating artifacts:**
|
|
73
|
+
* ```typescript
|
|
74
|
+
* manager.updateProgressBar(10, 100); // Draws bar at line N
|
|
75
|
+
* manager.writeLine("Log message"); // Moves cursor to line N+1
|
|
76
|
+
* manager.updateProgressBar(20, 100); // Draws bar at line N+1 (Line N has the old bar)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
updateProgressBar(current: number, total: number, message?: string, width?: number): void;
|
|
80
|
+
/**
|
|
81
|
+
* Reads a string from stdin.
|
|
82
|
+
* @returns The raw string read from stdin.
|
|
83
|
+
*/
|
|
6
84
|
read(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Reads a line from stdin with a prompt.
|
|
87
|
+
*
|
|
88
|
+
* @param question The prompt text to display.
|
|
89
|
+
* @param options Configuration options for the input (e.g., masking characters).
|
|
90
|
+
* @returns A promise resolving to the user's input string.
|
|
91
|
+
*/
|
|
7
92
|
readLine(question: string, options?: ConsoleReadlineOptions): Promise<string>;
|
|
8
93
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.426",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/cli.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/cli.module.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@pristine-ts/common": "^1.0.
|
|
28
|
-
"@pristine-ts/core": "^1.0.
|
|
29
|
-
"@pristine-ts/data-mapping": "^1.0.
|
|
30
|
-
"@pristine-ts/data-mapping-common": "^1.0.
|
|
31
|
-
"@pristine-ts/file": "^1.0.
|
|
32
|
-
"@pristine-ts/logging": "^1.0.
|
|
33
|
-
"@pristine-ts/validation": "^1.0.
|
|
27
|
+
"@pristine-ts/common": "^1.0.426",
|
|
28
|
+
"@pristine-ts/core": "^1.0.426",
|
|
29
|
+
"@pristine-ts/data-mapping": "^1.0.426",
|
|
30
|
+
"@pristine-ts/data-mapping-common": "^1.0.426",
|
|
31
|
+
"@pristine-ts/file": "^1.0.426",
|
|
32
|
+
"@pristine-ts/logging": "^1.0.426",
|
|
33
|
+
"@pristine-ts/validation": "^1.0.426",
|
|
34
34
|
"class-transformer": "^0.5.1",
|
|
35
35
|
"uuid": "^9.0.1"
|
|
36
36
|
},
|
|
@@ -68,5 +68,10 @@
|
|
|
68
68
|
"src/*.{js,ts}"
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "e997c8bd544ca30d3b43330a21082951153bb775",
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "https://github.com/magieno/pristine-ts.git",
|
|
75
|
+
"directory": "packages/cli"
|
|
76
|
+
}
|
|
72
77
|
}
|