Move Colors enum class as NamedColor enum inside Color struct
This commit is contained in:
parent
dc46eda279
commit
bbefde9379
|
@ -30,7 +30,7 @@ Color str_to_color(StringView color)
|
|||
{
|
||||
auto it = find_if(color_names, [&](const char* c){ return color == c; });
|
||||
if (it != std::end(color_names))
|
||||
return static_cast<Colors>(it - color_names);
|
||||
return static_cast<Color::NamedColor>(it - color_names);
|
||||
|
||||
auto hval = [&color](char c) -> int
|
||||
{
|
||||
|
@ -49,12 +49,12 @@ Color str_to_color(StringView color)
|
|||
(unsigned char)(hval(color[8]) * 16 + hval(color[9])) };
|
||||
|
||||
throw runtime_error(format("Unable to parse color '{}'", color));
|
||||
return Colors::Default;
|
||||
return Color::Default;
|
||||
}
|
||||
|
||||
String color_to_str(Color color)
|
||||
{
|
||||
if (color.color == Colors::RGB)
|
||||
if (color.color == Color::RGB)
|
||||
{
|
||||
char buffer[11];
|
||||
sprintf(buffer, "rgb:%02x%02x%02x", color.r, color.g, color.b);
|
||||
|
|
22
src/color.hh
22
src/color.hh
|
@ -9,7 +9,9 @@ namespace Kakoune
|
|||
class String;
|
||||
class StringView;
|
||||
|
||||
enum class Colors : char
|
||||
struct Color
|
||||
{
|
||||
enum NamedColor : char
|
||||
{
|
||||
Default,
|
||||
Black,
|
||||
|
@ -23,17 +25,15 @@ enum class Colors : char
|
|||
RGB,
|
||||
};
|
||||
|
||||
struct Color
|
||||
{
|
||||
Colors color;
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
NamedColor color;
|
||||
unsigned char r = 0;
|
||||
unsigned char g = 0;
|
||||
unsigned char b = 0;
|
||||
|
||||
constexpr Color() : Color{Colors::Default} {}
|
||||
constexpr Color(Colors c) : color{c}, r{0}, g{0}, b{0} {}
|
||||
constexpr Color() : Color{Default} {}
|
||||
constexpr Color(NamedColor c) : color{c} {}
|
||||
constexpr Color(unsigned char r, unsigned char g, unsigned char b)
|
||||
: color{Colors::RGB}, r{r}, g{g}, b{b} {}
|
||||
: color{RGB}, r{r}, g{g}, b{b} {}
|
||||
};
|
||||
|
||||
constexpr bool operator==(Color lhs, Color rhs)
|
||||
|
@ -57,7 +57,7 @@ bool is_color_name(StringView color);
|
|||
|
||||
inline size_t hash_value(const Color& val)
|
||||
{
|
||||
return val.color == Colors::RGB ?
|
||||
return val.color == Color::RGB ?
|
||||
hash_values(val.color, val.r, val.g, val.b)
|
||||
: hash_value(val.color);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ struct Face
|
|||
Color bg;
|
||||
Attribute attributes;
|
||||
|
||||
constexpr Face(Color fg = Colors::Default, Color bg = Colors::Default,
|
||||
constexpr Face(Color fg = Color::Default, Color bg = Color::Default,
|
||||
Attribute attributes = Attribute::Normal)
|
||||
: fg{fg}, bg{bg}, attributes{attributes} {}
|
||||
};
|
||||
|
|
|
@ -91,21 +91,21 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix,
|
|||
|
||||
FaceRegistry::FaceRegistry()
|
||||
: m_aliases{
|
||||
{ "PrimarySelection", Face{ Colors::White, Colors::Blue } },
|
||||
{ "SecondarySelection", Face{ Colors::Black, Colors::Blue } },
|
||||
{ "PrimaryCursor", Face{ Colors::Black, Colors::White } },
|
||||
{ "SecondaryCursor", Face{ Colors::Black, Colors::White } },
|
||||
{ "LineNumbers", Face{ Colors::Default, Colors::Default } },
|
||||
{ "LineNumberCursor", Face{ Colors::Default, Colors::Default, Attribute::Reverse } },
|
||||
{ "MenuForeground", Face{ Colors::White, Colors::Blue } },
|
||||
{ "MenuBackground", Face{ Colors::Blue, Colors::White } },
|
||||
{ "Information", Face{ Colors::Black, Colors::Yellow } },
|
||||
{ "Error", Face{ Colors::Black, Colors::Red } },
|
||||
{ "StatusLine", Face{ Colors::Cyan, Colors::Default } },
|
||||
{ "StatusCursor", Face{ Colors::Black, Colors::Cyan } },
|
||||
{ "Prompt", Face{ Colors::Yellow, Colors::Default } },
|
||||
{ "MatchingChar", Face{ Colors::Default, Colors::Default, Attribute::Bold } },
|
||||
{ "Search", Face{ Colors::Default, Colors::Default, Attribute::Underline } },
|
||||
{ "PrimarySelection", Face{ Color::White, Color::Blue } },
|
||||
{ "SecondarySelection", Face{ Color::Black, Color::Blue } },
|
||||
{ "PrimaryCursor", Face{ Color::Black, Color::White } },
|
||||
{ "SecondaryCursor", Face{ Color::Black, Color::White } },
|
||||
{ "LineNumbers", Face{ Color::Default, Color::Default } },
|
||||
{ "LineNumberCursor", Face{ Color::Default, Color::Default, Attribute::Reverse } },
|
||||
{ "MenuForeground", Face{ Color::White, Color::Blue } },
|
||||
{ "MenuBackground", Face{ Color::Blue, Color::White } },
|
||||
{ "Information", Face{ Color::Black, Color::Yellow } },
|
||||
{ "Error", Face{ Color::Black, Color::Red } },
|
||||
{ "StatusLine", Face{ Color::Cyan, Color::Default } },
|
||||
{ "StatusCursor", Face{ Color::Black, Color::Cyan } },
|
||||
{ "Prompt", Face{ Color::Yellow, Color::Default } },
|
||||
{ "MatchingChar", Face{ Color::Default, Color::Default, Attribute::Bold } },
|
||||
{ "Search", Face{ Color::Default, Color::Default, Attribute::Underline } },
|
||||
}
|
||||
{}
|
||||
|
||||
|
|
|
@ -154,9 +154,9 @@ void apply_highlighter(const Context& context,
|
|||
auto apply_face = [](const Face& face)
|
||||
{
|
||||
return [&face](DisplayAtom& atom) {
|
||||
if (face.fg != Colors::Default)
|
||||
if (face.fg != Color::Default)
|
||||
atom.face.fg = face.fg;
|
||||
if (face.bg != Colors::Default)
|
||||
if (face.bg != Color::Default)
|
||||
atom.face.bg = face.bg;
|
||||
if (face.attributes != Attribute::Normal)
|
||||
atom.face.attributes |= face.attributes;
|
||||
|
@ -760,7 +760,7 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf
|
|||
if (next.coord() < atom_it->end())
|
||||
atom_it = line.split(atom_it, next.coord());
|
||||
atom_it->replace(str);
|
||||
atom_it->face = { Colors::Red, Colors::Black };
|
||||
atom_it->face = { Color::Red, Color::Black };
|
||||
break;
|
||||
}
|
||||
it = next;
|
||||
|
@ -800,7 +800,7 @@ HighlighterAndId create_flag_lines_highlighter(HighlighterParameters params)
|
|||
String content = it != lines.end() ? std::get<2>(*it) : empty;
|
||||
content += String(' ', width - content.char_length());
|
||||
DisplayAtom atom{std::move(content)};
|
||||
atom.face = { it != lines.end() ? std::get<1>(*it) : Colors::Default , bg };
|
||||
atom.face = { it != lines.end() ? std::get<1>(*it) : Color::Default , bg };
|
||||
line.insert(line.begin(), std::move(atom));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -225,16 +225,16 @@ public:
|
|||
|
||||
DisplayLine mode_line() const override
|
||||
{
|
||||
AtomList atoms = { { to_string(context().selections().size()) + " sel", Face(Colors::Blue) } };
|
||||
AtomList atoms = { { to_string(context().selections().size()) + " sel", Face(Color::Blue) } };
|
||||
if (m_params.count != 0)
|
||||
{
|
||||
atoms.push_back({ "; param=", Face(Colors::Yellow) });
|
||||
atoms.push_back({ to_string(m_params.count), Face(Colors::Green) });
|
||||
atoms.push_back({ "; param=", Face(Color::Yellow) });
|
||||
atoms.push_back({ to_string(m_params.count), Face(Color::Green) });
|
||||
}
|
||||
if (m_params.reg != '"')
|
||||
{
|
||||
atoms.push_back({ "; reg=", Face(Colors::Yellow) });
|
||||
atoms.push_back({ StringView(m_params.reg).str(), Face(Colors::Green) });
|
||||
atoms.push_back({ "; reg=", Face(Color::Yellow) });
|
||||
atoms.push_back({ StringView(m_params.reg).str(), Face(Color::Green) });
|
||||
}
|
||||
return atoms;
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ public:
|
|||
|
||||
DisplayLine mode_line() const override
|
||||
{
|
||||
return { "menu", Face(Colors::Yellow) };
|
||||
return { "menu", Face(Color::Yellow) };
|
||||
}
|
||||
|
||||
KeymapMode keymap_mode() const override { return KeymapMode::Menu; }
|
||||
|
@ -755,7 +755,7 @@ public:
|
|||
|
||||
DisplayLine mode_line() const override
|
||||
{
|
||||
return { "prompt", Face(Colors::Yellow) };
|
||||
return { "prompt", Face(Color::Yellow) };
|
||||
}
|
||||
|
||||
KeymapMode keymap_mode() const override { return KeymapMode::Prompt; }
|
||||
|
@ -842,7 +842,7 @@ public:
|
|||
|
||||
DisplayLine mode_line() const override
|
||||
{
|
||||
return { "enter key", Face(Colors::Yellow) };
|
||||
return { "enter key", Face(Color::Yellow) };
|
||||
}
|
||||
|
||||
KeymapMode keymap_mode() const override { return m_keymap_mode; }
|
||||
|
@ -1009,8 +1009,8 @@ public:
|
|||
DisplayLine mode_line() const override
|
||||
{
|
||||
auto num_sel = context().selections().size();
|
||||
return {AtomList{ { "insert ", Face(Colors::Green) },
|
||||
{ to_string(num_sel) + " sel", Face(Colors::Blue) } }};
|
||||
return {AtomList{ { "insert ", Face(Color::Green) },
|
||||
{ to_string(num_sel) + " sel", Face(Color::Blue) } }};
|
||||
}
|
||||
|
||||
KeymapMode keymap_mode() const override { return KeymapMode::Insert; }
|
||||
|
|
|
@ -62,7 +62,7 @@ static void set_attribute(WINDOW* window, int attribute, bool on)
|
|||
|
||||
static bool operator<(Color lhs, Color rhs)
|
||||
{
|
||||
if (lhs.color == rhs.color and lhs.color == Colors::RGB)
|
||||
if (lhs.color == rhs.color and lhs.color == Color::RGB)
|
||||
return lhs.r == rhs.r ? (lhs.g == rhs.g ? lhs.b < rhs.b
|
||||
: lhs.g < rhs.g)
|
||||
: lhs.r < rhs.r;
|
||||
|
@ -74,15 +74,15 @@ template<typename T> T sq(T x) { return x * x; }
|
|||
static int nc_color(Color color)
|
||||
{
|
||||
static std::map<Color, int> colors = {
|
||||
{ Colors::Default, -1 },
|
||||
{ Colors::Black, COLOR_BLACK },
|
||||
{ Colors::Red, COLOR_RED },
|
||||
{ Colors::Green, COLOR_GREEN },
|
||||
{ Colors::Yellow, COLOR_YELLOW },
|
||||
{ Colors::Blue, COLOR_BLUE },
|
||||
{ Colors::Magenta, COLOR_MAGENTA },
|
||||
{ Colors::Cyan, COLOR_CYAN },
|
||||
{ Colors::White, COLOR_WHITE },
|
||||
{ Color::Default, -1 },
|
||||
{ Color::Black, COLOR_BLACK },
|
||||
{ Color::Red, COLOR_RED },
|
||||
{ Color::Green, COLOR_GREEN },
|
||||
{ Color::Yellow, COLOR_YELLOW },
|
||||
{ Color::Blue, COLOR_BLUE },
|
||||
{ Color::Magenta, COLOR_MAGENTA },
|
||||
{ Color::Cyan, COLOR_CYAN },
|
||||
{ Color::White, COLOR_WHITE },
|
||||
};
|
||||
static int next_color = 8;
|
||||
|
||||
|
@ -91,7 +91,7 @@ static int nc_color(Color color)
|
|||
return it->second;
|
||||
else if (can_change_color() and COLORS > 8)
|
||||
{
|
||||
kak_assert(color.color == Colors::RGB);
|
||||
kak_assert(color.color == Color::RGB);
|
||||
if (next_color > COLORS)
|
||||
next_color = 8;
|
||||
init_color(next_color,
|
||||
|
@ -103,7 +103,7 @@ static int nc_color(Color color)
|
|||
}
|
||||
else
|
||||
{
|
||||
kak_assert(color.color == Colors::RGB);
|
||||
kak_assert(color.color == Color::RGB);
|
||||
static const struct { unsigned char r, g, b; } builtin_colors[] = {
|
||||
{0x00,0x00,0x00}, {0x80,0x00,0x00}, {0x00,0x80,0x00}, {0x80,0x80,0x00},
|
||||
{0x00,0x00,0x80}, {0x80,0x00,0x80}, {0x00,0x80,0x80}, {0xc0,0xc0,0xc0},
|
||||
|
@ -213,7 +213,7 @@ static void set_face(WINDOW* window, Face face)
|
|||
if (current_pair != -1)
|
||||
wattroff(window, COLOR_PAIR(current_pair));
|
||||
|
||||
if (face.fg != Colors::Default or face.bg != Colors::Default)
|
||||
if (face.fg != Color::Default or face.bg != Color::Default)
|
||||
{
|
||||
current_pair = get_color_pair(face);
|
||||
wattron(window, COLOR_PAIR(current_pair));
|
||||
|
@ -376,7 +376,7 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer,
|
|||
++line_index;
|
||||
}
|
||||
|
||||
set_face(m_window, { Colors::Blue, Colors::Default });
|
||||
set_face(m_window, { Color::Blue, Color::Default });
|
||||
while (line_index < m_dimensions.line + (m_status_on_top ? 1 : 0))
|
||||
{
|
||||
wmove(m_window, (int)line_index++, 0);
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
void write(Color color)
|
||||
{
|
||||
write(color.color);
|
||||
if (color.color == Colors::RGB)
|
||||
if (color.color == Color::RGB)
|
||||
{
|
||||
write(color.r);
|
||||
write(color.g);
|
||||
|
@ -188,8 +188,8 @@ template<>
|
|||
Color read<Color>(int socket)
|
||||
{
|
||||
Color res;
|
||||
res.color = read<Colors>(socket);
|
||||
if (res.color == Colors::RGB)
|
||||
res.color = read<Color::NamedColor>(socket);
|
||||
if (res.color == Color::RGB)
|
||||
{
|
||||
res.r = read<unsigned char>(socket);
|
||||
res.g = read<unsigned char>(socket);
|
||||
|
|
Loading…
Reference in New Issue
Block a user