progress-barjs v2.2.1
Progress barjs
A small library that shows a progress bar
Installation
npm install progress-barjs
Usage
let options = {
info: 'Progress stuff',
total: 30,
};
let bar = Bar(options);
let i = 1;
let timer = setInterval(()=>{
bar.tick('Tick number ' + i);
if (bar.complete) {clearInterval(timer);}
i++;
}, 100);API
Bar([options][,draw])
optionsObject with the following keys:labelProgress bar labelinfoSpecific info about type of data being progressedtotalTotal number of ticks to completeappendIf true show accumulated tick text separated with commashowShow configuration object with the following keys:activeWhich bars items to showdatetrue|falsebartrue|falsepercenttrue|falsecounttrue|falsetimetrue|false
overwriteIf bar should do line overwrite true|falseonly_at_completed_rowsIf bar ony should be written when a row have completed. Good option when each print out generates a new row when bar is written to a file stream (e.g. logfile).dateInclude date before labelcolorANSI color as string
labelObject with the following keys:colorANSI color as string
barObject with the following keys:colorANSI colorlengthbar lengthcompletedcharacter to show fro complete bar tickincompletedcharacter to show fro incompleted bartick_per_progressnumber of tick one progress step represents (only applicable with overwrite=false)
percentObject with the following keys:colorANSI color
countObject with the following keys:colorANSI color
timeObject with the following keys:colorANSI color
tickObject with the following keys:colorANSI color
streamStream to write to (process.stdout default)
drawCustom draw function(bar, stream)=>{ The magic ... )
bar.tick([text])
Increment the bar with one
textText shown at tick.
bar.tickChunk(chunk, [text])
Increment the bar with variable amount
chunkchunk to tick.textshown at tick.
bar.reset()
Reset the progress bar
bar.setTotal(total)
Change total ticks of the progress bar
totalTotal number of ticks
bar.setLabel(label)
Change the label of the progress bar
labelProgress bar label
bar.setInfo(info)
Change the info of the progress bar
infoProgress bar info
bar.defaultFormat(type)
Progress bar components
typeFormat type "percent" | "count" | "time" | "tick" | "bar" | "date" | "info"
Examples
Two in a row:
let options = {
info: 'Progress stuff',
total: 5,
show:{
active:{date:true}}
};
let bar = Bar(options);
let timer= (options, callback) => {
let i = 1;
timer = setInterval(()=>{
bar.tick('Tick number '+i);
if (bar.complete) {
clearInterval(timer);
bar.setInfo('Progress other stuff after reset')
.setTotal(9)
.reset();
}
i++;
}, 100);
};
timer(options, timer)Without overwrite and change of color:
let options = {
info: 'Without overwrite',
total: 36,
show:{
active:{date:true},
overwrite:false,
bar:{
color:'\x1b[0;31m',
completed:'.',
tick_per_progress:2,
length:6
},
percent:{color:'\x1b[1;37m'},
count:{color:'\x1b[0;36m'},
time:{color:'\x1b[0;34m'}
}
};
let bar = Bar(options);
let i=1;
let timer = setInterval(()=>{
bar.tick('Tick number '+i);
if (bar.complete) { clearInterval(timer);}
i++;
}, 100);With custom draw function:
let options = {
label: 'Assume progress bar',
total: 33,
show: {
bar: {
completed: '\x1b[47m \x1b[0;37m',
incompleted: ' ',
}
}
};
let draw=(bar, stream)=>{
let str=util.format(
'\r%s%s | %s | %s%s miliseconds%s ',
'\x1b[0;34m',
bar.label,
bar.defaultFormats('bar'), // pull in default progress bar
bar.show.time.color,
Math.round((new Date().valueOf() - bar.timer)),
'\x1b[0;37m' // end with white
);
stream.write(str); //show
};
let bar = Bar(options, draw);
let i=1;
let timer = setInterval(()=>{
bar.tick('Tick number '+i);
if (bar.complete) {clearInterval(timer);}
i++;
}, 100);
timer(options, timer)Tests
Lab.cmd
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
Release History
- 0.1.0 Initial release
- 0.1.1 fixed username
- 0.1.2 previous bars not overwritten
- 0.1.3 option to show elapsed time
- 0.1.4 fixed screenshot link
- 0.2.0 added setTotal, setLabel and reset methods and removed count print extra space
- 1.0.0 Bar is now created without new, bar progress, new type of bar without overwrite, improved control of bar appearance (color, show/hide information)
- 1.0.1 Small fix
- 1.0.2 Without overwrite bug fix
- 1.1.0 Added custom draw function, tick_per_progress to
option.show.barfor bar without overwrite and deafaultFormat function - 1.1.1 Changed package.json
- 1.1.2 travis + coveralls
- 1.1.3 Example fix
- 1.1.4 Example fix again
- 2.0.0 Change api for draw function, bug fix, circular dependencies when stringify a bar
- 2.0.1 Bug fix
- 2.0.2 Bug fix
- 2.0.3 Bug fix
- 2.1.0 Added function
bar.setInfo(info), added options to show date, introduced info field and bug fixes - 2.1.1 Bug fix
- 2.2.0 Added option show.only_at_completed_rows and function
bar.tickChunk(chunk, [text]) - 2.2.1 Bug fix
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago