Mercurial > jwe > qt-gui-with-push-parser
view qt-interpreter.cpp @ 4:0e154787183d
new interpreter and qt_interpreter objects
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 May 2019 17:30:46 -0400 |
parents | |
children | 54edd85237ab |
line wrap: on
line source
#include <sstream> #include "gui-main.h" #include "interpreter.h" #include "qt-interpreter.h" #include <readline/readline.h> #include <readline/history.h> namespace calc { static int getc (FILE *) { int tmp = gui::available_char; gui::available_char = 0; return tmp; } static void redisplay (void) { if (gui::calc_interaction_window) gui::calc_interaction_window->redisplay (); } static void prep_term (int) { } static void deprep_term (void) { } static void accept_line (char *line) { if (gui::calc_interaction_window) gui::calc_interaction_window->accept (line ? line : ""); } static void display_completion_matches (char **matches, int num_matches, int /* max_length */) { if (gui::calc_interaction_window) { std::ostringstream buf; if (num_matches > 1) buf << "\n"; for (int i = 1; i < num_matches; i++) buf << matches[i] << "\n"; gui::calc_interaction_window->insert_at_end (buf.str ()); gui::calc_interaction_window->redisplay (); } } static void readline_init (void) { rl_initialize (); rl_getc_function = getc; rl_redisplay_function = redisplay; rl_prep_term_function = prep_term; rl_deprep_term_function = deprep_term; rl_completion_display_matches_hook = display_completion_matches; rl_callback_handler_install (">> ", accept_line); } static void readline_fini (void) { rl_callback_handler_remove (); } qt_interpreter::qt_interpreter (void) { interpreter::init (); } qt_interpreter::~qt_interpreter (void) { interpreter::fini (); readline_fini (); } void qt_interpreter::execute (void) { readline_init (); } }