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: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ concat-idents = "1.1.5"
console = "0.15.8"
crossbeam-channel = "0.5.12"
csv = "1.3.0"
ctrlc = "3.4"
dashmap = "6.1.0"
deno_task_shell = "0.16.0"
dialoguer = "0.11.0"
Expand Down Expand Up @@ -207,6 +208,7 @@ clap_complete_nushell = { workspace = true }
console = { workspace = true, features = ["windows-console-colors"] }
crossbeam-channel = { workspace = true }
csv = { workspace = true }
ctrlc = { workspace = true }
deno_task_shell = { workspace = true }
dialoguer = { workspace = true }
dirs = { workspace = true }
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
20 changes: 20 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ fn disambiguate_task_interactive<'p>(
..ColorfulTheme::default()
};

// Ignore CTRL+C in the dialoguer prompt so that it shows the cursor again.
ctrlc::set_handler(move || {
Copy link
Member

Choose a reason for hiding this comment

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

I am still in favor of using tokio if we can make it work :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it back

dialoguer_reset_cursor_hack();
// Exit the process, this potentially leaves the running program in an unexpected way.
// But not exiting make ctrl-c not work at all.
std::process::exit(0);
}).ok()?;

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 +351,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