Skip to content
This repository
Browse code

On OSX revert back to terminal hack to avoid a readline bug

  • Loading branch information...
commit a269bd67612ba3f349e069690b18b20697adb50a 1 parent 5a12caf
Dav Glass authored September 19, 2012

Showing 1 changed file with 10 additions and 3 deletions. Show diff stats Hide diff stats

  1. 13  lib/node-progress.js
13  lib/node-progress.js
@@ -47,6 +47,13 @@ function ProgressBar(fmt, options) {
47 47
     output: options.stream || process.stdout
48 48
   });
49 49
   this.rl.setPrompt('', 0);
  50
+  this.rl.clearLine = function() {
  51
+      if (process.platform === 'darwin') {
  52
+        this.output.write('\r');
  53
+      } else {
  54
+        this.write(null, {ctrl: true, name: 'u'});
  55
+      }
  56
+  };
50 57
 
51 58
   options = options || {};
52 59
   if ('string' != typeof fmt) throw new Error('format required');
@@ -83,7 +90,7 @@ ProgressBar.prototype.tick = function(len, tokens){
83 90
   // progress complete
84 91
   if ((this.curr += len) > this.total) {
85 92
     this.complete = true;
86  
-    //this.rl.write(null, {ctrl: true, name: 'u'});
  93
+    this.rl.clearLine();
87 94
     this.rl.resume();
88 95
     this.rl.close();
89 96
     return;
@@ -110,7 +117,7 @@ ProgressBar.prototype.tick = function(len, tokens){
110 117
       str = str.replace(':' + key, tokens[key]);
111 118
     }
112 119
   }
113  
-
114  
-  this.rl.write(null, {ctrl: true, name: 'u'});
  120
+  
  121
+  this.rl.clearLine();
115 122
   this.rl.write(str);
116 123
 };

0 notes on commit a269bd6

Please sign in to comment.
Something went wrong with that request. Please try again.