mirror of
https://github.com/monero-project/monero.git
synced 2025-05-02 21:14:55 -04:00
Merge pull request #2240
b7d6ec83
simplewallet: add (out of sync) or (no daemon) markers in the prompt (moneromooo-monero)fa23a500
wallet2: add a is_synced function (moneromooo-monero)f1307bbd
node_rpc_proxy: add a proxy for target height (moneromooo-monero)
This commit is contained in:
commit
6f60613ffb
7 changed files with 89 additions and 28 deletions
|
@ -293,13 +293,13 @@ namespace epee
|
|||
}
|
||||
|
||||
template<class t_server, class chain_handler>
|
||||
bool run(t_server* psrv, chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "")
|
||||
bool run(t_server* psrv, chain_handler ch_handler, std::function<std::string(void)> prompt, const std::string& usage = "")
|
||||
{
|
||||
return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(psrv, cmd); }, [&] { psrv->send_stop_signal(); });
|
||||
}
|
||||
|
||||
template<class chain_handler>
|
||||
bool run(chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "", std::function<void(void)> exit_handler = NULL)
|
||||
bool run(chain_handler ch_handler, std::function<std::string(void)> prompt, const std::string& usage = "", std::function<void(void)> exit_handler = NULL)
|
||||
{
|
||||
return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(cmd); }, exit_handler);
|
||||
}
|
||||
|
@ -312,18 +312,19 @@ namespace epee
|
|||
|
||||
void print_prompt()
|
||||
{
|
||||
if (!m_prompt.empty())
|
||||
std::string prompt = m_prompt();
|
||||
if (!prompt.empty())
|
||||
{
|
||||
#ifdef HAVE_READLINE
|
||||
std::string color_prompt = "\001\033[1;33m\002" + m_prompt;
|
||||
if (' ' != m_prompt.back())
|
||||
std::string color_prompt = "\001\033[1;33m\002" + prompt;
|
||||
if (' ' != prompt.back())
|
||||
color_prompt += " ";
|
||||
color_prompt += "\001\033[0m\002";
|
||||
m_stdin_reader.get_readline_buffer().set_prompt(color_prompt);
|
||||
#else
|
||||
epee::set_console_color(epee::console_color_yellow, true);
|
||||
std::cout << m_prompt;
|
||||
if (' ' != m_prompt.back())
|
||||
std::cout << prompt;
|
||||
if (' ' != prompt.back())
|
||||
std::cout << ' ';
|
||||
epee::reset_console_color();
|
||||
std::cout.flush();
|
||||
|
@ -333,7 +334,7 @@ namespace epee
|
|||
|
||||
private:
|
||||
template<typename t_cmd_handler>
|
||||
bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler)
|
||||
bool run(std::function<std::string(void)> prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler)
|
||||
{
|
||||
bool continue_handle = true;
|
||||
m_prompt = prompt;
|
||||
|
@ -394,7 +395,7 @@ namespace epee
|
|||
private:
|
||||
async_stdin_reader m_stdin_reader;
|
||||
std::atomic<bool> m_running = {true};
|
||||
std::string m_prompt;
|
||||
std::function<std::string(void)> m_prompt;
|
||||
};
|
||||
|
||||
|
||||
|
@ -516,19 +517,23 @@ namespace epee
|
|||
std::unique_ptr<boost::thread> m_console_thread;
|
||||
async_console_handler m_console_handler;
|
||||
public:
|
||||
bool start_handling(const std::string& prompt, const std::string& usage_string = "", std::function<void(void)> exit_handler = NULL)
|
||||
bool start_handling(std::function<std::string(void)> prompt, const std::string& usage_string = "", std::function<void(void)> exit_handler = NULL)
|
||||
{
|
||||
m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string, exit_handler)));
|
||||
m_console_thread->detach();
|
||||
return true;
|
||||
}
|
||||
bool start_handling(const std::string &prompt, const std::string& usage_string = "", std::function<void(void)> exit_handler = NULL)
|
||||
{
|
||||
return start_handling([prompt](){ return prompt; }, usage_string, exit_handler);
|
||||
}
|
||||
|
||||
void stop_handling()
|
||||
{
|
||||
m_console_handler.stop();
|
||||
}
|
||||
|
||||
bool run_handling(const std::string& prompt, const std::string& usage_string, std::function<void(void)> exit_handler = NULL)
|
||||
bool run_handling(std::function<std::string(void)> prompt, const std::string& usage_string, std::function<void(void)> exit_handler = NULL)
|
||||
{
|
||||
return m_console_handler.run(boost::bind(&console_handlers_binder::process_command_str, this, _1), prompt, usage_string, exit_handler);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue