Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding colors in python interpreter prompt, does not wrap properly

Tags:

python

bash

I would like to have a more colorful Python prompt in the terminal, just for readability. I currently have:

sys.ps1 = '\033[96m>>> \033[0m'
sys.ps2 = '\033[96m... \033[0m'

in my PYTHONSTARTUP file, which does give it colors as desired. However, any text over a line does not wrap properly. The text goes to the end of the line, and instead of immediately starting a new line, starts overwriting the beginning of the first line before starting a new line. As you might imagine, this is actually rather unreadable. How can I fix this behavior?

like image 811
user812786 Avatar asked Jun 08 '12 18:06

user812786


2 Answers

Is there some reason to not use IPython? IPython does provide color prompts, etc. out of the box...

like image 41
reptilicus Avatar answered Oct 20 '22 01:10

reptilicus


Try the following:

sys.ps1 = '\001\033[96m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[96m\002... \001\033[0m\002'

This answer to a similar question explains why the \001 and \002 are necessary.

like image 109
Andrew Clark Avatar answered Oct 20 '22 00:10

Andrew Clark