2014-07-11 01:27:04 +02:00
|
|
|
#ifndef face_hh_INCLUDED
|
|
|
|
#define face_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "color.hh"
|
2014-11-12 21:31:56 +01:00
|
|
|
#include "flags.hh"
|
2014-07-11 01:27:04 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-07-15 21:11:47 +02:00
|
|
|
enum class Attribute : int
|
|
|
|
{
|
|
|
|
Normal = 0,
|
2018-09-23 15:17:12 +02:00
|
|
|
Underline = 1 << 1,
|
|
|
|
Reverse = 1 << 2,
|
|
|
|
Blink = 1 << 3,
|
|
|
|
Bold = 1 << 4,
|
|
|
|
Dim = 1 << 5,
|
|
|
|
Italic = 1 << 6,
|
|
|
|
FinalFg = 1 << 7,
|
|
|
|
FinalBg = 1 << 8,
|
2018-09-24 09:54:21 +02:00
|
|
|
FinalAttr = 1 << 9,
|
2018-09-23 15:17:12 +02:00
|
|
|
Final = FinalFg | FinalBg | FinalAttr
|
2014-07-11 01:27:04 +02:00
|
|
|
};
|
|
|
|
|
2017-03-15 18:55:34 +01:00
|
|
|
constexpr bool with_bit_ops(Meta::Type<Attribute>) { return true; }
|
2014-07-15 21:11:47 +02:00
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
struct Face
|
|
|
|
{
|
|
|
|
Color fg;
|
|
|
|
Color bg;
|
|
|
|
Attribute attributes;
|
|
|
|
|
2015-04-25 11:47:39 +02:00
|
|
|
constexpr Face(Color fg = Color::Default, Color bg = Color::Default,
|
2014-07-15 21:11:47 +02:00
|
|
|
Attribute attributes = Attribute::Normal)
|
2014-07-11 01:27:04 +02:00
|
|
|
: fg{fg}, bg{bg}, attributes{attributes} {}
|
|
|
|
};
|
|
|
|
|
2015-03-21 17:32:22 +01:00
|
|
|
constexpr bool operator==(const Face& lhs, const Face& rhs)
|
2014-07-11 01:27:04 +02:00
|
|
|
{
|
|
|
|
return lhs.fg == rhs.fg and
|
|
|
|
lhs.bg == rhs.bg and
|
|
|
|
lhs.attributes == rhs.attributes;
|
|
|
|
}
|
|
|
|
|
2015-03-21 17:32:22 +01:00
|
|
|
constexpr bool operator!=(const Face& lhs, const Face& rhs)
|
2014-07-11 01:27:04 +02:00
|
|
|
{
|
|
|
|
return not (lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:35:23 +02:00
|
|
|
constexpr size_t hash_value(const Face& val)
|
|
|
|
{
|
|
|
|
return hash_values(val.fg, val.bg, val.attributes);
|
|
|
|
}
|
|
|
|
|
2018-09-23 15:17:12 +02:00
|
|
|
inline Face merge_faces(const Face& base, const Face& face)
|
2015-08-23 13:13:14 +02:00
|
|
|
{
|
2018-09-23 15:17:12 +02:00
|
|
|
auto choose = [&](Color Face::*color, Attribute final_attr) {
|
|
|
|
if (face.attributes & final_attr)
|
|
|
|
return face.*color;
|
|
|
|
if (base.attributes & final_attr)
|
|
|
|
return base.*color;
|
|
|
|
if (face.*color == Color::Default)
|
|
|
|
return base.*color;
|
|
|
|
return face.*color;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Face{ choose(&Face::fg, Attribute::FinalFg),
|
|
|
|
choose(&Face::bg, Attribute::FinalBg),
|
|
|
|
face.attributes & Attribute::FinalAttr ? face.attributes :
|
|
|
|
base.attributes & Attribute::FinalAttr ? base.attributes :
|
|
|
|
face.attributes | base.attributes };
|
2015-08-23 13:13:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // face_hh_INCLUDED
|