Skip to content

Commit

Permalink
Merge pull request #15 from davglass/readline-osx
Browse files Browse the repository at this point in the history
On OSX revert back to terminal hack to avoid a readline bug
  • Loading branch information
tj committed Sep 19, 2012
2 parents 5a12caf + a269bd6 commit f0e3963
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/node-progress.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -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);
};

0 comments on commit f0e3963

Please sign in to comment.