Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cli/unstable_progress_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
export interface ProgressBarFormatter {
/**
* A function that returns a formatted version of the duration.
* `[mm:ss]`
* `mm:ss`
*/
styledTime: () => string;
/**
* A function that returns a formatted version of the data received.
* `[0.40/97.66 KiB]`
* `0.40/97.66 KiB`
* @param fractions The number of decimal places the values should have.
*/
styledData: (fractions?: number) => string;
/**
* The progress bar string.
* Default Style: `[###-------]`
* Default Style: `###-------`
*/
progressBar: string;
/**
Expand Down Expand Up @@ -150,7 +150,7 @@ const UNIT_RATE_MAP = new Map<Unit, number>([
* const bar = new ProgressBar({
* max: 100,
* fmt(x) {
* return `${x.styledTime()}${x.progressBar}[${x.value}/${x.max} files]`;
* return `[${x.styledTime()}] [${x.progressBar}] [${x.value}/${x.max} files]`;
* },
* });
*
Expand Down Expand Up @@ -223,7 +223,7 @@ export class ProgressBar {
fillChar = "#",
emptyChar = "-",
clear = false,
fmt = (x) => `${x.styledTime()} ${x.progressBar} ${x.styledData()} `,
fmt = (x) => `[${x.styledTime()}] [${x.progressBar}] [${x.styledData()}]`,
keepOpen = true,
} = options;
this.value = value;
Expand Down Expand Up @@ -260,14 +260,14 @@ export class ProgressBar {
styledTime() {
const minutes = (this.time / 1000 / 60 | 0).toString().padStart(2, "0");
const seconds = (this.time / 1000 % 60 | 0).toString().padStart(2, "0");
return `[${minutes}:${seconds}]`;
return `${minutes}:${seconds}`;
},
styledData: (fractions = 2): string => {
const currentValue = (this.value / this.#rate).toFixed(fractions);
const maxValue = (this.max / this.#rate).toFixed(fractions);
return `[${currentValue}/${maxValue} ${this.#unit}]`;
return `${currentValue}/${maxValue} ${this.#unit}`;
},
progressBar: `[${fillChars}${emptyChars}]`,
progressBar: `${fillChars}${emptyChars}`,
time: currentTime - this.#startTime,
previousTime: this.#lastTime - this.#startTime,
value: this.value,
Expand Down
2 changes: 1 addition & 1 deletion cli/unstable_progress_bar_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Deno.test("ProgressBar() uses correct unit type", async () => {

const decoder = new TextDecoder();
for await (const buffer of readable) {
assertEquals(decoder.decode(buffer.subarray(-5, -2)), unit);
assertEquals(decoder.decode(buffer.subarray(-4, -1)), unit);
break;
}
bar.stop();
Expand Down
Loading