-
Notifications
You must be signed in to change notification settings - Fork 143
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling Interrupt Signals (e.g., Ctrl+C) in Select
and Other Dialoguer Actions
#294
Comments
I found a magic solution:
let _ = ctrlc::set_handler(move || {
// DO NOTHING
});
use dialoguer::console::Term;
if dialoguer_result.is_err() {
let _ = Term::stderr().show_cursor();
} |
Thanks for this. It is a much better solution for me with a fn main() -> anyhow::Result<()> {
// Ignore SIGINT so we can handle it ourselves
ctrlc::set_handler(move || {}).expect("Error setting Ctrl-C handler");
let app = App::parse();
match &app.command {
// Handle clap commands
}
.map_err(|e| {
let _ = Term::stdout().show_cursor();
e
})
} |
There are two challenges with dialoguer at the moment about this. The underlying console library is now quite decent at restoring terminal state in more cases, even in light of ctrl-c. However in dialoguer the cursor is explicitly hidden in many interactions which results in this sort of behavior. It would be weird for console to try to install a ctrl-c handler though. One option would be to say the components do not hide the cursor but |
Playing with this a bit now I do wonder if it would not be a better solution to just provide a convenient way to reset the terminal on ctrl-c with a utility function. fn main() -> anyhow::Result<()> {
ctrlc::set_handler(|| console::reset_terminal(); };
// ...
} |
Fixes an issue whereby exiting the confirmation prompt can lead to your cursor disappearing: console-rs/dialoguer#294. See: https://github.com/mitsuhiko/rye/blob/b839a2c5b7e648e9e5d836a8bf5f703c9807d615/rye/src/main.rs#L36-L48.
using the latest version
using example-select, when everything operates as expected, it looks like this:
however, when I press
Ctrl+C
inSelect
, the following occurs:This issue is not limited to the
Select
; it affects all actions that initially hide the cursor. The root of the problem seems to be the lack of a handler for keys likeCtrl+C
.Is it possible to provide a custom handler to manage these kinds of inputs? Any assistance or suggestions would be greatly appreciated.
The text was updated successfully, but these errors were encountered: