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

fix: always show cursor after control+c #2635

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ clap = { version = "4.5.9", default-features = false }
clap-verbosity-flag = "2.2.0"
clap_complete = "4.5.2"
clap_complete_nushell = "4.5.2"
concat-idents = "1.1.5"
console = "0.15.8"
crossbeam-channel = "0.5.12"
csv = "1.3.0"
Expand Down
1 change: 0 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ pub async fn execute() -> miette::Result<()> {
let args = Args::parse();
set_console_colors(&args);
let use_colors = console::colors_enabled_stderr();

// Set up the default miette handler based on whether we want colors or not.
miette::set_hook(Box::new(move |_| {
Box::new(
Expand Down
19 changes: 19 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ fn disambiguate_task_interactive<'p>(
..ColorfulTheme::default()
};

// Ignore CTRL+C in the dialoguer prompt so that it shows the cursor again.
// Related: https://github.com/console-rs/dialoguer/issues/77
tokio::spawn(async {
let _ = tokio::signal::ctrl_c().await;
dialoguer_reset_cursor_hack();
});

dialoguer::Select::with_theme(&theme)
.with_prompt(format!(
"The task '{}' {}can be run in multiple environments.\n\nPlease select an environment to run the task in:",
Expand All @@ -343,3 +350,15 @@ fn disambiguate_task_interactive<'p>(
.map_or(None, identity)
.map(|idx| problem.environments[idx].clone())
}

/// `dialoguer` doesn't clean up your term if it's aborted via e.g. `SIGINT` or other exceptions:
/// https://github.com/console-rs/dialoguer/issues/188.
///
/// `dialoguer`, as a library, doesn't want to mess with signal handlers,
/// but we, as an application, are free to mess with signal handlers if we feel like it, since we
/// own the process.
/// This function was taken from https://github.com/dnjstrom/git-select-branch/blob/16c454624354040bc32d7943b9cb2e715a5dab92/src/main.rs#L119
fn dialoguer_reset_cursor_hack() {
let term = console::Term::stdout();
let _ = term.show_cursor();
}
Loading