TerminalInputHelper stops Ctrl-C and similar signals from leaving the terminal in an unusable state if its settings have been modified when reading user input.
This can be an issue on non-Windows platforms.
Usage:
$inputHelper = new TerminalInputHelper($inputStream);
...change terminal settings
// Wait for input before all input reads
$inputHelper->waitForInput();
...read input
// Call finish to restore terminal settings and signal handlers
$inputHelper->finish()
- internal
CloneableFinalInstantiable
| Methods |
public __construct( $inputStream)
|
| public finish() : void Restores terminal state and signal handlers. |
| public waitForInput() : void Waits for input and terminates if sent a default signal. |
| Properties |
| private string $initialState |
private $inputStream = NULL
|
| private bool $isStdin |
| private array $signalHandlers = [] |
| private int $signalToKill = 0 |
| private array $targetSignals = [] |
| Methods |
| private checkForKillSignal() : void |
| private createSignalHandlers() : void |