UNPKG

simp-bar

Version:

use cli-progress module simpler

35 lines (33 loc) 1.11 kB
const cliProgress = require('cli-progress'); class Bar { constructor(total, current = 0, { format = 'Progress | {bar} {percentage}% | {value}/{total}', presets = 'shades_gray', barCompleteChar = '\u2588', barIncompleteChar = '\u2591', stopOnComplete = true, hideCursor = false, } = {}) { this.bar = new cliProgress.SingleBar({ format: format, barCompleteChar: barCompleteChar, barIncompleteChar: barIncompleteChar, stopOnComplete: stopOnComplete, hideCursor: hideCursor, }, cliProgress.Presets[presets]); this.bar.start(total, current); this.stopOnComplete = stopOnComplete; } set(current) { this.bar.update(current); if (this.stopOnComplete && this.bar.value >= this.bar.total) this.stop(); } increment() { this.bar.increment(); if (this.stopOnComplete && this.bar.value >= this.bar.total) this.stop(); } stop() { this.bar.stop(); } } module.exports = Bar;