Add get_color helper function

This commit is contained in:
Maxime Coste 2013-04-04 18:47:34 +02:00
parent 1822b81d58
commit 6ffdfd7735
4 changed files with 18 additions and 17 deletions

View File

@ -22,6 +22,11 @@ private:
std::unordered_map<String, ColorPair> m_aliases;
};
inline const ColorPair& get_color(const String& colordesc)
{
return ColorRegistry::instance()[colordesc];
}
}
#endif // color_registry_hh_INCLUDED

View File

@ -684,8 +684,7 @@ void info(const CommandParameters& params, Context& context)
pos = context.window().display_position(it);
}
const String& message = parser.has_option("assist") ? assist(parser[0], dimensions.column) : parser[0];
ColorPair colors = ColorRegistry::instance()["Information"];
context.ui().info_show(message, pos, colors, style);
context.ui().info_show(message, pos, get_color("Information"), style);
}
}

View File

@ -135,7 +135,7 @@ HighlighterAndId colorize_regex_factory(const HighlighterParameters params, cons
int capture = str_to_int(String(res[1].first, res[1].second));
const ColorPair*& color = colors[capture];
color = &ColorRegistry::instance()[String(res[2].first, res[2].second)];
color = &get_color(String(res[2].first, res[2].second));
}
String id = "colre'" + params[0] + "'";
@ -185,7 +185,7 @@ HighlighterAndId highlight_search_factory(const HighlighterParameters params, co
throw runtime_error("wrong parameter count");
try
{
ColorSpec colors { { 0, &ColorRegistry::instance()[params[0]] } };
ColorSpec colors { { 0, &get_color(params[0]) } };
auto get_regex = []{
auto s = RegisterManager::instance()['/'].values(Context{});
return s.empty() ? Regex{} : Regex{s[0].begin(), s[0].end()};
@ -203,7 +203,7 @@ HighlighterAndId highlight_regex_option_factory(const HighlighterParameters para
if (params.size() != 2)
throw runtime_error("wrong parameter count");
ColorSpec colors { { 0, &ColorRegistry::instance()[params[1]] } };
ColorSpec colors { { 0, &get_color(params[1]) } };
String option_name = params[0];
const OptionManager& options = window.options();
// verify option type now
@ -266,7 +266,7 @@ void show_line_numbers(DisplayBuffer& display_buffer)
char format[] = "%?d ";
format[1] = '0' + digit_count;
auto& colors = ColorRegistry::instance()["LineNumbers"];
auto& colors = get_color("LineNumbers");
for (auto& line : display_buffer.lines())
{
char buffer[10];
@ -290,11 +290,11 @@ void highlight_selections(const Window& window, DisplayBuffer& display_buffer)
const bool primary = (i == window.main_selection_index());
if (not only_cursor)
{
ColorPair sel_colors = ColorRegistry::instance()[primary ? "PrimarySelection" : "SecondarySelection"];
ColorPair sel_colors = get_color(primary ? "PrimarySelection" : "SecondarySelection");
highlight_range(display_buffer, begin, end, false,
[&](DisplayAtom& atom) { atom.colors = sel_colors; });
}
ColorPair cur_colors = ColorRegistry::instance()[primary ? "PrimaryCursor" : "SecondaryCursor"];
ColorPair cur_colors = get_color(primary ? "PrimaryCursor" : "SecondaryCursor");
highlight_range(display_buffer, sel.last(), utf8::next(sel.last()), false,
[&](DisplayAtom& atom) { atom.colors = cur_colors; });
}

View File

@ -154,9 +154,8 @@ public:
m_selected(m_choices.begin())
{
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
ColorRegistry& colreg = ColorRegistry::instance();
context().ui().menu_show(choices, menu_pos, colreg["MenuForeground"],
colreg["MenuBackground"], MenuStyle::Prompt);
context().ui().menu_show(choices, menu_pos, get_color("MenuForeground"),
get_color("MenuBackground"), MenuStyle::Prompt);
}
void on_key(const Key& key) override
@ -378,9 +377,8 @@ public:
context().ui().menu_hide();
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
ColorRegistry& colreg = ColorRegistry::instance();
context().ui().menu_show(candidates, menu_pos, colreg["MenuForeground"],
colreg["MenuBackground"], MenuStyle::Prompt);
context().ui().menu_show(candidates, menu_pos, get_color("MenuForeground"),
get_color("MenuBackground"), MenuStyle::Prompt);
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
String prefix = use_common_prefix ? common_prefix(candidates) : String();
@ -608,10 +606,9 @@ private:
{
DisplayCoord menu_pos = m_context.window().display_position(m_completions.begin);
ColorRegistry& colreg = ColorRegistry::instance();
m_context.ui().menu_show(m_matching_candidates, menu_pos,
colreg["MenuForeground"],
colreg["MenuBackground"],
get_color("MenuForeground"),
get_color("MenuBackground"),
MenuStyle::Inline);
m_context.ui().menu_select(m_current_candidate);
}