2926
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2926
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_cmd_edit_h) |
|
25 #define octave_cmd_edit_h 1 |
|
26 |
|
27 #include <cstdio> |
|
28 |
6913
|
29 #include <set> |
2926
|
30 #include <string> |
|
31 |
4604
|
32 #include "str-vec.h" |
|
33 |
2926
|
34 class |
6108
|
35 OCTAVE_API |
2926
|
36 command_editor |
|
37 { |
|
38 protected: |
|
39 |
|
40 command_editor (void) |
|
41 : command_number (0) { } |
|
42 |
|
43 public: |
|
44 |
4802
|
45 typedef int (*startup_hook_fcn) (void); |
3519
|
46 |
4802
|
47 typedef int (*event_hook_fcn) (void); |
2926
|
48 |
3504
|
49 typedef std::string (*completion_fcn) (const std::string&, int); |
2941
|
50 |
2926
|
51 virtual ~command_editor (void) { } |
|
52 |
3504
|
53 static void set_name (const std::string& n); |
2926
|
54 |
3504
|
55 static std::string readline (const std::string& prompt); |
2926
|
56 |
3504
|
57 static std::string readline (const std::string& prompt, bool& eof); |
3219
|
58 |
2926
|
59 static void set_input_stream (FILE *f); |
|
60 |
|
61 static FILE *get_input_stream (void); |
|
62 |
|
63 static void set_output_stream (FILE *f); |
|
64 |
|
65 static FILE *get_output_stream (void); |
|
66 |
|
67 static int terminal_rows (void); |
|
68 |
|
69 static int terminal_cols (void); |
|
70 |
|
71 static void clear_screen (void); |
|
72 |
3281
|
73 static void resize_terminal (void); |
|
74 |
3504
|
75 static std::string decode_prompt_string (const std::string& s); |
2926
|
76 |
|
77 static void restore_terminal_state (void); |
|
78 |
|
79 static void blink_matching_paren (bool flag); |
|
80 |
4055
|
81 static void set_basic_word_break_characters (const std::string& s); |
3933
|
82 |
4055
|
83 static void set_completer_word_break_characters (const std::string& s); |
3933
|
84 |
3504
|
85 static void set_basic_quote_characters (const std::string& s); |
2926
|
86 |
|
87 static void set_completion_append_character (char c); |
|
88 |
2941
|
89 static void set_completion_function (completion_fcn f); |
|
90 |
|
91 static completion_fcn get_completion_function (void); |
2926
|
92 |
4604
|
93 static string_vector generate_filename_completions (const std::string& text); |
|
94 |
3504
|
95 static void insert_text (const std::string& text); |
2926
|
96 |
|
97 static void newline (void); |
|
98 |
|
99 static void clear_undo_list (void); |
|
100 |
6913
|
101 static void add_startup_hook (startup_hook_fcn f); |
2926
|
102 |
6913
|
103 static void remove_startup_hook (startup_hook_fcn f); |
2926
|
104 |
6913
|
105 static void add_event_hook (event_hook_fcn f); |
3215
|
106 |
6913
|
107 static void remove_event_hook (event_hook_fcn f); |
3215
|
108 |
3504
|
109 static void read_init_file (const std::string& file = std::string ()); |
3189
|
110 |
4143
|
111 static bool filename_completion_desired (bool); |
|
112 |
2926
|
113 static int current_command_number (void); |
|
114 |
|
115 static void reset_current_command_number (int n); |
|
116 |
2967
|
117 static void increment_current_command_number (void); |
|
118 |
2926
|
119 private: |
|
120 |
|
121 // No copying! |
|
122 |
|
123 command_editor (const command_editor&); |
|
124 |
|
125 command_editor& operator = (const command_editor&); |
|
126 |
|
127 static bool instance_ok (void); |
|
128 |
|
129 static void make_command_editor (void); |
|
130 |
6913
|
131 static int startup_handler (void); |
|
132 |
|
133 static int event_handler (void); |
|
134 |
|
135 static std::set<startup_hook_fcn> startup_hook_set; |
|
136 |
|
137 static std::set<event_hook_fcn> event_hook_set; |
|
138 |
|
139 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator; |
|
140 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator; |
|
141 |
|
142 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator; |
|
143 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator; |
|
144 |
2926
|
145 // The real thing. |
|
146 static command_editor *instance; |
|
147 |
|
148 protected: |
|
149 |
|
150 // To use something other than the GNU readline library, derive a new |
|
151 // class from command_editor, overload these functions as |
|
152 // necessary, and make instance point to the new class. |
|
153 |
3504
|
154 virtual void do_set_name (const std::string&) { } |
2926
|
155 |
3504
|
156 std::string do_readline (const std::string& prompt) |
3219
|
157 { |
|
158 bool eof; |
|
159 |
|
160 return do_readline (prompt, eof); |
|
161 } |
|
162 |
3504
|
163 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926
|
164 |
|
165 virtual void do_set_input_stream (FILE *) = 0; |
|
166 |
|
167 virtual FILE *do_get_input_stream (void) = 0; |
|
168 |
|
169 virtual void do_set_output_stream (FILE *) = 0; |
|
170 |
|
171 virtual FILE *do_get_output_stream (void) = 0; |
|
172 |
|
173 virtual int do_terminal_rows (void) { return 24; } |
|
174 |
|
175 virtual int do_terminal_cols (void) { return 80; } |
|
176 |
|
177 virtual void do_clear_screen (void) { } |
|
178 |
3281
|
179 virtual void do_resize_terminal (void) { } |
|
180 |
3504
|
181 virtual std::string do_decode_prompt_string (const std::string&); |
2926
|
182 |
3504
|
183 virtual std::string newline_chars (void) { return "\n"; } |
2926
|
184 |
|
185 virtual void do_restore_terminal_state (void) { } |
|
186 |
|
187 virtual void do_blink_matching_paren (bool) { } |
|
188 |
3933
|
189 virtual void do_set_basic_word_break_characters (const std::string&) { } |
|
190 |
|
191 virtual void do_set_completer_word_break_characters (const std::string&) { } |
|
192 |
3504
|
193 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926
|
194 |
|
195 virtual void do_set_completion_append_character (char) { } |
|
196 |
2941
|
197 virtual void do_set_completion_function (completion_fcn) { } |
|
198 |
|
199 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926
|
200 |
4604
|
201 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
|
202 |
3504
|
203 virtual void do_insert_text (const std::string&) = 0; |
2926
|
204 |
|
205 virtual void do_newline (void) = 0; |
|
206 |
|
207 virtual void do_clear_undo_list (void) { } |
|
208 |
6913
|
209 virtual void set_startup_hook (startup_hook_fcn) { } |
2926
|
210 |
6913
|
211 virtual void restore_startup_hook (void) { } |
2926
|
212 |
6913
|
213 virtual void set_event_hook (startup_hook_fcn) { } |
3215
|
214 |
6913
|
215 virtual void restore_event_hook (void) { } |
3215
|
216 |
3504
|
217 virtual void do_read_init_file (const std::string&) { } |
3189
|
218 |
4143
|
219 virtual bool do_filename_completion_desired (bool) { return false; } |
|
220 |
3504
|
221 int read_octal (const std::string& s); |
2926
|
222 |
|
223 void error (int); |
|
224 |
3504
|
225 void error (const std::string&); |
2926
|
226 |
|
227 // The current command number. |
|
228 int command_number; |
|
229 }; |
|
230 |
|
231 #endif |
|
232 |
|
233 /* |
|
234 ;;; Local Variables: *** |
|
235 ;;; mode: C++ *** |
|
236 ;;; End: *** |
|
237 */ |