2022-10-03 18:40:16 +02:00
|
|
|
use tabled::{
|
|
|
|
style::RawStyle,
|
|
|
|
style::{HorizontalLine, Line, Style},
|
|
|
|
};
|
2022-07-06 21:57:40 +02:00
|
|
|
|
2022-05-16 17:35:57 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TableTheme {
|
2022-07-17 20:56:31 +02:00
|
|
|
pub(crate) theme: RawStyle,
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: bool,
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Option<RawStyle>,
|
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-02-16 20:32:07 +01:00
|
|
|
full_theme: None,
|
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-02-16 20:32:07 +01:00
|
|
|
full_theme: None,
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn light() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2022-07-18 18:45:21 +02:00
|
|
|
theme: Style::blank()
|
2022-10-03 18:40:16 +02:00
|
|
|
.horizontals([HorizontalLine::new(
|
|
|
|
1,
|
|
|
|
Line::new(Some('─'), Some('─'), None, None),
|
|
|
|
)])
|
2022-07-18 18:45:21 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(Style::modern().into()),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn compact() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::modern()
|
2022-07-17 20:56:31 +02:00
|
|
|
.off_left()
|
|
|
|
.off_right()
|
|
|
|
.off_horizontal()
|
2022-10-03 18:40:16 +02:00
|
|
|
.horizontals([HorizontalLine::new(1, Style::modern().get_horizontal())
|
|
|
|
.left(None)
|
|
|
|
.right(None)])
|
2022-07-06 21:57:40 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(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 {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2022-07-17 20:56:31 +02:00
|
|
|
theme: Style::empty()
|
2022-07-06 21:57:40 +02:00
|
|
|
.top('❤')
|
|
|
|
.bottom('❤')
|
|
|
|
.vertical('❤')
|
2022-10-03 18:40:16 +02:00
|
|
|
.horizontals([HorizontalLine::new(
|
|
|
|
1,
|
|
|
|
Line::new(Some('❤'), Some('❤'), None, None),
|
|
|
|
)])
|
2022-07-06 21:57:40 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(
|
|
|
|
Style::empty()
|
|
|
|
.top('❤')
|
|
|
|
.bottom('❤')
|
|
|
|
.vertical('❤')
|
|
|
|
.horizontal('❤')
|
|
|
|
.left('❤')
|
|
|
|
.right('❤')
|
|
|
|
.top_intersection('❤')
|
|
|
|
.top_left_corner('❤')
|
|
|
|
.top_right_corner('❤')
|
|
|
|
.bottom_intersection('❤')
|
|
|
|
.bottom_left_corner('❤')
|
|
|
|
.bottom_right_corner('❤')
|
|
|
|
.right_intersection('❤')
|
|
|
|
.left_intersection('❤')
|
|
|
|
.inner_intersection('❤')
|
|
|
|
.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 {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2022-07-17 20:56:31 +02:00
|
|
|
theme: Style::extended()
|
|
|
|
.off_left()
|
|
|
|
.off_right()
|
|
|
|
.off_horizontal()
|
2022-10-03 18:40:16 +02:00
|
|
|
.horizontals([HorizontalLine::new(1, Style::extended().get_horizontal())
|
|
|
|
.left(None)
|
|
|
|
.right(None)])
|
2022-07-06 21:57:40 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(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-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(
|
|
|
|
Style::modern()
|
|
|
|
.top_left_corner('╭')
|
|
|
|
.top_right_corner('╮')
|
|
|
|
.bottom_left_corner('╰')
|
|
|
|
.bottom_right_corner('╯')
|
|
|
|
.into(),
|
|
|
|
),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reinforced() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
|
|
|
theme: Style::modern()
|
|
|
|
.top_left_corner('┏')
|
|
|
|
.top_right_corner('┓')
|
|
|
|
.bottom_left_corner('┗')
|
|
|
|
.bottom_right_corner('┛')
|
2022-07-17 20:56:31 +02:00
|
|
|
.off_horizontal()
|
2022-07-06 21:57:40 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(
|
|
|
|
Style::modern()
|
|
|
|
.top_left_corner('┏')
|
|
|
|
.top_right_corner('┓')
|
|
|
|
.bottom_left_corner('┗')
|
|
|
|
.bottom_right_corner('┛')
|
|
|
|
.into(),
|
|
|
|
),
|
2023-01-26 21:06:17 +01:00
|
|
|
has_inner: true,
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn heavy() -> TableTheme {
|
2022-07-06 21:57:40 +02:00
|
|
|
Self {
|
2022-07-17 20:56:31 +02:00
|
|
|
theme: Style::empty()
|
2022-07-06 21:57:40 +02:00
|
|
|
.top('━')
|
|
|
|
.bottom('━')
|
|
|
|
.vertical('┃')
|
|
|
|
.left('┃')
|
|
|
|
.right('┃')
|
|
|
|
.top_intersection('┳')
|
2022-07-17 20:56:31 +02:00
|
|
|
.bottom_intersection('┻')
|
2022-07-06 21:57:40 +02:00
|
|
|
.top_left_corner('┏')
|
|
|
|
.top_right_corner('┓')
|
|
|
|
.bottom_left_corner('┗')
|
|
|
|
.bottom_right_corner('┛')
|
2022-10-03 18:40:16 +02:00
|
|
|
.horizontals([HorizontalLine::new(1, Line::full('━', '╋', '┣', '┫'))])
|
2022-07-06 21:57:40 +02:00
|
|
|
.into(),
|
2023-02-16 20:32:07 +01:00
|
|
|
full_theme: Some(
|
|
|
|
Style::modern()
|
|
|
|
.top('━')
|
|
|
|
.bottom('━')
|
|
|
|
.vertical('┃')
|
|
|
|
.left('┃')
|
|
|
|
.right('┃')
|
|
|
|
.top_intersection('┳')
|
|
|
|
.bottom_intersection('┻')
|
|
|
|
.top_left_corner('┏')
|
|
|
|
.top_right_corner('┓')
|
|
|
|
.bottom_left_corner('┗')
|
|
|
|
.bottom_right_corner('┛')
|
|
|
|
.horizontal('━')
|
|
|
|
.left_intersection('┣')
|
|
|
|
.right_intersection('┫')
|
|
|
|
.inner_intersection('╋')
|
|
|
|
.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-02-16 20:32:07 +01:00
|
|
|
full_theme: None,
|
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
|
|
|
|
|
|
|
pub fn into_full(&self) -> Option<RawStyle> {
|
|
|
|
self.full_theme.clone()
|
|
|
|
}
|
2022-05-16 17:35:57 +02:00
|
|
|
}
|