From 23fec8eb0d6d96834ee242960b02dc3c446cb95f Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Thu, 14 Dec 2023 03:16:23 +0800 Subject: [PATCH] Fix piping output logic (#11317) # Description Fixes: #11295 Sorry for introducing such issue. The issue is caused by we wrongly set `redirect_stdout` and `redirect_stderr` during eval, take the following as example: ```nushell ls | bat --paging always ``` When running `bat --paging always`, `redirect_stdout` should be `false`. But before this pr, it's set to true due to `ls` command, and then the `true` value will go to all remaining commands. # User-Facing Changes NaN # Tests + Formatting Sorry I don't think we have a way to test it. Because it needs to be tested on interactive command like `nvim`. # After Submitting NaN --- crates/nu-engine/src/eval.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index b4a3b632e..4fe6f17e3 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -603,8 +603,8 @@ pub fn eval_block( stack: &mut Stack, block: &Block, mut input: PipelineData, - mut redirect_stdout: bool, - mut redirect_stderr: bool, + redirect_stdout: bool, + redirect_stderr: bool, ) -> Result { // if Block contains recursion, make sure we don't recurse too deeply (to avoid stack overflow) if let Some(recursive) = block.recursive { @@ -629,6 +629,8 @@ pub fn eval_block( let elements = &pipeline.elements; let elements_length = elements.len(); for (idx, element) in elements.iter().enumerate() { + let mut redirect_stdout = redirect_stdout; + let mut redirect_stderr = redirect_stderr; if !redirect_stderr && idx < elements_length - 1 { let next_element = &elements[idx + 1]; if matches!(