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]]
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",

View File

@ -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"] }

View File

@ -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::<tabled::width::PriorityMax>();
if *try_to_keep_words {
w = w.keep_words();
}
let mut w = w.priority::<tabled::width::PriorityMax>();
w.change(grid)
}
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 {
w = w.suffix(suffix);
w = w.suffix(suffix).suffix_try_color(true);
}
let mut w = w.priority::<tabled::width::PriorityMax>();
w.change(grid);
}

View File

@ -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(),
}
}