diff qt-interpreter.cpp @ 5:54edd85237ab

use signal to send input to qt interpreter object
author John W. Eaton <jwe@octave.org>
date Wed, 22 May 2019 18:07:37 -0400
parents 0e154787183d
children 1b575145197e
line wrap: on
line diff
--- a/qt-interpreter.cpp	Wed May 22 17:30:46 2019 -0400
+++ b/qt-interpreter.cpp	Wed May 22 18:07:37 2019 -0400
@@ -1,5 +1,7 @@
 #include <sstream>
 
+#include <QString>
+
 #include "gui-main.h"
 #include "interpreter.h"
 #include "qt-interpreter.h"
@@ -9,70 +11,6 @@
 
 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 ();
@@ -81,12 +19,14 @@
   qt_interpreter::~qt_interpreter (void)
   {
     interpreter::fini ();
-
-    readline_fini ();
   }
 
   void qt_interpreter::execute (void)
   {
-    readline_init ();
+  }
+
+  void qt_interpreter::accept_input_line (const QString& line)
+  {
+    interpreter::parse_and_execute (line.toStdString ());
   }
 }