Skip to content

Commit 191256e

Browse files
Merge pull request #128 from Dineshs91/master
Add head option to specify head character
2 parents e135a3d + 407ce63 commit 191256e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ These are keys in the options object you can pass to the progress bar along with
3434
- `total` total number of ticks to complete
3535
- `width` the displayed width of the progress bar defaulting to total
3636
- `stream` the output stream defaulting to stderr
37+
- `head` head character defaulting to complete character
3738
- `complete` completion character defaulting to "="
3839
- `incomplete` incomplete character defaulting to "-"
3940
- `renderThrottle` minimum time between updates in milliseconds defaulting to 16

lib/node-progress.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports = module.exports = ProgressBar;
2020
* - `total` total number of ticks to complete
2121
* - `width` the displayed width of the progress bar defaulting to total
2222
* - `stream` the output stream defaulting to stderr
23+
* - `head` head character defaulting to complete character
2324
* - `complete` completion character defaulting to "="
2425
* - `incomplete` incomplete character defaulting to "-"
2526
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
@@ -61,7 +62,8 @@ function ProgressBar(fmt, options) {
6162
this.clear = options.clear
6263
this.chars = {
6364
complete : options.complete || '=',
64-
incomplete : options.incomplete || '-'
65+
incomplete : options.incomplete || '-',
66+
head : options.head || (options.complete || '=')
6567
};
6668
this.renderThrottle = options.renderThrottle !== 0 ? (options.renderThrottle || 16) : 0;
6769
this.callback = options.callback || function () {};
@@ -153,6 +155,10 @@ ProgressBar.prototype.render = function (tokens) {
153155
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
154156
incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete);
155157

158+
/* add head to the complete string */
159+
if(completeLength > 0)
160+
complete = complete.slice(0, -1) + this.chars.head;
161+
156162
/* fill in the actual progress bar */
157163
str = str.replace(':bar', complete + incomplete);
158164

0 commit comments

Comments
 (0)