Skip to content

Commit

Permalink
Hacky, but seems to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Jan 22, 2025
1 parent 29931f2 commit cb928fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
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.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ concat-idents = "1.1.5"
console = "0.15.10"
crossbeam-channel = "0.5.14"
csv = "1.3.1"
ctrlc = "3.4.5"
dashmap = "6.1.0"
deno_task_shell = "0.20.2"
dialoguer = "0.11.0"
Expand Down Expand Up @@ -269,6 +270,7 @@ uv-pep440 = { workspace = true }
uv-pep508 = { workspace = true }
uv-pypi-types = { workspace = true }

ctrlc = { workspace = true }
fs-err = { workspace = true, features = ["tokio"] }
pixi_allocator = { workspace = true, optional = true }
pixi_build_frontend = { workspace = true }
Expand Down Expand Up @@ -333,6 +335,7 @@ xxhash-rust = { workspace = true }
zip = { workspace = true, features = ["deflate", "time"] }
zstd = { workspace = true }


[target.'cfg(unix)'.dependencies]
libc = { workspace = true, default-features = false }
nix = { workspace = true, features = ["poll", "term"] }
Expand Down
35 changes: 19 additions & 16 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,11 @@ async fn execute_task<'p>(
};
let cwd = task.working_directory()?;

// Ignore CTRL+C
// Specifically so that the child is responsible for its own signal handling
// NOTE: once CTRL+C is registered it will always stay registered for the rest of
// the runtime of the program which is fine when using run in isolation,
// however if we start to use run in conjunction with some other command we
// might want to revaluate this.
let ctrl_c = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} });
ctrlc::set_handler(move || {
let term = console::Term::stdout();
let _ = term.show_cursor();
})
.unwrap();

let execute_future = deno_task_shell::execute(
script,
Expand All @@ -316,9 +314,7 @@ async fn execute_task<'p>(
Default::default(),
);
let status_code = tokio::select! {
code = execute_future => code,
// This should never exit
_ = ctrl_c => { unreachable!("Ctrl+C should not be triggered") }
code = execute_future => code
};

if status_code != 0 {
Expand All @@ -342,12 +338,19 @@ 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();
});
ctrlc::set_handler(move || {
let term = console::Term::stdout();
let _ = term.show_cursor();

// https://learn.microsoft.com/en-us/cpp/c-runtime-library/signal-constants
#[cfg(target_os = "windows")]
std::process::exit(3);

// POSIX compliant OSs: 128 + SIGINT (2)
#[cfg(not(target_os = "windows"))]
std::process::exit(130);
})
.unwrap();

dialoguer::Select::with_theme(&theme)
.with_prompt(format!(
Expand Down

0 comments on commit cb928fc

Please sign in to comment.