27 template<
typename CommandHandler>
31 static constexpr
int BUFFER_SIZE = 1024;
33 asio::io_context& context;
35 asio::posix::stream_descriptor input_stream;
37 asio::streambuf input_buffer;
39 CommandHandler& handler;
42 void read_command_line() {
43 asio::async_read_until(input_stream, input_buffer,
'\n',
44 [&](
const std::error_code& error, std::size_t length){
46 std::cout <<
"CLI::read_command_line - " << error << std::endl;
50 auto data = asio::buffers_begin(input_buffer.data());
52 handler.parse(std::string(data, data + length));
54 input_buffer.consume(length);
67 CLI(asio::io_context& context_, CommandHandler& handler_) :
69 input_stream(context, ::dup(STDIN_FILENO)),
70 input_buffer(BUFFER_SIZE),
71 handler(handler_) { read_command_line(); }