Add initial ctrl-c support

This commit is contained in:
JT
2021-10-28 17:13:10 +13:00
parent 1308eb45d5
commit bac8b8a450
32 changed files with 318 additions and 144 deletions

View File

@ -1,7 +1,7 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Value,
Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value,
};
use sysinfo::{ProcessExt, System, SystemExt};
@ -30,12 +30,12 @@ impl Command for Ps {
fn run(
&self,
_engine_state: &EngineState,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
run_ps(call)
run_ps(engine_state, call)
}
fn examples(&self) -> Vec<Example> {
@ -47,7 +47,7 @@ impl Command for Ps {
}
}
fn run_ps(call: &Call) -> Result<PipelineData, ShellError> {
fn run_ps(engine_state: &EngineState, call: &Call) -> Result<PipelineData, ShellError> {
let span = call.head;
let long = call.has_flag("long");
let mut sys = System::new_all();
@ -126,5 +126,7 @@ fn run_ps(call: &Call) -> Result<PipelineData, ShellError> {
}
}
Ok(output.into_iter().into_pipeline_data())
Ok(output
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
}

View File

@ -7,7 +7,7 @@ use std::sync::mpsc;
use nu_protocol::engine::{EngineState, Stack};
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::{IntoPipelineData, PipelineData, Span, Spanned};
use nu_protocol::{IntoInterruptiblePipelineData, PipelineData, Span, Spanned};
use nu_engine::CallExt;
@ -49,7 +49,7 @@ impl Command for External {
last_expression,
env_vars,
};
command.run_with_input(input)
command.run_with_input(engine_state, input)
}
}
@ -61,9 +61,15 @@ pub struct ExternalCommand {
}
impl ExternalCommand {
pub fn run_with_input(&self, input: PipelineData) -> Result<PipelineData, ShellError> {
pub fn run_with_input(
&self,
engine_state: &EngineState,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let mut process = self.create_command();
let ctrlc = engine_state.ctrlc.clone();
// TODO. We don't have a way to know the current directory
// This should be information from the EvaluationContex or EngineState
let path = env::current_dir().unwrap();
@ -155,7 +161,7 @@ impl ExternalCommand {
});
// The ValueStream is consumed by the next expression in the pipeline
ChannelReceiver::new(rx).into_pipeline_data()
ChannelReceiver::new(rx).into_pipeline_data(ctrlc)
} else {
PipelineData::new()
};