Skip to content

Commit

Permalink
Merge pull request #128 from Dineshs91/master
Browse files Browse the repository at this point in the history
Add head option to specify head character
  • Loading branch information
thebigredgeek authored Dec 18, 2016
2 parents e135a3d + 407ce63 commit 191256e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These are keys in the options object you can pass to the progress bar along with
- `total` total number of ticks to complete
- `width` the displayed width of the progress bar defaulting to total
- `stream` the output stream defaulting to stderr
- `head` head character defaulting to complete character
- `complete` completion character defaulting to "="
- `incomplete` incomplete character defaulting to "-"
- `renderThrottle` minimum time between updates in milliseconds defaulting to 16
Expand Down
8 changes: 7 additions & 1 deletion lib/node-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports = module.exports = ProgressBar;
* - `total` total number of ticks to complete
* - `width` the displayed width of the progress bar defaulting to total
* - `stream` the output stream defaulting to stderr
* - `head` head character defaulting to complete character
* - `complete` completion character defaulting to "="
* - `incomplete` incomplete character defaulting to "-"
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
Expand Down Expand Up @@ -61,7 +62,8 @@ function ProgressBar(fmt, options) {
this.clear = options.clear
this.chars = {
complete : options.complete || '=',
incomplete : options.incomplete || '-'
incomplete : options.incomplete || '-',
head : options.head || (options.complete || '=')
};
this.renderThrottle = options.renderThrottle !== 0 ? (options.renderThrottle || 16) : 0;
this.callback = options.callback || function () {};
Expand Down Expand Up @@ -153,6 +155,10 @@ ProgressBar.prototype.render = function (tokens) {
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete);

/* add head to the complete string */
if(completeLength > 0)
complete = complete.slice(0, -1) + this.chars.head;

/* fill in the actual progress bar */
str = str.replace(':bar', complete + incomplete);

Expand Down

0 comments on commit 191256e

Please sign in to comment.