]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Host/Editline.h
Import LLDB as of upstream SVN r216948 (git 50f7fe44)
[FreeBSD/FreeBSD.git] / include / lldb / Host / Editline.h
1 //===-- Editline.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Editline_h_
11 #define liblldb_Editline_h_
12 #if defined(__cplusplus)
13
14 #include "lldb/lldb-private.h"
15
16 #include <stdio.h>
17 #ifdef _WIN32
18 #include "lldb/Host/windows/editlinewin.h"
19 #else
20 #include <histedit.h>
21 #endif
22
23 #include <string>
24 #include <vector>
25
26 #include "lldb/Core/ConnectionFileDescriptor.h"
27 #include "lldb/Host/Condition.h"
28 #include "lldb/Host/FileSpec.h"
29 #include "lldb/Host/Mutex.h"
30 #include "lldb/Host/Predicate.h"
31
32 namespace lldb_private {
33
34 //----------------------------------------------------------------------
35 /// @class Editline Editline.h "lldb/Host/Editline.h"
36 /// @brief A class that encapsulates editline functionality.
37 //----------------------------------------------------------------------
38 class EditlineHistory;
39     
40 typedef std::shared_ptr<EditlineHistory> EditlineHistorySP;
41     
42 class Editline
43 {
44 public:
45     typedef LineStatus (*LineCompletedCallbackType) (
46         Editline *editline,
47         StringList &lines,
48         uint32_t line_idx,
49         Error &error,
50         void *baton);
51     
52     typedef int (*CompleteCallbackType) (
53         const char *current_line,
54         const char *cursor,
55         const char *last_char,
56         int skip_first_n_matches,
57         int max_matches,
58         StringList &matches,
59         void *baton);
60
61     typedef int (*GetCharCallbackType) (
62         ::EditLine *,
63         char *c);
64     
65     Editline(const char *prog,  // Used for the history file and for editrc program name
66              const char *prompt,
67              bool configure_for_multiline,             
68              FILE *fin,
69              FILE *fout,
70              FILE *ferr);
71
72     ~Editline();
73
74     Error
75     GetLine (std::string &line,
76              bool &interrupted);
77
78     Error
79     GetLines (const std::string &end_line,
80               StringList &lines,
81               bool &interrupted);
82
83     bool
84     LoadHistory ();
85     
86     bool
87     SaveHistory ();
88     
89     FILE *
90     GetInputFile ();
91     
92     FILE *
93     GetOutputFile ();
94     
95     FILE *
96     GetErrorFile ();
97
98     bool
99     GettingLine () const
100     {
101         return m_getting_line;
102     }
103
104     void
105     Hide ();
106
107     void
108     Refresh();
109
110     bool
111     Interrupt ();
112
113     void
114     SetAutoCompleteCallback (CompleteCallbackType callback,
115                              void *baton)
116     {
117         m_completion_callback = callback;
118         m_completion_callback_baton = baton;
119     }
120
121     void
122     SetLineCompleteCallback (LineCompletedCallbackType callback,
123                              void *baton)
124     {
125         m_line_complete_callback = callback;
126         m_line_complete_callback_baton = baton;
127     }
128
129     size_t
130     Push (const char *bytes, size_t len);
131     
132     static int
133     GetCharFromInputFileCallback (::EditLine *e, char *c);
134
135     void
136     SetGetCharCallback (GetCharCallbackType callback);
137     
138     const char *
139     GetPrompt();
140     
141     void
142     SetPrompt (const char *p);
143     
144     void
145     ShowLineNumbers (bool enable, uint32_t line_offset)
146     {
147         m_prompt_with_line_numbers = enable;
148         m_line_offset = line_offset;
149     }
150     
151 private:
152
153     Error
154     PrivateGetLine(std::string &line);
155     
156     unsigned char
157     HandleCompletion (int ch);
158
159     static unsigned char
160     CallbackEditPrevLine (::EditLine *e, int ch);
161     
162     static unsigned char
163     CallbackEditNextLine (::EditLine *e, int ch);
164     
165     static unsigned char
166     CallbackComplete (::EditLine *e, int ch);
167
168     static const char *
169     GetPromptCallback (::EditLine *e);
170
171     static Editline *
172     GetClientData (::EditLine *e);
173     
174     static FILE *
175     GetFilePointer (::EditLine *e, int fd);
176
177     enum class Command
178     {
179         None = 0,
180         EditPrevLine,
181         EditNextLine,
182     };
183     ::EditLine *m_editline;
184     EditlineHistorySP m_history_sp;
185     std::string m_prompt;
186     std::string m_lines_prompt;
187     lldb_private::Predicate<bool> m_getting_char;
188     CompleteCallbackType m_completion_callback;
189     void *m_completion_callback_baton;
190     LineCompletedCallbackType m_line_complete_callback;
191     void *m_line_complete_callback_baton;
192     Command m_lines_command;
193     uint32_t m_line_offset;
194     uint32_t m_lines_curr_line;
195     uint32_t m_lines_max_line;
196     ConnectionFileDescriptor m_file;
197     bool m_prompt_with_line_numbers;
198     bool m_getting_line;
199     bool m_got_eof;    // Set to true when we detect EOF
200     bool m_interrupted;
201     
202     DISALLOW_COPY_AND_ASSIGN(Editline);
203 };
204
205 } // namespace lldb_private
206
207 #endif  // #if defined(__cplusplus)
208 #endif  // liblldb_Host_h_