ListStream touchup (#12524)

# Description

Does some misc changes to `ListStream`:
- Moves it into its own module/file separate from `RawStream`.
- `ListStream`s now have an associated `Span`.
- This required changes to `ListStreamInfo` in `nu-plugin`. Note sure if
this is a breaking change for the plugin protocol.
- Hides the internals of `ListStream` but also adds a few more methods.
- This includes two functions to more easily alter a stream (these take
a `ListStream` and return a `ListStream` instead of having to go through
the whole `into_pipeline_data(..)` route).
  -  `map`: takes a `FnMut(Value) -> Value`
  - `modify`: takes a function to modify the inner stream.
This commit is contained in:
Ian Manske
2024-05-05 16:00:59 +00:00
committed by GitHub
parent 3143ded374
commit e879d4ecaf
106 changed files with 957 additions and 874 deletions

View File

@ -84,8 +84,11 @@ impl Command for FromJson {
.collect()
};
Ok(converted_lines
.into_pipeline_data_with_metadata(metadata, engine_state.ctrlc.clone()))
Ok(converted_lines.into_pipeline_data_with_metadata(
span,
engine_state.ctrlc.clone(),
metadata,
))
} else if strict {
Ok(convert_string_to_value_strict(&string_input, span)?
.into_pipeline_data_with_metadata(metadata))

View File

@ -109,10 +109,9 @@ MessagePack: https://msgpack.org/
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = input.span().unwrap_or(call.head);
let objects = call.has_flag(engine_state, stack, "objects")?;
let opts = Opts {
span,
span: call.head,
objects,
ctrlc: engine_state.ctrlc.clone(),
};
@ -126,10 +125,10 @@ MessagePack: https://msgpack.org/
stdout: Some(raw_stream),
..
} => read_msgpack(ReadRawStream::new(raw_stream), opts),
_ => Err(ShellError::PipelineMismatch {
input => Err(ShellError::PipelineMismatch {
exp_input_type: "binary".into(),
dst_span: call.head,
src_span: span,
src_span: input.span().unwrap_or(call.head),
}),
}
}
@ -257,7 +256,7 @@ pub(crate) fn read_msgpack(
None
}
})
.into_pipeline_data(ctrlc))
.into_pipeline_data(span, ctrlc))
} else {
// Read a single value and then make sure it's EOF
let result = read_value(&mut input, span, 0)?;

View File

@ -1,6 +1,6 @@
use chrono_humanize::HumanTime;
use nu_engine::command_prelude::*;
use nu_protocol::{format_duration, format_filesize_from_conf, Config, ListStream, RawStream};
use nu_protocol::{format_duration, format_filesize_from_conf, Config, RawStream, ValueIterator};
#[derive(Clone)]
pub struct ToText;
@ -41,7 +41,7 @@ impl Command for ToText {
Ok(PipelineData::ExternalStream {
stdout: Some(RawStream::new(
Box::new(ListStreamIterator {
stream,
stream: stream.into_inner(),
separator: line_ending.into(),
config: config.clone(),
}),
@ -86,7 +86,7 @@ impl Command for ToText {
}
struct ListStreamIterator {
stream: ListStream,
stream: ValueIterator,
separator: String,
config: Config,
}