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