From 5ad17309708418bc24b682451c5b30ce4fa3387f Mon Sep 17 00:00:00 2001 From: darkdarcool <66882633+darkdarcool@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:58:12 -0500 Subject: [PATCH 1/7] feat(cli): spinner.ts" --- cli/mod.ts | 1 + cli/spinner.ts | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 cli/spinner.ts diff --git a/cli/mod.ts b/cli/mod.ts index 5e3b4e211659..c73538ff5571 100644 --- a/cli/mod.ts +++ b/cli/mod.ts @@ -8,3 +8,4 @@ export * from "./parse_args.ts"; export * from "./prompt_secret.ts"; +export * from './spinner.ts'; \ No newline at end of file diff --git a/cli/spinner.ts b/cli/spinner.ts new file mode 100644 index 000000000000..2441e68cb948 --- /dev/null +++ b/cli/spinner.ts @@ -0,0 +1,163 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +const encoder = new TextEncoder(); + +const LINE_CLEAR = encoder.encode("\r\u001b[K"); // From cli/prompt_secret.ts +const COLOR_RESET = "\u001b[0m"; +const DEFAULT_SPEED = 75; + +/** The options for the spinner */ +export interface SpinnerOptions { + /** The spinner to be animated */ + spinner: string[]; + /** The message to display next to the spinner */ + message?: string; + /** The speed of the spinner. Defaults to 75 */ + speed?: number; + /** The color of the spinner. Defaults to the default terminal color */ + color?: string; + /** Whether to cleanup the output if the process is terminated. Defaults to true */ + cleanup?: boolean; +} + +/** The default spinners */ +export const spinners = { + lines: ['-', '\\', '|', '/'], + binary: ['0000', '1000', '1100', '1110', '1111', '0111', '0011', '0001'], + dots: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], + dots2: ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'], + blink: ['◜', '◠', '◝', '◞', '◡', '◟'], +} + +/** + * A spinner that can be used to indicate that something is loading. + */ +export class Spinner { + #message: string | undefined; + #speed: number; + #spinner: string[]; + #color: string | undefined; + #cleanup: boolean; + + #intervalId: number | undefined; + + /** + * Creates a new spinner. + * @param message - The message to display next to the spinner. + * @param speed - The speed of the spinner. + * @param spinner - The spinner to use. + * @param color - The color of the spinner. + * @param cleanup - Whether to cleanup the output if the process is terminated. + */ + constructor(message: string | undefined, speed: number, spinner: string[], color: string | undefined, cleanup: boolean) { + this.#message = message; + this.#speed = speed; + this.#spinner = spinner; + this.#color = color; + this.#cleanup = cleanup; + } + + /** + * Starts the spinner. + */ + start() { + let i = 0; + const message = this.#message ?? ''; + + const color = this.#color ?? ''; + + if (Deno.stdout.writable.locked) return; + + // Updates the spinner after the given interval. + const updateFrame = () => { + Deno.stdout.writeSync(LINE_CLEAR); + let frame; + // If color was specified, add it to the frame. Otherwise, just use the spinner and message. + if (this.#color) frame = encoder.encode(color + this.#spinner[i] + COLOR_RESET + ' ' + message); + else frame = encoder.encode(this.#spinner[i] + ' ' + message); + Deno.stdout.writeSync(frame); + i = (i + 1) % this.#spinner.length; + } + + this.#intervalId = setInterval(updateFrame, this.#speed); + + // Cleanup if the process is terminated. + if (this.#cleanup) Deno.addSignalListener("SIGINT" , this.cleanup.bind(this)); + } + + /** + * Stops the spinner. + */ + stop() { + if (this.#intervalId) { + clearInterval(this.#intervalId); + Deno.stdout.writeSync(LINE_CLEAR); // Clear the current line + } + } + + /** + * Stops the spinner and cleans up the output. + */ + cleanup() { + this.stop(); + Deno.stdout.writeSync(encoder.encode("\n")); + } +} + +/** + * Creates a spinner with the given options. + * + * Note: The spinner will _not_ start automatically. + * @param options - The options for the spinner. + * @returns The created spinner. + * + * @example + * ```ts + * const mySpinner = createSpinner({ + * spinner: spinners.lineSpinner, + * message: 'Loading...', + * }); + * + * mySpinner.start(); + * ``` + * + * You can also add custom spinners: + * ```ts + * const mySpinner = createSpinner({ + * spinner: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], + * message: 'Loading...', + * speed: 20 + * }); + * + * mySpinner.start(); + * ``` + */ +export function createSpinner({ message, speed = DEFAULT_SPEED, spinner, color, cleanup = true }: SpinnerOptions): Spinner { + return new Spinner(message, speed, spinner, color, cleanup); +} + +/** + * Creates a spinner with the given options and starts it. + * + * @param promise The async callback function + * @param spinner The spinner to use + * @returns The result of the promise + * + * @example + * ```ts + * const myPromise = () => new Promise((resolve) => setTimeout(resolve, 5000)); + * + * const spinner = createSpinner({ + * spinner: spinners.dots, + * message: 'Loading...', + * }); + * + * spinnerPromise(myPromise, spinner).then(() => console.log('Done!')); + * ``` + */ +export async function spinnerPromise(promise: () => Promise, spinner: Spinner): Promise { + spinner.start(); + const result = await promise(); + spinner.stop(); + return result; +} \ No newline at end of file From dff1a8a59a3c35689cae0f3d84188efcd887b06b Mon Sep 17 00:00:00 2001 From: darkdarcool <66882633+darkdarcool@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:51:45 -0500 Subject: [PATCH 2/7] feat(cli/spinner.ts): Added iuioiua's suggestions, and got rid of the createSpinner function --- cli/spinner.ts | 170 ++++++++++++++++++------------------------------- 1 file changed, 61 insertions(+), 109 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 2441e68cb948..5f3a09b75762 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -5,66 +5,78 @@ const encoder = new TextEncoder(); const LINE_CLEAR = encoder.encode("\r\u001b[K"); // From cli/prompt_secret.ts const COLOR_RESET = "\u001b[0m"; const DEFAULT_SPEED = 75; +const DEFAULT_SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; -/** The options for the spinner */ +/** Options for {@linkcode Spinner}. */ export interface SpinnerOptions { - /** The spinner to be animated */ - spinner: string[]; - /** The message to display next to the spinner */ + /** + * The sequence of characters to be iterated through for animation. + * + * @default {["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]} + */ + spinner?: string[]; + /** The message to display next to the spinner. */ message?: string; - /** The speed of the spinner. Defaults to 75 */ + /** The speed of the spinner. + * + * @default {75} + */ speed?: number; - /** The color of the spinner. Defaults to the default terminal color */ + /** The color of the spinner. Defaults to the default terminal color. */ color?: string; - /** Whether to cleanup the output if the process is terminated. Defaults to true */ + /** + * Whether to cleanup the output if the process is terminated. + * + * @default {true} + */ cleanup?: boolean; } -/** The default spinners */ -export const spinners = { - lines: ['-', '\\', '|', '/'], - binary: ['0000', '1000', '1100', '1110', '1111', '0111', '0011', '0001'], - dots: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], - dots2: ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'], - blink: ['◜', '◠', '◝', '◞', '◡', '◟'], -} - /** * A spinner that can be used to indicate that something is loading. */ export class Spinner { - #message: string | undefined; - #speed: number; - #spinner: string[]; - #color: string | undefined; - #cleanup: boolean; - + #options: SpinnerOptions; + #intervalId: number | undefined; + #active = false; /** * Creates a new spinner. - * @param message - The message to display next to the spinner. - * @param speed - The speed of the spinner. - * @param spinner - The spinner to use. - * @param color - The color of the spinner. - * @param cleanup - Whether to cleanup the output if the process is terminated. + * @param options - The options for the spinner. + * + * @example + * ```ts + * const spinner = new Spinner({ message: "Loading..." }); + * spinner.start(); + * ``` */ - constructor(message: string | undefined, speed: number, spinner: string[], color: string | undefined, cleanup: boolean) { - this.#message = message; - this.#speed = speed; - this.#spinner = spinner; - this.#color = color; - this.#cleanup = cleanup; + constructor(options?: SpinnerOptions) { + this.#options = options ?? { + message: undefined, + speed: DEFAULT_SPEED, + spinner: DEFAULT_SPINNER, + color: undefined, + cleanup: true, + }; } /** * Starts the spinner. */ start() { + // Check if the spinner is already active. + if (this.#active) return; + this.#active = true; + let i = 0; - const message = this.#message ?? ''; - - const color = this.#color ?? ''; + + const message = this.#options.message ?? ""; + const spinner = this.#options.spinner ?? DEFAULT_SPINNER; + const speed = this.#options.speed ?? DEFAULT_SPEED; + const cleanup = this.#options.cleanup ?? true; + + const color = this.#options.color ?? ""; if (Deno.stdout.writable.locked) return; @@ -73,91 +85,31 @@ export class Spinner { Deno.stdout.writeSync(LINE_CLEAR); let frame; // If color was specified, add it to the frame. Otherwise, just use the spinner and message. - if (this.#color) frame = encoder.encode(color + this.#spinner[i] + COLOR_RESET + ' ' + message); - else frame = encoder.encode(this.#spinner[i] + ' ' + message); + if (this.#options.color) { + frame = encoder.encode(color + spinner + COLOR_RESET + " " + message); + } else frame = encoder.encode(spinner[i] + " " + message); + Deno.stdout.writeSync(frame); - i = (i + 1) % this.#spinner.length; - } + i = (i + 1) % spinner.length; + }; - this.#intervalId = setInterval(updateFrame, this.#speed); + this.#intervalId = setInterval(updateFrame, speed); // Cleanup if the process is terminated. - if (this.#cleanup) Deno.addSignalListener("SIGINT" , this.cleanup.bind(this)); + if (cleanup) { + Deno.addSignalListener("SIGINT", this.stop.bind(this)); + } } /** * Stops the spinner. */ stop() { - if (this.#intervalId) { + if (this.#intervalId && this.#active) { clearInterval(this.#intervalId); Deno.stdout.writeSync(LINE_CLEAR); // Clear the current line + Deno.removeSignalListener("SIGINT", this.stop.bind(this)); + this.#active = false; } } - - /** - * Stops the spinner and cleans up the output. - */ - cleanup() { - this.stop(); - Deno.stdout.writeSync(encoder.encode("\n")); - } -} - -/** - * Creates a spinner with the given options. - * - * Note: The spinner will _not_ start automatically. - * @param options - The options for the spinner. - * @returns The created spinner. - * - * @example - * ```ts - * const mySpinner = createSpinner({ - * spinner: spinners.lineSpinner, - * message: 'Loading...', - * }); - * - * mySpinner.start(); - * ``` - * - * You can also add custom spinners: - * ```ts - * const mySpinner = createSpinner({ - * spinner: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], - * message: 'Loading...', - * speed: 20 - * }); - * - * mySpinner.start(); - * ``` - */ -export function createSpinner({ message, speed = DEFAULT_SPEED, spinner, color, cleanup = true }: SpinnerOptions): Spinner { - return new Spinner(message, speed, spinner, color, cleanup); -} - -/** - * Creates a spinner with the given options and starts it. - * - * @param promise The async callback function - * @param spinner The spinner to use - * @returns The result of the promise - * - * @example - * ```ts - * const myPromise = () => new Promise((resolve) => setTimeout(resolve, 5000)); - * - * const spinner = createSpinner({ - * spinner: spinners.dots, - * message: 'Loading...', - * }); - * - * spinnerPromise(myPromise, spinner).then(() => console.log('Done!')); - * ``` - */ -export async function spinnerPromise(promise: () => Promise, spinner: Spinner): Promise { - spinner.start(); - const result = await promise(); - spinner.stop(); - return result; } \ No newline at end of file From 70bc64cc724556b60c7b9d9a5de96837332b30d5 Mon Sep 17 00:00:00 2001 From: darkdarcool <66882633+darkdarcool@users.noreply.github.com> Date: Mon, 18 Dec 2023 07:31:00 -0500 Subject: [PATCH 3/7] feat(cli/spinner.ts): Added jsdoc to start and stop, and got rid of the cleanup option --- cli/spinner.ts | 61 +++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 5f3a09b75762..08021cd44078 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -24,12 +24,6 @@ export interface SpinnerOptions { speed?: number; /** The color of the spinner. Defaults to the default terminal color. */ color?: string; - /** - * Whether to cleanup the output if the process is terminated. - * - * @default {true} - */ - cleanup?: boolean; } /** @@ -47,34 +41,39 @@ export class Spinner { * * @example * ```ts + * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; + * * const spinner = new Spinner({ message: "Loading..." }); - * spinner.start(); * ``` */ constructor(options?: SpinnerOptions) { - this.#options = options ?? { - message: undefined, - speed: DEFAULT_SPEED, + this.#options = { spinner: DEFAULT_SPINNER, - color: undefined, - cleanup: true, - }; + speed: DEFAULT_SPEED, + message: "", + ...options + } } /** * Starts the spinner. + * + * @example + * ```ts + * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; + * + * const spinner = new Spinner({ message: "Loading..." }); + * spinner.start(); + * ``` */ start() { + const options = this.#options; // Check if the spinner is already active. if (this.#active) return; this.#active = true; let i = 0; - - const message = this.#options.message ?? ""; - const spinner = this.#options.spinner ?? DEFAULT_SPINNER; - const speed = this.#options.speed ?? DEFAULT_SPEED; - const cleanup = this.#options.cleanup ?? true; + const color = this.#options.color ?? ""; @@ -86,23 +85,33 @@ export class Spinner { let frame; // If color was specified, add it to the frame. Otherwise, just use the spinner and message. if (this.#options.color) { - frame = encoder.encode(color + spinner + COLOR_RESET + " " + message); - } else frame = encoder.encode(spinner[i] + " " + message); + frame = encoder.encode(color + options.spinner![i] + COLOR_RESET + " " + options.message); + } else frame = encoder.encode(options.spinner![i] + " " + options.message); Deno.stdout.writeSync(frame); - i = (i + 1) % spinner.length; + i = (i + 1) % options.spinner!.length; }; - this.#intervalId = setInterval(updateFrame, speed); + this.#intervalId = setInterval(updateFrame, options.speed); + - // Cleanup if the process is terminated. - if (cleanup) { - Deno.addSignalListener("SIGINT", this.stop.bind(this)); - } } /** * Stops the spinner. + * + * @example + * ```ts + * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; + * + * const spinner = new Spinner({ message: "Loading..." }); + * spinner.start(); + * + * setTimeout(() => { + * spinner.stop(); + * console.log("Finished loading!"); + * }, 3000); + * ``` */ stop() { if (this.#intervalId && this.#active) { From 0a0230999a21ca86d348f89f8e119beacc7ac34e Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 19 Dec 2023 09:02:03 +1100 Subject: [PATCH 4/7] tweaks --- cli/mod.ts | 2 +- cli/spinner.ts | 61 +++++++++++++++++++------------------------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/cli/mod.ts b/cli/mod.ts index c73538ff5571..f6c54995430f 100644 --- a/cli/mod.ts +++ b/cli/mod.ts @@ -8,4 +8,4 @@ export * from "./parse_args.ts"; export * from "./prompt_secret.ts"; -export * from './spinner.ts'; \ No newline at end of file +export * from "./spinner.ts"; diff --git a/cli/spinner.ts b/cli/spinner.ts index 08021cd44078..a2f50b6682f7 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -30,83 +30,68 @@ export interface SpinnerOptions { * A spinner that can be used to indicate that something is loading. */ export class Spinner { - #options: SpinnerOptions; - + #spinner: string[]; + #message: string; + #speed: number; + #color?: string; #intervalId: number | undefined; #active = false; /** * Creates a new spinner. - * @param options - The options for the spinner. * * @example * ```ts * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; - * + * * const spinner = new Spinner({ message: "Loading..." }); * ``` */ constructor(options?: SpinnerOptions) { - this.#options = { - spinner: DEFAULT_SPINNER, - speed: DEFAULT_SPEED, - message: "", - ...options - } + this.#spinner = options?.spinner ?? DEFAULT_SPINNER; + this.#message = options?.message ?? ""; + this.#speed = options?.speed ?? DEFAULT_SPEED; + this.#color = options?.color; } /** * Starts the spinner. - * - * @example + * + * @example * ```ts * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; - * + * * const spinner = new Spinner({ message: "Loading..." }); * spinner.start(); * ``` */ start() { - const options = this.#options; - // Check if the spinner is already active. - if (this.#active) return; + if (this.#active || Deno.stdout.writable.locked) return; this.#active = true; - let i = 0; - - - const color = this.#options.color ?? ""; - - if (Deno.stdout.writable.locked) return; + const color = this.#color ?? ""; // Updates the spinner after the given interval. const updateFrame = () => { Deno.stdout.writeSync(LINE_CLEAR); - let frame; - // If color was specified, add it to the frame. Otherwise, just use the spinner and message. - if (this.#options.color) { - frame = encoder.encode(color + options.spinner![i] + COLOR_RESET + " " + options.message); - } else frame = encoder.encode(options.spinner![i] + " " + options.message); - + const frame = encoder.encode( + color + this.#spinner[i] + COLOR_RESET + " " + this.#message, + ); Deno.stdout.writeSync(frame); - i = (i + 1) % options.spinner!.length; + i = (i + 1) % this.#spinner.length; }; - - this.#intervalId = setInterval(updateFrame, options.speed); - - + this.#intervalId = setInterval(updateFrame, this.#speed); } - /** * Stops the spinner. - * + * * @example * ```ts * import { Spinner } from "https://deno.land/std@$STD_VERSION/cli/spinner.ts"; - * + * * const spinner = new Spinner({ message: "Loading..." }); * spinner.start(); - * + * * setTimeout(() => { * spinner.stop(); * console.log("Finished loading!"); @@ -121,4 +106,4 @@ export class Spinner { this.#active = false; } } -} \ No newline at end of file +} From 1b22a75579dde2f928dd1648dbb1001b1f7a4257 Mon Sep 17 00:00:00 2001 From: darkdarcool Date: Tue, 19 Dec 2023 09:43:38 -0500 Subject: [PATCH 5/7] changed speed to interval, and added support for human readable colors --- cli/spinner.ts | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index a2f50b6682f7..c8dd558a326d 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -4,9 +4,26 @@ const encoder = new TextEncoder(); const LINE_CLEAR = encoder.encode("\r\u001b[K"); // From cli/prompt_secret.ts const COLOR_RESET = "\u001b[0m"; -const DEFAULT_SPEED = 75; +const DEFAULT_INTERVAL = 75; const DEFAULT_SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; +// This is a hack to allow us to use the same type for both the color name and an ANSI escape code. +// deno-lint-ignore ban-types +type Ansi = string & { }; +type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | Ansi; + +const COLORS: Record = { + black: "\u001b[30m", + red: "\u001b[31m", + green: "\u001b[32m", + yellow: "\u001b[33m", + blue: "\u001b[34m", + magenta: "\u001b[35m", + cyan: "\u001b[36m", + white: "\u001b[37m", + gray: "\u001b[90m", +}; + /** Options for {@linkcode Spinner}. */ export interface SpinnerOptions { /** @@ -17,13 +34,13 @@ export interface SpinnerOptions { spinner?: string[]; /** The message to display next to the spinner. */ message?: string; - /** The speed of the spinner. + /** The time between each frame of the spinner. * * @default {75} */ - speed?: number; + interval?: number; /** The color of the spinner. Defaults to the default terminal color. */ - color?: string; + color?: Color; } /** @@ -32,8 +49,8 @@ export interface SpinnerOptions { export class Spinner { #spinner: string[]; #message: string; - #speed: number; - #color?: string; + #interval: number; + #color?: Color; #intervalId: number | undefined; #active = false; @@ -50,8 +67,8 @@ export class Spinner { constructor(options?: SpinnerOptions) { this.#spinner = options?.spinner ?? DEFAULT_SPINNER; this.#message = options?.message ?? ""; - this.#speed = options?.speed ?? DEFAULT_SPEED; - this.#color = options?.color; + this.#interval = options?.interval ?? DEFAULT_INTERVAL; + this.#color = options?.color ? COLORS[options.color] : undefined; } /** @@ -80,7 +97,7 @@ export class Spinner { Deno.stdout.writeSync(frame); i = (i + 1) % this.#spinner.length; }; - this.#intervalId = setInterval(updateFrame, this.#speed); + this.#intervalId = setInterval(updateFrame, this.#interval); } /** * Stops the spinner. @@ -102,8 +119,7 @@ export class Spinner { if (this.#intervalId && this.#active) { clearInterval(this.#intervalId); Deno.stdout.writeSync(LINE_CLEAR); // Clear the current line - Deno.removeSignalListener("SIGINT", this.stop.bind(this)); this.#active = false; } } -} +} \ No newline at end of file From ab957cb877e35177448c2a812d11d55c5441bd63 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 20 Dec 2023 15:31:08 +0900 Subject: [PATCH 6/7] fmt --- cli/spinner.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index c8dd558a326d..be651e567ad6 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -9,8 +9,18 @@ const DEFAULT_SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", // This is a hack to allow us to use the same type for both the color name and an ANSI escape code. // deno-lint-ignore ban-types -type Ansi = string & { }; -type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | Ansi; +type Ansi = string & {}; +type Color = + | "black" + | "red" + | "green" + | "yellow" + | "blue" + | "magenta" + | "cyan" + | "white" + | "gray" + | Ansi; const COLORS: Record = { black: "\u001b[30m", @@ -122,4 +132,4 @@ export class Spinner { this.#active = false; } } -} \ No newline at end of file +} From ffb621c20eae211a205a46e6f188bb8b140ffec3 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 20 Dec 2023 15:36:50 +0900 Subject: [PATCH 7/7] add comments --- cli/spinner.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/spinner.ts b/cli/spinner.ts index be651e567ad6..3d08f820afe3 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -1,5 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +// TODO(kt3k): Write test when pty is supported in Deno +// See: https://github.com/denoland/deno/issues/3994 + const encoder = new TextEncoder(); const LINE_CLEAR = encoder.encode("\r\u001b[K"); // From cli/prompt_secret.ts @@ -8,6 +11,7 @@ const DEFAULT_INTERVAL = 75; const DEFAULT_SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; // This is a hack to allow us to use the same type for both the color name and an ANSI escape code. +// ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-460346421 // deno-lint-ignore ban-types type Ansi = string & {}; type Color =