Code Monkey home page Code Monkey logo

spinnies's Introduction

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! ๐Ÿ™Œ.

Acknowledgements

Thanks to chalk for helping making this lib colorful ๐ŸŒˆ and to ora which was a great inspiration ๐Ÿฆ„.

License

MIT

spinnies's People

Contributors

jbcarpanelli avatar dependabot[bot] avatar jonbarrow avatar mloughry avatar noriyotcp avatar rap2hpoutre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.