summaryrefslogtreecommitdiff
path: root/src/face.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-07-15 20:11:47 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-07-15 20:11:47 +0100
commit032b6211503bb0491e4df38e7f62437a1f35b6d0 (patch)
tree9b99c7184bcbfba47fa5f2e7828a6a747e6fcc9f /src/face.hh
parente6699c66ede2d482fe2a6d16c3367913c5116dad (diff)
Use strongly typed enum for Face Attribute, add Dim
Diffstat (limited to 'src/face.hh')
-rw-r--r--src/face.hh38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/face.hh b/src/face.hh
index 1914ff7b..00bb4e08 100644
--- a/src/face.hh
+++ b/src/face.hh
@@ -6,16 +6,36 @@
namespace Kakoune
{
-using Attribute = char;
-enum Attributes
-{
- Normal = 0,
- Underline = 1,
- Reverse = 2,
- Blink = 4,
- Bold = 8
+enum class Attribute : int
+{
+ Normal = 0,
+ Underline = 1 << 1,
+ Reverse = 1 << 2,
+ Blink = 1 << 3,
+ Bold = 1 << 4,
+ Dim = 1 << 5
};
+inline constexpr Attribute operator|(Attribute lhs, Attribute rhs)
+{
+ return (Attribute)((int) lhs | (int) rhs);
+}
+
+inline Attribute& operator|=(Attribute& lhs, Attribute rhs)
+{
+ return (Attribute&)((int&) lhs |= (int) rhs);
+}
+
+inline constexpr bool operator&(Attribute lhs, Attribute rhs)
+{
+ return ((int) lhs & (int) rhs) != 0;
+}
+
+inline Attribute& operator&=(Attribute& lhs, Attribute rhs)
+{
+ return (Attribute&)((int&) lhs &= (int) rhs);
+}
+
struct Face
{
Color fg;
@@ -23,7 +43,7 @@ struct Face
Attribute attributes;
Face(Color fg = Colors::Default, Color bg = Colors::Default,
- Attribute attributes = 0)
+ Attribute attributes = Attribute::Normal)
: fg{fg}, bg{bg}, attributes{attributes} {}
};