[Top][All Lists]

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

Re: Read Prompt Width Miscalculation (Non-Printing Characters)

From: Greg Wooledge
Subject: Re: Read Prompt Width Miscalculation (Non-Printing Characters)
Date: Wed, 28 Dec 2022 15:05:32 -0500

On Wed, Dec 28, 2022 at 01:09:02PM -0600, The Administrator wrote:
> Hello and happy holiday hacking.  Does the read builtin stand to benefit
> from \[ and \] denotation ala $PS1 and friends?  Here is a quick example:
> > read -erp "$( tput setaf 2 )NEW:$( tput sgr0 ) "
> Fill the line with “0123456789ABCDEFGH” and try deleting some of it.  I have
> attached a small demonstration.

There's a (secret?) feature of readline that lets you do \[ \] type
stuff using 001 and 002 bytes instead.

x01=$'\x01' x02=$'\x02'
read -erp "$x01$(tput setaf 2)${x02}NEW:$x01$(tput sgr0)$x02 "

Not pretty, but it works.

reply via email to

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