Add get_color helper function
This commit is contained in:
parent
1822b81d58
commit
6ffdfd7735
|
@ -22,6 +22,11 @@ private:
|
||||||
std::unordered_map<String, ColorPair> m_aliases;
|
std::unordered_map<String, ColorPair> m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const ColorPair& get_color(const String& colordesc)
|
||||||
|
{
|
||||||
|
return ColorRegistry::instance()[colordesc];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // color_registry_hh_INCLUDED
|
#endif // color_registry_hh_INCLUDED
|
||||||
|
|
|
@ -684,8 +684,7 @@ void info(const CommandParameters& params, Context& context)
|
||||||
pos = context.window().display_position(it);
|
pos = context.window().display_position(it);
|
||||||
}
|
}
|
||||||
const String& message = parser.has_option("assist") ? assist(parser[0], dimensions.column) : parser[0];
|
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, get_color("Information"), style);
|
||||||
context.ui().info_show(message, pos, colors, style);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ HighlighterAndId colorize_regex_factory(const HighlighterParameters params, cons
|
||||||
|
|
||||||
int capture = str_to_int(String(res[1].first, res[1].second));
|
int capture = str_to_int(String(res[1].first, res[1].second));
|
||||||
const ColorPair*& color = colors[capture];
|
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] + "'";
|
String id = "colre'" + params[0] + "'";
|
||||||
|
@ -185,7 +185,7 @@ HighlighterAndId highlight_search_factory(const HighlighterParameters params, co
|
||||||
throw runtime_error("wrong parameter count");
|
throw runtime_error("wrong parameter count");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ColorSpec colors { { 0, &ColorRegistry::instance()[params[0]] } };
|
ColorSpec colors { { 0, &get_color(params[0]) } };
|
||||||
auto get_regex = []{
|
auto get_regex = []{
|
||||||
auto s = RegisterManager::instance()['/'].values(Context{});
|
auto s = RegisterManager::instance()['/'].values(Context{});
|
||||||
return s.empty() ? Regex{} : Regex{s[0].begin(), s[0].end()};
|
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)
|
if (params.size() != 2)
|
||||||
throw runtime_error("wrong parameter count");
|
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];
|
String option_name = params[0];
|
||||||
const OptionManager& options = window.options();
|
const OptionManager& options = window.options();
|
||||||
// verify option type now
|
// verify option type now
|
||||||
|
@ -266,7 +266,7 @@ 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"];
|
auto& colors = get_color("LineNumbers");
|
||||||
for (auto& line : display_buffer.lines())
|
for (auto& line : display_buffer.lines())
|
||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
|
@ -290,11 +290,11 @@ void highlight_selections(const Window& window, DisplayBuffer& display_buffer)
|
||||||
const bool primary = (i == window.main_selection_index());
|
const bool primary = (i == window.main_selection_index());
|
||||||
if (not only_cursor)
|
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,
|
highlight_range(display_buffer, begin, end, false,
|
||||||
[&](DisplayAtom& atom) { atom.colors = sel_colors; });
|
[&](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,
|
highlight_range(display_buffer, sel.last(), utf8::next(sel.last()), false,
|
||||||
[&](DisplayAtom& atom) { atom.colors = cur_colors; });
|
[&](DisplayAtom& atom) { atom.colors = cur_colors; });
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,9 +154,8 @@ public:
|
||||||
m_selected(m_choices.begin())
|
m_selected(m_choices.begin())
|
||||||
{
|
{
|
||||||
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
||||||
ColorRegistry& colreg = ColorRegistry::instance();
|
context().ui().menu_show(choices, menu_pos, get_color("MenuForeground"),
|
||||||
context().ui().menu_show(choices, menu_pos, colreg["MenuForeground"],
|
get_color("MenuBackground"), MenuStyle::Prompt);
|
||||||
colreg["MenuBackground"], MenuStyle::Prompt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_key(const Key& key) override
|
void on_key(const Key& key) override
|
||||||
|
@ -378,9 +377,8 @@ public:
|
||||||
|
|
||||||
context().ui().menu_hide();
|
context().ui().menu_hide();
|
||||||
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
||||||
ColorRegistry& colreg = ColorRegistry::instance();
|
context().ui().menu_show(candidates, menu_pos, get_color("MenuForeground"),
|
||||||
context().ui().menu_show(candidates, menu_pos, colreg["MenuForeground"],
|
get_color("MenuBackground"), MenuStyle::Prompt);
|
||||||
colreg["MenuBackground"], MenuStyle::Prompt);
|
|
||||||
|
|
||||||
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
|
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
|
||||||
String prefix = use_common_prefix ? common_prefix(candidates) : String();
|
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);
|
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,
|
m_context.ui().menu_show(m_matching_candidates, menu_pos,
|
||||||
colreg["MenuForeground"],
|
get_color("MenuForeground"),
|
||||||
colreg["MenuBackground"],
|
get_color("MenuBackground"),
|
||||||
MenuStyle::Inline);
|
MenuStyle::Inline);
|
||||||
m_context.ui().menu_select(m_current_candidate);
|
m_context.ui().menu_select(m_current_candidate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user