-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazy.logger.js
More file actions
58 lines (50 loc) · 1.41 KB
/
Copy pathlazy.logger.js
File metadata and controls
58 lines (50 loc) · 1.41 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict'
const chalk = require('chalk');
const LOADING_ANIMATION_FRAME_MS = 80;
const LOADING_ANIMATION_SPRITES = [
"⠋",
"⠙",
"⠹",
"⠸",
"⠼",
"⠴",
"⠦",
"⠧",
"⠇",
"⠏"
]
class TinyLogger{
constructor(){
if(!instance){
this.timer = null;
this.loadingText = "";
this.loadingAnimationFrame = 0;
instance = this;
}
return instance;
}
get currentLoadingAnimationSprite(){
return LOADING_ANIMATION_SPRITES[this.loadingAnimationFrame];
}
log(txt, end = false){
this.loadingText = txt;
if(this.timer == null){
var self = this;
this.timer = setInterval(function(){
self.loadingAnimationFrame = (self.loadingAnimationFrame + 1) % LOADING_ANIMATION_SPRITES.length;
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(` ${chalk.green(self.currentLoadingAnimationSprite)} ${chalk.yellow(self.loadingText)}...`)
}, LOADING_ANIMATION_FRAME_MS);
}
if(end){
clearInterval(this.timer);
this.timer = null;
this.loadingAnimationFrame = 0;
process.stdout.clearLine();
process.stdout.cursorTo(0);
}
}
}
var instance = new TinyLogger();
module.exports = instance;