You are not logged in.

#1 2013-12-06 23:25:41

Ploppz
Member
Registered: 2013-09-14
Posts: 313

[Solved] How do you use 256 colours in PS1?

I found a function
function EXT_COLOUR () { echo -ne "\033[38;5;$1m"; }

But it messes up my terminal by suddenly jumping to the beginning of the line instead of breaking the line when text overflows.

And here is my prompt:
`EXT_COLOUR 6`\u`EXT_COLOUR 10` @ `EXT_COLOUR 1`\h`EXT_COLOUR 3`\w `EXT_COLOUR 10` $ \[\e[0m\]

I noticed the more hidden characters (the more colours) I use, the sooner will it bug out and jump at the beginning of the line. Using termite.

o4a772n.png

So do you know another way to make use of the 256 terminal colours in the PS1 variable? Thanks.

Edit: Another question, but still relevant to this:
http://unix.stackexchange.com/questions … -with-bold - I tested the for loop in a bash file and it worked, but if I write echo -e "\e[38;05;${code}m $code: Test" (replacing code with a number between 0 and 255 ofcourse) in my bash prompt and run, it only prints the output in color 0.

Last edited by Ploppz (2013-12-08 18:10:12)

Offline

#2 2013-12-07 15:08:34

brewlius_cesar
Member
From: VA
Registered: 2013-06-07
Posts: 24

Re: [Solved] How do you use 256 colours in PS1?

I think the problem is that the shell is unable to properly determine the length of the prompt.  Try enclosing everything that does not get printed in square brackets:

PS1="\[`EXT_COLOUR 6`\u`EXT_COLOUR 10`\] @ \[`EXT_COLOUR 1`\h`EXT_COLOUR 3`\w `EXT_COLOUR 10`\] $ \[\e[0m\]"

I haven't tried that command ^^^, but hopefully you get the idea...

Offline

#3 2013-12-08 18:09:54

Ploppz
Member
Registered: 2013-09-14
Posts: 313

Re: [Solved] How do you use 256 colours in PS1?

That did it, thanks! For simplicity, I put \[ and \] Inside the EXT_COLOUR function.

Last edited by Ploppz (2013-12-08 18:12:26)

Offline

Board footer

Powered by FluxBB