mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 10:38:07 +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:
@ -165,7 +165,7 @@ fn fill(
|
||||
cell_paths,
|
||||
};
|
||||
|
||||
operate(action, arg, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, arg, input, call.head, engine_state.signals())
|
||||
}
|
||||
|
||||
fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
|
@ -138,7 +138,7 @@ fn into_binary(
|
||||
cell_paths,
|
||||
compact: call.has_flag(engine_state, stack, "compact")?,
|
||||
};
|
||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, head, engine_state.signals())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ fn into_bool(
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
||||
let args = CellPathOnlyArgs::from(cell_paths);
|
||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
|
||||
fn string_to_boolean(s: &str, span: Span) -> Result<bool, ShellError> {
|
||||
|
@ -141,7 +141,7 @@ impl Command for SubCommand {
|
||||
zone_options,
|
||||
cell_paths,
|
||||
};
|
||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ fn into_duration(
|
||||
ret
|
||||
}
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
engine_state.signals(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ impl Command for SubCommand {
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
||||
let args = CellPathOnlyArgs::from(cell_paths);
|
||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -49,7 +49,7 @@ impl Command for SubCommand {
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
||||
let args = CellPathOnlyArgs::from(cell_paths);
|
||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -87,7 +87,7 @@ fn glob_helper(
|
||||
Ok(Value::glob(stream.into_string()?, false, head).into_pipeline_data())
|
||||
} else {
|
||||
let args = Arguments { cell_paths };
|
||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, head, engine_state.signals())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ impl Command for SubCommand {
|
||||
signed,
|
||||
cell_paths,
|
||||
};
|
||||
operate(action, args, input, call.head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -125,7 +125,7 @@ fn into_record(
|
||||
),
|
||||
},
|
||||
Value::Range { val, .. } => Value::record(
|
||||
val.into_range_iter(span, engine_state.ctrlc.clone())
|
||||
val.into_range_iter(span, engine_state.signals().clone())
|
||||
.enumerate()
|
||||
.map(|(idx, val)| (format!("{idx}"), val))
|
||||
.collect(),
|
||||
|
@ -180,7 +180,7 @@ fn string_helper(
|
||||
cell_paths,
|
||||
config,
|
||||
};
|
||||
operate(action, args, input, head, engine_state.ctrlc.clone())
|
||||
operate(action, args, input, head, engine_state.signals())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,14 +57,12 @@ impl Command for IntoValue {
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let engine_state = engine_state.clone();
|
||||
let metadata = input.metadata();
|
||||
let ctrlc = engine_state.ctrlc.clone();
|
||||
let span = call.head;
|
||||
let display_as_filesizes = call.has_flag(&engine_state, stack, "prefer-filesizes")?;
|
||||
let display_as_filesizes = call.has_flag(engine_state, stack, "prefer-filesizes")?;
|
||||
|
||||
// the columns to update
|
||||
let columns: Option<Value> = call.get_flag(&engine_state, stack, "columns")?;
|
||||
let columns: Option<Value> = call.get_flag(engine_state, stack, "columns")?;
|
||||
let columns: Option<HashSet<String>> = match columns {
|
||||
Some(val) => Some(
|
||||
val.into_list()?
|
||||
@ -81,7 +79,7 @@ impl Command for IntoValue {
|
||||
display_as_filesizes,
|
||||
span,
|
||||
}
|
||||
.into_pipeline_data(span, ctrlc)
|
||||
.into_pipeline_data(span, engine_state.signals().clone())
|
||||
.set_metadata(metadata))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user