14 class InterpreterOutput;
20 [[nodiscard]]
const std::string&
getName()
const {
return theName; }
24 [[nodiscard]]
virtual std::string
help(
const std::vector<std::string>& tokens)
const = 0;
35 template<
typename ITER>
38 bool caseSensitive =
true);
39 template<
typename RANGE>
41 const RANGE& possibleValues,
42 bool caseSensitive =
true);
43 template<
typename RANGE>
51 const std::vector<std::string_view>& input);
68 template<
typename String>
70 : theName(std::forward<String>(name_))
77 static bool equalHead(std::string_view s1, std::string_view s2,
bool caseSensitive);
78 template<
typename ITER>
79 static std::vector<std::string_view> filter(
80 std::string_view str, ITER
begin, ITER
end,
bool caseSensitive);
81 template<
typename RANGE>
82 static std::vector<std::string_view> filter(
83 std::string_view str,
const RANGE& range,
bool caseSensitive);
84 static bool completeImpl(std::string& str, std::vector<std::string_view> matches,
86 static void completeFileNameImpl(std::vector<std::string>& tokens,
88 std::vector<std::string_view> matches);
90 const std::string theName;
95 template<
typename ITER>
97 std::string_view str, ITER
begin, ITER
end,
bool caseSensitive)
99 std::vector<std::string_view> result;
100 for (
auto it =
begin; it !=
end; ++it) {
101 if (equalHead(str, *it, caseSensitive)) {
102 result.push_back(*it);
108 template<
typename RANGE>
109 inline std::vector<std::string_view> Completer::filter(
110 std::string_view str,
const RANGE& range,
bool caseSensitive)
115 template<
typename RANGE>
117 std::vector<std::string>& tokens,
118 const RANGE& possibleValues,
121 auto& str = tokens.back();
122 if (completeImpl(str,
123 filter(str, possibleValues, caseSensitive),
125 tokens.emplace_back();
129 template<
typename ITER>
131 std::vector<std::string>& tokens,
135 auto& str = tokens.back();
136 if (completeImpl(str,
137 filter(str,
begin,
end, caseSensitive),
139 tokens.emplace_back();
143 template<
typename RANGE>
145 std::vector<std::string>& tokens,
149 completeFileNameImpl(tokens,
context, filter(tokens.back(), extra,
true));
const std::string & getName() const
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
static void setOutput(InterpreterOutput *output_)
virtual std::string help(const std::vector< std::string > &tokens) const =0
Print help for this command.
static std::vector< std::string > formatListInColumns(const std::vector< std::string_view > &input)
Completer(String &&name_)
virtual void tabCompletion(std::vector< std::string > &tokens) const =0
Attempt tab completion for this command.
void checkNumArgs(span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
virtual Interpreter & getInterpreter() const =0
std::unique_ptr< Context > context
This file implemented 3 utility functions:
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)