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