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.
This commit is contained in:
Reilly Wood 2023-02-09 23:23:46 -08:00 committed by GitHub
parent 00601f1835
commit ddb7e4e179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<Spanned<String>, 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()?);
}