Skip to content

lahmatiy/multibar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multibar

NPM version Build Status

Simple and robust terminal's progress bar with multiple instance support.

Features:

  • Simple and robust
  • Multiple progress bar at once
  • Supports ANSI styled strings in labels (e.g. styled with chalk)

Install

npm install multibar

Usage

var chalk = require('chalk');
var multibar = require('multibar');

function createProgressBar(name, freq) {
    var bar = multibar(name, chalk.gray('awaiting...'));
    var count = 0;
    var timer = setInterval(function() {
        if (count < 100) {
            count += 5;
            bar.update(count / 100, chalk.yellow(count + '%'));
        } else {
            bar.done(chalk.green('OK'));
            clearInterval(timer);
        }
    }, freq);
}

for (var i = 0; i < 3; i++) {
    createProgressBar('#' + (i + 1), parseInt(250 * Math.random()));
}

Example in action:

multibar-demo

API

multibar(prelude, message, options);

All agruments are optional. Returns a bar instance with method:

  • update(progress, message)

    Update bar progress and message. Parameters:

    • progress should be a number in range [0..1]
    • message – any string to output on right side of bar
  • done(message)

    Finalize bar progress (hide progress bar, prelude and message are left).

    • message any string

Options:

  • complete

    Type: String
    Default: depends on platform and chalk enabled

    Character for fill a completion progress.

  • incomplete

    Type: String
    Default: depends on platform and chalk enabled

    Character for fill rest of progress.

Useful packages

  • chalk – Terminal string styling done right
  • fixed-width-string – Terminal ANSI-aware string fit to fixed width

License

MIT

About

Simple and robust terminal's progress bar with multiple instance support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published