nu-table: Add suffix coloring (#6071)

* nu-table: Bump tabled

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

* nu-table: Add suffix coloring while truncating

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

* Fix cargo fmt

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt 2022-07-17 21:56:31 +03:00 committed by GitHub
parent 9aabafeb41
commit d8d88cd395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 35 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=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62"
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=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62"
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=9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278#9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278" source = "git+https://github.com/zhiburt/tabled?rev=0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62#0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62"
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 = "9c831d5bc5bcd5a7b7a349ce63f746a64bf1c278", features = ["color"] } tabled = { git = "https://github.com/zhiburt/tabled", rev = "0ac6b7b7b89b56b23ba479d1b1cfe1976b71fd62", features = ["color"] }

View File

@ -178,10 +178,10 @@ fn build_table(
let mut builder = Builder::from(data); let mut builder = Builder::from(data);
if let Some(headers) = headers { if let Some(headers) = headers {
builder = builder.set_columns(headers.clone()); builder.set_columns(headers.clone());
if need_footer { 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) { fn change(&mut self, grid: &mut papergrid::Grid) {
match self.trim_strategy { match self.trim_strategy {
TrimStrategy::Wrap { try_to_keep_words } => { TrimStrategy::Wrap { try_to_keep_words } => {
let mut w = Width::wrap(self.termwidth); let mut w = Width::wrap(self.termwidth).priority::<tabled::width::PriorityMax>();
if *try_to_keep_words { if *try_to_keep_words {
w = w.keep_words(); w = w.keep_words();
} }
let mut w = w.priority::<tabled::width::PriorityMax>();
w.change(grid) w.change(grid)
} }
TrimStrategy::Truncate { suffix } => { TrimStrategy::Truncate { suffix } => {
let mut w = Width::truncate(self.termwidth); let mut w =
Width::truncate(self.termwidth).priority::<tabled::width::PriorityMax>();
if let Some(suffix) = suffix { if let Some(suffix) = suffix {
w = w.suffix(suffix); w = w.suffix(suffix).suffix_try_color(true);
} }
let mut w = w.priority::<tabled::width::PriorityMax>();
w.change(grid); w.change(grid);
} }

View File

@ -1,8 +1,8 @@
use tabled::{style::StyleConfig, Style}; use tabled::{papergrid::Line, style::RawStyle, Style};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TableTheme { pub struct TableTheme {
pub(crate) theme: StyleConfig, pub(crate) theme: RawStyle,
} }
impl TableTheme { impl TableTheme {
@ -20,41 +20,39 @@ impl TableTheme {
pub fn light() -> TableTheme { pub fn light() -> TableTheme {
Self { Self {
theme: Style::blank().header('─').into(), theme: Style::blank().lines([(1, Line::short('─', '─'))]).into(),
} }
} }
pub fn compact() -> TableTheme { pub fn compact() -> TableTheme {
Self { Self {
theme: Style::modern() theme: Style::modern()
.left_off() .off_left()
.right_off() .off_right()
.horizontal_off() .off_horizontal()
.lines([(1, Style::modern().get_horizontal().left(None).right(None))])
.into(), .into(),
} }
} }
pub fn with_love() -> TableTheme { pub fn with_love() -> TableTheme {
Self { Self {
theme: Style::psql() theme: Style::empty()
.header('❤')
.top('❤') .top('❤')
.bottom('❤') .bottom('❤')
.vertical('❤') .vertical('❤')
.lines([(1, Line::short('❤', '❤'))])
.into(), .into(),
} }
} }
pub fn compact_double() -> TableTheme { pub fn compact_double() -> TableTheme {
Self { Self {
theme: Style::psql() theme: Style::extended()
.header('═') .off_left()
.top('═') .off_right()
.bottom('═') .off_horizontal()
.vertical('║') .lines([(1, Style::extended().get_horizontal().left(None).right(None))])
.top_intersection('╦')
.bottom_intersection('╩')
.header_intersection('╬')
.into(), .into(),
} }
} }
@ -72,30 +70,26 @@ impl TableTheme {
.top_right_corner('┓') .top_right_corner('┓')
.bottom_left_corner('┗') .bottom_left_corner('┗')
.bottom_right_corner('┛') .bottom_right_corner('┛')
.horizontal_off() .off_horizontal()
.into(), .into(),
} }
} }
pub fn heavy() -> TableTheme { pub fn heavy() -> TableTheme {
Self { Self {
theme: Style::modern() theme: Style::empty()
.header('━')
.top('━') .top('━')
.bottom('━') .bottom('━')
.vertical('┃') .vertical('┃')
.left('┃') .left('┃')
.right('┃') .right('┃')
.left_intersection('┣')
.right_intersection('┫')
.bottom_intersection('┻')
.top_intersection('┳') .top_intersection('┳')
.bottom_intersection('┻')
.top_left_corner('┏') .top_left_corner('┏')
.top_right_corner('┓') .top_right_corner('┓')
.bottom_left_corner('┗') .bottom_left_corner('┗')
.bottom_right_corner('┛') .bottom_right_corner('┛')
.header_intersection('╋') .lines([(1, Line::full('━', '╋', '┣', '┫'))])
.horizontal_off()
.into(), .into(),
} }
} }