jquast / blessed

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

Add support for the linewrap escape sequence #228

Open SystematicError opened 2 years ago

SystematicError commented 2 years ago

Hello, I've been using this library for a project and its amazing, one thing I felt was missing was the ability to enable or disable auto linewrap (documentation here). This is particularly useful as if by chance any text were to overflow, it won't interfere with any other lines.

For example, this is how its done in bash or any other shell scripts:

# Disabling line wrapping.
printf '\e[?7l'

# Enabling line wrapping.
printf '\e[?7h'

Once added, this feature could possibly be used like this:

with term.no_wrap():
    print("Hello World!")
jquast commented 2 years ago

I would gladly accept a PR of the suggested design into next release, be sure to use rmam and smam terminal capabilities

Thank you!

SystematicError commented 2 years ago

Thanks for the response, I've only scoured through the code for a couple minutes so I've only got a very loose understanding of this. I am currently working on some other stuff, so I'd try forking and submitting a PR when I'm free :)

SystematicError commented 2 years ago

image I had a bit of free time and decided to quickly clone the repo to try understand how it works. I got this sorta working by adding rmam and smam to the dictionary _sugar and adding a context manager. It seems to work fine, however it seems to be truncating the line one character too long. I'll see if there's any fix to this.

SystematicError commented 2 years ago

image I tested across a different terminal just to verify whether it was my fault or not, the same issue still occurs.

SystematicError commented 2 years ago

image Weirdly this isn't happening when doing this from the terminal directly

avylove commented 2 years ago

I think we'd need to see what you implemented in order to assist. My guess is it's something in your context manager as I can do this with the current release.

>>> print(term.rmam + '123456789|' * 10 )
123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|
>>> print(term.smam + '123456789|' * 10 )
123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|