#5 calling using_history() takes over terminal

open
nobody
None
5
2010-08-13
2010-08-13
Anonymous
No

Simply by calling using_history(), one loses terminal control capabilities.

This program:

#include <stdio.h>
#include <histedit.h>

int main(int argc, char *argv[])
{
using_history();
printf("Some interesting info\n");
return 0;
}

When compiled, linked to libedit, and piped to the command line program 'less', will display the problem, as less won't be able to use full terminal control.

I would not expect the initailization function to do this, seeing as it is only supposed to initialize interactive variables.

This is demonstrated as a problem in PHP here:

https://bugs.launchpad.net/ubuntu/+source/php5/+bug/322214

Discussion


  • Anonymous
    2011-01-26

    The problem arises because tgetent in ncurses does a ton of setup on the terminal, whereas old termcap tgetent did not.

    There's really no reason to be setting up the terminal when stdout is not a tty, so this patch disables calling tgetent whenever the output is not a tty

    (would attach but SF.net won't let me.

    --- libedit/term.c 2008-06-14 17:13:08 +0000
    +++ libedit/term.c 2011-01-26 08:59:38 +0000
    @@ -923,7 +923,11 @@

    memset(el->el_term.t_cap, 0, TC_BUFSIZE);

    - i = tgetent(el->el_term.t_cap, term);
    + if (isatty(fileno(el->el_outfile))) {
    + i = tgetent(el->el_term.t_cap, term);
    + } else {
    + i = 0;
    + }

    if (i <= 0) {
    if (i == -1)

     

  • Anonymous
    2011-01-26

    Ignore previous patch, this one actually works:

    === modified file 'libedit/tty.c'
    --- libedit/tty.c 2008-06-14 17:13:08 +0000
    +++ libedit/tty.c 2011-01-26 21:03:59 +0000
    @@ -472,6 +472,9 @@
    if (el->el_flags & EDIT_DISABLED)
    return (0);

    + if (!isatty(fileno(el->el_outfile)))
    + return (-1);
    +
    if (tty_getty(el, &el->el_tty.t_ed) == -1) {
    #ifdef DEBUG_TTY
    (void) fprintf(el->el_errfile,

     

  • Anonymous
    2013-04-02

    This "fix" was unfortunately (at least for me) included as a patch to Debian and has caused me much grief. Although it may have fixed your issue, it has broken my use of libedit. Basically, I have a long-running application which uses libedit to provide an interactive prompt. We then pipe the output to tee to capture a log. E.G.:

    my-program 2>&1 | tee logfile.txt

    With this patch in place, I no longer get a prompt and the arrow keys do not work. The input is still available - I can still type commands in and they are recognized and passed on to my application.

    To get around this issue I had to recompile the package with this patch removed.