@@ -55,8 +55,7 @@ const {
55
55
kClearScreenDown
56
56
} = CSI ;
57
57
58
- // Lazy load StringDecoder for startup performance.
59
- let StringDecoder ;
58
+ const { StringDecoder } = require ( 'string_decoder' ) ;
60
59
61
60
// Lazy load Readable for startup performance.
62
61
let Readable ;
@@ -84,9 +83,6 @@ function Interface(input, output, completer, terminal) {
84
83
return new Interface ( input , output , completer , terminal ) ;
85
84
}
86
85
87
- if ( StringDecoder === undefined )
88
- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
89
-
90
86
this . _sawReturnAt = 0 ;
91
87
this . isCompletionEnabled = true ;
92
88
this . _sawKeyPress = false ;
@@ -1122,8 +1118,6 @@ Interface.prototype[Symbol.asyncIterator] = function() {
1122
1118
function emitKeypressEvents ( stream , iface ) {
1123
1119
if ( stream [ KEYPRESS_DECODER ] ) return ;
1124
1120
1125
- if ( StringDecoder === undefined )
1126
- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
1127
1121
stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
1128
1122
1129
1123
stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
@@ -1138,8 +1132,11 @@ function emitKeypressEvents(stream, iface) {
1138
1132
if ( r ) {
1139
1133
clearTimeout ( timeoutId ) ;
1140
1134
1135
+ let escapeTimeout = ESCAPE_CODE_TIMEOUT ;
1136
+
1141
1137
if ( iface ) {
1142
1138
iface . _sawKeyPress = r . length === 1 ;
1139
+ escapeTimeout = iface . escapeCodeTimeout ;
1143
1140
}
1144
1141
1145
1142
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -1151,10 +1148,7 @@ function emitKeypressEvents(stream, iface) {
1151
1148
stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
1152
1149
// Escape letter at the tail position
1153
1150
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 ) ;
1158
1152
}
1159
1153
} catch ( err ) {
1160
1154
// If the generator throws (it could happen in the `keypress`
0 commit comments