[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] color in bash read builtin prompt
From: |
Clark Wang |
Subject: |
Re: [Help-bash] color in bash read builtin prompt |
Date: |
Mon, 20 Oct 2014 10:20:00 +0800 |
On Fri, Oct 17, 2014 at 8:50 PM, Geir Hauge <address@hidden> wrote:
> 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
>
Hi Geir,
What does \1 and \2 here means? Is there a tput command used to get them?
-clark
>
> 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
>