@mpen/progressbar
v0.1.10
Published
Terminal progress bar utilities.
Readme
@mpen/progressbar
Terminal progress bar utilities.
Usage
import { setTimeout } from 'node:timers/promises'
import ProgressBar from '@mpen/progressbar'
const progress = new ProgressBar({ max: 100 })
for (let i = 0; i < 100; ++i) {
await setTimeout(25) // Replace with your actual work.
progress.tick()
}
progress.complete()The bar starts immediately and writes to stdout. Call tick() after each item,
tick(count) after a batch, or update(count) to set the absolute completed count.
Call complete() to render 100% and finish with a newline.
Customization
import ProgressBar, { ProgressBarPartialBlocks } from '@mpen/progressbar'
const progress = new ProgressBar({
max: 100,
width: 40,
fps: 30,
partialBlocks: ProgressBarPartialBlocks.shades,
emptyBlock: '·',
enableColors: false,
start: false,
})
progress.start()
progress.update(25)
progress.logLine('Finished the first batch')
progress.tick(75)
progress.complete()Use logLine() to write messages above the active bar. If work stops early, call
interrupt() to render the current progress and finish with a newline.
After complete() has been called, interrupt() does nothing, so it is safe to
call in a finally block without changing successful output.
