Gathering detailed insights and metrics for cli-progress
Gathering detailed insights and metrics for cli-progress
Gathering detailed insights and metrics for cli-progress
Gathering detailed insights and metrics for cli-progress
⌛ easy to use progress-bar for command-line/terminal applications
npm install cli-progress
Export formatter functions + ETA display limit change
Published on 31 Jan 2021
Custom format functions, autopadding and more
Published on 25 Jan 2020
Minor bugfix
Published on 02 Oct 2019
Align Option; Improved ETA calculation
Published on 11 Aug 2018
Enhanced increment() method
Published on 03 Jan 2018
Custom Payload Data/Tokens
Published on 23 Sept 2017
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,121 Stars
139 Commits
84 Forks
7 Watching
2 Branches
18 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.3%
703,042
Compared to previous day
Last week
2.8%
3,877,326
Compared to previous week
Last month
9.6%
16,105,716
Compared to previous month
Last year
5.6%
191,351,317
Compared to previous year
1
3
Single Bar | Multi Bar | Options | Examples | Presets | Events
easy to use progress-bar for command-line/terminal applications
1$ yarn add cli-progress 2$ npm install cli-progress --save
Multiple examples are available e.g. example.js - just try it $ node example.js
1const cliProgress = require('cli-progress'); 2 3// create a new progress bar instance and use shades_classic theme 4const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); 5 6// start the progress bar with a total value of 200 and start value of 0 7bar1.start(200, 0); 8 9// update the current value in your application.. 10bar1.update(100); 11 12// stop the progress bar 13bar1.stop();
1const cliProgress = require('cli-progress'); 2 3// note: you have to install this dependency manually since it's not required by cli-progress 4const colors = require('ansi-colors'); 5 6// create new progress bar 7const b1 = new cliProgress.SingleBar({ 8 format: 'CLI Progress |' + colors.cyan('{bar}') + '| {percentage}% || {value}/{total} Chunks || Speed: {speed}', 9 barCompleteChar: '\u2588', 10 barIncompleteChar: '\u2591', 11 hideCursor: true 12}); 13 14// initialize the bar - defining payload token "speed" with the default value "N/A" 15b1.start(200, 0, { 16 speed: "N/A" 17}); 18 19// update values 20b1.increment(); 21b1.update(20); 22 23// stop the bar 24b1.stop();
Initialize a new Progress bar. An instance can be used multiple times! it's not required to re-create it!
1const cliProgress = require('cli-progress'); 2 3const <instance> = new cliProgress.SingleBar(options:object [, preset:object]);
Starts the progress bar and set the total and initial value
1<instance>.start(totalValue:int, startValue:int [, payload:object = {}]);
Sets the current progress value and optionally the payload with values of custom tokens as a second parameter. To update payload only, set currentValue to null
.
1<instance>.update([currentValue:int [, payload:object = {}]]); 2 3// update progress without altering value 4<instance>.update([payload:object = {}]);
Increases the current progress value by a specified amount (default +1). Update payload optionally
1<instance>.increment([delta:int [, payload:object = {}]]); 2 3// delta=1 assumed 4<instance>.increment(payload:object = {}]);
Sets the total progress value while progressbar is active. Especially useful handling dynamic tasks.
1<instance>.setTotal(totalValue:int);
Stops the progress bar and go to next line
1<instance>.stop();
Force eta calculation update (long running processes) without altering the progress values.
Note: you may want to increase etaBuffer
size - otherwise it can cause INF
eta values in case the value didn't changed within the time series.
1<instance>.updateETA();
1const cliProgress = require('cli-progress'); 2 3// create new container 4const multibar = new cliProgress.MultiBar({ 5 clearOnComplete: false, 6 hideCursor: true, 7 format: ' {bar} | {filename} | {value}/{total}', 8}, cliProgress.Presets.shades_grey); 9 10// add bars 11const b1 = multibar.create(200, 0); 12const b2 = multibar.create(1000, 0); 13 14// control bars 15b1.increment(); 16b2.update(20, {filename: "test1.txt"}); 17b1.update(20, {filename: "helloworld.txt"}); 18 19// stop all bars 20multibar.stop();
Initialize a new multiprogress container. Bars need to be added. The options/presets are used for each single bar!
1const cliProgress = require('cli-progress'); 2 3const <instance> = new cliProgress.MultiBar(options:object [, preset:object]);
Adds a new progress bar to the container and starts the bar. Returns regular SingleBar
object which can be individually controlled.
Additional barOptions
can be passed directly to the generic-bar to override the global options for a single bar instance. This can be useful to change the appearance of a single bar object. But be patient: this should only be used to override formats - DON'T try to set other global options like the terminal, synchronous flags, etc..
1const <barInstance> = <instance>.create(totalValue:int, startValue:int [, payload:object = {} [, barOptions:object = {}]]);
Removes an existing bar from the multi progress container.
1<instance>.remove(<barInstance>:object);
Stops the all progress bars
1<instance>.stop();
Outputs (buffered) content on top of the multibars during operation.
Notice: newline at the end is required
Example: example-logging.js
1<instance>.log("Hello World\n");
The following options can be changed
format
(type:string|function) - progress bar output format @see format sectionfps
(type:float) - the maximum update rate (default: 10)stream
(type:stream) - output stream to use (default: process.stderr
)stopOnComplete
(type:boolean) - automatically call stop()
when the value reaches the total (default: false)clearOnComplete
(type:boolean) - clear the progress bar on complete / stop()
call (default: false)barsize
(type:int) - the length of the progress bar in chars (default: 40)align
(type:char) - position of the progress bar - 'left' (default), 'right' or 'center'barCompleteChar
(type:char) - character to use as "complete" indicator in the bar (default: "=")barIncompleteChar
(type:char) - character to use as "incomplete" indicator in the bar (default: "-")hideCursor
(type:boolean) - hide the cursor during progress operation; restored on complete (default: false) - pass null
to keep terminal settingslinewrap
(type:boolean) - disable line wrapping (default: false) - pass null
to keep terminal settings; pass true
to add linebreaks automatically (not recommended)gracefulExit
(type:boolean) - stop the bars in case of SIGINT
or SIGTERM
- this restores most cursor settings before exiting (default: false
- subjected to change)etaBuffer
(type:int) - number of updates with which to calculate the eta; higher numbers give a more stable eta (default: 10)etaAsynchronousUpdate
(type:boolean) - trigger an eta calculation update during asynchronous rendering trigger using the current value - should only be used for long running processes in conjunction with lof fps
values and large etaBuffer
(default: false)progressCalculationRelative
(type:boolean) - progress calculation uses startValue
as zero-offset (default: false)synchronousUpdate
(type:boolean) - trigger redraw during update()
in case threshold time x2 is exceeded (default: true) - limited to single bar usagenoTTYOutput
(type:boolean) - enable scheduled output to notty streams - e.g. redirect to files (default: false)notTTYSchedule
(type:int) - set the output schedule/interval for notty output in ms
(default: 2000ms)emptyOnZero
(type:boolean) - display progress bars with 'total' of zero(0) as empty, not full (default: false)forceRedraw
(type:boolean) - trigger redraw on every frame even if progress remains the same; can be useful if progress bar gets overwritten by other concurrent writes to the terminal (default: false)barGlue
(type:string) - a "glue" string between the complete and incomplete bar elements used to insert ascii control sequences for colorization (default: empty) - Note: in case you add visible "glue" characters the barsize will be increased by the length of the glue!autopadding
(type: boolean) - add padding chars to formatted time and percentage to force fixed width (default: false) - Note: handled standard format functions!autopaddingChar
(type: string) - the character sequence used for autopadding (default: " ") - Note: due to performance optimizations this value requires a length of 3 identical charsformatBar
(type: function) - a custom bar formatter function which renders the bar-element (default: format-bar.js)formatTime
(type: function) - a custom timer formatter function which renders the formatted time elements like eta_formatted
and duration-formatted
(default: format-time.js)formatValue
(type: function) - a custom value formatter function which renders all other values (default: format-value.js)The classes extends EventEmitter which allows you to hook into different events.
See event docs for detailed information + examples.
The progressbar can be customized by using the following build-in placeholders. They can be combined in any order.
{bar}
- the progress bar, customizable by the options barsize, barCompleteString and barIncompleteString{percentage}
- the current progress in percent (0-100){total}
- the end value{value}
- the current value set by last update()
call{eta}
- expected time of accomplishment in seconds (limmited to 115days, otherwise INF is displayed){duration}
- elapsed time in seconds{eta_formatted}
- expected time of accomplishment formatted into appropriate units{duration_formatted}
- elapsed time formatted into appropriate units{<payloadKeyName>}
- the payload value identified by its key1const opt = { 2 format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}' 3}
is rendered as
progress [========================================] 100% | ETA: 0s | 200/200
Instead of a "static" format string it is also possible to pass a custom callback function as formatter.
For a full example (including params) take a look on lib/formatter.js
1function formatter(options, params, payload){ 2 3 // bar grows dynamically by current progress - no whitespaces are added 4 const bar = options.barCompleteString.substr(0, Math.round(params.progress*options.barsize)); 5 6 // end value reached ? 7 // change color to green when finished 8 if (params.value >= params.total){ 9 return '# ' + colors.grey(payload.task) + ' ' + colors.green(params.value + '/' + params.total) + ' --[' + bar + ']-- '; 10 }else{ 11 return '# ' + payload.task + ' ' + colors.yellow(params.value + '/' + params.total) + ' --[' + bar + ']-- '; 12 } 13} 14 15const opt = { 16 format: formatter 17}
is rendered as
# Task 1 0/200 --[]--
# Task 1 98/200 --[████████████████████]--
# Task 1 200/200 --[████████████████████████████████████████]--
You can also access the default format functions to use them within your formatter:
1const {TimeFormat, ValueFormat, BarFormat, Formatter} = require('cli-progess').Format; 2...
1// change the progress characters
2// set fps limit to 5
3// change the output stream and barsize
4const bar = new _progress.Bar({
5 barCompleteChar: '#',
6 barIncompleteChar: '.',
7 fps: 5,
8 stream: process.stdout,
9 barsize: 65,
10 position: 'center'
11});
1// uee shades preset
2// change the barsize
3const bar = new _progress.Bar({
4 barsize: 65,
5 position: 'right'
6}, _progress.Presets.shades_grey);
The payload object keys should only contain keys matching standard \w+
regex!
1// create new progress bar with custom token "speed" 2const bar = new _progress.Bar({ 3 format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit' 4}); 5 6// initialize the bar - set payload token "speed" with the default value "N/A" 7bar.start(200, 0, { 8 speed: "N/A" 9}); 10 11// some code/update loop 12// ... 13 14// update bar value. set custom token "speed" to 125 15bar.update(5, { 16 speed: '125' 17}); 18 19// process finished 20bar.stop();
File myPreset.js
1const colors = require('ansi-colors'); 2 3module.exports = { 4 format: colors.red(' {bar}') + ' {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit', 5 barCompleteChar: '\u2588', 6 barIncompleteChar: '\u2591' 7};
Application
1const myPreset = require('./myPreset.js'); 2 3const bar = new _progress.Bar({ 4 barsize: 65 5}, myPreset);
Need a more modern appearance ? cli-progress supports predefined themes via presets. You are welcome to add your custom one :)
But keep in mind that a lot of the "special-chars" rely on Unicode - it might not work as expected on legacy systems.
The following presets are included by default
cli-progress is designed for linux/macOS/container applications which mostly providing standard compliant tty terminals/shells. In non-tty mode it is suitable to be used with logging daemons (cyclic output).
It also works with PowerShell on Windows 10 - the legacy command prompt on outdated Windows versions won't work as expected and is not supported!
Please open a new issue on GitHub
CLI-Progress is OpenSource and licensed under the Terms of The MIT License (X11). You're welcome to contribute!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More