From 42eb658c37c7d6d6c92be37c927e62445260caa6 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 11 May 2020 14:47:27 +1200 Subject: [PATCH] Add a simplified list view (#1749) --- crates/nu-cli/src/commands/to_html.rs | 4 ++-- crates/nu-cli/src/commands/to_md.rs | 2 +- crates/nu-cli/src/format/table.rs | 10 +++++++--- crates/nu-protocol/src/type_shape.rs | 4 ++-- crates/nu-protocol/src/value.rs | 6 ++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/nu-cli/src/commands/to_html.rs b/crates/nu-cli/src/commands/to_html.rs index bd5f3bef25..36867b290b 100644 --- a/crates/nu-cli/src/commands/to_html.rs +++ b/crates/nu-cli/src/commands/to_html.rs @@ -39,7 +39,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result 1 || headers[0] != "") { + if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") { output_string.push_str(""); output_string.push_str(""); @@ -109,7 +109,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result 1 || headers[0] != "") { + if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") { output_string.push_str("
"); } output_string.push_str(""); diff --git a/crates/nu-cli/src/commands/to_md.rs b/crates/nu-cli/src/commands/to_md.rs index 0bc5b1a6f9..9bf98b7c3a 100644 --- a/crates/nu-cli/src/commands/to_md.rs +++ b/crates/nu-cli/src/commands/to_md.rs @@ -38,7 +38,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result 1 || headers[0] != "") { + if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") { output_string.push_str("|"); for header in &headers { output_string.push_str(&htmlescape::encode_minimal(&header)); diff --git a/crates/nu-cli/src/format/table.rs b/crates/nu-cli/src/format/table.rs index 2169817ec2..3d05777d85 100644 --- a/crates/nu-cli/src/format/table.rs +++ b/crates/nu-cli/src/format/table.rs @@ -89,14 +89,14 @@ fn values_to_entries(values: &[Value], headers: &mut Vec, starting_idx: let mut entries = vec![]; if headers.is_empty() { - headers.push("".to_string()); + headers.push("".to_string()); } for (idx, value) in values.iter().enumerate() { let mut row: Vec<(String, &'static str)> = headers .iter() .map(|d: &String| { - if d == "" { + if d == "" { match value { Value { value: UntaggedValue::Row(..), @@ -374,6 +374,8 @@ impl RenderView for TableView { } } + let skip_headers = self.headers.len() == 2 && self.headers[1] == ""; + let header: Vec = self .headers .iter() @@ -387,7 +389,9 @@ impl RenderView for TableView { }) .collect(); - table.set_titles(Row::new(header)); + if !skip_headers { + table.set_titles(Row::new(header)); + } for row in &self.entries { table.add_row(Row::new( diff --git a/crates/nu-protocol/src/type_shape.rs b/crates/nu-protocol/src/type_shape.rs index 1341b60315..c3897fa936 100644 --- a/crates/nu-protocol/src/type_shape.rs +++ b/crates/nu-protocol/src/type_shape.rs @@ -239,7 +239,7 @@ impl PrettyDebug for Type { row.map.iter().map(|(key, ty)| { (b::key(match key { Column::String(string) => string.clone(), - Column::Value => "".to_string(), + Column::Value => "".to_string(), }) + b::delimit("(", ty.pretty(), ")").into_kind()) .nest() }), @@ -303,7 +303,7 @@ impl<'a> PrettyDebug for DebugEntry<'a> { fn pretty(&self) -> DebugDocBuilder { b::key(match self.key { Column::String(string) => string.clone(), - Column::Value => "".to_string(), + Column::Value => "".to_string(), }) + b::delimit("(", self.value.pretty(), ")").into_kind() } } diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index 233a1f4704..91ae29907b 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -32,8 +32,10 @@ use std::time::SystemTime; pub enum UntaggedValue { /// A primitive (or fundamental) type of values Primitive(Primitive), + /// A table row Row(Dictionary), + /// A full inner (or embedded) table Table(Vec), @@ -494,13 +496,13 @@ impl std::ops::Add for Value { pub fn merge_descriptors(values: &[Value]) -> Vec { let mut ret: Vec = vec![]; - let value_column = "".to_string(); + let value_column = "".to_string(); for value in values { let descs = value.data_descriptors(); if descs.is_empty() { if !ret.contains(&value_column) { - ret.push("".to_string()); + ret.push("".to_string()); } } else { for desc in value.data_descriptors() {