|
@ -41,6 +41,7 @@ function Interface(input, output, completer, terminal) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this._sawReturn = false; |
|
|
this._sawReturn = false; |
|
|
|
|
|
this.isCompletionEnabled = true; |
|
|
|
|
|
|
|
|
EventEmitter.call(this); |
|
|
EventEmitter.call(this); |
|
|
var historySize; |
|
|
var historySize; |
|
@ -130,7 +131,7 @@ function Interface(input, output, completer, terminal) { |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
emitKeypressEvents(input); |
|
|
emitKeypressEvents(input, this); |
|
|
|
|
|
|
|
|
// input usually refers to stdin
|
|
|
// input usually refers to stdin
|
|
|
input.on('keypress', onkeypress); |
|
|
input.on('keypress', onkeypress); |
|
@ -883,7 +884,7 @@ Interface.prototype._ttyWrite = function(s, key) { |
|
|
|
|
|
|
|
|
case 'tab': |
|
|
case 'tab': |
|
|
// If tab completion enabled, do that...
|
|
|
// If tab completion enabled, do that...
|
|
|
if (typeof this.completer === 'function') { |
|
|
if (typeof this.completer === 'function' && this.isCompletionEnabled) { |
|
|
this._tabComplete(); |
|
|
this._tabComplete(); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -917,7 +918,7 @@ exports.Interface = Interface; |
|
|
const KEYPRESS_DECODER = Symbol('keypress-decoder'); |
|
|
const KEYPRESS_DECODER = Symbol('keypress-decoder'); |
|
|
const ESCAPE_DECODER = Symbol('escape-decoder'); |
|
|
const ESCAPE_DECODER = Symbol('escape-decoder'); |
|
|
|
|
|
|
|
|
function emitKeypressEvents(stream) { |
|
|
function emitKeypressEvents(stream, iface) { |
|
|
if (stream[KEYPRESS_DECODER]) return; |
|
|
if (stream[KEYPRESS_DECODER]) return; |
|
|
var StringDecoder = require('string_decoder').StringDecoder; // lazy load
|
|
|
var StringDecoder = require('string_decoder').StringDecoder; // lazy load
|
|
|
stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); |
|
|
stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); |
|
@ -930,6 +931,10 @@ function emitKeypressEvents(stream) { |
|
|
var r = stream[KEYPRESS_DECODER].write(b); |
|
|
var r = stream[KEYPRESS_DECODER].write(b); |
|
|
if (r) { |
|
|
if (r) { |
|
|
for (var i = 0; i < r.length; i++) { |
|
|
for (var i = 0; i < r.length; i++) { |
|
|
|
|
|
if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) { |
|
|
|
|
|
iface.isCompletionEnabled = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
stream[ESCAPE_DECODER].next(r[i]); |
|
|
stream[ESCAPE_DECODER].next(r[i]); |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
@ -938,6 +943,10 @@ function emitKeypressEvents(stream) { |
|
|
stream[ESCAPE_DECODER] = emitKeys(stream); |
|
|
stream[ESCAPE_DECODER] = emitKeys(stream); |
|
|
stream[ESCAPE_DECODER].next(); |
|
|
stream[ESCAPE_DECODER].next(); |
|
|
throw err; |
|
|
throw err; |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (iface) { |
|
|
|
|
|
iface.isCompletionEnabled = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|