@yumerijs/core 3.0.6 → 3.0.7
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/logger.d.ts +7 -0
- package/dist/logger.js +24 -0
- package/package.json +1 -1
package/dist/logger.d.ts
CHANGED
|
@@ -25,5 +25,12 @@ export declare class Logger {
|
|
|
25
25
|
info(...args: any[]): void;
|
|
26
26
|
warn(...args: any[]): void;
|
|
27
27
|
error(...args: any[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Display an interactive prompt and resolve with the entered text.
|
|
30
|
+
* The answer is deliberately not added to the log stream because it may be sensitive.
|
|
31
|
+
*/
|
|
32
|
+
input(question: string): Promise<string>;
|
|
33
|
+
/** Alias for input(), for callers that prefer prompt terminology. */
|
|
34
|
+
prompt(question: string): Promise<string>;
|
|
28
35
|
}
|
|
29
36
|
export {};
|
package/dist/logger.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* WindyPear-Team All right reserved
|
|
5
5
|
**/
|
|
6
6
|
import * as pcc from 'picocolors';
|
|
7
|
+
import { createInterface } from 'readline/promises';
|
|
8
|
+
import { stdin, stdout } from 'process';
|
|
7
9
|
const { createColors } = pcc;
|
|
8
10
|
const pc = createColors();
|
|
9
11
|
export class Logger {
|
|
@@ -70,4 +72,26 @@ export class Logger {
|
|
|
70
72
|
error(...args) {
|
|
71
73
|
this.log('E', ...args);
|
|
72
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Display an interactive prompt and resolve with the entered text.
|
|
77
|
+
* The answer is deliberately not added to the log stream because it may be sensitive.
|
|
78
|
+
*/
|
|
79
|
+
async input(question) {
|
|
80
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
81
|
+
throw new Error('Logger input requires an interactive terminal.');
|
|
82
|
+
}
|
|
83
|
+
const readline = createInterface({ input: stdin, output: stdout });
|
|
84
|
+
const timestamp = this.getTimestamp();
|
|
85
|
+
const prefix = `${pc.gray(timestamp)} [${pc.cyan('I')}] ${this.titleColor(this.title)} `;
|
|
86
|
+
try {
|
|
87
|
+
return await readline.question(`${prefix}${question}`);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
readline.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Alias for input(), for callers that prefer prompt terminology. */
|
|
94
|
+
async prompt(question) {
|
|
95
|
+
return await this.input(question);
|
|
96
|
+
}
|
|
73
97
|
}
|