From 139775dcce565971d8a24ccd99b84bc0e8afb9fc Mon Sep 17 00:00:00 2001 From: JT Date: Sun, 26 Sep 2021 06:37:25 +1300 Subject: [PATCH] improve table for lists --- crates/nu-command/src/table.rs | 30 ++++++++++++++++------------- crates/nu-protocol/src/value/mod.rs | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/nu-command/src/table.rs b/crates/nu-command/src/table.rs index 25914f6e22..b5122d70c1 100644 --- a/crates/nu-command/src/table.rs +++ b/crates/nu-command/src/table.rs @@ -66,26 +66,30 @@ fn convert_to_table(iter: impl IntoIterator) -> Option" { - Ok(item.clone()) - } else { - item.clone().follow_cell_path(&[PathMember::String { - val: header.into(), - span: Span::unknown(), - }]) - }; + 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(), + }]) + }; - match result { - Ok(value) => row.push(value.into_string()), - Err(_) => row.push(String::new()), + match result { + Ok(value) => row.push(value.into_string()), + Err(_) => row.push(String::new()), + } } } diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index f27dc45bbc..bdb31de395 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -290,7 +290,7 @@ impl Value { pub fn columns(&self) -> Vec { match self { Value::Record { cols, .. } => cols.clone(), - _ => vec!["".into()], + _ => vec![], } } }