forked from extern/nushell
improve table for lists
This commit is contained in:
parent
22c6ed4718
commit
abac7e3795
@ -65,24 +65,28 @@ fn convert_to_table(iter: impl IntoIterator<Item = Value>) -> Option<nu_table::T
|
|||||||
let mut iter = iter.into_iter().peekable();
|
let mut iter = iter.into_iter().peekable();
|
||||||
|
|
||||||
if let Some(first) = iter.peek() {
|
if let Some(first) = iter.peek() {
|
||||||
let mut headers = match first {
|
let mut headers = first.columns();
|
||||||
Value::Record { .. } => first.columns(),
|
|
||||||
_ => ["Column_0".to_string()].to_vec(),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if !headers.is_empty() {
|
||||||
headers.insert(0, "#".into());
|
headers.insert(0, "#".into());
|
||||||
|
}
|
||||||
|
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
|
|
||||||
for (row_num, item) in iter.enumerate() {
|
for (row_num, item) in iter.enumerate() {
|
||||||
let mut row = vec![row_num.to_string()];
|
let mut row = vec![row_num.to_string()];
|
||||||
|
|
||||||
|
if headers.is_empty() {
|
||||||
|
row.push(item.into_string())
|
||||||
|
} else {
|
||||||
for header in headers.iter().skip(1) {
|
for header in headers.iter().skip(1) {
|
||||||
let result = match item {
|
let result = match item {
|
||||||
Value::Record { .. } => item.clone().follow_cell_path(&[PathMember::String {
|
Value::Record { .. } => {
|
||||||
|
item.clone().follow_cell_path(&[PathMember::String {
|
||||||
val: header.into(),
|
val: header.into(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
}]),
|
}])
|
||||||
|
}
|
||||||
_ => Ok(item.clone()),
|
_ => Ok(item.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,6 +95,7 @@ fn convert_to_table(iter: impl IntoIterator<Item = Value>) -> Option<nu_table::T
|
|||||||
Err(_) => row.push(String::new()),
|
Err(_) => row.push(String::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data.push(row);
|
data.push(row);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user