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);
146 generate_filename_completions (
const std::string& text);
148 static std::string get_line_buffer (
void);
150 static std::string get_current_line (
void);
152 static char get_prev_char (
int);
154 static void replace_line (
const std::string& text,
bool clear_undo =
true);
156 static void kill_full_line (
void);
158 static void insert_text (
const std::string& text);
160 static void newline (
void);
162 static void accept_line (
void);
164 static bool undo (
void);
166 static void clear_undo_list (
void);
168 static void add_startup_hook (startup_hook_fcn
f);
170 static void remove_startup_hook (startup_hook_fcn
f);
172 static void add_pre_input_hook (pre_input_hook_fcn
f);
174 static void remove_pre_input_hook (pre_input_hook_fcn
f);
176 static void add_event_hook (event_hook_fcn
f);
178 static void remove_event_hook (event_hook_fcn
f);
180 static void run_event_hooks (
void);
182 static void read_init_file (
const std::string& file =
"");
184 static void re_read_init_file (
void);
186 static bool filename_completion_desired (
bool);
188 static bool filename_quoting_desired (
bool);
190 static bool prefer_env_winsize (
bool);
192 static bool interrupt (
bool =
true);
194 static void interrupt_event_loop (
bool flag =
true);
196 static bool event_loop_interrupted (
void);
198 static int current_command_number (
void);
200 static void reset_current_command_number (
int n);
202 static void increment_current_command_number (
void);
204 static void force_default_editor (
void);
206 static void set_initial_input (
const std::string& text);
208 static int insert_initial_input (
void);
212 static bool instance_ok (
void);
214 static void make_command_editor (
void);
216 static int startup_handler (
void);
218 static int pre_input_handler (
void);
220 static int event_handler (
void);
225 s_instance =
nullptr;
228 static void handle_interrupt_signal (
void);
250 return do_readline (prompt, eof);
279 virtual std::string do_decode_prompt_string (
const std::string&);
381 {
return m_interrupt_event_loop; }
383 int do_insert_initial_input (
void);
385 int read_octal (
const std::string& s);
389 void error (
const std::string&);
virtual string_vector do_generate_filename_completions(const std::string &text)=0
static void cleanup_instance(void)
virtual void restore_event_hook(void)
static std::set< pre_input_hook_fcn > m_pre_input_hook_set
static command_editor * s_instance
virtual void do_set_screen_size(int ht, int wd)
virtual void do_resize_terminal(void)
virtual bool do_erase_empty_line(bool)
virtual void do_set_basic_quote_characters(const std::string &)
std::string do_readline(const std::string &prompt)
virtual void do_set_user_accept_line_function(user_accept_line_fcn)
virtual void do_set_name(const std::string &)
virtual char do_get_prev_char(int) const =0
virtual void do_set_filename_quote_characters(const std::string &)
virtual void do_set_completer_word_break_characters(const std::string &)
virtual void do_set_input_stream(FILE *)=0
virtual std::string do_get_current_line(void) const =0
std::string m_initial_input
command_editor(const command_editor &)=delete
virtual quoting_fcn do_get_quoting_function(void) const
virtual void do_read_init_file(const std::string &)
virtual void do_set_completion_append_character(char)
virtual bool do_filename_completion_desired(bool)
static std::set< event_hook_fcn > m_event_hook_set
bool m_interrupt_event_loop
virtual void do_replace_line(const std::string &text, bool clear_undo)=0
virtual void do_set_output_stream(FILE *)=0
virtual bool do_undo(void)
void do_interrupt_event_loop(bool arg)
virtual void do_set_completer_word_break_hook(completion_hook_fcn)
virtual void do_set_quoting_function(quoting_fcn)
virtual void do_restore_terminal_state(void)
virtual user_accept_line_fcn do_get_user_accept_line_function(void) const
virtual void do_set_char_is_quoted_function(char_is_quoted_fcn)
virtual void restore_pre_input_hook(void)
virtual std::string do_get_line_buffer(void) const =0
virtual char_is_quoted_fcn do_get_char_is_quoted_function(void) const
virtual FILE * do_get_output_stream(void)=0
virtual void do_interrupt(bool)
static std::set< startup_hook_fcn > m_startup_hook_set
virtual int do_terminal_rows(void)
virtual void do_clear_screen(bool)
virtual void do_accept_line(void)=0
virtual void do_set_basic_word_break_characters(const std::string &)
virtual void do_set_completion_function(completion_fcn)
virtual void do_blink_matching_paren(bool)
virtual void do_clear_undo_list(void)
bool do_event_loop_interrupted(void) const
virtual std::string newline_chars(void)
virtual void do_re_read_init_file(void)
virtual ~command_editor(void)=default
virtual completion_fcn do_get_completion_function(void) const
virtual dequoting_fcn do_get_dequoting_function(void) const
virtual void do_insert_text(const std::string &text)=0
virtual void do_newline(void)=0
virtual void do_kill_full_line(void)=0
virtual void do_handle_interrupt_signal(void)
virtual void do_redisplay(void)
virtual void set_pre_input_hook(pre_input_hook_fcn)
virtual bool do_prefer_env_winsize(bool)
virtual void do_set_completer_quote_characters(const std::string &)
virtual int do_terminal_cols(void)
virtual void restore_startup_hook(void)
virtual bool do_filename_quoting_desired(bool)
virtual void do_set_dequoting_function(dequoting_fcn)
virtual FILE * do_get_input_stream(void)=0
virtual void set_event_hook(event_hook_fcn)
virtual std::string do_readline(const std::string &, bool &)=0
virtual void set_startup_hook(startup_hook_fcn)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
F77_RET_T const F77_DBLE const F77_DBLE * f