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