Mercurial > octave
annotate liboctave/util/cmd-edit.cc @ 19304:ad93e9be78ee gui-release
command_editor: provide access to rl_prefer_env_winsize
* cmd-edit.h, cmd-edit.cc (command_editor::prefer_env_winsize,
command_editor::do_prefer_env_winsize,
gnu_readline::do_prefer_env_winsize): New functions.
* oct-rl-edit.h, oct-rl-edit.c (octave_rl_prefer_env_winsize): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Sep 2014 16:36:41 -0400 |
parents | 37159a873c96 |
children | 735bc47d18af |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17644
diff
changeset
|
3 Copyright (C) 1996-2013 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 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
27 #include <cstdlib> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstring> |
2926 | 29 |
30 #include <string> | |
31 | |
32 #include <sys/types.h> | |
33 #include <unistd.h> | |
34 | |
5247 | 35 #include "quit.h" |
36 | |
2926 | 37 #include "cmd-edit.h" |
38 #include "cmd-hist.h" | |
5872 | 39 #include "file-ops.h" |
2926 | 40 #include "lo-error.h" |
41 #include "lo-utils.h" | |
42 #include "oct-env.h" | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
43 #include "oct-mutex.h" |
3260 | 44 #include "oct-time.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
45 #include "singleton-cleanup.h" |
2926 | 46 |
47 command_editor *command_editor::instance = 0; | |
48 | |
6913 | 49 std::set<command_editor::startup_hook_fcn> command_editor::startup_hook_set; |
50 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
51 std::set<command_editor::pre_input_hook_fcn> command_editor::pre_input_hook_set; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
52 |
6913 | 53 std::set<command_editor::event_hook_fcn> command_editor::event_hook_set; |
54 | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
55 static octave_mutex event_hook_lock; |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
56 |
2926 | 57 #if defined (USE_READLINE) |
58 | |
59 #include <cstdio> | |
60 #include <cstdlib> | |
61 | |
3519 | 62 #include "oct-rl-edit.h" |
2926 | 63 |
64 class | |
65 gnu_readline : public command_editor | |
66 { | |
67 public: | |
68 | |
3519 | 69 typedef command_editor::startup_hook_fcn startup_hook_fcn; |
70 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
71 typedef command_editor::pre_input_hook_fcn pre_input_hook_fcn; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
72 |
6913 | 73 typedef command_editor::event_hook_fcn event_hook_fcn; |
2926 | 74 |
2941 | 75 typedef command_editor::completion_fcn completion_fcn; |
76 | |
2926 | 77 gnu_readline (void); |
78 | |
79 ~gnu_readline (void) { } | |
80 | |
3504 | 81 void do_set_name (const std::string& n); |
2926 | 82 |
3504 | 83 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 84 |
85 void do_set_input_stream (FILE *f); | |
86 | |
87 FILE *do_get_input_stream (void); | |
88 | |
89 void do_set_output_stream (FILE *f); | |
90 | |
91 FILE *do_get_output_stream (void); | |
92 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
93 void do_redisplay (void); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
94 |
2926 | 95 int do_terminal_rows (void); |
96 | |
97 int do_terminal_cols (void); | |
98 | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
99 void do_clear_screen (bool skip_redisplay); |
2926 | 100 |
3281 | 101 void do_resize_terminal (void); |
102 | |
3504 | 103 std::string newline_chars (void); |
2926 | 104 |
105 void do_restore_terminal_state (void); | |
106 | |
107 void do_blink_matching_paren (bool flag); | |
108 | |
3933 | 109 void do_set_basic_word_break_characters (const std::string& s); |
110 | |
111 void do_set_completer_word_break_characters (const std::string& s); | |
112 | |
3504 | 113 void do_set_basic_quote_characters (const std::string& s); |
2926 | 114 |
6979 | 115 void do_set_filename_quote_characters (const std::string& s); |
116 | |
117 void do_set_completer_quote_characters (const std::string& s); | |
118 | |
2926 | 119 void do_set_completion_append_character (char c); |
120 | |
2941 | 121 void do_set_completion_function (completion_fcn f); |
122 | |
6979 | 123 void do_set_quoting_function (quoting_fcn f); |
124 | |
125 void do_set_dequoting_function (dequoting_fcn f); | |
126 | |
127 void do_set_char_is_quoted_function (char_is_quoted_fcn f); | |
128 | |
129 void do_set_user_accept_line_function (user_accept_line_fcn f); | |
130 | |
2941 | 131 completion_fcn do_get_completion_function (void) const; |
2926 | 132 |
6979 | 133 quoting_fcn do_get_quoting_function (void) const; |
134 | |
135 dequoting_fcn do_get_dequoting_function (void) const; | |
136 | |
137 char_is_quoted_fcn do_get_char_is_quoted_function (void) const; | |
138 | |
139 user_accept_line_fcn do_get_user_accept_line_function (void) const; | |
140 | |
4604 | 141 string_vector |
142 do_generate_filename_completions (const std::string& text); | |
143 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
144 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
145 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
146 std::string do_get_current_line (void) const; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
147 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
148 void do_replace_line (const std::string& text, bool clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
149 |
3504 | 150 void do_insert_text (const std::string& text); |
2926 | 151 |
152 void do_newline (void); | |
153 | |
6979 | 154 void do_accept_line (void); |
155 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
156 bool do_undo (void); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
157 |
2926 | 158 void do_clear_undo_list (void); |
159 | |
6913 | 160 void set_startup_hook (startup_hook_fcn f); |
161 | |
162 void restore_startup_hook (void); | |
2926 | 163 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
164 void set_pre_input_hook (pre_input_hook_fcn f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
165 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
166 void restore_pre_input_hook (void); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
167 |
6913 | 168 void set_event_hook (event_hook_fcn f); |
2926 | 169 |
6913 | 170 void restore_event_hook (void); |
3215 | 171 |
172 void do_restore_event_hook (void); | |
173 | |
3504 | 174 void do_read_init_file (const std::string& file); |
3189 | 175 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
176 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
|
177 |
4143 | 178 bool do_filename_completion_desired (bool); |
179 | |
6979 | 180 bool do_filename_quoting_desired (bool); |
181 | |
19304
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
182 bool do_prefer_env_winsize (bool); |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
183 |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
184 void do_interrupt (bool); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
185 |
3519 | 186 static int operate_and_get_next (int, int); |
2926 | 187 |
3951 | 188 static int history_search_backward (int, int); |
189 | |
190 static int history_search_forward (int, int); | |
191 | |
2926 | 192 private: |
193 | |
3519 | 194 startup_hook_fcn previous_startup_hook; |
2926 | 195 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
196 pre_input_hook_fcn previous_pre_input_hook; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
197 |
3519 | 198 event_hook_fcn previous_event_hook; |
3215 | 199 |
2941 | 200 completion_fcn completion_function; |
201 | |
6979 | 202 quoting_fcn quoting_function; |
203 | |
204 dequoting_fcn dequoting_function; | |
205 | |
206 char_is_quoted_fcn char_is_quoted_function; | |
207 | |
208 user_accept_line_fcn user_accept_line_function; | |
209 | |
2941 | 210 static char *command_generator (const char *text, int state); |
211 | |
6979 | 212 static char *command_quoter (char *text, int match_type, char *quote_pointer); |
213 static char *command_dequoter (char *text, int match_type); | |
214 | |
215 static int command_char_is_quoted (char *text, int index); | |
216 | |
217 static int command_accept_line (int count, int key); | |
218 | |
3519 | 219 static char **command_completer (const char *text, int start, int end); |
2926 | 220 }; |
221 | |
222 gnu_readline::gnu_readline () | |
3215 | 223 : command_editor (), previous_startup_hook (0), |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
224 previous_pre_input_hook (0), |
6979 | 225 previous_event_hook (0), completion_function (0), |
226 quoting_function (0), dequoting_function (0), | |
227 char_is_quoted_function (0), user_accept_line_function (0) | |
2926 | 228 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
229 // FIXME: need interface to rl_add_defun, rl_initialize, and |
3519 | 230 // a function to set rl_terminal_name |
3225 | 231 |
3520 | 232 std::string term = octave_env::getenv ("TERM"); |
3519 | 233 |
234 octave_rl_set_terminal_name (term.c_str ()); | |
235 | |
236 octave_rl_initialize (); | |
2926 | 237 |
238 do_blink_matching_paren (true); | |
239 | |
5452 | 240 // Bind operate-and-get-next. |
2926 | 241 |
3519 | 242 octave_rl_add_defun ("operate-and-get-next", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
243 gnu_readline::operate_and_get_next, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
244 octave_rl_ctrl ('O')); |
2926 | 245 |
5452 | 246 // And the history search functions. |
2926 | 247 |
3519 | 248 octave_rl_add_defun ("history-search-backward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
249 gnu_readline::history_search_backward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
250 octave_rl_meta ('P')); |
2926 | 251 |
3519 | 252 octave_rl_add_defun ("history-search-forward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
253 gnu_readline::history_search_forward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
254 octave_rl_meta ('N')); |
2926 | 255 } |
256 | |
257 void | |
3519 | 258 gnu_readline::do_set_name (const std::string& nm) |
2926 | 259 { |
3519 | 260 ::octave_rl_set_name (nm.c_str ()); |
2926 | 261 } |
262 | |
3504 | 263 std::string |
264 gnu_readline::do_readline (const std::string& prompt, bool& eof) | |
2926 | 265 { |
3504 | 266 std::string retval; |
2926 | 267 |
3219 | 268 eof = false; |
269 | |
5247 | 270 char *line = 0; |
271 | |
5336 | 272 const char *p = prompt.c_str (); |
273 | |
5452 | 274 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5247 | 275 |
5336 | 276 line = ::octave_rl_readline (p); |
5247 | 277 |
5452 | 278 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
2926 | 279 |
280 if (line) | |
281 { | |
282 retval = line; | |
283 | |
284 free (line); | |
285 } | |
3219 | 286 else |
287 eof = true; | |
2926 | 288 |
289 return retval; | |
290 } | |
291 | |
292 void | |
293 gnu_readline::do_set_input_stream (FILE *f) | |
294 { | |
3519 | 295 ::octave_rl_set_input_stream (f); |
2926 | 296 } |
297 | |
298 FILE * | |
299 gnu_readline::do_get_input_stream (void) | |
300 { | |
3519 | 301 return ::octave_rl_get_input_stream (); |
2926 | 302 } |
303 | |
304 void | |
305 gnu_readline::do_set_output_stream (FILE *f) | |
306 { | |
3519 | 307 ::octave_rl_set_output_stream (f); |
2926 | 308 } |
309 | |
310 FILE * | |
311 gnu_readline::do_get_output_stream (void) | |
312 { | |
3519 | 313 return ::octave_rl_get_output_stream (); |
2926 | 314 } |
315 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
316 void |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
317 gnu_readline::do_redisplay (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
318 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
319 ::octave_rl_redisplay (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
320 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
321 |
2926 | 322 // GNU readline handles SIGWINCH, so these values have a good chance |
323 // of being correct even if the window changes size (they may be | |
324 // wrong if, for example, the luser changes the window size while the | |
325 // pager is running, and the signal is handled by the pager instead of | |
326 // us. | |
327 | |
328 int | |
329 gnu_readline::do_terminal_rows (void) | |
330 { | |
3519 | 331 int sh = ::octave_rl_screen_height (); |
332 | |
333 return sh > 0 ? sh : 24; | |
2926 | 334 } |
335 | |
336 int | |
337 gnu_readline::do_terminal_cols (void) | |
338 { | |
3519 | 339 int sw = ::octave_rl_screen_width (); |
340 | |
341 return sw > 0 ? sw : 80; | |
2926 | 342 } |
343 | |
344 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
345 gnu_readline::do_clear_screen (bool skip_redisplay) |
2926 | 346 { |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
347 ::octave_rl_clear_screen (skip_redisplay); |
2926 | 348 } |
349 | |
3281 | 350 void |
351 gnu_readline::do_resize_terminal (void) | |
352 { | |
3519 | 353 ::octave_rl_resize_terminal (); |
3281 | 354 } |
355 | |
3504 | 356 std::string |
2926 | 357 gnu_readline::newline_chars (void) |
358 { | |
359 return "\r\n"; | |
360 } | |
361 | |
362 void | |
363 gnu_readline::do_restore_terminal_state (void) | |
364 { | |
3519 | 365 ::octave_rl_restore_terminal_state (); |
2926 | 366 } |
367 | |
368 void | |
369 gnu_readline::do_blink_matching_paren (bool flag) | |
370 { | |
3779 | 371 ::octave_rl_enable_paren_matching (flag ? 1 : 0); |
2926 | 372 } |
373 | |
374 void | |
3933 | 375 gnu_readline::do_set_basic_word_break_characters (const std::string& s) |
376 { | |
377 ::octave_rl_set_basic_word_break_characters (s.c_str ()); | |
378 } | |
379 | |
380 void | |
381 gnu_readline::do_set_completer_word_break_characters (const std::string& s) | |
382 { | |
383 ::octave_rl_set_completer_word_break_characters (s.c_str ()); | |
384 } | |
385 | |
386 void | |
3504 | 387 gnu_readline::do_set_basic_quote_characters (const std::string& s) |
2926 | 388 { |
3519 | 389 ::octave_rl_set_basic_quote_characters (s.c_str ()); |
2926 | 390 } |
391 | |
392 void | |
6979 | 393 gnu_readline::do_set_filename_quote_characters (const std::string& s) |
394 { | |
395 ::octave_rl_set_filename_quote_characters (s.c_str ()); | |
396 } | |
397 | |
398 void | |
399 gnu_readline::do_set_completer_quote_characters (const std::string& s) | |
400 { | |
401 ::octave_rl_set_completer_quote_characters (s.c_str ()); | |
402 } | |
403 | |
404 void | |
2926 | 405 gnu_readline::do_set_completion_append_character (char c) |
406 { | |
3519 | 407 ::octave_rl_set_completion_append_character (c); |
2926 | 408 } |
409 | |
410 void | |
2941 | 411 gnu_readline::do_set_completion_function (completion_fcn f) |
2926 | 412 { |
2941 | 413 completion_function = f; |
414 | |
3519 | 415 rl_attempted_completion_fcn_ptr fp |
416 = f ? gnu_readline::command_completer : 0; | |
2941 | 417 |
3519 | 418 ::octave_rl_set_completion_function (fp); |
2941 | 419 } |
420 | |
6979 | 421 void |
422 gnu_readline::do_set_quoting_function (quoting_fcn f) | |
423 { | |
424 quoting_function = f; | |
425 | |
426 rl_quoting_fcn_ptr fp | |
427 = f ? gnu_readline::command_quoter : 0; | |
428 | |
429 ::octave_rl_set_quoting_function (fp); | |
430 } | |
431 | |
432 void | |
433 gnu_readline::do_set_dequoting_function (dequoting_fcn f) | |
434 { | |
435 dequoting_function = f; | |
436 | |
437 rl_dequoting_fcn_ptr fp | |
438 = f ? gnu_readline::command_dequoter : 0; | |
439 | |
440 ::octave_rl_set_dequoting_function (fp); | |
441 } | |
442 | |
443 void | |
444 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f) | |
445 { | |
446 char_is_quoted_function = f; | |
447 | |
448 rl_char_is_quoted_fcn_ptr fp | |
449 = f ? gnu_readline::command_char_is_quoted : 0; | |
450 | |
451 ::octave_rl_set_char_is_quoted_function (fp); | |
452 } | |
453 | |
454 void | |
455 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f) | |
456 { | |
457 user_accept_line_function = f; | |
458 | |
459 if (f) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
460 octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
461 ::octave_rl_ctrl ('M')); |
6979 | 462 else |
463 octave_rl_add_defun ("accept-line", ::octave_rl_newline, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
464 ::octave_rl_ctrl ('M')); |
6979 | 465 } |
466 | |
2941 | 467 gnu_readline::completion_fcn |
468 gnu_readline::do_get_completion_function (void) const | |
469 { | |
470 return completion_function; | |
2926 | 471 } |
472 | |
6979 | 473 gnu_readline::quoting_fcn |
474 gnu_readline::do_get_quoting_function (void) const | |
475 { | |
476 return quoting_function; | |
477 } | |
478 | |
479 gnu_readline::dequoting_fcn | |
480 gnu_readline::do_get_dequoting_function (void) const | |
481 { | |
482 return dequoting_function; | |
483 } | |
484 | |
485 gnu_readline::char_is_quoted_fcn | |
486 gnu_readline::do_get_char_is_quoted_function (void) const | |
487 { | |
488 return char_is_quoted_function; | |
489 } | |
490 | |
491 gnu_readline::user_accept_line_fcn | |
492 gnu_readline::do_get_user_accept_line_function (void) const | |
493 { | |
494 return user_accept_line_function; | |
495 } | |
496 | |
4604 | 497 string_vector |
498 gnu_readline::do_generate_filename_completions (const std::string& text) | |
499 { | |
500 string_vector retval; | |
501 | |
502 int n = 0; | |
503 int count = 0; | |
504 | |
505 char *fn = 0; | |
506 | |
507 while (1) | |
508 { | |
509 fn = ::octave_rl_filename_completion_function (text.c_str (), count); | |
510 | |
511 if (fn) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
512 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
513 if (count == n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
514 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
515 // Famous last words: Most large directories will not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
516 // have more than a few hundred files, so we should not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
517 // resize too many times even if the growth is linear... |
4604 | 518 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
519 n += 100; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
520 retval.resize (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
521 } |
4604 | 522 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
523 retval[count++] = fn; |
4604 | 524 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
525 free (fn); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
526 } |
4604 | 527 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
528 break; |
4604 | 529 } |
530 | |
531 retval.resize (count); | |
532 | |
533 return retval; | |
534 } | |
535 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
536 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
537 gnu_readline::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
538 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
539 return ::octave_rl_line_buffer (); |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
540 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
541 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
542 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
543 gnu_readline::do_get_current_line (void) const |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
544 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
545 std::string retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
546 char *buf = ::octave_rl_copy_line (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
547 retval = buf; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
548 free (buf); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
549 return retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
550 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
551 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
552 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
553 gnu_readline::do_replace_line (const std::string& text, bool clear_undo) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
554 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
555 ::octave_rl_replace_line (text.c_str (), clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
556 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
557 |
2926 | 558 void |
3504 | 559 gnu_readline::do_insert_text (const std::string& text) |
2926 | 560 { |
3519 | 561 ::octave_rl_insert_text (text.c_str ()); |
2926 | 562 } |
563 | |
564 void | |
565 gnu_readline::do_newline (void) | |
566 { | |
6979 | 567 ::octave_rl_newline (1, '\n'); |
568 } | |
569 | |
570 void | |
571 gnu_readline::do_accept_line (void) | |
572 { | |
573 command_accept_line (1, '\n'); | |
2926 | 574 } |
575 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
576 bool |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
577 gnu_readline::do_undo (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
578 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
579 return ::octave_rl_do_undo (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
580 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
581 |
2926 | 582 void |
583 gnu_readline::do_clear_undo_list () | |
584 { | |
3519 | 585 ::octave_rl_clear_undo_list (); |
2926 | 586 } |
587 | |
588 void | |
6913 | 589 gnu_readline::set_startup_hook (startup_hook_fcn f) |
2926 | 590 { |
3519 | 591 previous_startup_hook = ::octave_rl_get_startup_hook (); |
2926 | 592 |
6917 | 593 if (f != previous_startup_hook) |
594 ::octave_rl_set_startup_hook (f); | |
2926 | 595 } |
596 | |
597 void | |
6913 | 598 gnu_readline::restore_startup_hook (void) |
2926 | 599 { |
3519 | 600 ::octave_rl_set_startup_hook (previous_startup_hook); |
2926 | 601 } |
602 | |
603 void | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
604 gnu_readline::set_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
605 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
606 previous_pre_input_hook = ::octave_rl_get_pre_input_hook (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
607 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
608 if (f != previous_pre_input_hook) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
609 ::octave_rl_set_pre_input_hook (f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
610 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
611 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
612 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
613 gnu_readline::restore_pre_input_hook (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
614 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
615 ::octave_rl_set_pre_input_hook (previous_pre_input_hook); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
616 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
617 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
618 void |
6913 | 619 gnu_readline::set_event_hook (event_hook_fcn f) |
3215 | 620 { |
3519 | 621 previous_event_hook = octave_rl_get_event_hook (); |
3215 | 622 |
3519 | 623 ::octave_rl_set_event_hook (f); |
3215 | 624 } |
625 | |
626 void | |
6913 | 627 gnu_readline::restore_event_hook (void) |
3215 | 628 { |
3519 | 629 ::octave_rl_set_event_hook (previous_event_hook); |
3215 | 630 } |
631 | |
632 void | |
3504 | 633 gnu_readline::do_read_init_file (const std::string& file) |
3189 | 634 { |
3519 | 635 ::octave_rl_read_init_file (file.c_str ()); |
3189 | 636 } |
637 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
638 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
639 gnu_readline::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
|
640 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
641 ::octave_rl_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
642 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
643 |
4143 | 644 bool |
645 gnu_readline::do_filename_completion_desired (bool arg) | |
646 { | |
647 return ::octave_rl_filename_completion_desired (arg); | |
648 } | |
649 | |
6979 | 650 bool |
651 gnu_readline::do_filename_quoting_desired (bool arg) | |
652 { | |
653 return ::octave_rl_filename_quoting_desired (arg); | |
654 } | |
655 | |
19304
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
656 bool |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
657 gnu_readline::do_prefer_env_winsize (bool arg) |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
658 { |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
659 return ::octave_rl_prefer_env_winsize (arg); |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
660 } |
ad93e9be78ee
command_editor: provide access to rl_prefer_env_winsize
John W. Eaton <jwe@octave.org>
parents:
19302
diff
changeset
|
661 |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
662 void |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
663 gnu_readline::do_interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
664 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
665 ::octave_rl_done (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
666 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
667 |
3519 | 668 int |
2926 | 669 gnu_readline::operate_and_get_next (int /* count */, int /* c */) |
670 { | |
671 // Accept the current line. | |
672 | |
6979 | 673 command_editor::accept_line (); |
2926 | 674 |
675 // Find the current line, and find the next line to use. | |
676 | |
677 int x_where = command_history::where (); | |
678 | |
679 int x_length = command_history::length (); | |
680 | |
681 if ((command_history::is_stifled () | |
682 && (x_length >= command_history::max_input_history ())) | |
683 || (x_where >= x_length - 1)) | |
684 command_history::set_mark (x_where); | |
685 else | |
686 command_history::set_mark (x_where + 1); | |
687 | |
6913 | 688 command_editor::add_startup_hook (command_history::goto_mark); |
3519 | 689 |
690 return 0; | |
2926 | 691 } |
692 | |
3951 | 693 int |
694 gnu_readline::history_search_backward (int count, int c) | |
695 { | |
696 return octave_rl_history_search_backward (count, c); | |
697 } | |
698 | |
699 int | |
700 gnu_readline::history_search_forward (int count, int c) | |
701 { | |
702 return octave_rl_history_search_forward (count, c); | |
703 } | |
704 | |
2941 | 705 char * |
706 gnu_readline::command_generator (const char *text, int state) | |
707 { | |
708 char *retval = 0; | |
709 | |
710 completion_fcn f = command_editor::get_completion_function (); | |
711 | |
3504 | 712 std::string tmp = f (text, state); |
2941 | 713 |
714 size_t len = tmp.length (); | |
715 | |
716 if (len > 0) | |
717 { | |
10411 | 718 retval = static_cast<char *> (gnulib::malloc (len+1)); |
2941 | 719 |
720 strcpy (retval, tmp.c_str ()); | |
721 } | |
722 | |
723 return retval; | |
724 } | |
725 | |
6979 | 726 char * |
727 gnu_readline::command_quoter (char *text, int matches, char *qcp) | |
728 { | |
729 char *retval = 0; | |
730 | |
731 quoting_fcn f = command_editor::get_quoting_function (); | |
732 | |
733 std::string tmp = f (text, matches, *qcp); | |
734 | |
735 size_t len = tmp.length (); | |
736 | |
737 if (len > 0) | |
738 { | |
10411 | 739 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 740 |
741 strcpy (retval, tmp.c_str ()); | |
742 } | |
743 | |
744 return retval; | |
745 } | |
746 | |
747 char * | |
748 gnu_readline::command_dequoter (char *text, int quote) | |
749 { | |
750 char *retval = 0; | |
751 | |
752 dequoting_fcn f = command_editor::get_dequoting_function (); | |
753 | |
754 std::string tmp = f (text, quote); | |
755 | |
756 size_t len = tmp.length (); | |
757 | |
758 if (len > 0) | |
759 { | |
10411 | 760 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 761 |
762 strcpy (retval, tmp.c_str ()); | |
763 } | |
764 | |
765 return retval; | |
766 } | |
767 | |
768 int | |
769 gnu_readline::command_char_is_quoted (char *text, int quote) | |
770 { | |
771 char_is_quoted_fcn f = command_editor::get_char_is_quoted_function (); | |
772 | |
773 return f (text, quote); | |
774 } | |
775 | |
776 int | |
777 gnu_readline::command_accept_line (int count, int key) | |
778 { | |
779 user_accept_line_fcn f = command_editor::get_user_accept_line_function (); | |
780 | |
781 if (f) | |
782 f (::octave_rl_line_buffer ()); | |
783 | |
784 ::octave_rl_redisplay (); | |
785 | |
786 return ::octave_rl_newline (count, key); | |
787 } | |
788 | |
2941 | 789 char ** |
3519 | 790 gnu_readline::command_completer (const char *text, int, int) |
2941 | 791 { |
792 char **matches = 0; | |
3519 | 793 matches |
794 = ::octave_rl_completion_matches (text, gnu_readline::command_generator); | |
2941 | 795 return matches; |
796 } | |
797 | |
2926 | 798 #endif |
799 | |
800 class | |
801 default_command_editor : public command_editor | |
802 { | |
803 public: | |
804 | |
805 default_command_editor (void) | |
806 : command_editor (), input_stream (stdin), output_stream (stdout) { } | |
807 | |
808 ~default_command_editor (void) { } | |
809 | |
3504 | 810 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 811 |
812 void do_set_input_stream (FILE *f); | |
813 | |
814 FILE *do_get_input_stream (void); | |
815 | |
816 void do_set_output_stream (FILE *f); | |
817 | |
818 FILE *do_get_output_stream (void); | |
819 | |
4604 | 820 string_vector do_generate_filename_completions (const std::string& text); |
821 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
822 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
823 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
824 std::string do_get_current_line (void) const; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
825 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
826 void do_replace_line (const std::string& text, bool clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
827 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
828 void do_insert_text (const std::string& text); |
2926 | 829 |
830 void do_newline (void); | |
831 | |
6979 | 832 void do_accept_line (void); |
833 | |
2926 | 834 private: |
835 | |
836 FILE *input_stream; | |
837 | |
838 FILE *output_stream; | |
12153
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
839 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
840 // No copying! |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
841 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
842 default_command_editor (const default_command_editor&); |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
843 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
844 default_command_editor& operator = (const default_command_editor&); |
2926 | 845 }; |
846 | |
3504 | 847 std::string |
848 default_command_editor::do_readline (const std::string& prompt, bool& eof) | |
2926 | 849 { |
10411 | 850 gnulib::fputs (prompt.c_str (), output_stream); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12153
diff
changeset
|
851 gnulib::fflush (output_stream); |
2926 | 852 |
4527 | 853 return octave_fgetl (input_stream, eof); |
2926 | 854 } |
855 | |
856 void | |
857 default_command_editor::do_set_input_stream (FILE *f) | |
858 { | |
859 input_stream = f; | |
860 } | |
861 | |
862 FILE * | |
863 default_command_editor::do_get_input_stream (void) | |
864 { | |
865 return input_stream; | |
866 } | |
867 | |
868 void | |
869 default_command_editor::do_set_output_stream (FILE *f) | |
870 { | |
871 output_stream = f; | |
872 } | |
873 | |
874 FILE * | |
875 default_command_editor::do_get_output_stream (void) | |
876 { | |
877 return output_stream; | |
878 } | |
879 | |
4604 | 880 string_vector |
4663 | 881 default_command_editor::do_generate_filename_completions (const std::string&) |
4604 | 882 { |
5775 | 883 // FIXME |
4604 | 884 return string_vector (); |
885 } | |
886 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
887 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
888 default_command_editor::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
889 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
890 return ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
891 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
892 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
893 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
894 default_command_editor::do_get_current_line (void) const |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
895 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
896 // FIXME |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
897 return std::string (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
898 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
899 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
900 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
901 default_command_editor::do_replace_line (const std::string&, bool) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
902 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
903 // FIXME |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
904 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
905 |
2926 | 906 void |
3504 | 907 default_command_editor::do_insert_text (const std::string&) |
2926 | 908 { |
5775 | 909 // FIXME |
2926 | 910 } |
911 | |
912 void | |
913 default_command_editor::do_newline (void) | |
914 { | |
5775 | 915 // FIXME |
2926 | 916 } |
917 | |
6979 | 918 void |
919 default_command_editor::do_accept_line (void) | |
920 { | |
921 // FIXME | |
922 } | |
923 | |
2926 | 924 bool |
925 command_editor::instance_ok (void) | |
926 { | |
927 bool retval = true; | |
928 | |
929 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
930 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
931 make_command_editor (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
932 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
933 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
934 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
935 } |
2926 | 936 |
937 if (! instance) | |
938 { | |
2941 | 939 current_liboctave_error_handler |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
940 ("unable to create command history object!"); |
2926 | 941 |
942 retval = false; | |
943 } | |
944 | |
945 return retval; | |
946 } | |
947 | |
948 void | |
949 command_editor::make_command_editor (void) | |
950 { | |
951 #if defined (USE_READLINE) | |
952 instance = new gnu_readline (); | |
953 #else | |
954 instance = new default_command_editor (); | |
955 #endif | |
956 } | |
957 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
958 void |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
959 command_editor::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
|
960 { |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
961 delete instance; |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
962 instance = new default_command_editor (); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
963 } |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
964 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
965 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
966 command_editor::set_initial_input (const std::string& text) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
967 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
968 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
969 instance->initial_input = text; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
970 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
971 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
972 int |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
973 command_editor::insert_initial_input (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
974 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
975 return instance_ok () ? instance->do_insert_initial_input () : 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
976 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
977 |
6913 | 978 int |
979 command_editor::startup_handler (void) | |
980 { | |
981 for (startup_hook_set_iterator p = startup_hook_set.begin (); | |
982 p != startup_hook_set.end (); p++) | |
983 { | |
984 startup_hook_fcn f = *p; | |
985 | |
986 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 f (); |
6913 | 988 } |
989 | |
990 return 0; | |
991 } | |
992 | |
993 int | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
994 command_editor::pre_input_handler (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
995 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
996 for (pre_input_hook_set_iterator p = pre_input_hook_set.begin (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
997 p != pre_input_hook_set.end (); p++) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
998 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
999 pre_input_hook_fcn f = *p; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1000 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1001 if (f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1002 f (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1003 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1004 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1005 return 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1006 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1007 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1008 int |
6913 | 1009 command_editor::event_handler (void) |
1010 { | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1011 event_hook_lock.lock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1012 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1013 std::set<event_hook_fcn> hook_set (event_hook_set); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1014 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1015 event_hook_lock.unlock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1016 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1017 for (event_hook_set_iterator p = hook_set.begin (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1018 p != hook_set.end (); p++) |
6913 | 1019 { |
1020 event_hook_fcn f = *p; | |
1021 | |
1022 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1023 f (); |
6913 | 1024 } |
1025 | |
1026 return 0; | |
1027 } | |
1028 | |
2926 | 1029 void |
3504 | 1030 command_editor::set_name (const std::string& n) |
2926 | 1031 { |
1032 if (instance_ok ()) | |
1033 instance->do_set_name (n); | |
1034 } | |
1035 | |
3504 | 1036 std::string |
1037 command_editor::readline (const std::string& prompt) | |
2926 | 1038 { |
3219 | 1039 bool eof; |
1040 | |
1041 return readline (prompt, eof); | |
1042 } | |
1043 | |
3504 | 1044 std::string |
1045 command_editor::readline (const std::string& prompt, bool& eof) | |
3219 | 1046 { |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1047 std::string retval; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1048 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1049 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1050 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1051 if (! instance->initial_input.empty ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1052 add_pre_input_hook (command_editor::insert_initial_input); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1053 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1054 retval = instance->do_readline (prompt, eof); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1055 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1056 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1057 return retval; |
2926 | 1058 } |
1059 | |
1060 void | |
1061 command_editor::set_input_stream (FILE *f) | |
1062 { | |
1063 if (instance_ok ()) | |
1064 instance->do_set_input_stream (f); | |
1065 } | |
1066 | |
1067 FILE * | |
1068 command_editor::get_input_stream (void) | |
1069 { | |
1070 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1071 ? instance->do_get_input_stream () : 0; |
2926 | 1072 } |
1073 | |
1074 void | |
1075 command_editor::set_output_stream (FILE *f) | |
1076 { | |
1077 if (instance_ok ()) | |
1078 instance->do_set_output_stream (f); | |
1079 } | |
1080 | |
1081 FILE * | |
1082 command_editor::get_output_stream (void) | |
1083 { | |
1084 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1085 ? instance->do_get_output_stream () : 0; |
2926 | 1086 } |
1087 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1088 void |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1089 command_editor::redisplay (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1090 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1091 if (instance_ok ()) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1092 instance->do_redisplay (); |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1093 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1094 |
2926 | 1095 int |
1096 command_editor::terminal_rows (void) | |
1097 { | |
1098 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1099 ? instance->do_terminal_rows () : -1; |
2926 | 1100 } |
1101 | |
1102 int | |
1103 command_editor::terminal_cols (void) | |
1104 { | |
1105 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1106 ? instance->do_terminal_cols () : -1; |
2926 | 1107 } |
1108 | |
1109 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
1110 command_editor::clear_screen (bool skip_redisplay) |
2926 | 1111 { |
1112 if (instance_ok ()) | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
1113 instance->do_clear_screen (skip_redisplay); |
2926 | 1114 } |
1115 | |
3281 | 1116 void |
1117 command_editor::resize_terminal (void) | |
1118 { | |
1119 if (instance_ok ()) | |
1120 instance->do_resize_terminal (); | |
1121 } | |
1122 | |
3504 | 1123 std::string |
1124 command_editor::decode_prompt_string (const std::string& s) | |
2926 | 1125 { |
1126 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1127 ? instance->do_decode_prompt_string (s) : std::string (); |
2926 | 1128 } |
1129 | |
1130 int | |
1131 command_editor::current_command_number (void) | |
1132 { | |
1133 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1134 ? instance->command_number : 0; |
2926 | 1135 } |
1136 | |
1137 void | |
1138 command_editor::reset_current_command_number (int n) | |
1139 { | |
1140 if (instance_ok ()) | |
1141 instance->command_number = n; | |
1142 } | |
1143 | |
1144 void | |
2967 | 1145 command_editor::increment_current_command_number (void) |
1146 { | |
1147 if (instance_ok ()) | |
1148 instance->command_number++; | |
1149 } | |
1150 | |
1151 void | |
2926 | 1152 command_editor::restore_terminal_state (void) |
1153 { | |
1154 if (instance_ok ()) | |
1155 instance->do_restore_terminal_state (); | |
1156 } | |
1157 | |
1158 void | |
1159 command_editor::blink_matching_paren (bool flag) | |
1160 { | |
1161 if (instance_ok ()) | |
1162 instance->do_blink_matching_paren (flag); | |
1163 } | |
1164 | |
1165 void | |
3933 | 1166 command_editor::set_basic_word_break_characters (const std::string& s) |
1167 { | |
1168 if (instance_ok ()) | |
1169 instance->do_set_basic_word_break_characters (s); | |
1170 } | |
1171 | |
1172 void | |
1173 command_editor::set_completer_word_break_characters (const std::string& s) | |
1174 { | |
1175 if (instance_ok ()) | |
1176 instance->do_set_completer_word_break_characters (s); | |
1177 } | |
1178 | |
1179 void | |
3504 | 1180 command_editor::set_basic_quote_characters (const std::string& s) |
2926 | 1181 { |
1182 if (instance_ok ()) | |
3004 | 1183 instance->do_set_basic_quote_characters (s); |
2926 | 1184 } |
1185 | |
1186 void | |
6979 | 1187 command_editor::set_filename_quote_characters (const std::string& s) |
1188 { | |
1189 if (instance_ok ()) | |
1190 instance->do_set_filename_quote_characters (s); | |
1191 } | |
1192 | |
1193 void | |
1194 command_editor::set_completer_quote_characters (const std::string& s) | |
1195 { | |
1196 if (instance_ok ()) | |
1197 instance->do_set_completer_quote_characters (s); | |
1198 } | |
1199 | |
1200 void | |
2926 | 1201 command_editor::set_completion_append_character (char c) |
1202 { | |
1203 if (instance_ok ()) | |
1204 instance->do_set_completion_append_character (c); | |
1205 } | |
1206 | |
1207 void | |
2941 | 1208 command_editor::set_completion_function (completion_fcn f) |
2926 | 1209 { |
1210 if (instance_ok ()) | |
2941 | 1211 instance->do_set_completion_function (f); |
1212 } | |
1213 | |
6979 | 1214 void |
1215 command_editor::set_quoting_function (quoting_fcn f) | |
1216 { | |
1217 if (instance_ok ()) | |
1218 instance->do_set_quoting_function (f); | |
1219 } | |
1220 | |
1221 void | |
1222 command_editor::set_dequoting_function (dequoting_fcn f) | |
1223 { | |
1224 if (instance_ok ()) | |
1225 instance->do_set_dequoting_function (f); | |
1226 } | |
1227 | |
1228 void | |
1229 command_editor::set_char_is_quoted_function (char_is_quoted_fcn f) | |
1230 { | |
1231 if (instance_ok ()) | |
1232 instance->do_set_char_is_quoted_function (f); | |
1233 } | |
1234 | |
1235 void | |
1236 command_editor::set_user_accept_line_function (user_accept_line_fcn f) | |
1237 { | |
1238 if (instance_ok ()) | |
1239 instance->do_set_user_accept_line_function (f); | |
1240 } | |
1241 | |
2941 | 1242 command_editor::completion_fcn |
1243 command_editor::get_completion_function (void) | |
1244 { | |
1245 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1246 ? instance->do_get_completion_function () : 0; |
2926 | 1247 } |
1248 | |
6979 | 1249 command_editor::quoting_fcn |
1250 command_editor::get_quoting_function (void) | |
1251 { | |
1252 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1253 ? instance->do_get_quoting_function () : 0; |
6979 | 1254 } |
1255 | |
1256 command_editor::dequoting_fcn | |
1257 command_editor::get_dequoting_function (void) | |
1258 { | |
1259 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1260 ? instance->do_get_dequoting_function () : 0; |
6979 | 1261 } |
1262 | |
1263 command_editor::char_is_quoted_fcn | |
1264 command_editor::get_char_is_quoted_function (void) | |
1265 { | |
1266 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1267 ? instance->do_get_char_is_quoted_function () : 0; |
6979 | 1268 } |
1269 | |
1270 command_editor::user_accept_line_fcn | |
1271 command_editor::get_user_accept_line_function (void) | |
1272 { | |
1273 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1274 ? instance->do_get_user_accept_line_function () : 0; |
6979 | 1275 } |
1276 | |
4604 | 1277 string_vector |
1278 command_editor::generate_filename_completions (const std::string& text) | |
1279 { | |
1280 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1281 ? instance->do_generate_filename_completions (text) : string_vector (); |
4604 | 1282 } |
1283 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1284 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1285 command_editor::get_line_buffer (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1286 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1287 return (instance_ok ()) ? instance->do_get_line_buffer () : ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1288 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1289 |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1290 std::string |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1291 command_editor::get_current_line (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1292 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1293 return (instance_ok ()) ? instance->do_get_current_line () : ""; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1294 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1295 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1296 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1297 command_editor::replace_line (const std::string& text, bool clear_undo) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1298 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1299 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1300 instance->do_replace_line (text, clear_undo); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1301 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1302 |
2926 | 1303 void |
3504 | 1304 command_editor::insert_text (const std::string& text) |
2926 | 1305 { |
1306 if (instance_ok ()) | |
1307 instance->do_insert_text (text); | |
1308 } | |
1309 | |
1310 void | |
1311 command_editor::newline (void) | |
1312 { | |
1313 if (instance_ok ()) | |
1314 instance->do_newline (); | |
1315 } | |
1316 | |
1317 void | |
6979 | 1318 command_editor::accept_line (void) |
1319 { | |
1320 if (instance_ok ()) | |
1321 instance->do_accept_line (); | |
1322 } | |
1323 | |
16539
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1324 bool |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1325 command_editor::undo (void) |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1326 { |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1327 return instance_ok () ? instance->do_undo () : false; |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1328 } |
8ea8df0747e9
make undo button and menu item work for command window
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
1329 |
6979 | 1330 void |
2926 | 1331 command_editor::clear_undo_list (void) |
1332 { | |
1333 if (instance_ok ()) | |
1334 instance->do_clear_undo_list (); | |
1335 } | |
1336 | |
1337 void | |
6913 | 1338 command_editor::add_startup_hook (startup_hook_fcn f) |
2926 | 1339 { |
1340 if (instance_ok ()) | |
6913 | 1341 { |
1342 startup_hook_set.insert (f); | |
1343 | |
1344 instance->set_startup_hook (startup_handler); | |
1345 } | |
2926 | 1346 } |
1347 | |
1348 void | |
6913 | 1349 command_editor::remove_startup_hook (startup_hook_fcn f) |
2926 | 1350 { |
1351 if (instance_ok ()) | |
6913 | 1352 { |
1353 startup_hook_set_iterator p = startup_hook_set.find (f); | |
1354 | |
1355 if (p != startup_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 startup_hook_set.erase (p); |
6913 | 1357 |
1358 if (startup_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1359 instance->restore_startup_hook (); |
6913 | 1360 } |
2926 | 1361 } |
1362 | |
3189 | 1363 void |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1364 command_editor::add_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1365 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1366 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1367 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1368 pre_input_hook_set.insert (f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1369 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1370 instance->set_pre_input_hook (pre_input_handler); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1371 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1372 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1373 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1374 void |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1375 command_editor::remove_pre_input_hook (pre_input_hook_fcn f) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1376 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1377 if (instance_ok ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1378 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1379 pre_input_hook_set_iterator p = pre_input_hook_set.find (f); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1380 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1381 if (p != pre_input_hook_set.end ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1382 pre_input_hook_set.erase (p); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1383 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1384 if (pre_input_hook_set.empty ()) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1385 instance->restore_pre_input_hook (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1386 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1387 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1388 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1389 void |
6913 | 1390 command_editor::add_event_hook (event_hook_fcn f) |
3215 | 1391 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1392 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1393 |
3215 | 1394 if (instance_ok ()) |
6913 | 1395 { |
1396 event_hook_set.insert (f); | |
1397 | |
1398 instance->set_event_hook (event_handler); | |
1399 } | |
3215 | 1400 } |
1401 | |
1402 void | |
6913 | 1403 command_editor::remove_event_hook (event_hook_fcn f) |
3215 | 1404 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1405 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1406 |
3215 | 1407 if (instance_ok ()) |
6913 | 1408 { |
1409 event_hook_set_iterator p = event_hook_set.find (f); | |
1410 | |
1411 if (p != event_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1412 event_hook_set.erase (p); |
6913 | 1413 |
1414 if (event_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1415 instance->restore_event_hook (); |
6913 | 1416 } |
3215 | 1417 } |
1418 | |
1419 void | |
13924
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1420 command_editor::run_event_hooks (void) |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1421 { |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1422 event_handler (); |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1423 } |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1424 |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1425 void |
5872 | 1426 command_editor::read_init_file (const std::string& file_arg) |
3189 | 1427 { |
1428 if (instance_ok ()) | |
5872 | 1429 { |
1430 std::string file = file_ops::tilde_expand (file_arg); | |
1431 | |
1432 instance->do_read_init_file (file); | |
1433 } | |
3189 | 1434 } |
1435 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1436 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1437 command_editor::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
|
1438 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1439 if (instance_ok ()) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1440 instance->do_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1441 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1442 |
4143 | 1443 bool |
1444 command_editor::filename_completion_desired (bool arg) | |
1445 { | |
1446 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1447 ? instance->do_filename_completion_desired (arg) : false; |
4143 | 1448 } |
1449 | |
6979 | 1450 bool |
1451 command_editor::filename_quoting_desired (bool arg) | |
1452 { | |
1453 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1454 ? instance->do_filename_quoting_desired (arg) : false; |
6979 | 1455 } |
1456 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1457 bool |
19302
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1458 command_editor::prefer_env_winsize (bool arg) |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1459 { |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1460 return (instance_ok ()) |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1461 ? instance->do_prefer_env_winsize (arg) : false; |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1462 } |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1463 |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1464 bool |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1465 command_editor::interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1466 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1467 bool retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1468 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1469 if (instance_ok ()) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1470 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1471 // Return the current interrupt state. |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1472 retval = instance->interrupted; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1473 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1474 instance->do_interrupt (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1475 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1476 instance->interrupted = arg; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1477 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1478 else |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1479 retval = false; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1480 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1481 return retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1482 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1483 |
2926 | 1484 // Return a string which will be printed as a prompt. The string may |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1485 // contain special characters which are decoded as follows: |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1486 // |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 // \a bell (ascii 07) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1488 // \d the date |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1489 // \e escape (ascii 033) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1490 // \h the hostname up to the first '.' |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1491 // \H the hostname |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1492 // \n CRLF |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1493 // \r CR |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1494 // \s the name of the shell (program) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 // \t the time |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1496 // \T the time in 12-hour hh:mm:ss format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 // \@ the time in 12-hour hh:mm am/pm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1498 // \A the time in 24-hour hh:mm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 // \u your username |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 // \w the current working directory |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1501 // \W the last element of PWD |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 // \! the history number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1503 // \# the command number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1504 // \$ a $ or a # if you are root |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1505 // \nnn character code nnn in octal |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1506 // \\ a backslash |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1507 // \[ begin a sequence of non-printing chars |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1508 // \] end a sequence of non-printing chars |
2926 | 1509 |
3504 | 1510 std::string |
1511 command_editor::do_decode_prompt_string (const std::string& s) | |
2926 | 1512 { |
3504 | 1513 std::string result; |
1514 std::string temp; | |
2926 | 1515 size_t i = 0; |
1516 size_t slen = s.length (); | |
1517 int c; | |
1518 | |
1519 while (i < slen) | |
1520 { | |
1521 c = s[i]; | |
1522 | |
1523 i++; | |
1524 | |
1525 if (c == '\\') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1526 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1527 c = s[i]; |
2926 | 1528 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 switch (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 case '0': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 case '1': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1533 case '2': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 case '3': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1535 case '4': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 case '5': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 case '6': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 case '7': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1539 // Maybe convert an octal number. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 int n = read_octal (s.substr (i, 3)); |
2926 | 1542 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1543 temp = "\\"; |
2926 | 1544 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1545 if (n != -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1546 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1547 i += 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1548 temp[0] = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1549 } |
2926 | 1550 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1551 c = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1552 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1553 } |
5442 | 1554 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1555 case 'a': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1556 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1557 temp = '\a'; |
5442 | 1558 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1559 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1560 } |
5442 | 1561 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1562 case 'e': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1563 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1564 temp = '\033'; |
5442 | 1565 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1566 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1567 } |
5442 | 1568 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1569 case 'r': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1570 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1571 temp = '\r'; |
5442 | 1572 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1573 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1574 } |
5442 | 1575 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1576 case 'd': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1577 case 't': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1578 case 'T': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1579 case '@': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1580 case 'A': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1581 // Make the current time/date into a string. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1582 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1583 octave_localtime now; |
2926 | 1584 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1585 if (c == 'd') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1586 temp = now.strftime ("%a %b %d"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1587 else if (c == 't') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1588 temp = now.strftime ("%H:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1589 else if (c == 'T') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1590 temp = now.strftime ("%I:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1591 else if (c == '@') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1592 temp = now.strftime ("%I:%M %p"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1593 else if (c == 'A') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1594 temp = now.strftime ("%H:%M"); |
2926 | 1595 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1596 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1597 } |
2926 | 1598 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1599 case 'n': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1600 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1601 temp = newline_chars (); |
2926 | 1602 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1603 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1604 } |
2926 | 1605 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1606 case 's': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1607 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1608 temp = octave_env::get_program_name (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1609 temp = octave_env::base_pathname (temp); |
2926 | 1610 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1611 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1612 } |
5442 | 1613 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1614 case 'w': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1615 case 'W': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1616 { |
17644
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1617 try |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1618 { |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1619 temp = octave_env::get_current_directory (); |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1620 } |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1621 catch (octave_execution_exception) |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1622 { |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1623 temp = ""; |
ca9a9c0740c5
Fix infinite loop when PS1 needs deleted directory (bug #32176)
Mike Miller <mtmiller@ieee.org>
parents:
16570
diff
changeset
|
1624 } |
2926 | 1625 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1626 std::string home_dir = octave_env::get_home_directory (); |
5442 | 1627 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1628 if (c == 'W' && (home_dir.empty () || temp != home_dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1629 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1630 if (temp != "/" && temp != "//") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1631 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1632 size_t pos = temp.rfind ('/'); |
2926 | 1633 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1634 if (pos != std::string::npos && pos != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1635 temp = temp.substr (pos + 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1636 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1637 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1638 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1639 temp = octave_env::polite_directory_format (temp); |
2926 | 1640 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1641 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1642 } |
5442 | 1643 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1644 case 'u': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1645 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1646 temp = octave_env::get_user_name (); |
2926 | 1647 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1648 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1649 } |
2926 | 1650 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1651 case 'H': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1652 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1653 temp = octave_env::get_host_name (); |
2926 | 1654 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1655 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1656 } |
2926 | 1657 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1658 case 'h': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1659 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1660 temp = octave_env::get_host_name (); |
2926 | 1661 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1662 size_t pos = temp.find ('.'); |
2926 | 1663 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1664 if (pos != std::string::npos) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1665 temp.resize (pos); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1666 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1667 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1668 } |
2926 | 1669 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1670 case '#': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1671 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1672 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1673 sprintf (number_buffer, "%d", command_number); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1674 temp = number_buffer; |
2926 | 1675 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1676 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1677 } |
2926 | 1678 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1679 case '!': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1680 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1681 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1682 int num = command_history::current_number (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1683 if (num > 0) |
2926 | 1684 sprintf (number_buffer, "%d", num); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1685 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1686 strcpy (number_buffer, "!"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1687 temp = number_buffer; |
2926 | 1688 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1689 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1690 } |
2926 | 1691 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1692 case '$': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1693 { |
4062 | 1694 #if defined (HAVE_GETEUID) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1695 temp = (::geteuid () == 0 ? "#" : "$"); |
4062 | 1696 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1697 temp = "$"; |
4062 | 1698 #endif |
2926 | 1699 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1700 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1701 } |
2926 | 1702 |
1703 #if defined (USE_READLINE) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1704 case '[': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1705 case ']': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1706 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1707 temp.resize (1); |
2926 | 1708 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1709 temp[0] = ((c == '[') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1710 ? ::octave_rl_prompt_start_ignore () |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1711 : ::octave_rl_prompt_end_ignore ()); |
2926 | 1712 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1713 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1714 } |
2926 | 1715 #endif |
1716 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1717 case '\\': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1718 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1719 temp = "\\"; |
2926 | 1720 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1721 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1722 } |
2926 | 1723 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1724 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1725 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1726 temp = "\\ "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1727 temp[1] = c; |
2926 | 1728 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1729 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1730 } |
2926 | 1731 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1732 add_string: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1733 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1734 if (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1735 i++; |
2926 | 1736 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1737 result.append (temp); |
2926 | 1738 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1739 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1740 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1741 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1742 } |
2926 | 1743 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1744 result += c; |
2926 | 1745 } |
1746 | |
1747 return result; | |
1748 } | |
1749 | |
16570
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1750 int |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1751 command_editor::do_insert_initial_input (void) |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1752 { |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1753 std::string input = initial_input; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1754 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1755 initial_input = ""; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1756 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1757 do_insert_text (input); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1758 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1759 // Is it really right to redisplay here? |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1760 do_redisplay (); |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1761 |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1762 return 0; |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1763 } |
d5ae5aa80d42
preserve pending command line input when running commands from GUI actions
John W. Eaton <jwe@octave.org>
parents:
16539
diff
changeset
|
1764 |
2926 | 1765 // Return the octal number parsed from STRING, or -1 to indicate that |
1766 // the string contained a bad number. | |
1767 | |
1768 int | |
3504 | 1769 command_editor::read_octal (const std::string& s) |
2926 | 1770 { |
1771 int result = 0; | |
1772 int digits = 0; | |
1773 | |
1774 size_t i = 0; | |
1775 size_t slen = s.length (); | |
1776 | |
1777 while (i < slen && s[i] >= '0' && s[i] < '8') | |
1778 { | |
1779 digits++; | |
1780 result = (result * 8) + s[i] - '0'; | |
1781 i++; | |
1782 } | |
1783 | |
1784 if (! digits || result > 0777 || i < slen) | |
1785 result = -1; | |
1786 | |
1787 return result; | |
1788 } | |
1789 | |
1790 void | |
1791 command_editor::error (int err_num) | |
1792 { | |
10411 | 1793 current_liboctave_error_handler ("%s", gnulib::strerror (err_num)); |
2926 | 1794 } |
1795 | |
1796 void | |
3504 | 1797 command_editor::error (const std::string& s) |
2926 | 1798 { |
2941 | 1799 current_liboctave_error_handler ("%s", s.c_str ()); |
2926 | 1800 } |