1use textwrap::core::display_width;
2
3#[derive(Clone, Default, PartialEq)]
4pub struct Border {
5 pub top: String,
6 pub bottom: String,
7 pub left: String,
8 pub right: String,
9 pub top_left: String,
10 pub top_right: String,
11 pub bottom_right: String,
12 pub bottom_left: String,
13}
14
15pub fn normal_border() -> Border {
16 Border {
17 top: String::from("─"),
18 bottom: String::from("─"),
19 left: String::from("│"),
20 right: String::from("│"),
21 top_left: String::from("┌"),
22 top_right: String::from("┐"),
23 bottom_left: String::from("└"),
24 bottom_right: String::from("┘"),
25 }
26}
27
28pub fn rounded_border() -> Border {
29 Border {
30 top: String::from("─"),
31 bottom: String::from("─"),
32 left: String::from("│"),
33 right: String::from("│"),
34 top_left: String::from("╭"),
35 top_right: String::from("╮"),
36 bottom_left: String::from("╰"),
37 bottom_right: String::from("╯"),
38 }
39}
40
41pub fn block_border() -> Border {
42 Border {
43 top: String::from("█"),
44 bottom: String::from("█"),
45 left: String::from("█"),
46 right: String::from("█"),
47 top_left: String::from("█"),
48 top_right: String::from("█"),
49 bottom_left: String::from("█"),
50 bottom_right: String::from("█"),
51 }
52}
53
54pub fn outer_half_block_border() -> Border {
55 Border {
56 top: String::from("▀"),
57 bottom: String::from("▄"),
58 left: String::from("▌"),
59 right: String::from("▐"),
60 top_left: String::from("▛"),
61 top_right: String::from("▜"),
62 bottom_left: String::from("▙"),
63 bottom_right: String::from("▟"),
64 }
65}
66
67pub fn inner_half_block_border() -> Border {
68 Border {
69 top: "▄".into(),
70 bottom: "▀".into(),
71 left: "▐".into(),
72 right: "▌".into(),
73 top_left: "▗".into(),
74 top_right: "▖".into(),
75 bottom_left: "▝".into(),
76 bottom_right: "▘".into(),
77 }
78}
79
80pub fn thick_border() -> Border {
81 Border {
82 top: "━".into(),
83 bottom: "━".into(),
84 left: "┃".into(),
85 right: "┃".into(),
86 top_left: "┏".into(),
87 top_right: "┓".into(),
88 bottom_left: "┗".into(),
89 bottom_right: "┛".into(),
90 }
91}
92
93pub fn double_border() -> Border {
94 Border {
95 top: "═".to_string(),
96 bottom: "═".to_string(),
97 left: "║".to_string(),
98 right: "║".to_string(),
99 top_left: "╔".to_string(),
100 top_right: "╗".to_string(),
101 bottom_left: "╚".to_string(),
102 bottom_right: "╝".to_string(),
103 }
104}
105
106pub fn hidden_border() -> Border {
107 Border {
108 top: " ".into(),
109 bottom: " ".into(),
110 left: " ".into(),
111 right: " ".into(),
112 top_left: " ".into(),
113 top_right: " ".into(),
114 bottom_left: " ".into(),
115 bottom_right: " ".into(),
116 }
117}
118
119pub fn get_first_char_as_string(strs: &str) -> String {
120 if let Some(ch) = strs.chars().next() {
121 return ch.to_string();
122 }
123 return String::from("");
124}
125
126pub fn render_horizontal_edge(left: &str, mut middle: &str, right: &str, width: usize) -> String {
127 let mut compiled_string = String::new();
128 if width < 1 {
129 return String::from("");
130 }
131
132 if middle.is_empty() {
133 middle = " ";
134 }
135
136 let left_width = display_width(left);
137 let right_width = display_width(right);
138
139 let mut j = 0;
140 let mut i = left_width + right_width;
141 let chars: Vec<String> = middle.chars().map(|c| c.to_string()).collect();
142 compiled_string.push_str(left);
143
144 while i < (left_width + width + right_width) {
145 compiled_string.push_str(&chars[j]);
146 j += 1;
147 if j >= chars.len() {
148 j = 0
149 }
150 i += display_width(&chars[j].to_string());
151 }
152 compiled_string.push_str(right);
153
154 compiled_string
155}