ascii-progress

Ascii progress-bar(s) in the terminal.

README

ascii-progress

Ascii progress-bar(s) in the terminal.

MIT LicenseLanguagePRs Welcome


Features:

- Support multi progress-bars.
- Relative and absolute width.
- Colorful bar and text.
- Highly customizable.


snapshot


Install


  1. ```
  2. $ npm install ascii-progress
  3. ```

Usage


For more usage see the examples


  1. ```javascript
  2. const { ProgressBar } = require('ascii-progress');

  3. const bar = new ProgressBar({
  4.     schema: ':bar',
  5.     total : 10,
  6. });

  7. const iv = setInterval(function () {
  8.   bar.tick();
  9.   if (bar.completed) {
  10.     clearInterval(iv);
  11.   }
  12. }, 100);
  13. ```


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 "-".
- clean - 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.

  1. ```javascript
  2. const bar = new ProgressBar({
  3.     schema: ':current: :token1 :token2',
  4.     total : 3,
  5. });
  6. bar.tick({
  7.   'token1': "Hello",
  8.   'token2': "World!"
  9. })
  10. bar.tick(2, {
  11.   'token1': "Goodbye",
  12.   'token2': "World!"
  13. })
  14. ```

The above example would result in the output below.

  1. ```
  2. 1: Hello World!
  3. 3: Goodbye World!
  4. ```

Colors


Color names can be use in schema:

  1. ```
  2. :bar.red :percent.green
  3. ```

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.

  1. ```
  2. :bar.red.bgBlue
  3. ```

The above progress bar has blue background and red foreground.

Gradient


  1. ```
  2. :bar.gradient(red,blue)
  3. ```

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

  1. ```
  2. :bar.red :percent.green.bold
  3. ```

The percentage is green and bold.


Contributing


Please let us know how can we help. Do check out issues for bug reports or suggestions first.

To become a contributor, please follow our contributing guide.

Contributors


License


The scripts and documentation in this project are released under the MIT License