@@ -41,6 +41,7 @@ function Interface(input, output, completer, terminal) {
4141}
4242
4343this . _sawReturn = false ;
44+ this . isCompletionEnabled = true ;
4445
4546EventEmitter . call ( this ) ;
4647var 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
136137input . on ( 'keypress' , onkeypress ) ;
@@ -883,7 +884,7 @@ Interface.prototype._ttyWrite = function(s, key) {
883884
884885case 'tab' :
885886// If tab completion enabled, do that...
886- if ( typeof this . completer === 'function' ) {
887+ if ( typeof this . completer === 'function' && this . isCompletionEnabled ) {
887888this . _tabComplete ( ) ;
888889break ;
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 ) {
921922if ( stream [ KEYPRESS_DECODER ] ) return ;
922923var StringDecoder = require ( 'string_decoder' ) . StringDecoder ; // lazy load
923924stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
@@ -930,6 +931,10 @@ function emitKeypressEvents(stream) {
930931var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
931932if ( r ) {
932933for ( var i = 0 ; i < r . length ; i ++ ) {
934+ if ( r [ i ] === '\t' && typeof r [ i + 1 ] === 'string' && iface ) {
935+ iface . isCompletionEnabled = false ;
936+ }
937+
933938try {
934939stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
935940} catch ( err ) {
@@ -938,6 +943,10 @@ function emitKeypressEvents(stream) {
938943stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
939944stream [ ESCAPE_DECODER ] . next ( ) ;
940945throw err ;
946+ } finally {
947+ if ( iface ) {
948+ iface . isCompletionEnabled = true ;
949+ }
941950}
942951}
943952}
0 commit comments