-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconsole-manager.js
32 lines (27 loc) · 1.13 KB
/
console-manager.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
const definitions = require('./definitions');
let consoleGif = {
timer: -1,
frame: 0,
text: ''
};
//*************************************************************************************************
exports.write = function (text, color = 'DEFAULT') {
console.log(definitions.CONSOLE_COLORS[String(color).toUpperCase()], text, definitions.CONSOLE_RESET);
};
//*************************************************************************************************
exports.setLiveText = function (text) {
consoleGif.text = text;
if (consoleGif.timer !== -1) {
return;
}
consoleGif.timer = setInterval(()=>{
process.stdout.write(`${definitions.CONSOLE_ANIMATION[consoleGif.frame%definitions.CONSOLE_ANIMATION.length]} ${consoleGif.text}\r`);
consoleGif.frame = ++consoleGif.frame % definitions.CONSOLE_ANIMATION.length;
}, definitions.CONSOLE_ANIMATION_SPEED);
};
//*************************************************************************************************
exports.hideLiveText = function () {
clearInterval(consoleGif.timer);
consoleGif.timer = -1;
process.stdout.write('');
};