From ddb7e4e179d747766515238c4c1b8d0db2a434b1 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Thu, 9 Feb 2023 23:23:46 -0800 Subject: [PATCH] Check ctrl+c when collecting a RawStream (#8020) I noticed that `open some_big_file | into binary` cannot be cancelled with `ctrl+c`. This small PR fixes that by checking `ctrl+c` in `RawStream::into_bytes()`, and does the same in `RawStream::into_string()` for good measure. --- crates/nu-protocol/src/value/stream.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/nu-protocol/src/value/stream.rs b/crates/nu-protocol/src/value/stream.rs index e826a7013a..f00e90b9c8 100644 --- a/crates/nu-protocol/src/value/stream.rs +++ b/crates/nu-protocol/src/value/stream.rs @@ -34,6 +34,9 @@ impl RawStream { let mut output = vec![]; for item in self.stream { + if nu_utils::ctrl_c::was_pressed(&self.ctrlc) { + break; + } output.extend(item?); } @@ -46,8 +49,12 @@ impl RawStream { pub fn into_string(self) -> Result, ShellError> { let mut output = String::new(); let span = self.span; + let ctrlc = &self.ctrlc.clone(); for item in self { + if nu_utils::ctrl_c::was_pressed(ctrlc) { + break; + } output.push_str(&item?.as_string()?); }