summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-03-06 20:31:07 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-03-06 20:33:20 +0100
commit1e8a109d0d72656bac43be2c43dba8a9d3b93a22 (patch)
tree2785c1ee08db78a6a79555b45a8d581a1aa587bb /src
parente4240448b10092599977acafaadd2beaa87aa508 (diff)
Use some builtins colors aliases instead of hardcoded values for highlighters
Diffstat (limited to 'src')
-rw-r--r--src/color_registry.cc10
-rw-r--r--src/color_registry.hh2
-rw-r--r--src/highlighters.cc13
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<ColorRegistry>
{
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; });
}
}