8000 RFE: FormattingString(...)('') should return '' · Issue #145 · erikrose/blessings · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
RFE: FormattingString(...)('') should return '' #145
Open
@mgedmin

Description

@mgedmin

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0