Skip to content

Commit 1498a7b

Browse files
committed
feat(qt): add /clearhistory command
1 parent eeb9cc1 commit 1498a7b

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/qt/rpcconsole.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,46 @@ void RPCConsole::WriteCommandHistory()
691691
settings.endArray();
692692
}
693693

694+
void RPCConsole::ClearCommandHistory()
695+
{
696+
// First pass: read existing commands and overwrite with dummy data of same length
697+
QSettings settings;
698+
int size = settings.beginReadArray("nRPCConsoleWindowHistory");
699+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
700+
history.resize(size);
701+
#else
702+
if (history.size() > size) {
703+
history.erase(history.begin() + size, history.end());
704+
} else {
705+
history.reserve(size);
706+
for (int i = history.size(); i < size; ++i) {
707+
history.append(QString());
708+
}
709+
}
710+
#endif
711+
for (int i = 0; i < size; ++i) {
712+
settings.setArrayIndex(i);
713+
QString cmd = settings.value("cmd").toString();
714+
// Store dummy command with same length as original (don't leak length info)
715+
history[i].fill('x', cmd.size());
716+
}
717+
settings.endArray();
718+
719+
// Write dummy data to overwrite the original commands
720+
WriteCommandHistory();
721+
722+
// Clear the dummy data (leaves it intact on disk)
723+
for (QStringList::size_type i = history.size(); i; ) {
724+
--i;
725+
history[i].clear();
726+
}
727+
WriteCommandHistory();
728+
729+
// Clear the history list
730+
historyPtr = 0;
731+
cmdBeforeBrowsing.clear();
732+
}
733+
694734
RPCConsole::~RPCConsole()
695735
{
696736
QSettings settings;
@@ -1182,6 +1222,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11821222
return;
11831223
}
11841224

1225+
// Special command to clear command history
1226+
if (cmd == QLatin1String("/clearhistory")) {
1227+
QMessageBox::StandardButton reply = QMessageBox::question(this,
1228+
tr("Clear Command History"),
1229+
tr("This will permanently clear your command history and console output.<br><br>"
1230+
"While this action is irreversible, complete removal from memory and disk "
1231+
"cannot be guaranteed.<br><br>"
1232+
"Are you sure you want to proceed?"),
1233+
QMessageBox::Yes | QMessageBox::No,
1234+
QMessageBox::No);
1235+
1236+
if (reply == QMessageBox::Yes) {
1237+
ClearCommandHistory();
1238+
clear(false); // Clear console output too
1239+
message(CMD_REPLY, tr("Command history and console output cleared."));
1240+
}
1241+
ui->lineEdit->clear();
1242+
return;
1243+
}
1244+
11851245
if (m_is_executing) {
11861246
return;
11871247
}

src/qt/rpcconsole.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public Q_SLOTS:
166166
void startExecutor();
167167
void setTrafficGraphRange(int mins);
168168
void WriteCommandHistory();
169+
void ClearCommandHistory();
169170

170171
enum ColumnWidths
171172
{

0 commit comments

Comments
 (0)