From 1e8a109d0d72656bac43be2c43dba8a9d3b93a22 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 6 Mar 2013 20:31:07 +0100 Subject: [PATCH] Use some builtins colors aliases instead of hardcoded values for highlighters --- src/color_registry.cc | 10 ++++++++++ src/color_registry.hh | 2 ++ src/highlighters.cc | 13 +++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/color_registry.cc b/src/color_registry.cc index f380c4fa..ad77324a 100644 --- a/src/color_registry.cc +++ b/src/color_registry.cc @@ -54,4 +54,14 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc, 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 } }, + } +{} + } diff --git a/src/color_registry.hh b/src/color_registry.hh index 4b6256fc..a33c9162 100644 --- a/src/color_registry.hh +++ b/src/color_registry.hh @@ -12,6 +12,8 @@ namespace Kakoune class ColorRegistry : public Singleton { public: + ColorRegistry(); + const ColorPair& operator[](const String& colordesc); void register_alias(const String& name, const String& colordesc, bool override = false); diff --git a/src/highlighters.cc b/src/highlighters.cc index c7238bfe..48212c99 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -248,13 +248,13 @@ void show_line_numbers(DisplayBuffer& display_buffer) char format[] = "%?d "; format[1] = '0' + digit_count; - + auto& colors = ColorRegistry::instance()["LineNumbers"]; for (auto& line : display_buffer.lines()) { char buffer[10]; snprintf(buffer, 10, format, (int)line.buffer_line() + 1); DisplayAtom atom = DisplayAtom(AtomContent(buffer)); - atom.colors = { Color::Black, Color::White }; + atom.colors = colors; 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 end = forward ? sel.last() : utf8::next(sel.first()); - ColorPair colors = (i == selections.size() - 1) ? ColorPair{ Color::Cyan, Color::Blue } - : ColorPair{ Color::Black, Color::Blue }; + const bool primary = (i == selections.size() - 1); + ColorPair sel_colors = ColorRegistry::instance()[primary ? "PrimarySelection" : "SecondarySelection"]; + ColorPair cur_colors = ColorRegistry::instance()[primary ? "PrimaryCursor" : "SecondaryCursor"]; 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, - [](DisplayAtom& atom) { atom.colors = { Color::Black, Color::White}; }); + [&](DisplayAtom& atom) { atom.colors = cur_colors; }); } }