mirror of
https://github.com/nushell/nushell
synced 2025-01-02 16:29:00 +00:00
e215fbbd08
I've been working on streaming and pipeline interruption lately. It was bothering me that checking ctrl+c (something we want to do often) always requires a bunch of boilerplate like: ```rust use std::sync::atomic::Ordering; if let Some(ctrlc) = &engine_state.ctrlc { if ctrlc.load(Ordering::SeqCst) { ... ``` I added a helper method to cut that down to: ```rust if nu_utils::ctrl_c::was_pressed(&engine_state.ctrlc) { ... ```
13 lines
300 B
Rust
13 lines
300 B
Rust
use std::sync::{
|
|
atomic::{AtomicBool, Ordering},
|
|
Arc,
|
|
};
|
|
|
|
/// Returns true if Nu has received a SIGINT signal / ctrl+c event
|
|
pub fn was_pressed(ctrlc: &Option<Arc<AtomicBool>>) -> bool {
|
|
if let Some(ctrlc) = ctrlc {
|
|
ctrlc.load(Ordering::SeqCst)
|
|
} else {
|
|
false
|
|
}
|
|
}
|