Add basic support for colalias completion
This commit is contained in:
parent
7dc5588adc
commit
2a7335edef
|
@ -36,6 +36,19 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
|||
it->second : parse_color_pair(colordesc);
|
||||
}
|
||||
|
||||
CandidateList ColorRegistry::complete_alias_name(const String& prefix,
|
||||
ByteCount cursor_pos) const
|
||||
{
|
||||
CandidateList res;
|
||||
String real_prefix = prefix.substr(0, cursor_pos);
|
||||
for (auto& alias : m_aliases)
|
||||
{
|
||||
if (prefix_match(alias.first, real_prefix))
|
||||
res.push_back(alias.first);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
ColorRegistry::ColorRegistry()
|
||||
: m_aliases{
|
||||
{ "PrimarySelection", { Colors::Cyan, Colors::Blue } },
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "color.hh"
|
||||
#include "utils.hh"
|
||||
#include "completion.hh"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -18,6 +19,8 @@ public:
|
|||
void register_alias(const String& name, const String& colordesc,
|
||||
bool override = false);
|
||||
|
||||
CandidateList complete_alias_name(const String& prefix,
|
||||
ByteCount cursor_pos) const;
|
||||
private:
|
||||
std::unordered_map<String, ColorPair> m_aliases;
|
||||
};
|
||||
|
|
|
@ -1113,13 +1113,20 @@ const CommandDesc try_catch_cmd = {
|
|||
}
|
||||
};
|
||||
|
||||
static Completions complete_colalias(const Context&, CompletionFlags flags,
|
||||
const String& prefix, ByteCount cursor_pos)
|
||||
{
|
||||
return {0_byte, prefix.length(),
|
||||
ColorRegistry::instance().complete_alias_name(prefix, cursor_pos)};
|
||||
}
|
||||
|
||||
const CommandDesc define_color_alias_cmd = {
|
||||
"colalias",
|
||||
"ca",
|
||||
"colalias <name> <color>: set <name> to refer to color <color> (which can be an alias itself)",
|
||||
ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 2, 2 },
|
||||
CommandFlags::None,
|
||||
CommandCompleter{},
|
||||
PerArgumentCommandCompleter({ complete_colalias, complete_colalias }),
|
||||
[](const ParametersParser& parser, Context& context)
|
||||
{
|
||||
ColorRegistry::instance().register_alias(parser[0], parser[1], true);
|
||||
|
|
Loading…
Reference in New Issue
Block a user