@@ -693,6 +693,49 @@ 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+ history.clear ();
733+ WriteCommandHistory ();
734+
735+ historyPtr = 0 ;
736+ cmdBeforeBrowsing.clear ();
737+ }
738+
696739RPCConsole::~RPCConsole ()
697740{
698741 QSettings settings;
@@ -1184,6 +1227,26 @@ void RPCConsole::on_lineEdit_returnPressed()
11841227 return ;
11851228 }
11861229
1230+ // Special command to clear command history
1231+ if (cmd == QLatin1String (" /clearhistory" )) {
1232+ QMessageBox::StandardButton reply = QMessageBox::question (this ,
1233+ tr (" Clear Command History" ),
1234+ tr (" This will permanently clear your command history and console output.<br><br>"
1235+ " While this action is irreversible, complete removal from memory and disk "
1236+ " cannot be guaranteed.<br><br>"
1237+ " Are you sure you want to proceed?" ),
1238+ QMessageBox::Yes | QMessageBox::No,
1239+ QMessageBox::No);
1240+
1241+ if (reply == QMessageBox::Yes) {
1242+ ClearCommandHistory ();
1243+ clear (/* keep_prompt=*/ false ); // Clear console output too
1244+ message (CMD_REPLY, tr (" Command history and console output cleared." ));
1245+ }
1246+ ui->lineEdit ->clear ();
1247+ return ;
1248+ }
1249+
11871250 if (m_is_executing) {
11881251 return ;
11891252 }
0 commit comments