9#ifndef LLVM_LINEEDITOR_LINEEDITOR_H
10#define LLVM_LINEEDITOR_LINEEDITOR_H
35 FILE *In = stdin, FILE *Out = stdout, FILE *Err = stderr);
87 Completer.reset(
new CompleterModel<T>(Comp));
95 Completer.reset(
new ListCompleterModel<T>(Comp));
116 std::string HistoryPath;
117 std::unique_ptr<InternalData>
Data;
120 virtual ~CompleterConcept();
121 virtual CompletionAction complete(
StringRef Buffer,
size_t Pos)
const = 0;
124 struct LLVM_ABI ListCompleterConcept : CompleterConcept {
125 ~ListCompleterConcept()
override;
126 CompletionAction complete(StringRef Buffer,
size_t Pos)
const override;
127 static std::string getCommonPrefix(
const std::vector<Completion> &Comps);
128 virtual std::vector<Completion> getCompletions(StringRef Buffer,
129 size_t Pos)
const = 0;
132 template <
typename T>
133 struct CompleterModel : CompleterConcept {
134 CompleterModel(
T Value) : Value(Value) {}
135 CompletionAction complete(StringRef Buffer,
size_t Pos)
const override {
136 return Value(Buffer, Pos);
141 template <
typename T>
142 struct ListCompleterModel : ListCompleterConcept {
143 ListCompleterModel(
T Value) : Value(std::
move(Value)) {}
144 std::vector<Completion> getCompletions(StringRef Buffer,
145 size_t Pos)
const override {
146 return Value(Buffer, Pos);
151 std::unique_ptr<const CompleterConcept> Completer;
LLVM_ABI void setHistorySize(int size)
void setPrompt(const std::string &P)
LLVM_ABI CompletionAction getCompletionAction(StringRef Buffer, size_t Pos) const
Use the current completer to produce a CompletionAction for the given completion request.
LLVM_ABI void loadHistory()
static LLVM_ABI std::string getDefaultHistoryPath(StringRef ProgName)
LLVM_ABI LineEditor(StringRef ProgName, StringRef HistoryPath="", FILE *In=stdin, FILE *Out=stdout, FILE *Err=stderr)
Create a LineEditor object.
LLVM_ABI std::optional< std::string > readLine() const
Reads a line.
void setCompleter(T Comp)
Set the completer for this LineEditor.
LLVM_ABI void saveHistory()
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.
FunctionAddr VTableAddr Value
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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.
std::string DisplayText
A description of this completion.
std::string TypedText
The text to insert.
Completion(const std::string &TypedText, const std::string &DisplayText)