diff --git a/crates/nu-command/src/commands/autoview/command.rs b/crates/nu-command/src/commands/autoview/command.rs index 1bc3570739..285dce6eaa 100644 --- a/crates/nu-command/src/commands/autoview/command.rs +++ b/crates/nu-command/src/commands/autoview/command.rs @@ -50,13 +50,8 @@ pub fn autoview(context: CommandArgs) -> Result { let text = context.scope.get_command("textview"); let table = context.scope.get_command("table"); - let pivot_mode = configuration.pivot_mode(); - let (mut input_stream, context) = context.split(); - let term_width = context.host.lock().width(); - let color_hm = get_color_config(); - if let Some(x) = input_stream.next() { match input_stream.next() { Some(y) => { @@ -183,41 +178,57 @@ pub fn autoview(context: CommandArgs) -> Result { } Value { - value: UntaggedValue::Row(row), + value: UntaggedValue::Row(ref row), .. - } if pivot_mode.is_always() - || (pivot_mode.is_auto() - && (row - .entries - .iter() - .map(|(_, v)| v.convert_to_string()) - .collect::>() - .iter() - .fold(0usize, |acc, len| acc + len.len()) - + row.entries.iter().count() * 2) - > term_width) => - { - let mut entries = vec![]; - for (key, value) in row.entries.iter() { - entries.push(vec![ - nu_table::StyledString::new( - key.to_string(), - TextStyle::new() - .alignment(nu_table::Alignment::Left) - .fg(nu_ansi_term::Color::Green) - .bold(Some(true)), - ), - nu_table::StyledString::new( - format_leaf(value).plain_string(100_000), - nu_table::TextStyle::basic_left(), - ), - ]); + } => { + let pivot_mode = configuration.pivot_mode(); + + let term_width = context.host.lock().width(); + if pivot_mode.is_always() + || (pivot_mode.is_auto() + && (row + .entries + .iter() + .map(|(_, v)| v.convert_to_string()) + .collect::>() + .iter() + .fold(0usize, |acc, len| acc + len.len()) + + row.entries.iter().count() * 2) + > term_width) + { + let mut entries = vec![]; + for (key, value) in row.entries.iter() { + entries.push(vec![ + nu_table::StyledString::new( + key.to_string(), + TextStyle::new() + .alignment(nu_table::Alignment::Left) + .fg(nu_ansi_term::Color::Green) + .bold(Some(true)), + ), + nu_table::StyledString::new( + format_leaf(value).plain_string(100_000), + nu_table::TextStyle::basic_left(), + ), + ]); + } + + let color_hm = get_color_config(); + + let table = + nu_table::Table::new(vec![], entries, nu_table::Theme::compact()); + + println!("{}", nu_table::draw_table(&table, term_width, &color_hm)); + } else if let Some(table) = table { + let mut stream = VecDeque::new(); + stream.push_back(x); + let command_args = + create_default_command_args(&context).with_input(stream); + let result = table.run(command_args)?; + let _ = result.collect::>(); + } else { + out!("{:?}", row); } - - let table = - nu_table::Table::new(vec![], entries, nu_table::Theme::compact()); - - println!("{}", nu_table::draw_table(&table, term_width, &color_hm)); } Value { value: UntaggedValue::Primitive(Primitive::Nothing), diff --git a/crates/nu-command/src/commands/if_.rs b/crates/nu-command/src/commands/if_.rs index ab196b9168..37f2f46ef7 100644 --- a/crates/nu-command/src/commands/if_.rs +++ b/crates/nu-command/src/commands/if_.rs @@ -76,7 +76,7 @@ fn if_command(raw_args: CommandArgs) -> Result { } match condition.block.block[0].pipelines.get(0) { Some(item) => match item.list.get(0) { - Some(ClassifiedCommand::Expr(expr)) => expr.clone(), + Some(ClassifiedCommand::Expr(expr)) => expr, _ => { return Err(ShellError::labeled_error( "Expected a condition", diff --git a/crates/nu-command/src/commands/let_.rs b/crates/nu-command/src/commands/let_.rs index 1016df0903..a5e4cc90da 100644 --- a/crates/nu-command/src/commands/let_.rs +++ b/crates/nu-command/src/commands/let_.rs @@ -55,7 +55,7 @@ pub fn letcmd(args: CommandArgs) -> Result { } match rhs.block.block[0].pipelines.get(0) { Some(item) => match item.list.get(0) { - Some(ClassifiedCommand::Expr(expr)) => (expr.clone(), rhs.captured.clone()), + Some(ClassifiedCommand::Expr(expr)) => (expr, &rhs.captured), _ => { return Err(ShellError::labeled_error( "Expected a value", diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index 91c5c200b7..d0a26eb7aa 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -6,7 +6,7 @@ use log::trace; use nu_errors::{ArgumentError, ShellError}; use nu_protocol::did_you_mean; use nu_protocol::{ - hir::{self, CapturedBlock, Expression, ExternalRedirection, RangeOperator, SpannedExpression}, + hir::{self, CapturedBlock, Expression, RangeOperator, SpannedExpression}, Dictionary, }; use nu_protocol::{ @@ -154,11 +154,8 @@ pub fn evaluate_baseline_expr( } } - let mut block = block.clone(); - block.infer_params(); - Ok( - UntaggedValue::Block(Box::new(CapturedBlock::new(block, captured))) + UntaggedValue::Block(Box::new(CapturedBlock::new(block.clone(), captured))) .into_value(&tag), ) } @@ -276,9 +273,6 @@ fn evaluate_invocation(block: &hir::Block, ctx: &EvaluationContext) -> Result InputStream::empty(), }; - let mut block = block.clone(); - block.set_redirect(ExternalRedirection::Stdout); - let result = run_block(&block, ctx, input)?; let output = result.into_vec(); diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 127ca8c557..aad2aee20d 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -425,9 +425,11 @@ fn parse_invocation( }; scope.enter_scope(); - let (classified_block, err) = classify_block(&lite_block, scope); + let (mut classified_block, err) = classify_block(&lite_block, scope); scope.exit_scope(); + classified_block.set_redirect(ExternalRedirection::Stdout); + ( SpannedExpression::new(Expression::Invocation(classified_block), lite_arg.span), err, @@ -2044,6 +2046,7 @@ pub fn classify_block( output.definitions.insert(name, definition.clone()); } } + output.infer_params(); (output, error) } diff --git a/crates/nu-stream/src/output.rs b/crates/nu-stream/src/output.rs index f934109472..2abc4f817a 100644 --- a/crates/nu-stream/src/output.rs +++ b/crates/nu-stream/src/output.rs @@ -22,8 +22,9 @@ impl OutputStream { } pub fn empty() -> OutputStream { - let v: VecDeque = VecDeque::new(); - v.into() + OutputStream { + values: Box::new(std::iter::empty()), + } } pub fn one(item: impl Into) -> OutputStream {