@@ -93,6 +93,8 @@ public Q_SLOTS:
9393
9494Q_SIGNALS:
9595 void reply (int category, const QString &command);
96+ void clearConsole (bool clear_screen, bool clear_history);
97+ void printHistory ();
9698
9799private:
98100 interfaces::Node& m_node;
@@ -402,7 +404,25 @@ 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+ " clear-all Clears the screen and command history.\n "
411+ " history Prints all command history.\n "
412+ " history-clear Clears the command history.\n\n "
413+ )));
414+ return ;
415+ } else if (executableCommand == " clear\n " ) {
416+ Q_EMIT clearConsole (true , false );
417+ return ;
418+ } else if (executableCommand == " clear-all\n " ) {
419+ Q_EMIT clearConsole (true , true );
420+ return ;
421+ } else if (executableCommand == " history-clear\n " ) {
422+ Q_EMIT clearConsole (false , true );
423+ return ;
424+ } else if (executableCommand == " history\n " ) {
425+ Q_EMIT printHistory ();
406426 return ;
407427 }
408428 if (!RPCConsole::RPCExecuteCommandLine (m_node, result, executableCommand, nullptr , wallet_name)) {
@@ -728,6 +748,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
728748 }
729749
730750 wordList << " help-console" ;
751+ wordList << " clear" ;
752+ wordList << " clear-all" ;
753+ wordList << " history" ;
754+ wordList << " history-clear" ;
731755 wordList.sort ();
732756 autoCompleter = new QCompleter (wordList, this );
733757 autoCompleter->setModelSorting (QCompleter::CaseSensitivelySortedModel);
@@ -1081,14 +1105,34 @@ void RPCConsole::startExecutor()
10811105{
10821106 m_executor = new RPCExecutor (m_node);
10831107 m_executor->moveToThread (&thread);
1084-
1085- // Replies from executor object must go to this object
1086- connect (m_executor, &RPCExecutor::reply, this , [this ](int category, const QString& command) {
1087- // Remove "Executing…" message.
1108+ const auto finish = [this ](const auto action) {
10881109 ui->messagesWidget ->undo ();
1089- message (category, command );
1110+ action ( );
10901111 scrollToEnd ();
10911112 m_is_executing = false ;
1113+ };
1114+
1115+ // Replies from executor object must go to this object
1116+ connect (m_executor, &RPCExecutor::reply, this , [this , finish](int category, const QString& command) {
1117+ finish ([this , category, command]() { message (category, command); });
1118+ });
1119+ connect (m_executor, &RPCExecutor::clearConsole, this , [this , finish](bool clear_screen, bool clear_history) {
1120+ finish ([this , clear_screen, clear_history]() {
1121+ if (clear_history) {
1122+ history.clear ();
1123+ if (!clear_screen) message (CMD_REPLY, tr (" History has been cleared." ));
1124+ }
1125+ if (clear_screen) clear ();
1126+ });
1127+ });
1128+ connect (m_executor, &RPCExecutor::printHistory, this , [this , finish]() {
1129+ finish ([this ]() {
1130+ QStringList out;
1131+ out.reserve (history.size ());
1132+ for (qsizetype i = 0 ; i < history.size (); ++i)
1133+ out << tr (" %1: %2" ).arg (i+1 ).arg (history.at (i));
1134+ message (CMD_REPLY, out.join (QStringLiteral (" \n " )));
1135+ });
10921136 });
10931137
10941138 // Make sure executor object is deleted in its own thread
0 commit comments