Use strongly typed enum for Face Attribute, add Dim

This commit is contained in:
Maxime Coste 2014-07-15 20:11:47 +01:00
parent e6699c66ed
commit 032b621150
4 changed files with 41 additions and 18 deletions

View File

@ -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} {}
};

View File

@ -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 } },
}
{}

View File

@ -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;
};
};

View File

@ -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;