• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

ascii-progress

Ascii progress-bar(s) in the terminal.

MIT License Language PRs Welcome

Features:

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

snapshot

Install

$ npm install ascii-progress

Usage

For more usage see the examples

const { ProgressBar } = require('ascii-progress');

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

const 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 "-".
  • 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.

const 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

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

More Repositories

1

html-to-image

βœ‚οΈ Generates an image from a DOM node using HTML5 canvas and SVG.
TypeScript
5,680
star
2

hexo-filter-flowchart

Generate flowchart diagrams for Hexo.
JavaScript
122
star
3

hexo-toc

πŸ“– Insert a markdown TOC before posts be rendered.
JavaScript
121
star
4

natsort

🌴 Javascript natural sort algorithm with unicode support.
TypeScript
74
star
5

logo.svg

Generate a svg logo, then you can embed it in you README.
JavaScript
48
star
6

grunt-restful-mock

πŸš€ A mock server returning random JSON-data.
JavaScript
42
star
7

hexo-theme-formula

πŸ‘™ Hexo theme base on jade and less.
JavaScript
40
star
8

hexo-filter-sequence

Generate UML sequence diagrams for Hexo.
JavaScript
39
star
9

text2svg

πŸ„ Convert text to svg path.
JavaScript
29
star
10

get-cursor-position

🐾 Get the cursor's current position in your terminal.
C++
27
star
11

hexo-filter-fenced-code

🎨 Extend syntax for the native fenced code block.
JavaScript
18
star
12

global-proxy

Set system proxy for mac and windows platform.
TypeScript
14
star
13

run-shared-scripts

Define and run shared npm scripts of a monorepo using Yarn workspaces, Bolt, Lerna or pnpm
JavaScript
14
star
14

grunt-file-hash

πŸ‘Ύ Generate hashed mapping for your static files.
JavaScript
10
star
15

ansi.js

ansi escape sequences for terminal cursor positioning and coloring.
TypeScript
8
star
16

number-abbreviate

🎱 Abbreviate number to a more human-friendly format (3.6K, 6.8M, etc.)
TypeScript
8
star
17

vscode-action-buttons

A vscode plugin to append action buttons in the status bar.
TypeScript
6
star
18

ocr.it

⏰ A tool to recognize text from images.
TypeScript
6
star
19

configs

Shared configs for my projects
JavaScript
6
star
20

electron-tray-indicator

πŸ“A progress indicator in tray for your Electron app.
TypeScript
5
star
21

coder-calendar

η¨‹εΊε‘˜ηš„θ€ι»„εŽ†
TypeScript
5
star
22

dataurl-to-blob

Convert the given dataURL to a Blob.
JavaScript
5
star
23

awesome-badge-list

πŸ‘“ A collection awesome badges.
5
star
24

spelling-suggestion

Given a name and a list of names that are not equal to the name, return a spelling suggestion if there is one that is close enough.
TypeScript
3
star
25

fetch-client

A convenient fetch client with middleware support.
JavaScript
3
star
26

moment

Moment is a Menu Bar and Notification Center based countdown app to help you remember the most memorable days of your life.
3
star
27

global-proxy-cli

Set system proxy for mac and windows platform.
JavaScript
3
star
28

bot

A GitHub App for me.
TypeScript
3
star
29

licen

Generate license files for your projects.
JavaScript
3
star
30

find-monorepo-root

Find the root directory of a monorepo using Yarn workspaces, Bolt, Lerna or pnpm
TypeScript
3
star
31

bubkoo.com

JavaScript
3
star
32

grunt-underscore-compiler

Compile underscore templates into JavaScript files.
JavaScript
3
star
33

semantic-release-monorepo

Apply semantic-release's automatic publishing to a monorepo.
TypeScript
3
star
34

bubkoo

πŸ€Ήβ€β™€οΈ
3
star
35

365dots

Presenting the time progress of a year.
TypeScript
2
star
36

daily-saying

Fetch a daily saying from iciba.com and output it
JavaScript
2
star
37

position-sticky-polyfill

position: sticky; The shim/polyfill!
JavaScript
2
star
38

bubkoo.github.com

bubkoo's blog. Welcome
HTML
2
star
39

boxup

Wrap content with a box in the terminal
JavaScript
2
star
40

reusable-workflows

2
star
41

hexo-theme-flight

Hexo's theme for bubkoo's blog
JavaScript
2
star
42

hexo-filter-sub

Generate subscript (<sub>) tag for Hexo.
JavaScript
1
star
43

boxup-preset

Some presets for boxup.
JavaScript
1
star
44

loadrc

Load runtime configuration files for your module.
JavaScript
1
star
45

toolbox

dotfiles, scripts, etc.
Shell
1
star
46

cert-generator

Generate a root certificate.
JavaScript
1
star
47

semantic-release-config

1
star
48

rsw-b

JavaScript
1
star
49

break-string

Break string into lines according to visual width
JavaScript
1
star
50

on-new-line

Hijacks NodeJS Stream and emits events when newline(s) written to the output.
JavaScript
1
star
51

boxup-cli

Create boxes in the terminal
JavaScript
1
star
52

regexper

Regular expression visualizer using railroad diagrams.
TypeScript
1
star