use crate::palette::Role;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum Sigil {
Snowflake,
Check,
Cross,
Arrow,
Section,
Dot,
DotHollow,
Plus,
Minus,
Tilde,
PlusMinus,
Triangle,
Clock,
Diamond,
Lightning,
Gear,
Hex,
}
impl Sigil {
pub fn glyph(self) -> &'static str {
match self {
Self::Snowflake => "❄",
Self::Check => "✓",
Self::Cross => "✗",
Self::Arrow => "→",
Self::Section => "⟡",
Self::Dot => "●",
Self::DotHollow => "○",
Self::Plus => "+",
Self::Minus => "−",
Self::Tilde => "~",
Self::PlusMinus => "±",
Self::Triangle => "▲",
Self::Clock => "⏱",
Self::Diamond => "◇",
Self::Lightning => "⚡",
Self::Gear => "⚙",
Self::Hex => "⬢",
}
}
pub fn default_role(self) -> Role {
match self {
Self::Snowflake | Self::Triangle | Self::Section | Self::Hex => Role::Primary,
Self::Check | Self::Plus | Self::Lightning => Role::Success,
Self::Cross | Self::Minus => Role::Error,
Self::Tilde | Self::Clock | Self::Gear => Role::Warn,
Self::Arrow | Self::Dot | Self::Diamond => Role::Info,
Self::DotHollow | Self::PlusMinus => Role::Dim,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_sigil_renders_to_one_display_cluster() {
for s in [
Sigil::Snowflake,
Sigil::Check,
Sigil::Cross,
Sigil::Arrow,
Sigil::Section,
Sigil::Dot,
Sigil::DotHollow,
Sigil::Plus,
Sigil::Minus,
Sigil::Tilde,
Sigil::PlusMinus,
Sigil::Triangle,
Sigil::Clock,
Sigil::Diamond,
Sigil::Lightning,
Sigil::Gear,
Sigil::Hex,
] {
assert!(!s.glyph().is_empty());
}
}
#[test]
fn semantic_role_mapping_matches_intuition() {
assert!(matches!(Sigil::Check.default_role(), Role::Success));
assert!(matches!(Sigil::Cross.default_role(), Role::Error));
assert!(matches!(Sigil::Snowflake.default_role(), Role::Primary));
assert!(matches!(Sigil::Tilde.default_role(), Role::Warn));
}
}