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
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 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("<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("</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 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("|");
for header in &headers {
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![];
if headers.is_empty() {
headers.push("<value>".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 == "<value>" {
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<Cell> = 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(