Skip to content
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

Suppress MultipleHandlers from ctrlc in confirm #2903

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions crates/uv-requirements/src/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use console::{style, Key, Term};
/// This is a slimmed-down version of `dialoguer::Confirm`, with the post-confirmation report
/// enabled.
pub(crate) fn confirm(message: &str, term: &Term, default: bool) -> Result<bool> {
ctrlc::set_handler(move || {
let handler_set = ctrlc::set_handler(move || {
let term = Term::stderr();
term.show_cursor().ok();
term.flush().ok();
Expand All @@ -17,7 +17,13 @@ pub(crate) fn confirm(message: &str, term: &Term, default: bool) -> Result<bool>
} else {
130
});
})?;
});

// silence MultipleHandlers error from ctrlc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should maybe mention something about why we're doing this 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I added a note.

match handler_set {
Ok(_) | Err(ctrlc::Error::MultipleHandlers) => {}
Err(e) => return Err(e.into()),
}

let prompt = format!(
"{} {} {} {} {}",
Expand Down
Loading