2017-05-29 16:39:49 -06:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <streambuf>
|
|
|
|
#include <sstream>
|
2017-07-07 13:40:32 -06:00
|
|
|
#include <vector>
|
2017-05-29 16:39:49 -06:00
|
|
|
|
|
|
|
namespace rdln
|
|
|
|
{
|
2017-08-21 05:55:06 -06:00
|
|
|
typedef enum { empty, partial, full } linestatus;
|
2017-05-29 16:39:49 -06:00
|
|
|
class readline_buffer : public std::stringbuf
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
readline_buffer();
|
|
|
|
void start();
|
|
|
|
void stop();
|
2017-06-21 10:33:30 -06:00
|
|
|
bool is_running() const
|
2017-05-29 16:39:49 -06:00
|
|
|
{
|
|
|
|
return m_cout_buf != NULL;
|
|
|
|
}
|
2017-08-21 05:55:06 -06:00
|
|
|
linestatus get_line(std::string& line) const;
|
2017-05-29 16:39:49 -06:00
|
|
|
void set_prompt(const std::string& prompt);
|
2017-08-16 07:34:32 -06:00
|
|
|
static void add_completion(const std::string& command);
|
|
|
|
static const std::vector<std::string>& get_completions();
|
2017-05-29 16:39:49 -06:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int sync();
|
2017-08-21 05:55:06 -06:00
|
|
|
|
2017-05-29 16:39:49 -06:00
|
|
|
private:
|
|
|
|
std::streambuf* m_cout_buf;
|
2018-10-12 15:02:59 -06:00
|
|
|
size_t m_prompt_length;
|
2017-08-16 07:34:32 -06:00
|
|
|
static std::vector<std::string>& completion_commands();
|
2017-05-29 16:39:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class suspend_readline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
suspend_readline();
|
|
|
|
~suspend_readline();
|
|
|
|
private:
|
|
|
|
readline_buffer* m_buffer;
|
|
|
|
bool m_restart;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|