summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-03-29 13:18:46 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-03-29 13:18:46 +0000
commit2a7335edefc8bc47e5f0501c4a973aacf15d47fc (patch)
tree7b33badc45a0e3b4bcb03a266379cc50fe909f7a /src
parent7dc5588adc29a16dfe1cb1cf5ea580bbc9ad83cf (diff)
Add basic support for colalias completion
Diffstat (limited to 'src')
-rw-r--r--src/color_registry.cc13
-rw-r--r--src/color_registry.hh3
-rw-r--r--src/commands.cc9
3 files changed, 24 insertions, 1 deletions
diff --git a/src/color_registry.cc b/src/color_registry.cc
index 36d19e72..0820409f 100644
--- a/src/color_registry.cc
+++ b/src/color_registry.cc
@@ -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 } },
diff --git a/src/color_registry.hh b/src/color_registry.hh
index 730ea0d1..3eff6fab 100644
--- a/src/color_registry.hh
+++ b/src/color_registry.hh
@@ -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;
};
diff --git a/src/commands.cc b/src/commands.cc
index 3b19e5f7..48e549bc 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -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);