#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BorderType {
None,
Ascii,
Single,
Double,
#[default]
Rounded,
Thick,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BorderChars {
pub top_left: char,
pub top_right: char,
pub bottom_left: char,
pub bottom_right: char,
pub horizontal: char,
pub vertical: char,
pub cross: char,
pub tee_down: char,
pub tee_up: char,
pub tee_right: char,
pub tee_left: char,
}
impl BorderType {
pub fn chars(self) -> BorderChars {
match self {
Self::None => SPACE,
Self::Ascii => ASCII,
Self::Single => SINGLE,
Self::Double => DOUBLE,
Self::Rounded => ROUNDED,
Self::Thick => THICK,
}
}
pub fn is_none(self) -> bool {
matches!(self, Self::None)
}
}
const SPACE: BorderChars = BorderChars {
top_left: ' ',
top_right: ' ',
bottom_left: ' ',
bottom_right: ' ',
horizontal: ' ',
vertical: ' ',
cross: ' ',
tee_down: ' ',
tee_up: ' ',
tee_right: ' ',
tee_left: ' ',
};
const ASCII: BorderChars = BorderChars {
top_left: '+',
top_right: '+',
bottom_left: '+',
bottom_right: '+',
horizontal: '-',
vertical: '|',
cross: '+',
tee_down: '+',
tee_up: '+',
tee_right: '+',
tee_left: '+',
};
const SINGLE: BorderChars = BorderChars {
top_left: '┌',
top_right: '┐',
bottom_left: '└',
bottom_right: '┘',
horizontal: '─',
vertical: '│',
cross: '┼',
tee_down: '┬',
tee_up: '┴',
tee_right: '├',
tee_left: '┤',
};
const DOUBLE: BorderChars = BorderChars {
top_left: '╔',
top_right: '╗',
bottom_left: '╚',
bottom_right: '╝',
horizontal: '═',
vertical: '║',
cross: '╬',
tee_down: '╦',
tee_up: '╩',
tee_right: '╠',
tee_left: '╣',
};
const ROUNDED: BorderChars = BorderChars {
top_left: '╭',
top_right: '╮',
bottom_left: '╰',
bottom_right: '╯',
horizontal: '─',
vertical: '│',
cross: '┼',
tee_down: '┬',
tee_up: '┴',
tee_right: '├',
tee_left: '┤',
};
const THICK: BorderChars = BorderChars {
top_left: '┏',
top_right: '┓',
bottom_left: '┗',
bottom_right: '┛',
horizontal: '━',
vertical: '┃',
cross: '╋',
tee_down: '┳',
tee_up: '┻',
tee_right: '┣',
tee_left: '┫',
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn rounded_is_the_default() {
assert_eq!(BorderType::default(), BorderType::Rounded);
}
#[test]
fn rounded_uses_curved_corners() {
let chars = BorderType::Rounded.chars();
assert_eq!(chars.top_left, '╭');
assert_eq!(chars.bottom_right, '╯');
}
#[test]
fn none_reports_is_none() {
assert!(BorderType::None.is_none());
assert!(!BorderType::Single.is_none());
}
}