[Top][All Lists]

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

Re: [Help-bash] read -ep and ANSI colour sequences

From: Chet Ramey
Subject: Re: [Help-bash] read -ep and ANSI colour sequences
Date: Wed, 20 Feb 2013 10:16:17 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 2/20/13 6:57 AM, Chris Down wrote:
> On 2013-02-20 13:44, Pierre Gaston wrote:
>> The problem appears when your answer reach the rightmost column of
>> your termina, it will wrap instead of going to the next line.
>> Try with and without colors in the prompt and type enough chars to
>> reach the end of the line and you will see.
> Yes, that's true. As far as I am aware there is no way around this using
> readline.

There is, you just have to do a little bit of work to find it.  The
readline documentation points you in the right direction:

"Applications may indicate that the prompt contains characters that take
up no physical screen space when displayed by bracketing a sequence of
such characters with the special markers @code{RL_PROMPT_START_IGNORE}
and @code{RL_PROMPT_END_IGNORE} (declared in @file{readline.h}.  This may
be used to embed terminal-specific escape sequences in prompts."

It's aimed at applications using the C interface, hence the reference to
readline.h.  You can look for yourself:

$ grep IGNORE readline.h
#define RL_PROMPT_START_IGNORE  '\001'
#define RL_PROMPT_END_IGNORE    '\002'

So you should be able to use 0x01 and 0x02 to bracket non-printing
sequences.  This is all the bash prompt expansion code does.

Make sure you use an construct like $'...' that will expand the octal
escapes to single characters.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden

reply via email to

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