summaryrefslogtreecommitdiff
path: root/src/face.hh
blob: 098664d7e9e71ec96cf89338f559a85bfdd30578 (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
53
54
55
56
57
58
59
60
61
62
#ifndef face_hh_INCLUDED
#define face_hh_INCLUDED

#include "color.hh"
#include "flags.hh"

namespace Kakoune
{

enum class Attribute : int
{
    Normal    = 0,
    Exclusive = 1 << 1,
    Underline = 1 << 2,
    Reverse   = 1 << 3,
    Blink     = 1 << 4,
    Bold      = 1 << 5,
    Dim       = 1 << 6,
    Italic    = 1 << 7,
};

constexpr bool with_bit_ops(Meta::Type<Attribute>) { return true; }

struct Face
{
    Color fg;
    Color bg;
    Attribute attributes;

    constexpr Face(Color fg = Color::Default, Color bg = Color::Default,
         Attribute attributes = Attribute::Normal)
      : fg{fg}, bg{bg}, attributes{attributes} {}
};

constexpr bool operator==(const Face& lhs, const Face& rhs)
{
    return lhs.fg == rhs.fg and
           lhs.bg == rhs.bg and
           lhs.attributes == rhs.attributes;
}

constexpr bool operator!=(const Face& lhs, const Face& rhs)
{
    return not (lhs == rhs);
}

constexpr size_t hash_value(const Face& val)
{
    return hash_values(val.fg, val.bg, val.attributes);
}

constexpr Face merge_faces(const Face& base, const Face& face)
{
    return face.attributes & Attribute::Exclusive ?
       face : Face{ face.fg == Color::Default ? base.fg : face.fg,
                    face.bg == Color::Default ? base.bg : face.bg,
                    face.attributes | base.attributes };
}

}

#endif // face_hh_INCLUDED