From b52dbcc8efeaf5a183cec8951b80d6ddd980ec4c Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 26 Jan 2020 07:10:20 +1300 Subject: [PATCH] Separate dissimilar tables into separate tables (#1281) * Allow the table command to stream * Next part of table view refactor --- src/commands/autoview.rs | 3 --- src/commands/table.rs | 41 +++++++++++++++++++++++++++++++--------- src/format/table.rs | 11 +++-------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/commands/autoview.rs b/src/commands/autoview.rs index 7a6dbcafd3..6dbfa832de 100644 --- a/src/commands/autoview.rs +++ b/src/commands/autoview.rs @@ -41,9 +41,6 @@ pub fn autoview( let table = context.get_command("table"); Ok(OutputStream::new(async_stream! { - //let mut output_stream: OutputStream = context.input.into(); - //let next = output_stream.try_next().await; - let mut input_stream = context.input; match input_stream.next().await { diff --git a/src/commands/table.rs b/src/commands/table.rs index e136b9525f..6f75b63747 100644 --- a/src/commands/table.rs +++ b/src/commands/table.rs @@ -54,18 +54,41 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result = VecDeque::new(); for _ in 0..STREAM_PAGE_SIZE { - match args.input.next().await { - Some(a) => { - new_input.push_back(a); - } - _ => { - finished = true; - break; + if let Some(val) = delay_slot { + new_input.push_back(val); + delay_slot = None; + } else { + match args.input.next().await { + Some(a) => { + if !new_input.is_empty() { + if let Some(descs) = new_input.get(0) { + let descs = descs.data_descriptors(); + let compare = a.data_descriptors(); + if descs != compare { + delay_slot = Some(a); + break; + } else { + new_input.push_back(a); + } + } else { + new_input.push_back(a); + } + } else { + new_input.push_back(a); + } + } + _ => { + finished = true; + break; + } } + } } @@ -80,7 +103,7 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result, starting_idx: usize) -> Entries { let mut entries = vec![]; - let values_len = values.len(); if headers.is_empty() { headers.push("".to_string()); @@ -138,17 +137,13 @@ fn values_to_entries(values: &[Value], headers: &mut Vec, starting_idx: }) .collect(); - if values_len > 1 { - // Indices are green, bold, right-aligned: - row.insert(0, ((starting_idx + idx).to_string(), "Fgbr")); - } + // Indices are green, bold, right-aligned: + row.insert(0, ((starting_idx + idx).to_string(), "Fgbr")); entries.push(row); } - if values_len > 1 { - headers.insert(0, "#".to_owned()); - } + headers.insert(0, "#".to_owned()); entries }