@@ -36,6 +36,7 @@ function Interface(input, output, completer, terminal) {
36
36
}
37
37
38
38
this . _sawReturn = false ;
39
+ this . isCompletionEnabled = true ;
39
40
40
41
EventEmitter . call ( this ) ;
41
42
var historySize ;
@@ -122,7 +123,7 @@ function Interface(input, output, completer, terminal) {
122
123
123
124
} else {
124
125
125
- exports . emitKeypressEvents ( input ) ;
126
+ exports . emitKeypressEvents ( input , this ) ;
126
127
127
128
// input usually refers to stdin
128
129
input . on ( 'keypress' , onkeypress ) ;
@@ -868,7 +869,7 @@ Interface.prototype._ttyWrite = function(s, key) {
868
869
869
870
case 'tab' :
870
871
// If tab completion enabled, do that...
871
- if ( typeof this . completer === 'function' ) {
872
+ if ( typeof this . completer === 'function' && this . isCompletionEnabled ) {
872
873
this . _tabComplete ( ) ;
873
874
break ;
874
875
}
@@ -902,7 +903,7 @@ exports.Interface = Interface;
902
903
const KEYPRESS_DECODER = Symbol ( 'keypress-decoder' ) ;
903
904
const ESCAPE_DECODER = Symbol ( 'escape-decoder' ) ;
904
905
905
- function emitKeypressEvents ( stream ) {
906
+ function emitKeypressEvents ( stream , iface ) {
906
907
if ( stream [ KEYPRESS_DECODER ] ) return ;
907
908
var StringDecoder = require ( 'string_decoder' ) . StringDecoder ; // lazy load
908
909
stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
@@ -915,6 +916,10 @@ function emitKeypressEvents(stream) {
915
916
var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
916
917
if ( r ) {
917
918
for ( var i = 0 ; i < r . length ; i ++ ) {
919
+ if ( r [ i ] === '\t' && typeof r [ i + 1 ] === 'string' && iface ) {
920
+ iface . isCompletionEnabled = false ;
921
+ }
922
+
918
923
try {
919
924
stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
920
925
} catch ( err ) {
@@ -923,6 +928,10 @@ function emitKeypressEvents(stream) {
923
928
stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
924
929
stream [ ESCAPE_DECODER ] . next ( ) ;
925
930
throw err ;
931
+ } finally {
932
+ if ( iface ) {
933
+ iface . isCompletionEnabled = true ;
934
+ }
926
935
}
927
936
}
928
937
}
0 commit comments