summaryrefslogtreecommitdiff
path: root/src/color.hh
blob: 1de59fcd31c5cfbafc7ee8d1e37b6553a589c2e3 (plain)
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
#ifndef color_hh_INCLUDED
#define color_hh_INCLUDED

namespace Kakoune
{

class String;
class StringView;

enum class Colors : char
{
    Default,
    Black,
    Red,
    Green,
    Yellow,
    Blue,
    Magenta,
    Cyan,
    White,
    RGB,
};

struct Color
{
    Colors color;
    unsigned char r;
    unsigned char g;
    unsigned char b;

    Color() : Color{Colors::Default} {}
    Color(Colors c) : color{c}, r{0}, g{0}, b{0} {}
    Color(unsigned char r, unsigned char g, unsigned char b)
        : color{Colors::RGB}, r{r}, g{g}, b{b} {}

    bool operator==(Color c) const
    { return color == c.color and r == c.r and g == c.g and b == c.b; }
    bool operator!=(Color c) const
    { return color != c.color or r != c.r or g != c.g or b != c.b; }
};

Color str_to_color(StringView color);
String color_to_str(Color color);

String option_to_string(Color color);
void option_from_string(StringView str, Color& color);

bool is_color_name(StringView color);

}

#endif // color_hh_INCLUDED