Fix multiline wallet cli output with readline

monero-wallet-cli commands which have multine output sometimes causes
issues with the readline support. This patch fixes show_transfers,
payments and incoming_transfers.
This commit is contained in:
Jethro Grassie 2017-06-22 08:15:18 -04:00
parent 0c6ea4f8a6
commit be9d4f0411
No known key found for this signature in database
GPG Key ID: DE8ED755616565BB
2 changed files with 20 additions and 1 deletions

View File

@ -12,7 +12,7 @@ static void remove_line_handler();
static std::string last_line; static std::string last_line;
static std::string last_prompt; static std::string last_prompt;
std::mutex line_mutex, sync_mutex; std::mutex line_mutex, sync_mutex, process_mutex;
std::condition_variable have_line; std::condition_variable have_line;
namespace namespace
@ -21,6 +21,7 @@ namespace
} }
rdln::suspend_readline::suspend_readline() rdln::suspend_readline::suspend_readline()
: m_buffer(NULL), m_restart(false)
{ {
m_buffer = current; m_buffer = current;
if(!m_buffer) if(!m_buffer)
@ -46,6 +47,7 @@ rdln::readline_buffer::readline_buffer()
void rdln::readline_buffer::start() void rdln::readline_buffer::start()
{ {
std::unique_lock<std::mutex> lock(process_mutex);
if(m_cout_buf != NULL) if(m_cout_buf != NULL)
return; return;
m_cout_buf = std::cout.rdbuf(); m_cout_buf = std::cout.rdbuf();
@ -55,6 +57,7 @@ void rdln::readline_buffer::start()
void rdln::readline_buffer::stop() void rdln::readline_buffer::stop()
{ {
std::unique_lock<std::mutex> lock(process_mutex);
if(m_cout_buf == NULL) if(m_cout_buf == NULL)
return; return;
std::cout.rdbuf(m_cout_buf); std::cout.rdbuf(m_cout_buf);
@ -80,6 +83,7 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt)
int rdln::readline_buffer::process() int rdln::readline_buffer::process()
{ {
std::unique_lock<std::mutex> lock(process_mutex);
if(m_cout_buf == NULL) if(m_cout_buf == NULL)
return 0; return 0;
return process_input(); return process_input();

View File

@ -62,6 +62,15 @@
#include "wallet/wallet_args.h" #include "wallet/wallet_args.h"
#include <stdexcept> #include <stdexcept>
#ifdef HAVE_READLINE
#include "readline_buffer.h"
#define PAUSE_READLINE() \
rdln::suspend_readline pause_readline; \
std::cout << std::endl
#else
#define PAUSE_READLINE()
#endif
using namespace std; using namespace std;
using namespace epee; using namespace epee;
using namespace cryptonote; using namespace cryptonote;
@ -1831,6 +1840,8 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
} }
} }
PAUSE_READLINE();
tools::wallet2::transfer_container transfers; tools::wallet2::transfer_container transfers;
m_wallet->get_transfers(transfers); m_wallet->get_transfers(transfers);
@ -1891,6 +1902,8 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
LOCK_IDLE_SCOPE(); LOCK_IDLE_SCOPE();
PAUSE_READLINE();
message_writer() << boost::format("%68s%68s%12s%21s%16s") % message_writer() << boost::format("%68s%68s%12s%21s%16s") %
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time"); tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
@ -3716,6 +3729,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::multimap<uint64_t, std::pair<bool,std::string>> output; std::multimap<uint64_t, std::pair<bool,std::string>> output;
PAUSE_READLINE();
if (in) { if (in) {
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
m_wallet->get_payments(payments, min_height, max_height); m_wallet->get_payments(payments, min_height, max_height);