You are not logged in.

#1 2011-07-30 00:27:46

Pingwinski
Member
From: Sweden
Registered: 2010-10-09
Posts: 15

["SOLVED"] Buggy (!) Bash prompt

I recently killed a couple of hours (stone cold) fixing my prompt just the way I wanted it. But tore my hair I did, as the reverse-i-search (Ctrl-R) results turned transparent when selecting them (left/right arrow).

Here's my beautiful PS1 as of tonight, notice the dark background until end of line:
Pingwinski's PS1

ccup=$'\033[1A'
chome=$'\033[0;0H'
ceod=$'\033[0J'
cend=$'\033[1;1f'
cbold=$'\033[1m'
cunder=$'\033[4m'
cblink=$'\033[5m'
creverse=$'\033[7m'
cconcealed=$'\033[8m'
cblack=$'\033[30m'
cblackb=$'\033[40m'
cwhite=$'\033[37m'
cwhiteb=$'\033[47m'
cnull=$'\033[0m'

#PS1='\n ${cblackb}${cwhite}${cbold}\u${cnull}${cblackb} ${cwhite}\h \j ${cbold}\w${ceod}${cnull}\n ${ceod}\$ '
PS1='\n \[\033[40m\]\[\033[37m\]\[\033[1m\]\u\[\033[0m\]\[\033[40m\] \[\033[37m\]\h \j \[\033[1m\]\w\[\033[0J\]\[\033[0m\]\n \[\033[0J\]\$ '

...and here's the working, but non-favorable, version:

#PS1='\n ${cblackb}${cwhite}${cbold}\u${cnull}${cblackb} ${cwhite}\h \j ${cbold}\w${cnull}\n \$ '
PS1='\n \[\033[40m\]\[\033[37m\]\[\033[1m\]\u\[\033[0m\]\[\033[40m\] \[\033[37m\]\h \j \[\033[1m\]\w\[\033[0m\]\n \$ '

Seems that \[\033[0J\] (end of document) screws things up...

I admit not knowing exactly what I'm doing with the escape sequences, but the reverse-i-search result shouldn't be transparent, right? Setting a background image in the terminal shows no sign of text either. Someone with the force within, please help!

Edit:
Removed some unused color variables to shorten list.

Last edited by Pingwinski (2011-07-31 01:43:06)

Offline

#2 2011-07-30 07:50:48

FarmerF
Member
From: Netherlands
Registered: 2009-06-08
Posts: 76

Re: ["SOLVED"] Buggy (!) Bash prompt

Firstly I never tried this or anything similar so I might be horribly wrong... But the first thing I see is that in the 'wrong' version you have a linebreak '\n' in the middle of the statement and the second thing is that you have '0J' as thirdlast and last value which is the only time you have a value with a capital and the only time it is not a value followed by an 'm'. Possibly either of these is related to the problem. If not then I'll leave it to the experts smile

Offline

#3 2011-07-30 13:29:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: ["SOLVED"] Buggy (!) Bash prompt

I think you forgot

\[\e[m\]

(which means 'end color') at the end:

PS1='\n \[\033[40m\]\[\033[37m\]\[\033[1m\]\u\[\033[0m\]\[\033[40m\] \[\033[37m\]\h \j \[\033[1m\]\w\[\033[0m\]\n \$ \[\e[m\]'

Now the black background extend only as far as the prompt. The newline '\n' is fine.

Offline

#4 2011-07-31 01:39:17

Pingwinski
Member
From: Sweden
Registered: 2010-10-09
Posts: 15

Re: ["SOLVED"] Buggy (!) Bash prompt

After some research I now have found my first seemingly undocumented bug (hooray..?). See last paragraph.

@FarmerF: the escape sequences are correctly typed, exactly why they look like they do are a mystery for me to wink

@karol: I actually want the background to extend all the way to the end, but still be able to see the search results smile Anyway... I tried adding another "null" statement to my desired prompt as suggested, but to no avail. I'm actually nulling the background just after the first "end-of-document" sequence (\[\033[0J\]\) and before the last new-line (using \[\033[0m\] instead of suggested \[\e[m\]). While testing this I found out that...



In Bash, when:
1. setting a background color,
2. using the end-of-document escape sequence,
3. nulling it,
4. then again using the "eod" to continue the nulled formatting
-> reverse-i-search breaks. Results containing an space turns transparent when trying to edit them while other results shows as expected.

Thanks for your replies!

Last edited by Pingwinski (2011-07-31 01:40:24)

Offline

Board footer

Powered by FluxBB