hadean-old/src/Progressbar.ts

12 lines
408 B
TypeScript
Raw Normal View History

2021-06-14 22:03:55 -04:00
import chalk from "chalk";
export function progressbar(completion, width, style = chalk.bold.bgRed.green) {
const chars = [' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
let str = '';
for(let i = 0; i < width; i ++) {
const remainder = Math.floor(Math.min(Math.max(0, (completion * width) - i), 1) * 8);
const char = chars[remainder];
str += style(char);
}
return str;
}