@@ -247,7 +247,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
247
247
$ matches = $ autocomplete ($ ret );
248
248
$ numMatches = \count ($ matches );
249
249
250
- $ sttyMode = shell_exec ( ' stty -g ' );
250
+ $ sttyMode = Terminal:: backupSttyMode ( );
251
251
252
252
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
253
253
shell_exec ('stty -icanon -echo ' );
@@ -257,11 +257,17 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
257
257
258
258
// Read a keypress
259
259
while (!feof ($ inputStream )) {
260
+ do {
261
+ // Give signal handlers a chance to run
262
+ $ r = [$ inputStream ];
263
+ $ w = [];
264
+ } while (0 === @stream_select ($ r , $ w , $ w , 0 , 100 ));
265
+
260
266
$ c = fread ($ inputStream , 1 );
261
267
262
268
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
263
269
if (false === $ c || ('' === $ ret && '' === $ c && null === $ question ->getDefault ())) {
264
- shell_exec ( sprintf ( ' stty %s ' , $ sttyMode) );
270
+ Terminal:: restoreSttyMode ( $ sttyMode );
265
271
throw new MissingInputException ('Aborted. ' );
266
272
} elseif ("\177" === $ c ) { // Backspace Character
267
273
if (0 === $ numMatches && 0 !== $ i ) {
@@ -365,8 +371,7 @@ function ($match) use ($ret) {
365
371
}
366
372
}
367
373
368
- // Reset stty so it behaves normally again
369
- shell_exec (sprintf ('stty %s ' , $ sttyMode ));
374
+ Terminal::restoreSttyMode ($ sttyMode );
370
375
371
376
return $ fullChoice ;
372
377
}
@@ -418,7 +423,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
418
423
}
419
424
420
425
if (self ::$ stty && Terminal::hasSttyAvailable ()) {
421
- $ sttyMode = shell_exec ( ' stty -g ' );
426
+ $ sttyMode = Terminal:: backupSttyMode ( );
422
427
shell_exec ('stty -echo ' );
423
428
} elseif ($ this ->isInteractiveInput ($ inputStream )) {
424
429
throw new RuntimeException ('Unable to hide the response. ' );
@@ -427,7 +432,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
427
432
$ value = fgets ($ inputStream , 4096 );
428
433
429
434
if (self ::$ stty && Terminal::hasSttyAvailable ()) {
430
- shell_exec ( sprintf ( ' stty %s ' , $ sttyMode) );
435
+ Terminal:: restoreSttyMode ( $ sttyMode );
431
436
}
432
437
433
438
if (false === $ value ) {
0 commit comments