Use some builtins colors aliases instead of hardcoded values for highlighters

This commit is contained in:
Maxime Coste 2013-03-06 20:31:07 +01:00
parent e4240448b1
commit 1e8a109d0d
3 changed files with 19 additions and 6 deletions

View File

@ -54,4 +54,14 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc,
m_aliases[name] = { fg, bg }; m_aliases[name] = { fg, bg };
} }
ColorRegistry::ColorRegistry()
: m_aliases{
{ "PrimarySelection", { Color::Cyan, Color::Blue } },
{ "SecondarySelection", { Color::Black, Color::Blue } },
{ "PrimaryCursor", { Color::Black, Color::White } },
{ "SecondaryCursor", { Color::Black, Color::White } },
{ "LineNumbers", { Color::Black, Color::White } },
}
{}
} }

View File

@ -12,6 +12,8 @@ namespace Kakoune
class ColorRegistry : public Singleton<ColorRegistry> class ColorRegistry : public Singleton<ColorRegistry>
{ {
public: public:
ColorRegistry();
const ColorPair& operator[](const String& colordesc); const ColorPair& operator[](const String& colordesc);
void register_alias(const String& name, const String& colordesc, void register_alias(const String& name, const String& colordesc,
bool override = false); bool override = false);

View File

@ -248,13 +248,13 @@ void show_line_numbers(DisplayBuffer& display_buffer)
char format[] = "%?d "; char format[] = "%?d ";
format[1] = '0' + digit_count; format[1] = '0' + digit_count;
auto& colors = ColorRegistry::instance()["LineNumbers"];
for (auto& line : display_buffer.lines()) for (auto& line : display_buffer.lines())
{ {
char buffer[10]; char buffer[10];
snprintf(buffer, 10, format, (int)line.buffer_line() + 1); snprintf(buffer, 10, format, (int)line.buffer_line() + 1);
DisplayAtom atom = DisplayAtom(AtomContent(buffer)); DisplayAtom atom = DisplayAtom(AtomContent(buffer));
atom.colors = { Color::Black, Color::White }; atom.colors = colors;
line.insert(line.begin(), std::move(atom)); line.insert(line.begin(), std::move(atom));
} }
} }
@ -268,12 +268,13 @@ void highlight_selections(const SelectionList& selections, DisplayBuffer& displa
BufferIterator begin = forward ? sel.first() : utf8::next(sel.last()); BufferIterator begin = forward ? sel.first() : utf8::next(sel.last());
BufferIterator end = forward ? sel.last() : utf8::next(sel.first()); BufferIterator end = forward ? sel.last() : utf8::next(sel.first());
ColorPair colors = (i == selections.size() - 1) ? ColorPair{ Color::Cyan, Color::Blue } const bool primary = (i == selections.size() - 1);
: ColorPair{ Color::Black, Color::Blue }; ColorPair sel_colors = ColorRegistry::instance()[primary ? "PrimarySelection" : "SecondarySelection"];
ColorPair cur_colors = ColorRegistry::instance()[primary ? "PrimaryCursor" : "SecondaryCursor"];
highlight_range(display_buffer, begin, end, false, highlight_range(display_buffer, begin, end, false,
[&](DisplayAtom& atom) { atom.colors = colors; }); [&](DisplayAtom& atom) { atom.colors = sel_colors; });
highlight_range(display_buffer, sel.last(), utf8::next(sel.last()), false, highlight_range(display_buffer, sel.last(), utf8::next(sel.last()), false,
[](DisplayAtom& atom) { atom.colors = { Color::Black, Color::White}; }); [&](DisplayAtom& atom) { atom.colors = cur_colors; });
} }
} }