diff --git a/lib/node-progress.js b/lib/node-progress.js index 8eb0740..43a0954 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -80,7 +80,7 @@ function ProgressBar(fmt, options) { * @api public */ -ProgressBar.prototype.tick = function(len, tokens){ +ProgressBar.prototype.tick = function(len, tokens) { if (len !== 0) len = len || 1; @@ -149,11 +149,14 @@ ProgressBar.prototype.render = function (tokens, force) { /* compute the available space (non-zero) for the bar */ var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length); - if(availableSpace && process.platform === 'win32'){ + + if (availableSpace && process.platform === 'win32') { availableSpace = availableSpace - 1; } - var width = Math.min(this.width, availableSpace); + var width = typeof(this.width) === 'number' + ? Math.min(this.width, availableSpace) + : availableSpace; /* TODO: the following assumes the user has one ':bar' token */ completeLength = Math.round(width * ratio); @@ -161,7 +164,7 @@ ProgressBar.prototype.render = function (tokens, force) { incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete); /* add head to the complete string */ - if(completeLength > 0) + if (completeLength > 0) complete = complete.slice(0, -1) + this.chars.head; /* fill in the actual progress bar */