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:
Reilly Wood
2022-12-15 09:39:24 -08:00
committed by GitHub
parent 33aea56ccd
commit e215fbbd08
16 changed files with 69 additions and 137 deletions

View File

@ -31,10 +31,8 @@ pub fn eval_call(
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
if let Some(ctrlc) = &engine_state.ctrlc {
if ctrlc.load(core::sync::atomic::Ordering::SeqCst) {
return Ok(Value::Nothing { span: call.head }.into_pipeline_data());
}
if nu_utils::ctrl_c::was_pressed(&engine_state.ctrlc) {
return Ok(Value::Nothing { span: call.head }.into_pipeline_data());
}
let decl = engine_state.get_decl(call.decl_id);