-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathprogressBar.mjs
More file actions
43 lines (37 loc) · 890 Bytes
/
progressBar.mjs
File metadata and controls
43 lines (37 loc) · 890 Bytes
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
import { styleText } from 'node:util';
import cliProgress from 'cli-progress';
/**
*
* @param {string} label
* @returns {import('cli-progress').SingleBar}
*/
export function createProgressBar(label = '') {
const format = ` ${styleText(['bold', 'green'], '{bar}')} | ${label} {percentage}% | {value}/{total}`;
return new cliProgress.SingleBar({
format,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
});
}
/**
*
* @param {import('cli-progress').SingleBar} bar
* @param {number} total
*/
export function startProgressBar(bar, total) {
bar.start(total, 0);
}
/**
* @param {import('cli-progress').SingleBar} bar
* @param {number} value
*/
export function updateProgressBar(bar, value = 1) {
bar.update(value);
}
/**
* @param {import('cli-progress').SingleBar} bar
*/
export function stopProgressBar(bar) {
bar.stop();
}