From 9424aeab4bba5169c67d3ab63b4d5a2ea6e3e5c5 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 20 May 2025 15:32:12 +0200 Subject: [PATCH] initial commit --- cli/unstable_progress_bar.ts | 16 ---------------- cli/unstable_progress_bar_test.ts | 23 ----------------------- 2 files changed, 39 deletions(-) diff --git a/cli/unstable_progress_bar.ts b/cli/unstable_progress_bar.ts index de85fea31df1..40584f913530 100644 --- a/cli/unstable_progress_bar.ts +++ b/cli/unstable_progress_bar.ts @@ -24,18 +24,10 @@ export interface ProgressBarFormatter { * The duration of the progress bar. */ time: number; - /** - * The duration passed to the last call. - */ - previousTime: number; /** * The current value the progress bar is sitting at. */ value: number; - /** - * The value passed to the last call. - */ - previousValue: number; /** * The max value expected to receive. */ @@ -167,8 +159,6 @@ export class ProgressBar { #writer: WritableStreamDefaultWriter; #id: number; #startTime: number; - #lastTime: number; - #lastValue: number; #value: number; #max: number; @@ -215,8 +205,6 @@ export class ProgressBar { this.#writer = stream.writable.getWriter(); this.#id = setInterval(() => this.#print(), 1000); this.#startTime = performance.now(); - this.#lastTime = this.#startTime; - this.#lastValue = this.#value; } async #print(): Promise { @@ -239,13 +227,9 @@ export class ProgressBar { }, progressBar: `[${fillChars}${emptyChars}]`, time: currentTime - this.#startTime, - previousTime: this.#lastTime - this.#startTime, value: this.#value, - previousValue: this.#lastValue, max: this.#max, }; - this.#lastTime = currentTime; - this.#lastValue = this.#value; await this.#writer.write("\r\u001b[K" + this.#fmt(formatter)) .catch(() => {}); } diff --git a/cli/unstable_progress_bar_test.ts b/cli/unstable_progress_bar_test.ts index b73b308108aa..6f287e23cfec 100644 --- a/cli/unstable_progress_bar_test.ts +++ b/cli/unstable_progress_bar_test.ts @@ -85,29 +85,6 @@ Deno.test("ProgressBar() can remove itself when finished", async () => { } }); -Deno.test("ProgressBar() passes correct values to formatter", async () => { - const { readable, writable } = new TransformStream(); - let lastTime: undefined | number = undefined; - let lastValue: undefined | number = undefined; - const bar = new ProgressBar({ - writable, - max: 10 * 1000, - keepOpen: false, - fmt(x) { - if (lastTime != undefined) assertEquals(x.previousTime, lastTime); - if (lastValue != undefined) assertEquals(x.previousValue, lastValue); - lastTime = x.time; - lastValue = x.value; - return ""; - }, - }); - - for await (const a of getData(10, 1000)) bar.add(a.length); - bar.stop(); - - await new Response(readable).bytes(); -}); - Deno.test("ProgressBar() uses correct unit type", async () => { const units = ["KiB", "MiB", "GiB", "TiB", "PiB"]; let i = 0;