help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] color in bash read builtin prompt


From: Geir Hauge
Subject: Re: [Help-bash] color in bash read builtin prompt
Date: Fri, 17 Oct 2014 14:50:23 +0200

2014-10-17 14:37 GMT+02:00 Clark Wang <address@hidden>:

> On Fri, Oct 17, 2014 at 6:20 PM, Patrick Byrne <address@hidden> wrote:
>
> > Hi,
> >
> > I am finding that color codes are not recognised in a 'read' prompt:
> > read -e -p "\x1b[31mtarget_dir:${rst} " -i "${default_target_dir}"
> > target_dir
> >
> > output:
> > ^[[0;31;40mtarget_dir:\x1b[0m /home/digital/python_1411
> >
> > Is there a way around this please?
> >
>
> Try like this:
>
> read -p $'\033[1;31mRED:\033[0m ' var
>

Also needs \1 and \2 around the non-printable bytes

red=$'\1'$(tput setaf 1;tput bold)$'\2' reset=$'\1'$(tput sgr0)$'\2'

read -ep "${red}target_dir:${reset} " -i "$default_target_dir"

-- 
Geir Hauge


reply via email to

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