[LCP]Interrupting readline

Robert Wuest rwuest at wuest.org
Sun Jul 15 22:47:21 UTC 2001


Hi all,

I can't figure out how to get out of readline once it is called, except
to press enter or one more key.  I want exit the loop if the user hits
control-c, but readline insists on an enter.  I have the basic readline
loop :

int done = 0;

int cli(void)
{
.
.
	// install cli_int on SIGINT
.
    do {
        rbuffer = readline("spgmr08: ");
        if ( rbuffer) {
            if ( rbuffer[0] ) {
                add_history( rbuffer );
                proc_line(rbuffer);      // process input
            }
            free (rbuffer);
        } else {                        // EOF on empty line
            done = 1;
        }
    } while ( !done );
.
.
.
}

And an interrupt handler, which is being called properly (I see
"interrupt" on stdout)

void cli_int(int i)	// cli interrupt handler
{
    printf( "interrupt\n");
    rl_done = 1;
    done = 1;
}


Bash handles this no problem, and I've looked at the bash code, but
can't seem to duplicate it.

If I set rl_done (as shown above) readline waits for one more key, any
key.  That's not what I want.

Calling rl_named_function("accept-line")();  in the handler doesn't work
either.

Robert



More information about the linuxCprogramming mailing list