-
Notifications
You must be signed in to change notification settings - Fork 2
/
prompt.ts
37 lines (32 loc) · 895 Bytes
/
prompt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {stdout, stdin} from 'process';
import {createInterface, Interface} from 'readline';
const readlineInterface: Interface = createInterface({
input: stdin,
output: stdout,
});
export interface PromptParameters {
query: string;
color: Function;
suffix: string;
callback?: Function;
}
export class Prompt {
private config: PromptParameters;
public answers: Array<string> = [];
constructor(config: PromptParameters) {
this.config = config;
this.createPrompt();
}
private createPrompt = () => {
readlineInterface.question(
this.config.color(`${this.config.query} ${this.config.suffix} `),
(solution) => {
if (this.config.callback) {
this.answers.push(solution);
this.config.callback(solution.toString(), this);
}
readlineInterface.close();
}
);
};
}