@@ -169,6 +169,34 @@ function REPLServer(prompt,
169
169
170
170
eval_ = eval_ || defaultEval ;
171
171
172
+ // Pause taking in new input, and store the keys in a buffer.
173
+ const pausedBuffer = [ ] ;
174
+ let paused = false ;
175
+ function pause ( ) {
176
+ paused = true ;
177
+ }
178
+ function unpause ( ) {
179
+ if ( ! paused ) return ;
180
+ paused = false ;
181
+ let entry ;
182
+ while ( entry = pausedBuffer . shift ( ) ) {
183
+ const [ type , payload ] = entry ;
184
+ switch ( type ) {
185
+ case 'key' : {
186
+ const [ d , key ] = payload ;
187
+ self . _ttyWrite ( d , key ) ;
188
+ break ;
189
+ }
190
+ case 'close' :
191
+ self . emit ( 'exit' ) ;
192
+ break ;
193
+ }
194
+ if ( paused ) {
195
+ break ;
196
+ }
197
+ }
198
+ }
199
+
172
200
function defaultEval ( code , context , file , cb ) {
173
201
var err , result , script , wrappedErr ;
174
202
var wrappedCmd = false ;
@@ -420,6 +448,10 @@ function REPLServer(prompt,
420
448
'DEP0075' ) ;
421
449
422
450
self . on ( 'close' , function emitExit ( ) {
451
+ if ( paused ) {
452
+ pausedBuffer . push ( [ 'close' ] ) ;
453
+ return ;
454
+ }
423
455
self . emit ( 'exit' ) ;
424
456
} ) ;
425
457
@@ -557,10 +589,14 @@ function REPLServer(prompt,
557
589
}
558
590
} ) ;
559
591
560
- // Wrap readline tty to enable editor mode
592
+ // Wrap readline tty to enable editor mode and pausing.
561
593
const ttyWrite = self . _ttyWrite . bind ( self ) ;
562
594
self . _ttyWrite = ( d , key ) => {
563
595
key = key || { } ;
596
+ if ( paused && ! ( self . breakEvalOnSigint && key . ctrl && key . name === 'c' ) ) {
597
+ pausedBuffer . push ( [ 'key' , [ d , key ] ] ) ;
598
+ return ;
599
+ }
564
600
if ( ! self . editorMode || ! self . terminal ) {
565
601
ttyWrite ( d , key ) ;
566
602
return ;
0 commit comments