use ratatui::symbols::border;
use ratatui::widgets::Block;
pub use crate::title::{BlockExt, TitleAlignment, TitlePosition};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BorderStyle {
#[default]
Standard,
Rounded,
Dashed,
RoundedDashed,
CornerGapped,
RoundedCornerGapped,
DoubleLineStandard,
DoubleLineRounded,
Thick,
ThickRounded,
ThickDashed,
ThickCornerGapped,
}
impl BorderStyle {
#[must_use]
pub fn block(self) -> Block<'static> {
match self {
Self::Standard => Block::bordered(),
Self::Rounded => Block::bordered().border_set(border::ROUNDED),
Self::Dashed => Block::bordered().border_set(BORDER_DASHED),
Self::RoundedDashed => Block::bordered().border_set(BORDER_ROUNDED_DASHED),
Self::CornerGapped => Block::bordered().border_set(BORDER_CORNER_GAPPED),
Self::RoundedCornerGapped => Block::bordered().border_set(BORDER_ROUNDED_CORNER_GAPPED),
Self::DoubleLineStandard => Block::bordered().border_set(border::DOUBLE),
Self::DoubleLineRounded => Block::bordered().border_set(BORDER_DOUBLE_ROUNDED),
Self::Thick => Block::bordered().border_set(border::THICK),
Self::ThickRounded => Block::bordered().border_set(BORDER_THICK_ROUNDED),
Self::ThickDashed => Block::bordered().border_set(BORDER_THICK_DASHED),
Self::ThickCornerGapped => Block::bordered().border_set(BORDER_THICK_CORNER_GAPPED),
}
}
}
pub const BORDER_DASHED: border::Set = border::Set {
top_left: "┌",
top_right: "┐",
bottom_left: "└",
bottom_right: "┘",
vertical_left: "┊",
vertical_right: "┊",
horizontal_top: "┄",
horizontal_bottom: "┄",
};
pub const BORDER_ROUNDED_DASHED: border::Set = border::Set {
top_left: "╭",
top_right: "╮",
bottom_left: "╰",
bottom_right: "╯",
vertical_left: "┊",
vertical_right: "┊",
horizontal_top: "┄",
horizontal_bottom: "┄",
};
pub const BORDER_CORNER_GAPPED: border::Set = border::Set {
top_left: " ",
top_right: " ",
bottom_left: " ",
bottom_right: " ",
vertical_left: "│",
vertical_right: "│",
horizontal_top: "─",
horizontal_bottom: "─",
};
pub const BORDER_ROUNDED_CORNER_GAPPED: border::Set = border::Set {
top_left: " ",
top_right: " ",
bottom_left: " ",
bottom_right: " ",
vertical_left: "│",
vertical_right: "│",
horizontal_top: "─",
horizontal_bottom: "─",
};
pub const BORDER_DOUBLE_ROUNDED: border::Set = border::Set {
top_left: "╭",
top_right: "╮",
bottom_left: "╰",
bottom_right: "╯",
vertical_left: "║",
vertical_right: "║",
horizontal_top: "═",
horizontal_bottom: "═",
};
pub const BORDER_THICK_ROUNDED: border::Set = border::Set {
top_left: "╭",
top_right: "╮",
bottom_left: "╰",
bottom_right: "╯",
vertical_left: "┃",
vertical_right: "┃",
horizontal_top: "━",
horizontal_bottom: "━",
};
pub const BORDER_THICK_DASHED: border::Set = border::Set {
top_left: "┏",
top_right: "┓",
bottom_left: "┗",
bottom_right: "┛",
vertical_left: "┇",
vertical_right: "┇",
horizontal_top: "┅",
horizontal_bottom: "┅",
};
pub const BORDER_THICK_CORNER_GAPPED: border::Set = border::Set {
top_left: " ",
top_right: " ",
bottom_left: " ",
bottom_right: " ",
vertical_left: "┃",
vertical_right: "┃",
horizontal_top: "━",
horizontal_bottom: "━",
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn border_style_default() {
assert_eq!(BorderStyle::default(), BorderStyle::Standard);
}
#[test]
fn border_style_block_creation() {
let styles = [
BorderStyle::Standard,
BorderStyle::Rounded,
BorderStyle::Dashed,
BorderStyle::RoundedDashed,
BorderStyle::CornerGapped,
BorderStyle::RoundedCornerGapped,
BorderStyle::DoubleLineStandard,
BorderStyle::DoubleLineRounded,
BorderStyle::Thick,
BorderStyle::ThickRounded,
BorderStyle::ThickDashed,
BorderStyle::ThickCornerGapped,
];
for style in &styles {
let _block = style.block();
}
}
#[test]
fn border_style_equality() {
assert_eq!(BorderStyle::Standard, BorderStyle::Standard);
assert_ne!(BorderStyle::Standard, BorderStyle::Rounded);
}
#[test]
fn border_sets_have_valid_characters() {
let sets = [
BORDER_DASHED,
BORDER_ROUNDED_DASHED,
BORDER_CORNER_GAPPED,
BORDER_ROUNDED_CORNER_GAPPED,
BORDER_DOUBLE_ROUNDED,
BORDER_THICK_ROUNDED,
BORDER_THICK_DASHED,
BORDER_THICK_CORNER_GAPPED,
];
for set in &sets {
assert!(!set.top_left.is_empty());
assert!(!set.top_right.is_empty());
assert!(!set.bottom_left.is_empty());
assert!(!set.bottom_right.is_empty());
assert!(!set.vertical_left.is_empty());
assert!(!set.vertical_right.is_empty());
assert!(!set.horizontal_top.is_empty());
assert!(!set.horizontal_bottom.is_empty());
}
}
}