Try prefix completion and then subsequence completion for option names
fixes #4
This commit is contained in:
parent
608098cdde
commit
e12bf4978c
|
@ -63,25 +63,35 @@ const Option& OptionManager::operator[](const String& name) const
|
|||
throw option_not_found(name);
|
||||
}
|
||||
|
||||
CandidateList OptionManager::complete_option_name(const String& prefix,
|
||||
ByteCount cursor_pos)
|
||||
template<typename MatchingFunc>
|
||||
CandidateList OptionManager::get_matching_names(MatchingFunc func)
|
||||
{
|
||||
String real_prefix = prefix.substr(0, cursor_pos);
|
||||
CandidateList result;
|
||||
if (m_parent)
|
||||
result = m_parent->complete_option_name(prefix, cursor_pos);
|
||||
result = m_parent->get_matching_names(func);
|
||||
for (auto& option : m_options)
|
||||
{
|
||||
if (option->flags() & Option::Flags::Hidden)
|
||||
continue;
|
||||
|
||||
const auto& name = option->name();
|
||||
if (prefix_match(name, real_prefix) and not contains(result, name))
|
||||
if (func(name) and not contains(result, name))
|
||||
result.push_back(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CandidateList OptionManager::complete_option_name(const String& prefix,
|
||||
ByteCount cursor_pos)
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
String real_prefix = prefix.substr(0, cursor_pos);
|
||||
auto result = get_matching_names(std::bind(prefix_match, _1, std::ref(real_prefix)));
|
||||
if (result.empty())
|
||||
result = get_matching_names(std::bind(subsequence_match, _1, std::ref(real_prefix)));
|
||||
return result;
|
||||
}
|
||||
|
||||
OptionManager::OptionList OptionManager::flatten_options() const
|
||||
{
|
||||
OptionList res = m_parent ? m_parent->flatten_options() : OptionList{};
|
||||
|
|
|
@ -91,6 +91,9 @@ private:
|
|||
// the only one allowed to construct a root option manager
|
||||
friend class GlobalOptions;
|
||||
|
||||
template<typename MatchingFunc>
|
||||
CandidateList get_matching_names(MatchingFunc func);
|
||||
|
||||
std::vector<std::unique_ptr<Option>> m_options;
|
||||
OptionManager* m_parent;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user