@@ -93,6 +93,9 @@ public Q_SLOTS:
9393
9494Q_SIGNALS:
9595 void reply (int category, const QString &command);
96+ void clearScreen ();
97+ void clearHistory ();
98+ void printHistory ();
9699
97100private:
98101 interfaces::Node& m_node;
@@ -402,7 +405,21 @@ void RPCExecutor::request(const QString &command, const QString& wallet_name)
402405 " example: getblock(getblockhash(0) 1)[tx]\n\n "
403406
404407 " 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 " )));
408+ " example: getblock(getblockhash(0),1)[tx][0]\n\n "
409+ " Console commands:\n "
410+ " clear Clears the screen.\n "
411+ " history-clear Clears the command history and the screen.\n "
412+ " history Prints all command history.\n\n "
413+ )));
414+ return ;
415+ } else if (executableCommand == " clear\n " ) {
416+ Q_EMIT clearScreen ();
417+ return ;
418+ } else if (executableCommand == " history-clear\n " ) {
419+ Q_EMIT clearHistory ();
420+ return ;
421+ } else if (executableCommand == " history\n " ) {
422+ Q_EMIT printHistory ();
406423 return ;
407424 }
408425 if (!RPCConsole::RPCExecuteCommandLine (m_node, result, executableCommand, nullptr , wallet_name)) {
@@ -506,6 +523,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
506523 ui->openDebugLogfileButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/export" ));
507524 }
508525 ui->clearButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/remove" ));
526+ ui->resetButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/transaction_abandoned" )); // Trash icon
509527
510528 ui->fontBiggerButton ->setIcon (platformStyle->SingleColorIcon (" :/icons/fontbigger" ));
511529 // : Main shortcut to increase the RPC console font size.
@@ -527,7 +545,11 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
527545 ui->messagesWidget ->installEventFilter (this );
528546
529547 connect (ui->hidePeersDetailButton , &QAbstractButton::clicked, this , &RPCConsole::clearSelectedNode);
530- connect (ui->clearButton , &QAbstractButton::clicked, [this ] { clear (); });
548+ connect (ui->clearButton , &QAbstractButton::clicked, [this ]() { clear (); });
549+ connect (ui->resetButton , &QAbstractButton::clicked, [this ]() {
550+ history.clear ();
551+ clear (false );
552+ });
531553 connect (ui->fontBiggerButton , &QAbstractButton::clicked, this , &RPCConsole::fontBigger);
532554 connect (ui->fontSmallerButton , &QAbstractButton::clicked, this , &RPCConsole::fontSmaller);
533555 connect (ui->btnClearTrafficGraph , &QPushButton::clicked, ui->trafficGraph , &TrafficGraphWidget::clear);
@@ -728,6 +750,9 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
728750 }
729751
730752 wordList << " help-console" ;
753+ wordList << " clear" ;
754+ wordList << " history-clear" ;
755+ wordList << " history" ;
731756 wordList.sort ();
732757 autoCompleter = new QCompleter (wordList, this );
733758 autoCompleter->setModelSorting (QCompleter::CaseSensitivelySortedModel);
@@ -863,6 +888,7 @@ void RPCConsole::clear(bool keep_prompt)
863888 they are not space separated from the rest of the text intentionally. */
864889 tr (" Welcome to the %1 RPC console.\n "
865890 " Use up and down arrows to navigate history, and %2 to clear screen.\n "
891+ " Use %9 to reset the console, clearing both the screen and command history.\n "
866892 " Use %3 and %4 to increase or decrease the font size.\n "
867893 " Type %5 for an overview of available commands.\n "
868894 " For more information on using this console, type %6.\n "
@@ -877,7 +903,8 @@ void RPCConsole::clear(bool keep_prompt)
877903 " <b>help</b>" ,
878904 " <b>help-console</b>" ,
879905 " <span class=\" secwarning\" >" ,
880- " <span>" );
906+ " <span>" ,
907+ " <b>" + ui->resetButton ->shortcut ().toString (QKeySequence::NativeText) + " </b>" );
881908
882909 message (CMD_REPLY, welcome_message, true );
883910}
@@ -1077,18 +1104,43 @@ void RPCConsole::browseHistory(int offset)
10771104 ui->lineEdit ->setText (cmd);
10781105}
10791106
1107+ void RPCConsole::finishCommand (const std::function<void ()>& action)
1108+ {
1109+ // Remove "Executing…" message.
1110+ ui->messagesWidget ->undo ();
1111+ action ();
1112+ scrollToEnd ();
1113+ m_is_executing = false ;
1114+ }
1115+
10801116void RPCConsole::startExecutor ()
10811117{
10821118 m_executor = new RPCExecutor (m_node);
10831119 m_executor->moveToThread (&thread);
10841120
10851121 // Replies from executor object must go to this object
10861122 connect (m_executor, &RPCExecutor::reply, this , [this ](int category, const QString& command) {
1087- // Remove "Executing…" message.
1088- ui->messagesWidget ->undo ();
1089- message (category, command);
1090- scrollToEnd ();
1091- m_is_executing = false ;
1123+ finishCommand ([this , category, command]() { message (category, command); });
1124+ });
1125+ connect (m_executor, &RPCExecutor::clearScreen, this , [this ]() {
1126+ finishCommand ([this ]() { clear (false ); });
1127+ });
1128+ connect (m_executor, &RPCExecutor::clearHistory, this , [this ]() {
1129+ finishCommand ([this ]() {
1130+ history.clear ();
1131+ message (CMD_REPLY, tr (" History has been cleared." ));
1132+ });
1133+ });
1134+ connect (m_executor, &RPCExecutor::printHistory, this , [this ]() {
1135+ finishCommand ([this ]() {
1136+ QStringList out;
1137+ out.reserve (history.size ());
1138+ qsizetype index = 0 ;
1139+ for (const QString& entry : history) {
1140+ out << QStringLiteral (" %1: %2" ).arg (++index).arg (entry);
1141+ }
1142+ message (CMD_REPLY, out.join (QStringLiteral (" \n " )));
1143+ });
10921144 });
10931145
10941146 // Make sure executor object is deleted in its own thread
0 commit comments