Skip to content

Commit

Permalink
ProgressBars - Verify bar exists on update. Should fix #215
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Oct 30, 2024
1 parent 0030d99 commit e5e5532
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lib/logging/ProgressBars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ export class ProgressBars extends ProgressLogger implements IProgressLogger {
super(title);

this.title = title.slice(0, 32).trim();
let i = 1;
while (ProgressBars._Bars.getIndex(this.title) !== undefined) this.title = `${title.trim().slice(0, 32).trim()} [${++i}]`;
ProgressBars.Total++;
}
private updateTask(...args: Parameters<typeof ProgressBars._Bars.updateTask>) {
if (ProgressBars._Bars.getIndex(this.title) === undefined) {
ProgressBars._Bars.addTask(this.title, { type: "percentage" });
}
ProgressBars._Bars.updateTask(...args);
}

public start() {
ProgressBars._Bars.addTask(this.title, { type: "percentage" });
ProgressBars._Bars.updateTask(this.title, { percentage: 0 });
let i = 1;
while (ProgressBars._Bars.getIndex(this.title) !== undefined) this.title = `${this.title} [${++i}]`;
this.updateTask(this.title, { percentage: 0 });
}
public log(message: string) {
ProgressBars._Bars.updateTask(this.title, { message });
this.updateTask(this.title, { message });
}
private reset() {
ProgressBars.DownloadSpeed -= this._downloadSpeed;
Expand Down Expand Up @@ -78,7 +83,7 @@ export class ProgressBars extends ProgressLogger implements IProgressLogger {
const speed = chalk`{green ${(this._downloadSpeed / 125000).toFixed(2)} mb/s}`;
const eta = chalk`ETA: {blue ${Math.floor(downloadETA / 60)}m ${Math.floor(downloadETA) % 60}s}`;

ProgressBars._Bars.updateTask(this.title, {
this.updateTask(this.title, {
percentage: progress.percent,
message: `${downloaded} ${speed} ${eta}`,
});
Expand Down

0 comments on commit e5e5532

Please sign in to comment.