Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11303

Re: Ctrl-U doesn't clear read -ep prompt input properly

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Ctrl-U doesn't clear read -ep prompt input properly
Date 2015-08-07 15:01 -0400
Message-ID <mailman.7949.1438974088.904.bug-bash@gnu.org> (permalink)
References <0D835E9B9CD07F40A48423F80D3B5A702E90C868@USA7109MB022.na.xerox.net>

Show all headers | View raw


On 8/7/15 9:36 AM, Nellis, Kenneth wrote:
> Bash Version: 4.3
> Patch Level: 39
> Release Status: release
> 
> Description:
> Pressing CTRL-U after entering data in response to a read -ep prompt should work as does the PS1 bash prompt.
> Consider a custom PS1 bash prompt containing ansi escape sequences, for example, to display
> the prompt in color. To get proper CTRL-U clearing of input typed at the prompt, bash
> recognizes special \ [ and \ ] delimiters in the prompt string. Here is my PS1, for example:
> \ [ ESC [ 3 2 m \ ] $ SP \ [ ESC ( B ESC [ m \ ] LF
> which displays a "$ " prompt in green.
> Without \ [ and \ ] in the prompt, CTRL-U doesn't clear the line properly, so it's a necessary feature.
> 
> read -ep prompt, however, does not support the \ [ and \ ] delimiters. Consequently, for prompts containing
> ansi escape sequences, CTRL-U doesn't clear the line properly.
> 
> Repeat-By:
> The following example demonstrates the problem.
> $ prompt="$(tput setaf 2)test>$(tput sgr0) "
> $ read -ep "$prompt" answer
> test> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<CTRL-U>
> 
> Note that all the x's are not cleared.

You're correct.  The prompt given to read -p prompt is not expanded like
the PSn variables.  It never has been, and it's not documented to do so.
As such, using invisible characters in the read -p prompt string is not
supported.

Since you're adding the non-visible characters to the prompt, you can
try bracketing them with \001 and \002, but you have to do that yourself.

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

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Ctrl-U doesn't clear read -ep prompt input properly Chet Ramey <chet.ramey@case.edu> - 2015-08-07 15:01 -0400

csiph-web