10

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?

user812786
  • 4,302
  • 5
  • 38
  • 50

2 Answers2

14

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.

Community
  • 1
  • 1
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306
3

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
reptilicus
  • 10,290
  • 6
  • 55
  • 79