Bug 179676

Summary: bash readline doesn't work properly with colored PS1
Product: [Fedora] Fedora Reporter: Hooman Mesgary <hooman>
Component: readlineAssignee: Miroslav Lichvar <mlichvar>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4CC: bugs+behnam
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-12-13 17:36:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hooman Mesgary 2006-02-01 23:57:33 UTC
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-02 00:24:14 UTC
Of course it's a readline bug.

readline-5.0-3

Comment 2 Miroslav Lichvar 2006-12-13 17:36:51 UTC
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]\] '