From 616613c157cd7e4657f139765fdf06285eeb57c9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 8 Aug 2026 14:07:52 +0500 Subject: [PATCH] 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. --- src/simplewallet/simplewallet.cpp | 12 ++++++++++++ src/simplewallet/simplewallet.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 066c1d10a..7eff5d1ed 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -279,6 +279,7 @@ namespace const char* USAGE_WELCOME("welcome"); const char* USAGE_SHOW_QR_CODE("show_qr_code []"); const char* USAGE_VERSION("version"); + const char* USAGE_CLEAR("clear"); const char* USAGE_HELP("help [ | all]"); const char* USAGE_APROPOS("apropos [ ...]"); const char* USAGE_SCAN_TX("scan_tx [ ...]"); @@ -2148,6 +2149,13 @@ bool simple_wallet::version(const std::vector &args) return true; } +bool simple_wallet::clear(const std::vector &args) +{ + PAUSE_READLINE(); + tools::clear_screen(); + return true; +} + bool simple_wallet::on_unknown_command(const std::vector &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), diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 6d8719ab0..54c4e00c7 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -256,6 +256,7 @@ namespace cryptonote bool public_nodes(const std::vector& args); bool welcome(const std::vector& args); bool version(const std::vector& args); + bool clear(const std::vector& args); bool on_unknown_command(const std::vector& args); bool cold_sign_tx(const std::vector& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector &dsts_info, std::function accept_func);