use glyphs::Color;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Border {
#[default]
None,
Normal,
Rounded,
Thick,
Double,
Ascii,
Block,
Dashed,
Custom(BorderStyle),
}
impl Border {
pub const fn style(self) -> BorderStyle {
match self {
Border::None => BorderStyle::NONE,
Border::Normal => BorderStyle::NORMAL,
Border::Rounded => BorderStyle::ROUNDED,
Border::Thick => BorderStyle::THICK,
Border::Double => BorderStyle::DOUBLE,
Border::Ascii => BorderStyle::ASCII,
Border::Block => BorderStyle::BLOCK,
Border::Dashed => BorderStyle::DASHED,
Border::Custom(style) => style,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BorderStyle {
pub top_left: char,
pub top: char,
pub top_right: char,
pub right: char,
pub bottom_right: char,
pub bottom: char,
pub bottom_left: char,
pub left: char,
}
impl BorderStyle {
pub const NONE: Self = Self {
top_left: ' ',
top: ' ',
top_right: ' ',
right: ' ',
bottom_right: ' ',
bottom: ' ',
bottom_left: ' ',
left: ' ',
};
pub const NORMAL: Self = Self {
top_left: '┌',
top: '─',
top_right: '┐',
right: '│',
bottom_right: '┘',
bottom: '─',
bottom_left: '└',
left: '│',
};
pub const ROUNDED: Self = Self {
top_left: '╭',
top: '─',
top_right: '╮',
right: '│',
bottom_right: '╯',
bottom: '─',
bottom_left: '╰',
left: '│',
};
pub const THICK: Self = Self {
top_left: '┏',
top: '━',
top_right: '┓',
right: '┃',
bottom_right: '┛',
bottom: '━',
bottom_left: '┗',
left: '┃',
};
pub const DOUBLE: Self = Self {
top_left: '╔',
top: '═',
top_right: '╗',
right: '║',
bottom_right: '╝',
bottom: '═',
bottom_left: '╚',
left: '║',
};
pub const ASCII: Self = Self {
top_left: '+',
top: '-',
top_right: '+',
right: '|',
bottom_right: '+',
bottom: '-',
bottom_left: '+',
left: '|',
};
pub const BLOCK: Self = Self {
top_left: '█',
top: '█',
top_right: '█',
right: '█',
bottom_right: '█',
bottom: '█',
bottom_left: '█',
left: '█',
};
pub const DASHED: Self = Self {
top_left: '┌',
top: '╌',
top_right: '┐',
right: '╎',
bottom_right: '┘',
bottom: '╌',
bottom_left: '└',
left: '╎',
};
#[allow(clippy::too_many_arguments)]
pub const fn new(
top_left: char,
top: char,
top_right: char,
right: char,
bottom_right: char,
bottom: char,
bottom_left: char,
left: char,
) -> Self {
Self {
top_left,
top,
top_right,
right,
bottom_right,
bottom,
bottom_left,
left,
}
}
}
impl Default for BorderStyle {
fn default() -> Self {
Self::NONE
}
}
#[derive(Debug, Clone, Default)]
#[allow(dead_code)]
pub struct BorderColors {
pub top: Option<Color>,
pub right: Option<Color>,
pub bottom: Option<Color>,
pub left: Option<Color>,
}
impl BorderColors {
pub fn all(color: Color) -> Self {
Self {
top: Some(color),
right: Some(color),
bottom: Some(color),
left: Some(color),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_border_styles() {
assert_eq!(Border::Rounded.style().top_left, '╭');
assert_eq!(Border::Normal.style().top_left, '┌');
assert_eq!(Border::Double.style().top_left, '╔');
assert_eq!(Border::Ascii.style().top_left, '+');
}
#[test]
fn test_custom_border() {
let custom = BorderStyle::new('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
assert_eq!(custom.top_left, 'A');
assert_eq!(custom.bottom_right, 'E');
}
}