Skip to content

Commit 66495c5

Browse files
author
Christoffer Hallas
committed
Merge pull request #58 from visionmedia/no-readline
bump to version 1.1.5, added missing changelogs, make now runs all examples, removed readline dependency and a little ocd
2 parents 4c5374f + 70c30e3 commit 66495c5

File tree

4 files changed

+87
-79
lines changed

4 files changed

+87
-79
lines changed

History.md

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,67 @@
1+
### 1.1.5 / 2014-03-25
12

2-
1.0.0 / 2013-06-18
3-
==================
3+
* updated documentation and various other repo maintenance
4+
* updated makefile to run examples with `make`
5+
* removed dependency on readline module
46

5-
* remove .version
6-
* >=. Closes #19
7-
* Merge pull request #15 from davglass/readline-osx
8-
* On OSX revert back to terminal hack to avoid a readline bug
7+
### 1.1.4 / 2014-03-14
98

10-
0.1.0 / 2012-09-19
11-
==================
9+
* now supports streams, for example output progress bar to stderr, while piping
10+
stdout
11+
* increases performance and flicker by remembering the last drawn progress bar
1212

13-
* Fixed logic bug that caused bar to jump one extra space at the end [davglass]
14-
* Working with readline impl, even on Windows [davglass]
15-
* Using readline instead of the \r hack [davglass]
13+
### 1.1.3 / 2013-12-31
1614

17-
0.0.5 / 2012-08-07
18-
==================
15+
* fixes a bug where bar would bug when initializing
16+
* allows to pass updated tokens when ticking or updating the bar
17+
* fixes a bug where the bar would throw if skipping to far
18+
19+
### 1.1.2 / 2013-10-17
20+
21+
* lets you pass an `fmt` and a `total` instead of an options object
22+
23+
### 1.1.0 / 2013-09-18
24+
25+
* eta and elapsed tokens default to 0.0 instead of ?.?
26+
* better JSDocs
27+
* added back and forth example
28+
* added method to update the progress bar to a specific percentage
29+
* added an option to hide the bar on completion
30+
31+
### 1.0.1 / 2013-08-07
32+
33+
* on os x readline now works, reverting the terminal hack
34+
35+
### 1.0.0 / 2013-06-18
36+
37+
* remove .version
38+
* merge pull request #15 from davglass/readline-osx
39+
* on OSX revert back to terminal hack to avoid a readline bug
40+
41+
### 0.1.0 / 2012-09-19
42+
43+
* fixed logic bug that caused bar to jump one extra space at the end [davglass]
44+
* working with readline impl, even on Windows [davglass]
45+
* using readline instead of the \r hack [davglass]
46+
47+
### 0.0.5 / 2012-08-07
1948

2049
* add ability to tick by zero chunks - tick(0)
2150
* fix ETA. Closes #4 [lwille]
2251

23-
0.0.4 / 2011-11-14
24-
==================
52+
### 0.0.4 / 2011-11-14
2553

26-
* Allow more recent versions of node
54+
* allow more recent versions of node
2755

28-
0.0.3 / 2011-04-20
29-
==================
56+
### 0.0.3 / 2011-04-20
3057

31-
* Changed; erase the line when complete
58+
* changed; erase the line when complete
3259

33-
0.0.2 / 2011-04-20
34-
==================
60+
### 0.0.2 / 2011-04-20
3561

36-
* Added custom tokens support
37-
* Fixed; clear line before writing
62+
* added custom tokens support
63+
* fixed; clear line before writing
3864

39-
0.0.1 / 2010-01-03
40-
==================
65+
### 0.0.1 / 2010-01-03
4166

42-
* Initial release
67+
* initial release

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Flexible CLI ASCII progress bar for Node.js.
1+
Flexible ascii progress bar.
22

33
## Installation
44

lib/node-progress.js

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
exports = module.exports = ProgressBar;
1212

1313
/**
14-
* Initialize a `ProgressBar` with the given
15-
* `fmt` string and `options` or `total`.
14+
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
15+
* `total`.
1616
*
1717
* Options:
1818
*
@@ -22,6 +22,7 @@ exports = module.exports = ProgressBar;
2222
* - `complete` completion character defaulting to "="
2323
* - `incomplete` incomplete character defaulting to "-"
2424
* - `callback` optional function to call when the progress bar completes
25+
* - `clear` will clear the progress bar upon termination
2526
*
2627
* Tokens:
2728
*
@@ -32,21 +33,13 @@ exports = module.exports = ProgressBar;
3233
* - `:percent` completion percentage
3334
* - `:eta` eta in seconds
3435
*
35-
* @param {String} fmt
36-
* @param {Object|Number} options or total
36+
* @param {string} fmt
37+
* @param {object|number} options or total
3738
* @api public
3839
*/
3940

