mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 01:21:14 +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:
@ -11,7 +11,7 @@ use commands::{ExpandCmd, HelpCmd, NuCmd, QuitCmd, TableCmd, TryCmd};
|
||||
pub use default_context::add_explore_context;
|
||||
pub use explore::Explore;
|
||||
use explore::ExploreConfig;
|
||||
use nu_common::{collect_pipeline, has_simple_value, CtrlC};
|
||||
use nu_common::{collect_pipeline, has_simple_value};
|
||||
use nu_protocol::{
|
||||
engine::{EngineState, Stack},
|
||||
PipelineData, Value,
|
||||
@ -28,7 +28,6 @@ mod util {
|
||||
fn run_pager(
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
ctrlc: CtrlC,
|
||||
input: PipelineData,
|
||||
config: PagerConfig,
|
||||
) -> Result<Option<Value>> {
|
||||
@ -45,14 +44,14 @@ fn run_pager(
|
||||
p.show_message("For help type :help");
|
||||
|
||||
let view = binary_view(input, config.explore_config)?;
|
||||
return p.run(engine_state, stack, ctrlc, Some(view), commands);
|
||||
return p.run(engine_state, stack, Some(view), commands);
|
||||
}
|
||||
|
||||
let (columns, data) = collect_pipeline(input)?;
|
||||
|
||||
let has_no_input = columns.is_empty() && data.is_empty();
|
||||
if has_no_input {
|
||||
return p.run(engine_state, stack, ctrlc, help_view(), commands);
|
||||
return p.run(engine_state, stack, help_view(), commands);
|
||||
}
|
||||
|
||||
p.show_message("For help type :help");
|
||||
@ -60,11 +59,11 @@ fn run_pager(
|
||||
if let Some(value) = has_simple_value(&data) {
|
||||
let text = value.to_abbreviated_string(config.nu_config);
|
||||
let view = Some(Page::new(Preview::new(&text), false));
|
||||
return p.run(engine_state, stack, ctrlc, view, commands);
|
||||
return p.run(engine_state, stack, view, commands);
|
||||
}
|
||||
|
||||
let view = create_record_view(columns, data, is_record, config);
|
||||
p.run(engine_state, stack, ctrlc, view, commands)
|
||||
p.run(engine_state, stack, view, commands)
|
||||
}
|
||||
|
||||
fn create_record_view(
|
||||
|
Reference in New Issue
Block a user