|
@ -13,16 +13,23 @@ var EventEmitter = require('events').EventEmitter; |
|
|
var tty = require('tty'); |
|
|
var tty = require('tty'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createInterface = function(output, completer) { |
|
|
exports.createInterface = function(input, output, completer) { |
|
|
return new Interface(output, completer); |
|
|
return new Interface(input, output, completer); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Interface(output, completer) { |
|
|
function Interface(input, output, completer) { |
|
|
if (!(this instanceof Interface)) return new Interface(output, completer); |
|
|
if (!(this instanceof Interface)) { |
|
|
|
|
|
return new Interface(input, output, completer); |
|
|
|
|
|
} |
|
|
EventEmitter.call(this); |
|
|
EventEmitter.call(this); |
|
|
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
this.output = output; |
|
|
this.output = output; |
|
|
|
|
|
this.input = input; |
|
|
|
|
|
input.resume(); |
|
|
|
|
|
|
|
|
this.completer = completer; |
|
|
this.completer = completer; |
|
|
|
|
|
|
|
|
this.setPrompt('> '); |
|
|
this.setPrompt('> '); |
|
@ -33,8 +40,17 @@ function Interface(output, completer) { |
|
|
this.enabled = false; |
|
|
this.enabled = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (this.enabled) { |
|
|
if (!this.enabled) { |
|
|
// input refers to stdin
|
|
|
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
|
|
|
// Current line
|
|
|
this.line = ''; |
|
|
this.line = ''; |
|
|