From d8d88cd39566d6d67103fac3ba568831fc5121c9 Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Sun, 17 Jul 2022 21:56:31 +0300 Subject: [PATCH] nu-table: Add suffix coloring (#6071) * nu-table: Bump tabled Signed-off-by: Maxim Zhiburt * nu-table: Add suffix coloring while truncating Signed-off-by: Maxim Zhiburt * Fix cargo fmt Signed-off-by: Maxim Zhiburt --- Cargo.lock | 6 ++--- crates/nu-table/Cargo.toml | 2 +- crates/nu-table/src/table.rs | 13 +++++---- crates/nu-table/src/table_theme.rs | 42 +++++++++++++----------------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0cbab519a8..3d868edf54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3171,7 +3171,7 @@ checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" [[package]] name = "papergrid" version = "0.4.0" -source = "git+https://github.com/zhiburt/tabled?rev=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" +source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" 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=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" +source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" 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=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" +source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62" dependencies = [ "heck 0.4.0", "proc-macro-error", diff --git a/crates/nu-table/Cargo.toml b/crates/nu-table/Cargo.toml index 79147ae8ea..90b0744f8e 100644 --- a/crates/nu-table/Cargo.toml +++ b/crates/nu-table/Cargo.toml @@ -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 = "9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278", features = ["color"] } +tabled = { git = "https://github.com/zhiburt/tabled", rev = "0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62", features = ["color"] } diff --git a/crates/nu-table/src/table.rs b/crates/nu-table/src/table.rs index 8d47dc3861..1f23ecd5d8 100644 --- a/crates/nu-table/src/table.rs +++ b/crates/nu-table/src/table.rs @@ -178,10 +178,10 @@ fn build_table( let mut builder = Builder::from(data); if let Some(headers) = headers { - builder = builder.set_columns(headers.clone()); + builder.set_columns(headers.clone()); if need_footer { - builder = builder.add_record(headers); + builder.add_record(headers); } } @@ -344,20 +344,19 @@ impl tabled::TableOption for &TrimStrategyModifier<'_> { fn change(&mut self, grid: &mut papergrid::Grid) { match self.trim_strategy { TrimStrategy::Wrap { try_to_keep_words } => { - let mut w = Width::wrap(self.termwidth); + let mut w = Width::wrap(self.termwidth).priority::(); if *try_to_keep_words { w = w.keep_words(); } - let mut w = w.priority::(); w.change(grid) } TrimStrategy::Truncate { suffix } => { - let mut w = Width::truncate(self.termwidth); + let mut w = + Width::truncate(self.termwidth).priority::(); if let Some(suffix) = suffix { - w = w.suffix(suffix); + w = w.suffix(suffix).suffix_try_color(true); } - let mut w = w.priority::(); w.change(grid); } diff --git a/crates/nu-table/src/table_theme.rs b/crates/nu-table/src/table_theme.rs index 05e9d5d6f0..d0179eb41a 100644 --- a/crates/nu-table/src/table_theme.rs +++ b/crates/nu-table/src/table_theme.rs @@ -1,8 +1,8 @@ -use tabled::{style::StyleConfig, Style}; +use tabled::{papergrid::Line, style::RawStyle, Style}; #[derive(Debug, Clone)] pub struct TableTheme { - pub(crate) theme: StyleConfig, + pub(crate) theme: RawStyle, } impl TableTheme { @@ -20,41 +20,39 @@ impl TableTheme { pub fn light() -> TableTheme { Self { - theme: Style::blank().header('─').into(), + theme: Style::blank().lines([(1, Line::short('─', '─'))]).into(), } } pub fn compact() -> TableTheme { Self { theme: Style::modern() - .left_off() - .right_off() - .horizontal_off() + .off_left() + .off_right() + .off_horizontal() + .lines([(1, Style::modern().get_horizontal().left(None).right(None))]) .into(), } } pub fn with_love() -> TableTheme { Self { - theme: Style::psql() - .header('❤') + theme: Style::empty() .top('❤') .bottom('❤') .vertical('❤') + .lines([(1, Line::short('❤', '❤'))]) .into(), } } pub fn compact_double() -> TableTheme { Self { - theme: Style::psql() - .header('═') - .top('═') - .bottom('═') - .vertical('║') - .top_intersection('╦') - .bottom_intersection('╩') - .header_intersection('╬') + theme: Style::extended() + .off_left() + .off_right() + .off_horizontal() + .lines([(1, Style::extended().get_horizontal().left(None).right(None))]) .into(), } } @@ -72,30 +70,26 @@ impl TableTheme { .top_right_corner('┓') .bottom_left_corner('┗') .bottom_right_corner('┛') - .horizontal_off() + .off_horizontal() .into(), } } pub fn heavy() -> TableTheme { Self { - theme: Style::modern() - .header('━') + theme: Style::empty() .top('━') .bottom('━') .vertical('┃') .left('┃') .right('┃') - .left_intersection('┣') - .right_intersection('┫') - .bottom_intersection('┻') .top_intersection('┳') + .bottom_intersection('┻') .top_left_corner('┏') .top_right_corner('┓') .bottom_left_corner('┗') .bottom_right_corner('┛') - .header_intersection('╋') - .horizontal_off() + .lines([(1, Line::full('━', '╋', '┣', '┫'))]) .into(), } }