Skip to content

Commit 7605d2c

Browse files
committed
allowed 0 (zero) value for total/progress initialization #11
1 parent ccce482 commit 7605d2c

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ gfx/*
66
PublicHtml/*
77
node_modules*
88
.tmp*
9-
intern_*
9+
intern_*
10+
dev.js

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.5.0 ###
2+
* Added: **0** values for total/progress initialization are allowed - feature requested by [jfmmm on GitHub](https://github.com/AndiDittrich/Node.CLI-Progress/issues/11) #11
3+
14
### 1.4.0 ###
25
* Added: **Preset/Theme support**. Different bar-styles can be loaded from internal library (in addition to full customization)
36
* Added: Dependency **colors** for colorized progress bars

lib/Bar.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Bar.prototype.render = function(){
7171
var s = this.format;
7272

7373
// calculate the normalized current progress
74-
var progress = this.value/this.total;
74+
// handle NaN Errors
75+
var progress = (this.value/this.total) || 1.0;
7576

7677
// limiter
7778
progress = Math.min(Math.max(progress, 0.0), 1.0);
@@ -150,7 +151,8 @@ Bar.prototype.formatTime = function (t, roundTo) {
150151
Bar.prototype.start = function(total, startValue){
151152
// set initial values
152153
this.value = startValue || 0;
153-
this.total = total || 100;
154+
this.total = (typeof total !== 'undefined' && total >= 0) ? total : 100;
155+
154156
this.startTime = Date.now();
155157
this.lastDrawnString = '';
156158

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cli-progress",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"description": "Easy to use Progress-Bar for Command-Line/Terminal Applications",
55
"keywords": [
66
"cli",

0 commit comments

Comments
 (0)