Skip to content

Commit 7cb0262

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

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/qt/rpcconsole.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,45 @@ 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+
QStringList dummy_commands;
698+
QSettings settings;
699+
int size = settings.beginReadArray("nRPCConsoleWindowHistory");
700+
for (int i = 0; i < size; ++i) {
701+
settings.setArrayIndex(i);
702+
QString cmd = settings.value("cmd").toString();
703+
// Store dummy command with same length as original (don't leak length info)
704+
dummy_commands.append(QString(cmd.size(), 'x'));
705+
}
706+
settings.endArray();
707+
708+
// Write dummy data to overwrite the original commands
709+
if (!dummy_commands.empty()) {
710+
settings.beginWriteArray("nRPCConsoleWindowHistory");
711+
for (int i = 0; i < dummy_commands.size(); ++i) {
712+
settings.setArrayIndex(i);
713+
settings.setValue("cmd", dummy_commands[i]);
714+
}
715+
settings.endArray();
716+
settings.sync(); // Force to disk
717+
}
718+
719+
// Overwrite in-memory history with dummy data
720+
for (int i = 0; i < history.size(); ++i) {
721+
history[i] = QString(history[i].size(), 'x');
722+
}
723+
724+
// Clear the history list
725+
history.clear();
726+
historyPtr = 0;
727+
cmdBeforeBrowsing.clear();
728+
729+
// Second pass: write empty history to settings
730+
WriteCommandHistory();
731+
}
732+
694733
RPCConsole::~RPCConsole()
695734
{
696735
QSettings settings;
@@ -1182,6 +1221,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11821221
return;
11831222
}
11841223

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

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)