<commit_before>#include <bts/cli/cli.hpp>
#include <bts/rpc/rpc_server.hpp>
#include <bts/wallet/pretty.hpp>
#include <bts/wallet/wallet.hpp>

#include <fc/io/buffered_iostream.hpp>
#include <fc/io/console.hpp>
#include <fc/io/json.hpp>
#include <fc/io/sstream.hpp>
#include <fc/log/logger.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/thread/thread.hpp>
#include <fc/variant.hpp>

#include <boost/algorithm/string/trim.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iomanip>
#include <iostream>
#include <sstream>

#ifdef HAVE_READLINE
#include <readline/history.h>
#include <readline/readline.h>
#endif

namespace bts { namespace cli {

  namespace detail
  {
      class cli_impl
      {
         public:
            client_ptr                  _client;
            rpc_server_ptr              _rpc_server;
            bts::cli::cli*              _self;
//            fc::thread*                 _main_thread;
            fc::thread                  _cin_thread;
            fc::future<void>            _cin_complete;

            cli_impl( const client_ptr& client, const rpc_server_ptr& rpc_server );

            string get_prompt()const
            {
              string wallet_name =  _client->get_wallet()->get_wallet_name();
              string prompt = wallet_name;
              if( prompt == "" )
              {
                 prompt = "(wallet closed) >>> ";
              }
              else
              {
                 if( _client->get_wallet()->is_locked() )
                    prompt += " (locked) >>> ";
                 else
                    prompt += " (unlocked) >>> ";
              }
              return prompt;
            }

            void process_commands()
            { 
              try {
                 string line = _self->get_line(get_prompt());
                 while (std::cin.good())
                 {
                   string trimmed_line_to_parse(boost::algorithm::trim_copy(line));
                   if (!trimmed_line_to_parse.empty())
                   {
                     string::const_iterator iter = std::find_if(trimmed_line_to_parse.begin(), trimmed_line_to_parse.end(), ::isspace);
                     string command;
                     fc::istream_ptr argument_stream;
                     if (iter != trimmed_line_to_parse.end())
                     {
                       // then there are arguments to this function
                       size_t first_space_pos = iter - trimmed_line_to_parse.begin();
                       command = trimmed_line_to_parse.substr(0, first_space_pos);
                       argument_stream = std::make_shared<fc::stringstream>((trimmed_line_to_parse.substr(first_space_pos + 1)));
                     }
                     else
                     {
                       command = trimmed_line_to_parse;
                       argument_stream = std::make_shared<fc::stringstream>();
                     }

                     fc::buffered_istream buffered_argument_stream(argument_stream);

                     bool command_is_valid = false;
                     fc::variants arguments;
                     try
                     {
                       arguments = _self->parse_interactive_command(buffered_argument_stream, command);
                       command_is_valid = true;
                     }
                     catch( const fc::key_not_found_exception& )
                     {
                       std::cout << "Error: invalid command \"" << command << "\"\n";
                     }
                  catch( const fc::canceled_exception& except)
                  {
                    std::cout << "Command aborted.\n";
                  }
                     catch( const fc::exception& )
                     {
                       //std::cout << "Error parsing command \"" << command << "\": " << e.to_string() << "\n";
                       arguments = fc::variants { command };
                       auto usage = _rpc_server->direct_invoke_method("help", arguments).as_string();
                       std::cout << usage << "\n";
                     }

                     if (command_is_valid)
                     {
                       try
                       {
                         fc::variant result = _self->execute_interactive_command(command, arguments);
                         _self->format_and_print_result(command, result);
                       }
                       catch( const fc::canceled_exception& )
                       {
                         if( command == "quit" ) 
                           break;
                         std::cout << "Command aborted\n";
                       }
                       catch( const fc::exception& e )
                       {
                         std::cout << e.to_detail_string() << "\n";
                       }
                     }
                   }
                   line = _self->get_line( get_prompt()  );
                 } // while cin.good
                 _rpc_server->shutdown_rpc_server();
              } 
              catch ( const fc::exception& e )
              {
                 std::cout << "\nshutting down\n";
                 _rpc_server->shutdown_rpc_server();
              }
              // user has executed "quit" or sent an EOF to the CLI to make us shut down.  
              // Tell the RPC server to close, which will allow the process to exit.
              _cin_complete.cancel();
            } 

