jquast / blessed

Blessed is an easy, practical library for making python terminal apps
http://pypi.python.org/pypi/blessed
MIT License
1.18k stars 71 forks source link

Prevent term.normal from adding carriage return to string #240

Closed ajgringo619 closed 2 years ago

ajgringo619 commented 2 years ago

I'm trying to add a bold/underlined variable to an f-string. While this works, I want to add a closing parentheses at the end of the line:

print(f"{MY_USERNAME}'s info (updated on "
      f"{term.bold_underline}{user_stats_timestamp}{term.normal})")

Unfortunately, I'm getting a carriage return inserted by term.normal, placing the parentheses mark on the next line:

ajgringo619's info (updated on Mon Apr 25 15:13:16 GMT 2022
)

Is there a way to prevent this?

avylove commented 2 years ago

Are you sure the carriage return is in term.normal and not in user_stats_timestamp? Can you provide the output of term.normal? I would expect it to be similar to the following.

>>> import blessed
>>> term = blessed.Terminal()
>>> term.normal
'\x1b(B\x1b[m'
ajgringo619 commented 2 years ago

Thanks for the hint. I had forgotten to strip the variable when it was read from a file.