Skip to content

Commit ba80d4d

Browse files
committed
Transfer data gathering responsibility to readline
Fixes non-raw REPL/Debugger on Posix.
1 parent d412771 commit ba80d4d

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

lib/_debugger.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ function SourceInfo(body) {
566566
function Interface() {
567567
var self = this;
568568
var term = this.term =
569-
readline.createInterface(process.stdout, function (line) {
569+
readline.createInterface(process.stdin, process.stdout, function (line) {
570570
return self.complete(line);
571571
});
572572
var child;
@@ -578,9 +578,6 @@ function Interface() {
578578
});
579579

580580
this.stdin = process.openStdin();
581-
this.stdin.addListener('keypress', function(s, key) {
582-
term.write(s, key);
583-
});
584581

585582
term.setPrompt('debug> ');
586583
term.prompt();

lib/readline.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ var EventEmitter = require('events').EventEmitter;
1313
var tty = require('tty');
1414

1515

16-
exports.createInterface = function(output, completer) {
17-
return new Interface(output, completer);
16+
exports.createInterface = function(input, output, completer) {
17+
return new Interface(input, output, completer);
1818
};
1919

2020

21-
function Interface(output, completer) {
22-
if (!(this instanceof Interface)) return new Interface(output, completer);
21+
function Interface(input, output, completer) {
22+
if (!(this instanceof Interface)) {
23+
return new Interface(input, output, completer);
24+
}
2325
EventEmitter.call(this);
2426

27+
var self = this;
28+
2529
this.output = output;
30+
this.input = input;
31+
input.resume();
32+
2633
this.completer = completer;
2734

2835
this.setPrompt('> ');
@@ -33,8 +40,17 @@ function Interface(output, completer) {
3340
this.enabled = false;
3441
}
3542

36-
if (this.enabled) {
37-
// input refers to stdin
43+
if (!this.enabled) {
44+
input.on('data', function(data) {
45+
self._normalWrite(data);
46+
});
47+
48+
} else {
49+
50+
// input usually refers to stdin
51+
input.on('keypress', function(s, key) {
52+
self._ttyWrite(s, key);
53+
});
3854

3955
// Current line
4056
this.line = '';

lib/repl.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function REPLServer(prompt, stream) {
6464

6565
self.prompt = prompt || '> ';
6666

67-
var rli = self.rli = rl.createInterface(self.outputStream, function(text) {
67+
var rli = self.rli = rl.createInterface(self.inputStream, self.outputStream, function(text) {
6868
return self.complete(text);
6969
});
7070

@@ -90,10 +90,6 @@ function REPLServer(prompt, stream) {
9090
}
9191
});
9292

93-
self.inputStream.addListener('keypress', function(s, key) {
94-
rli.write(s, key);
95-
});
96-
9793
rli.addListener('line', function(cmd) {
9894
var skipCatchall = false;
9995
cmd = trimWhitespace(cmd);

0 commit comments

Comments
 (0)