@@ -40,6 +40,7 @@ function Interface(input, output, completer, terminal) {
4040 }
4141
4242 this . _sawReturn = false ;
43+ this . isCompletionEnabled = true ;
4344
4445 EventEmitter . call ( this ) ;
4546 var historySize ;
@@ -129,7 +130,7 @@ function Interface(input, output, completer, terminal) {
129130
130131 } else {
131132
132- emitKeypressEvents ( input ) ;
133+ emitKeypressEvents ( input , this ) ;
133134
134135 // input usually refers to stdin
135136 input . on ( 'keypress' , onkeypress ) ;
@@ -878,7 +879,7 @@ Interface.prototype._ttyWrite = function(s, key) {
878879
879880 case 'tab' :
880881 // If tab completion enabled, do that...
881- if ( typeof this . completer === 'function' ) {
882+ if ( typeof this . completer === 'function' && this . isCompletionEnabled ) {
882883 this . _tabComplete ( ) ;
883884 break ;
884885 }
@@ -912,7 +913,7 @@ exports.Interface = Interface;
912913const KEYPRESS_DECODER = Symbol ( 'keypress-decoder' ) ;
913914const ESCAPE_DECODER = Symbol ( 'escape-decoder' ) ;
914915
915- function emitKeypressEvents ( stream ) {
916+ function emitKeypressEvents ( stream , iface ) {
916917 if ( stream [ KEYPRESS_DECODER ] ) return ;
917918 var StringDecoder = require ( 'string_decoder' ) . StringDecoder ; // lazy load
918919 stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
@@ -925,6 +926,10 @@ function emitKeypressEvents(stream) {
925926 var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
926927 if ( r ) {
927928 for ( var i = 0 ; i < r . length ; i ++ ) {
929+ if ( r [ i ] === '\t' && typeof r [ i + 1 ] === 'string' && iface ) {
930+ iface . isCompletionEnabled = false ;
931+ }
932+
928933 try {
929934 stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
930935 } catch ( err ) {
@@ -933,6 +938,10 @@ function emitKeypressEvents(stream) {
933938 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
934939 stream [ ESCAPE_DECODER ] . next ( ) ;
935940 throw err ;
941+ } finally {
942+ if ( iface ) {
943+ iface . isCompletionEnabled = true ;
944+ }
936945 }
937946 }
938947 }
0 commit comments