@@ -36,6 +36,7 @@ function Interface(input, output, completer, terminal) {
3636 }
3737
3838 this . _sawReturn = false ;
39+ this . isCompletionEnabled = true ;
3940
4041 EventEmitter . call ( this ) ;
4142 var historySize ;
@@ -122,7 +123,7 @@ function Interface(input, output, completer, terminal) {
122123
123124 } else {
124125
125- exports . emitKeypressEvents ( input ) ;
126+ exports . emitKeypressEvents ( input , this ) ;
126127
127128 // input usually refers to stdin
128129 input . on ( 'keypress' , onkeypress ) ;
@@ -868,7 +869,7 @@ Interface.prototype._ttyWrite = function(s, key) {
868869
869870 case 'tab' :
870871 // If tab completion enabled, do that...
871- if ( typeof this . completer === 'function' ) {
872+ if ( typeof this . completer === 'function' && this . isCompletionEnabled ) {
872873 this . _tabComplete ( ) ;
873874 break ;
874875 }
@@ -902,7 +903,7 @@ exports.Interface = Interface;
902903const KEYPRESS_DECODER = Symbol ( 'keypress-decoder' ) ;
903904const ESCAPE_DECODER = Symbol ( 'escape-decoder' ) ;
904905
905- function emitKeypressEvents ( stream ) {
906+ function emitKeypressEvents ( stream , iface ) {
906907 if ( stream [ KEYPRESS_DECODER ] ) return ;
907908 var StringDecoder = require ( 'string_decoder' ) . StringDecoder ; // lazy load
908909 stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
@@ -915,6 +916,10 @@ function emitKeypressEvents(stream) {
915916 var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
916917 if ( r ) {
917918 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+
918923 try {
919924 stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
920925 } catch ( err ) {
@@ -923,6 +928,10 @@ function emitKeypressEvents(stream) {
923928 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
924929 stream [ ESCAPE_DECODER ] . next ( ) ;
925930 throw err ;
931+ } finally {
932+ if ( iface ) {
933+ iface . isCompletionEnabled = true ;
934+ }
926935 }
927936 }
928937 }
0 commit comments