Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,49 @@ void RPCConsole::WriteCommandHistory()
settings.endArray();
}

void RPCConsole::ClearCommandHistory()
{
// First pass: read existing commands and overwrite with dummy data of same length
QSettings settings;
int size = settings.beginReadArray("nRPCConsoleWindowHistory");
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
history.resize(size);
#else
if (history.size() > size) {
history.erase(history.begin() + size, history.end());
} else {
history.reserve(size);
for (int i = history.size(); i < size; ++i) {
history.append(QString());
}
}
#endif
for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
QString cmd = settings.value("cmd").toString();
// Store dummy command with same length as original (don't leak length info)
history[i].fill('x', cmd.size());
}
settings.endArray();

// Write dummy data to overwrite the original commands
WriteCommandHistory();

// Clear the dummy data (leaves it intact on disk)
for (QStringList::size_type i = history.size(); i; ) {
--i;
history[i].clear();
}
WriteCommandHistory();

// Clear the history list
history.clear();
WriteCommandHistory();

historyPtr = 0;
cmdBeforeBrowsing.clear();
}

RPCConsole::~RPCConsole()
{
QSettings settings;
Expand Down Expand Up @@ -1184,6 +1227,26 @@ void RPCConsole::on_lineEdit_returnPressed()
return;
}

// Special command to clear command history
if (cmd == QLatin1String("/clearhistory")) {
QMessageBox::StandardButton reply = QMessageBox::question(this,
tr("Clear Command History"),
tr("This will permanently clear your command history and console output.<br><br>"
"While this action is irreversible, complete removal from memory and disk "
"cannot be guaranteed.<br><br>"
"Are you sure you want to proceed?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);

if (reply == QMessageBox::Yes) {
ClearCommandHistory();
clear(/*keep_prompt=*/false); // Clear console output too
message(CMD_REPLY, tr("Command history and console output cleared."));
}
ui->lineEdit->clear();
return;
}

if (m_is_executing) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public Q_SLOTS:
void startExecutor();
void setTrafficGraphRange(int mins);
void WriteCommandHistory();
void ClearCommandHistory();

enum ColumnWidths
{
Expand Down