nu-table: Don't show empty header (#6035)

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt 2022-07-13 14:43:39 +03:00 committed by GitHub
parent ad9449bf00
commit f2a79cf381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -167,11 +167,7 @@ impl Command for Table {
]) ])
} }
let table = nu_table::Table { let table = nu_table::Table::new(None, output, load_theme_from_config(config));
headers: None,
data: output,
theme: load_theme_from_config(config),
};
let result = nu_table::draw_table(&table, term_width, &color_hm, config) let result = nu_table::draw_table(&table, term_width, &color_hm, config)
.unwrap_or_else(|| format!("Couldn't fit table into {} columns!", term_width)); .unwrap_or_else(|| format!("Couldn't fit table into {} columns!", term_width));
@ -429,8 +425,8 @@ fn convert_to_table(
data.push(row); data.push(row);
} }
Ok(Some(nu_table::Table { Ok(Some(nu_table::Table::new(
headers: Some( Some(
headers headers
.into_iter() .into_iter()
.map(|x| StyledString { .map(|x| StyledString {
@ -442,8 +438,7 @@ fn convert_to_table(
}) })
.collect(), .collect(),
), ),
data: data data.into_iter()
.into_iter()
.map(|x| { .map(|x| {
x.into_iter() x.into_iter()
.enumerate() .enumerate()
@ -477,8 +472,8 @@ fn convert_to_table(
.collect::<Vec<StyledString>>() .collect::<Vec<StyledString>>()
}) })
.collect(), .collect(),
theme: load_theme_from_config(config), load_theme_from_config(config),
})) )))
} else { } else {
Ok(None) Ok(None)
} }

View File

@ -19,9 +19,9 @@ use crate::{
#[derive(Debug)] #[derive(Debug)]
pub struct Table { pub struct Table {
pub headers: Option<Vec<StyledString>>, headers: Option<Vec<StyledString>>,
pub data: Vec<Vec<StyledString>>, data: Vec<Vec<StyledString>>,
pub theme: TableTheme, theme: TableTheme,
} }
impl Table { impl Table {
@ -30,6 +30,11 @@ impl Table {
data: Vec<Vec<StyledString>>, data: Vec<Vec<StyledString>>,
theme: TableTheme, theme: TableTheme,
) -> Table { ) -> Table {
let headers = match headers {
Some(headers) if headers.is_empty() => None,
headers => headers,
};
Table { Table {
headers, headers,
data, data,