From 99ea325013443ab709af3649a12b6e2686ad282b Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 19 Dec 2024 16:10:04 -0500 Subject: [PATCH] ProgressWriter: Logic Modifications - The progress and percentage is now calculated separately. - The progress bar is removed once the operation has completed. --- project/src/utils/ProgressWriter.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/project/src/utils/ProgressWriter.ts b/project/src/utils/ProgressWriter.ts index 67205a98..74d6a76e 100644 --- a/project/src/utils/ProgressWriter.ts +++ b/project/src/utils/ProgressWriter.ts @@ -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; } }