mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:15:14 +02:00
Add helper method to check whether ctrl+c was pressed, adopt it (#7482)
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) { ... ```
This commit is contained in:
13
crates/nu-utils/src/ctrl_c.rs
Normal file
13
crates/nu-utils/src/ctrl_c.rs
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
pub mod ctrl_c;
|
||||
mod deansi;
|
||||
pub mod locale;
|
||||
pub mod utils;
|
||||
|
||||
pub use ctrl_c::was_pressed;
|
||||
pub use locale::get_system_locale;
|
||||
pub use utils::{
|
||||
enable_vt_processing, get_default_config, get_default_env, get_ls_colors,
|
||||
|
Reference in New Issue
Block a user