cprog

Concurrent fully configurable cli progress bars.

Usage no npm install needed!

<script type="module">
  import cprog from 'https://cdn.skypack.dev/cprog';
</script>

README

cprog

Concurrent fully configurable cli progress bars.

Installation

npm i cprog

Usage

const Progress = require('cprog')

new Progress(options)

Create a new progress bar.
If multiple progress bars are active, the first one hides other bars until it is disposed. If other content is written to the output stream, the progress bar will dodge the output without leaving partial output behind.

const progress = new Progress({
    render: Progress.barWithText('Hello World!')
    stream: process.stdout,
    force: false
})
  • render <function> - The render function as described below. This options is required.
  • stream <tty.WriteStream> - Optional. The output stream. Default is process.stdout
  • force <boolean> - If true, this bar will overwrite any other active progress bar. Default is false

progress.update(value)

Update the progress.

progress.update(0.123)
  • value <number> - The progress. This should be a value between 0 and 1

progress.dispose()

Remove the progress bar and make place for other hidden progress bars.

Progress.forceAll

  • forceAll <boolean> - Get or set if all newly created progress bars should overwrite other progress bars. This overwrites the force option.

Render Functions

A render function takes the progress value and the output stream and returns a string.
The output stream parameter can be used to determine the terminal width using output.columns

function render(value, output) {
    return 'some text'
}

Progress.barWithText(text, options)

Returns a render function that displays a bar with the progress value and additional text.

Progress.barWithText('Hello World!', {
    width: 16,
    barChar: '#',
    barCharEmpty: ' ',
    barColor,
    color
})
  • text <string> - The text.
  • options <object> - Optional. An object with the following options:
    • width <number> - The number of chars inside the bar. Default is 16
    • barChar <string> - The char for filled parts of the bar. Default is '#'
    • barCharEmpty <string> - The char for empty parts of the bar. Default is ' '
    • barColor <function> - A function for coloring the bar.
    • color <function> - A function for coloring the text.

Note that the color functions take the string to color as argument and return the colored string. chalk contains many compatible coloring functions.