mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
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:
parent
eeaca50dee
commit
41669e60c8
5 changed files with 49 additions and 12 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -3171,7 +3171,7 @@ checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
|
|||
[[package]]
|
||||
name = "papergrid"
|
||||
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 = [
|
||||
"ansi-str 0.1.1",
|
||||
"bytecount",
|
||||
|
@ -4789,7 +4789,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "tabled"
|
||||
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 = [
|
||||
"ansi-str 0.2.0",
|
||||
"papergrid",
|
||||
|
@ -4800,7 +4800,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "tabled_derive"
|
||||
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 = [
|
||||
"heck 0.4.0",
|
||||
"proc-macro-error",
|
||||
|
|
|
@ -16,4 +16,4 @@ nu-ansi-term = "0.46.0"
|
|||
nu-protocol = { path = "../nu-protocol", version = "0.65.1" }
|
||||
strip-ansi-escapes = "0.1.1"
|
||||
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"] }
|
||||
|
|
|
@ -257,7 +257,12 @@ fn load_theme(
|
|||
with_footer: bool,
|
||||
with_header: bool,
|
||||
) -> 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") {
|
||||
let color = color.paint(" ").to_string();
|
||||
|
@ -274,10 +279,6 @@ fn load_theme(
|
|||
);
|
||||
}
|
||||
|
||||
if !with_header {
|
||||
table = table.with(RemoveHeaderLine);
|
||||
}
|
||||
|
||||
table
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use tabled::{papergrid::Line, style::RawStyle, Style};
|
||||
use tabled::style::{Line, RawStyle, Style};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableTheme {
|
||||
|
@ -20,7 +20,9 @@ impl TableTheme {
|
|||
|
||||
pub fn light() -> TableTheme {
|
||||
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('❤')
|
||||
.bottom('❤')
|
||||
.vertical('❤')
|
||||
.lines([(1, Line::short('❤', '❤'))])
|
||||
.lines([(1, Line::new(Some('❤'), Some('❤'), None, None))])
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
|
|
34
crates/nu-table/tests/style.rs
Normal file
34
crates/nu-table/tests/style.rs
Normal 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())
|
||||
}
|
Loading…
Reference in a new issue