Restore cursor if dialoguer Ctrl+C-ed #2559
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fixes #2557.
At the moment, this prints
Error: read interruptedafter the Ctrl+C. I've tried some of the suggested fixes and they have either had the same quirk, or not fixed the problem, or both. So for now I'm accepting that ugliness as a compromise. Better offers eagerly accepted!This PR sets the Ctrl+C handler up at the entry to every command that uses
dialoguerhidden-cursor functions. This is safer than putting it near the point of use, because you can only set a Ctrl+C handler once per process; and we cannot put it at the top of the whole program because some commands need different/extra Ctrl+C processing (e.g.spin uptearing down triggers). This can result in setting up a handler that might never be needed (and it's not 100% clear if that could have unexpected side effects).There is code duplication here: we could move it into
commonorterminalbut that would introduce new dependencies into those crates, which are used quite widely. But maybe it's worth it.