Revert "Add support for optional list stream output formatting (#6325)" (#6454)

This reverts commit ec4e3a6d5c.
This commit is contained in:
Darren Schroeder
2022-08-31 18:09:40 -05:00
committed by GitHub
parent 3ec53e544c
commit 4858a9a817
21 changed files with 60 additions and 181 deletions

View File

@@ -90,7 +90,7 @@ prints out the list properly."#
}
PipelineData::ListStream(stream, ..) => {
// dbg!("value::stream");
let data = convert_to_list(stream.map(|(v, _)| v), config, call.head);
let data = convert_to_list(stream, config, call.head);
if let Some(items) = data {
Ok(create_grid_output(
items,

View File

@@ -266,7 +266,7 @@ fn handle_row_stream(
let show_clickable_links = config.show_clickable_links_in_ls && !in_ssh_session;
ListStream::from_stream(
stream.map(move |(mut x, _)| match &mut x {
stream.map(move |mut x| match &mut x {
Value::Record { cols, vals, .. } => {
let mut idx = 0;
@@ -564,11 +564,7 @@ impl Iterator for PagingTableCreator {
let mut idx = 0;
// Pull from stream until time runs out or we have enough items
for (mut item, formatter) in self.stream.by_ref() {
if let Some(formatter) = formatter {
item = formatter.format(item);
}
for item in self.stream.by_ref() {
batch.push(item);
idx += 1;
@@ -633,70 +629,3 @@ fn load_theme_from_config(config: &Config) -> TableTheme {
_ => nu_table::TableTheme::rounded(),
}
}
#[cfg(test)]
mod tests {
use nu_protocol::ValueFormatter;
use super::*;
#[test]
fn list_stream_value_formatters() {
let span = Span::test_data();
let ctrlc = None;
let config = Config {
use_ansi_coloring: false,
..<_>::default()
};
let hex_formatter = ValueFormatter::from_fn(|value| {
let (value, span) = match value {
Value::Int { val, span } => (val, span),
_ => return value,
};
let value = format!("0x{:016x}", value);
Value::string(value, span)
});
let stream = ListStream::from_stream(
[
(Value::int(42, span), Some(hex_formatter.clone())),
(Value::int(777, span), None),
(Value::int(-1, span), Some(hex_formatter)),
]
.into_iter(),
ctrlc.clone(),
);
let paging_table_creator = PagingTableCreator {
head: span,
stream,
ctrlc,
config,
row_offset: 0,
width_param: Some(80),
};
let mut output = Vec::new();
for chunk in paging_table_creator {
let chunk = chunk.unwrap();
output.extend(chunk);
}
let output = String::from_utf8(output).unwrap();
assert_eq!(
output,
concat!(
"╭───┬────────────────────╮\n",
"│ 0 │ 0x000000000000002a │\n",
"│ 1 │ 777 │\n",
"│ 2 │ 0xffffffffffffffff │\n",
"╰───┴────────────────────╯"
)
)
}
}