@@ -55,8 +55,7 @@ const {
5555 kClearScreenDown
5656} = CSI ;
5757
58- // Lazy load StringDecoder for startup performance.
59- let StringDecoder ;
58+ const { StringDecoder } = require ( 'string_decoder' ) ;
6059
6160// Lazy load Readable for startup performance.
6261let Readable ;
@@ -84,9 +83,6 @@ function Interface(input, output, completer, terminal) {
8483 return new Interface ( input , output , completer , terminal ) ;
8584 }
8685
87- if ( StringDecoder === undefined )
88- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
89-
9086 this . _sawReturnAt = 0 ;
9187 this . isCompletionEnabled = true ;
9288 this . _sawKeyPress = false ;
@@ -1122,8 +1118,6 @@ Interface.prototype[Symbol.asyncIterator] = function() {
11221118function emitKeypressEvents ( stream , iface ) {
11231119 if ( stream [ KEYPRESS_DECODER ] ) return ;
11241120
1125- if ( StringDecoder === undefined )
1126- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
11271121 stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
11281122
11291123 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
@@ -1138,8 +1132,11 @@ function emitKeypressEvents(stream, iface) {
11381132 if ( r ) {
11391133 clearTimeout ( timeoutId ) ;
11401134
1135+ let escapeTimeout = ESCAPE_CODE_TIMEOUT ;
1136+
11411137 if ( iface ) {
11421138 iface . _sawKeyPress = r . length === 1 ;
1139+ escapeTimeout = iface . escapeCodeTimeout ;
11431140 }
11441141
11451142 for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -1151,10 +1148,7 @@ function emitKeypressEvents(stream, iface) {
11511148 stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
11521149 // Escape letter at the tail position
11531150 if ( r [ i ] === kEscape && i + 1 === r . length ) {
1154- timeoutId = setTimeout (
1155- escapeCodeTimeout ,
1156- iface ? iface . escapeCodeTimeout : ESCAPE_CODE_TIMEOUT
1157- ) ;
1151+ timeoutId = setTimeout ( escapeCodeTimeout , escapeTimeout ) ;
11581152 }
11591153 } catch ( err ) {
11601154 // If the generator throws (it could happen in the `keypress`
0 commit comments