nu-table: Fix header style (again 2x) (#6073)

* nu-table: Fix header style

It did appeared again after my small change...

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>

* nu-table: Add a empty header style test

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt 2022-07-18 19:45:21 +03:00 committed by GitHub
parent eeaca50dee
commit 41669e60c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 12 deletions

6
Cargo.lock generated
View File

@ -3171,7 +3171,7 @@ checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
[[package]] [[package]]
name = "papergrid" name = "papergrid"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" source = "git+https://github.com/zhiburt/tabled?rev=5ac9aa53196cd5bbf570daa5357a76aa238722c1#5ac9aa53196cd5bbf570daa5357a76aa238722c1"
dependencies = [ dependencies = [
"ansi-str 0.1.1", "ansi-str 0.1.1",
"bytecount", "bytecount",
@ -4789,7 +4789,7 @@ dependencies = [
[[package]] [[package]]
name = "tabled" name = "tabled"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" source = "git+https://github.com/zhiburt/tabled?rev=5ac9aa53196cd5bbf570daa5357a76aa238722c1#5ac9aa53196cd5bbf570daa5357a76aa238722c1"
dependencies = [ dependencies = [
"ansi-str 0.2.0", "ansi-str 0.2.0",
"papergrid", "papergrid",
@ -4800,7 +4800,7 @@ dependencies = [
[[package]] [[package]]
name = "tabled_derive" name = "tabled_derive"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" source = "git+https://github.com/zhiburt/tabled?rev=5ac9aa53196cd5bbf570daa5357a76aa238722c1#5ac9aa53196cd5bbf570daa5357a76aa238722c1"
dependencies = [ dependencies = [
"heck 0.4.0", "heck 0.4.0",
"proc-macro-error", "proc-macro-error",

View File

@ -16,4 +16,4 @@ nu-ansi-term = "0.46.0"
nu-protocol = { path = "../nu-protocol", version = "0.65.1" } nu-protocol = { path = "../nu-protocol", version = "0.65.1" }
strip-ansi-escapes = "0.1.1" strip-ansi-escapes = "0.1.1"
atty = "0.2.14" atty = "0.2.14"
tabled = { git = "https://github.com/zhiburt/tabled", rev = "0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62", features = ["color"] } tabled = { git = "https://github.com/zhiburt/tabled", rev = "5ac9aa53196cd5bbf570daa5357a76aa238722c1", features = ["color"] }

View File

@ -257,7 +257,12 @@ fn load_theme(
with_footer: bool, with_footer: bool,
with_header: bool, with_header: bool,
) -> tabled::Table { ) -> tabled::Table {
table = table.with(theme.theme.clone()); let mut theme = theme.theme.clone();
if !with_header {
theme.set_lines(HashMap::default());
}
table = table.with(theme);
if let Some(color) = color_hm.get("separator") { if let Some(color) = color_hm.get("separator") {
let color = color.paint(" ").to_string(); let color = color.paint(" ").to_string();
@ -274,10 +279,6 @@ fn load_theme(
); );
} }
if !with_header {
table = table.with(RemoveHeaderLine);
}
table table
} }

View File

@ -1,4 +1,4 @@
use tabled::{papergrid::Line, style::RawStyle, Style}; use tabled::style::{Line, RawStyle, Style};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TableTheme { pub struct TableTheme {
@ -20,7 +20,9 @@ impl TableTheme {
pub fn light() -> TableTheme { pub fn light() -> TableTheme {
Self { Self {
theme: Style::blank().lines([(1, Line::short('─', '─'))]).into(), theme: Style::blank()
.lines([(1, Line::new(Some('─'), Some('─'), None, None))])
.into(),
} }
} }
@ -41,7 +43,7 @@ impl TableTheme {
.top('❤') .top('❤')
.bottom('❤') .bottom('❤')
.vertical('❤') .vertical('❤')
.lines([(1, Line::short('❤', '❤'))]) .lines([(1, Line::new(Some('❤'), Some('❤'), None, None))])
.into(), .into(),
} }
} }

View File

@ -0,0 +1,34 @@
use std::collections::HashMap;
use nu_protocol::Config;
use nu_table::{Alignments, StyledString, Table, TableTheme, TextStyle};
#[test]
fn test_rounded_style() {
let headers = vec![no_style_str("Hello"), no_style_str("World")];
let data = vec![vec![no_style_str("1"), no_style_str("2")]];
let table = Table::new(headers, data.clone(), TableTheme::rounded());
let table = table.draw_table(
&Config::default(),
&HashMap::default(),
Alignments::default(),
std::usize::MAX,
);
assert_eq!(table.as_deref(), Some("╭───────┬───────╮\n│ Hello │ World │\n├───────┼───────┤\n│ 1 │ 2 │\n╰───────┴───────╯"));
let table = Table::new(Vec::new(), data, TableTheme::rounded());
let table = table.draw_table(
&Config::default(),
&HashMap::default(),
Alignments::default(),
std::usize::MAX,
);
assert_eq!(table.as_deref(), Some("╭───┬───╮\n│ 1 │ 2 │\n╰───┴───╯"));
}
fn no_style_str(text: &str) -> StyledString {
StyledString::new(text.to_owned(), TextStyle::default())
}