Skip to content

Commit

Permalink
ProgressWriter: Logic Modifications
Browse files Browse the repository at this point in the history
- The progress and percentage is now calculated separately.
- The progress bar is removed once the operation has completed.
  • Loading branch information
refringe committed Dec 19, 2024
1 parent d9fd560 commit 99ea325
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions project/src/utils/ProgressWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 99ea325

Please sign in to comment.