use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct BoxChars {
pub top_left: Cow<'static, str>,
pub top: Cow<'static, str>,
pub top_right: Cow<'static, str>,
pub right: Cow<'static, str>,
pub bottom_right: Cow<'static, str>,
pub bottom: Cow<'static, str>,
pub bottom_left: Cow<'static, str>,
pub left: Cow<'static, str>,
}
macro_rules! static_chars {
($tl:expr, $t:expr, $tr:expr, $r:expr, $br:expr, $b:expr, $bl:expr, $l:expr) => {
BoxChars {
top_left: Cow::Borrowed($tl),
top: Cow::Borrowed($t),
top_right: Cow::Borrowed($tr),
right: Cow::Borrowed($r),
bottom_right: Cow::Borrowed($br),
bottom: Cow::Borrowed($b),
bottom_left: Cow::Borrowed($bl),
left: Cow::Borrowed($l),
}
};
}
pub struct CustomChars {
pub top_left: String,
pub top: String,
pub top_right: String,
pub right: String,
pub bottom_right: String,
pub bottom: String,
pub bottom_left: String,
pub left: String,
}
impl BoxChars {
pub fn from_custom(c: CustomChars) -> Self {
Self {
top_left: Cow::Owned(c.top_left),
top: Cow::Owned(c.top),
top_right: Cow::Owned(c.top_right),
right: Cow::Owned(c.right),
bottom_right: Cow::Owned(c.bottom_right),
bottom: Cow::Owned(c.bottom),
bottom_left: Cow::Owned(c.bottom_left),
left: Cow::Owned(c.left),
}
}
}
fn single() -> BoxChars {
static_chars!("┌", "─", "┐", "│", "┘", "─", "└", "│")
}
fn double() -> BoxChars {
static_chars!("╔", "═", "╗", "║", "╝", "═", "╚", "║")
}
fn round() -> BoxChars {
static_chars!("╭", "─", "╮", "│", "╯", "─", "╰", "│")
}
fn bold() -> BoxChars {
static_chars!("┏", "━", "┓", "┃", "┛", "━", "┗", "┃")
}
fn single_double() -> BoxChars {
static_chars!("╓", "─", "╖", "║", "╜", "─", "╙", "║")
}
fn double_single() -> BoxChars {
static_chars!("╒", "═", "╕", "│", "╛", "═", "╘", "│")
}
fn classic() -> BoxChars {
static_chars!("+", "-", "+", "|", "+", "-", "+", "|")
}
fn arrow() -> BoxChars {
static_chars!("↘", "↓", "↙", "←", "↖", "↑", "↗", "→")
}
pub fn named(style: &str) -> Option<BoxChars> {
match style {
"single" => Some(single()),
"double" => Some(double()),
"round" => Some(round()),
"bold" => Some(bold()),
"singleDouble" => Some(single_double()),
"doubleSingle" => Some(double_single()),
"classic" => Some(classic()),
"arrow" => Some(arrow()),
_ => None,
}
}