From 5381ab294ba8326dd3c6b1e4c9069a12a931c362 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 22 May 2024 12:54:39 -0400 Subject: [PATCH 1/4] fix(cli): reduce flicker in spinner render function --- cli/spinner.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 3498ce4cfa97..c358a0abc6ac 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -136,13 +136,16 @@ export class Spinner { // Updates the spinner after the given interval. const updateFrame = () => { const color = this.#color ?? ""; - Deno.stdout.writeSync(LINE_CLEAR); const frame = encoder.encode( noColor ? this.#spinner[i] + " " + this.message : color + this.#spinner[i] + COLOR_RESET + " " + this.message, ); - Deno.stdout.writeSync(frame); + // batch the writeSync call to reduce flickering + const batch = new Uint8Array(LINE_CLEAR.length + frame.length); + batch.set(LINE_CLEAR); + batch.set(frame, LINE_CLEAR.length); + Deno.stdout.writeSync(batch); i = (i + 1) % this.#spinner.length; }; this.#intervalId = setInterval(updateFrame, this.#interval); From 2f058727124449ee6d585d5df394cb6a92dba4ac Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 22 May 2024 12:55:48 -0400 Subject: [PATCH 2/4] update --- cli/spinner.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index c358a0abc6ac..7f5e49224f27 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -141,11 +141,11 @@ export class Spinner { ? this.#spinner[i] + " " + this.message : color + this.#spinner[i] + COLOR_RESET + " " + this.message, ); - // batch the writeSync call to reduce flickering - const batch = new Uint8Array(LINE_CLEAR.length + frame.length); - batch.set(LINE_CLEAR); - batch.set(frame, LINE_CLEAR.length); - Deno.stdout.writeSync(batch); + // call writeSync once to reduce flickering + const writeData = new Uint8Array(LINE_CLEAR.length + frame.length); + writeData.set(LINE_CLEAR); + writeData.set(frame, LINE_CLEAR.length); + Deno.stdout.writeSync(writeData); i = (i + 1) % this.#spinner.length; }; this.#intervalId = setInterval(updateFrame, this.#interval); From 2930525f459d26f72e3dd523a0c87f7dbdd1dbfd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 May 2024 01:01:55 -0400 Subject: [PATCH 3/4] Update cli/spinner.ts Co-authored-by: Asher Gomez --- cli/spinner.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 7f5e49224f27..396a9c46e4d8 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -142,10 +142,7 @@ export class Spinner { : color + this.#spinner[i] + COLOR_RESET + " " + this.message, ); // call writeSync once to reduce flickering - const writeData = new Uint8Array(LINE_CLEAR.length + frame.length); - writeData.set(LINE_CLEAR); - writeData.set(frame, LINE_CLEAR.length); - Deno.stdout.writeSync(writeData); + Deno.stdout.writeSync(concat([LINE_CLEAR, frame])); i = (i + 1) % this.#spinner.length; }; this.#intervalId = setInterval(updateFrame, this.#interval); From 483d0727d7be128097455bff6dbab60dbbff19dd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 May 2024 01:04:11 -0400 Subject: [PATCH 4/4] Revert "Update cli/spinner.ts" This reverts commit 2930525f459d26f72e3dd523a0c87f7dbdd1dbfd. --- cli/spinner.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 396a9c46e4d8..7f5e49224f27 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -142,7 +142,10 @@ export class Spinner { : color + this.#spinner[i] + COLOR_RESET + " " + this.message, ); // call writeSync once to reduce flickering - Deno.stdout.writeSync(concat([LINE_CLEAR, frame])); + const writeData = new Uint8Array(LINE_CLEAR.length + frame.length); + writeData.set(LINE_CLEAR); + writeData.set(frame, LINE_CLEAR.length); + Deno.stdout.writeSync(writeData); i = (i + 1) % this.#spinner.length; }; this.#intervalId = setInterval(updateFrame, this.#interval);