Skip to content

Commit 1c5281a

Browse files
committed
[lineeditor] Add setHistorySize() method for adjusting history size
1 parent dff114b commit 1c5281a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/include/llvm/LineEditor/LineEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class LineEditor {
4141

4242
void saveHistory();
4343
void loadHistory();
44+
void setHistorySize(int size);
4445

4546
static std::string getDefaultHistoryPath(StringRef ProgName);
4647

llvm/lib/LineEditor/LineEditor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#endif
2121

2222
using namespace llvm;
23+
constexpr int DefaultHistorySize = 800;
2324

2425
std::string LineEditor::getDefaultHistoryPath(StringRef ProgName) {
2526
SmallString<32> Path;
@@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
220221
NULL); // Fix the delete key.
221222
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
222223

224+
setHistorySize(DefaultHistorySize);
223225
HistEvent HE;
224-
::history(Data->Hist, &HE, H_SETSIZE, 800);
225226
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
226227
loadHistory();
227228
}
@@ -248,6 +249,11 @@ void LineEditor::loadHistory() {
248249
}
249250
}
250251

252+
void LineEditor::setHistorySize(int size) {
253+
HistEvent HE;
254+
::history(Data->Hist, &HE, H_SETSIZE, size);
255+
}
256+
251257
std::optional<std::string> LineEditor::readLine() const {
252258
// Call el_gets to prompt the user and read the user's input.
253259
int LineLen = 0;
@@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
291297

292298
void LineEditor::saveHistory() {}
293299
void LineEditor::loadHistory() {}
300+
void LineEditor::setHistorySize(int size) {}
294301

295302
std::optional<std::string> LineEditor::readLine() const {
296303
::fprintf(Data->Out, "%s", Prompt.c_str());

0 commit comments

Comments
 (0)