2023-04-26 20:56:10 +02:00
|
|
|
use tabled::settings::style::{HorizontalLine, Line, RawStyle, Style};
|
2022-07-06 21:57:40 +02:00
|
|
|
|
2022-05-16 17:35:57 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme: RawStyle,
|
|
|
|
full_theme: RawStyle,
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: bool,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TableTheme {
|
|
|
|
pub fn basic() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::ascii().into(),
|
2023-04-26 20:56:10 +02:00
|
|
|
full_theme: Style::ascii().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn thin() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::modern().into(),
|
2023-04-26 20:56:10 +02:00
|
|
|
full_theme: Style::modern().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn light() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let theme = Style::blank()
|
|
|
|
.horizontals([HorizontalLine::new(
|
|
|
|
1,
|
|
|
|
Line::new(Some('─'), Some('─'), None, None),
|
|
|
|
)])
|
|
|
|
.into();
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme,
|
|
|
|
full_theme: Style::modern().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-08 23:34:36 +02:00
|
|
|
pub fn psql() -> TableTheme {
|
|
|
|
Self {
|
|
|
|
theme: Style::psql().into(),
|
|
|
|
full_theme: Style::psql().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn markdown() -> TableTheme {
|
|
|
|
Self {
|
|
|
|
theme: Style::markdown().into(),
|
|
|
|
full_theme: Style::markdown().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dots() -> TableTheme {
|
|
|
|
let theme = Style::dots().remove_horizontal().into();
|
|
|
|
Self {
|
|
|
|
theme,
|
|
|
|
full_theme: Style::dots().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 12:37:06 +02:00
|
|
|
pub fn restructured() -> TableTheme {
|
2023-09-08 23:34:36 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::re_structured_text().into(),
|
|
|
|
full_theme: Style::re_structured_text().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ascii_rounded() -> TableTheme {
|
|
|
|
Self {
|
|
|
|
theme: Style::ascii_rounded().into(),
|
|
|
|
full_theme: Style::ascii_rounded().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn basic_compact() -> TableTheme {
|
|
|
|
let theme = Style::ascii().remove_horizontal().into();
|
|
|
|
Self {
|
|
|
|
theme,
|
|
|
|
full_theme: Style::ascii().into(),
|
|
|
|
has_inner: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 17:35:57 +02:00
|
|
|
pub fn compact() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let theme = Style::modern()
|
|
|
|
.remove_left()
|
|
|
|
.remove_right()
|
|
|
|
.remove_horizontal()
|
|
|
|
.horizontals([HorizontalLine::new(1, Style::modern().get_horizontal())
|
|
|
|
.left(None)
|
|
|
|
.right(None)])
|
|
|
|
.into();
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme,
|
|
|
|
full_theme: Style::modern().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_love() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let theme = Style::empty()
|
|
|
|
.top('❤')
|
|
|
|
.bottom('❤')
|
|
|
|
.vertical('❤')
|
|
|
|
.horizontals([HorizontalLine::new(
|
|
|
|
1,
|
|
|
|
Line::new(Some('❤'), Some('❤'), None, None),
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let full_theme = Style::empty()
|
|
|
|
.top('❤')
|
|
|
|
.bottom('❤')
|
|
|
|
.vertical('❤')
|
|
|
|
.horizontal('❤')
|
|
|
|
.left('❤')
|
|
|
|
.right('❤')
|
|
|
|
.intersection_top('❤')
|
|
|
|
.corner_top_left('❤')
|
|
|
|
.corner_top_right('❤')
|
|
|
|
.intersection_bottom('❤')
|
|
|
|
.corner_bottom_left('❤')
|
|
|
|
.corner_bottom_right('❤')
|
|
|
|
.intersection_right('❤')
|
|
|
|
.intersection_left('❤')
|
|
|
|
.intersection('❤');
|
|
|
|
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme: theme.into(),
|
|
|
|
full_theme: full_theme.into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn compact_double() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let theme = Style::extended()
|
|
|
|
.remove_left()
|
|
|
|
.remove_right()
|
|
|
|
.remove_horizontal()
|
|
|
|
.horizontals([HorizontalLine::new(1, Style::extended().get_horizontal())
|
|
|
|
.left(None)
|
|
|
|
.right(None)])
|
|
|
|
.into();
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme,
|
|
|
|
full_theme: Style::extended().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rounded() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::rounded().into(),
|
2023-04-26 20:56:10 +02:00
|
|
|
full_theme: Style::modern()
|
|
|
|
.corner_top_left('╭')
|
|
|
|
.corner_top_right('╮')
|
|
|
|
.corner_bottom_left('╰')
|
|
|
|
.corner_bottom_right('╯')
|
|
|
|
.into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reinforced() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let full_theme = Style::modern()
|
|
|
|
.corner_top_left('┏')
|
|
|
|
.corner_top_right('┓')
|
|
|
|
.corner_bottom_left('┗')
|
|
|
|
.corner_bottom_right('┛');
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme: full_theme.clone().remove_horizontal().into(),
|
|
|
|
full_theme: full_theme.into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn heavy() -> TableTheme {
|
2023-04-26 20:56:10 +02:00
|
|
|
let theme = Style::empty()
|
|
|
|
.top('━')
|
|
|
|
.bottom('━')
|
|
|
|
.vertical('┃')
|
|
|
|
.left('┃')
|
|
|
|
.right('┃')
|
|
|
|
.intersection_top('┳')
|
|
|
|
.intersection_bottom('┻')
|
|
|
|
.corner_top_left('┏')
|
|
|
|
.corner_top_right('┓')
|
|
|
|
.corner_bottom_left('┗')
|
|
|
|
.corner_bottom_right('┛')
|
|
|
|
.horizontals([HorizontalLine::new(1, Line::full('━', '╋', '┣', '┫'))]);
|
|
|
|
let full_theme = theme
|
|
|
|
.clone()
|
|
|
|
.remove_horizontals()
|
|
|
|
.horizontal('━')
|
|
|
|
.intersection_left('┣')
|
|
|
|
.intersection_right('┫')
|
|
|
|
.intersection('╋');
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2023-04-26 20:56:10 +02:00
|
|
|
theme: theme.into(),
|
|
|
|
full_theme: full_theme.into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-06 21:57:40 +02:00
|
|
|
pub fn none() -> TableTheme {
|
|
|
|
Self {
|
|
|
|
theme: Style::blank().into(),
|
2023-04-26 20:56:10 +02:00
|
|
|
full_theme: Style::blank().into(),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 13:29:55 +02:00
|
|
|
|
|
|
|
pub fn has_top_line(&self) -> bool {
|
|
|
|
self.theme.get_top().is_some()
|
|
|
|
|| self.theme.get_top_intersection().is_some()
|
|
|
|
|| self.theme.get_top_left().is_some()
|
|
|
|
|| self.theme.get_top_right().is_some()
|
|
|
|
}
|
2023-01-26 21:06:17 +01:00
|
|
|
|
|
|
|
pub fn has_left(&self) -> bool {
|
|
|
|
self.theme.get_left().is_some()
|
|
|
|
|| self.theme.get_left_intersection().is_some()
|
|
|
|
|| self.theme.get_top_left().is_some()
|
|
|
|
|| self.theme.get_bottom_left().is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_right(&self) -> bool {
|
|
|
|
self.theme.get_right().is_some()
|
|
|
|
|| self.theme.get_right_intersection().is_some()
|
|
|
|
|| self.theme.get_top_right().is_some()
|
|
|
|
|| self.theme.get_bottom_right().is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_inner(&self) -> bool {
|
|
|
|
self.has_inner
|
|
|
|
}
|
2023-02-16 20:32:07 +01:00
|
|
|
|
2023-08-04 20:50:47 +02:00
|
|
|
pub fn has_horizontals(&self) -> bool {
|
|
|
|
self.full_theme.get_borders().has_horizontal()
|
|
|
|
}
|
|
|
|
|
2023-04-26 20:56:10 +02:00
|
|
|
pub fn get_theme_full(&self) -> RawStyle {
|
2023-02-16 20:32:07 +01:00
|
|
|
self.full_theme.clone()
|
|
|
|
}
|
2023-04-26 20:56:10 +02:00
|
|
|
|
|
|
|
pub fn get_theme(&self) -> RawStyle {
|
|
|
|
self.theme.clone()
|
|
|
|
}
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|