ascii-bar

Why is it cool?
- 🚀 Extreme lightweight (<50kB) and zero dependencies
- ⭕ Fancy Spinners (automatic ascii fallback for windows)
- 🎨 Colors and Emoji support (if your terminal can display this)
- 🖋️ Intuitive styling via templateString
- ⏰ Calculation and pretty printing of overall progress time and time to finish
- 🔧 Extreme customizable (configure output stream, timing calculation, spinner behavior,...)
- 📖 Typescript types and documentation
How to use
Installation
npm install ascii-bar
Basic Usage
const AsciiBar = require('ascii-bar').default;
const bar = new AsciiBar();
bar.update(numberOfDoneThings,someInfoAboutCurrentTask);
Using with import
import AsciiBar from 'ascii-bar'
For more examples see examples folder.
Configuration
Template string
The templateString
has the greatest influence on the appearance. It allows you to define which elements your status bar contains and how they are arranged.
To use a special templateString
use it as a parameter in the constructor:
const bar = new AsciiBar('#spinner #percent #bar Overall time: #overall ##blue #message');
You can use and mix the following placeholders and modificators:
#bar | The visualized progress bar | [>>>>>>>>------] |
#count | Count of done tasks and total tasks | [12/42] |
#percent | Percentage of done tasks | 30% |
#overall | Estimated overall time | 1h 12m |
#elapsed | Elapsed time | 1d 2h 34m |
#ttf | Estimated time to finish | 34m 13s |
#message | Information about the current task | Uploading dummy.txt |
#spinner | A spinner | ⠼ |
##default | Reset text formatting | default text |
##green | green text | green text |
##blue | blue text | blue text |
##red | red text | red text |
##yellow | yellow text | yellow text |
##bright | bright text | bright blue text |
##dim | dimmed text | dimmed green text |
Options
You can also use a configuration object in the constructor:
const bar = new AsciiBar({
undoneSymbol: "-",
doneSymbol: ">",
width: 20,
formatString: '#percent #bar',
total: 100,
enableSpinner: false,
lastUpdateForTiming: false,
autoStop : true,
print: true,
start: 0,
startDate: new Date().getTime(),
stream: process.stdout,
hideCursor: false,
});
For more detailed explanation off all these options have a look at the AsciiBar.d.ts
Spinner

Use a spinner
To use a spinner simply set the enableSpinner
option to true
.
Also use the #spinner
placeholder in your template string.
Minimal example:
const bar = new AsciiBar({
formatString: '#spinner #percent #bar',
enableSpinner: true
});
Modify spinner
You can also set a custom spinner
For more spinner inspiration see cli-spinners
bar.spinner = {
interval: 100,
frames: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
}
API Methods and properties
Methods
bar.update(current: number, message?: string)
bar.renderLine(): string
bar.stop(withInfo = true)
Properties
All of this properties can be changed (even while the progressbar is running).
E.g. to set a new message text do:
bar.message = "SomeNewText";
public formatString = '#percent #bar';
public total = 100;
public startDate = new Date().getTime();
public lastUpdateForTiming = false;
public width = 20;
public doneSymbol = ">";
public undoneSymbol = "-";
public print = true;
public spinner = defaultSpinner;
public message = "";
public autoStop = true;
hideCursor?: boolean;