Electroneum
rdln::readline_buffer Class Reference

#include <readline_buffer.h>

Inheritance diagram for rdln::readline_buffer:
Collaboration diagram for rdln::readline_buffer:

Public Member Functions

 readline_buffer ()
 
void start ()
 
void stop ()
 
bool is_running () const
 
linestatus get_line (std::string &line) const
 
void set_prompt (const std::string &prompt)
 

Static Public Member Functions

static void add_completion (const std::string &command)
 
static const std::vector< std::string > & get_completions ()
 

Protected Member Functions

virtual int sync ()
 

Detailed Description

Definition at line 10 of file readline_buffer.h.

Constructor & Destructor Documentation

◆ readline_buffer()

rdln::readline_buffer::readline_buffer ( )

Definition at line 46 of file readline_buffer.cpp.

47 : std::stringbuf(), m_cout_buf(NULL), m_prompt_length(0)
48 {
49  current = this;
50 }

Member Function Documentation

◆ add_completion()

void rdln::readline_buffer::add_completion ( const std::string &  command)
static

Definition at line 96 of file readline_buffer.cpp.

97 {
98  if(std::find(completion_commands().begin(), completion_commands().end(), command) != completion_commands().end())
99  return;
100  completion_commands().push_back(command);
101 }
Here is the caller graph for this function:

◆ get_completions()

const std::vector< std::string > & rdln::readline_buffer::get_completions ( )
static

Definition at line 103 of file readline_buffer.cpp.

104 {
105  return completion_commands();
106 }

◆ get_line()

rdln::linestatus rdln::readline_buffer::get_line ( std::string &  line) const

Definition at line 70 of file readline_buffer.cpp.

71 {
72  boost::lock_guard<boost::mutex> lock(sync_mutex);
73  line_stat = rdln::partial;
74  rl_callback_read_char();
75  if (line_stat == rdln::full)
76  {
77  line = the_line;
78  free(the_line);
79  the_line = NULL;
80  }
81  return line_stat;
82 }

◆ is_running()

bool rdln::readline_buffer::is_running ( ) const
inline

Definition at line 16 of file readline_buffer.h.

17  {
18  return m_cout_buf != NULL;
19  }
Here is the caller graph for this function:

◆ set_prompt()

void rdln::readline_buffer::set_prompt ( const std::string &  prompt)

Definition at line 84 of file readline_buffer.cpp.

85 {
86  if(m_cout_buf == NULL)
87  return;
88  boost::lock_guard<boost::mutex> lock(sync_mutex);
89  rl_set_prompt(std::string(m_prompt_length, ' ').c_str());
90  rl_redisplay();
91  rl_set_prompt(prompt.c_str());
92  rl_redisplay();
93  m_prompt_length = prompt.size();
94 }
::std::string string
Definition: gtest-port.h:1097

◆ start()

void rdln::readline_buffer::start ( )

Definition at line 52 of file readline_buffer.cpp.

53 {
54  if(m_cout_buf != NULL)
55  return;
56  m_cout_buf = std::cout.rdbuf();
57  std::cout.rdbuf(this);
58  install_line_handler();
59 }

◆ stop()

void rdln::readline_buffer::stop ( )

Definition at line 61 of file readline_buffer.cpp.

62 {
63  if(m_cout_buf == NULL)
64  return;
65  std::cout.rdbuf(m_cout_buf);
66  m_cout_buf = NULL;
67  remove_line_handler();
68 }
Here is the caller graph for this function:

◆ sync()

int rdln::readline_buffer::sync ( )
protectedvirtual

Definition at line 108 of file readline_buffer.cpp.

109 {
110  boost::lock_guard<boost::mutex> lock(sync_mutex);
111 #if RL_READLINE_VERSION < 0x0700
112  char lbuf[2] = {0,0};
113  char *line = NULL;
114  int end = 0, point = 0;
115 #endif
116 
117  if (rl_end || (rl_prompt && *rl_prompt))
118  {
119 #if RL_READLINE_VERSION >= 0x0700
120  rl_clear_visible_line();
121 #else
122  line = rl_line_buffer;
123  end = rl_end;
124  point = rl_point;
125  rl_line_buffer = lbuf;
126  rl_end = 0;
127  rl_point = 0;
128  rl_save_prompt();
129  rl_redisplay();
130 #endif
131  }
132 
133  do
134  {
135  m_cout_buf->sputc( this->sgetc() );
136  }
137  while ( this->snextc() != EOF );
138 
139 #if RL_READLINE_VERSION < 0x0700
140  if (end || (rl_prompt && *rl_prompt))
141  {
142  rl_restore_prompt();
143  rl_line_buffer = line;
144  rl_end = end;
145  rl_point = point;
146  }
147 #endif
148  rl_on_new_line();
149  rl_redisplay();
150 
151  return 0;
152 }

The documentation for this class was generated from the following files: