forked from extern/nushell
Separate dissimilar tables into separate tables (#1281)
* Allow the table command to stream * Next part of table view refactor
This commit is contained in:
parent
4429a75e17
commit
b52dbcc8ef
@ -41,9 +41,6 @@ pub fn autoview(
|
|||||||
let table = context.get_command("table");
|
let table = context.get_command("table");
|
||||||
|
|
||||||
Ok(OutputStream::new(async_stream! {
|
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;
|
let mut input_stream = context.input;
|
||||||
|
|
||||||
match input_stream.next().await {
|
match input_stream.next().await {
|
||||||
|
@ -54,19 +54,42 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut delay_slot = None;
|
||||||
|
|
||||||
while !finished {
|
while !finished {
|
||||||
let mut new_input = VecDeque::new();
|
let mut new_input: VecDeque<Value> = VecDeque::new();
|
||||||
|
|
||||||
for _ in 0..STREAM_PAGE_SIZE {
|
for _ in 0..STREAM_PAGE_SIZE {
|
||||||
|
if let Some(val) = delay_slot {
|
||||||
|
new_input.push_back(val);
|
||||||
|
delay_slot = None;
|
||||||
|
} else {
|
||||||
match args.input.next().await {
|
match args.input.next().await {
|
||||||
Some(a) => {
|
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);
|
new_input.push_back(a);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
new_input.push_back(a);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new_input.push_back(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
finished = true;
|
finished = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let input: Vec<Value> = new_input.into();
|
let input: Vec<Value> = new_input.into();
|
||||||
@ -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
|
// Needed for async_stream to type check
|
||||||
|
@ -96,7 +96,6 @@ impl TableView {
|
|||||||
|
|
||||||
fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx: usize) -> Entries {
|
fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx: usize) -> Entries {
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
let values_len = values.len();
|
|
||||||
|
|
||||||
if headers.is_empty() {
|
if headers.is_empty() {
|
||||||
headers.push("<value>".to_string());
|
headers.push("<value>".to_string());
|
||||||
@ -138,17 +137,13 @@ fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx:
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if values_len > 1 {
|
|
||||||
// Indices are green, bold, right-aligned:
|
// Indices are green, bold, right-aligned:
|
||||||
row.insert(0, ((starting_idx + idx).to_string(), "Fgbr"));
|
row.insert(0, ((starting_idx + idx).to_string(), "Fgbr"));
|
||||||
}
|
|
||||||
|
|
||||||
entries.push(row);
|
entries.push(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
if values_len > 1 {
|
|
||||||
headers.insert(0, "#".to_owned());
|
headers.insert(0, "#".to_owned());
|
||||||
}
|
|
||||||
|
|
||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user