annotate gui-main.cpp @ 7:04867eba6428

function objects and signals/slots for errors and results
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 09:27:09 -0400
parents 54edd85237ab
children 822a2fe5bb51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 #include <iostream>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 #include <sstream>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 #include <string>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 #include <cstdlib>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 #include <cstring>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 #include <QApplication>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 #include <QKeyEvent>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 #include <QTextDocument>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 #include <QTextEdit>
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
12 #include <QTimer>
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 #include "gui-main.h"
3
52c033864347 add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
15 #include "main.h"
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 #include "gui-main.h"
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
18 #include "interpreter.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
19 #include "parser.h"
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 #include <readline/readline.h>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 #include <readline/history.h>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 namespace gui
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 {
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
26 static int available_char = 0;
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
27
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
28 static command_window *calc_interaction_window = 0;
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 static inline int ctrl (int c)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 return c & 0x1f;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
35 static int getc (FILE *)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
36 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
37 int tmp = available_char;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
38 available_char = 0;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
39 return tmp;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
40 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
41
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
42 static void redisplay (void)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
43 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
44 if (calc_interaction_window)
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
45 emit calc_interaction_window->redisplay_signal ();
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
46 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
47
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
48 static void prep_term (int)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
49 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
50 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
51
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
52 static void deprep_term (void)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
53 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
54 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
55
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
56 static void accept_line (char *line)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
57 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
58 if (calc_interaction_window)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
59 calc_interaction_window->accept_line (line ? line : "");
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
60 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
61
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
62 static void display_completion_matches (char **matches, int num_matches,
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
63 int /* max_length */)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
64 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
65 if (calc_interaction_window)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
66 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
67 std::ostringstream buf;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
68
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
69 if (num_matches > 1)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
70 buf << "\n";
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
71
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
72 for (int i = 1; i < num_matches; i++)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
73 buf << matches[i] << "\n";
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
74
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
75 calc_interaction_window->insert_at_end (buf.str ());
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
76
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
77 emit calc_interaction_window->redisplay_signal ();
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
78 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
79 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
80
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
81 static void readline_init (void)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
82 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
83 rl_initialize ();
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
84
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
85 rl_getc_function = getc;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
86 rl_redisplay_function = redisplay;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
87 rl_prep_term_function = prep_term;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
88 rl_deprep_term_function = deprep_term;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
89 rl_completion_display_matches_hook = display_completion_matches;
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
90
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
91 rl_callback_handler_install (">> ", accept_line);
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
92 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
93
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
94 static void readline_fini (void)
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
95 {
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
96 rl_callback_handler_remove ();
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
97 }
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
98
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 command_window::command_window (QWidget *p)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 : QTextEdit (p),
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 m_buffer (new QTextDocument ()),
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
102 m_interpreter (new calc::qt_interpreter ()),
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 beg_mark (), prompt_mark ()
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 setWindowTitle ("Qt::TextEdit example");
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 setMinimumSize (QSize (600, 400));
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 setDocument (m_buffer);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
111 connect (m_interpreter, SIGNAL (result_ready (double)),
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 this, SLOT (handle_result (double)));
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
114 connect (m_interpreter, SIGNAL (error_signal (const QString&)),
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
115 this, SLOT (handle_error (const QString&)));
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
116
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
117 connect (this, SIGNAL (input_char_available (int)),
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
118 this, SLOT (handle_input_char (int)));
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
119
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
120 connect (this, SIGNAL (redisplay_signal (void)),
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
121 this, SLOT (redisplay (void)));
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
122
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
123 connect (this, SIGNAL (accept_line_signal (const QString&)),
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
124 m_interpreter, SLOT (accept_input_line (const QString&)));
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
125
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 insert_at_end
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 ("Qt Example Calculator.\n"
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 "Available operations: + - * / ^ ()\n"
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 "Semicolon terminates statement.\n"
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 "Up Arrow key moves to previous line in the command history.\n"
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 "Down Arrow key moves to next line in the comand history.\n\n");
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 beg_mark = set_mark ();
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
134
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
135 // Defer initializing and executing the interpreter until after the main
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
136 // window and QApplication are running to prevent race conditions
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
137 QTimer::singleShot (0, m_interpreter, SLOT (execute (void)));
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 // Accept an input line, parse and possibly execute it.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
142 void command_window::accept_line (const std::string& line)
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 {
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
144 if (calc::debug_mode)
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
145 std::cerr << "accept: " << line << std::endl;
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
146
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 insert_at_end ("\n");
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 if (! line.empty ())
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 add_history (line.c_str ());
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 using_history ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
154 emit accept_line_signal (QString::fromStdString (line));
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
158 void command_window::insert_at_end (const std::string& text)
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
159 {
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
160 scroll_to_bottom ();
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
161
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
162 insert_at_cursor (text);
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
163 }
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
164
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
165 void command_window::handle_error (const QString& msg)
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
166 {
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
167 insert_at_end ("parse error: " + msg.toStdString () + "\n");
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
168
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
169 rl_abort (0, 0);
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
170 }
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
171
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
172 // FIXME: do we really need this extra function?
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
173 void command_window::handle_result (double value)
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
174 {
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
175 insert_result (value);
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
176 }
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
177
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 // Redisplay current command line.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 void command_window::redisplay (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 erase_line ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 std::string line = rl_line_buffer ? rl_line_buffer : "";
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 3
diff changeset
185 std::string prompt = (rl_prompt && parser::beg_of_stmt) ? rl_prompt : "";
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 insert_line (prompt, line);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 scroll_to_bottom ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 QTextCursor cursor = textCursor ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 cursor.setPosition (prompt_mark + rl_point, QTextCursor::MoveAnchor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 setTextCursor (cursor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 void command_window::keyPressEvent (QKeyEvent *event)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 if (! event)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 return;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 if (event->type () == QEvent::KeyPress)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 int key = event->key ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 switch (key)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 case Qt::Key_Return:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 key = 0x0A;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 case Qt::Key_Backspace:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 key = 0x08;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 case Qt::Key_Tab:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 key = 0x09;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 case Qt::Key_Escape:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 key = 0x1b;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 case Qt::Key_Up:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 case Qt::Key_Down:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 case Qt::Key_Right:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 case Qt::Key_Left:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 key = do_arrow_key (key);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 default:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 switch (event->modifiers ())
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 case Qt::ControlModifier:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 if (key > 0x3f && key < 0x7b)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 key &= 0x1f;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 else
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 key = -1;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 default:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 // Don't shoot me, this is just a demo...
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 QString text = event->text ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 QByteArray latin_text = text.toLatin1 ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 key = latin_text[0];
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 if (key >= 0)
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
257 emit input_char_available (key);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
261 void command_window::handle_input_char (int key)
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
262 {
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
263 available_char = key;
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
264 rl_callback_read_char ();
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
265 }
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
266
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267 int command_window::do_arrow_key (int arrow_key)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 int retval = 0;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 available_char = 0x1b;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 rl_callback_read_char ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 available_char = '[';
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 rl_callback_read_char ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277 switch (arrow_key)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279 case Qt::Key_Up:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 retval = 'A';
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 case Qt::Key_Down:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284 retval = 'B';
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 case Qt::Key_Right:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 retval = 'C';
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 case Qt::Key_Left:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292 retval = 'D';
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 break;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296 return retval;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 // Retrieve a command from the history list and insert it on the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 // current command.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 void command_window::history (bool up)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 HIST_ENTRY *entry = up ? previous_history () : next_history ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 if (entry)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 erase_line ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 std::string prompt = rl_prompt ? rl_prompt : "";
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 insert_line (prompt, entry->line);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 else if (! up)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 erase_line ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 scroll_to_bottom ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 void command_window::erase_line (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 QTextCursor cursor = textCursor ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 cursor.movePosition (QTextCursor::End);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 cursor.select (QTextCursor::LineUnderCursor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 cursor.removeSelectedText ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 setTextCursor (cursor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331 void command_window::insert_at_cursor (const std::string& text)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333 QTextCursor cursor = textCursor ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 cursor.insertText (QString::fromStdString (text));
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337 setTextCursor (cursor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
338 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 void command_window::insert_line (const std::string& prompt,
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341 const std::string& line)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 beg_mark = set_mark ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345 insert_at_cursor (prompt);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 prompt_mark = set_mark ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349 insert_at_cursor (line);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352 int command_window::set_mark (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 return textCursor ().position ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 void command_window::insert_result (double value)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 std::ostringstream buf;
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
360
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 buf << "ans = " << value << "\n";
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363 insert_at_cursor (buf.str ());
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 beg_mark = set_mark ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 scroll_to_bottom ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 void command_window::scroll_to_bottom (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372 QTextCursor cursor = textCursor ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 cursor.movePosition (QTextCursor::End);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
376 setTextCursor (cursor);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 int main (int argc, char *argv[])
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 QApplication app (argc, argv);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 calc_interaction_window = new command_window ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 calc_interaction_window->show ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
387 readline_init ();
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
388
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389 int status = app.exec ();
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
391 readline_fini ();
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
392
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393 return status;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 // -- Variable: rl_getc_func_t * rl_getc_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 // If non-zero, Readline will call indirectly through this pointer to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399 // get a character from the input stream. By default, it is set to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 // `rl_getc', the default Readline character input function (*note
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 // Character Input::).
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 // -- Variable: rl_voidfunc_t * rl_redisplay_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404 // If non-zero, Readline will call indirectly through this pointer to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 // update the display with the current contents of the editing buffer.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406 // By default, it is set to `rl_redisplay', the default Readline
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 // redisplay function (*note Redisplay::).
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 // -- Variable: rl_vintfunc_t * rl_prep_term_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 // If non-zero, Readline will call indirectly through this pointer to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 // initialize the terminal. The function takes a single argument, an
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412 // `int' flag that says whether or not to use eight-bit characters.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413 // By default, this is set to `rl_prep_terminal' (*note Terminal
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414 // Management::).
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 // -- Variable: rl_voidfunc_t * rl_deprep_term_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 // If non-zero, Readline will call indirectly through this pointer to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418 // reset the terminal. This function should undo the effects of
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 // `rl_prep_term_function'. By default, this is set to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 // `rl_deprep_terminal' (*note Terminal Management::).
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 // -- Function: void rl_callback_handler_install (const char *prompt,
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 // rl_vcpfunc_t *lhandler)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 // Set up the terminal for readline I/O and display the initial
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425 // expanded value of PROMPT. Save the value of LHANDLER to use as a
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426 // function to call when a complete line of input has been entered.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 // The function takes the text of the line as an argument.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429 // -- Function: void rl_callback_read_char (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 // Whenever an application determines that keyboard input is
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 // available, it should call `rl_callback_read_char()', which will
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432 // read the next character from the current input source. If that
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 // character completes the line, `rl_callback_read_char' will invoke
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 // the LHANDLER function saved by `rl_callback_handler_install' to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 // process the line. Before calling the LHANDLER function, the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 // terminal settings are reset to the values they had before calling
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 // `rl_callback_handler_install'. If the LHANDLER function returns,
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 // the terminal settings are modified for Readline's use again.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439 // `EOF' is indicated by calling LHANDLER with a `NULL' line.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 // -- Function: void rl_callback_handler_remove (void)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 // Restore the terminal to its initial state and remove the line
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 // handler. This may be called from within a callback as well as
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444 // independently. If the LHANDLER installed by
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445 // `rl_callback_handler_install' does not exit the program, either
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446 // this function or the function referred to by the value of
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447 // `rl_deprep_term_function' should be called before the program
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448 // exits to reset the terminal settings.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450 // -- Variable: rl_compdisp_func_t * rl_completion_display_matches_hook
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451 // If non-zero, then this is the address of a function to call when
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
452 // completing a word would normally display the list of possible
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453 // matches. This function is called in lieu of Readline displaying
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
454 // the list. It takes three arguments: (`char **'MATCHES, `int'
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455 // NUM_MATCHES, `int' MAX_LENGTH) where MATCHES is the array of
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456 // matching strings, NUM_MATCHES is the number of strings in that
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457 // array, and MAX_LENGTH is the length of the longest string in that
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458 // array. Readline provides a convenience function,
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459 // `rl_display_match_list', that takes care of doing the display to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460 // Readline's output stream. That function may be called from this
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461 // hook.