LLVM: include/llvm/LineEditor/LineEditor.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_LINEEDITOR_LINEEDITOR_H
10#define LLVM_LINEEDITOR_LINEEDITOR_H
11
14#include
15#include
16#include
17#include
18#include
19#include
20
21namespace llvm {
22
24public:
25
26
27
28
29
30
31
32
33
35 FILE *In = stdin, FILE *Out = stdout, FILE *Err = stderr);
37
38
39
40
42
46
48
49
66
67
81
82
83
84
85
87 Completer.reset(new CompleterModel(Comp));
88 }
89
90
91
92
93
95 Completer.reset(new ListCompleterModel(Comp));
96 }
97
98
99
100
101
102
103
104
106 size_t Pos) const;
107
108 const std::string &getPrompt() const { return Prompt; }
110
111
112 struct InternalData;
113
114private:
115 std::string Prompt;
116 std::string HistoryPath;
117 std::unique_ptr Data;
118
119 struct LLVM_ABI CompleterConcept {
120 virtual ~CompleterConcept();
121 virtual CompletionAction complete(StringRef Buffer, size_t Pos) const = 0;
122 };
123
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 &Comps);
128 virtual std::vector getCompletions(StringRef Buffer,
129 size_t Pos) const = 0;
130 };
131
132 template
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);
137 }
138 T Value;
139 };
140
141 template
142 struct ListCompleterModel : ListCompleterConcept {
143 ListCompleterModel(T Value) : Value(std::move(Value)) {}
144 std::vector getCompletions(StringRef Buffer,
145 size_t Pos) const override {
146 return Value(Buffer, Pos);
147 }
148 T Value;
149 };
150
151 std::unique_ptr Completer;
152};
153
154}
155
156#endif
LLVM_ABI void setHistorySize(int size)
void setPrompt(const std::string &P)
Definition LineEditor.h:109
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.
Definition LineEditor.h:86
LLVM_ABI void saveHistory()
const std::string & getPrompt() const
Definition LineEditor.h:108
void setListCompleter(T Comp)
Set the completer for this LineEditor to the given list completer.
Definition LineEditor.h:94
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.
Definition LineEditor.h:50
std::string Text
The text to insert.
Definition LineEditor.h:61
std::vector< std::string > Completions
The list of completions to show.
Definition LineEditor.h:64
ActionKind Kind
Definition LineEditor.h:58
ActionKind
Definition LineEditor.h:51
@ AK_ShowCompletions
Show Completions, or beep if the list is empty.
Definition LineEditor.h:55
@ AK_Insert
Insert Text at the cursor position.
Definition LineEditor.h:53
std::string DisplayText
A description of this completion.
Definition LineEditor.h:79
std::string TypedText
The text to insert.
Definition LineEditor.h:75
Completion(const std::string &TypedText, const std::string &DisplayText)
Definition LineEditor.h:70