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