Skip to content

Commit 918f4ec

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

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/qt/rpcconsole.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,34 @@ 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+
history.resize(size);
701+
for (int i = 0; i < size; ++i) {
702+
settings.setArrayIndex(i);
703+
QString cmd = settings.value("cmd").toString();
704+
// Store dummy command with same length as original (don't leak length info)
705+
dummy_commands.append(QString(cmd.size(), 'x'));
706+
history.replace(i, QString(cmd.size(), 'x'));
707+
}
708+
settings.endArray();
709+
710+
// Write dummy data to overwrite the original commands
711+
WriteCommandHistory();
712+
713+
// Clear the history list
714+
history.clear();
715+
historyPtr = 0;
716+
cmdBeforeBrowsing.clear();
717+
718+
// Second pass: write empty history to settings
719+
WriteCommandHistory();
720+
}
721+
694722
RPCConsole::~RPCConsole()
695723
{
696724
QSettings settings;
@@ -1182,6 +1210,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11821210
return;
11831211
}
11841212

1213+
// Special command to clear command history
1214+
if (cmd == QLatin1String("/clearhistory")) {
1215+
QMessageBox::StandardButton reply = QMessageBox::question(this,
1216+
tr("Clear Command History"),
1217+
tr("This will permanently clear your command history and console output.<br><br>"
1218+
"While this action is irreversible, complete removal from memory and disk "
1219+
"cannot be guaranteed.<br><br>"
1220+
"Are you sure you want to proceed?"),
1221+
QMessageBox::Yes | QMessageBox::No,
1222+
QMessageBox::No);
1223+
1224+
if (reply == QMessageBox::Yes) {
1225+
ClearCommandHistory();
1226+
clear(false); // Clear console output too
1227+
message(CMD_REPLY, tr("Command history and console output cleared."));
1228+
}
1229+
ui->lineEdit->clear();
1230+
return;
1231+
}
1232+
11851233
if (m_is_executing) {
11861234
return;
11871235
}

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)