Skip to content
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

RFE: FormattingString(...)('') should return '' #145

Open
mgedmin opened this issue Aug 23, 2019 · 0 comments
Open

RFE: FormattingString(...)('') should return '' #145

mgedmin opened this issue Aug 23, 2019 · 0 comments

Comments

@mgedmin
Copy link

mgedmin commented Aug 23, 2019

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.

sbraz pushed a commit to sbraz/blessed that referenced this issue Apr 26, 2020
small fix in the recently introduced .readthedocs.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant