Transfer data gathering responsibility to readline
authorRyan Dahl <ry@tinyclouds.org>
Wed, 19 Jan 2011 19:46:14 +0000 (11:46 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 19 Jan 2011 19:46:16 +0000 (11:46 -0800)
Fixes non-raw REPL/Debugger on Posix.

lib/_debugger.js
lib/readline.js
lib/repl.js

index 7619b25..e313ec3 100644 (file)
@@ -566,7 +566,7 @@ function SourceInfo(body) {
 function Interface() {
   var self = this;
   var term = this.term =
-    readline.createInterface(process.stdout, function (line) {
+    readline.createInterface(process.stdin, process.stdout, function (line) {
       return self.complete(line);
     });
   var child;
@@ -578,9 +578,6 @@ function Interface() {
   });
 
   this.stdin = process.openStdin();
-  this.stdin.addListener('keypress', function(s, key) {
-    term.write(s, key);
-  });
 
   term.setPrompt('debug> ');
   term.prompt();
index 7a022e7..aba3098 100644 (file)
@@ -13,16 +13,23 @@ var EventEmitter = require('events').EventEmitter;
 var tty = require('tty');
 
 
-exports.createInterface = function(output, completer) {
-  return new Interface(output, completer);
+exports.createInterface = function(input, output, completer) {
+  return new Interface(input, output, completer);
 };
 
 
-function Interface(output, completer) {
-  if (!(this instanceof Interface)) return new Interface(output, completer);
+function Interface(input, output, completer) {
+  if (!(this instanceof Interface)) {
+    return new Interface(input, output, completer);
+  }
   EventEmitter.call(this);
 
+  var self = this;
+
   this.output = output;
+  this.input = input;
+  input.resume();
+
   this.completer = completer;
 
   this.setPrompt('> ');
@@ -33,8 +40,17 @@ function Interface(output, completer) {
     this.enabled = false;
   }
 
-  if (this.enabled) {
-    // input refers to stdin
+  if (!this.enabled) {
+    input.on('data', function(data) {
+      self._normalWrite(data);
+    });
+
+  } else {
+
+    // input usually refers to stdin
+    input.on('keypress', function(s, key) {
+      self._ttyWrite(s, key);
+    });
 
     // Current line
     this.line = '';
index add102e..e3f84f1 100644 (file)
@@ -64,7 +64,7 @@ function REPLServer(prompt, stream) {
 
   self.prompt = prompt || '> ';
 
-  var rli = self.rli = rl.createInterface(self.outputStream, function(text) {
+  var rli = self.rli = rl.createInterface(self.inputStream, self.outputStream, function(text) {
     return self.complete(text);
   });
 
@@ -90,10 +90,6 @@ function REPLServer(prompt, stream) {
     }
   });
 
-  self.inputStream.addListener('keypress', function(s, key) {
-    rli.write(s, key);
-  });
-
   rli.addListener('line', function(cmd) {
     var skipCatchall = false;
     cmd = trimWhitespace(cmd);