| 3 | const { stdout } = process; |
| 4 | |
| 5 | export function renderProgress(percent: number, stage: string, row?: number): void { |
| 6 | const width = 25; |
| 7 | const filled = Math.floor(percent / (100 / width)); |
| 8 | const empty = width - filled; |
| 9 | const bar = c.progress("\u2588".repeat(filled)) + c.dim("\u2591".repeat(empty)); |
| 10 | |
| 11 | const line = ` ${bar} ${c.bold(String(Math.round(percent)) + "%")} ${c.dim(stage)}`; |
| 12 | |
| 13 | if (row !== undefined && stdout.isTTY) { |
| 14 | stdout.write(`\x1b[${row};1H\x1b[2K${line}`); |
| 15 | } else { |
| 16 | stdout.write(`\r\x1b[2K${line}`); |
| 17 | } |
| 18 | } |