| Crates.io | ctrlc-tiny |
| lib.rs | ctrlc-tiny |
| version | 1.0.0 |
| created_at | 2025-07-15 18:03:31.639941+00 |
| updated_at | 2025-12-09 13:02:45.622647+00 |
| description | A tiny crate for checking if Ctrl-C was pressed ā no handlers, no AtomicBool. |
| homepage | https://github.com/malt03/ctrlc-tiny |
| repository | https://github.com/malt03/ctrlc-tiny |
| max_upload_size | |
| id | 1753670 |
| size | 30,601 |
A tiny crate for checking if Ctrl-C was pressed.
No handlers to set. No threads. No AtomicBool.
Just call init_ctrlc() once, then check is_ctrlc_received() in your loop.
SIGINT handlerAdd to your Cargo.toml:
ctrlc-tiny = "0.2"
Example:
fn main() -> std::io::Result<()> {
ctrlc_tiny::init_ctrlc_with_print("Ctrl+C pressed\n")?;
while !ctrlc_tiny::is_ctrlc_received() {
// work...
}
Ok(())
}
Need to detect Ctrl-C more than once? See examples/multi_ctrlc.rs.
ctrlc?ctrlc is great when you want to run custom logic when Ctrl-C is pressed.
But if you just want to check whether Ctrl-C was pressed, it can feel more involved than necessary.
ctrlc-tiny keeps things simple: a single flag you can poll.
volatile sig_atomic_t flag ā safe in POSIX signal handlers.reset_ctrlc_received(), but may race with the signal handler if SIGINT is received at the same time.Honestly, Arc, AtomicBool, and even the internals of the ctrlc crate don't pose any real-world performance issues.
This crate was created to scratch a personal itch ā to get rid of a subjective sense of overkill and a bit of boilerplate.
In that sense, Iām quite happy with how this crate turned out.
Licensed under either of:
See LICENSE-MIT or LICENSE-APACHE.