fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] String formatting with color functions


From: Jeff Forcier
Subject: Re: [Fab-user] String formatting with color functions
Date: Mon, 21 Nov 2011 17:12:18 -0800

On Mon, Nov 21, 2011 at 3:40 PM, Ahsan Rabbani <address@hidden> wrote:
> I've noticed that when printing strings that are wrapped in color functions
> it screws up the string formatting.

My guess would be that it has something to do with the non-printing
ANSI color escape codes that the color functions add. They're likely
"counting" as individual characters from the perspective of Python's
string formatter when it does the left-justify.

Offhand workarounds (caveat: I don't do a ton of string manip these
days...): manually calculating how the justification should occur
(based on the string before it is colorized) and adding the extra
spaces yourself; or doing a substitution (i.e. justify, then take the
result and substitute the original string for the colorized string.)

Hope that helps,
Jeff

-- 
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]