mirror of
https://github.com/nushell/nushell
synced 2025-01-13 13:49:21 +00:00
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
3 changed files with 35 additions and 20 deletions
|
@ -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 {
|
||||
|
|
|
@ -54,19 +54,42 @@ 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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
entries.push(row);
|
||||
}
|
||||
|
||||
if values_len > 1 {
|
||||
headers.insert(0, "#".to_owned());
|
||||
}
|
||||
|
||||
entries
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue