Mercurial > hg > octave-lyh
annotate liboctave/cmd-edit.h @ 14685:4460c4fb20e6 stable rc-3-6-2-2
3.6.2-rc2 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc2.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 May 2012 15:35:50 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2926 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2926 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2926 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_cmd_edit_h) | |
24 #define octave_cmd_edit_h 1 | |
25 | |
26 #include <cstdio> | |
27 | |
6913 | 28 #include <set> |
2926 | 29 #include <string> |
30 | |
4604 | 31 #include "str-vec.h" |
32 | |
2926 | 33 class |
6108 | 34 OCTAVE_API |
2926 | 35 command_editor |
36 { | |
37 protected: | |
38 | |
39 command_editor (void) | |
40 : command_number (0) { } | |
41 | |
42 public: | |
43 | |
4802 | 44 typedef int (*startup_hook_fcn) (void); |
3519 | 45 |
4802 | 46 typedef int (*event_hook_fcn) (void); |
2926 | 47 |
3504 | 48 typedef std::string (*completion_fcn) (const std::string&, int); |
2941 | 49 |
6979 | 50 typedef std::string (*quoting_fcn) (const std::string&, int, char); |
51 | |
52 typedef std::string (*dequoting_fcn) (const std::string&, int); | |
53 | |
54 typedef int (*char_is_quoted_fcn) (const std::string&, int); | |
55 | |
56 typedef void (*user_accept_line_fcn) (const std::string&); | |
57 | |
2926 | 58 virtual ~command_editor (void) { } |
59 | |
3504 | 60 static void set_name (const std::string& n); |
2926 | 61 |
3504 | 62 static std::string readline (const std::string& prompt); |
2926 | 63 |
3504 | 64 static std::string readline (const std::string& prompt, bool& eof); |
3219 | 65 |
2926 | 66 static void set_input_stream (FILE *f); |
67 | |
68 static FILE *get_input_stream (void); | |
69 | |
70 static void set_output_stream (FILE *f); | |
71 | |
72 static FILE *get_output_stream (void); | |
73 | |
74 static int terminal_rows (void); | |
75 | |
76 static int terminal_cols (void); | |
77 | |
78 static void clear_screen (void); | |
79 | |
3281 | 80 static void resize_terminal (void); |
81 | |
3504 | 82 static std::string decode_prompt_string (const std::string& s); |
2926 | 83 |
84 static void restore_terminal_state (void); | |
85 | |
86 static void blink_matching_paren (bool flag); | |
87 | |
4055 | 88 static void set_basic_word_break_characters (const std::string& s); |
3933 | 89 |
4055 | 90 static void set_completer_word_break_characters (const std::string& s); |
3933 | 91 |
3504 | 92 static void set_basic_quote_characters (const std::string& s); |
2926 | 93 |
6979 | 94 static void set_filename_quote_characters (const std::string& s); |
95 | |
96 static void set_completer_quote_characters (const std::string& s); | |
97 | |
2926 | 98 static void set_completion_append_character (char c); |
99 | |
2941 | 100 static void set_completion_function (completion_fcn f); |
101 | |
6979 | 102 static void set_quoting_function (quoting_fcn f); |
103 | |
104 static void set_dequoting_function (dequoting_fcn f); | |
105 | |
106 static void set_char_is_quoted_function (char_is_quoted_fcn f); | |
107 | |
108 static void set_user_accept_line_function (user_accept_line_fcn f); | |
109 | |
2941 | 110 static completion_fcn get_completion_function (void); |
2926 | 111 |
6979 | 112 static quoting_fcn get_quoting_function (void); |
113 | |
114 static dequoting_fcn get_dequoting_function (void); | |
115 | |
116 static char_is_quoted_fcn get_char_is_quoted_function (void); | |
117 | |
118 static user_accept_line_fcn get_user_accept_line_function (void); | |
119 | |
4604 | 120 static string_vector generate_filename_completions (const std::string& text); |
121 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
122 static std::string get_line_buffer (void); |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
123 |
3504 | 124 static void insert_text (const std::string& text); |
2926 | 125 |
126 static void newline (void); | |
127 | |
6979 | 128 static void accept_line (void); |
129 | |
2926 | 130 static void clear_undo_list (void); |
131 | |
6913 | 132 static void add_startup_hook (startup_hook_fcn f); |
2926 | 133 |
6913 | 134 static void remove_startup_hook (startup_hook_fcn f); |
2926 | 135 |
6913 | 136 static void add_event_hook (event_hook_fcn f); |
3215 | 137 |
6913 | 138 static void remove_event_hook (event_hook_fcn f); |
3215 | 139 |
13924
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
140 static void run_event_hooks (void); |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
141 |
3504 | 142 static void read_init_file (const std::string& file = std::string ()); |
3189 | 143 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
144 static void re_read_init_file (void); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
145 |
4143 | 146 static bool filename_completion_desired (bool); |
147 | |
6979 | 148 static bool filename_quoting_desired (bool); |
149 | |
2926 | 150 static int current_command_number (void); |
151 | |
152 static void reset_current_command_number (int n); | |
153 | |
2967 | 154 static void increment_current_command_number (void); |
155 | |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
156 static void force_default_editor (void); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
157 |
2926 | 158 private: |
159 | |
160 // No copying! | |
161 | |
162 command_editor (const command_editor&); | |
163 | |
164 command_editor& operator = (const command_editor&); | |
165 | |
166 static bool instance_ok (void); | |
167 | |
168 static void make_command_editor (void); | |
169 | |
6913 | 170 static int startup_handler (void); |
171 | |
172 static int event_handler (void); | |
173 | |
174 static std::set<startup_hook_fcn> startup_hook_set; | |
175 | |
176 static std::set<event_hook_fcn> event_hook_set; | |
177 | |
178 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator; | |
179 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator; | |
180 | |
181 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator; | |
182 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator; | |
183 | |
2926 | 184 // The real thing. |
185 static command_editor *instance; | |
186 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
187 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
188 |
2926 | 189 protected: |
190 | |
191 // To use something other than the GNU readline library, derive a new | |
192 // class from command_editor, overload these functions as | |
193 // necessary, and make instance point to the new class. | |
194 | |
3504 | 195 virtual void do_set_name (const std::string&) { } |
2926 | 196 |
3504 | 197 std::string do_readline (const std::string& prompt) |
3219 | 198 { |
199 bool eof; | |
200 | |
201 return do_readline (prompt, eof); | |
202 } | |
203 | |
3504 | 204 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926 | 205 |
206 virtual void do_set_input_stream (FILE *) = 0; | |
207 | |
208 virtual FILE *do_get_input_stream (void) = 0; | |
209 | |
210 virtual void do_set_output_stream (FILE *) = 0; | |
211 | |
212 virtual FILE *do_get_output_stream (void) = 0; | |
213 | |
214 virtual int do_terminal_rows (void) { return 24; } | |
215 | |
216 virtual int do_terminal_cols (void) { return 80; } | |
217 | |
218 virtual void do_clear_screen (void) { } | |
219 | |
3281 | 220 virtual void do_resize_terminal (void) { } |
221 | |
3504 | 222 virtual std::string do_decode_prompt_string (const std::string&); |
2926 | 223 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 virtual std::string newline_chars (void) { return "\n"; } |
2926 | 225 |
226 virtual void do_restore_terminal_state (void) { } | |
227 | |
228 virtual void do_blink_matching_paren (bool) { } | |
229 | |
3933 | 230 virtual void do_set_basic_word_break_characters (const std::string&) { } |
231 | |
232 virtual void do_set_completer_word_break_characters (const std::string&) { } | |
233 | |
3504 | 234 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926 | 235 |
6979 | 236 virtual void do_set_filename_quote_characters (const std::string&) { } |
237 | |
238 virtual void do_set_completer_quote_characters (const std::string&) { } | |
239 | |
2926 | 240 virtual void do_set_completion_append_character (char) { } |
241 | |
2941 | 242 virtual void do_set_completion_function (completion_fcn) { } |
243 | |
6979 | 244 virtual void do_set_quoting_function (quoting_fcn) { } |
245 | |
246 virtual void do_set_dequoting_function (dequoting_fcn) { } | |
247 | |
248 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { } | |
249 | |
250 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { } | |
251 | |
2941 | 252 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926 | 253 |
6979 | 254 virtual quoting_fcn do_get_quoting_function (void) const { return 0; } |
255 | |
256 virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; } | |
257 | |
258 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { return 0; } | |
259 | |
260 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const { return 0; } | |
261 | |
4604 | 262 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
263 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
264 virtual std::string do_get_line_buffer (void) const = 0; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
265 |
3504 | 266 virtual void do_insert_text (const std::string&) = 0; |
2926 | 267 |
268 virtual void do_newline (void) = 0; | |
269 | |
6979 | 270 virtual void do_accept_line (void) = 0; |
271 | |
2926 | 272 virtual void do_clear_undo_list (void) { } |
273 | |
6913 | 274 virtual void set_startup_hook (startup_hook_fcn) { } |
2926 | 275 |
6913 | 276 virtual void restore_startup_hook (void) { } |
2926 | 277 |
6913 | 278 virtual void set_event_hook (startup_hook_fcn) { } |
3215 | 279 |
6913 | 280 virtual void restore_event_hook (void) { } |
3215 | 281 |
3504 | 282 virtual void do_read_init_file (const std::string&) { } |
3189 | 283 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
284 virtual void do_re_read_init_file (void) { } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
285 |
4143 | 286 virtual bool do_filename_completion_desired (bool) { return false; } |
287 | |
6979 | 288 virtual bool do_filename_quoting_desired (bool) { return false; } |
289 | |
3504 | 290 int read_octal (const std::string& s); |
2926 | 291 |
292 void error (int); | |
293 | |
3504 | 294 void error (const std::string&); |
2926 | 295 |
296 // The current command number. | |
297 int command_number; | |
298 }; | |
299 | |
300 #endif |