Browse files

fix prompt being displayed before buffer is flushed

  • Loading branch information...
1 parent 6ec7722 commit 9b7b8abd64268c914d2135e66f3d814426823a0b cloudhead committed Jul 20, 2010
Showing with 14 additions and 3 deletions.
  1. +14 −3 lib/http-console.js
View
17 lib/http-console.js
@@ -171,8 +171,9 @@ this.Console.prototype = new(function () {
this.dataPrompt();
} else {
this.request(method, path, {}, function (res, body) {
- that.printResponse.call(that, res, body);
- that.prompt();
+ that.printResponse.call(that, res, body, function () {
+ that.prompt();
+ });
}).end();
}
return;
@@ -181,7 +182,7 @@ this.Console.prototype = new(function () {
}
this.prompt();
};
- this.printResponse = function (res, body) {
+ this.printResponse = function (res, body, callback) {
var status = ('HTTP/' + res.httpVersion +
' ' + res.statusCode +
' ' + http.STATUS_CODES[res.statusCode]).bold, output;
@@ -205,6 +206,16 @@ this.Console.prototype = new(function () {
} else {
inspect(output);
}
+
+ // Make sure the buffer is flushed before
+ // we display the prompt.
+ if (process.stdout.write('')) {
+ callback();
+ } else {
+ process.stdout.addListener('drain', function () {
+ callback();
+ });
+ }
};
this.prompt = function () {
var protocol = this.options.useSSL ? 'https://' : 'http://',

0 comments on commit 9b7b8ab

Please sign in to comment.