Open
Description
I would like to format a line of text with optional trailing parts like this:
t = Terminal()
print('{part1} {part2} {part3}'.format(
part1=t.green(text_for_part1),
part2=t.blue(text_for_part2),
part3=t.yellow(text_for_part3),
).rstrip())
I would like to avoid trailing whitespace (for pointless aesthetic reasons), hence the .rstrip(). That doesn't work when text_for_part3 is an empty string, because the escape sequences for color changes get inserted anyway.
I would like to suggest that FormattingString.__call__
ought to check if the text parameter is empty and if so avoid wrapping it in formatting/reset codes.
I'm willing to prepare a PR if you think that's a reasonable idea.
Metadata
Metadata
Assignees
Labels
No labels