diff --git a/src/cli/shell.rs b/src/cli/shell.rs index 0adc0baa3..8916e9ae7 100644 --- a/src/cli/shell.rs +++ b/src/cli/shell.rs @@ -36,6 +36,18 @@ pub struct Args { prompt_config: ConfigCliPrompt, } +/// Set up Ctrl-C handler to ignore it (the child process should react on CTRL-C) +fn ignore_ctrl_c() { + tokio::spawn(async move { + loop { + tokio::signal::ctrl_c() + .await + .expect("Failed to listen for Ctrl+C"); + // Do nothing, effectively ignoring the Ctrl+C signal + } + }); +} + fn start_powershell( pwsh: PowerShell, env: &HashMap, @@ -67,6 +79,8 @@ fn start_powershell( command.arg("-File"); command.arg(&temp_path); + ignore_ctrl_c(); + let mut process = command.spawn().into_diagnostic()?; Ok(process.wait().into_diagnostic()?.code()) } @@ -100,6 +114,8 @@ fn start_cmdexe( command.arg("/K"); command.arg(temp_file.path()); + ignore_ctrl_c(); + let mut process = command.spawn().into_diagnostic()?; Ok(process.wait().into_diagnostic()?.code()) }