summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-06-10 21:46:16 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-06-10 21:46:16 +0100
commitca93ae807d7aca7e49360e6547759228b0b5e3eb (patch)
treeff9b580cc161d218e122b63128160629e08c2e26 /src
parent4bb62d63e69dcb96f8e92a70be9c619a5b25594b (diff)
Add a fill highlighter that just fills the display buffer
Diffstat (limited to 'src')
-rw-r--r--src/highlighters.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 9cb66a05..f44c40a0 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -150,6 +150,29 @@ void apply_highlighter(const Context& context,
using ColorSpec = std::unordered_map<size_t, const ColorPair*>;
+struct Fill
+{
+ Fill(ColorPair colors) : m_colors(colors) {}
+
+ void operator()(const Context& context, HighlightFlags flags,
+ DisplayBuffer& display_buffer)
+ {
+ auto range = display_buffer.range();
+ highlight_range(display_buffer, range.first, range.second, true,
+ [this](DisplayAtom& atom) { atom.colors = m_colors; });
+ }
+
+ ColorPair m_colors;
+};
+
+HighlighterAndId fill_factory(HighlighterParameters params)
+{
+ if (params.size() != 1)
+ throw runtime_error("wrong parameter count");
+ ColorPair colors = get_color(params[0]);
+ return HighlighterAndId("fill_" + params[0], Fill(colors));
+}
+
template<typename T>
struct BufferSideCache
{
@@ -892,6 +915,7 @@ void register_highlighters()
registry.register_func("number_lines", SimpleHighlighterFactory<show_line_numbers>("number_lines"));
registry.register_func("show_matching", SimpleHighlighterFactory<show_matching_char>("show_matching"));
registry.register_func("show_whitespaces", SimpleHighlighterFactory<show_whitespaces>("show_whitespaces"));
+ registry.register_func("fill", fill_factory);
registry.register_func("regex", colorize_regex_factory);
registry.register_func("regex_option", highlight_regex_option_factory);
registry.register_func("search", highlight_search_factory);