[Top][All Lists]

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

Re: read -e deletes extra characters

From: Chet Ramey
Subject: Re: read -e deletes extra characters
Date: Tue, 24 Mar 2015 09:54:07 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 3/24/15 1:54 AM, isabella parakiss wrote:
> rlwrap is a nice utility that enables readline's features in utilities
> that don't provide them.  I tried to rewrite something similar in bash
> so here's a sketch of the code:
> while read -re; do
>   history -p -- "$REPLY"
>   history -s -- "$REPLY"
> done | ...
> The problem is when I pipe that to a program that prints a prompt.
> On a first impression, it seems to work fine, since pressing backspace
> doesn't delete the printed prompt, but actually it will delete it if I
> type some other character, then backspace.
> In the examples, the prompt will be a $ and it will be printed by the
> second program in the pipeline.
> $<backspace><backspace><backspace>     # keeps the prompt
> $x<backspace>                          # deletes both x and the prompt
> I know that read has -p to print a prompt, and this seems to work if I
> set read's prompt to any printable character.
> read -e -p ' '
> $ x<backspace>                         # deletes x, keeps space and $
> read -e -p ''
> $x<backspace>                          # deletes x and $
> The same behaviour happens in all the versions from bash 3.
> I think this is a bug, please fix it either by allowing an empty prompt
> to read -p, or somehow disabling/removing the "feature" that deletes
> extra characters that weren't typed by the user.

There are a number of unjustified expectations here.  The biggest is that
readline can know about characters printed to the screen by another
program.  Readline expects to be able to use the entire line and that it
begins with the cursor in column 0.  The second is that you're going to
be able to drive an arbitrary program via a pipe -- the key to rlwrap's
working is that it allocates and uses a pty.

(And there's nothing wrong with giving read -p an empty string for a prompt.)

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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