@@ -41,6 +41,7 @@ function Interface(input, output, completer, terminal) {
4141 }
4242
4343 this . _sawReturn = false ;
44+ this . isCompletionEnabled = true ;
4445
4546 EventEmitter . call ( this ) ;
4647 var historySize ;
@@ -130,7 +131,7 @@ function Interface(input, output, completer, terminal) {
130131
131132 } else {
132133
133- emitKeypressEvents ( input ) ;
134+ emitKeypressEvents ( input , this ) ;
134135
135136 // input usually refers to stdin
136137 input . on ( 'keypress' , onkeypress ) ;
@@ -883,7 +884,7 @@ Interface.prototype._ttyWrite = function(s, key) {
883884
884885 case 'tab' :
885886 // If tab completion enabled, do that...
886- if ( typeof this . completer === 'function' ) {
887+ if ( typeof this . completer === 'function' && this . isCompletionEnabled ) {
887888 this . _tabComplete ( ) ;
888889 break ;
889890 }
@@ -917,7 +918,7 @@ exports.Interface = Interface;
917918const KEYPRESS_DECODER = Symbol ( 'keypress-decoder' ) ;
918919const ESCAPE_DECODER = Symbol ( 'escape-decoder' ) ;
919920
920- function emitKeypressEvents ( stream ) {
921+ function emitKeypressEvents ( stream , iface ) {
921922 if ( stream [ KEYPRESS_DECODER ] ) return ;
922923 var StringDecoder = require ( 'string_decoder' ) . StringDecoder ; // lazy load
923924 stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
@@ -930,6 +931,10 @@ function emitKeypressEvents(stream) {
930931 var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
931932 if ( r ) {
932933 for ( var i = 0 ; i < r . length ; i ++ ) {
934+ if ( r [ i ] === '\t' && typeof r [ i + 1 ] === 'string' && iface ) {
935+ iface . isCompletionEnabled = false ;
936+ }
937+
933938 try {
934939 stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
935940 } catch ( err ) {
@@ -938,6 +943,10 @@ function emitKeypressEvents(stream) {
938943 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
939944 stream [ ESCAPE_DECODER ] . next ( ) ;
940945 throw err ;
946+ } finally {
947+ if ( iface ) {
948+ iface . isCompletionEnabled = true ;
949+ }
941950 }
942951 }
943952 }
0 commit comments