Dynamically change prompt color for regex prompt depending on regex validity
This commit is contained in:
parent
6e2fa38c15
commit
9bb9eda302
|
@ -433,6 +433,15 @@ public:
|
||||||
m_callback(line, PromptEvent::Change, context());
|
m_callback(line, PromptEvent::Change, context());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_prompt_colors(ColorPair colors)
|
||||||
|
{
|
||||||
|
if (colors != m_prompt_colors)
|
||||||
|
{
|
||||||
|
m_prompt_colors = colors;
|
||||||
|
display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void display() const
|
void display() const
|
||||||
{
|
{
|
||||||
|
@ -799,6 +808,13 @@ void InputHandler::prompt(const String& prompt, ColorPair prompt_colors,
|
||||||
completer, callback));
|
completer, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputHandler::set_prompt_colors(ColorPair prompt_colors)
|
||||||
|
{
|
||||||
|
InputModes::Prompt* prompt = dynamic_cast<InputModes::Prompt*>(m_mode.get());
|
||||||
|
if (prompt)
|
||||||
|
prompt->set_prompt_colors(prompt_colors);
|
||||||
|
}
|
||||||
|
|
||||||
void InputHandler::menu(const memoryview<String>& choices,
|
void InputHandler::menu(const memoryview<String>& choices,
|
||||||
MenuCallback callback)
|
MenuCallback callback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
// not change the mode itself
|
// not change the mode itself
|
||||||
void prompt(const String& prompt, ColorPair prompt_colors,
|
void prompt(const String& prompt, ColorPair prompt_colors,
|
||||||
Completer completer, PromptCallback callback);
|
Completer completer, PromptCallback callback);
|
||||||
|
void set_prompt_colors(ColorPair prompt_colors);
|
||||||
|
|
||||||
// enter menu mode, callback is called on each selection change,
|
// enter menu mode, callback is called on each selection change,
|
||||||
// abort or validation with corresponding MenuEvent value
|
// abort or validation with corresponding MenuEvent value
|
||||||
|
|
15
src/main.cc
15
src/main.cc
|
@ -326,6 +326,11 @@ void do_select_regex(Context& context)
|
||||||
if (not ex.empty())
|
if (not ex.empty())
|
||||||
context.editor().multi_select(std::bind(select_all_matches, _1, ex));
|
context.editor().multi_select(std::bind(select_all_matches, _1, ex));
|
||||||
}
|
}
|
||||||
|
else if (event == PromptEvent::Change)
|
||||||
|
{
|
||||||
|
const bool ok = Regex{str, boost::regex_constants::no_except}.status() == 0;
|
||||||
|
context.input_handler().set_prompt_colors(get_color(ok ? "Prompt" : "Error"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,6 +348,11 @@ void do_split_regex(Context& context)
|
||||||
if (not ex.empty())
|
if (not ex.empty())
|
||||||
context.editor().multi_select(std::bind(split_selection, _1, ex));
|
context.editor().multi_select(std::bind(split_selection, _1, ex));
|
||||||
}
|
}
|
||||||
|
else if (event == PromptEvent::Change)
|
||||||
|
{
|
||||||
|
const bool ok = Regex{str, boost::regex_constants::no_except}.status() == 0;
|
||||||
|
context.input_handler().set_prompt_colors(get_color(ok ? "Prompt" : "Error"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,6 +403,11 @@ void do_keep(Context& context)
|
||||||
throw runtime_error("no selections remaining");
|
throw runtime_error("no selections remaining");
|
||||||
editor.select(std::move(keep));
|
editor.select(std::move(keep));
|
||||||
}
|
}
|
||||||
|
else if (event == PromptEvent::Change)
|
||||||
|
{
|
||||||
|
const bool ok = Regex{str, boost::regex_constants::no_except}.status() == 0;
|
||||||
|
context.input_handler().set_prompt_colors(get_color(ok ? "Prompt" : "Error"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user