Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Console] Ensure terminal is usable after termination signal#61861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Do you have a use case for using this helper in your own commands whether coming from a Symfony application or a reusable bundle? Elsewhere than in core I mean. |
Not at all. The helper is to fix the issues with Symfony/Console. |
I've just noticed this issue#61852 (that has been closed). This PR fixes the problem described, which is having to hit Enter after a Ctrl-C to send the signal (when submitting hidden input). |
Please inline back the logic into Application and QuestionHelper. Helpers in this namespace are part of Console's public API, but I can't think of a use case for this helper in userland either and I looking at it, I don't think it's worth it. Expanding the public API is a feature also while this PR is a bugfix targeting a branch that is in maintenance mode, so please do the minimum changes to fix the bug at hand. Thanks |
Given the need for extra state in this input helper, I'm fine with using a separate class. But it should be |
The non-obvious name of that helper annoys me but probably fine if it’s internal. Works for me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Here's some nitpicking.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
I tried several before choosing the least annoying. Feel free to suggest an alternative. |
valx76 commentedSep 29, 2025
I can think of |
Thank you@johnstevenson. |
This PR introduces a new helper
TerminalInputHelperthat restores the terminal to its original state after it has been modified when reading using input. This ensures that the terminal is not broken when a terminating signal, like Ctrl-C, is received.QuestionHelper.php disables
icanonandechowhen accepting input from a selection, and disablesechowhen accepting hidden input. If these are not restored before termination, the user's terminal can end up in a broken state.Usage:
The helper creates its own signal handlers (for
SIGINT,SIGQUIT, andSIGTERM) that restore the original terminal settings then call any original handler callback. If the original handler callback does not terminate the process then the current terminal settings are restored.If there is no original signal handler callback and the signal's disposition is set to the default action (
SIG_DFL), then that action is invoked by aposix_killcall.The
finishmethod restores the terminal settings and replaces the new signal handlers with the original ones.