mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:46:00 +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:
@ -46,7 +46,7 @@ impl Command for Debug {
|
||||
Value::string(x.to_expanded_string(", ", &config), head)
|
||||
}
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
engine_state.signals(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ impl Command for MetadataSet {
|
||||
let ds_fp: Option<String> = call.get_flag(engine_state, stack, "datasource-filepath")?;
|
||||
let ds_ls = call.has_flag(engine_state, stack, "datasource-ls")?;
|
||||
let content_type: Option<String> = call.get_flag(engine_state, stack, "content-type")?;
|
||||
|
||||
let signals = engine_state.signals().clone();
|
||||
let metadata = input
|
||||
.metadata()
|
||||
.clone()
|
||||
@ -58,19 +58,15 @@ impl Command for MetadataSet {
|
||||
match (ds_fp, ds_ls) {
|
||||
(Some(path), false) => Ok(input.into_pipeline_data_with_metadata(
|
||||
head,
|
||||
engine_state.ctrlc.clone(),
|
||||
signals,
|
||||
metadata.with_data_source(DataSource::FilePath(path.into())),
|
||||
)),
|
||||
(None, true) => Ok(input.into_pipeline_data_with_metadata(
|
||||
head,
|
||||
engine_state.ctrlc.clone(),
|
||||
signals,
|
||||
metadata.with_data_source(DataSource::Ls),
|
||||
)),
|
||||
_ => Ok(input.into_pipeline_data_with_metadata(
|
||||
head,
|
||||
engine_state.ctrlc.clone(),
|
||||
metadata,
|
||||
)),
|
||||
_ => Ok(input.into_pipeline_data_with_metadata(head, signals, metadata)),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user