mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50: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:
@ -2,7 +2,7 @@ use filesize::file_real_size_fast;
|
||||
use nu_glob::Pattern;
|
||||
use nu_protocol::{ShellError, Span, Value};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -106,13 +106,8 @@ impl DirInfo {
|
||||
match std::fs::read_dir(&s.path) {
|
||||
Ok(d) => {
|
||||
for f in d {
|
||||
match ctrl_c {
|
||||
Some(ref cc) => {
|
||||
if cc.load(Ordering::SeqCst) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
None => continue,
|
||||
if nu_utils::ctrl_c::was_pressed(&ctrl_c) {
|
||||
break;
|
||||
}
|
||||
|
||||
match f {
|
||||
|
Reference in New Issue
Block a user