From: Ryan Dahl Date: Wed, 19 Jan 2011 19:46:14 +0000 (-0800) Subject: Transfer data gathering responsibility to readline X-Git-Tag: v0.3.6~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba80d4d8a9e6141c00fe60b6fb65983a7f7b8fd9;p=platform%2Fupstream%2Fnodejs.git Transfer data gathering responsibility to readline Fixes non-raw REPL/Debugger on Posix. --- diff --git a/lib/_debugger.js b/lib/_debugger.js index 7619b25..e313ec3 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -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(); diff --git a/lib/readline.js b/lib/readline.js index 7a022e7..aba3098 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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 = ''; diff --git a/lib/repl.js b/lib/repl.js index add102e..e3f84f1 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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);