9#ifndef LLVM_LINEEDITOR_LINEEDITOR_H
10#define LLVM_LINEEDITOR_LINEEDITOR_H
34 FILE *Out = stdout, FILE *Err = stderr);
40 std::optional<std::string>
readLine()
const;
86 Completer.reset(
new CompleterModel<T>(Comp));
94 Completer.reset(
new ListCompleterModel<T>(Comp));
114 std::string HistoryPath;
115 std::unique_ptr<InternalData> Data;
117 struct CompleterConcept {
118 virtual ~CompleterConcept();
119 virtual CompletionAction complete(
StringRef Buffer,
size_t Pos)
const = 0;
122 struct ListCompleterConcept : CompleterConcept {
123 ~ListCompleterConcept()
override;
124 CompletionAction complete(StringRef Buffer,
size_t Pos)
const override;
125 static std::string getCommonPrefix(
const std::vector<Completion> &Comps);
126 virtual std::vector<Completion> getCompletions(StringRef Buffer,
127 size_t Pos)
const = 0;
130 template <
typename T>
131 struct CompleterModel : CompleterConcept {
133 CompletionAction complete(StringRef Buffer,
size_t Pos)
const override {
134 return Value(Buffer, Pos);
139 template <
typename T>
140 struct ListCompleterModel : ListCompleterConcept {
142 std::vector<Completion> getCompletions(StringRef Buffer,
143 size_t Pos)
const override {
144 return Value(Buffer, Pos);
149 std::unique_ptr<const CompleterConcept> Completer;
void setHistorySize(int size)
void setPrompt(const std::string &P)
CompletionAction getCompletionAction(StringRef Buffer, size_t Pos) const
Use the current completer to produce a CompletionAction for the given completion request.
static std::string getDefaultHistoryPath(StringRef ProgName)
std::optional< std::string > readLine() const
Reads a line.
void setCompleter(T Comp)
Set the completer for this LineEditor.
const std::string & getPrompt() const
void setListCompleter(T Comp)
Set the completer for this LineEditor to the given list completer.
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
The action to perform upon a completion request.
std::string Text
The text to insert.
std::vector< std::string > Completions
The list of completions to show.
@ AK_ShowCompletions
Show Completions, or beep if the list is empty.
@ AK_Insert
Insert Text at the cursor position.
A possible completion at a given cursor position.
std::string DisplayText
A description of this completion.
std::string TypedText
The text to insert.
Completion(const std::string &TypedText, const std::string &DisplayText)