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