0.0.1 • Published 3 months ago

@khaidev1012/cli-pbar v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@opentf/cli-pbar

⚡ by OPEN TECH FOUNDATION

Build

npm.io

CLI progress bar.

Features

  • Single & Multi progress bar

  • Custom bar colors

  • Multiple sizes

Installation

npm install cli-pbar
yarn add cli-pbar
pnpm add cli-pbar

Syntax

new ProgressBar(options?: Options)

Usage

Single progress bar.

import { ProgressBar } from 'cli-pbar';

const pBar = new ProgressBar();
pBar.start({ total: 100 });
pBar.update({ value: 50 });
pBar.update({ value: 100 });
pBar.stop();

Multi progress bar.

import { ProgressBar } from 'cli-pbar';

const multiPBar = new ProgressBar();
multiPBar.start();
const b1 = multiPBar.add({ total: 100 });
const b2 = multiPBar.add({ total: 100 });
const b3 = multiPBar.add({ total: 100 });
b1.update({ value: 23 });
b3.update({ value: 35 });
b2.update({ value: 17 });
multiPBar.stop();

API

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'g'The color to render the completed progress bar.The default color is green. It uses @opentf/cli-styles for colors.You can also use the rgb & hex color modes, please refer the supported color keys here.
bgColorstring'gr'The color to render the incomplete progress bar.The default color is grey. It uses @opentf/cli-styles for colors.You can also use the rgb & hex color modes, please refer the supported color keys here.
sizestring'DEFAULT'The size of the progress bar to render.Available sizes:'DEFAULT''MEDIUM''SMALL'
autoClearbooleanfalseIf true, then it auto-clears the progress bar after the stop method is called.

Instance methods:

start(obj?: Partial<Bar>): void

After the method is called, the progress bar starts rendering.

Bar:

NameTypeDefaultDescription
totalnumberNaNThe total value for the progress bar.
valuenumberNaNThe current value of the progress bar.
prefixstring''The string to be prefixed progress bar.
suffixstring''The string to be suffixed progress bar.
colorstring'g'The color to render the completed progress bar.The default color is green. It uses @opentf/cli-styles for colors.You can also use the rgb & hex color modes, please refer the supported color keys here.
bgColorstring'gr'The color to render the incomplete progress bar.The default color is grey. It uses @opentf/cli-styles for colors.You can also use the rgb & hex color modes, please refer the supported color keys here.
sizestring'DEFAULT'The size of the progress bar.Available sizes:'DEFAULT''MEDIUM''SMALL'
progressbooleantrueIf false, it does not render a progress bar, making it useful to add an empty line or text without displaying a progress bar.

add(obj: Partial<Bar>): { update: (obj: Partial<Bar>) => void }

In multi-progress bars, it appends a progress bar to the container and returns an object with a method to update it.

update(obj: Partial<Bar>): void

In updates the current progress bar instance.

stop(msg?: string): void

Stops the current progress bar instance with the current state and optionally clears the progress bar when autoClear is true.

You can also pass msg text to be displayed after the instance stops.

Related

License

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