Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14 from davglass/readline

Use readline instead of the \r terminal hack
  • Loading branch information...
commit 252f6966c9f2a6bfede044cac3edd26e9f2b9e39 2 parents 55178e9 + 296704d
@tj authored
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/node-progress.js
View
15 lib/node-progress.js
@@ -42,10 +42,15 @@ exports.version = '0.0.5';
*/
function ProgressBar(fmt, options) {
+ this.rl = require('readline').createInterface({
+ input: process.stdin,
+ output: options.stream || process.stdout
+ });
+ this.rl.setPrompt('', 0);
+
options = options || {};
if ('string' != typeof fmt) throw new Error('format required');
if ('number' != typeof options.total) throw new Error('total required');
- this.stream = options.stream || process.stdout;
this.fmt = fmt;
this.curr = 0;
this.total = options.total;
@@ -78,7 +83,9 @@ ProgressBar.prototype.tick = function(len, tokens){
// progress complete
if ((this.curr += len) > this.total) {
this.complete = true;
- this.stream.write('\r\033[2K');
+ //this.rl.write(null, {ctrl: true, name: 'u'});
+ this.rl.resume();
+ this.rl.close();
return;
}
@@ -87,7 +94,6 @@ ProgressBar.prototype.tick = function(len, tokens){
, incomplete
, elapsed = new Date - this.start
, eta = elapsed * (this.total / this.curr - 1)
-
complete = Array(complete).join(this.chars.complete);
incomplete = Array(this.width - complete.length).join(this.chars.incomplete);
@@ -105,5 +111,6 @@ ProgressBar.prototype.tick = function(len, tokens){
}
}
- this.stream.write('\r\033[2K' + str);
+ this.rl.write(null, {ctrl: true, name: 'u'});
+ this.rl.write(str);
};
Please sign in to comment.
Something went wrong with that request. Please try again.