Add and use new Signals struct (#13314)

# Description
This PR introduces a new `Signals` struct to replace our adhoc passing
around of `ctrlc: Option<Arc<AtomicBool>>`. Doing so has a few benefits:
- We can better enforce when/where resetting or triggering an interrupt
is allowed.
- Consolidates `nu_utils::ctrl_c::was_pressed` and other ad-hoc
re-implementations into a single place: `Signals::check`.
- This allows us to add other types of signals later if we want. E.g.,
exiting or suspension.
- Similarly, we can more easily change the underlying implementation if
we need to in the future.
- Places that used to have a `ctrlc` of `None` now use
`Signals::empty()`, so we can double check these usages for correctness
in the future.
This commit is contained in:
Ian Manske
2024-07-07 22:29:01 +00:00
committed by GitHub
parent c6b6b1b7a8
commit 399a7c8836
246 changed files with 1332 additions and 1234 deletions

View File

@ -166,7 +166,7 @@ used as the next argument to the closure, otherwise generation stops.
Ok(iter
.flatten()
.into_pipeline_data(call.head, engine_state.ctrlc.clone()))
.into_pipeline_data(call.head, engine_state.signals().clone()))
}
}

View File

@ -129,7 +129,7 @@ pub fn run_seq(
span,
},
span,
engine_state.ctrlc.clone(),
engine_state.signals().clone(),
)
} else {
ListStream::new(
@ -141,7 +141,7 @@ pub fn run_seq(
span,
},
span,
engine_state.ctrlc.clone(),
engine_state.signals().clone(),
)
};