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:
parent
c1dcf75a7c
commit
e48c7fe49f
@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
void saveHistory();
|
void saveHistory();
|
||||||
void loadHistory();
|
void loadHistory();
|
||||||
|
void setHistorySize(int size);
|
||||||
|
|
||||||
static std::string getDefaultHistoryPath(StringRef ProgName);
|
static std::string getDefaultHistoryPath(StringRef ProgName);
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#ifdef HAVE_LIBEDIT
|
#ifdef HAVE_LIBEDIT
|
||||||
#include <histedit.h>
|
#include <histedit.h>
|
||||||
|
constexpr int DefaultHistorySize = 800;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
|
|||||||
NULL); // Fix the delete key.
|
NULL); // Fix the delete key.
|
||||||
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
|
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
|
||||||
|
|
||||||
|
setHistorySize(DefaultHistorySize);
|
||||||
HistEvent HE;
|
HistEvent HE;
|
||||||
::history(Data->Hist, &HE, H_SETSIZE, 800);
|
|
||||||
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
|
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
|
||||||
loadHistory();
|
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 {
|
std::optional<std::string> LineEditor::readLine() const {
|
||||||
// Call el_gets to prompt the user and read the user's input.
|
// Call el_gets to prompt the user and read the user's input.
|
||||||
int LineLen = 0;
|
int LineLen = 0;
|
||||||
@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
|
|||||||
|
|
||||||
void LineEditor::saveHistory() {}
|
void LineEditor::saveHistory() {}
|
||||||
void LineEditor::loadHistory() {}
|
void LineEditor::loadHistory() {}
|
||||||
|
void LineEditor::setHistorySize(int size) {}
|
||||||
|
|
||||||
std::optional<std::string> LineEditor::readLine() const {
|
std::optional<std::string> LineEditor::readLine() const {
|
||||||
::fprintf(Data->Out, "%s", Prompt.c_str());
|
::fprintf(Data->Out, "%s", Prompt.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user