Carpet

Carpet

2M Downloads

str() discards format() formatting

Kaedenn opened this issue ยท 2 comments

commented

It would appear that str() discards formatting generated via the format() function.

The following displays text, but without formatting:

/script run print(str('%s', format('rb test')))

I suggest having str() preserve formatting when given a formatted string as an argument.

commented

str() is a wrapper for a good'ol printf function which is tuned for string composing, not just for %s but other formatters as well , format() combines consecutive formatted strings. While it would be convenient if str would preserve formatting, understanding what each of them is designed for makes sense that str() only operates on simple strings.
What you would want to use is format strings with str and then pass them to format to create the final formatted output.

tl;dr; valid request, but won't fix due to extra complexity.

commented

Then I'll look into what it'd take to implement a smarter str() to handle such formatting. I might be able to hand you something that just drop-in work, if you're receptive to such things.