bootc_lib/
glyph.rs

1//! Special Unicode characters used for display with ASCII fallbacks
2//! in case we're not in a UTF-8 locale.
3
4use std::fmt::Display;
5
6#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7pub(crate) enum Glyph {
8    BlackCircle,
9}
10
11impl Glyph {
12    // TODO: Add support for non-Unicode output
13    #[allow(dead_code)]
14    pub(crate) fn as_ascii(&self) -> &'static str {
15        match self {
16            Glyph::BlackCircle => "*",
17        }
18    }
19
20    pub(crate) fn as_utf8(&self) -> &'static str {
21        match self {
22            Glyph::BlackCircle => "●",
23        }
24    }
25}
26
27impl Display for Glyph {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        f.write_str(self.as_utf8())
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn test_glyph() {
39        assert_eq!(Glyph::BlackCircle.as_utf8(), "●");
40    }
41}