comparison liboctave/util/cmd-edit.h @ 31607:aac27ad79be6 stable

maint: Re-indent code after switch to using namespace macros. * build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc, __ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc, __pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc, debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc, gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h, oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h, octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc, gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc, ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h, octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc, op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h: Re-indent code after switch to using namespace macros.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 18:02:15 -0800
parents e88a07dec498
children 597f3ee61a48
comparison
equal deleted inserted replaced
31605:e88a07dec498 31607:aac27ad79be6
35 35
36 #include "str-vec.h" 36 #include "str-vec.h"
37 37
38 OCTAVE_BEGIN_NAMESPACE(octave) 38 OCTAVE_BEGIN_NAMESPACE(octave)
39 39
40 class 40 class
41 OCTAVE_API 41 OCTAVE_API
42 command_editor 42 command_editor
43 {
44 protected:
45
46 command_editor (void)
47 : m_command_number (1), m_rows (24), m_cols (80), m_interrupted (false),
48 m_interrupt_event_loop (false), m_initial_input ()
49 { }
50
51 public:
52
53 typedef int (*startup_hook_fcn) (void);
54
55 typedef int (*pre_input_hook_fcn) (void);
56
57 typedef int (*event_hook_fcn) (void);
58
59 typedef std::string (*completion_fcn) (const std::string&, int);
60
61 typedef char *(*completion_hook_fcn) ();
62
63 typedef std::string (*quoting_fcn) (const std::string&, int, char);
64
65 typedef std::string (*dequoting_fcn) (const std::string&, int);
66
67 typedef int (*char_is_quoted_fcn) (const std::string&, int);
68
69 typedef void (*user_accept_line_fcn) (const std::string&);
70
71 // No copying!
72
73 command_editor (const command_editor&) = delete;
74
75 command_editor& operator = (const command_editor&) = delete;
76
77 virtual ~command_editor (void) = default;
78
79 static void set_name (const std::string& n);
80
81 static std::string readline (const std::string& prompt);
82
83 static std::string readline (const std::string& prompt, bool& eof);
84
85 static void set_input_stream (FILE *f);
86
87 static FILE * get_input_stream (void);
88
89 static void set_output_stream (FILE *f);
90
91 static FILE * get_output_stream (void);
92
93 static void redisplay (void);
94
95 static int terminal_rows (void);
96
97 static int terminal_cols (void);
98
99 static void clear_screen (bool skip_redisplay = false);
100
101 static void resize_terminal (void);
102
103 static void set_screen_size (int ht, int wd);
104
105 static std::string decode_prompt_string (const std::string& s);
106
107 static void restore_terminal_state (void);
108
109 static void blink_matching_paren (bool flag);
110
111 static bool erase_empty_line (bool flag);
112
113 static void set_basic_word_break_characters (const std::string& s);
114
115 static void set_completer_word_break_characters (const std::string& s);
116
117 static void set_basic_quote_characters (const std::string& s);
118
119 static void set_filename_quote_characters (const std::string& s);
120
121 static void set_completer_quote_characters (const std::string& s);
122
123 static void set_completion_append_character (char c);
124
125 static void set_completion_function (completion_fcn f);
126
127 static void set_quoting_function (quoting_fcn f);
128
129 static void set_dequoting_function (dequoting_fcn f);
130
131 static void set_char_is_quoted_function (char_is_quoted_fcn f);
132
133 static void set_user_accept_line_function (user_accept_line_fcn f);
134
135 static completion_fcn get_completion_function (void);
136
137 static quoting_fcn get_quoting_function (void);
138
139 static dequoting_fcn get_dequoting_function (void);
140
141 static char_is_quoted_fcn get_char_is_quoted_function (void);
142
143 static user_accept_line_fcn get_user_accept_line_function (void);
144
145 static string_vector
146 generate_filename_completions (const std::string& text);
147
148 static std::string get_line_buffer (void);
149
150 static std::string get_current_line (void);
151
152 static char get_prev_char (int);
153
154 static void replace_line (const std::string& text, bool clear_undo = true);
155
156 static void kill_full_line (void);
157
158 static void insert_text (const std::string& text);
159
160 static void newline (void);
161
162 static void accept_line (void);
163
164 static bool undo (void);
165
166 static void clear_undo_list (void);
167
168 static void add_startup_hook (startup_hook_fcn f);
169
170 static void remove_startup_hook (startup_hook_fcn f);
171
172 static void add_pre_input_hook (pre_input_hook_fcn f);
173
174 static void remove_pre_input_hook (pre_input_hook_fcn f);
175
176 static void add_event_hook (event_hook_fcn f);
177
178 static void remove_event_hook (event_hook_fcn f);
179
180 static void run_event_hooks (void);
181
182 static void read_init_file (const std::string& file = "");
183
184 static void re_read_init_file (void);
185
186 static bool filename_completion_desired (bool);
187
188 static bool filename_quoting_desired (bool);
189
190 static bool prefer_env_winsize (bool);
191
192 static bool interrupt (bool = true);
193
194 static void interrupt_event_loop (bool flag = true);
195
196 static bool event_loop_interrupted (void);
197
198 static int current_command_number (void);
199
200 static void reset_current_command_number (int n);
201
202 static void increment_current_command_number (void);
203
204 static void force_default_editor (void);
205
206 static void set_initial_input (const std::string& text);
207
208 static int insert_initial_input (void);
209
210 private:
211
212 static bool instance_ok (void);
213
214 static void make_command_editor (void);
215
216 static int startup_handler (void);
217
218 static int pre_input_handler (void);
219
220 static int event_handler (void);
221
222 static void cleanup_instance (void)
43 { 223 {
44 protected: 224 delete s_instance;
45 225 s_instance = nullptr;
46 command_editor (void) 226 }
47 : m_command_number (1), m_rows (24), m_cols (80), m_interrupted (false), 227
48 m_interrupt_event_loop (false), m_initial_input () 228 static void handle_interrupt_signal (void);
49 { } 229
50 230 //--------
51 public: 231
52 232 static command_editor *s_instance; // the real thing.
53 typedef int (*startup_hook_fcn) (void); 233
54 234 static std::set<startup_hook_fcn> m_startup_hook_set;
55 typedef int (*pre_input_hook_fcn) (void); 235 static std::set<pre_input_hook_fcn> m_pre_input_hook_set;
56 236 static std::set<event_hook_fcn> m_event_hook_set;
57 typedef int (*event_hook_fcn) (void); 237
58 238 protected:
59 typedef std::string (*completion_fcn) (const std::string&, int); 239
60 240 // To use something other than the GNU readline library, derive a new
61 typedef char * (*completion_hook_fcn) (); 241 // class from command_editor, overload these functions as
62 242 // necessary, and make instance point to the new class.
63 typedef std::string (*quoting_fcn) (const std::string&, int, char); 243
64 244 virtual void do_set_name (const std::string&) { }
65 typedef std::string (*dequoting_fcn) (const std::string&, int); 245
66 246 std::string do_readline (const std::string& prompt)
67 typedef int (*char_is_quoted_fcn) (const std::string&, int); 247 {
68 248 bool eof;
69 typedef void (*user_accept_line_fcn) (const std::string&); 249
70 250 return do_readline (prompt, eof);
71 // No copying! 251 }
72 252
73 command_editor (const command_editor&) = delete; 253 virtual std::string do_readline (const std::string&, bool&) = 0;
74 254
75 command_editor& operator = (const command_editor&) = delete; 255 virtual void do_set_input_stream (FILE *) = 0;
76 256
77 virtual ~command_editor (void) = default; 257 virtual FILE * do_get_input_stream (void) = 0;
78 258
79 static void set_name (const std::string& n); 259 virtual void do_set_output_stream (FILE *) = 0;
80 260
81 static std::string readline (const std::string& prompt); 261 virtual FILE * do_get_output_stream (void) = 0;
82 262
83 static std::string readline (const std::string& prompt, bool& eof); 263 virtual void do_redisplay (void) { }
84 264
85 static void set_input_stream (FILE *f); 265 virtual int do_terminal_rows (void) { return m_rows; }
86 266
87 static FILE * get_input_stream (void); 267 virtual int do_terminal_cols (void) { return m_cols; }
88 268
89 static void set_output_stream (FILE *f); 269 virtual void do_clear_screen (bool) { }
90 270
91 static FILE * get_output_stream (void); 271 virtual void do_resize_terminal (void) { }
92 272
93 static void redisplay (void); 273 virtual void do_set_screen_size (int ht, int wd)
94 274 {
95 static int terminal_rows (void); 275 m_rows = ht;
96 276 m_cols = wd;
97 static int terminal_cols (void); 277 }
98 278
99 static void clear_screen (bool skip_redisplay = false); 279 virtual std::string do_decode_prompt_string (const std::string&);
100 280
101 static void resize_terminal (void); 281 virtual std::string newline_chars (void) { return "\n"; }
102 282
103 static void set_screen_size (int ht, int wd); 283 virtual void do_restore_terminal_state (void) { }
104 284
105 static std::string decode_prompt_string (const std::string& s); 285 virtual void do_blink_matching_paren (bool) { }
106 286
107 static void restore_terminal_state (void); 287 virtual bool do_erase_empty_line (bool) { return false; }
108 288
109 static void blink_matching_paren (bool flag); 289 virtual void do_set_basic_word_break_characters (const std::string&) { }
110 290
111 static bool erase_empty_line (bool flag); 291 virtual void do_set_completer_word_break_characters (const std::string&) { }
112 292
113 static void set_basic_word_break_characters (const std::string& s); 293 virtual void do_set_completer_word_break_hook (completion_hook_fcn) { }
114 294
115 static void set_completer_word_break_characters (const std::string& s); 295 virtual void do_set_basic_quote_characters (const std::string&) { }
116 296
117 static void set_basic_quote_characters (const std::string& s); 297 virtual void do_set_filename_quote_characters (const std::string&) { }
118 298
119 static void set_filename_quote_characters (const std::string& s); 299 virtual void do_set_completer_quote_characters (const std::string&) { }
120 300
121 static void set_completer_quote_characters (const std::string& s); 301 virtual void do_set_completion_append_character (char) { }
122 302
123 static void set_completion_append_character (char c); 303 virtual void do_set_completion_function (completion_fcn) { }
124 304
125 static void set_completion_function (completion_fcn f); 305 virtual void do_set_quoting_function (quoting_fcn) { }
126 306
127 static void set_quoting_function (quoting_fcn f); 307 virtual void do_set_dequoting_function (dequoting_fcn) { }
128 308
129 static void set_dequoting_function (dequoting_fcn f); 309 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { }
130 310
131 static void set_char_is_quoted_function (char_is_quoted_fcn f); 311 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { }
132 312
133 static void set_user_accept_line_function (user_accept_line_fcn f); 313 virtual completion_fcn do_get_completion_function (void) const
134 314 { return nullptr; }
135 static completion_fcn get_completion_function (void); 315
136 316 virtual quoting_fcn do_get_quoting_function (void) const
137 static quoting_fcn get_quoting_function (void); 317 { return nullptr; }
138 318
139 static dequoting_fcn get_dequoting_function (void); 319 virtual dequoting_fcn do_get_dequoting_function (void) const
140 320 { return nullptr; }
141 static char_is_quoted_fcn get_char_is_quoted_function (void); 321
142 322 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const
143 static user_accept_line_fcn get_user_accept_line_function (void); 323 { return nullptr; }
144 324
145 static string_vector 325 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const
146 generate_filename_completions (const std::string& text); 326 { return nullptr; }
147 327
148 static std::string get_line_buffer (void); 328 virtual string_vector
149 329 do_generate_filename_completions (const std::string& text) = 0;
150 static std::string get_current_line (void); 330
151 331 virtual std::string do_get_line_buffer (void) const = 0;
152 static char get_prev_char (int); 332
153 333 virtual std::string do_get_current_line (void) const = 0;
154 static void replace_line (const std::string& text, bool clear_undo = true); 334
155 335 virtual char do_get_prev_char (int) const = 0;
156 static void kill_full_line (void); 336
157 337 virtual void
158 static void insert_text (const std::string& text); 338 do_replace_line (const std::string& text, bool clear_undo) = 0;
159 339
160 static void newline (void); 340 virtual void do_kill_full_line (void) = 0;
161 341
162 static void accept_line (void); 342 virtual void do_insert_text (const std::string& text) = 0;
163 343
164 static bool undo (void); 344 virtual void do_newline (void) = 0;
165 345
166 static void clear_undo_list (void); 346 virtual void do_accept_line (void) = 0;
167 347
168 static void add_startup_hook (startup_hook_fcn f); 348 virtual bool do_undo (void) { return false; }
169 349
170 static void remove_startup_hook (startup_hook_fcn f); 350 virtual void do_clear_undo_list (void) { }
171 351
172 static void add_pre_input_hook (pre_input_hook_fcn f); 352 virtual void set_startup_hook (startup_hook_fcn) { }
173 353
174 static void remove_pre_input_hook (pre_input_hook_fcn f); 354 virtual void restore_startup_hook (void) { }
175 355
176 static void add_event_hook (event_hook_fcn f); 356 virtual void set_pre_input_hook (pre_input_hook_fcn) { }
177 357
178 static void remove_event_hook (event_hook_fcn f); 358 virtual void restore_pre_input_hook (void) { }
179 359
180 static void run_event_hooks (void); 360 virtual void set_event_hook (event_hook_fcn) { }
181 361
182 static void read_init_file (const std::string& file = ""); 362 virtual void restore_event_hook (void) { }
183 363
184 static void re_read_init_file (void); 364 virtual void do_read_init_file (const std::string&) { }
185 365
186 static bool filename_completion_desired (bool); 366 virtual void do_re_read_init_file (void) { }
187 367
188 static bool filename_quoting_desired (bool); 368 virtual bool do_filename_completion_desired (bool) { return false; }
189 369
190 static bool prefer_env_winsize (bool); 370 virtual bool do_filename_quoting_desired (bool) { return false; }
191 371
192 static bool interrupt (bool = true); 372 virtual bool do_prefer_env_winsize (bool) { return false; }
193 373
194 static void interrupt_event_loop (bool flag = true); 374 virtual void do_interrupt (bool) { }
195 375
196 static bool event_loop_interrupted (void); 376 virtual void do_handle_interrupt_signal (void) { }
197 377
198 static int current_command_number (void); 378 void do_interrupt_event_loop (bool arg) { m_interrupt_event_loop = arg; }
199 379
200 static void reset_current_command_number (int n); 380 bool do_event_loop_interrupted (void) const
201 381 { return m_interrupt_event_loop; }
202 static void increment_current_command_number (void); 382
203 383 int do_insert_initial_input (void);
204 static void force_default_editor (void); 384
205 385 int read_octal (const std::string& s);
206 static void set_initial_input (const std::string& text); 386
207 387 void error (int);
208 static int insert_initial_input (void); 388
209 389 void error (const std::string&);
210 private: 390
211 391 // The current command number.
212 static bool instance_ok (void); 392 int m_command_number;
213 393
214 static void make_command_editor (void); 394 int m_rows;
215 395 int m_cols;
216 static int startup_handler (void); 396
217 397 bool m_interrupted;
218 static int pre_input_handler (void); 398
219 399 bool m_interrupt_event_loop;
220 static int event_handler (void); 400
221 401 std::string m_initial_input;
222 static void cleanup_instance (void) 402 };
223 {
224 delete s_instance;
225 s_instance = nullptr;
226 }
227
228 static void handle_interrupt_signal (void);
229
230 //--------
231
232 static command_editor *s_instance; // the real thing.
233
234 static std::set<startup_hook_fcn> m_startup_hook_set;
235 static std::set<pre_input_hook_fcn> m_pre_input_hook_set;
236 static std::set<event_hook_fcn> m_event_hook_set;
237
238 protected:
239
240 // To use something other than the GNU readline library, derive a new
241 // class from command_editor, overload these functions as
242 // necessary, and make instance point to the new class.
243
244 virtual void do_set_name (const std::string&) { }
245
246 std::string do_readline (const std::string& prompt)
247 {
248 bool eof;
249
250 return do_readline (prompt, eof);
251 }
252
253 virtual std::string do_readline (const std::string&, bool&) = 0;
254
255 virtual void do_set_input_stream (FILE *) = 0;
256
257 virtual FILE * do_get_input_stream (void) = 0;
258
259 virtual void do_set_output_stream (FILE *) = 0;
260
261 virtual FILE * do_get_output_stream (void) = 0;
262
263 virtual void do_redisplay (void) { }
264
265 virtual int do_terminal_rows (void) { return m_rows; }
266
267 virtual int do_terminal_cols (void) { return m_cols; }
268
269 virtual void do_clear_screen (bool) { }
270
271 virtual void do_resize_terminal (void) { }
272
273 virtual void do_set_screen_size (int ht, int wd)
274 {
275 m_rows = ht;
276 m_cols = wd;
277 }
278
279 virtual std::string do_decode_prompt_string (const std::string&);
280
281 virtual std::string newline_chars (void) { return "\n"; }
282
283 virtual void do_restore_terminal_state (void) { }
284
285 virtual void do_blink_matching_paren (bool) { }
286
287 virtual bool do_erase_empty_line (bool) { return false; }
288
289 virtual void do_set_basic_word_break_characters (const std::string&) { }
290
291 virtual void do_set_completer_word_break_characters (const std::string&) { }
292
293 virtual void do_set_completer_word_break_hook (completion_hook_fcn) { }
294
295 virtual void do_set_basic_quote_characters (const std::string&) { }
296
297 virtual void do_set_filename_quote_characters (const std::string&) { }
298
299 virtual void do_set_completer_quote_characters (const std::string&) { }
300
301 virtual void do_set_completion_append_character (char) { }
302
303 virtual void do_set_completion_function (completion_fcn) { }
304
305 virtual void do_set_quoting_function (quoting_fcn) { }
306
307 virtual void do_set_dequoting_function (dequoting_fcn) { }
308
309 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { }
310
311 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { }
312
313 virtual completion_fcn do_get_completion_function (void) const
314 { return nullptr; }
315
316 virtual quoting_fcn do_get_quoting_function (void) const
317 { return nullptr; }
318
319 virtual dequoting_fcn do_get_dequoting_function (void) const
320 { return nullptr; }
321
322 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const
323 { return nullptr; }
324
325 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const
326 { return nullptr; }
327
328 virtual string_vector
329 do_generate_filename_completions (const std::string& text) = 0;
330
331 virtual std::string do_get_line_buffer (void) const = 0;
332
333 virtual std::string do_get_current_line (void) const = 0;
334
335 virtual char do_get_prev_char (int) const = 0;
336
337 virtual void
338 do_replace_line (const std::string& text, bool clear_undo) = 0;
339
340 virtual void do_kill_full_line (void) = 0;
341
342 virtual void do_insert_text (const std::string& text) = 0;
343
344 virtual void do_newline (void) = 0;
345
346 virtual void do_accept_line (void) = 0;
347
348 virtual bool do_undo (void) { return false; }
349
350 virtual void do_clear_undo_list (void) { }
351
352 virtual void set_startup_hook (startup_hook_fcn) { }
353
354 virtual void restore_startup_hook (void) { }
355
356 virtual void set_pre_input_hook (pre_input_hook_fcn) { }
357
358 virtual void restore_pre_input_hook (void) { }
359
360 virtual void set_event_hook (event_hook_fcn) { }
361
362 virtual void restore_event_hook (void) { }
363
364 virtual void do_read_init_file (const std::string&) { }
365
366 virtual void do_re_read_init_file (void) { }
367
368 virtual bool do_filename_completion_desired (bool) { return false; }
369
370 virtual bool do_filename_quoting_desired (bool) { return false; }
371
372 virtual bool do_prefer_env_winsize (bool) { return false; }
373
374 virtual void do_interrupt (bool) { }
375
376 virtual void do_handle_interrupt_signal (void) { }
377
378 void do_interrupt_event_loop (bool arg) { m_interrupt_event_loop = arg; }
379
380 bool do_event_loop_interrupted (void) const
381 { return m_interrupt_event_loop; }
382
383 int do_insert_initial_input (void);
384
385 int read_octal (const std::string& s);
386
387 void error (int);
388
389 void error (const std::string&);
390
391 // The current command number.
392 int m_command_number;
393
394 int m_rows;
395 int m_cols;
396
397 bool m_interrupted;
398
399 bool m_interrupt_event_loop;
400
401 std::string m_initial_input;
402 };
403 403
404 OCTAVE_END_NAMESPACE(octave) 404 OCTAVE_END_NAMESPACE(octave)
405 405
406 #endif 406 #endif