Skip to content

Commit

Permalink
fix: bind ctrl c listener so that it doesn't interfere on powershell (#…
Browse files Browse the repository at this point in the history
…2260)

This should fix #514
  • Loading branch information
wolfv authored Oct 14, 2024
1 parent ddc54f7 commit f6b9d11
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit f6b9d11

Please # to comment.