cprog
Concurrent fully configurable cli progress bars.
Installation
npm i cprog
Usage
const Progress =
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 = render: Progress stream: processstdout force: false
- render
<function>
- The render function as described below. This options is required. - stream
<tty.WriteStream>
- Optional. The output stream. Default isprocess.stdout
- force
<boolean>
- Iftrue
, this bar will overwrite any other active progress bar. Default isfalse
progress.update(value)
Update the progress.
progress
- value
<number>
- The progress. This should be a value between0
and1
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 theforce
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
{ return 'some text'}
Progress.barWithText(text, options)
Returns a render function that displays a bar with the progress value and additional text.
Progress
- text
<string>
- The text. - options
<object>
- Optional. An object with the following options:- width
<number>
- The number of chars inside the bar. Default is16
- 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.
- width
Note that the color functions take the string to color as argument and return the colored string. chalk contains many compatible coloring functions.