From 7ed5ab47ea05900250e72bafb11d0e0fc3d180b9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 11 Aug 2017 13:38:18 +0100 Subject: [PATCH 1/2] scoped_message_writer: pause readline to match simplewallet --- src/common/scoped_message_writer.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h index e31f8f0b2..804e9dbdf 100644 --- a/src/common/scoped_message_writer.h +++ b/src/common/scoped_message_writer.h @@ -31,6 +31,14 @@ #include "misc_log_ex.h" #include +#ifdef HAVE_READLINE + #include "readline_buffer.h" + #define PAUSE_READLINE() \ + rdln::suspend_readline pause_readline; +#else + #define PAUSE_READLINE() +#endif + namespace tools { @@ -99,6 +107,7 @@ public: } else { + PAUSE_READLINE(); set_console_color(m_color, m_bright); std::cout << m_oss.str(); epee::reset_console_color(); From e499ff3322fd46b1107681184dac300fcc7dbebd Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 11 Aug 2017 13:38:42 +0100 Subject: [PATCH 2/2] simplewallet: factor out message_writer --- src/common/scoped_message_writer.h | 4 +- src/simplewallet/simplewallet.cpp | 92 ++++-------------------------- 2 files changed, 12 insertions(+), 84 deletions(-) diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h index 804e9dbdf..8fc98d2b0 100644 --- a/src/common/scoped_message_writer.h +++ b/src/common/scoped_message_writer.h @@ -117,9 +117,9 @@ public: } }; -inline scoped_message_writer success_msg_writer() +inline scoped_message_writer success_msg_writer(bool color = true) { - return scoped_message_writer(epee::console_color_green, false, std::string(), el::Level::Info); + return scoped_message_writer(color ? epee::console_color_green : epee::console_color_default, false, std::string(), el::Level::Info); } inline scoped_message_writer msg_writer(epee::console_colors color = epee::console_color_default) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 596c298d7..3d66b7aa6 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -48,6 +48,7 @@ #include "common/util.h" #include "common/dns_utils.h" #include "common/base58.h" +#include "common/scoped_message_writer.h" #include "p2p/net_node.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "simplewallet.h" @@ -62,14 +63,6 @@ #include "wallet/wallet_args.h" #include -#ifdef HAVE_READLINE - #include "readline_buffer.h" - #define PAUSE_READLINE() \ - rdln::suspend_readline pause_readline; -#else - #define PAUSE_READLINE() -#endif - using namespace std; using namespace epee; using namespace cryptonote; @@ -147,84 +140,19 @@ namespace return err; } - class message_writer + tools::scoped_message_writer success_msg_writer(bool color = false) { - public: - message_writer(console_colors color = console_color_default, bool bright = false, - std::string&& prefix = std::string(), el::Level log_level = el::Level::Info) - : m_flush(true) - , m_color(color) - , m_bright(bright) - , m_log_level(log_level) - { - m_oss << prefix; - } - - message_writer(message_writer&& rhs) - : m_flush(std::move(rhs.m_flush)) -#if defined(_MSC_VER) - , m_oss(std::move(rhs.m_oss)) -#else - // GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316 - , m_oss(rhs.m_oss.str(), ios_base::out | ios_base::ate) -#endif - , m_color(std::move(rhs.m_color)) - , m_log_level(std::move(rhs.m_log_level)) - { - rhs.m_flush = false; - } - - template - std::ostream& operator<<(const T& val) - { - m_oss << val; - return m_oss; - } - - ~message_writer() - { - if (m_flush) - { - m_flush = false; - - MCLOG(m_log_level, "global", m_oss.str()); - - if (console_color_default == m_color) - { - std::cout << m_oss.str(); - } - else - { - PAUSE_READLINE(); - set_console_color(m_color, m_bright); - std::cout << m_oss.str(); - reset_console_color(); - } - std::cout << std::endl; - } - } - - private: - message_writer(message_writer& rhs); - message_writer& operator=(message_writer& rhs); - message_writer& operator=(message_writer&& rhs); - - private: - bool m_flush; - std::stringstream m_oss; - console_colors m_color; - bool m_bright; - el::Level m_log_level; - }; - - message_writer success_msg_writer(bool color = false) - { - return message_writer(color ? console_color_green : console_color_default, false, std::string(), el::Level::Info); + return tools::scoped_message_writer(color ? console_color_green : console_color_default, false, std::string(), el::Level::Info); } - message_writer fail_msg_writer() + tools::scoped_message_writer message_writer(epee::console_colors color = epee::console_color_default, bool bright = false) { - return message_writer(console_color_red, true, sw::tr("Error: "), el::Level::Error); + return tools::scoped_message_writer(color, bright); + } + + tools::scoped_message_writer fail_msg_writer() + { + return tools::scoped_message_writer(console_color_red, true, sw::tr("Error: "), el::Level::Error); } bool is_it_true(const std::string& s)