mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-30 14:01:13 +00:00
Suppress MultipleHandlers
from Ctrl-C in confirm (#2903)
## Summary Fixes #2900 ## Test Plan Tried reproducing the steps described in #2900, but with `cargo run -- pip ...` and it didn't crash 😄.
This commit is contained in:
parent
10dfd43af9
commit
f1630a70f5
1 changed files with 12 additions and 2 deletions
|
@ -6,7 +6,8 @@ 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 || {
|
||||
// Set the Ctrl-C handler to exit the process.
|
||||
let result = ctrlc::set_handler(move || {
|
||||
let term = Term::stderr();
|
||||
term.show_cursor().ok();
|
||||
term.flush().ok();
|
||||
|
@ -17,7 +18,16 @@ pub(crate) fn confirm(message: &str, term: &Term, default: bool) -> Result<bool>
|
|||
} else {
|
||||
130
|
||||
});
|
||||
})?;
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(()) => {}
|
||||
Err(ctrlc::Error::MultipleHandlers) => {
|
||||
// If multiple handlers were set, we assume that the existing handler is our
|
||||
// confirmation handler, and continue.
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
|
||||
let prompt = format!(
|
||||
"{} {} {} {} {}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue