Open KommuSoft opened 1 year ago
I like this idea, for it is a common use case to just style lines of text (and not bleed the effects to the rest of the output). The extension of functionality to add a call behavior is simple enough, but it's also very opinionated.
Rethinking this, perhaps the __call__
is indeed a bad idea, but perhaps just adding an extra method like .sandwich(..)
could be useful?
In the
AnsiCodes
, we use some logic in the__init__
to makeFore.RED
for example to a string.We could subclass the
str
class to make it callable, for example:Then in the
code_to_chars
method, we can wrap the string into aFormattingString
:This makes it useful for short formatting, like:
which will print the
foo
into red, and then reset it, so:Is this an improvement that might be considered?