-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support (and tests) for tuples with nested styles #45
base: master
Are you sure you want to change the base?
Conversation
Hi Erik, I just noticed this PR is languishing. Is there anything i can do to make it more palatable, or is this just out of scope for the tool? |
My fault; I just got distracted with other libraries. I'll try to have a look after PyCon. Sorry! |
which should be simple strings or FormattingStrings (allows nested | ||
calls for "inner" style). | ||
|
||
For example, this creates a red phrase with some bold words in the middle: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this rst
happy? (double the colons) add a new line after 478 and make sure 479 is 4 spaces in.
It's a nit that I'd do myself, but I have another request below...
In general I like this, but only because there's no nice way of doing this with a single string format. The fact that you reset just what's in the nest, IMO, is the value add. Would be nice to be able to use your fancy resetting to let something like this work:
but that's another pull request for another time... |
if self._normal: | ||
# "refresh" my style in the inner text by inserting it after each 'normal' (reset) code | ||
refresh = self._normal + self | ||
args = [refresh.join(a.split(self._normal)) for a in args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a crazy idea. It's backtracking, but I do believe it'll work. This lets us compose formatted strings without having to go down the road of assembling a syntax tree and keeping it off to the side someplace. This is a very promising functionality/complexity tradeoff. I'm impressed.
@jimallman brings us this convenience of allowing existing strings to be joined as a call parameter argument to a FormattingString, allowing nestation: This was rejected upstream as erikrose#45 ```python t.red('This is ', t.bold('extremely important'), ' information!') t.green('foo', t.bold('bar', t.underline('baz'), 'herp'), 'derp') ```
In some cases, it would be nice if we could "nest" styles by passing tuples, like so:
I've added tests with and without TTY, and so far it seems robust. Thoughts?