Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

.format() color injection #16

Closed
ThiefMaster opened this issue Dec 30, 2015 · 6 comments
Closed

.format() color injection #16

ThiefMaster opened this issue Dec 30, 2015 · 6 comments

Comments

@ThiefMaster
Copy link

>>> print(colorclass.Color('{red}XXX: {/red}{}').format('{green}moo{/green}'))
XXX: moo

Expected: XXX: {green}moo{/green} (with XXX: in red)
Actual: XXX: moo (with XXX: in red and moo in green)

This is especially annoying since it means one cannot use the Color class without the tag parsing.

@Robpol86
Copy link
Owner

Color.format() will return a Color instance which parses {green}, just as str.format() returns a str instance. If you don't want {green} to be parsed you'll need to feed it into str.format(). Something like print(str(colorclass.Color('{red}XXX: {/red}{}')).format('{green}moo{/green}'))

@ThiefMaster
Copy link
Author

But as soon as I convert it back to a Color class it'll be parsed. (I'm just using the Color class to get the proper length calculation)

@Robpol86
Copy link
Owner

Hmm, true. I should fix colorclass so you can do something like .format('{{green}}moo{{/green}}'), which is what str.format() does.

@ThiefMaster
Copy link
Author

a way that lets you create a Color instance without invoking the parsing logic at all would be nice, too

@Robpol86
Copy link
Owner

I'm not sure about that. My goal with colorclass was to mimic str. str.format() doesn't have such functionality. Hence why it supports escaping curly brackets with {{ and }}.

@ThiefMaster
Copy link
Author

that last one wasn't format-specific, more a general suggestion to make Color() more flexible

Robpol86 added a commit that referenced this issue May 2, 2016
For #16. Option to disable
parsing of curly brackets, leaving them as-is.
Robpol86 added a commit that referenced this issue May 3, 2016
Extension of #16. Better to
do this for Color() % str() and other operations.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants