ratatui_core/symbols/
marker.rs

1use strum::{Display, EnumString};
2
3pub const DOT: &str = "•";
4
5/// Marker to use when plotting data points
6#[derive(Debug, Default, Display, EnumString, Clone, Copy, Eq, PartialEq, Hash)]
7#[non_exhaustive]
8pub enum Marker {
9    /// One point per cell in shape of dot (`•`)
10    #[default]
11    Dot,
12    /// One point per cell in shape of a block (`█`)
13    Block,
14    /// One point per cell in the shape of a bar (`▄`)
15    Bar,
16    /// Use the [Unicode Braille Patterns](https://en.wikipedia.org/wiki/Braille_Patterns) block to
17    /// represent data points.
18    ///
19    /// This is a 2x4 grid of dots, where each dot can be either on or off.
20    ///
21    /// Note: Support for this marker is limited to terminals and fonts that support Unicode
22    /// Braille Patterns. If your terminal does not support this, you will see unicode replacement
23    /// characters (`�`) instead of Braille dots (`⠓`, `⣇`, `⣿`).
24    Braille,
25    /// Use the unicode block and half block characters (`█`, `▄`, and `▀`) to represent points in
26    /// a grid that is double the resolution of the terminal. Because each terminal cell is
27    /// generally about twice as tall as it is wide, this allows for a square grid of pixels.
28    HalfBlock,
29    /// Use quadrant characters to represent data points.
30    ///
31    /// Quadrant characters display densely packed and regularly spaced pseudo-pixels with a 2x2
32    /// resolution per character, without visible bands between cells.
33    Quadrant,
34    /// Use sextant characters from the [Unicode Symbols for Legacy Computing
35    /// Supplement](https://en.wikipedia.org/wiki/Symbols_for_Legacy_Computing_Supplement) to
36    /// represent data points.
37    ///
38    /// Sextant characters display densely packed and regularly spaced pseudo-pixels with a 2x3
39    /// resolution per character, without visible bands between cells.
40    ///
41    /// Note: the Symbols for Legacy Computing Supplement block is a relatively recent addition to
42    /// unicode that is less broadly supported than Braille dots. If your terminal does not support
43    /// this, you will see unicode replacement characters (`�`) instead of sextants (`🬌`, `🬲`, `🬑`).
44    Sextant,
45    /// Use octant characters from the [Unicode Symbols for Legacy Computing
46    /// Supplement](https://en.wikipedia.org/wiki/Symbols_for_Legacy_Computing_Supplement) to
47    /// represent data points.
48    ///
49    /// Octant characters have the same 2x4 resolution as Braille characters but display densely
50    /// packed and regularly spaced pseudo-pixels, without visible bands between cells.
51    ///
52    /// Note: the Symbols for Legacy Computing Supplement block is a relatively recent addition to
53    /// unicode that is less broadly supported than Braille dots. If your terminal does not support
54    /// this, you will see unicode replacement characters (`�`) instead of octants (`𜴇`, `𜷀`, `𜴷`).
55    Octant,
56}
57
58#[cfg(test)]
59mod tests {
60    use alloc::string::ToString;
61
62    use strum::ParseError;
63
64    use super::*;
65
66    #[test]
67    fn marker_tostring() {
68        assert_eq!(Marker::Dot.to_string(), "Dot");
69        assert_eq!(Marker::Block.to_string(), "Block");
70        assert_eq!(Marker::Bar.to_string(), "Bar");
71        assert_eq!(Marker::Braille.to_string(), "Braille");
72    }
73
74    #[test]
75    fn marker_from_str() {
76        assert_eq!("Dot".parse::<Marker>(), Ok(Marker::Dot));
77        assert_eq!("Block".parse::<Marker>(), Ok(Marker::Block));
78        assert_eq!("Bar".parse::<Marker>(), Ok(Marker::Bar));
79        assert_eq!("Braille".parse::<Marker>(), Ok(Marker::Braille));
80        assert_eq!("".parse::<Marker>(), Err(ParseError::VariantNotFound));
81    }
82}