Bug 179676 - bash readline doesn't work properly with colored PS1
bash readline doesn't work properly with colored PS1
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: readline (Show other bugs)
4
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Miroslav Lichvar
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-02-01 18:57 EST by Hooman Mesgary
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-12-13 12:36:51 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Hooman Mesgary 2006-02-01 18:57:33 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET CLR 1.1.4322)

Description of problem:
When I use escape character for coloring the bash command line it doesn't work as usual. It goes to the next line before reaching the last column. Also it start again from the same line.


Version-Release number of selected component (if applicable):
bash-3.0-31

How reproducible:
Always

Steps to Reproduce:
1. export PS1='[\e[31m\u\e[0m@\e[34m\h \e[32m\W\e[0m] '
It should change you bash to something like this: [mesgary@sib ~] while mesgary is red, sib is blue, ~ is green and other characters are white.
2. Try to write a command longer than one line, like:
grep -e "ends with this$" `grep -li "have this" *` | grep -e "^starts with this" | grep -v "not having this" | less
  

Actual Results:  You will see that before you reach to the last column, it will start again from the first column but it didin't go to the next line.

Expected Results:  It continute to the last column, then go to next line and start from the first column.

Additional info:

It is because of the excape character used in the PS1. It seems that readline counts the number of character used in the PS1 by just removing the "\" character from the string. so it counts "e[31m", "e[0m", "e[34m", "e[32m" and "e[0m". and they are 23 characters. Also readline goes to the first column 23 columns befor etha last column in this example.
Comment 1 Behnam [:ZWNJ] Esfahbod 2006-02-01 19:24:14 EST
Of course it's a readline bug.

readline-5.0-3
Comment 2 Miroslav Lichvar 2006-12-13 12:36:51 EST
Not a bug. In bash, non-printing characters have to be marked with special
characters \[ and \].

Correct is:
export PS1='[\[\e[31m\]\u\[\e[0m\]@\[\e[34m\]\h \[\e[32m\]\W\[\e[0m]\] '

Note You need to log in before you can comment on or make changes to this bug.