Separate dissimilar tables into separate tables (#1281)

* Allow the table command to stream

* Next part of table view refactor
This commit is contained in:
Jonathan Turner 2020-01-26 07:10:20 +13:00 committed by GitHub
parent 4429a75e17
commit b52dbcc8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 20 deletions

View File

@ -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 {

View File

@ -54,18 +54,41 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
}
};
let mut delay_slot = None;
while !finished {
let mut new_input = VecDeque::new();
let mut new_input: VecDeque<Value> = 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<OutputStream,
}
}
start_number += STREAM_PAGE_SIZE;
start_number += input.len();
}
// Needed for async_stream to type check

View File

@ -96,7 +96,6 @@ impl TableView {
fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx: usize) -> Entries {
let mut entries = vec![];
let values_len = values.len();
if headers.is_empty() {
headers.push("<value>".to_string());
@ -138,17 +137,13 @@ fn values_to_entries(values: &[Value], headers: &mut Vec<String>, 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
}