Mercurial > jwe > qt-gui-with-push-parser
annotate NOTES @ 9:822a2fe5bb51
move command window to separate file and other refactoring
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 12:36:26 -0400 |
parents | 52c033864347 |
children | bfa9aaa2d608 |
rev | line source |
---|---|
3
52c033864347
add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
1 To build: |
52c033864347
add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
2 |
52c033864347
add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
3 qmake calc.pro |
52c033864347
add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
4 make |
52c033864347
add build instructions to NOTES file
John W. Eaton <jwe@octave.org>
parents:
0
diff
changeset
|
5 |
0 | 6 Current terminal widget: |
7 | |
8 * Run Octave in a separate thread. On unixy, interact through pty. | |
9 On Windows systems, use hidden console and mirror contents in Qt | |
10 widget. | |
11 | |
12 Octave interpreter sees input directly, same as for normal | |
13 terminal application. Good, because no change in the way Octave | |
14 accepts and parses input. Bad because GUI is not in control of | |
15 input and must arrange to communicate across threads. | |
16 | |
17 Terminal window can (in theory) be used to run other applications | |
18 started from the system command (for example). This feature works | |
19 well enough for us to use less running as a separate process to | |
20 handle paging output, but it doesn't work for all applications. | |
21 For example, I am not able to run editors like Emacs or vi in the | |
22 GUI terminal window. | |
23 | |
24 To make less work as the pager on Unixy systems, the Octave must | |
25 fork, call setsid in the child to detach from the controlling | |
26 terminal, and then exec the GUI. | |
27 | |
28 GUI must deal with threads when communicating with the | |
29 interpreter. | |
30 | |
31 Proposal: | |
32 | |
33 * GUI terminal widget is in control of input. | |
34 | |
35 Use callback interface for readline to handle command line | |
36 editing. | |
37 | |
38 Use push parser to parse lines as they become available. Push | |
39 parser will return status of parse, either complete or needing | |
40 more input. | |
41 | |
42 Uses the following readline callbacks to manage input and update | |
43 the display. We may need more in the future to handle other | |
44 features. | |
45 | |
46 rl_getc_function | |
47 rl_redisplay_function | |
48 rl_completion_display_matches_hook | |
49 | |
50 rl_prep_term_function (do nothing) | |
51 rl_deprep_term_function (do nothing) | |
52 | |
53 Call rl_callback_handler_install to setup readlines | |
54 callback mode. This sets the initial prompt and provides a pointer | |
55 to a function that readline should call when a complete line of | |
56 input is available. | |
57 | |
58 Call rl_callback_read_char when a character is available for | |
59 readline to handle. We currently store the character to read in a | |
60 global value, then rl_get_function returns that character to | |
61 readline. | |
62 | |
63 Call rl_callback_handler_remove when shutting down. | |
64 | |
65 To avoid global variables, it would be helpful if we could use | |
66 lambda functions/functors as callbacks instead of plain C function | |
67 pointers. | |
68 | |
69 Questions: | |
70 | |
71 * With this arrangement, would the interpreter have to run in a | |
72 separtae thread? | |
73 | |
74 * Example parser currently computes results | |
75 immediately. How do we deal with parsing multiple expressions and | |
76 statements with this method? | |
77 | |
78 * Do we need text position markers to keep track of the prompt position | |
79 (beginning of current line) when inserting or clearing text? | |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
80 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
81 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
82 readline callback functions: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
83 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
84 // -- Variable: rl_getc_func_t * rl_getc_function |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
85 // If non-zero, Readline will call indirectly through this pointer to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
86 // get a character from the input stream. By default, it is set to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
87 // `rl_getc', the default Readline character input function (*note |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
88 // Character Input::). |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
89 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
90 // -- Variable: rl_voidfunc_t * rl_redisplay_function |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
91 // If non-zero, Readline will call indirectly through this pointer to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
92 // update the display with the current contents of the editing buffer. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
93 // By default, it is set to `rl_redisplay', the default Readline |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
94 // redisplay function (*note Redisplay::). |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
95 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
96 // -- Variable: rl_vintfunc_t * rl_prep_term_function |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
97 // If non-zero, Readline will call indirectly through this pointer to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
98 // initialize the terminal. The function takes a single argument, an |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
99 // `int' flag that says whether or not to use eight-bit characters. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
100 // By default, this is set to `rl_prep_terminal' (*note Terminal |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
101 // Management::). |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
102 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
103 // -- Variable: rl_voidfunc_t * rl_deprep_term_function |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
104 // If non-zero, Readline will call indirectly through this pointer to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
105 // reset the terminal. This function should undo the effects of |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
106 // `rl_prep_term_function'. By default, this is set to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
107 // `rl_deprep_terminal' (*note Terminal Management::). |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
108 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
109 // -- Function: void rl_callback_handler_install (const char *prompt, |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
110 // rl_vcpfunc_t *lhandler) |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
111 // Set up the terminal for readline I/O and display the initial |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
112 // expanded value of PROMPT. Save the value of LHANDLER to use as a |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
113 // function to call when a complete line of input has been entered. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
114 // The function takes the text of the line as an argument. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
115 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
116 // -- Function: void rl_callback_read_char (void) |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
117 // Whenever an application determines that keyboard input is |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
118 // available, it should call `rl_callback_read_char()', which will |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
119 // read the next character from the current input source. If that |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
120 // character completes the line, `rl_callback_read_char' will invoke |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
121 // the LHANDLER function saved by `rl_callback_handler_install' to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
122 // process the line. Before calling the LHANDLER function, the |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
123 // terminal settings are reset to the values they had before calling |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
124 // `rl_callback_handler_install'. If the LHANDLER function returns, |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
125 // the terminal settings are modified for Readline's use again. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
126 // `EOF' is indicated by calling LHANDLER with a `NULL' line. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
127 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
128 // -- Function: void rl_callback_handler_remove (void) |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
129 // Restore the terminal to its initial state and remove the line |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
130 // handler. This may be called from within a callback as well as |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
131 // independently. If the LHANDLER installed by |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
132 // `rl_callback_handler_install' does not exit the program, either |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
133 // this function or the function referred to by the value of |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
134 // `rl_deprep_term_function' should be called before the program |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
135 // exits to reset the terminal settings. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
136 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
137 // -- Variable: rl_compdisp_func_t * rl_completion_display_matches_hook |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
138 // If non-zero, then this is the address of a function to call when |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
139 // completing a word would normally display the list of possible |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
140 // matches. This function is called in lieu of Readline displaying |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
141 // the list. It takes three arguments: (`char **'MATCHES, `int' |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
142 // NUM_MATCHES, `int' MAX_LENGTH) where MATCHES is the array of |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
143 // matching strings, NUM_MATCHES is the number of strings in that |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
144 // array, and MAX_LENGTH is the length of the longest string in that |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
145 // array. Readline provides a convenience function, |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
146 // `rl_display_match_list', that takes care of doing the display to |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
147 // Readline's output stream. That function may be called from this |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
3
diff
changeset
|
148 // hook. |