Skip to content

qt: add reset button and console commands for clearing output/history #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,32 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="resetButton">
<property name="toolTip">
<string>Clear console output and history.</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/transaction_abandoned</normaloff>:/icons/transaction_abandoned</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+L</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
47 changes: 44 additions & 3 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public Q_SLOTS:

Q_SIGNALS:
void reply(int category, const QString &command);
void clear(bool clear_history);
void printHistory();

private:
interfaces::Node& m_node;
Expand Down Expand Up @@ -402,7 +404,21 @@ void RPCExecutor::request(const QString &command, const QString& wallet_name)
" example: getblock(getblockhash(0) 1)[tx]\n\n"

"Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
" example: getblock(getblockhash(0),1)[tx][0]\n\n"
"Console commands:\n"
" clear Clears the screen.\n"
" history-clear Clears the command history and the screen.\n"
" history Prints all command history.\n\n"
)));
return;
} else if (executableCommand == "clear\n") {
Q_EMIT clear(false);
return;
} else if (executableCommand == "history-clear\n") {
Q_EMIT clear(true);
return;
} else if (executableCommand == "history\n") {
Q_EMIT printHistory();
return;
}
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
Expand Down Expand Up @@ -506,6 +522,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
}
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
ui->resetButton->setIcon(platformStyle->SingleColorIcon(":/icons/transaction_abandoned")); // Trash icon

ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
//: Main shortcut to increase the RPC console font size.
Expand All @@ -528,6 +545,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty

connect(ui->hidePeersDetailButton, &QAbstractButton::clicked, this, &RPCConsole::clearSelectedNode);
connect(ui->clearButton, &QAbstractButton::clicked, [this] { clear(); });
connect(ui->resetButton, &QAbstractButton::clicked, [this] { clear(false, true); });
connect(ui->fontBiggerButton, &QAbstractButton::clicked, this, &RPCConsole::fontBigger);
connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);
Expand Down Expand Up @@ -728,6 +746,9 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
}

wordList << "help-console";
wordList << "clear";
wordList << "history-clear";
wordList << "history";
wordList.sort();
autoCompleter = new QCompleter(wordList, this);
autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
Expand Down Expand Up @@ -823,8 +844,9 @@ void RPCConsole::setFontSize(int newSize)
ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
}

void RPCConsole::clear(bool keep_prompt)
void RPCConsole::clear(bool keep_prompt, bool clear_history)
{
if (clear_history) history.clear();
ui->messagesWidget->clear();
if (!keep_prompt) ui->lineEdit->clear();
ui->lineEdit->setFocus();
Expand Down Expand Up @@ -863,6 +885,7 @@ void RPCConsole::clear(bool keep_prompt)
they are not space separated from the rest of the text intentionally. */
tr("Welcome to the %1 RPC console.\n"
"Use up and down arrows to navigate history, and %2 to clear screen.\n"
"Use %9 to clear both the screen and the command history.\n"
"Use %3 and %4 to increase or decrease the font size.\n"
"Type %5 for an overview of available commands.\n"
"For more information on using this console, type %6.\n"
Expand All @@ -877,7 +900,9 @@ void RPCConsole::clear(bool keep_prompt)
"<b>help</b>",
"<b>help-console</b>",
"<span class=\"secwarning\">",
"<span>");
"<span>",
"<b>" + ui->resetButton->shortcut().toString(QKeySequence::NativeText) + "</b>"
);

message(CMD_REPLY, welcome_message, true);
}
Expand Down Expand Up @@ -1090,6 +1115,22 @@ void RPCConsole::startExecutor()
scrollToEnd();
m_is_executing = false;
});
connect(m_executor, &RPCExecutor::clear, this, [this](bool clear_history) {
clear(false, clear_history);
scrollToEnd();
m_is_executing = false;
});
connect(m_executor, &RPCExecutor::printHistory, this, [this]() {
QStringList out;
int index = 0;
for (const QString& entry : history) {
out << QString::number(++index) + ": " + entry;
}
ui->messagesWidget->undo();
message(CMD_REPLY, out.join("\n"));
scrollToEnd();
m_is_executing = false;
});

// Make sure executor object is deleted in its own thread
connect(&thread, &QThread::finished, m_executor, &RPCExecutor::deleteLater);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Q_SLOTS:
void updateDetailWidget();

public Q_SLOTS:
void clear(bool keep_prompt = false);
void clear(bool keep_prompt = false, bool clear_history = false);
void fontBigger();
void fontSmaller();
void setFontSize(int newSize);
Expand Down