@@ -64,8 +64,7 @@ const {
6464 kClearScreenDown
6565} = CSI ;
6666
67- // Lazy load StringDecoder for startup performance.
68- let StringDecoder ;
67+ const { StringDecoder } = require ( 'string_decoder' ) ;
6968
7069// Lazy load Readable for startup performance.
7170let Readable ;
@@ -93,9 +92,6 @@ function Interface(input, output, completer, terminal) {
9392 return new Interface ( input , output , completer , terminal ) ;
9493 }
9594
96- if ( StringDecoder === undefined )
97- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
98-
9995 this . _sawReturnAt = 0 ;
10096 this . isCompletionEnabled = true ;
10197 this . _sawKeyPress = false ;
@@ -1131,8 +1127,6 @@ Interface.prototype[Symbol.asyncIterator] = function() {
11311127function emitKeypressEvents ( stream , iface ) {
11321128 if ( stream [ KEYPRESS_DECODER ] ) return ;
11331129
1134- if ( StringDecoder === undefined )
1135- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
11361130 stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
11371131
11381132 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
@@ -1147,8 +1141,11 @@ function emitKeypressEvents(stream, iface) {
11471141 if ( r ) {
11481142 clearTimeout ( timeoutId ) ;
11491143
1144+ let escapeTimeout = ESCAPE_CODE_TIMEOUT ;
1145+
11501146 if ( iface ) {
11511147 iface . _sawKeyPress = r . length === 1 ;
1148+ escapeTimeout = iface . escapeCodeTimeout ;
11521149 }
11531150
11541151 for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -1160,10 +1157,7 @@ function emitKeypressEvents(stream, iface) {
11601157 stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
11611158 // Escape letter at the tail position
11621159 if ( r [ i ] === kEscape && i + 1 === r . length ) {
1163- timeoutId = setTimeout (
1164- escapeCodeTimeout ,
1165- iface ? iface . escapeCodeTimeout : ESCAPE_CODE_TIMEOUT
1166- ) ;
1160+ timeoutId = setTimeout ( escapeCodeTimeout , escapeTimeout ) ;
11671161 }
11681162 } catch ( err ) {
11691163 // If the generator throws (it could happen in the `keypress`
0 commit comments