sys.ps1 with formatting (linux)

Hugo python at hugo.doemaarwat.nl
Wed Aug 6 07:42:07 EDT 2008


Hi all,

My apologies for resurrecting an old thread, but I couldn't find the 
answer on the list and others might still have the same problem.

On Mon Jul 23 22:33:22 CEST 2007, Jon Dobson wrote (reformatted):
> I'm trying to set sys.ps1 and sys.ps2 with some formatting using:
> 
> sys.ps1="\033[1m\033[32mspy>\033[0m"
 > sys.ps2="\033[1m\033[32m   .\033[0m"
> 
> I get the colored prompt(s) as you might expect, but I'm getting some
 > strange behavior with wrapping.  Once the interactive command gets long
 > enough to wrap, it wraps back to the same line (overwriting the
 > beginning).  It doesn't break anything - the command gets interpreted
 > correctly, it's just an ugly way to work.

After a couple of hours of having the same problem, I found out that you 
should surround the unprintable characters with \001 and \002:

sys.ps1="\001\033[1m\033[32m\002spy>\001\033[0m\002"
sys.ps2="\001\033[1m\033[32m\002   .\001\033[0m\002"

Solution found in: http://hg.secdev.org/scapy/raw-file/tip/scapy.py:
 > ^A and ^B delimit invisible caracters for readline to count right

Greetings,
Hugo



More information about the Python-list mailing list