@@ -693,6 +693,46 @@ void RPCConsole::WriteCommandHistory()
693693 settings.endArray ();
694694}
695695
696+ void RPCConsole::ClearCommandHistory ()
697+ {
698+ // First pass: read existing commands and overwrite with dummy data of same length
699+ QSettings settings;
700+ int size = settings.beginReadArray (" nRPCConsoleWindowHistory" );
701+ #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
702+ history.resize (size);
703+ #else
704+ if (history.size () > size) {
705+ history.erase (history.begin () + size, history.end ());
706+ } else {
707+ history.reserve (size);
708+ for (int i = history.size (); i < size; ++i) {
709+ history.append (QString ());
710+ }
711+ }
712+ #endif
713+ for (int i = 0 ; i < size; ++i) {
714+ settings.setArrayIndex (i);
715+ QString cmd = settings.value (" cmd" ).toString ();
716+ // Store dummy command with same length as original (don't leak length info)
717+ history[i].fill (' x' , cmd.size ());
718+ }
719+ settings.endArray ();
720+
721+ // Write dummy data to overwrite the original commands
722+ WriteCommandHistory ();
723+
724+ // Clear the dummy data (leaves it intact on disk)
725+ for (QStringList::size_type i = history.size (); i; ) {
726+ --i;
727+ history[i].clear ();
728+ }
729+ WriteCommandHistory ();
730+
731+ // Clear the history list
732+ historyPtr = 0 ;
733+ cmdBeforeBrowsing.clear ();
734+ }
735+
696736RPCConsole::~RPCConsole ()
697737{
698738 QSettings settings;
@@ -1184,6 +1224,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11841224 return ;
11851225 }
11861226
1227+ // Special command to clear command history
1228+ if (cmd == QLatin1String (" /clearhistory" )) {
1229+ QMessageBox::StandardButton reply = QMessageBox::question (this ,
1230+ tr (" Clear Command History" ),
1231+ tr (" This will permanently clear your command history and console output.<br><br>"
1232+ " While this action is irreversible, complete removal from memory and disk "
1233+ " cannot be guaranteed.<br><br>"
1234+ " Are you sure you want to proceed?" ),
1235+ QMessageBox::Yes | QMessageBox::No,
1236+ QMessageBox::No);
1237+
1238+ if (reply == QMessageBox::Yes) {
1239+ ClearCommandHistory ();
1240+ clear (false ); // Clear console output too
1241+ message (CMD_REPLY, tr (" Command history and console output cleared." ));
1242+ }
1243+ ui->lineEdit ->clear ();
1244+ return ;
1245+ }
1246+
11871247 if (m_is_executing) {
11881248 return ;
11891249 }
0 commit comments