progress-barjs
v2.2.1
Published
A customizable progress bar for NodeJS
Downloads
2,117
Maintainers
Readme
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])
options
Object with the following keys:label
Progress bar labelinfo
Specific info about type of data being progressedtotal
Total number of ticks to completeappend
If true show accumulated tick text separated with commashow
Show configuration object with the following keys:active
Which bars items to showdate
true|falsebar
true|falsepercent
true|falsecount
true|falsetime
true|false
overwrite
If bar should do line overwrite true|falseonly_at_completed_rows
If 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).date
Include date before labelcolor
ANSI color as string
label
Object with the following keys:color
ANSI color as string
bar
Object with the following keys:color
ANSI colorlength
bar lengthcompleted
character to show fro complete bar tickincompleted
character to show fro incompleted bartick_per_progress
number of tick one progress step represents (only applicable with overwrite=false)
percent
Object with the following keys:color
ANSI color
count
Object with the following keys:color
ANSI color
time
Object with the following keys:color
ANSI color
tick
Object with the following keys:color
ANSI color
stream
Stream to write to (process.stdout default)
draw
Custom draw function(bar, stream)=>{ The magic ... )
bar.tick([text])
Increment the bar with one
text
Text shown at tick.
bar.tickChunk(chunk, [text])
Increment the bar with variable amount
chunk
chunk to tick.text
shown at tick.
bar.reset()
Reset the progress bar
bar.setTotal(total)
Change total ticks of the progress bar
total
Total number of ticks
bar.setLabel(label)
Change the label of the progress bar
label
Progress bar label
bar.setInfo(info)
Change the info of the progress bar
info
Progress bar info
bar.defaultFormat(type)
Progress bar components
type
Format 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.bar
for 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