From a269bd67612ba3f349e069690b18b20697adb50a Mon Sep 17 00:00:00 2001 From: Dav Glass Date: Wed, 19 Sep 2012 18:17:10 -0500 Subject: [PATCH] On OSX revert back to terminal hack to avoid a readline bug --- lib/node-progress.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/node-progress.js b/lib/node-progress.js index 346d51e..92e7dc1 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -47,6 +47,13 @@ function ProgressBar(fmt, options) { output: options.stream || process.stdout }); this.rl.setPrompt('', 0); + this.rl.clearLine = function() { + if (process.platform === 'darwin') { + this.output.write('\r'); + } else { + this.write(null, {ctrl: true, name: 'u'}); + } + }; options = options || {}; if ('string' != typeof fmt) throw new Error('format required'); @@ -83,7 +90,7 @@ ProgressBar.prototype.tick = function(len, tokens){ // progress complete if ((this.curr += len) > this.total) { this.complete = true; - //this.rl.write(null, {ctrl: true, name: 'u'}); + this.rl.clearLine(); this.rl.resume(); this.rl.close(); return; @@ -110,7 +117,7 @@ ProgressBar.prototype.tick = function(len, tokens){ str = str.replace(':' + key, tokens[key]); } } - - this.rl.write(null, {ctrl: true, name: 'u'}); + + this.rl.clearLine(); this.rl.write(str); };