oseda_cli/
color.rs

1use serde::{Deserialize, Serialize};
2use strum_macros::{Display, EnumIter};
3
4
5#[derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumIter)]
6pub enum Color {
7    Black,
8    White,
9    Red,
10    Green,
11    Blue,
12    Yellow,
13    Cyan,
14    Magenta,
15    Gray,
16    Silver,
17    Maroon,
18    Olive,
19    Lime,
20    Navy,
21    Teal,
22    Purple,
23    Orange,
24    Brown,
25    Pink,
26    Gold,
27}
28
29impl Color {
30    pub fn into_hex(&self) -> String {
31
32        match self {
33            self::Color::Black =>   "#000000".to_owned(),
34            self::Color::White =>	"#FFFFFF".to_owned(),
35            self::Color::Red =>	    "#FF0000".to_owned(),
36            self::Color::Green =>	"#008000".to_owned(),
37            self::Color::Blue =>	"#0000FF".to_owned(),
38            self::Color::Yellow =>	"#FFFF00".to_owned(),
39            self::Color::Cyan => 	"#00FFFF".to_owned(),
40            self::Color::Magenta =>	"#FF00FF".to_owned(),
41            self::Color::Gray =>	"#808080".to_owned(),
42            self::Color::Silver =>	"#C0C0C0".to_owned(),
43            self::Color::Maroon =>	"#800000".to_owned(),
44            self::Color::Olive =>	"#808000".to_owned(),
45            self::Color::Lime =>	"#00FF00".to_owned(),
46            self::Color::Navy =>	"#000080".to_owned(),
47            self::Color::Teal =>	"#008080".to_owned(),
48            self::Color::Purple =>	"#800080".to_owned(),
49            self::Color::Orange =>	"#FFA500".to_owned(),
50            self::Color::Brown =>	"#A52A2A".to_owned(),
51            self::Color::Pink =>	"#FFC0CB".to_owned(),
52            self::Color::Gold =>	"#FFD700".to_owned(),
53        }
54    }
55}
56
57// trick to let me only serialize this specific value in a struct with this logic, instead of default
58pub fn as_hex<S>(c: &Color, s: S) -> Result<S::Ok, S::Error>
59where
60    S: serde::Serializer,
61{
62    s.serialize_str(&c.into_hex())
63}