mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
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:
@ -1,7 +1,7 @@
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
|
||||
use nu_protocol::{
|
||||
ByteStream, ByteStreamType, Category, Example, LabeledError, PipelineData, Signature, Type,
|
||||
Value,
|
||||
ByteStream, ByteStreamType, Category, Example, LabeledError, PipelineData, Signals, Signature,
|
||||
Type, Value,
|
||||
};
|
||||
|
||||
use crate::ExamplePlugin;
|
||||
@ -52,7 +52,7 @@ impl PluginCommand for CollectBytes {
|
||||
ByteStream::from_result_iter(
|
||||
input.into_iter().map(Value::coerce_into_binary),
|
||||
call.head,
|
||||
None,
|
||||
Signals::empty(),
|
||||
ByteStreamType::Unknown,
|
||||
),
|
||||
None,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, LabeledError, PipelineData, Signature,
|
||||
SyntaxShape, Type, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, LabeledError, PipelineData, Signals,
|
||||
Signature, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use crate::ExamplePlugin;
|
||||
@ -85,7 +85,7 @@ impl PluginCommand for Generate {
|
||||
})
|
||||
.map(|result| result.unwrap_or_else(|err| Value::error(err, head)))
|
||||
})
|
||||
.into_pipeline_data(head, None))
|
||||
.into_pipeline_data(head, Signals::empty()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
|
||||
use nu_protocol::{
|
||||
Category, Example, LabeledError, ListStream, PipelineData, Signature, SyntaxShape, Type, Value,
|
||||
Category, Example, LabeledError, ListStream, PipelineData, Signals, Signature, SyntaxShape,
|
||||
Type, Value,
|
||||
};
|
||||
|
||||
use crate::ExamplePlugin;
|
||||
@ -54,7 +55,7 @@ impl PluginCommand for Seq {
|
||||
let first: i64 = call.req(0)?;
|
||||
let last: i64 = call.req(1)?;
|
||||
let iter = (first..=last).map(move |number| Value::int(number, head));
|
||||
Ok(ListStream::new(iter, head, None).into())
|
||||
Ok(ListStream::new(iter, head, Signals::empty()).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user