diff --git a/lib/node-progress.js b/lib/node-progress.js index 2b62641..56bcf0a 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -59,7 +59,8 @@ function ProgressBar(fmt, options) { this.curr = options.curr || 0; this.total = options.total; this.width = options.width || this.total; - this.clear = options.clear + this.clear = options.clear; + this.smooth = options.smooth || 0; this.chars = { complete : options.complete || '=', incomplete : options.incomplete || '-', @@ -154,13 +155,37 @@ ProgressBar.prototype.render = function (tokens) { /* 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) - complete = complete.slice(0, -1) + this.chars.head; + if (this.smooth) //smooth overwrites complete,incomplete,head (unicode) + { + completeLength = parseInt(width * ratio); + this.chars.complete = '█'; + this.chars.incomplete = ' '; + + switch (parseInt(((this.curr-(completeLength*(this.total/width)))/((this.total/width)/8)))) + { + case 0: this.chars.head="▏";break; + case 1: this.chars.head="▎";break; + case 2: this.chars.head="▍";break; + case 3: this.chars.head="▌";break; + case 4: this.chars.head="▋";break; + case 5: this.chars.head="▊";break; + case 6: this.chars.head="▉";break; + case 7: this.chars.head="█";break; + } + complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete); + incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete); + + complete += this.chars.head; + } else + { + 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);