spin icon indicating copy to clipboard operation
spin copied to clipboard

Restore cursor if dialoguer Ctrl+C-ed

Open itowlson opened this issue 3 weeks ago • 9 comments

Fixes #2557.

At the moment, this prints Error: read interrupted after 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 dialoguer hidden-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 up tearing 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 common or terminal but that would introduce new dependencies into those crates, which are used quite widely. But maybe it's worth it.

itowlson avatar Jun 13 '24 22:06 itowlson