0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 15:50:42 -05:00

ProgressWriter: Logic Modifications

- The progress and percentage is now calculated separately.
- The progress bar is removed once the operation has completed.
This commit is contained in:
Refringe 2024-12-19 16:10:04 -05:00
parent d9fd560a5b
commit 99ea325013
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k

View File

@ -29,21 +29,23 @@ export class ProgressWriter {
this.count++;
const progress = Math.floor((this.count / this.total) * 100);
const filledChars = Math.floor((progress / 100) * this.maxBarLength);
const progress = this.count / this.total;
const percent = Math.floor(progress * 100);
const filledChars = Math.floor(progress * this.maxBarLength);
const emptyChars = this.maxBarLength - filledChars;
const barFill = this.barFillChar.repeat(filledChars);
const barEmptySpace = this.barEmptyChar.repeat(emptyChars);
const progressBar = ` -> ${this.count} / ${this.total} [${barFill}${barEmptySpace}] ${progress}%`;
const progressBar = `-> ${this.count} / ${this.total} [${barFill}${barEmptySpace}] ${percent}%`;
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, null);
process.stdout.write(progressBar);
if (progress === 100) {
process.stdout.write("\n");
if (percent >= 100) {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, null);
this.done = true;
}
}