nushell/crates/nu-table/src/table_theme.rs

103 lines
2.5 KiB
Rust
Raw Normal View History

use tabled::{papergrid::Line, style::RawStyle, Style};
2022-05-16 17:35:57 +02:00
#[derive(Debug, Clone)]
pub struct TableTheme {
pub(crate) theme: RawStyle,
2022-05-16 17:35:57 +02:00
}
impl TableTheme {
pub fn basic() -> TableTheme {
Self {
theme: Style::ascii().into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn thin() -> TableTheme {
Self {
theme: Style::modern().into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn light() -> TableTheme {
Self {
theme: Style::blank().lines([(1, Line::short('─', '─'))]).into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn compact() -> TableTheme {
Self {
theme: Style::modern()
.off_left()
.off_right()
.off_horizontal()
.lines([(1, Style::modern().get_horizontal().left(None).right(None))])
.into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn with_love() -> TableTheme {
Self {
theme: Style::empty()
.top('❤')
.bottom('❤')
.vertical('❤')
.lines([(1, Line::short('❤', '❤'))])
.into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn compact_double() -> TableTheme {
Self {
theme: Style::extended()
.off_left()
.off_right()
.off_horizontal()
.lines([(1, Style::extended().get_horizontal().left(None).right(None))])
.into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn rounded() -> TableTheme {
Self {
theme: Style::rounded().into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn reinforced() -> TableTheme {
Self {
theme: Style::modern()
.top_left_corner('┏')
.top_right_corner('┓')
.bottom_left_corner('┗')
.bottom_right_corner('┛')
.off_horizontal()
.into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn heavy() -> TableTheme {
Self {
theme: Style::empty()
.top('━')
.bottom('━')
.vertical('┃')
.left('┃')
.right('┃')
.top_intersection('┳')
.bottom_intersection('┻')
.top_left_corner('┏')
.top_right_corner('┓')
.bottom_left_corner('┗')
.bottom_right_corner('┛')
.lines([(1, Line::full('━', '╋', '┣', '┫'))])
.into(),
2022-05-16 17:35:57 +02:00
}
}
pub fn none() -> TableTheme {
Self {
theme: Style::blank().into(),
2022-05-16 17:35:57 +02:00
}
}
}