make CLI prompt configurable

This commit is contained in:
Daniel Larimer 2015-05-18 13:40:01 -04:00
parent 135949ee19
commit a3c284408e
2 changed files with 9 additions and 10 deletions

View file

@ -53,16 +53,18 @@ namespace fc { namespace rpc {
virtual void getline( const fc::string& prompt, fc::string& line ); virtual void getline( const fc::string& prompt, fc::string& line );
void set_prompt( const string& prompt ) { _prompt = prompt; }
private: private:
void run() void run()
{ {
while( !_run_complete.canceled() ) while( !_run_complete.canceled() )
{ {
try { try {
std::string line; std::string line;
try try
{ {
getline( ">>> ", line ); getline( _prompt.c_str(), line );
} }
catch ( const fc::eof_exception& e ) catch ( const fc::eof_exception& e )
{ {
@ -88,8 +90,9 @@ namespace fc { namespace rpc {
{ {
std::cout << e.to_detail_string() << "\n"; std::cout << e.to_detail_string() << "\n";
} }
} }
} }
std::string _prompt = ">>>";
std::map<string,std::function<string(variant,const variants&)> > _result_formatters; std::map<string,std::function<string(variant,const variants&)> > _result_formatters;
fc::future<void> _run_complete; fc::future<void> _run_complete;
}; };

View file

@ -1,4 +1,3 @@
#include <fc/rpc/cli.hpp> #include <fc/rpc/cli.hpp>
#include <fc/thread/thread.hpp> #include <fc/thread/thread.hpp>
@ -31,10 +30,7 @@
namespace fc { namespace rpc { namespace fc { namespace rpc {
void cli::getline( void cli::getline( const fc::string& prompt, fc::string& line)
const fc::string& prompt,
fc::string& line
)
{ {
// getting file descriptor for C++ streams is near impossible // getting file descriptor for C++ streams is near impossible
// so we just assume it's the same as the C stream... // so we just assume it's the same as the C stream...