0.2
Another flexible ascii progress bar for deno
Repository
Current version released
4 years ago
deno progress
Usage
First we create a Progressbar, giving it a fmt
string and options || total,
telling it when it will be considered complete. then we will do tick()
import Progressbar from "https://deno.land/x/deno_progress@<version>/mod.ts";
const bar = new Progressbar("|:bar|", { total: 100, width: 50 });
const id = setInterval(() => {
bar.tick(2);
if (bar.complete === true) {
clearInterval(id);
}
}, 100);
Options
curr
current completed indextotal
total number of ticks to completewidth
the displayed width of the progress bar defaulting to totalhead
head character defaulting to complete charactercomplete
completion character defaulting to βββincomplete
incomplete character defaulting to βββrenderThrottle
minimum time between updates in milliseconds defaulting to 16callback
optional function to call when the progress bar completesclear
will clear the progress bar upon termination
Mehods:
tick
tick the progress bar with the givenlength
and optionaltokens
render
render the progress bar with optionaltokens
and optionalforce
interrupt
interrupt the progress bar and write a message above it.terminate
terminates the progress bar
Tokens:
:bar
the progress bar itself:current
current tick number:total
total ticks:elapsed
time elapsed in seconds:percent
completion percentage:eta
eta in seconds:rate
rate of ticks per second
Custom Tokens
You can define custom tokens by adding
{ "name": value }
object parameter to tick()
method
import { Progressbar } from "https://deno.land/x/deno_progress@<version>/mod.ts";
const bar = new Progressbar(":current: :token1 :token2", { total: 3 });
const bar = new Progressbar(":current: :token1 :token2", { total: 3 });
bar.tick({
token1: "Hello",
token2: "World!\n",
});
The above example would result in the result output below:
1: Hello World!
Examples
a simple example
import { Progressbar } from "https://deno.land/x/deno_progress@<version>/mod.ts";
const bar = new Progressbar(" :title |:bar| eta: :eta :percent", {
total: 100,
});
const id = setInterval(() => {
bar.tick(1, { title: "progress " });
if (bar.complete === true) {
clearInterval(id);
}
}, 50);
More examples can be found on the example folder
Credits
Ported from node-progress. Thanks for the work and inspiration!
License
MIT.