4041
function ProgressBar(fmt, options) {
4142
this.stream = options.stream || process.stderr;
42-
this.rl = require('readline').createInterface({
43-
input: process.stdin,
44-
output: this.stream
45-
});
46-
this.rl.setPrompt('', 0);
47-
this.rl.clearLine = function() {
48-
this.write(null, {ctrl: true, name: 'u'});
49-
};
5043

5144
if (typeof(options) == 'number') {
5245
var total = options;
@@ -64,19 +57,18 @@ function ProgressBar(fmt, options) {
6457
this.width = options.width || this.total;
6558
this.clear = options.clear
6659
this.chars = {
67-
complete: options.complete || '='
68-
, incomplete: options.incomplete || '-'
60+
complete : options.complete || '=',
61+
incomplete : options.incomplete || '-'
6962
};
7063
this.callback = options.callback || function () {};
7164
this.lastDraw = '';
7265
}
7366

7467
/**
75-
* "tick" the progress bar with optional `len` and
76-
* optional `tokens`.
68+
* "tick" the progress bar with optional `len` and optional `tokens`.
7769
*
78-
* @param {Number|Object} len or tokens
79-
* @param {Object} tokens
70+
* @param {number|object} len or tokens
71+
* @param {object} tokens
8072
* @api public
8173
*/
8274

@@ -103,26 +95,24 @@ ProgressBar.prototype.tick = function(len, tokens){
10395
};
10496

10597
/**
106-
* Method to render the progress bar with optional `tokens` to
107-
* place in the progress bar's `fmt` field.
98+
* Method to render the progress bar with optional `tokens` to place in the
99+
* progress bar's `fmt` field.
108100
*
109-
* @param {Object} tokens
101+
* @param {object} tokens
110102
* @api public
111103
*/
112104

113-
ProgressBar.prototype.render = function(tokens){
114-
if (!this.stream.isTTY) {
115-
return;
116-
}
105+
ProgressBar.prototype.render = function (tokens) {
106+
if (!this.stream.isTTY) return;
117107

118108
var ratio = this.curr / this.total;
119109
ratio = Math.min(Math.max(ratio, 0), 1);
120110

121-
var percent = ratio * 100
122-
, complete = Math.round(this.width * ratio)
123-
, incomplete
124-
, elapsed = new Date - this.start
125-
, eta = (percent == 100) ? 0 : elapsed * (this.total / this.curr - 1);
111+
var percent = ratio * 100;
112+
var complete = Math.round(this.width * ratio);
113+
var incomplete;
114+
var elapsed = new Date - this.start;
115+
var eta = (percent == 100) ? 0 : elapsed * (this.total / this.curr - 1);
126116

127117
complete = Array(complete).join(this.chars.complete);
128118
incomplete = Array(this.width - complete.length).join(this.chars.incomplete);
@@ -131,19 +121,17 @@ ProgressBar.prototype.render = function(tokens){
131121
.replace(':bar', complete + incomplete)
132122
.replace(':current', this.curr)
133123
.replace(':total', this.total)
134-
.replace(':elapsed', isNaN(elapsed) ? "0.0" : (elapsed / 1000).toFixed(1))
135-
.replace(':eta', (isNaN(eta) || !isFinite(eta)) ? "0.0" : (eta / 1000).toFixed(1))
124+
.replace(':elapsed', isNaN(elapsed) ? '0.0' : (elapsed / 1000).toFixed(1))
125+
.replace(':eta', (isNaN(eta) || !isFinite(eta)) ? '0.0' : (eta / 1000)
126+
.toFixed(1))
136127
.replace(':percent', percent.toFixed(0) + '%');
137128

138-
if (tokens) {
139-
for (var key in tokens) {
140-
str = str.replace(':' + key, tokens[key]);
141-
}
142-
}
129+
if (tokens) for (var key in tokens) str = str.replace(':' + key, tokens[key]);
143130

144131
if (this.lastDraw !== str) {
145-
this.rl.clearLine();
146-
this.rl.write(str);
132+
this.stream.clearLine();
133+
this.stream.cursorTo(0);
134+
this.stream.write(str);
147135
this.lastDraw = str;
148136
}
149137
};
@@ -157,12 +145,12 @@ ProgressBar.prototype.render = function(tokens){
157145
*
158146
* A ratio of 0.5 will attempt to set the progress to halfway.
159147
*
160-
* @param {Number} ratio The ratio (between 0 and 1 inclusive) to set the
161-
* overall completion to.
148+
* @param {number} ratio The ratio (between 0 and 1 inclusive) to set the
149+
* overall completion to.
162150
* @api public
163151
*/
164152

165-
ProgressBar.prototype.update = function(ratio, tokens) {
153+
ProgressBar.prototype.update = function (ratio, tokens) {
166154
var goal = Math.floor(ratio * this.total);
167155
var delta = goal - this.curr;
168156

@@ -175,14 +163,9 @@ ProgressBar.prototype.update = function(ratio, tokens) {
175163
* @api public
176164
*/
177165

178-
ProgressBar.prototype.terminate = function() {
179-
this.rl.resume();
180-
166+
ProgressBar.prototype.terminate = function () {
181167
if (this.clear) {
182-
this.rl.clearLine();
183-
this.rl.close();
184-
} else {
185-
this.rl.close();
186-
console.log();
187-
}
168+
this.stream.clearLine();
169+
this.stream.cursorTo(0);
170+
} else console.log();
188171
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "progress"
3-
, "version": "1.1.4"
3+
, "version": "1.1.5"
44
, "description": "Flexible ascii progress bar"
55
, "keywords": ["cli", "progress"]
66
, "author": "TJ Holowaychuk <tj@vision-media.ca>"

0 commit comments

Comments
 (0)