1use strum::{Display, EnumString};
2
3pub mod border;
4pub mod line;
5
6pub mod block {
7 pub const FULL: &str = "█";
8 pub const SEVEN_EIGHTHS: &str = "▉";
9 pub const THREE_QUARTERS: &str = "▊";
10 pub const FIVE_EIGHTHS: &str = "▋";
11 pub const HALF: &str = "▌";
12 pub const THREE_EIGHTHS: &str = "▍";
13 pub const ONE_QUARTER: &str = "▎";
14 pub const ONE_EIGHTH: &str = "▏";
15
16 #[derive(Debug, Clone, Eq, PartialEq, Hash)]
17 pub struct Set {
18 pub full: &'static str,
19 pub seven_eighths: &'static str,
20 pub three_quarters: &'static str,
21 pub five_eighths: &'static str,
22 pub half: &'static str,
23 pub three_eighths: &'static str,
24 pub one_quarter: &'static str,
25 pub one_eighth: &'static str,
26 pub empty: &'static str,
27 }
28
29 impl Default for Set {
30 fn default() -> Self {
31 NINE_LEVELS
32 }
33 }
34
35 pub const THREE_LEVELS: Set = Set {
36 full: FULL,
37 seven_eighths: FULL,
38 three_quarters: HALF,
39 five_eighths: HALF,
40 half: HALF,
41 three_eighths: HALF,
42 one_quarter: HALF,
43 one_eighth: " ",
44 empty: " ",
45 };
46
47 pub const NINE_LEVELS: Set = Set {
48 full: FULL,
49 seven_eighths: SEVEN_EIGHTHS,
50 three_quarters: THREE_QUARTERS,
51 five_eighths: FIVE_EIGHTHS,
52 half: HALF,
53 three_eighths: THREE_EIGHTHS,
54 one_quarter: ONE_QUARTER,
55 one_eighth: ONE_EIGHTH,
56 empty: " ",
57 };
58}
59
60pub mod half_block {
61 pub const UPPER: char = '▀';
62 pub const LOWER: char = '▄';
63 pub const FULL: char = '█';
64}
65
66pub mod bar {
67 pub const FULL: &str = "█";
68 pub const SEVEN_EIGHTHS: &str = "▇";
69 pub const THREE_QUARTERS: &str = "▆";
70 pub const FIVE_EIGHTHS: &str = "▅";
71 pub const HALF: &str = "▄";
72 pub const THREE_EIGHTHS: &str = "▃";
73 pub const ONE_QUARTER: &str = "▂";
74 pub const ONE_EIGHTH: &str = "▁";
75
76 #[derive(Debug, Clone, Eq, PartialEq, Hash)]
77 pub struct Set {
78 pub full: &'static str,
79 pub seven_eighths: &'static str,
80 pub three_quarters: &'static str,
81 pub five_eighths: &'static str,
82 pub half: &'static str,
83 pub three_eighths: &'static str,
84 pub one_quarter: &'static str,
85 pub one_eighth: &'static str,
86 pub empty: &'static str,
87 }
88
89 impl Default for Set {
90 fn default() -> Self {
91 NINE_LEVELS
92 }
93 }
94
95 pub const THREE_LEVELS: Set = Set {
96 full: FULL,
97 seven_eighths: FULL,
98 three_quarters: HALF,
99 five_eighths: HALF,
100 half: HALF,
101 three_eighths: HALF,
102 one_quarter: HALF,
103 one_eighth: " ",
104 empty: " ",
105 };
106
107 pub const NINE_LEVELS: Set = Set {
108 full: FULL,
109 seven_eighths: SEVEN_EIGHTHS,
110 three_quarters: THREE_QUARTERS,
111 five_eighths: FIVE_EIGHTHS,
112 half: HALF,
113 three_eighths: THREE_EIGHTHS,
114 one_quarter: ONE_QUARTER,
115 one_eighth: ONE_EIGHTH,
116 empty: " ",
117 };
118}
119
120pub const DOT: &str = "•";
121
122pub mod braille {
123 pub const BLANK: u16 = 0x2800;
124 pub const DOTS: [[u16; 2]; 4] = [
125 [0x0001, 0x0008],
126 [0x0002, 0x0010],
127 [0x0004, 0x0020],
128 [0x0040, 0x0080],
129 ];
130}
131
132#[derive(Debug, Default, Display, EnumString, Clone, Copy, Eq, PartialEq, Hash)]
134pub enum Marker {
135 #[default]
137 Dot,
138 Block,
140 Bar,
142 Braille,
151 HalfBlock,
155}
156
157pub mod scrollbar {
158 use crate::symbols::{block, line};
159
160 #[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
170 pub struct Set {
171 pub track: &'static str,
172 pub thumb: &'static str,
173 pub begin: &'static str,
174 pub end: &'static str,
175 }
176
177 pub const DOUBLE_VERTICAL: Set = Set {
178 track: line::DOUBLE_VERTICAL,
179 thumb: block::FULL,
180 begin: "▲",
181 end: "▼",
182 };
183
184 pub const DOUBLE_HORIZONTAL: Set = Set {
185 track: line::DOUBLE_HORIZONTAL,
186 thumb: block::FULL,
187 begin: "◄",
188 end: "►",
189 };
190
191 pub const VERTICAL: Set = Set {
192 track: line::VERTICAL,
193 thumb: block::FULL,
194 begin: "↑",
195 end: "↓",
196 };
197
198 pub const HORIZONTAL: Set = Set {
199 track: line::HORIZONTAL,
200 thumb: block::FULL,
201 begin: "←",
202 end: "→",
203 };
204}
205
206pub mod shade {
207 pub const EMPTY: &str = " ";
208 pub const LIGHT: &str = "░";
209 pub const MEDIUM: &str = "▒";
210 pub const DARK: &str = "▓";
211 pub const FULL: &str = "█";
212}
213
214#[cfg(test)]
215mod tests {
216 use strum::ParseError;
217
218 use super::*;
219
220 #[test]
221 fn marker_tostring() {
222 assert_eq!(Marker::Dot.to_string(), "Dot");
223 assert_eq!(Marker::Block.to_string(), "Block");
224 assert_eq!(Marker::Bar.to_string(), "Bar");
225 assert_eq!(Marker::Braille.to_string(), "Braille");
226 }
227
228 #[test]
229 fn marker_from_str() {
230 assert_eq!("Dot".parse::<Marker>(), Ok(Marker::Dot));
231 assert_eq!("Block".parse::<Marker>(), Ok(Marker::Block));
232 assert_eq!("Bar".parse::<Marker>(), Ok(Marker::Bar));
233 assert_eq!("Braille".parse::<Marker>(), Ok(Marker::Braille));
234 assert_eq!("".parse::<Marker>(), Err(ParseError::VariantNotFound));
235 }
236}