Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.66 KB

progressbar.md

File metadata and controls

54 lines (43 loc) · 1.66 KB

ProgressBar plugin

Features

  • Display progress in a fancy way
  • Easily customizable (width, fill/empty symbols, percents)
  • Clear the bar on complete

Example

const sh = require('kool-shell')

const bar = sh.progressBar({
    // stop rendering and remove the bar when filled
    onComplete(bar) {
        bar.pause()
        console.log('Done!')
    }
})

// display the bar
bar.resume()

// update progress (0: empty / 1: filled)
bar.set(0)
setTimeout(() => bar.set(0.4), 1000)
setTimeout(() => bar.set(0.8), 2000)
setTimeout(() => bar.set(1),   3000)

Usage

const progressBar = sh.progressBar([opts])

Return a new progressBar instance

Options
  • showPercents (Boolean, default true): show or hide progress percentage
  • clearOnPause (Boolean, default true): The bar will be cleared once pause() is called
  • width (Number, default 20) : Set the width of the bar, in chars
  • emptySymbol (String, default ): Symbol used for the empty bar portion
  • fillSymbol (String, default ): Symbol used for the filled bar portion
  • onComplete (Function): Function called when the bar is entirely filled
Methods
  • progressBar.set(progress)
    • Set the progress, from 0 (empty) to 1 (filled)
    • You can set a value without calling resume(). The bar will update its progress without being displayed in the terminal.
  • progressBar.resume()
    • Start rendering the bar
    • Do not write in process.stdout when the bar is rendering, it will cause visual glitches.
  • progressBar.pause()
    • Stop rendering the bar
    • if clearOnPause option is set to true, the bar will be removed from the terminal