Skip to content

Commit 12277ef

Browse files
committed
qt: add console commands for clearing screen, clearing and viewing history
Adds the following console commands: - `clear`: clears the console output area. - `clear-all`: clears both output and command history. - `history`: lists stored command history. - `history-clear`: clears command history only. These additions improve privacy and convenience in shared or long-lived sessions by allowing users to remove sensitive commands and output from view.
1 parent 9314113 commit 12277ef

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

src/qt/rpcconsole.cpp

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public Q_SLOTS:
9393

9494
Q_SIGNALS:
9595
void reply(int category, const QString &command);
96+
void clearScreen();
97+
void clearHistory();
98+
void printHistory();
9699

97100
private:
98101
interfaces::Node& m_node;
@@ -402,7 +405,26 @@ 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+
" clear-all Clears the screen and command history.\n"
412+
" history Prints all command history.\n"
413+
" history-clear Clears the command history.\n\n"
414+
)));
415+
return;
416+
} else if (executableCommand == "clear\n") {
417+
Q_EMIT clearScreen();
418+
return;
419+
} else if (executableCommand == "clear-all\n") {
420+
Q_EMIT clearHistory();
421+
Q_EMIT clearScreen();
422+
return;
423+
} else if (executableCommand == "history-clear\n") {
424+
Q_EMIT clearHistory();
425+
return;
426+
} else if (executableCommand == "history\n") {
427+
Q_EMIT printHistory();
406428
return;
407429
}
408430
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
@@ -728,6 +750,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
728750
}
729751

730752
wordList << "help-console";
753+
wordList << "clear";
754+
wordList << "clear-all";
755+
wordList << "history";
756+
wordList << "history-clear";
731757
wordList.sort();
732758
autoCompleter = new QCompleter(wordList, this);
733759
autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
@@ -1081,14 +1107,36 @@ void RPCConsole::startExecutor()
10811107
{
10821108
m_executor = new RPCExecutor(m_node);
10831109
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.
1110+
const auto finish = [this](const auto action) {
10881111
ui->messagesWidget->undo();
1089-
message(category, command);
1112+
action();
10901113
scrollToEnd();
10911114
m_is_executing = false;
1115+
};
1116+
1117+
// Replies from executor object must go to this object
1118+
connect(m_executor, &RPCExecutor::reply, this, [this, finish](int category, const QString& command) {
1119+
finish([this, category, command]() { message(category, command); });
1120+
});
1121+
connect(m_executor, &RPCExecutor::clearScreen, this, [this, finish]() {
1122+
finish([this]() { clear(false); });
1123+
});
1124+
connect(m_executor, &RPCExecutor::clearHistory, this, [this, finish]() {
1125+
finish([this]() {
1126+
history.clear();
1127+
message(CMD_REPLY, tr("History has been cleared."));
1128+
});
1129+
});
1130+
connect(m_executor, &RPCExecutor::printHistory, this, [this, finish]() {
1131+
finish([this]() {
1132+
QStringList out;
1133+
out.reserve(history.size());
1134+
qsizetype index = 0;
1135+
for (const QString& entry : history) {
1136+
out << tr("%1: %2").arg(++index).arg(entry);
1137+
}
1138+
message(CMD_REPLY, out.join(QStringLiteral("\n")));
1139+
});
10921140
});
10931141

10941142
// Make sure executor object is deleted in its own thread

0 commit comments

Comments
 (0)