Reland '[lineeditor] Add setHistorySize() method for adjusting history size' (#115442)

Reland: https://github.com/llvm/llvm-project/pull/110092

Buildbot was failing due to an unused variable warning as there were 2
implementations (with and without libedit). Compared to last version,
wrap the variable inside the `#ifdef HAVE_LIBEDIT`.

Apologies for the oversight @vgvassilev
This commit is contained in:
Devajith 2024-12-02 14:17:51 +01:00 committed by GitHub
parent c1dcf75a7c
commit e48c7fe49f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,7 @@ public:
void saveHistory();
void loadHistory();
void setHistorySize(int size);
static std::string getDefaultHistoryPath(StringRef ProgName);

View File

@ -17,6 +17,7 @@
#include <cstdio>
#ifdef HAVE_LIBEDIT
#include <histedit.h>
constexpr int DefaultHistorySize = 800;
#endif
using namespace llvm;
@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
NULL); // Fix the delete key.
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
setHistorySize(DefaultHistorySize);
HistEvent HE;
::history(Data->Hist, &HE, H_SETSIZE, 800);
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
loadHistory();
}
@ -248,6 +249,11 @@ void LineEditor::loadHistory() {
}
}
void LineEditor::setHistorySize(int size) {
HistEvent HE;
::history(Data->Hist, &HE, H_SETSIZE, size);
}
std::optional<std::string> LineEditor::readLine() const {
// Call el_gets to prompt the user and read the user's input.
int LineLen = 0;
@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
void LineEditor::saveHistory() {}
void LineEditor::loadHistory() {}
void LineEditor::setHistorySize(int size) {}
std::optional<std::string> LineEditor::readLine() const {
::fprintf(Data->Out, "%s", Prompt.c_str());