Skip to main content

oxicode/symbols/
mod.rs

1#![allow(missing_docs)]
2
3use serde::{Deserialize, Serialize};
4use std::str::FromStr;
5
6/// Minimal glyph set selection for oxicode settings.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
8#[serde(rename_all = "snake_case")]
9pub enum GlyphSet {
10    Unicode,
11    Ascii,
12    Nerd,
13}
14
15impl Default for GlyphSet {
16    fn default() -> Self {
17        GlyphSet::Unicode
18    }
19}
20
21impl std::fmt::Display for GlyphSet {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            GlyphSet::Unicode => write!(f, "unicode"),
25            GlyphSet::Ascii => write!(f, "ascii"),
26            GlyphSet::Nerd => write!(f, "nerd"),
27        }
28    }
29}
30
31impl FromStr for GlyphSet {
32    type Err = String;
33    fn from_str(s: &str) -> Result<Self, Self::Err> {
34        match s.to_lowercase().as_str() {
35            "unicode" => Ok(GlyphSet::Unicode),
36            "ascii" => Ok(GlyphSet::Ascii),
37            "nerd" => Ok(GlyphSet::Nerd),
38            _ => Err(format!("Unknown glyph set: {s}")),
39        }
40    }
41}
42
43impl GlyphSet {
44    pub fn label(&self) -> &'static str {
45        match self {
46            GlyphSet::Unicode => "Unicode",
47            GlyphSet::Ascii => "ASCII",
48            GlyphSet::Nerd => "Nerd",
49        }
50    }
51}
52
53pub type UnknownGlyphSet = String;