#[derive(Debug)]
pub struct VerticalLine {
pub(crate) filler: char,
}
impl Default for VerticalLine {
fn default() -> Self {
Self { filler: '|' }
}
}
impl VerticalLine {
pub fn new(filler: char) -> Self {
Self { filler }
}
}
#[derive(Debug)]
pub struct HorizontalLine {
pub(crate) left_end: char,
pub(crate) right_end: char,
pub(crate) junction: char,
pub(crate) filler: char,
}
impl Default for HorizontalLine {
fn default() -> Self {
Self {
left_end: '+',
right_end: '+',
junction: '+',
filler: '-',
}
}
}
impl HorizontalLine {
pub fn new(left_end: char, right_end: char, junction: char, filler: char) -> Self {
Self {
left_end,
right_end,
junction,
filler,
}
}
}
#[derive(Debug)]
pub struct Border {
pub(crate) top: Option<HorizontalLine>,
pub(crate) bottom: Option<HorizontalLine>,
pub(crate) left: Option<VerticalLine>,
pub(crate) right: Option<VerticalLine>,
}
impl Border {
pub fn builder() -> BorderBuilder {
BorderBuilder(Border {
top: None,
bottom: None,
left: None,
right: None,
})
}
}
impl Default for Border {
fn default() -> Self {
Self {
top: Some(Default::default()),
bottom: Some(Default::default()),
left: Some(Default::default()),
right: Some(Default::default()),
}
}
}
#[derive(Debug)]
pub struct BorderBuilder(Border);
impl BorderBuilder {
pub fn top(mut self, top: Option<HorizontalLine>) -> Self {
self.0.top = top;
self
}
pub fn bottom(mut self, bottom: Option<HorizontalLine>) -> Self {
self.0.bottom = bottom;
self
}
pub fn left(mut self, left: Option<VerticalLine>) -> Self {
self.0.left = left;
self
}
pub fn right(mut self, right: Option<VerticalLine>) -> Self {
self.0.right = right;
self
}
pub fn build(self) -> Border {
self.0
}
}
#[derive(Debug)]
pub struct Separator {
pub(crate) column: Option<VerticalLine>,
pub(crate) row: Option<HorizontalLine>,
pub(crate) title: Option<HorizontalLine>,
}
impl Separator {
pub fn builder() -> SeparatorBuilder {
SeparatorBuilder(Separator {
column: None,
row: None,
title: None,
})
}
}
impl Default for Separator {
fn default() -> Self {
Self {
column: Some(Default::default()),
row: Some(Default::default()),
title: None,
}
}
}
#[derive(Debug)]
pub struct SeparatorBuilder(Separator);
impl SeparatorBuilder {
pub fn column(mut self, column: Option<VerticalLine>) -> Self {
self.0.column = column;
self
}
pub fn row(mut self, row: Option<HorizontalLine>) -> Self {
self.0.row = row;
self
}
pub fn title(mut self, title: Option<HorizontalLine>) -> Self {
self.0.title = title;
self
}
pub fn build(self) -> Separator {
self.0
}
}
#[derive(Debug, Default)]
pub struct TableFormat {
pub(crate) border: Border,
pub(crate) separator: Separator,
}
impl TableFormat {
pub fn new(border: Border, separator: Separator) -> Self {
Self { border, separator }
}
}