Permalink
Browse files

Using readline instead of the \r hack

  • Loading branch information...
1 parent 2b48b1d commit 0a66e71322458d52e6979c0a97ba11ffd47980b8 @davglass davglass committed Sep 19, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/node-progress.js
View
@@ -8,6 +8,12 @@
* Expose `ProgressBar`.
*/
+var rl = require('readline').createInterface({
+ input: process.stdin,
+ output: process.stdout
+});
+rl.setPrompt('', 0);
+
exports = module.exports = ProgressBar;
/**
@@ -78,7 +84,8 @@ ProgressBar.prototype.tick = function(len, tokens){
// progress complete
if ((this.curr += len) > this.total) {
this.complete = true;
- this.stream.write('\r\033[2K');
+ rl.write(null, {ctrl: true, name: 'u'});
+ rl.close();
return;
}
@@ -105,5 +112,6 @@ ProgressBar.prototype.tick = function(len, tokens){
}
}
- this.stream.write('\r\033[2K' + str);
+ rl.write(null, {ctrl: true, name: 'u'});
+ rl.write(str);
};

0 comments on commit 0a66e71

Please sign in to comment.