-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.js
37 lines (32 loc) · 1.02 KB
/
terminal.js
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
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
module.exports = new function(){
this.clearScreen = function() {
//console.log('\u001b[2J'); // Linux Clear Screen
//process.stdout.write('\x1b\x63'); // Windows Clear screen
console.clear(); // General Clear Screen
}
this.getUserInput = async function(question = "") {
return new Promise((resolve) => {
rl.question(question, (answer) => {
if (answer.toLowerCase() === 'exit') { // Check if the user wants to exit
rl.close(); // Close the readline interface
}
resolve(answer);
});
});
}
this.beep = function() {
// Bellow tested on windows
//process.stdout.write('\u0007');
console.log('\u0007');
}
this.sleep = async function(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
}