diff --git a/index.d.ts b/index.d.ts index 2f6ea26..0bd1d76 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,7 +22,7 @@ export type SuffixTextGenerator = () => string; export type Options = { /** - Text to display after the spinner. + The text to display next to the spinner. */ readonly text?: string; @@ -37,7 +37,7 @@ export type Options = { readonly suffixText?: string | SuffixTextGenerator; /** - Name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/main/example.js) in this repo if you want to test out different spinners. On Windows, it will always use the line spinner as the Windows command-line doesn't have proper Unicode support. + The name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/main/example.js) in this repo if you want to test out different spinners. On Windows (expect for Windows Terminal), it will always use the line spinner as the Windows command-line doesn't have proper Unicode support. @default 'dots' @@ -46,8 +46,8 @@ export type Options = { @example ``` { - interval: 80, // Optional - frames: ['-', '+', '-'] + frames: ['-', '+', '-'], + interval: 80 // Optional } ``` */ @@ -204,7 +204,7 @@ export interface Ora { set spinner(spinner: SpinnerName | Spinner); /** - A boolean of whether the instance is currently spinning. + A boolean indicating whether the instance is currently spinning. */ get isSpinning(): boolean; diff --git a/index.js b/index.js index a030362..a91a0cf 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,6 @@ class Ora { #text; #prefixText; #suffixText; - color; constructor(options) { diff --git a/package.json b/package.json index 4725f0b..71fdc43 100644 --- a/package.json +++ b/package.json @@ -44,21 +44,21 @@ ], "dependencies": { "chalk": "^5.3.0", - "cli-cursor": "^4.0.0", + "cli-cursor": "^5.0.0", "cli-spinners": "^2.9.2", "is-interactive": "^2.0.0", "is-unicode-supported": "^2.0.0", "log-symbols": "^6.0.0", - "stdin-discarder": "^0.2.1", - "string-width": "^7.0.0", + "stdin-discarder": "^0.2.2", + "string-width": "^7.2.0", "strip-ansi": "^7.1.0" }, "devDependencies": { - "@types/node": "^20.10.5", + "@types/node": "^22.5.0", "ava": "^5.3.1", - "get-stream": "^8.0.1", + "get-stream": "^9.0.1", "transform-tty": "^1.0.11", - "tsd": "^0.30.0", - "xo": "^0.56.0" + "tsd": "^0.31.1", + "xo": "^0.59.3" } } diff --git a/readme.md b/readme.md index 169d485..5fa97f5 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,8 @@ npm install ora ``` +*Check out [`yocto-spinner`](https://github.com/sindresorhus/yocto-spinner) for a smaller alternative.* + ## Usage ```js @@ -42,7 +44,7 @@ Type: `object` Type: `string` -Text to display after the spinner. +The text to display next to the spinner. ##### prefixText @@ -61,14 +63,14 @@ Text or a function that returns text to display after the spinner text. No suffi Type: `string | object`\ Default: `'dots'` -Name of one of the [provided spinners](#spinners). See `example.js` in this repo if you want to test out different spinners. On Windows, it will always use the `line` spinner as the Windows command-line doesn't have proper Unicode support. +The name of one of the [provided spinners](#spinners). See `example.js` in this repo if you want to test out different spinners. On Windows (except for Windows Terminal), it will always use the `line` spinner as the Windows command-line doesn't have proper Unicode support. Or an object like: ```js { - interval: 80, // Optional - frames: ['-', '+', '-'] + frames: ['-', '+', '-'], + interval: 80 // Optional } ``` @@ -140,7 +142,7 @@ This has no effect on Windows as there is no good way to implement discarding st #### .text get/set -Change the text after the spinner. +Change the text displayed after the spinner. #### .prefixText get/set @@ -168,7 +170,7 @@ Change the spinner indent. #### .isSpinning get -A boolean of whether the instance is currently spinning. +A boolean indicating whether the instance is currently spinning. #### .interval get @@ -224,17 +226,17 @@ Text to be persisted after the symbol. ###### prefixText -Type: `string`\ +Type: `string | () => string`\ Default: Current `prefixText` -Text to be persisted before the symbol. No prefix text will be displayed if set to an empty string. +Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string. ###### suffixText -Type: `string`\ +Type: `string | () => string`\ Default: Current `suffixText` -Text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string. +Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string. @@ -297,7 +299,7 @@ All [provided spinners](https://github.com/sindresorhus/cli-spinners/blob/main/s ### How do I change the color of the text? -Use [Chalk](https://github.com/chalk/chalk): +Use [`chalk`](https://github.com/chalk/chalk) or [`yoctocolors`](https://github.com/sindresorhus/yoctocolors): ```js import ora from 'ora'; @@ -308,12 +310,15 @@ const spinner = ora(`Loading ${chalk.red('unicorns')}`).start(); ### Why does the spinner freeze? -JavaScript is single-threaded, so synchronous operations blocks the thread, including the spinner animation. Prefer asynchronous operations whenever possible. +JavaScript is single-threaded, so any synchronous operations will block the spinner's animation. To avoid this, prefer using asynchronous operations. ## Related +- [yocto-spinner](https://github.com/sindresorhus/yocto-spinner) - Tiny terminal spinner - [cli-spinners](https://github.com/sindresorhus/cli-spinners) - Spinners for use in the terminal -- [listr](https://github.com/SamVerschueren/listr) - Terminal task list + +**Ports** + - [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinner library for Swift - [halo](https://github.com/ManrajGrover/halo) - Python port - [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust @@ -321,5 +326,4 @@ JavaScript is single-threaded, so synchronous operations blocks the thread, incl - [briandowns/spinner](https://github.com/briandowns/spinner) - Terminal spinner/progress indicator for Go - [tj/go-spin](https://github.com/tj/go-spin) - Terminal spinner package for Go - [observablehq.com/@victordidenko/ora](https://observablehq.com/@victordidenko/ora) - Ora port to Observable notebooks -- [spinnies](https://github.com/jcarpanelli/spinnies) - Terminal multi-spinner library for Node.js - [kia](https://github.com/HarryPeach/kia) - Simple terminal spinners for Deno 🦕 diff --git a/test.js b/test.js index c91dee3..d768f1d 100644 --- a/test.js +++ b/test.js @@ -17,7 +17,7 @@ const getPassThroughStream = () => { return stream; }; -const doSpinner = async (fn, extraOptions = {}) => { +const doSpinner = async (function_, extraOptions = {}) => { const stream = getPassThroughStream(); const output = getStream(stream); @@ -31,14 +31,14 @@ const doSpinner = async (fn, extraOptions = {}) => { }); spinner.start(); - fn(spinner); + function_(spinner); stream.end(); return stripAnsi(await output); }; -const macro = async (t, fn, expected, extraOptions = {}) => { - t.regex(await doSpinner(fn, extraOptions), expected); +const macro = async (t, function_, expected, extraOptions = {}) => { + t.regex(await doSpinner(function_, extraOptions), expected); }; test('main', macro, spinner => {