blessings icon indicating copy to clipboard operation
blessings copied to clipboard

Support (and tests) for tuples with nested styles

Open jimallman opened this issue 11 years ago • 3 comments

In some cases, it would be nice if we could "nest" styles by passing tuples, like so:

# creates a red phrase with some bold words in the middle:
t.red('This is ', t.bold('extremely important'), ' information!')

# deeper nesting of styles (green, then bold, then underline, and back out)
t.green('foo', t.bold('bar', t.underline('baz'), 'herp'), 'derp')

I've added tests with and without TTY, and so far it seems robust. Thoughts?

jimallman avatar Oct 26 '13 07:10 jimallman

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?

jimallman avatar Apr 03 '14 17:04 jimallman

My fault; I just got distracted with other libraries. I'll try to have a look after PyCon. Sorry!

erikrose avatar Apr 09 '14 16:04 erikrose

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:

"{t.red}This {t.bold}is important{t.no_bold}!".format(t=terminal)

but that's another pull request for another time...

davedash avatar Apr 29 '14 00:04 davedash