Anton,
See if this suits your purpose:
http://cheeseshop.python.org/pypi/SE/2.2 beta
Below the dotted line is how it works.
Frederic
----- Original Message -----
From: "Anton81" <
[email protected]>
Newsgroups: comp.lang.python
To: <
[email protected]>
Sent: Wednesday, August 09, 2006 7:48 PM
Subject: Escape sequences (colour) and padding with "%8s"%
Hi all!
I used escape sequences to produce colour output, but a construct like
print "%8s" % str_with_escape
doesn't do the right thing. I suppose the padding counts the escape
characters, too.
What could be a solution?
Anton
----------------------------------------------------------------------------------------------------------
# 1. List your ansi codes and invent concise place holders. Define each one like this 'symbol=ansi_escape'. ::=(x1b)[0m # Cancel all previous escapes
:B:=(x1b)[1m # bold
:blue:=(x1b)[34m
# etc.
'''
# 2. Mark your text up with your symbols
marked_up_text = "this has some :B:bold:: text and some :blue:blue:: text and some :B::blue:text that is bold and blue::"
# 3 Make an SE Stream Editor.
# 4. Stream-Edit'this has some \x1b[1mbold\x1b[0mtext and some \x1b[34mblue\x1b[0m text and some \x1b[1m\x1b[34mtext that is bold and blue\x1b[0m'