tuxtui_core/
symbols.rs

1//! Symbol sets for box drawing and UI elements.
2
3/// Line style for borders and separators.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct LineStyle {
6    /// Horizontal line
7    pub horizontal: &'static str,
8    /// Vertical line
9    pub vertical: &'static str,
10    /// Top-left corner
11    pub top_left: &'static str,
12    /// Top-right corner
13    pub top_right: &'static str,
14    /// Bottom-left corner
15    pub bottom_left: &'static str,
16    /// Bottom-right corner
17    pub bottom_right: &'static str,
18    /// Vertical and right intersection
19    pub vertical_right: &'static str,
20    /// Vertical and left intersection
21    pub vertical_left: &'static str,
22    /// Horizontal and down intersection
23    pub horizontal_down: &'static str,
24    /// Horizontal and up intersection
25    pub horizontal_up: &'static str,
26    /// Cross intersection
27    pub cross: &'static str,
28}
29
30/// Simple single-line borders (ASCII-compatible).
31pub const SIMPLE: LineStyle = LineStyle {
32    horizontal: "-",
33    vertical: "|",
34    top_left: "+",
35    top_right: "+",
36    bottom_left: "+",
37    bottom_right: "+",
38    vertical_right: "+",
39    vertical_left: "+",
40    horizontal_down: "+",
41    horizontal_up: "+",
42    cross: "+",
43};
44
45/// Single-line box drawing characters.
46pub const NORMAL: LineStyle = LineStyle {
47    horizontal: "─",
48    vertical: "│",
49    top_left: "┌",
50    top_right: "┐",
51    bottom_left: "└",
52    bottom_right: "┘",
53    vertical_right: "├",
54    vertical_left: "┤",
55    horizontal_down: "┬",
56    horizontal_up: "┴",
57    cross: "┼",
58};
59
60/// Rounded corner box drawing.
61pub const ROUNDED: LineStyle = LineStyle {
62    horizontal: "─",
63    vertical: "│",
64    top_left: "╭",
65    top_right: "╮",
66    bottom_left: "╰",
67    bottom_right: "╯",
68    vertical_right: "├",
69    vertical_left: "┤",
70    horizontal_down: "┬",
71    horizontal_up: "┴",
72    cross: "┼",
73};
74
75/// Double-line box drawing.
76pub const DOUBLE: LineStyle = LineStyle {
77    horizontal: "═",
78    vertical: "║",
79    top_left: "╔",
80    top_right: "╗",
81    bottom_left: "╚",
82    bottom_right: "╝",
83    vertical_right: "╠",
84    vertical_left: "╣",
85    horizontal_down: "╦",
86    horizontal_up: "╩",
87    cross: "╬",
88};
89
90/// Thick line style.
91pub const THICK: LineStyle = LineStyle {
92    horizontal: "━",
93    vertical: "┃",
94    top_left: "┏",
95    top_right: "┓",
96    bottom_left: "┗",
97    bottom_right: "┛",
98    vertical_right: "┣",
99    vertical_left: "┫",
100    horizontal_down: "┳",
101    horizontal_up: "┻",
102    cross: "╋",
103};
104
105/// Scrollbar symbols.
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
107pub struct ScrollbarSymbols {
108    /// The track symbol
109    pub track: &'static str,
110    /// The thumb symbol
111    pub thumb: &'static str,
112    /// Begin arrow
113    pub begin: &'static str,
114    /// End arrow
115    pub end: &'static str,
116}
117
118/// Default scrollbar symbols.
119pub const SCROLLBAR_DEFAULT: ScrollbarSymbols = ScrollbarSymbols {
120    track: "│",
121    thumb: "█",
122    begin: "▲",
123    end: "▼",
124};
125
126/// Scrollbar with block symbols.
127pub const SCROLLBAR_BLOCK: ScrollbarSymbols = ScrollbarSymbols {
128    track: "░",
129    thumb: "█",
130    begin: "▲",
131    end: "▼",
132};
133
134/// Bar chart symbols.
135pub const BAR_FULL: &str = "█";
136/// Seven-eighths filled bar symbol.
137pub const BAR_SEVEN_EIGHTHS: &str = "▉";
138/// Three-quarters filled bar symbol.
139pub const BAR_THREE_QUARTERS: &str = "▊";
140/// Five-eighths filled bar symbol.
141pub const BAR_FIVE_EIGHTHS: &str = "▋";
142/// Half filled bar symbol.
143pub const BAR_HALF: &str = "▌";
144/// Three-eighths filled bar symbol.
145pub const BAR_THREE_EIGHTHS: &str = "▍";
146/// Quarter filled bar symbol.
147pub const BAR_QUARTER: &str = "▎";
148/// One-eighth filled bar symbol.
149pub const BAR_ONE_EIGHTH: &str = "▏";
150
151/// Block symbols for different fill levels.
152pub const BLOCKS: [&str; 9] = [
153    " ",
154    BAR_ONE_EIGHTH,
155    BAR_QUARTER,
156    BAR_THREE_EIGHTHS,
157    BAR_HALF,
158    BAR_FIVE_EIGHTHS,
159    BAR_THREE_QUARTERS,
160    BAR_SEVEN_EIGHTHS,
161    BAR_FULL,
162];
163
164/// Dot symbols for charts.
165pub const DOT: &str = "•";
166/// Filled bullet point symbol.
167pub const BULLET: &str = "●";
168/// Empty circle symbol.
169pub const CIRCLE: &str = "○";
170
171/// Marker symbols for lists.
172pub const MARKER_DOT: &str = "•";
173/// Arrow marker symbol.
174pub const MARKER_ARROW: &str = "→";
175/// Angle bracket marker symbol.
176pub const MARKER_ANGLE: &str = "❯";
177/// Check mark symbol.
178pub const MARKER_CHECK: &str = "✓";
179
180/// Braille patterns for high-resolution canvas rendering.
181pub mod braille {
182    /// Get a braille character for the given pattern.
183    ///
184    /// The bits represent dots in this layout:
185    /// ```text
186    /// 0 3
187    /// 1 4
188    /// 2 5
189    /// 6 7
190    /// ```
191    #[must_use]
192    pub fn char_from_bits(bits: u8) -> char {
193        // Braille pattern base is U+2800
194        char::from_u32(0x2800 + bits as u32).unwrap_or('?')
195    }
196}
197
198#[cfg(test)]
199mod tests {
200    use super::*;
201
202    #[test]
203    fn test_line_styles() {
204        assert_eq!(NORMAL.horizontal, "─");
205        assert_eq!(ROUNDED.top_left, "╭");
206        assert_eq!(DOUBLE.vertical, "║");
207    }
208
209    #[test]
210    fn test_braille() {
211        let c = braille::char_from_bits(0b11111111);
212        assert_eq!(c, '⣿');
213    }
214}