Fixed interrupting a for-loop over a list bug #5378 (#5408)

Signed-off-by: gipsyh <gipsyh.icu@gmail.com>
This commit is contained in:
Yuheng Su 2022-05-02 15:56:37 +08:00 committed by GitHub
parent 74f1c5b67b
commit 07a7bb14bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,8 @@ use nu_engine::{eval_block, eval_expression, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack}; use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape, Category, Example, IntoInterruptiblePipelineData, ListStream, PipelineData, Signature, Span,
Value, SyntaxShape, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -88,46 +88,47 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
let redirect_stderr = call.redirect_stderr; let redirect_stderr = call.redirect_stderr;
match values { match values {
Value::List { vals, .. } => Ok(vals Value::List { vals, .. } => {
.into_iter() Ok(ListStream::from_stream(vals.into_iter(), ctrlc.clone())
.enumerate() .enumerate()
.map(move |(idx, x)| { .map(move |(idx, x)| {
stack.with_env(&orig_env_vars, &orig_env_hidden); stack.with_env(&orig_env_vars, &orig_env_hidden);
stack.add_var( stack.add_var(
var_id, var_id,
if numbered { if numbered {
Value::Record { Value::Record {
cols: vec!["index".into(), "item".into()], cols: vec!["index".into(), "item".into()],
vals: vec![ vals: vec![
Value::Int { Value::Int {
val: idx as i64, val: idx as i64,
span: head, span: head,
}, },
x, x,
], ],
span: head, span: head,
} }
} else { } else {
x x
}, },
); );
//let block = engine_state.get_block(block_id); //let block = engine_state.get_block(block_id);
match eval_block( match eval_block(
&engine_state, &engine_state,
&mut stack, &mut stack,
&block, &block,
PipelineData::new(head), PipelineData::new(head),
redirect_stdout, redirect_stdout,
redirect_stderr, redirect_stderr,
) { ) {
Ok(pipeline_data) => pipeline_data.into_value(head), Ok(pipeline_data) => pipeline_data.into_value(head),
Err(error) => Value::Error { error }, Err(error) => Value::Error { error },
} }
}) })
.filter(|x| !x.is_nothing()) .filter(|x| !x.is_nothing())
.into_pipeline_data(ctrlc)), .into_pipeline_data(ctrlc))
}
Value::Range { val, .. } => Ok(val Value::Range { val, .. } => Ok(val
.into_range_iter(ctrlc.clone())? .into_range_iter(ctrlc.clone())?
.enumerate() .enumerate()