1 //===-- Editline.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Editline_h_
11 #define liblldb_Editline_h_
12 #if defined(__cplusplus)
14 #include "lldb/lldb-private.h"
18 #include "lldb/Host/windows/editlinewin.h"
26 #include "lldb/Host/Condition.h"
27 #include "lldb/Host/FileSpec.h"
28 #include "lldb/Host/Mutex.h"
30 namespace lldb_private {
32 //----------------------------------------------------------------------
33 /// @class Editline Editline.h "lldb/Host/Editline.h"
34 /// @brief A class that encapsulates editline functionality.
35 //----------------------------------------------------------------------
39 typedef LineStatus (*LineCompletedCallbackType) (
46 typedef int (*CompleteCallbackType) (
47 const char *current_line,
49 const char *last_char,
50 int skip_first_n_matches,
55 typedef int (*GetCharCallbackType) (
59 Editline(const char *prog, // Used for the history file and for editrc program name
68 GetLine (std::string &line);
71 GetLines (const std::string &end_line, StringList &lines);
91 return m_getting_line;
104 SetAutoCompleteCallback (CompleteCallbackType callback,
107 m_completion_callback = callback;
108 m_completion_callback_baton = baton;
112 SetLineCompleteCallback (LineCompletedCallbackType callback,
115 m_line_complete_callback = callback;
116 m_line_complete_callback_baton = baton;
120 Push (const char *bytes, size_t len);
122 // Cache bytes and use them for input without using a FILE. Calling this function
123 // will set the getc callback in the editline
125 SetInputBuffer (const char *c, size_t len);
128 GetCharFromInputFileCallback (::EditLine *e, char *c);
131 SetGetCharCallback (GetCharCallbackType callback);
137 SetPrompt (const char *p);
142 PrivateGetLine(std::string &line);
148 HandleCompletion (int ch);
155 CallbackEditPrevLine (::EditLine *e, int ch);
158 CallbackEditNextLine (::EditLine *e, int ch);
161 CallbackComplete (::EditLine *e, int ch);
164 GetPromptCallback (::EditLine *e);
167 GetClientData (::EditLine *e);
170 GetFilePointer (::EditLine *e, int fd);
173 GetCharInputBufferCallback (::EditLine *e, char *c);
181 ::EditLine *m_editline;
182 ::History *m_history;
183 ::HistEvent m_history_event;
184 std::string m_program;
185 std::string m_prompt;
186 std::string m_lines_prompt;
187 std::string m_getc_buffer;
189 Condition m_getc_cond;
190 CompleteCallbackType m_completion_callback;
191 void *m_completion_callback_baton;
192 // Mutex m_gets_mutex; // Make sure only one thread
193 LineCompletedCallbackType m_line_complete_callback;
194 void *m_line_complete_callback_baton;
195 Command m_lines_command;
196 uint32_t m_lines_curr_line;
197 uint32_t m_lines_max_line;
198 bool m_prompt_with_line_numbers;
200 bool m_got_eof; // Set to true when we detect EOF
203 DISALLOW_COPY_AND_ASSIGN(Editline);
206 } // namespace lldb_private
208 #endif // #if defined(__cplusplus)
209 #endif // liblldb_Host_h_