-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (73 loc) · 1.53 KB
/
index.js
File metadata and controls
84 lines (73 loc) · 1.53 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const elegantSpinner = require('elegant-spinner');
const logUpdate = require('log-update');
const styles = require('./color');
module.exports = class ConsoleSpinner {
constructor(name) {
this.name = name;
this.word = [];
this.started = false;
this.frame = elegantSpinner();
this.update = logUpdate.create(process.stdout, {
showCursor: true
});
}
value() {
const args = [];
if (this.name) args.push(`${styles.gray}[${this.name}]${styles.colorClose}`);
args.push(...this.word);
return args;
}
start() {
this.timer = setInterval(() => {
this.update(this.frame(), ...this.value());
}, 50);
this.started = true;
}
log(...args) {
this.word = args;
}
error(...args) {
this.word = [
`${styles.red}Error${styles.colorClose}`,
...args
]
}
info(...args) {
this.word = [
`${styles.blue}Infomation${styles.colorClose}`,
...args
];
}
success(...args) {
this.word = [
`${styles.green}Success${styles.colorClose}`,
...args
];
}
warn(...args) {
this.word = [
`${styles.yellow}Warning${styles.colorClose}`,
...args
];
}
debug(...args) {
this.word = [
`${styles.magenta}Debug${styles.colorClose}`,
...args
];
}
test(...args) {
this.word = [
`${styles.cyan}Test${styles.colorClose}`,
...args
];
}
stop(clear) {
clearInterval(this.timer);
this.word = [];
this.started = false;
if (clear) {
this.update.clear();
}
}
};