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 +enum class Attribute : int { - Normal = 0, - Underline = 1, - Reverse = 2, - Blink = 4, - Bold = 8 + 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} {} }; diff --git a/src/face_registry.cc b/src/face_registry.cc index 74868151..b057ec6c 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -21,9 +21,11 @@ static Face parse_face(StringView facedesc) { switch (*attr_it) { - case 'u': res.attributes |= Underline; break; - case 'r': res.attributes |= Reverse; break; - case 'b': res.attributes |= Bold; break; + case 'u': res.attributes |= Attribute::Underline; break; + case 'r': res.attributes |= Attribute::Reverse; break; + case 'b': res.attributes |= Attribute::Bold; break; + case 'B': res.attributes |= Attribute::Blink; break; + case 'd': res.attributes |= Attribute::Dim; break; default: throw runtime_error("unknown face attribute '" + String(*attr_it) + "'"); } } @@ -81,8 +83,8 @@ FaceRegistry::FaceRegistry() { "StatusLine", { Colors::Cyan, Colors::Default } }, { "StatusCursor", { Colors::Black, Colors::Cyan } }, { "Prompt", { Colors::Yellow, Colors::Default } }, - { "MatchingChar", { Colors::Default, Colors::Default, Underline } }, - { "Search", { Colors::Default, Colors::Default, Underline } }, + { "MatchingChar", { Colors::Default, Colors::Default, Attribute::Underline } }, + { "Search", { Colors::Default, Colors::Default, Attribute::Underline } }, } {} diff --git a/src/highlighters.cc b/src/highlighters.cc index cd191fa7..9e3fd819 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -156,7 +156,7 @@ auto apply_face = [](const Face& face) atom.face.fg = face.fg; if (face.bg != Colors::Default) atom.face.bg = face.bg; - if (face.attributes != Normal) + if (face.attributes != Attribute::Normal) atom.face.attributes |= face.attributes; }; }; diff --git a/src/ncurses.cc b/src/ncurses.cc index 0335638f..980f2bdd 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -196,10 +196,11 @@ static void set_face(WINDOW* window, Face face) wattron(window, COLOR_PAIR(current_pair)); } - set_attribute(A_UNDERLINE, face.attributes & Underline); - set_attribute(A_REVERSE, face.attributes & Reverse); - set_attribute(A_BLINK, face.attributes & Blink); - set_attribute(A_BOLD, face.attributes & Bold); + set_attribute(A_UNDERLINE, face.attributes & Attribute::Underline); + set_attribute(A_REVERSE, face.attributes & Attribute::Reverse); + set_attribute(A_BLINK, face.attributes & Attribute::Blink); + set_attribute(A_BOLD, face.attributes & Attribute::Bold); + set_attribute(A_DIM, face.attributes & Attribute::Dim); } static sig_atomic_t resize_pending = 0;