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 |
6108
|
34 OCTAVE_API |
2926
|
35 command_editor |
|
36 { |
|
37 protected: |
|
38 |
|
39 command_editor (void) |
|
40 : command_number (0) { } |
|
41 |
|
42 public: |
|
43 |
4802
|
44 typedef int (*startup_hook_fcn) (void); |
3519
|
45 |
4802
|
46 typedef int (*event_hook_fcn) (void); |
2926
|
47 |
3504
|
48 typedef std::string (*completion_fcn) (const std::string&, int); |
2941
|
49 |
2926
|
50 virtual ~command_editor (void) { } |
|
51 |
3504
|
52 static void set_name (const std::string& n); |
2926
|
53 |
3504
|
54 static std::string readline (const std::string& prompt); |
2926
|
55 |
3504
|
56 static std::string readline (const std::string& prompt, bool& eof); |
3219
|
57 |
2926
|
58 static void set_input_stream (FILE *f); |
|
59 |
|
60 static FILE *get_input_stream (void); |
|
61 |
|
62 static void set_output_stream (FILE *f); |
|
63 |
|
64 static FILE *get_output_stream (void); |
|
65 |
|
66 static int terminal_rows (void); |
|
67 |
|
68 static int terminal_cols (void); |
|
69 |
|
70 static void clear_screen (void); |
|
71 |
3281
|
72 static void resize_terminal (void); |
|
73 |
3504
|
74 static std::string decode_prompt_string (const std::string& s); |
2926
|
75 |
|
76 static void restore_terminal_state (void); |
|
77 |
|
78 static void blink_matching_paren (bool flag); |
|
79 |
4055
|
80 static void set_basic_word_break_characters (const std::string& s); |
3933
|
81 |
4055
|
82 static void set_completer_word_break_characters (const std::string& s); |
3933
|
83 |
3504
|
84 static void set_basic_quote_characters (const std::string& s); |
2926
|
85 |
|
86 static void set_completion_append_character (char c); |
|
87 |
2941
|
88 static void set_completion_function (completion_fcn f); |
|
89 |
|
90 static completion_fcn get_completion_function (void); |
2926
|
91 |
4604
|
92 static string_vector generate_filename_completions (const std::string& text); |
|
93 |
3504
|
94 static void insert_text (const std::string& text); |
2926
|
95 |
|
96 static void newline (void); |
|
97 |
|
98 static void clear_undo_list (void); |
|
99 |
3519
|
100 static void set_startup_hook (startup_hook_fcn f); |
2926
|
101 |
|
102 static void restore_startup_hook (void); |
|
103 |
3519
|
104 static void set_event_hook (event_hook_fcn f); |
3215
|
105 |
|
106 static void restore_event_hook (void); |
|
107 |
3504
|
108 static void read_init_file (const std::string& file = std::string ()); |
3189
|
109 |
4143
|
110 static bool filename_completion_desired (bool); |
|
111 |
2926
|
112 static int current_command_number (void); |
|
113 |
|
114 static void reset_current_command_number (int n); |
|
115 |
2967
|
116 static void increment_current_command_number (void); |
|
117 |
2926
|
118 private: |
|
119 |
|
120 // No copying! |
|
121 |
|
122 command_editor (const command_editor&); |
|
123 |
|
124 command_editor& operator = (const command_editor&); |
|
125 |
|
126 static bool instance_ok (void); |
|
127 |
|
128 static void make_command_editor (void); |
|
129 |
|
130 // The real thing. |
|
131 static command_editor *instance; |
|
132 |
|
133 protected: |
|
134 |
|
135 // To use something other than the GNU readline library, derive a new |
|
136 // class from command_editor, overload these functions as |
|
137 // necessary, and make instance point to the new class. |
|
138 |
3504
|
139 virtual void do_set_name (const std::string&) { } |
2926
|
140 |
3504
|
141 std::string do_readline (const std::string& prompt) |
3219
|
142 { |
|
143 bool eof; |
|
144 |
|
145 return do_readline (prompt, eof); |
|
146 } |
|
147 |
3504
|
148 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926
|
149 |
|
150 virtual void do_set_input_stream (FILE *) = 0; |
|
151 |
|
152 virtual FILE *do_get_input_stream (void) = 0; |
|
153 |
|
154 virtual void do_set_output_stream (FILE *) = 0; |
|
155 |
|
156 virtual FILE *do_get_output_stream (void) = 0; |
|
157 |
|
158 virtual int do_terminal_rows (void) { return 24; } |
|
159 |
|
160 virtual int do_terminal_cols (void) { return 80; } |
|
161 |
|
162 virtual void do_clear_screen (void) { } |
|
163 |
3281
|
164 virtual void do_resize_terminal (void) { } |
|
165 |
3504
|
166 virtual std::string do_decode_prompt_string (const std::string&); |
2926
|
167 |
3504
|
168 virtual std::string newline_chars (void) { return "\n"; } |
2926
|
169 |
|
170 virtual void do_restore_terminal_state (void) { } |
|
171 |
|
172 virtual void do_blink_matching_paren (bool) { } |
|
173 |
3933
|
174 virtual void do_set_basic_word_break_characters (const std::string&) { } |
|
175 |
|
176 virtual void do_set_completer_word_break_characters (const std::string&) { } |
|
177 |
3504
|
178 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926
|
179 |
|
180 virtual void do_set_completion_append_character (char) { } |
|
181 |
2941
|
182 virtual void do_set_completion_function (completion_fcn) { } |
|
183 |
|
184 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926
|
185 |
4604
|
186 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
|
187 |
3504
|
188 virtual void do_insert_text (const std::string&) = 0; |
2926
|
189 |
|
190 virtual void do_newline (void) = 0; |
|
191 |
|
192 virtual void do_clear_undo_list (void) { } |
|
193 |
3519
|
194 virtual void do_set_startup_hook (startup_hook_fcn) { } |
2926
|
195 |
|
196 virtual void do_restore_startup_hook (void) { } |
|
197 |
3519
|
198 virtual void do_set_event_hook (event_hook_fcn) { } |
3215
|
199 |
|
200 virtual void do_restore_event_hook (void) { } |
|
201 |
3504
|
202 virtual void do_read_init_file (const std::string&) { } |
3189
|
203 |
4143
|
204 virtual bool do_filename_completion_desired (bool) { return false; } |
|
205 |
3504
|
206 int read_octal (const std::string& s); |
2926
|
207 |
|
208 void error (int); |
|
209 |
3504
|
210 void error (const std::string&); |
2926
|
211 |
|
212 // The current command number. |
|
213 int command_number; |
|
214 }; |
|
215 |
|
216 #endif |
|
217 |
|
218 /* |
|
219 ;;; Local Variables: *** |
|
220 ;;; mode: C++ *** |
|
221 ;;; End: *** |
|
222 */ |