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