26 #if ! defined (octave_cmd_edit_h)
27 #define octave_cmd_edit_h 1
29 #include "octave-config.h"
47 : m_command_number (1), m_rows (24), m_cols (80), m_interrupted (false),
48 m_interrupt_event_loop (false), m_initial_input ()
53 typedef int (*startup_hook_fcn) (void);
55 typedef int (*pre_input_hook_fcn) (void);
57 typedef int (*event_hook_fcn) (void);
59 typedef std::string (*completion_fcn) (
const std::string&, int);
61 typedef char * (*completion_hook_fcn) ();
63 typedef std::string (*quoting_fcn) (
const std::string&, int, char);
65 typedef std::string (*dequoting_fcn) (
const std::string&, int);
67 typedef int (*char_is_quoted_fcn) (
const std::string&, int);
69 typedef void (*user_accept_line_fcn) (
const std::string&);
79 static void set_name (
const std::string&
n);
81 static std::string readline (
const std::string& prompt);
83 static std::string readline (
const std::string& prompt,
bool& eof);
85 static void set_input_stream (FILE *
f);
87 static FILE * get_input_stream (
void);
89 static void set_output_stream (FILE *
f);
91 static FILE * get_output_stream (
void);
93 static void redisplay (
void);
95 static int terminal_rows (
void);
97 static int terminal_cols (
void);
99 static void clear_screen (
bool skip_redisplay =
false);
101 static void resize_terminal (
void);
103 static void set_screen_size (
int ht,
int wd);
105 static std::string decode_prompt_string (
const std::string& s);
107 static void restore_terminal_state (
void);
109 static void blink_matching_paren (
bool flag);
111 static bool erase_empty_line (
bool flag);
113 static void set_basic_word_break_characters (
const std::string& s);
115 static void set_completer_word_break_characters (
const std::string& s);
117 static void set_basic_quote_characters (
const std::string& s);
119 static void set_filename_quote_characters (
const std::string& s);
121 static void set_completer_quote_characters (
const std::string& s);
123 static void set_completion_append_character (
char c);
125 static void set_completion_function (completion_fcn
f);
127 static void set_quoting_function (quoting_fcn
f);
129 static void set_dequoting_function (dequoting_fcn
f);
131 static void set_char_is_quoted_function (char_is_quoted_fcn
f);
133 static void set_user_accept_line_function (user_accept_line_fcn
f);
135 static completion_fcn get_completion_function (
void);
137 static quoting_fcn get_quoting_function (
void);
139 static dequoting_fcn get_dequoting_function (
void);
141 static char_is_quoted_fcn get_char_is_quoted_function (
void);
143 static user_accept_line_fcn get_user_accept_line_function (
void);
147 static std::string get_line_buffer (
void);
149 static std::string get_current_line (
void);
151 static char get_prev_char (
int);
153 static void replace_line (
const std::string&
text,
bool clear_undo =
true);
155 static void kill_full_line (
void);
157 static void insert_text (
const std::string&
text);
159 static void newline (
void);
161 static void accept_line (
void);
163 static bool undo (
void);
165 static void clear_undo_list (
void);
167 static void add_startup_hook (startup_hook_fcn
f);
169 static void remove_startup_hook (startup_hook_fcn
f);
171 static void add_pre_input_hook (pre_input_hook_fcn
f);
173 static void remove_pre_input_hook (pre_input_hook_fcn
f);
175 static void add_event_hook (event_hook_fcn
f);
177 static void remove_event_hook (event_hook_fcn
f);
179 static void run_event_hooks (
void);
181 static void read_init_file (
const std::string& file =
"");
183 static void re_read_init_file (
void);
185 static bool filename_completion_desired (
bool);
187 static bool filename_quoting_desired (
bool);
189 static bool prefer_env_winsize (
bool);
191 static bool interrupt (
bool =
true);
193 static void interrupt_event_loop (
bool flag =
true);
195 static bool event_loop_interrupted (
void);
197 static int current_command_number (
void);
199 static void reset_current_command_number (
int n);
201 static void increment_current_command_number (
void);
203 static void force_default_editor (
void);
205 static void set_initial_input (
const std::string&
text);
207 static int insert_initial_input (
void);
211 static bool instance_ok (
void);
213 static void make_command_editor (
void);
215 static int startup_handler (
void);
217 static int pre_input_handler (
void);
219 static int event_handler (
void);
233 s_instance =
nullptr;
236 static void handle_interrupt_signal (
void);
250 return do_readline (prompt, eof);
279 virtual std::string do_decode_prompt_string (
const std::string&);
378 return m_interrupt_event_loop;
381 int do_insert_initial_input (
void);
383 int read_octal (
const std::string& s);
387 void error (
const std::string&);
virtual quoting_fcn do_get_quoting_function(void) const
static std::set< pre_input_hook_fcn > pre_input_hook_set
virtual bool do_undo(void)
virtual void do_kill_full_line(void)=0
virtual void do_set_dequoting_function(dequoting_fcn)
virtual std::string do_readline(const std::string &, bool &)=0
virtual void do_newline(void)=0
virtual void do_resize_terminal(void)
std::string m_initial_input
void do_interrupt_event_loop(bool arg)
bool m_interrupt_event_loop
virtual void do_set_quoting_function(quoting_fcn)
virtual void set_startup_hook(startup_hook_fcn)
virtual bool do_filename_quoting_desired(bool)
virtual void do_set_output_stream(FILE *)=0
virtual void restore_startup_hook(void)
static std::set< startup_hook_fcn > startup_hook_set
virtual void do_restore_terminal_state(void)
virtual completion_fcn do_get_completion_function(void) const
static void cleanup_instance(void)
virtual void do_insert_text(const std::string &text)=0
static command_editor * s_instance
virtual FILE * do_get_output_stream(void)=0
virtual dequoting_fcn do_get_dequoting_function(void) const
virtual void set_pre_input_hook(pre_input_hook_fcn)
virtual void do_accept_line(void)=0
virtual void do_set_input_stream(FILE *)=0
virtual string_vector do_generate_filename_completions(const std::string &text)=0
virtual void do_set_completer_word_break_characters(const std::string &)
virtual void do_set_char_is_quoted_function(char_is_quoted_fcn)
virtual char do_get_prev_char(int) const =0
virtual void set_event_hook(event_hook_fcn)
virtual void do_set_name(const std::string &)
virtual char_is_quoted_fcn do_get_char_is_quoted_function(void) const
virtual int do_terminal_cols(void)
static std::set< event_hook_fcn > event_hook_set
virtual void restore_pre_input_hook(void)
virtual std::string newline_chars(void)
virtual std::string do_get_current_line(void) const =0
virtual void do_set_completion_function(completion_fcn)
virtual ~command_editor(void)=default
virtual void do_set_screen_size(int ht, int wd)
virtual void do_re_read_init_file(void)
virtual void do_clear_screen(bool)
std::string do_readline(const std::string &prompt)
virtual void restore_event_hook(void)
virtual bool do_prefer_env_winsize(bool)
virtual void do_set_filename_quote_characters(const std::string &)
virtual FILE * do_get_input_stream(void)=0
virtual void do_set_completion_append_character(char)
virtual void do_clear_undo_list(void)
virtual void do_read_init_file(const std::string &)
virtual std::string do_get_line_buffer(void) const =0
virtual void do_blink_matching_paren(bool)
virtual void do_set_user_accept_line_function(user_accept_line_fcn)
virtual void do_set_basic_quote_characters(const std::string &)
bool do_event_loop_interrupted(void) const
virtual void do_set_completer_word_break_hook(completion_hook_fcn)
virtual user_accept_line_fcn do_get_user_accept_line_function(void) const
virtual void do_replace_line(const std::string &text, bool clear_undo)=0
virtual void do_interrupt(bool)
virtual void do_set_basic_word_break_characters(const std::string &)
virtual bool do_erase_empty_line(bool)
virtual void do_handle_interrupt_signal(void)
command_editor(const command_editor &)=delete
virtual void do_redisplay(void)
virtual bool do_filename_completion_desired(bool)
virtual int do_terminal_rows(void)
virtual void do_set_completer_quote_characters(const std::string &)
void error(const char *fmt,...)
static double f(double k, double l_nu, double c_pm)