Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/node-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -149,19 +149,22 @@ 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);
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)
if (completeLength > 0)
complete = complete.slice(0, -1) + this.chars.head;

/* fill in the actual progress bar */
Expand Down