-
Notifications
You must be signed in to change notification settings - Fork 72
/
progress.js
55 lines (46 loc) · 1.58 KB
/
progress.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
export default class Progress {
constructor(total, progressBarLength) {
this.total = total;
this.progressBarLength = progressBarLength;
this.cdnLinks = { success: 0, fails: 0 };
this.downloads = { success: 0, fails: 0 };
this.printProgress(true);
}
cdnLinkSucceeded(didSucceed) {
didSucceed ? this.cdnLinks.success++ : this.cdnLinks.fails++;
this.printProgress();
}
downloadSucceeded(didSucceed) {
didSucceed ? this.downloads.success++ : this.downloads.fails++;
this.printProgress();
}
printProgress(firstRun) {
if (!firstRun) process.stdout.moveCursor(0, -2);
process.stdout.clearLine();
process.stdout.cursorTo(0);
this.printBar(
"CDN-LINKS: ",
this.cdnLinks.success,
this.cdnLinks.fails
);
this.printBar(
"DOWNLOADS: ",
this.downloads.success,
this.downloads.fails
);
}
printBar(name, success, fails) {
process.stdout.write(name);
var progress = (success + fails) / this.total;
var bar = Math.floor(this.progressBarLength * progress);
process.stdout.write("[");
process.stdout.write(
"=".repeat(bar) + "-".repeat(this.progressBarLength - bar)
);
process.stdout.write("] ");
//process.stdout.write((progress * 100).toFixed(2) + "% ")
process.stdout.write("" + success + "/" + this.total);
process.stdout.write("\tFailed: " + fails);
process.stdout.write("\n");
}
};