simplewallet: add clear command

Clears the console screen, as one would expect from a shell.
tools::clear_screen() already existed, but its only caller was the
wallet lock screen; this exposes it as a command.

PAUSE_READLINE() is used because readline substitutes its own streambuf
for std::cout's while running, so without it the escape sequences would
be routed through readline_buffer::sync() and interleaved with prompt
redraws.
This commit is contained in:
Thomas
2026-08-08 14:17:57 +05:00
parent d56daee995
commit 616613c157
2 changed files with 13 additions and 0 deletions
+12
View File
@@ -279,6 +279,7 @@ namespace
const char* USAGE_WELCOME("welcome");
const char* USAGE_SHOW_QR_CODE("show_qr_code [<subaddress_index>]");
const char* USAGE_VERSION("version");
const char* USAGE_CLEAR("clear");
const char* USAGE_HELP("help [<command> | all]");
const char* USAGE_APROPOS("apropos <keyword> [<keyword> ...]");
const char* USAGE_SCAN_TX("scan_tx <txid> [<txid> ...]");
@@ -2148,6 +2149,13 @@ bool simple_wallet::version(const std::vector<std::string> &args)
return true;
}
bool simple_wallet::clear(const std::vector<std::string> &args)
{
PAUSE_READLINE();
tools::clear_screen();
return true;
}
bool simple_wallet::on_unknown_command(const std::vector<std::string> &args)
{
if (args[0] == "exit" || args[0] == "q") // backward compat
@@ -3516,6 +3524,10 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::on_command, this, &simple_wallet::version, _1),
tr(USAGE_VERSION),
tr("Returns version information"));
m_cmd_binder.set_handler("clear",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::clear, _1),
tr(USAGE_CLEAR),
tr("Clear the console screen"));
m_cmd_binder.set_handler("show_qr_code",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::show_qr_code, _1),
tr(USAGE_SHOW_QR_CODE),
+1
View File
@@ -256,6 +256,7 @@ namespace cryptonote
bool public_nodes(const std::vector<std::string>& args);
bool welcome(const std::vector<std::string>& args);
bool version(const std::vector<std::string>& args);
bool clear(const std::vector<std::string>& args);
bool on_unknown_command(const std::vector<std::string>& args);
bool cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func);