@@ -64,8 +64,7 @@ const {
64
64
kClearScreenDown
65
65
} = CSI ;
66
66
67
- // Lazy load StringDecoder for startup performance.
68
- let StringDecoder ;
67
+ const { StringDecoder } = require ( 'string_decoder' ) ;
69
68
70
69
// Lazy load Readable for startup performance.
71
70
let Readable ;
@@ -93,9 +92,6 @@ function Interface(input, output, completer, terminal) {
93
92
return new Interface ( input , output , completer , terminal ) ;
94
93
}
95
94
96
- if ( StringDecoder === undefined )
97
- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
98
-
99
95
this . _sawReturnAt = 0 ;
100
96
this . isCompletionEnabled = true ;
101
97
this . _sawKeyPress = false ;
@@ -1131,8 +1127,6 @@ Interface.prototype[Symbol.asyncIterator] = function() {
1131
1127
function emitKeypressEvents ( stream , iface ) {
1132
1128
if ( stream [ KEYPRESS_DECODER ] ) return ;
1133
1129
1134
- if ( StringDecoder === undefined )
1135
- StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
1136
1130
stream [ KEYPRESS_DECODER ] = new StringDecoder ( 'utf8' ) ;
1137
1131
1138
1132
stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
@@ -1147,8 +1141,11 @@ function emitKeypressEvents(stream, iface) {
1147
1141
if ( r ) {
1148
1142
clearTimeout ( timeoutId ) ;
1149
1143
1144
+ let escapeTimeout = ESCAPE_CODE_TIMEOUT ;
1145
+
1150
1146
if ( iface ) {
1151
1147
iface . _sawKeyPress = r . length === 1 ;
1148
+ escapeTimeout = iface . escapeCodeTimeout ;
1152
1149
}
1153
1150
1154
1151
for ( let i = 0 ; i < r . length ; i ++ ) {
@@ -1160,10 +1157,7 @@ function emitKeypressEvents(stream, iface) {
1160
1157
stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
1161
1158
// Escape letter at the tail position
1162
1159
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 ) ;
1167
1161
}
1168
1162
} catch ( err ) {
1169
1163
// If the generator throws (it could happen in the `keypress`
0 commit comments