mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-12 21:50:43 -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:
parent
d9fd560a5b
commit
99ea325013
@ -29,21 +29,23 @@ export class ProgressWriter {
|
|||||||
|
|
||||||
this.count++;
|
this.count++;
|
||||||
|
|
||||||
const progress = Math.floor((this.count / this.total) * 100);
|
const progress = this.count / this.total;
|
||||||
const filledChars = Math.floor((progress / 100) * this.maxBarLength);
|
const percent = Math.floor(progress * 100);
|
||||||
|
|
||||||
|
const filledChars = Math.floor(progress * this.maxBarLength);
|
||||||
const emptyChars = this.maxBarLength - filledChars;
|
const emptyChars = this.maxBarLength - filledChars;
|
||||||
|
|
||||||
const barFill = this.barFillChar.repeat(filledChars);
|
const barFill = this.barFillChar.repeat(filledChars);
|
||||||
const barEmptySpace = this.barEmptyChar.repeat(emptyChars);
|
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);
|
readline.cursorTo(process.stdout, 0, null);
|
||||||
process.stdout.write(progressBar);
|
process.stdout.write(progressBar);
|
||||||
|
|
||||||
if (progress === 100) {
|
if (percent >= 100) {
|
||||||
process.stdout.write("\n");
|
readline.clearLine(process.stdout, 0);
|
||||||
|
readline.cursorTo(process.stdout, 0, null);
|
||||||
this.done = true;
|
this.done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user