Skip to content

alcidesqueiroz/node-loading

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

node-loading Build status

šŸ•¶ Superb loadings for Node console apps.

A set of loading animations for terminal apps written in Node.

Install

With npm:

$ npm install node-loading

With Yarn:

$ yarn add node-loading

Usage

const { DeterminateBar } = require('node-loading');
const loading = DeterminateBar();
loading.start();
loading.message = 'Doing something nice...';

let progress = 0;
const intervalId = setInterval(() => {
  loading.setProgress(++progress);

  if (progress === 50) loading.message = 'Calculating things...';

  if (progress === 100) {
    loading.stop();
    clearInterval(intervalId);
  }
}, 100);

Colors

As shown below, it's possible to define custom colors for both loading animations. Node-loading accepts these colors: black, red, green, yellow, blue, magenta, cyan, white and gray (or grey).

API

Node-loading has two different loading animations: DeterminateBar and IndeterminateBar.

DeterminateBar

A loading bar that goes from 0% to 100% and is ideal for showing that a specific quantity of progress has occurred.

DeterminateBar([options])

options
  • stream: The stream to write the output. Accepted values: STDERR (default) and STDOUT.
  • row: The index of the row where the bar should be rendered.
  • completedColor: The color for the part that represents the completed quantity (default: 'green').
  • remainingColor: The color for the part that represents the remaining quantity (default: 'gray').
  • messageColor: The color for the message (default: the value of completedColor).
  • width: The width (in columns) of the loading animation (default: the full console width).

instance.start()

Starts the animation.

instance.stop()

Stops the animation and clears the line.

instance.setProgress(progress)

Sets the progress (a number between 0 and 100);

instance.message

The message to be shown below the bar.

IndeterminateBar

A loading bar that has no specific amount of progress indicated.

IndeterminateBar([options])

options
  • stream: The stream to write the output. Accepted values: STDERR (default) and STDOUT.
  • row: The index of the row where the bar should be rendered.
  • foregroundColor: The bar foreground color (default: 'cyan').
  • backgroundColor: The bar background color (default: 'gray').
  • messageColor: The color for the message (default: the value of completedColor).
  • width: The width (in columns) of the loading animation (default: the full console width).

instance.start()

Starts the animation.

instance.stop()

Stops the animation and clears the line.

instance.message

The message to be shown below the bar.

instance.speed

A number from 1 to 5 that controls the animation speed.

Author

Alcides Queiroz Aguiar

License

This code is free to use under the terms of the MIT License.

About

šŸ•¶ Superb loadings for Node console apps.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published