Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Stdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function __construct(LoopInterface $loop)
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
shell_exec('stty -icanon -echo');
}

// register shutdown function to restore TTY mode in case of unclean shutdown (uncaught exception)
// this will not trigger on SIGKILL etc., but the terminal should take care of this
register_shutdown_function(array($this, 'close'));
}

public function close()
Expand All @@ -52,6 +56,11 @@ private function restore()
shell_exec(sprintf('stty %s', $this->oldMode));
$this->oldMode = null;
}

// restore blocking mode so following programs behave normally
if (defined('STDIN') && is_resource(STDIN)) {
stream_set_blocking(STDIN, true);
}
}

/**
Expand Down