Skip to main content

rnk_style_core/
border.rs

1//! Border styles shared across rnk crates.
2
3/// Border style
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum BorderStyle {
6    #[default]
7    None,
8    Single,
9    Double,
10    Round,
11    Bold,
12    SingleDouble,
13    DoubleSingle,
14    Classic,
15}
16
17impl BorderStyle {
18    /// Get border characters: (top_left, top_right, bottom_left, bottom_right, horizontal, vertical)
19    pub fn chars(
20        &self,
21    ) -> (
22        &'static str,
23        &'static str,
24        &'static str,
25        &'static str,
26        &'static str,
27        &'static str,
28    ) {
29        match self {
30            BorderStyle::None => (" ", " ", " ", " ", " ", " "),
31            BorderStyle::Single => ("┌", "┐", "└", "┘", "─", "│"),
32            BorderStyle::Double => ("╔", "╗", "╚", "╝", "═", "║"),
33            BorderStyle::Round => ("╭", "╮", "╰", "╯", "─", "│"),
34            BorderStyle::Bold => ("┏", "┓", "┗", "┛", "━", "┃"),
35            BorderStyle::SingleDouble => ("╓", "╖", "╙", "╜", "─", "║"),
36            BorderStyle::DoubleSingle => ("╒", "╕", "╘", "╛", "═", "│"),
37            BorderStyle::Classic => ("+", "+", "+", "+", "-", "|"),
38        }
39    }
40
41    /// Check if border is visible
42    pub fn is_visible(&self) -> bool {
43        !matches!(self, BorderStyle::None)
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_border_chars() {
53        let (tl, tr, bl, br, h, v) = BorderStyle::Round.chars();
54        assert_eq!(tl, "╭");
55        assert_eq!(tr, "╮");
56        assert_eq!(bl, "╰");
57        assert_eq!(br, "╯");
58        assert_eq!(h, "─");
59        assert_eq!(v, "│");
60    }
61
62    #[test]
63    fn test_is_visible() {
64        assert!(!BorderStyle::None.is_visible());
65        assert!(BorderStyle::Single.is_visible());
66        assert!(BorderStyle::Round.is_visible());
67    }
68}