bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Readline-8.2-beta available


From: Andrew Burgess
Subject: Re: Readline-8.2-beta available
Date: Tue, 26 Apr 2022 13:55:25 +0100

Chet Ramey <chet.ramey@case.edu> writes:

> The first beta release of the GNU Readline library, version 8.2,
> is now available with the URLs
>
> ftp://ftp.cwru.edu/pub/bash/readline-8.2-beta.tar.gz
> https://ftp.gnu.org/pub/gnu/readline/readline-8.2-beta.tar.gz
>
> and from the readline-8.2-testing branch in the readline git repository
> (http://git.savannah.gnu.org/cgit/readline.git/log/?h=readline-8.2-testing).
>
> You can use
>
> git clone --branch readline-8.2-testing 
> git://git.savannah.gnu.org/readline.git
>
> to clone the testing branch.
>
> The CWRU FTP site works best if your client supports Extended Passive
> (EPSV) mode.
>
> This distribution is essentially a standalone version of the
> readline library that appears in bash-5.2-beta together with
> an `autoconf' framework.  The documentation has been updated and
> is current.  Postscript, DVI, and Info versions of the Readline
> and History manuals are included.  A list of changes in this
> release is appended to this announcement.
>
> This release accompanies the simultaneous release of bash-5.2-beta.
> There are more improvements in the programming interface and new
> user-visible variables and bindable commands.
>
> The most visible new feature is the addition of a new option which allows
> users to turn off the active region support without disabling bracketed
> paste. The option has the same default value as bracketed-paste, and
> enabling bracketed paste enables the active region. When the default
> value of of bracketed paste is enabled, unsetting this option in an
> inputrc file should suffice to disable active region support.
>
> There are two new bindable readline variables, active-region-start-color
> and active-region-end-color. The first sets the color used to display the
> active region; the second turns it off. If set, these are used in place of
> the escape sequences that enable and disable terminal standout mode.
>
> There are bug fixes for redisplaying the prompt when aborting incremental
> searches or switching to and from a digit-argument prompt. There is a fix
> for a redisplay problem that caused the prompt to be wrapped incorrectly
> if the screen changed dimensions during a call to readline() and the prompt
> became longer than the screen width. There are fixes for a couple of
> problems that could cause rl_end to be set incorrectly.
>
> Full details of the changes and bug fixes are below.
>
> GNU Readline is a library which provides programs with an input
> facility including command-line editing and history.  Editing
> commands similar to both emacs and vi are included.  The GNU
> History library, which provides facilities for managing a list of
> previously-typed command lines and an interactive command line
> recall facility similar to that provided by csh, is also present.
> The history library is built as part of the readline as well as
> separately.
>
> Since this is a testing release, please send readline bug reports to
> chet.ramey@case.edu.

I found an issue with the alternative callback API and EOF detection
that was added after my earlier requests:

  https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00021.html

It appears that in some cases the EOF flag will be set when I don't
think that it should be.

I've included a test program at the end of this email, the test is based
on the alternative interface example from the manual.

Build the test and run it, you'll see something like this:

  rltest$

type anything you like at the prompt (I use 'abc') and then press
return, the application echos your input back.  You should see this:

 rltest$ abc
 input line: abc
 rltest$ 

Now if I use the up arrow key to select my previous input, and press
return, the complete output is now this:

  rltest$ abc
  input line: abc
  rltest$ abc
  quit
  input line: abc
  rltest$

Notice the extra 'quit' that appeared.  This was from cb_deprep_terminal
(installed as rl_deprep_term_function) in the program below, the quit is
printed when the EOF flag is set.

The problem seems to originate from the handling of 'RL_ISSTATE
(RL_STATE_MULTIKEY)' in rl_callback_read_char (callback.c), where eof is
set as a result of calling _rl_dispatch_callback.  I don't currently
understand what the return value of _rl_dispatch_callback actually
represents

---

/* Standard include files. stdio.h is required. */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <errno.h>

/* Used for select(2) */
#include <sys/types.h>
#include <sys/select.h>

#include <signal.h>

#include <stdio.h>

/* Standard readline include files. */
#include <readline/readline.h>
#include <readline/history.h>

static void cb_linehandler (char *);
static void sighandler (int);

int running;
int sigwinch_received;
const char *prompt = "rltest$ ";

/* Handle SIGWINCH and window size changes when readline is not active and
   reading a character. */
static void
sighandler (int sig)
{
  sigwinch_received = 1;
}

/* Callback function called for each line when accept-line executed, EOF
   seen, or EOF character read.  This sets a flag and returns; it could
   also call exit(3). */
static void
cb_linehandler (char *line)
{
#ifndef RL_STATE_EOF
  if (line == NULL)
    printf ("quit\n");
#endif

  /* Can use ^D (stty eof) or `exit' to exit. */
  if (line == NULL || strcmp (line, "exit") == 0)
    {
      /* This function needs to be called to reset the terminal settings,
         and calling it from the line handler keeps one extra prompt from
         being displayed. */
      rl_callback_handler_remove ();

      running = 0;
    }
  else
    {
      if (*line)
        add_history (line);
      printf ("input line: %s\n", line);
      free (line);
    }
}

void
cb_deprep_terminal (void)
{
#ifdef RL_STATE_EOF
  if (RL_ISSTATE (RL_STATE_EOF))
    printf ("quit\n");
#endif

  rl_deprep_terminal ();
}

int
main (int c, char **v)
{
  fd_set fds;
  int r;

  /* Set the default locale values according to environment variables. */
  setlocale (LC_ALL, "");

  /* Handle window size changes when readline is not active and reading
     characters. */
  signal (SIGWINCH, sighandler);

  /* Install the line handler. */
  rl_callback_handler_install (prompt, cb_linehandler);
  rl_deprep_term_function = cb_deprep_terminal;

  /* Enter a simple event loop.  This waits until something is available
     to read on readline's input stream (defaults to standard input) and
     calls the builtin character read callback to read it.  It does not
     have to modify the user's terminal settings. */
  running = 1;
  while (running)
    {
      FD_ZERO (&fds);
      FD_SET (fileno (rl_instream), &fds);

      r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
      if (r < 0 && errno != EINTR)
        {
          perror ("rltest: select");
          rl_callback_handler_remove ();
          break;
        }
      if (sigwinch_received)
        {
          rl_resize_terminal ();
          sigwinch_received = 0;
        }
      if (r < 0)
        continue;

      if (FD_ISSET (fileno (rl_instream), &fds))
        rl_callback_read_char ();
    }

  printf ("rltest: Event loop has exited\n");
  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]