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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 Current terminal widget:
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 * Run Octave in a separate thread. On unixy, interact through pty.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 On Windows systems, use hidden console and mirror contents in Qt
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 widget.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 Octave interpreter sees input directly, same as for normal
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 terminal application. Good, because no change in the way Octave
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 accepts and parses input. Bad because GUI is not in control of
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 input and must arrange to communicate across threads.
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 Terminal window can (in theory) be used to run other applications
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 started from the system command (for example). This feature works
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 well enough for us to use less running as a separate process to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 handle paging output, but it doesn't work for all applications.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 For example, I am not able to run editors like Emacs or vi in the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 GUI terminal window.
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 To make less work as the pager on Unixy systems, the Octave must
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 fork, call setsid in the child to detach from the controlling
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 terminal, and then exec the GUI.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 GUI must deal with threads when communicating with the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 interpreter.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 Proposal:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 * GUI terminal widget is in control of input.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 Use callback interface for readline to handle command line
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 editing.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 Use push parser to parse lines as they become available. Push
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 parser will return status of parse, either complete or needing
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 more input.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 Uses the following readline callbacks to manage input and update
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 the display. We may need more in the future to handle other
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 features.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 rl_getc_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 rl_redisplay_function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 rl_completion_display_matches_hook
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 rl_prep_term_function (do nothing)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 rl_deprep_term_function (do nothing)
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 Call rl_callback_handler_install to setup readlines
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 callback mode. This sets the initial prompt and provides a pointer
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 to a function that readline should call when a complete line of
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 input is available.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 Call rl_callback_read_char when a character is available for
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 readline to handle. We currently store the character to read in a
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 global value, then rl_get_function returns that character to
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 readline.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 Call rl_callback_handler_remove when shutting down.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 To avoid global variables, it would be helpful if we could use
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 lambda functions/functors as callbacks instead of plain C function
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 pointers.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 Questions:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 * With this arrangement, would the interpreter have to run in a
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 separtae thread?
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 * Example parser currently computes results
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 immediately. How do we deal with parsing multiple expressions and
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 statements with this method?
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 * Do we need text position markers to keep track of the prompt position
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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.