MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / get_line

Function get_line

src/Chain/libraries/cli/Cli.cpp:107–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105 FC_DECLARE_DERIVED_EXCEPTION(exit_cli_command, thinkyoung::cli::cli_exception, 11002, "exit CLI client requested by user");
106
107 string get_line(
108 std::istream* input_stream,
109 std::ostream* out,
110 const string& prompt, // = CLI_PROMPT_SUFFIX
111 bool no_echo, // = false
112 fc::thread* cin_thread, // = nullptr
113 bool saved_out, // = false
114 std::ostream* input_stream_log // = nullptr
115 )
116 {
117 if (input_stream == nullptr)
118 FC_CAPTURE_AND_THROW(thinkyoung::cli::exit_cli_command); //_input_stream != nullptr );
119
120 //FC_ASSERT( _self->is_interactive() );
121 string line;
122 if (no_echo)
123 {
124 *out << prompt;
125 // there is no need to add input to history when echo is off, so both Windows and Unix implementations are same
126 fc::set_console_echo(false);
127 sync_call(cin_thread, [&](){ std::getline(*input_stream, line); }, "getline");
128 fc::set_console_echo(true);
129 *out << std::endl;
130 }
131 else
132 {
133#ifdef HAVE_READLINE
134 if (input_stream == &std::cin)
135 {
136 char* line_read = nullptr;
137 out->flush(); //readline doesn't use cin, so we must manually flush _out
138 line_read = readline(prompt.c_str());
139 if (line_read && *line_read)
140 add_history(line_read);
141 if (line_read == nullptr)
142 FC_THROW_EXCEPTION(fc::eof_exception, "");
143 line = line_read;
144 free(line_read);
145 }
146 else
147 {
148 *out << prompt;
149 sync_call(cin_thread, [&](){ std::getline(*input_stream, line); }, "getline");
150 }
151#else
152 *out << prompt;
153 sync_call(cin_thread, [&](){ std::getline(*input_stream, line); }, "getline");
154#endif
155 if (input_stream_log != nullptr)
156 {
157 out->flush();
158 if (saved_out)
159 *input_stream_log << CLI_PROMPT_SUFFIX;
160 *input_stream_log << line << std::endl;
161 }
162 }
163
164 boost::trim(line);

Callers 5

Cli.cppFile · 0.70
prompt_for_inputFunction · 0.70
interactive_open_walletFunction · 0.70
interactive_open_sandboxFunction · 0.70
process_commandsMethod · 0.70

Calls 5

sync_callFunction · 0.85
trimFunction · 0.50
stringClass · 0.50
flushMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected