14class InterpreterOutput;
23 [[nodiscard]]
const std::string&
getName()
const {
return theName; }
27 [[nodiscard]]
virtual std::string
help(std::span<const TclObject> tokens)
const = 0;
38 template<
typename ITER>
41 bool caseSensitive =
true);
42 template<
typename RANGE>
44 RANGE&& possibleValues,
45 bool caseSensitive =
true);
46 template<
typename RANGE>
54 std::span<const std::string_view> input);
60 void checkNumArgs(std::span<const TclObject> tokens,
unsigned exactly,
const char* errMessage)
const;
61 void checkNumArgs(std::span<const TclObject> tokens,
AtLeast atLeast,
const char* errMessage)
const;
62 void checkNumArgs(std::span<const TclObject> tokens,
Between between,
const char* errMessage)
const;
63 void checkNumArgs(std::span<const TclObject> tokens,
unsigned exactly,
Prefix prefix,
const char* errMessage)
const;
71 template<
typename String>
73 : theName(
std::forward<String>(name_))
80 static bool equalHead(std::string_view s1, std::string_view s2,
bool caseSensitive);
81 template<
typename ITER>
82 static std::vector<std::string_view> filter(
83 std::string_view str, ITER
begin, ITER
end,
bool caseSensitive);
84 template<
typename RANGE>
85 static std::vector<std::string_view> filter(
86 std::string_view str, RANGE&& range,
bool caseSensitive);
87 static bool completeImpl(std::string& str, std::vector<std::string_view>
matches,
89 static void completeFileNameImpl(std::vector<std::string>& tokens,
91 std::vector<std::string_view>
matches);
93 const std::string theName;
98template<
typename ITER>
100 std::string_view str, ITER
begin, ITER
end,
bool caseSensitive)
102 std::vector<std::string_view> result;
103 for (
auto it =
begin; it !=
end; ++it) {
104 if (equalHead(str, *it, caseSensitive)) {
105 result.push_back(*it);
111template<
typename RANGE>
112inline std::vector<std::string_view> Completer::filter(
113 std::string_view str, RANGE&& range,
bool caseSensitive)
118template<
typename RANGE>
120 std::vector<std::string>& tokens,
121 RANGE&& possibleValues,
124 auto& str = tokens.back();
125 if (completeImpl(str,
126 filter(str, std::forward<RANGE>(possibleValues), caseSensitive),
128 tokens.emplace_back();
132template<
typename ITER>
134 std::vector<std::string>& tokens,
138 auto& str = tokens.back();
139 if (completeImpl(str,
140 filter(str,
begin,
end, caseSensitive),
142 tokens.emplace_back();
146template<
typename RANGE>
148 std::vector<std::string>& tokens,
152 completeFileNameImpl(tokens,
context, filter(tokens.back(), extra,
true));
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
static void setOutput(InterpreterOutput *output_)
Completer(String &&name_)
virtual void tabCompletion(std::vector< std::string > &tokens) const =0
Attempt tab completion for this command.
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
virtual std::string help(std::span< const TclObject > tokens) const =0
Print help for this command.
static std::vector< std::string > formatListInColumns(std::span< const std::string_view > input)
const std::string & getName() const
virtual Interpreter & getInterpreter() const =0
void checkNumArgs(std::span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
Completer & operator=(const Completer &)=delete
Completer(const Completer &)=delete
std::optional< Context > context
This file implemented 3 utility functions:
bool matches(const Event &self, const Event &other)
Does this event 'match' the given event.
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)