[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: Wed, 25 Mar 2015 11:01:16 -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 12:19 PM, isabella parakiss wrote:
> On 3/24/15, Chet Ramey <address@hidden> wrote:
>> 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.
> This cannot be right.

Of course it can.

> The other program's prompt is never deleted when i use read -p ' ', I
> can only erase until the point where readline printed that space.
> This means that readline _does_ know where to stop, right?

No.  Readline's redisplay algorithm is adaptive in the sense that it
computes the least expensive way to update the screen.  Sometimes that
means sending the cursor to column 0 (or an arbitrary column) and
reprinting the data, and sometimes it means using cursor motion primitives
or simple backspace/reprint operations.  You cannot a priori know which
one readline will choose, and readline expects to be able to use an entire
screen line to make that decision and perform redisplay.  Readline also
needs to know which column it starts in to perform redisplay, and it
assumes that it starts in column 0.  When you perform more complicated
updates, do line wrapping, or have multibyte characters in the line, that
information becomes important.

> This is what I consider the "correct" behaviour.  Is there any way to
> achieve this without printing additional characters to the screen?

This is what I mean by unjustified expectations.  Readline has no way to
know what is already on the screen when it runs and does redisplay --
and there is no good way for it to find out.

> To summarize:
> Please explain why using read -e -p ' ' the other program's prompt won't
> be deleted, but it will if i use read -e -p ''

Readline's redisplay algorithm makes different choices in those two cases.
You simply cannot count on readline not writing over text it does not know
is there.

``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]