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;
});
this.stdin = process.openStdin();
- this.stdin.addListener('keypress', function(s, key) {
- term.write(s, key);
- });
term.setPrompt('debug> ');
term.prompt();
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('> ');
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 = '';
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);
});
}
});
- self.inputStream.addListener('keypress', function(s, key) {
- rli.write(s, key);
- });
-
rli.addListener('line', function(cmd) {
var skipCatchall = false;
cmd = trimWhitespace(cmd);