Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

spinnies

jcarpanelli430.1kMIT0.5.1TypeScript support: definitely-typed

Create and manage multiple spinners in command-line interface programs

node, nodejs, node.js, multiple, multi, multispinner, spinner, spinners, loadre, loading, loading-bar, cli, console, command-line, command, terminal

readme

spin Spinnies spin

Node.js module to create and manage multiple spinners in command-line interface programs

npm CircleCI standard-readme compliant License: MIT


Installation

$ npm i spinnies

Usage & Example

const spinnies = new Spinnies();

spinnies.add('spinner-1', { text: 'I am a spinner' });
spinnies.add('spinner-2', { text: 'I am another spinner' });

setTimeout(() => {
  spinnies.succeed('spinner-1', { text: 'Success!' });
  spinnies.fail('spinner-2', { text: 'Fail :(' });
}, 2000);

API

This library follows a non-error-throwing philosophy. If you provide an invalid option or an invalid value for a valid option it will be ignored.

Initialization:

new Spinnies([options])

Parameters

  • options - object:

    • color - string: Any valid chalk color. The default value is white.
    • succeedColor - string: Any valid chalk color. The default value is green.
    • failColor - string: Any valid chalk color. The default value is red.
    • spinnerColor - string: Any valid chalk color. The default value is greenBright.
    • succeedPrefix - string: The default value is ✓.
    • failPrefix- string: The default value is ✖.
    • spinner- object:

      • interval - number
      • frames - string[]

      You can see the already provided spinner here.

    • disableSpins - boolean: Disable spins (will still print raw messages).

Note: If you are working in any win32 platform, the default spin animation will be overriden. You can get rid of this defining a different spinner animation manually, or by using the integrated VSCode terminal or Windows Terminal.

Example:

const spinner = { interval: 80, frames: ['🍇', '🍈', '🍉', '🍋'] }
const spinnies = new Spinnies({ color: 'blue', succeedColor: 'green', spinner });

Instance methods:

add(name, [options])

Adds a new spinner with the given name.

Parameters:

  • name - string: spinner reference name.
  • options - object:
    • text: - string: Optional text to show in the spinner. If none is provided, the name field will be shown.
    • indent: - number: Optional, indent the spinner with the given number of spaces.
    • status - string: Initial status of the spinner. Valid statuses are: succeed, fail, spinning, non-spinnableand stopped.
    • color - string: Any valid chalk color.
    • succeedColor - string: Any valid chalk color.
    • failColor - string: Any valid chalk color.

Return value: Returns the spinner's options.

Example:

const spinnies = new Spinnies();
spinnies.add('spinner-1');
spinnies.add('another-spinner', { text: 'Hello, I am a spinner!', color: 'greenBright' });

pick(name)

Picks a spinner.

Parameters:

  • name - string: spinner reference name.

Return value: Returns the spinner's options.

remove(name)

Removes a spinner.

Parameters:

  • name - string: spinner reference name.

Return value: Returns the spinner's options.

update(name, [options])

Updates the spinner with name name with the provided options.

Parameters:

  • name - string: spinner reference name.
  • options - object:
    • text: - string: Optional text to show in the spinner. If none is provided, the name field will be shown.
    • status - string: New status of the spinner. Valid statuses are: succeed, fail, spinning, non-spinnableand stopped.
    • color - string: Any valid chalk color.
    • succeedColor - string: Any valid chalk color.
    • failColor - string: Any valid chalk color.

Return value: Returns the spinner's options.

Example:

const spinnies = new Spinnies();
spinnies.add('spinner-1', { text: 'Hello! I am the initial text', color: 'green' });
// some code
spinnies.update('spinner-1', { text: 'Hello, I am an updated text!', color: 'blue' });

succeed(name, [options])

Sets the specified spinner status as succeed.

Parameters:

  • name - string: spinner reference name.
  • options - object:
    • text: - string: Optional text to show in the spinner. If none is provided, the name field will be shown.
    • succeedColor - string: Any valid chalk color.

Return value: Returns the spinner's options.

Example:

const spinnies = new Spinnies();
spinnies.add('spinner-1', { text: 'Hello! I am the initial text', color: 'green' });
// some code
spinnies.succeed('spinner-1', { text: 'Success!', successColor: 'greenBright' });

fail(name, [options])

Sets the specified spinner status as fail.

Parameters:

  • name - string: spinner reference name.
  • options - object:
    • text: - string: Optional text to show in the spinner. If none is provided, the name field will be shown.
    • failColor - string: Any valid chalk color.

Return value: Returns the spinner's options.

Example:

const spinnies = new Spinnies();
spinnies.add('spinner-1', { text: 'Hello! I am the initial text', color: 'green' });
// some code
spinnies.fail('spinner-1', { text: 'I failed', failColor: 'redBright' });

stopAll([status])

Stops the spinners and sets the non-succeeded and non-failed ones to the provided status, which can be succeed, fail or stopped. You can see an example here.

hasActiveSpinners()

Return value: returns false if all spinners have succeeded, failed or have been stopped.

Contribute

Star it, fork it, improve it, PR it! :raised_hands:.

Acknowledgements

Thanks to chalk for helping making this lib colorful :rainbow: and to ora which was a great inspiration :unicorn:.

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.5.1] - 2019-12-11

Fixed

[0.5.0] - 2019-08-25

Added

[0.4.3] - 2019-07-02

Fixed

[0.4.2] - 2019-06-18

Fixed

  • Fix line breaks when a custom succeedPrefix/failPrefix is provided

[0.4.1] - 2019-06-18

Fixed

  • Properly add line breaks in spinner texts when it has '\n' characters

[0.4.0] - 2019-06-16

Fixed

Added

  • Add succeedPrefix and failPrefix (#8). Thanks @RedDuckss!

Changed

Removed

[0.3.2] - 2019-06-09

Fixed

  • Print last stream without breaking lines manually

[0.3.1] - 2019-06-01

Fixed

[0.3.0] - 2019-05-28

Fixed

  • Fix typo when assigning default spinner for win32 platform.

Added

  • Add status argument to stopAll() method.

[0.2.0] - 2019-05-28

Fixed

  • Fix cursor position in clearStream function.

Added

  • Add new spinner for win32 platform.
  • Add non-tty/CI stream mode.

Removed

  • Remove enter key binds.

[0.1.3] - 2019-05-21

Fixed

  • Fix cursor position jump in stopAll method.

Added

  • Add ability to enable/disable pressing the enter (\n, \r) key through the preventLineBreaks option.

Changed

  • Change package name, description and author info

    [0.1.2] - 2019-05-21

    Fixed

  • Fix cursor position in clearStream function.

[0.1.1] - 2019-05-20

Fixed

  • Forbid the ability to press the enter key and thus move the stdout cursor.

[0.1.0] - 2019-05-20

Added

  • Added CircleCI builds.
  • Added unit tests (~99% coverage).
  • Added stopAll() method to stop all spinning spinners.
  • Added ability to set a spinner efect when constructing the spinner.

Fixed

  • Fix color properties when updating a spinner (with the update, success and fail methods).

Changed

  • Changed MultiSpinner object to a regular class.
  • Changed spinners array to an object.