1pub const VERTICAL: &str = "│";
2pub const DOUBLE_VERTICAL: &str = "║";
3pub const THICK_VERTICAL: &str = "┃";
4
5pub const HORIZONTAL: &str = "─";
6pub const DOUBLE_HORIZONTAL: &str = "═";
7pub const THICK_HORIZONTAL: &str = "━";
8
9pub const TOP_RIGHT: &str = "┐";
10pub const ROUNDED_TOP_RIGHT: &str = "╮";
11pub const DOUBLE_TOP_RIGHT: &str = "╗";
12pub const THICK_TOP_RIGHT: &str = "┓";
13
14pub const TOP_LEFT: &str = "┌";
15pub const ROUNDED_TOP_LEFT: &str = "╭";
16pub const DOUBLE_TOP_LEFT: &str = "╔";
17pub const THICK_TOP_LEFT: &str = "┏";
18
19pub const BOTTOM_RIGHT: &str = "┘";
20pub const ROUNDED_BOTTOM_RIGHT: &str = "╯";
21pub const DOUBLE_BOTTOM_RIGHT: &str = "╝";
22pub const THICK_BOTTOM_RIGHT: &str = "┛";
23
24pub const BOTTOM_LEFT: &str = "└";
25pub const ROUNDED_BOTTOM_LEFT: &str = "╰";
26pub const DOUBLE_BOTTOM_LEFT: &str = "╚";
27pub const THICK_BOTTOM_LEFT: &str = "┗";
28
29pub const VERTICAL_LEFT: &str = "┤";
30pub const DOUBLE_VERTICAL_LEFT: &str = "╣";
31pub const THICK_VERTICAL_LEFT: &str = "┫";
32
33pub const VERTICAL_RIGHT: &str = "├";
34pub const DOUBLE_VERTICAL_RIGHT: &str = "╠";
35pub const THICK_VERTICAL_RIGHT: &str = "┣";
36
37pub const HORIZONTAL_DOWN: &str = "┬";
38pub const DOUBLE_HORIZONTAL_DOWN: &str = "╦";
39pub const THICK_HORIZONTAL_DOWN: &str = "┳";
40
41pub const HORIZONTAL_UP: &str = "┴";
42pub const DOUBLE_HORIZONTAL_UP: &str = "╩";
43pub const THICK_HORIZONTAL_UP: &str = "┻";
44
45pub const CROSS: &str = "┼";
46pub const DOUBLE_CROSS: &str = "╬";
47pub const THICK_CROSS: &str = "╋";
48
49#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
50pub struct Set {
51 pub vertical: &'static str,
52 pub horizontal: &'static str,
53 pub top_right: &'static str,
54 pub top_left: &'static str,
55 pub bottom_right: &'static str,
56 pub bottom_left: &'static str,
57 pub vertical_left: &'static str,
58 pub vertical_right: &'static str,
59 pub horizontal_down: &'static str,
60 pub horizontal_up: &'static str,
61 pub cross: &'static str,
62}
63
64impl Default for Set {
65 fn default() -> Self {
66 NORMAL
67 }
68}
69
70pub const NORMAL: Set = Set {
71 vertical: VERTICAL,
72 horizontal: HORIZONTAL,
73 top_right: TOP_RIGHT,
74 top_left: TOP_LEFT,
75 bottom_right: BOTTOM_RIGHT,
76 bottom_left: BOTTOM_LEFT,
77 vertical_left: VERTICAL_LEFT,
78 vertical_right: VERTICAL_RIGHT,
79 horizontal_down: HORIZONTAL_DOWN,
80 horizontal_up: HORIZONTAL_UP,
81 cross: CROSS,
82};
83
84pub const ROUNDED: Set = Set {
85 top_right: ROUNDED_TOP_RIGHT,
86 top_left: ROUNDED_TOP_LEFT,
87 bottom_right: ROUNDED_BOTTOM_RIGHT,
88 bottom_left: ROUNDED_BOTTOM_LEFT,
89 ..NORMAL
90};
91
92pub const DOUBLE: Set = Set {
93 vertical: DOUBLE_VERTICAL,
94 horizontal: DOUBLE_HORIZONTAL,
95 top_right: DOUBLE_TOP_RIGHT,
96 top_left: DOUBLE_TOP_LEFT,
97 bottom_right: DOUBLE_BOTTOM_RIGHT,
98 bottom_left: DOUBLE_BOTTOM_LEFT,
99 vertical_left: DOUBLE_VERTICAL_LEFT,
100 vertical_right: DOUBLE_VERTICAL_RIGHT,
101 horizontal_down: DOUBLE_HORIZONTAL_DOWN,
102 horizontal_up: DOUBLE_HORIZONTAL_UP,
103 cross: DOUBLE_CROSS,
104};
105
106pub const THICK: Set = Set {
107 vertical: THICK_VERTICAL,
108 horizontal: THICK_HORIZONTAL,
109 top_right: THICK_TOP_RIGHT,
110 top_left: THICK_TOP_LEFT,
111 bottom_right: THICK_BOTTOM_RIGHT,
112 bottom_left: THICK_BOTTOM_LEFT,
113 vertical_left: THICK_VERTICAL_LEFT,
114 vertical_right: THICK_VERTICAL_RIGHT,
115 horizontal_down: THICK_HORIZONTAL_DOWN,
116 horizontal_up: THICK_HORIZONTAL_UP,
117 cross: THICK_CROSS,
118};
119
120#[cfg(test)]
121mod tests {
122 use indoc::{formatdoc, indoc};
123
124 use super::*;
125
126 #[test]
127 fn default() {
128 assert_eq!(Set::default(), NORMAL);
129 }
130
131 fn render(set: Set) -> String {
133 formatdoc!(
134 "{}{}{}{}
135 {}{}{}{}
136 {}{}{}{}
137 {}{}{}{}",
138 set.top_left,
139 set.horizontal,
140 set.horizontal_down,
141 set.top_right,
142 set.vertical,
143 " ",
144 set.vertical,
145 set.vertical,
146 set.vertical_right,
147 set.horizontal,
148 set.cross,
149 set.vertical_left,
150 set.bottom_left,
151 set.horizontal,
152 set.horizontal_up,
153 set.bottom_right
154 )
155 }
156
157 #[test]
158 fn normal() {
159 assert_eq!(
160 render(NORMAL),
161 indoc!(
162 "┌─┬┐
163 │ ││
164 ├─┼┤
165 └─┴┘"
166 )
167 );
168 }
169
170 #[test]
171 fn rounded() {
172 assert_eq!(
173 render(ROUNDED),
174 indoc!(
175 "╭─┬╮
176 │ ││
177 ├─┼┤
178 ╰─┴╯"
179 )
180 );
181 }
182
183 #[test]
184 fn double() {
185 assert_eq!(
186 render(DOUBLE),
187 indoc!(
188 "╔═╦╗
189 ║ ║║
190 ╠═╬╣
191 ╚═╩╝"
192 )
193 );
194 }
195
196 #[test]
197 fn thick() {
198 assert_eq!(
199 render(THICK),
200 indoc!(
201 "┏━┳┓
202 ┃ ┃┃
203 ┣━╋┫
204 ┗━┻┛"
205 )
206 );
207 }
208}