Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
@sidneys/cli-progress
Advanced tools
Easy to use Progress-Bar for Command-Line/Terminal Applications
Easy to use Progress-Bar for Command-Line/Terminal Applications
$ npm install cli-progress --save
$ yarn add cli-progress --save
Multiple examples are available e.g. example.js - just try it $ node example.js
const _cliProgress = require('cli-progress');
// create a new progress bar instance and use shades_classic theme
const bar1 = new _cliProgress.Bar({}, _cliProgress.Presets.shades_classic);
// start the progress bar with a total value of 200 and start value of 0
bar1.start(200, 0);
// update the current value in your application..
bar1.update(100);
// stop the progress bar
bar1.stop();
Initialize a new Progress bar. An instance can be used multiple times! it's not required to re-create it!
const <instance> = new namespace.Bar(options:object [, preset:object]);
format
(type:string) - 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'barCompleteString
(type:char) - character to use as "complete" indicator in the bar (default: "=")barIncompleteString
(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)etaBuffer
(type:int) - number of updates with which to calculate the eta; higher numbers give a more stable eta (default: 10)Starts the progress bar and set the total and initial value
<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
<instance>.update(currentValue:int [, payload:object = {}]);
Increases the current progress value by a specified amount (default +1). Update payload optionally
<instance>.increment([delta:int [, payload:object = {}]]);
Sets the total progress value while progressbar is active. Especially useful handling dynamic tasks.
<instance>.setTotal(totalValue:int);
Stops the progress bar and go to next line
<instance>.stop();
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{duration}
- elapsed time in seconds{eta_formatted}
- expected time of accomplishment formatted into appropriate units{duration_formatted}
- elapsed time formatted into appropriate unitsprogress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}
is rendered as
progress [========================================] 100% | ETA: 0s | 200/200
// change the progress characters
// set fps limit to 5
// change the output stream and barsize
const bar = new _progress.Bar({
barCompleteChar: '#',
barIncompleteChar: '.',
fps: 5,
stream: process.stdout,
barsize: 65,
position: 'center'
});
// uee shades preset
// change the barsize
const bar = new _progress.Bar({
barsize: 65,
position: 'right'
}, _progress.Presets.shades_grey);
// create new progress bar with custom token "speed"
const bar = new _progress.Bar({
format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit'
});
// initialize the bar - set payload token "speed" with the default value "N/A"
bar.start(200, 0, {
speed: "N/A"
});
// some code/update loop
// ...
// update bar value. set custom token "speed" to 125
bar.update(5, {
speed: '125'
});
// process finished
bar.stop();
File mypreset.js
const _colors = require('colors');
module.exports = {
format: _colors.red(' {bar}') + ' {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591'
};
Application
const _mypreset = require('./mypreset.js');
const bar = new _progress.Bar({
barsize: 65
}, _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
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!
2.1.0 ###
align
option to change the position of the progress bar (left, center, right) - thanks to sidneys on GitHub #22Infinity
is displayed as INF, NaN
as NULL - feature requested by AxelTerizaki on GitHub #21100000s
(INF is displayed in this case)example-notty.php
was brokenFAQs
Easy to use Progress-Bar for Command-Line/Terminal Applications
We found that @sidneys/cli-progress demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.