* 进度条 * @param {number} current 当前进度 * @param {number} total 总进度 * @param {string} label 标签
(current, total, label = '')
| 116 | * @param {string} label 标签 |
| 117 | */ |
| 118 | progress(current, total, label = '') { |
| 119 | if (this.silent) return; |
| 120 | |
| 121 | const percent = Math.floor((current / total) * 100); |
| 122 | const barLength = 40; |
| 123 | const filledLength = Math.floor((current / total) * barLength); |
| 124 | const emptyLength = barLength - filledLength; |
| 125 | |
| 126 | // 构建进度条 |
| 127 | const bar = '█'.repeat(filledLength) + '░'.repeat(emptyLength); |
| 128 | |
| 129 | // 构建输出 |
| 130 | const output = `[${bar}] ${percent}% ${current}/${total} ${label}`; |
| 131 | |
| 132 | // 输出进度条(覆盖当前行) |
| 133 | process.stdout.write(`\r${output}`); |
| 134 | |
| 135 | // 如果完成,添加换行 |
| 136 | if (current === total) { |
| 137 | process.stdout.write('\n'); |
| 138 | } |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | // 导出 |
nothing calls this directly
no outgoing calls
no test coverage detected