|
|
@ -86,12 +86,28 @@ function Interface(input, output, completer, terminal) { |
|
|
|
|
|
|
|
this.terminal = !!terminal; |
|
|
|
|
|
|
|
function ondata(data) { |
|
|
|
self._normalWrite(data); |
|
|
|
} |
|
|
|
|
|
|
|
function onend() { |
|
|
|
self.close(); |
|
|
|
} |
|
|
|
|
|
|
|
function onkeypress(s, key) { |
|
|
|
self._ttyWrite(s, key); |
|
|
|
} |
|
|
|
|
|
|
|
function onresize() { |
|
|
|
self._refreshLine(); |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.terminal) { |
|
|
|
input.on('data', function(data) { |
|
|
|
self._normalWrite(data); |
|
|
|
}); |
|
|
|
input.on('end', function() { |
|
|
|
self.close(); |
|
|
|
input.on('data', ondata); |
|
|
|
input.on('end', onend); |
|
|
|
self.once('close', function() { |
|
|
|
input.removeListener('data', ondata); |
|
|
|
input.removeListener('end', onend); |
|
|
|
}); |
|
|
|
var StringDecoder = require('string_decoder').StringDecoder; // lazy load
|
|
|
|
this._decoder = new StringDecoder('utf8'); |
|
|
@ -101,9 +117,7 @@ function Interface(input, output, completer, terminal) { |
|
|
|
exports.emitKeypressEvents(input); |
|
|
|
|
|
|
|
// input usually refers to stdin
|
|
|
|
input.on('keypress', function(s, key) { |
|
|
|
self._ttyWrite(s, key); |
|
|
|
}); |
|
|
|
input.on('keypress', onkeypress); |
|
|
|
|
|
|
|
// Current line
|
|
|
|
this.line = ''; |
|
|
@ -117,8 +131,10 @@ function Interface(input, output, completer, terminal) { |
|
|
|
this.history = []; |
|
|
|
this.historyIndex = -1; |
|
|
|
|
|
|
|
output.on('resize', function() { |
|
|
|
self._refreshLine(); |
|
|
|
output.on('resize', onresize); |
|
|
|
self.once('close', function() { |
|
|
|
input.removeListener('keypress', onkeypress); |
|
|
|
output.removeListener('resize', onresize); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|