Add a simplified list view (#1749)

This commit is contained in:
Jonathan Turner 2020-05-11 14:47:27 +12:00 committed by GitHub
parent a2e9bbd358
commit 42eb658c37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 10 deletions

View file

@ -39,7 +39,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let headers = nu_protocol::merge_descriptors(&input); let headers = nu_protocol::merge_descriptors(&input);
let mut output_string = "<html><body>".to_string(); let mut output_string = "<html><body>".to_string();
if !headers.is_empty() && (headers.len() > 1 || headers[0] != "<value>") { if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") {
output_string.push_str("<table>"); output_string.push_str("<table>");
output_string.push_str("<tr>"); output_string.push_str("<tr>");
@ -109,7 +109,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
} }
} }
if !headers.is_empty() && (headers.len() > 1 || headers[0] != "<value>") { if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") {
output_string.push_str("</table>"); output_string.push_str("</table>");
} }
output_string.push_str("</body></html>"); output_string.push_str("</body></html>");

View file

@ -38,7 +38,7 @@ fn to_html(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let headers = nu_protocol::merge_descriptors(&input); let headers = nu_protocol::merge_descriptors(&input);
let mut output_string = String::new(); let mut output_string = String::new();
if !headers.is_empty() && (headers.len() > 1 || headers[0] != "<value>") { if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") {
output_string.push_str("|"); output_string.push_str("|");
for header in &headers { for header in &headers {
output_string.push_str(&htmlescape::encode_minimal(&header)); output_string.push_str(&htmlescape::encode_minimal(&header));

View file

@ -89,14 +89,14 @@ fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx:
let mut entries = vec![]; let mut entries = vec![];
if headers.is_empty() { if headers.is_empty() {
headers.push("<value>".to_string()); headers.push("".to_string());
} }
for (idx, value) in values.iter().enumerate() { for (idx, value) in values.iter().enumerate() {
let mut row: Vec<(String, &'static str)> = headers let mut row: Vec<(String, &'static str)> = headers
.iter() .iter()
.map(|d: &String| { .map(|d: &String| {
if d == "<value>" { if d == "" {
match value { match value {
Value { Value {
value: UntaggedValue::Row(..), value: UntaggedValue::Row(..),
@ -374,6 +374,8 @@ impl RenderView for TableView {
} }
} }
let skip_headers = self.headers.len() == 2 && self.headers[1] == "";
let header: Vec<Cell> = self let header: Vec<Cell> = self
.headers .headers
.iter() .iter()
@ -387,7 +389,9 @@ impl RenderView for TableView {
}) })
.collect(); .collect();
table.set_titles(Row::new(header)); if !skip_headers {
table.set_titles(Row::new(header));
}
for row in &self.entries { for row in &self.entries {
table.add_row(Row::new( table.add_row(Row::new(

View file

@ -239,7 +239,7 @@ impl PrettyDebug for Type {
row.map.iter().map(|(key, ty)| { row.map.iter().map(|(key, ty)| {
(b::key(match key { (b::key(match key {
Column::String(string) => string.clone(), Column::String(string) => string.clone(),
Column::Value => "<value>".to_string(), Column::Value => "".to_string(),
}) + b::delimit("(", ty.pretty(), ")").into_kind()) }) + b::delimit("(", ty.pretty(), ")").into_kind())
.nest() .nest()
}), }),
@ -303,7 +303,7 @@ impl<'a> PrettyDebug for DebugEntry<'a> {
fn pretty(&self) -> DebugDocBuilder { fn pretty(&self) -> DebugDocBuilder {
b::key(match self.key { b::key(match self.key {
Column::String(string) => string.clone(), Column::String(string) => string.clone(),
Column::Value => "<value>".to_string(), Column::Value => "".to_string(),
}) + b::delimit("(", self.value.pretty(), ")").into_kind() }) + b::delimit("(", self.value.pretty(), ")").into_kind()
} }
} }

View file

@ -32,8 +32,10 @@ use std::time::SystemTime;
pub enum UntaggedValue { pub enum UntaggedValue {
/// A primitive (or fundamental) type of values /// A primitive (or fundamental) type of values
Primitive(Primitive), Primitive(Primitive),
/// A table row /// A table row
Row(Dictionary), Row(Dictionary),
/// A full inner (or embedded) table /// A full inner (or embedded) table
Table(Vec<Value>), Table(Vec<Value>),
@ -494,13 +496,13 @@ impl std::ops::Add for Value {
pub fn merge_descriptors(values: &[Value]) -> Vec<String> { pub fn merge_descriptors(values: &[Value]) -> Vec<String> {
let mut ret: Vec<String> = vec![]; let mut ret: Vec<String> = vec![];
let value_column = "<value>".to_string(); let value_column = "".to_string();
for value in values { for value in values {
let descs = value.data_descriptors(); let descs = value.data_descriptors();
if descs.is_empty() { if descs.is_empty() {
if !ret.contains(&value_column) { if !ret.contains(&value_column) {
ret.push("<value>".to_string()); ret.push("".to_string());
} }
} else { } else {
for desc in value.data_descriptors() { for desc in value.data_descriptors() {