mirror of
https://github.com/nushell/nushell.git
synced 2024-12-17 04:31:21 +01:00
improve table for lists
This commit is contained in:
parent
a2996abd47
commit
139775dcce
@ -66,17 +66,20 @@ fn convert_to_table(iter: impl IntoIterator<Item = Value>) -> Option<nu_table::T
|
||||
|
||||
if let Some(first) = iter.peek() {
|
||||
let mut headers = first.columns();
|
||||
if !headers.is_empty() {
|
||||
headers.insert(0, "#".into());
|
||||
}
|
||||
|
||||
let mut data = vec![];
|
||||
|
||||
for (row_num, item) in iter.enumerate() {
|
||||
let mut row = vec![row_num.to_string()];
|
||||
|
||||
for header in headers.iter().skip(1) {
|
||||
let result = if header == "<value>" {
|
||||
Ok(item.clone())
|
||||
if headers.is_empty() {
|
||||
row.push(item.into_string())
|
||||
} else {
|
||||
for header in headers.iter().skip(1) {
|
||||
let result = {
|
||||
item.clone().follow_cell_path(&[PathMember::String {
|
||||
val: header.into(),
|
||||
span: Span::unknown(),
|
||||
@ -88,6 +91,7 @@ fn convert_to_table(iter: impl IntoIterator<Item = Value>) -> Option<nu_table::T
|
||||
Err(_) => row.push(String::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.push(row);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ impl Value {
|
||||
pub fn columns(&self) -> Vec<String> {
|
||||
match self {
|
||||
Value::Record { cols, .. } => cols.clone(),
|
||||
_ => vec!["<value>".into()],
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user