            string get_line( const string& prompt, bool no_echo )
            {
                  string line;
                  if ( no_echo )
                  {
                      // there is no need to add input to history when echo is off, so both Windows and Unix implementations are same
                      std::cout<<prompt;<commit_msg>cleanup some minor compiler warnings<commit_after>#include <bts/cli/cli.hpp>
#include <bts/rpc/rpc_server.hpp>
#include <bts/wallet/pretty.hpp>
#include <bts/wallet/wallet.hpp>

#include <fc/io/buffered_iostream.hpp>
#include <fc/io/console.hpp>
#include <fc/io/json.hpp>
#include <fc/io/sstream.hpp>
#include <fc/log/logger.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/thread/thread.hpp>
#include <fc/variant.hpp>

#include <boost/algorithm/string/trim.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iomanip>
#include <iostream>
#include <sstream>

#ifdef HAVE_READLINE
#include <readline/history.h>
#include <readline/readline.h>
#endif

namespace bts { namespace cli {

  namespace detail
  {
      class cli_impl
      {
         public:
            client_ptr                  _client;
            rpc_server_ptr              _rpc_server;
            bts::cli::cli*              _self;
//            fc::thread*                 _main_thread;
            fc::thread                  _cin_thread;
            fc::future<void>            _cin_complete;

            cli_impl( const client_ptr& client, const rpc_server_ptr& rpc_server );

            string get_prompt()const
            {
              string wallet_name =  _client->get_wallet()->get_wallet_name();
              string prompt = wallet_name;
              if( prompt == "" )
              {
                 prompt = "(wallet closed) >>> ";
              }
              else
              {
                 if( _client->get_wallet()->is_locked() )
                    prompt += " (locked) >>> ";
                 else
                    prompt += " (unlocked) >>> ";
              }
              return prompt;
            }

            void process_commands()
            { 
              try {
                 string line = _self->get_line(get_prompt());
                 while (std::cin.good())
                 {
                   string trimmed_line_to_parse(boost::algorithm::trim_copy(line));
                   if (!trimmed_line_to_parse.empty())
                   {
                     string::const_iterator iter = std::find_if(trimmed_line_to_parse.begin(), trimmed_line_to_parse.end(), ::isspace);
                     string command;
                     fc::istream_ptr argument_stream;
                     if (iter != trimmed_line_to_parse.end())
                     {
                       // then there are arguments to this function
                       size_t first_space_pos = iter - trimmed_line_to_parse.begin();
                       command = trimmed_line_to_parse.substr(0, first_space_pos);
                       argument_stream = std::make_shared<fc::stringstream>((trimmed_line_to_parse.substr(first_space_pos + 1)));
                     }
                     else
                     {
                       command = trimmed_line_to_parse;
                       argument_stream = std::make_shared<fc::stringstream>();
                     }

                     fc::buffered_istream buffered_argument_stream(argument_stream);

                     bool command_is_valid = false;
                     fc::variants arguments;
                     try
                     {
                       arguments = _self->parse_interactive_command(buffered_argument_stream, command);
                       command_is_valid = true;
                     }
                     catch( const fc::key_not_found_exception& )
                     {
                       std::cout << "Error: invalid command \"" << command << "\"\n";
                     }
                     catch( const fc::canceled_exception&)
                     {
                       std::cout << "Command aborted.\n";
                     }
                     catch( const fc::exception& )
                     {
                       //std::cout << "Error parsing command \"" << command << "\": " << e.to_string() << "\n";
                       arguments = fc::variants { command };
                       auto usage = _rpc_server->direct_invoke_method("help", arguments).as_string();
                       std::cout << usage << "\n";
                     }

                     if (command_is_valid)
                     {
                       try
                       {
                         fc::variant result = _self->execute_interactive_command(command, arguments);
                         _self->format_and_print_result(command, result);
                       }
                       catch( const fc::canceled_exception& )
                       {
                         if( command == "quit" ) 
                           break;
                         std::cout << "Command aborted\n";
                       }
                       catch( const fc::exception& e )
                       {
                         std::cout << e.to_detail_string() << "\n";
                       }
                     }
                   }
                   line = _self->get_line( get_prompt()  );
                 } // while cin.good
                 _rpc_server->shutdown_rpc_server();
              } 
              catch ( const fc::exception&)
              {
                 std::cout << "\nshutting down\n";
                 _rpc_server->shutdown_rpc_server();
              }
              // user has executed "quit" or sent an EOF to the CLI to make us shut down.  
              // Tell the RPC server to close, which will allow the process to exit.
              _cin_complete.cancel();
            } 

            string get_line( const string& prompt, bool no_echo )
            {
                  string line;
                  if ( no_echo )
                  {
                      // there is no need to add input to history when echo is off, so both Windows and Unix implementations are same
                      std::cout<<prompt;
{'fraction_non_alphanumeric': 0.098868374032162, 'fraction_numerical': 0.00034033863694375905, 'mean_word_length': 1.1750555144337527, 'pattern_counts': {'":': 2, '<': 111, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620553', 'n_tokens_mistral': 3045, 'n_tokens_neox': 2835, 'n_words': 581}