1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
pub enum Colour {
    Black,
    Blue,
    Green,
    Cyan,
    Red,
    Magenta,
    Brown,
    LightGray,
    DarkGray,
    LightBlue,
    LightGreen,
    LightCyan,
    LightRed,
    LightMagenta,
    Yellow,
    White,
    Rgb(u8, u8, u8),
}

impl Colour {
    pub fn colour(&self) -> u32 {
        match self {
            Colour::Black => 0xff000000,
            Colour::Blue => 0xff800000,
            Colour::Green => 0xff008000,
            Colour::Cyan => 0xff808000,
            Colour::Red => 0xff000080,
            Colour::Magenta => 0xff800080,
            Colour::Brown => 0xff008080,
            Colour::LightGray => 0xff808080,
            Colour::DarkGray => 0xff404040,
            Colour::LightBlue => 0xffff0000,
            Colour::LightGreen => 0xff00ff00,
            Colour::LightCyan => 0xffffff00,
            Colour::LightRed => 0xff0000ff,
            Colour::LightMagenta => 0xffff00ff,
            Colour::Yellow => 0xff00ffff,
            Colour::White => 0xffffffff,
            Colour::Rgb(r, g, b) => {
                let r = *r as u32;
                let g = *g as u32;
                let b = *b as u32;
                0xff000000 | (r << 16) | (g << 8) | b
            }
        }
    }
}

impl From<Colour> for u32 {
    fn from(colour: Colour) -> Self {
        colour.colour()
    }
}