repl: proper `setPrompt()` and `multiline` support
authorFedor Indutny <fedor@indutny.com>
Thu, 31 Jul 2014 08:30:46 +0000 (12:30 +0400)
committerFedor Indutny <fedor@indutny.com>
Thu, 31 Jul 2014 08:30:46 +0000 (12:30 +0400)
fix #8031

lib/repl.js

index 6d49bda..578f99e 100644 (file)
@@ -389,16 +389,22 @@ REPLServer.prototype.resetContext = function() {
 };
 
 REPLServer.prototype.displayPrompt = function(preserveCursor) {
-  var initial = this._prompt;
-  var prompt = initial;
+  var prompt = this._initialPrompt;
   if (this.bufferedCommand.length) {
     prompt = '...';
     var levelInd = new Array(this.lines.level.length).join('..');
     prompt += levelInd + ' ';
   }
-  this.setPrompt(prompt);
+
+  // Do not overwrite `_initialPrompt` here
+  REPLServer.super_.prototype.setPrompt.call(this, prompt);
   this.prompt(preserveCursor);
-  this.setPrompt(initial);
+};
+
+// When invoked as an API method, overwrite _initialPrompt
+REPLServer.prototype.setPrompt = function setPrompt(prompt) {
+  this._initialPrompt = prompt;
+  REPLServer.super_.prototype.setPrompt.call(this, prompt);
 };
 
 // A stream to push an array into a REPL