GithubHelp home page GithubHelp logo

davidkk / ascii-progress Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bubkoo/ascii-progress

0.0 3.0 0.0 379 KB

๐Ÿ“ Ascii progress-bar(s) in the terminal.

License: MIT License

JavaScript 100.00%

ascii-progress's Introduction

ascii-progress

Ascii progress-bar(s) in the terminal.

MIT License Package Quality

Feature:

  • Support multi progress-bars
  • Relative and absolute with
  • Colorful bar and text
  • Highly customizable

snapshot

Install

$ npm install ascii-progress

Usage

For more usage see the examples

var ProgressBar = require('ascii-progress');

var bar = new ProgressBar({ 
    schema: ':bar',
    total : 10 
});

var iv = setInterval(function () {
  bar.tick();
  if (bar.completed) {
    clearInterval(iv);
  }
}, 100);

Options

These are keys in the options object you can pass to the progress bar along with total as seen in the example above.

  • schema - template string of the progress bar. Default " [:bar] :current/:total :percent :elapseds :etas'".
  • total - total number of ticks to complete. Default 100.
  • current- number of completed ticks. Default 0.
  • width - display width, percentage or less than 1 is relative the terminal's width. Default 60.
  • fixedWidth - do not adjust the bar based on the terminal size
  • filled- completion character. Default "โ–‡".
  • blank - blank character. Default "-".
  • clear - clear the progress bar on completion. Default false.
  • callback - optional function to call when the progress bar completes.

Properties

  • schema
  • total
  • current
  • completed

Methods

setSchema(schema, refresh/tokens)

Update the schema of the progress bar. If refresh or tokens is truely the progress bar will be refreshed.

tick(delta, tokens)

Update ticks of the progress bar by delta, then render the progress bar with optional tokens.

update(ratio, tokens)

Update the progress bar to ratio by percentage, then render the progress bar with optional tokens.

clear()

Clean the progress bar in the terminal.

Schema

The schema defines appearance the progress bar. Few inner tokens and many formatting methods can be used to customer you progress bar.

Tokens

These are tokens you can use in the format of your progress bar.

  • :filled Completed part of the progress bar.
  • :blank Blank part of the progress bar.
  • :bar Whole progress bar, equal to :completed:blank.
  • :current Current tick number.
  • :total Total ticks.
  • :percent Completion percentage.
  • :elapsed Time elapsed in seconds.
  • :eta Estimated completion time in seconds.

Custom Tokens

You can define custom tokens by adding a {name: value} object parameter to your method (tick(), update(), etc.) calls.

var bar = new ProgressBar({
    schema: ':current: :token1 :token2',
    total : 3 
});
bar.tick({
  'token1': "Hello",
  'token2': "World!"
})
bar.tick(2, {
  'token1': "Goodbye",
  'token2': "World!"
})

The above example would result in the output below.

1: Hello World!
3: Goodbye World!

Colors

Color names can be use in schema:

:bar.red :percent.green

Then the progress bar will be red, and the percentage will be green.

All available color names:

  • red
  • cyan
  • blue
  • grey
  • white
  • black
  • green
  • yellow
  • magenta
  • brightRed
  • brightBlue
  • brightCyan
  • brightWhite
  • brightBlack
  • brightGreen
  • brightYellow
  • brightMagenta

And with the bg prefix, such as bgRed, the color will be applied to the background.

:bar.red.bgBlue

The above progress bar has blue background and red foreground.

Gradient

:bar.gradient(red,blue)

The arguments can be color names or hex color:

  • red
  • cyan
  • blue
  • grey
  • white
  • black
  • green
  • yellow
  • magenta
  • #xxxxxx

Font style

Same as color names, font style can also be assigned by name:

  • bold
  • italic
  • inverse
  • underline
:bar.red :percent.green.bold

The percentage is green and bold.

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.

ascii-progress's People

Contributors

bubkoo avatar jacobwgillespie avatar legraphista avatar nitin42 avatar rogeriochaves avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.