Spinnies
Node.js module to create and manage multiple spinners in command-line interface programs
Installation
$ npm i spinnies
Usage & Example
const spinnies = ; spinnies;spinnies; ;
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 iswhite
. -
succeedColor -
string
: Any valid chalk color. The default value isgreen
. -
failColor -
string
: Any valid chalk color. The default value isred
. -
spinnerColor -
string
: Any valid chalk color. The default value isgreenBright
. -
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.
- interval -
-
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 = 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, thename
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-spinnable
andstopped
. - color -
string
: Any valid chalk color. - succeedColor -
string
: Any valid chalk color. - failColor -
string
: Any valid chalk color.
- text: -
Return value: Returns the spinner's options.
Example:
const spinnies = ;spinnies;spinnies;
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, thename
field will be shown. - status -
string
: New status of the spinner. Valid statuses are:succeed
,fail
,spinning
,non-spinnable
andstopped
. - color -
string
: Any valid chalk color. - succeedColor -
string
: Any valid chalk color. - failColor -
string
: Any valid chalk color.
- text: -
Return value: Returns the spinner's options.
Example:
const spinnies = ;spinnies;// some codespinnies;
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, thename
field will be shown. - succeedColor -
string
: Any valid chalk color.
- text: -
Return value: Returns the spinner's options.
Example:
const spinnies = ;spinnies;// some codespinnies;
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, thename
field will be shown. - failColor -
string
: Any valid chalk color.
- text: -
Return value: Returns the spinner's options.
Example:
const spinnies = ;spinnies;// some codespinnies;
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 🦄.