Thread: [Cgdb-devel] cgdb and readline
Brought to you by:
bobbybrasko,
crouchingturbo
|
From: Bob R. <bob...@co...> - 2003-02-20 03:12:38
|
Hey guys,
Look at this small example. It reads a line at a time and prints it.
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>
/* Gets called when the user hits '\t' */
int rl_complete (int ignore, int invoking_key) {
fprintf(stderr, "complete\n");
return 0;
}
int main(int argc, char **argv){
static char *line;
while(1) {
line =3D readline("PROMPT:");
fprintf(stderr, "LINE=3D(%s)\n", line);
}
return 0;
}
I am trying to integrate readline into cgdb and ran into a problem.
Readline has a function called 'readline' that gets a line of input from
stdin. This is great, however, it is a blocking call ( It reads a whole
line and then returns). This is not good, since cgdb should also be able
to receive input if the user is in cgdb mode.=20
For example, the users types 'info sour' and the ESC 'j' ( to go down a lin=
e )=20
and then 'i' ( to get back into gdb mode ) and then 'e<CR>'.=20
How would we get readline to give up control? Or feed it a char at a
time? I don't know how to resolve this problem.
By the way, currently cgdb sits in a select loop reading from stdin,
gdb's stdout, and the debugged programs stdout (tty). How could we make
readline be a part of this?
Any suggestions?
Thanks,
Bobby
|
|
From: Peter K. <pe...@ko...> - 2003-02-20 03:22:01
|
I was just searching through the readline info pages and I found this
entry:
Alternate Interface
-------------------
An alternate interface is available to plain `readline()'. Some
applications need to interleave keyboard I/O with file, device, or wind=
ow
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 expan=
ded
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 availabl=
e,
it should call `rl_callback_read_char()', which will read the next
character from the current input source. If that character comple=
tes
the line, `rl_callback_read_char' will invoke the LHANDLER function
saved by `rl_callback_handler_install' to process the line. `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 hand=
ler.
This may be called from within a callback as well as independently.
That seems to be exactly what we need doesn't it? I'm not sure how we
would integrate this into our main loop, but at least its a good start.
- Peter
On Wed, Feb 19, 2003 at 10:12:36PM -0500, Bob Rossi wrote:
> Hey guys,
>=20
> Look at this small example. It reads a line at a time and prints it.
>=20
> #include <readline/readline.h>
> #include <readline/history.h>
> #include <stdlib.h>
>=20
> /* Gets called when the user hits '\t' */
> int rl_complete (int ignore, int invoking_key) {
> fprintf(stderr, "complete\n");
> return 0;
> }
>=20
> int main(int argc, char **argv){
> static char *line;
> while(1) {
> line =3D readline("PROMPT:");
> fprintf(stderr, "LINE=3D(%s)\n", line);
> }
> return 0;
> }
>=20
> I am trying to integrate readline into cgdb and ran into a problem.
> Readline has a function called 'readline' that gets a line of input from
> stdin. This is great, however, it is a blocking call ( It reads a whole
> line and then returns). This is not good, since cgdb should also be able
> to receive input if the user is in cgdb mode.=20
>=20
> For example, the users types 'info sour' and the ESC 'j' ( to go down a l=
ine )=20
> and then 'i' ( to get back into gdb mode ) and then 'e<CR>'.=20
>=20
> How would we get readline to give up control? Or feed it a char at a
> time? I don't know how to resolve this problem.
>=20
> By the way, currently cgdb sits in a select loop reading from stdin,
> gdb's stdout, and the debugged programs stdout (tty). How could we make
> readline be a part of this?
>=20
> Any suggestions?
>=20
> Thanks,
> Bobby
--=20
Peter D. Kovacs <pe...@ko...>
|
|
From: Bob R. <bob...@co...> - 2003-02-20 12:00:43
|
Wow, I must have looked right over that. Thanks Peter! This is exactly
what we need.
Bobby
On Wed, Feb 19, 2003 at 10:21:57PM -0500, Peter Kovacs wrote:
> I was just searching through the readline info pages and I found this
> entry:
>=20
> Alternate Interface
> -------------------
>=20
> An alternate interface is available to plain `readline()'. Some
> applications need to interleave keyboard I/O with file, device, or wi=
ndow
> system I/O, typically by using a main loop to `select()' on various f=
ile
> descriptors. To accomodate this need, readline can also be invoked a=
s a
> `callback' function from an event loop. There are functions availabl=
e to
> make this easy.
>=20
> - 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 exp=
anded
> value of PROMPT. Save the value of LHANDLER to use as a functio=
n to
> call when a complete line of input has been entered. The functi=
on
> takes the text of the line as an argument.
>=20
> - Function: void rl_callback_read_char (void)
> Whenever an application determines that keyboard input is availa=
ble,
> it should call `rl_callback_read_char()', which will read the ne=
xt
> character from the current input source. If that character comp=
letes
> the line, `rl_callback_read_char' will invoke the LHANDLER funct=
ion
> saved by `rl_callback_handler_install' to process the line. `EO=
F' is
> indicated by calling LHANDLER with a `NULL' line.
>=20
> - Function: void rl_callback_handler_remove (void)
> Restore the terminal to its initial state and remove the line ha=
ndler.
> This may be called from within a callback as well as independent=
ly.
>=20
> That seems to be exactly what we need doesn't it? I'm not sure how we
> would integrate this into our main loop, but at least its a good start.
>=20
> - Peter
>=20
> On Wed, Feb 19, 2003 at 10:12:36PM -0500, Bob Rossi wrote:
> > Hey guys,
> >=20
> > Look at this small example. It reads a line at a time and prints it.
> >=20
> > #include <readline/readline.h>
> > #include <readline/history.h>
> > #include <stdlib.h>
> >=20
> > /* Gets called when the user hits '\t' */
> > int rl_complete (int ignore, int invoking_key) {
> > fprintf(stderr, "complete\n");
> > return 0;
> > }
> >=20
> > int main(int argc, char **argv){
> > static char *line;
> > while(1) {
> > line =3D readline("PROMPT:");
> > fprintf(stderr, "LINE=3D(%s)\n", line);
> > }
> > return 0;
> > }
> >=20
> > I am trying to integrate readline into cgdb and ran into a problem.
> > Readline has a function called 'readline' that gets a line of input from
> > stdin. This is great, however, it is a blocking call ( It reads a whole
> > line and then returns). This is not good, since cgdb should also be able
> > to receive input if the user is in cgdb mode.=20
> >=20
> > For example, the users types 'info sour' and the ESC 'j' ( to go down a=
line )=20
> > and then 'i' ( to get back into gdb mode ) and then 'e<CR>'.=20
> >=20
> > How would we get readline to give up control? Or feed it a char at a
> > time? I don't know how to resolve this problem.
> >=20
> > By the way, currently cgdb sits in a select loop reading from stdin,
> > gdb's stdout, and the debugged programs stdout (tty). How could we make
> > readline be a part of this?
> >=20
> > Any suggestions?
> >=20
> > Thanks,
> > Bobby
>=20
>=20
>=20
> --=20
> Peter D. Kovacs <pe...@ko...>
|