MCPcopy Index your code
hub / github.com/Detegr/rust-ctrlc

github.com/Detegr/rust-ctrlc @3.5.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.5.2 ↗ · + Follow
40 symbols 66 edges 12 files 5 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CtrlC

A simple easy to use wrapper around Ctrl-C signal.

Documentation

Example usage

In cargo.toml:

[dependencies]
ctrlc = "3.5"

then, in main.rs

use std::sync::mpsc::channel;
use ctrlc;

fn main() {
    let (tx, rx) = channel();

    ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
        .expect("Error setting Ctrl-C handler");

    println!("Waiting for Ctrl-C...");
    rx.recv().expect("Could not receive from channel.");
    println!("Got it! Exiting..."); 
}

Try the example yourself

cargo build --examples && target/debug/examples/readme_example

Handling SIGTERM and SIGHUP

Add CtrlC to Cargo.toml using termination feature and CtrlC will handle SIGINT, SIGTERM and SIGHUP.

License

Licensed under either of * Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Similar crates

There are alternatives that give you more control over the different signals and/or add async support.

Core symbols most depended-on inside this repo

set_handler
called by 4
src/lib.rs
init_and_set_handler
called by 2
src/lib.rs
cleanup
called by 2
tests/main/harness.rs
raise_ctrl_c
called by 2
tests/main/harness.rs
get_stdout
called by 2
tests/main/harness.rs
run_harness
called by 2
tests/main/harness.rs
try_set_handler
called by 1
src/lib.rs
set_handler_inner
called by 1
src/lib.rs

Shape

Function 28
Method 9
Enum 3

Languages

Rust100%

Modules by API surface

tests/main/harness.rs11 symbols
src/platform/unix/mod.rs6 symbols
src/error.rs6 symbols
src/lib.rs4 symbols
tests/main/mod.rs3 symbols
tests/main/issue_97.rs3 symbols
src/platform/windows/mod.rs3 symbols
tests/main/test_signal_hook.rs1 symbols
src/signal.rs1 symbols
examples/readme_example.rs1 symbols
examples/issue_46_example.rs1 symbols

For agents

$ claude mcp add rust-ctrlc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact