2.0.2 • Published 4 years ago

@open-tech-world/cli-progress-bar v2.0.2

Weekly downloads
43
License
MIT
Repository
github
Last release
4 years ago

@open-tech-world/cli-progress-bar

Build CodeFactor npm (scoped)

npm.io

Node.js CLI progress bar.

Internally it uses @open-tech-world/es-cli-styles for terminal colors. Refer it for supported colors.

Installation

Using npm

$ npm install @open-tech-world/cli-progress-bar

Using Yarn

$ yarn add @open-tech-world/cli-progress-bar

Usage

import { ProgressBar } from '@open-tech-world/cli-progress-bar';

const pBar = new ProgressBar({ prefix: 'Downloading' });
pBar.run({ value: 0, total: 100 });
pBar.run({ value: 50, total: 100 });
pBar.run({ value: 100, total: 100, prefix: 'Download Completed!' });

API

new ProgressBar(options?: Partial\<IOptions>)

It creates a new instance of the ProgressBar.

options:

NameTypeDefaultDescription
streamNodeJS.WriteStreamprocess.stderrThe stream to use.
widthnumber30The size of the progress bar.
prefixstring''The string to be prefixed progress bar.
suffixstring''The string to be suffixed progress bar.
colorstring'green'The color to render the progress bar. Refer the supported color names here.
autoClearbooleanfalseIf true, then it auto clears the progress bar when it reaches 100%.

Instance methods:

run(options: IRunOptions): void

Runs the current progress bar instance with the given values & options.

options:

NameTypeDefaultRequiredDescription
valuenumberNaNYesThe current value of the progress bar.
totalnumberNaNYesThe total value for the progress bar.
prefixstring''NoThe string to be prefixed progress bar.
suffixstring''NoThe string to be suffixed progress bar.
colorstring'green'NoThe color to render the progress bar. Refer the supported color names here.

stop(clear = false): void

Stops the current progress bar instance with the current state and optionally clears the progress bar.

pBar.stop(); // It just stops the progress bar.

pBar.stop(true); // It stops & removes the progress bar.

License

Copyright (c) 2021, Thanga Ganapathy (MIT License).