-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-progress.js
More file actions
18 lines (17 loc) · 816 Bytes
/
Copy pathsimple-progress.js
File metadata and controls
18 lines (17 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* This function displays a simple progress bar in the console.
* @param {number} completed The number of items completed.
* @param {number} total The total number of items.
* @param {number} [barLength=24] The length (in characters) of the progress bar.
*/
function displayProgressBar(completed, total, barLength = 24) {
const progress = Math.round((completed / total) * barLength);
const completedBar = "█".repeat(progress);
const remainingBar = "█".repeat(barLength - progress);
const percentage = Math.round((completed / total) * 100);
const color = percentage < 50 ? "\x1b[31m" : percentage < 75 ? "\x1b[33m" : "\x1b[32m"; // Red, Yellow, Green
process.stdout.write(`\r${color}${completedBar}\x1b[0m${remainingBar} ${completed}/${total}`);
}
module.exports = {
displayProgressBar,
};