#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct LineStyle {
pub left: Option<char>,
pub fill: Option<char>,
pub junction: Option<char>,
pub right: Option<char>,
}
impl LineStyle {
pub const fn new(left: char, fill: char, junction: char, right: char) -> Self {
Self {
left: Some(left),
fill: Some(fill),
junction: Some(junction),
right: Some(right),
}
}
pub const fn none() -> Self {
Self {
left: None,
fill: None,
junction: None,
right: None,
}
}
pub const fn left(mut self, character: char) -> Self {
self.left = Some(character);
self
}
pub const fn fill(mut self, character: char) -> Self {
self.fill = Some(character);
self
}
pub const fn junction(mut self, character: char) -> Self {
self.junction = Some(character);
self
}
pub const fn right(mut self, character: char) -> Self {
self.right = Some(character);
self
}
pub(crate) const fn is_visible(&self) -> bool {
self.left.is_some()
|| self.fill.is_some()
|| self.junction.is_some()
|| self.right.is_some()
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ContentLineStyle {
pub left: Option<char>,
pub junction: Option<char>,
pub right: Option<char>,
}
impl ContentLineStyle {
pub const fn new(left: char, junction: char, right: char) -> Self {
Self {
left: Some(left),
junction: Some(junction),
right: Some(right),
}
}
pub const fn none() -> Self {
Self {
left: None,
junction: None,
right: None,
}
}
pub const fn left(mut self, character: char) -> Self {
self.left = Some(character);
self
}
pub const fn junction(mut self, character: char) -> Self {
self.junction = Some(character);
self
}
pub const fn right(mut self, character: char) -> Self {
self.right = Some(character);
self
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct TableStyle {
pub top_border: LineStyle,
pub header_lines: ContentLineStyle,
pub header_separator: LineStyle,
pub content_lines: ContentLineStyle,
pub row_separator: LineStyle,
pub bottom_border: LineStyle,
}
impl TableStyle {
pub const fn new() -> Self {
Self {
top_border: LineStyle::none(),
header_lines: ContentLineStyle::none(),
header_separator: LineStyle::none(),
content_lines: ContentLineStyle::none(),
row_separator: LineStyle::none(),
bottom_border: LineStyle::none(),
}
}
pub const fn top_border(mut self, line: LineStyle) -> Self {
self.top_border = line;
self
}
pub const fn header_lines(mut self, line: ContentLineStyle) -> Self {
self.header_lines = line;
self
}
pub const fn header_separator(mut self, line: LineStyle) -> Self {
self.header_separator = line;
self
}
pub const fn content_lines(mut self, line: ContentLineStyle) -> Self {
self.content_lines = line;
self
}
pub const fn row_separator(mut self, line: LineStyle) -> Self {
self.row_separator = line;
self
}
pub const fn bottom_border(mut self, line: LineStyle) -> Self {
self.bottom_border = line;
self
}
pub const fn with_rounded_corners(mut self) -> Self {
self.top_border.left = Some('╭');
self.top_border.right = Some('╮');
self.bottom_border.left = Some('╰');
self.bottom_border.right = Some('╯');
self
}
pub const fn with_solid_inner_borders(mut self) -> Self {
self.header_lines.junction = Some('│');
self.content_lines.junction = Some('│');
self.row_separator.fill = Some('─');
self
}
pub(crate) const fn has_top_border(&self) -> bool {
self.top_border.is_visible()
}
pub(crate) const fn has_bottom_border(&self) -> bool {
self.bottom_border.is_visible()
}
pub(crate) const fn has_header_separator(&self) -> bool {
self.header_separator.is_visible()
}
pub(crate) const fn has_row_separator(&self) -> bool {
self.row_separator.is_visible()
}
pub(crate) const fn has_left_border(&self) -> bool {
self.header_lines.left.is_some()
|| self.content_lines.left.is_some()
|| self.top_border.left.is_some()
|| self.header_separator.left.is_some()
|| self.row_separator.left.is_some()
|| self.bottom_border.left.is_some()
}
pub(crate) const fn has_right_border(&self) -> bool {
self.header_lines.right.is_some()
|| self.content_lines.right.is_some()
|| self.top_border.right.is_some()
|| self.header_separator.right.is_some()
|| self.row_separator.right.is_some()
|| self.bottom_border.right.is_some()
}
pub(crate) const fn has_vertical_lines(&self) -> bool {
self.header_lines.junction.is_some()
|| self.content_lines.junction.is_some()
|| self.top_border.junction.is_some()
|| self.header_separator.junction.is_some()
|| self.row_separator.junction.is_some()
|| self.bottom_border.junction.is_some()
}
}