watchexec icon indicating copy to clipboard operation
watchexec copied to clipboard

Suggest adding Signal::Terminate to the home page example

Open alanwsmith opened this issue 6 months ago • 2 comments

**TL;DR

I suggest updating the home page example to include a check for:

Signal::Terminate

in addition to:

Signal::Interrupt

Is your feature request related to a problem? Please describe.

Yep. I use a startup script in development that changes to another direction for testing. The specific command is:

``bash cargo watch -C example -q -c -x run


The example code on the [home page](https://docs.rs/watchexec/latest/watchexec/) shows using this code in order to catch `Ctrl+c`:

```rust
if action.signals().any(|sig| sig == Signal::Interrupt) {
    action.quit();
}

Something in my setup prevents that from working and I can't Ctrl+c to kill the process.

I'm running a mac on 15.4. This was with watchexec 8.0.1.

I posted a repo here that shows what I'm seeing:

https://github.com/alanwsmith/watchexec_terminate_example

Describe the solution you'd like

I added a check for Signal::Terminate like this:

if action
    .signals()
    .any(|sig| sig == Signal::Interrupt || sig == Signal::Terminate)
{
    action.quit();
}

Ctrl+c works as expected with that in place.

I suggest updating the docs on the home page to add the check for Signal::Terminate as well.

And, possibly in the Watchexec::new() lines in the docs.

Describe alternatives you've considered

Since this is just an editorial change, I don't really have other options in play.

Additional context

I'm not sure how many folks will end up in a situation like the one I have. This may be too esoteric to consider, but it might save some folks the few hours of head scratching I went through.

alanwsmith avatar Jun 06 '25 20:06 alanwsmith

I'm happy to do a PR with the change if the idea works.

alanwsmith avatar Jun 06 '25 21:06 alanwsmith

Sure

passcod avatar Jun 08 '25 06:06 passcod