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,9 @@
use nu_engine::{eval_block, eval_expression};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
pub struct For;
@ -55,6 +57,7 @@ impl Command for For {
.as_block()
.expect("internal error: expected block");
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
let block = engine_state.get_block(block_id).clone();
let mut stack = stack.collect_captures(&block.captures);
@ -71,7 +74,7 @@ impl Command for For {
Err(error) => Value::Error { error },
}
})
.into_pipeline_data()),
.into_pipeline_data(ctrlc)),
Value::Range { val, .. } => Ok(val
.into_range_iter()?
.map(move |x| {
@ -83,7 +86,7 @@ impl Command for For {
Err(error) => Value::Error { error },
}
})
.into_pipeline_data()),
.into_pipeline_data(ctrlc)),
x => {
stack.add_var(var_id, x);

View File

@ -1,8 +1,8 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
span, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned, SyntaxShape,
Value,
span, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
Signature, Spanned, SyntaxShape, Value,
};
use nu_engine::{get_full_help, CallExt};
@ -121,7 +121,9 @@ fn help(
}
}
return Ok(found_cmds_vec.into_iter().into_pipeline_data());
return Ok(found_cmds_vec
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()));
}
if !rest.is_empty() {
@ -155,7 +157,9 @@ fn help(
});
}
Ok(found_cmds_vec.into_iter().into_pipeline_data())
Ok(found_cmds_vec
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
} else {
let mut name = String::new();
let mut output = String::new();