Bug 179676 - bash readline doesn't work properly with colored PS1
Summary: bash readline doesn't work properly with colored PS1
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: readline
Version: 4
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Miroslav Lichvar
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-02-01 23:57 UTC by Hooman Mesgary
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-12-13 17:36:51 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

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]\] '


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