Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 25, 2024
1 parent 3c63d5e commit fb0fced
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'
Expand All @@ -46,8 +46,8 @@ export type Options = {
@example
```
{
interval: 80, // Optional
frames: ['-', '+', '-']
frames: ['-', '+', '-'],
interval: 80 // Optional
}
```
*/
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Ora {
#text;
#prefixText;
#suffixText;

color;

constructor(options) {
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
32 changes: 18 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
npm install ora
```

*Check out [`yocto-spinner`](https://github.com/sindresorhus/yocto-spinner) for a smaller alternative.*

## Usage

```js
Expand Down Expand Up @@ -42,7 +44,7 @@ Type: `object`

Type: `string`

Text to display after the spinner.
The text to display next to the spinner.

##### prefixText

Expand All @@ -61,14 +63,14 @@ Text or a function that returns text to display after the spinner text. No suffi
Type: `string | object`\
Default: `'dots'` <img src="screenshot-spinner.gif" width="14">

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
}
```

Expand Down Expand Up @@ -140,7 +142,7 @@ This has no effect on Windows as there is no good way to implement discarding st

#### .text <sup>get/set</sup>

Change the text after the spinner.
Change the text displayed after the spinner.

#### .prefixText <sup>get/set</sup>

Expand Down Expand Up @@ -168,7 +170,7 @@ Change the spinner indent.

#### .isSpinning <sup>get</sup>

A boolean of whether the instance is currently spinning.
A boolean indicating whether the instance is currently spinning.

#### .interval <sup>get</sup>

Expand Down Expand Up @@ -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.

<img src="screenshot-2.gif" width="480">

Expand Down Expand Up @@ -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';
Expand All @@ -308,18 +310,20 @@ 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
- [marquee-ora](https://github.com/joeycozza/marquee-ora) - Scrolling marquee spinner for Ora
- [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 🦕
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 => {
Expand Down

0 comments on commit fb0fced

Please sign in to comment.