Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions crates/vite_task_bin/src/vtt/exit_on_ctrlc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

/// exit-on-ctrlc
///
/// Sets up a Ctrl+C handler, emits a "ready" milestone, then waits.
Expand Down Expand Up @@ -25,19 +27,18 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
}
}

ctrlc::set_handler(move || {
use std::io::Write;
let _ = write!(std::io::stdout(), "ctrl-c received");
let _ = std::io::stdout().flush();
std::process::exit(0);
let ctrlc_once_lock = Arc::new(std::sync::OnceLock::<()>::new());

ctrlc::set_handler({
let ctrlc_once_lock = Arc::clone(&ctrlc_once_lock);
move || {
let _ = ctrlc_once_lock.set(());
}
})?;

pty_terminal_test_client::mark_milestone("ready");
// Print a newline so the milestone bytes get flushed through line-buffered
// writers (labeled/grouped log modes).
println!();

loop {
std::thread::park();
}
ctrlc_once_lock.wait();
println!("ctrl-c received");
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ steps = [
] },
]

[[e2e]]
name = "ctrl-c terminates running tasks (labeled)"
steps = [
{ argv = [
"vt",
"run",
"--log=labeled",
"dev",
], interactions = [
{ "expect-milestone" = "ready" },
{ "write-key" = "ctrl-c" },
] },
]

[[e2e]]
name = "ctrl-c terminates running tasks (cached)"
steps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ expression: e2e_outputs
$ vtt exit-on-ctrlc
@ write-key: ctrl-c
$ vtt exit-on-ctrlc

ctrl-c received

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ expression: e2e_outputs
$ vtt exit-on-ctrlc ⊘ cache disabled
@ write-key: ctrl-c
$ vtt exit-on-ctrlc ⊘ cache disabled

ctrl-c received
Loading