[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Terminal emulation in Octave GUI
From: |
John W. Eaton |
Subject: |
Terminal emulation in Octave GUI |
Date: |
Thu, 7 Apr 2011 12:52:01 -0400 |
On 7-Apr-2011, Jordi GutiƩrrez Hermoso wrote:
| On 7 April 2011 01:44, Jacob Dawid <address@hidden> wrote:
| > it turned that I was not aware of the problem with readline. However, it is
| > quite questionable if putting a terminal emulation into a window can be a
| > solution for a GUI - I don't think so.
|
| I think you simply are envisioning a limited terminal. I don't know of
| a reason why we can't have an Octave terminal in a GUI with readline
| and not build other bells and whistles on top of it, like syntax
| highlighting or pop-up completion menus. What I do think is rather
| silly is to reimplement parts of readline like tab completion or
| history search.
Since this seems to be quite a sticking point for GUIs, I'm willing to
reconsider.
It seems to me the real question is about who should be handling
events. People who write GUIs think that the GUI should be the one
handling all events. That's counter to what normally happens for a
command-line application, where it is normally waiting to read input
from the terminal. GNU readline allows functions to be called
periodically while it is waiting for input, so it is possible for it
to handle events while waiting for input, but people who write GUIs
still don't like this very much because it is not the normal way they
think about handling events.
I spent some time thinking about how to properly merge readline with a
GUI by separating the parts that do terminal handling and redisplay
from the parts that just manage the state of the current line, and how
the normal usage of calling readline and expecting it to get input
needs to be inverted so that the GUI is gathering input and passing it
to readline one character at a time, only to discover that there is
apparently already a way to do this job:
http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC41
2.4.12 Alternate Interface
--------------------------
An alternate interface is available to plain `readline()'. Some
applications need to interleave keyboard I/O with file, device, or
window system I/O, typically by using a main loop to `select()' on
various file descriptors. To accomodate this need, readline can also
be invoked as a `callback' function from an event loop. There are
functions available to make this easy.
-- Function: void rl_callback_handler_install (const char *prompt,
rl_vcpfunc_t *lhandler)
Set up the terminal for readline I/O and display the initial
expanded value of PROMPT. Save the value of LHANDLER to use as a
function to call when a complete line of input has been entered.
The function takes the text of the line as an argument.
-- Function: void rl_callback_read_char (void)
Whenever an application determines that keyboard input is
available, it should call `rl_callback_read_char()', which will
read the next character from the current input source. If that
character completes the line, `rl_callback_read_char' will invoke
the LHANDLER function saved by `rl_callback_handler_install' to
process the line. Before calling the LHANDLER function, the
terminal settings are reset to the values they had before calling
`rl_callback_handler_install'. If the LHANDLER function returns,
the terminal settings are modified for Readline's use again.
`EOF' is indicated by calling LHANDLER with a `NULL' line.
-- Function: void rl_callback_handler_remove (void)
Restore the terminal to its initial state and remove the line
handler. This may be called from within a callback as well as
independently. If the LHANDLER installed by
`rl_callback_handler_install' does not exit the program, either
this function or the function referred to by the value of
`rl_deprep_term_function' should be called before the program
exits to reset the terminal settings.
Using this interface in a GUI text box will probably also require
writing a custom redisplay function because the text box will
presumably not be something known to termcap. So when readline needs
to delete characters from the text box, or display a new line from the
history list that replaces the current line, how is that supposed to
happen in the context of a GUI text box? A custom function would
probably be needed.
Would someone who knows GUIs like to take a stab at hooking up a GUI
text box (or other) widget with readline using the callback interface
to demonstrate how this can be done?
jwe