-
Notifications
You must be signed in to change notification settings - Fork 19
rjust and ljust has wrong offset #56
Comments
What was your use case? It looks like the calls can be swapped:
Sounds like the docs should have a warning about this. Is there interest in making this work? Seems pretty messy, but I guess a different class could be used for the output of colored.red which implements it's own rjust etc. and keeps track of the normal string part and the terminal color characters. |
Yeah, a custom class would work. Any chance the |
That approach would make more sense to me. That doesn't make your example work though, does it?
is a string, which we couldn't call a custom
to work though. |
Yup, you can't make the escape code characters just disappear. :-) |
What do you think about defining Like this: def __getattr__(self, att):
def func_help(*args, **kwargs):
getatt = getattr(self.s, att)(*args, **kwargs)
return ColoredString(self.color, getatt)
return func_help This code above solves the .ljust() and .rjust() problem. After some editing and discussion with thomasballinger , it also works for all other string methods with two exceptions and one note:
Also have a fix for just this bug, but if you're amenable to this idea, it seems useful. Is this fix interesting to you? Or would you prefer that the code were clearer or more separate? |
Great idea! I think that follows the principle of least surprise, so I'm all for it. |
see #57 |
The text was updated successfully, but these errors were encountered: