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