Unix Technical Forum

Colored PS1 reduces input line?

This is a discussion on Colored PS1 reduces input line? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hello everybody, I have noticed a strange thing with colored prompts in bash: they reduce the length of input ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-19-2008, 04:29 PM
Mikhail Zotov
 
Posts: n/a
Default Colored PS1 reduces input line?

Hello everybody,

I have noticed a strange thing with colored prompts in bash:
they reduce the length of input lines. AFAIK, an input line
normally consists of 80 characters. As soon as I make PS1
colored (e.g., like PS1='\033[1;33m\h:\W$\033[0m ') the line
reduces to less than 70 characters.

Does this happen to you? Can this be fixed? Configuration
HOWTO keeps silence on the subject :-/

Regards,
Mikhail
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-19-2008, 04:29 PM
Floyd L. Davidson
 
Posts: n/a
Default Re: Colored PS1 reduces input line?

muxaul@lenta.ru (Mikhail Zotov) wrote:
>Hello everybody,
>
>I have noticed a strange thing with colored prompts in bash:
>they reduce the length of input lines. AFAIK, an input line
>normally consists of 80 characters. As soon as I make PS1
>colored (e.g., like PS1='\033[1;33m\h:\W$\033[0m ') the line
>reduces to less than 70 characters.


Well... look at all the added characters you have! Even though
they are not printable characters, '\033[1;33m' sends 7 characters,
and '\033[0m' sends for, so you are down to 69 on a line.

>Does this happen to you? Can this be fixed? Configuration
>HOWTO keeps silence on the subject :-/


See the Bash-Prompt-HOWTO, which will show that what you want
is

PS1='\[\033[1;33m\]\h:\W$\[\033[0m\] ')

Where the escaped square brackets cause the enclosed text not to
be counted.

--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-19-2008, 04:29 PM
Joost Kremers
 
Posts: n/a
Default Re: Colored PS1 reduces input line?

Floyd L. Davidson wrote:
> muxaul@lenta.ru (Mikhail Zotov) wrote:
>>normally consists of 80 characters. As soon as I make PS1
>>colored (e.g., like PS1='\033[1;33m\h:\W$\033[0m ') the line
>>reduces to less than 70 characters.

>
> Well... look at all the added characters you have! Even though
> they are not printable characters, '\033[1;33m' sends 7 characters,
> and '\033[0m' sends for, so you are down to 69 on a line.


so *that's* what's wrong! man, this annoyed the heck out of me for i don't
know how long!

--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-19-2008, 04:30 PM
Faux_Pseudo
 
Posts: n/a
Default Re: Colored PS1 reduces input line?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

_.-In alt.os.linux.slackware, Floyd L. Davidson wrote the following -._
> Well... look at all the added characters you have! Even though
> they are not printable characters, '\033[1;33m' sends 7 characters,
> and '\033[0m' sends for, so you are down to 69 on a line.

<snip>
> See the Bash-Prompt-HOWTO, which will show that what you want
> is
>
> PS1='\[\033[1;33m\]\h:\W$\[\033[0m\] ')


Exactly. Another option which works is to add a new line at the end
of the prompt. Which is how I fixed the issue.

PS1="\e[0;36m+\e[1;36m-(\e[0;36m\u@\e[0;36m\h\e[1;36m)-(\e[0;36m\#/\e[0;36m\l\e[1;36m)-(\e[0;36m\t:\e[0;36m\d\e[1;36m)-\n\e[0;36m+\e[1;36m-(\e[0;36m\$:\e[0;36m\w\e[1;36m)-\e[0;0m\n"

- --
.-')) http://asciipr0n.com/fp ('-. | It's a damn poor mind that
' ..- .:" ) ( ":. -.. ' | can only think of one way to
((,,_;'.;' UIN=66618055 ';. ';_,,)) | spell a word.
((_.YIM=Faux_Pseudo :._)) | - Andrew Jackson
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBbxUYSJec2PH9pbURAgBYAJ0VWCimg7fPvyUiJEOyBz I3nSc9RACff2zw
rI9XHIAp9BNf1O7dCpY9dO4=
=o/V2
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-19-2008, 04:30 PM
Mikhail Zotov
 
Posts: n/a
Default Re: Colored PS1 reduces input line?

floyd@barrow.com (Floyd L. Davidson) wrote in message news:<87y8i9tfzr.fld@barrow.com>...
> muxaul@lenta.ru (Mikhail Zotov) wrote:
> >Hello everybody,
> >
> >I have noticed a strange thing with colored prompts in bash:
> >they reduce the length of input lines. AFAIK, an input line
> >normally consists of 80 characters. As soon as I make PS1
> >colored (e.g., like PS1='\033[1;33m\h:\W$\033[0m ') the line
> >reduces to less than 70 characters.

>
> Well... look at all the added characters you have! Even though
> they are not printable characters, '\033[1;33m' sends 7 characters,
> and '\033[0m' sends for, so you are down to 69 on a line.
>
> >Does this happen to you? Can this be fixed? Configuration
> >HOWTO keeps silence on the subject :-/

>
> See the Bash-Prompt-HOWTO, which will show that what you want
> is
>
> PS1='\[\033[1;33m\]\h:\W$\[\033[0m\] '
>
> Where the escaped square brackets cause the enclosed text not to
> be counted.


Superb! Thanks a lot!!

Regards,
Mikhail
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com