@@ -93,6 +93,8 @@ public Q_SLOTS:
9393
9494Q_SIGNALS:
9595 void reply (int category, const QString &command);
96+ void clear (bool clear_history);
97+ void printHistory ();
9698
9799private:
98100 interfaces::Node& m_node;
@@ -402,7 +404,21 @@ void RPCExecutor::request(const QString &command, const QString& wallet_name)
402404 " example: getblock(getblockhash(0) 1)[tx]\n\n "
403405
404406 " Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n "
405- " example: getblock(getblockhash(0),1)[tx][0]\n\n " )));
407+ " example: getblock(getblockhash(0),1)[tx][0]\n\n "
408+ " Console commands:\n "
409+ " clear Clears the screen.\n "
410+ " history-clear Clears the command history and the screen.\n "
411+ " history Prints all command history.\n\n "
412+ )));
413+ return ;
414+ } else if (executableCommand == " clear\n " ) {
415+ Q_EMIT clear (false );
416+ return ;
417+ } else if (executableCommand == " history-clear\n " ) {
418+ Q_EMIT clear (true );
419+ return ;
420+ } else if (executableCommand == " history\n " ) {
421+ Q_EMIT printHistory ();
406422 return ;
407423 }
408424 if (!RPCConsole::RPCExecuteCommandLine (m_node, result, executableCommand, nullptr , wallet_name)) {
@@ -506,6 +522,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
506522 ui->openDebugLogfileButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/export" ));
507523 }
508524 ui->clearButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/remove" ));
525+ ui->resetButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/transaction_abandoned" )); // Trash icon
509526
510527 ui->fontBiggerButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/fontbigger" ));
511528 // : Main shortcut to increase the RPC console font size.
@@ -528,6 +545,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
528545
529546 connect (ui->hidePeersDetailButton , &QAbstractButton::clicked, this , &RPCConsole::clearSelectedNode);
530547 connect (ui->clearButton , &QAbstractButton::clicked, [this ] { clear (); });
548+ connect (ui->resetButton , &QAbstractButton::clicked, [this ] { clear (false , true ); });
531549 connect (ui->fontBiggerButton , &QAbstractButton::clicked, this , &RPCConsole::fontBigger);
532550 connect (ui->fontSmallerButton , &QAbstractButton::clicked, this , &RPCConsole::fontSmaller);
533551 connect (ui->btnClearTrafficGraph , &QPushButton::clicked, ui->trafficGraph , &TrafficGraphWidget::clear);
@@ -728,6 +746,9 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
728746 }
729747
730748 wordList << " help-console" ;
749+ wordList << " clear" ;
750+ wordList << " history-clear" ;
751+ wordList << " history" ;
731752 wordList.sort ();
732753 autoCompleter = new QCompleter (wordList, this );
733754 autoCompleter->setModelSorting (QCompleter::CaseSensitivelySortedModel);
@@ -823,8 +844,9 @@ void RPCConsole::setFontSize(int newSize)
823844 ui->messagesWidget ->verticalScrollBar ()->setValue (oldPosFactor * ui->messagesWidget ->verticalScrollBar ()->maximum ());
824845}
825846
826- void RPCConsole::clear (bool keep_prompt)
847+ void RPCConsole::clear (bool keep_prompt, bool clear_history )
827848{
849+ if (clear_history) history.clear ();
828850 ui->messagesWidget ->clear ();
829851 if (!keep_prompt) ui->lineEdit ->clear ();
830852 ui->lineEdit ->setFocus ();
@@ -863,6 +885,7 @@ void RPCConsole::clear(bool keep_prompt)
863885 they are not space separated from the rest of the text intentionally. */
864886 tr (" Welcome to the %1 RPC console.\n "
865887 " Use up and down arrows to navigate history, and %2 to clear screen.\n "
888+ " Use %9 to clear both the screen and the command history.\n "
866889 " Use %3 and %4 to increase or decrease the font size.\n "
867890 " Type %5 for an overview of available commands.\n "
868891 " For more information on using this console, type %6.\n "
@@ -877,7 +900,9 @@ void RPCConsole::clear(bool keep_prompt)
877900 " <b>help</b>" ,
878901 " <b>help-console</b>" ,
879902 " <span class=\" secwarning\" >" ,
880- " <span>" );
903+ " <span>" ,
904+ " <b>" + ui->resetButton ->shortcut ().toString (QKeySequence::NativeText) + " </b>"
905+ );
881906
882907 message (CMD_REPLY, welcome_message, true );
883908}
@@ -1090,6 +1115,22 @@ void RPCConsole::startExecutor()
10901115 scrollToEnd ();
10911116 m_is_executing = false ;
10921117 });
1118+ connect (m_executor, &RPCExecutor::clear, this , [this ](bool clear_history) {
1119+ clear (false , clear_history);
1120+ scrollToEnd ();
1121+ m_is_executing = false ;
1122+ });
1123+ connect (m_executor, &RPCExecutor::printHistory, this , [this ]() {
1124+ QStringList out;
1125+ int index = 0 ;
1126+ for (const QString& entry : history) {
1127+ out << QString::number (++index) + " : " + entry;
1128+ }
1129+ ui->messagesWidget ->undo ();
1130+ message (CMD_REPLY, out.join (" \n " ));
1131+ scrollToEnd ();
1132+ m_is_executing = false ;
1133+ });
10931134
10941135 // Make sure executor object is deleted in its own thread
10951136 connect (&thread, &QThread::finished, m_executor, &RPCExecutor::deleteLater);
0 commit comments