prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

Renderer always subtracts one from the terminal width, leaving a column unoccupied #1758

Open LoganDark opened 1 year ago

LoganDark commented 1 year ago

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/5b3dd6dbbd72ac8323e749cc12e6aa2d7c7411af/src/prompt_toolkit/renderer.py#L199-L200

The renderer always subtracts one from the terminal width, leaving a column on the right unoccupied. This is a column that the application could be using (and seemingly has no reason to avoid), and looks ugly.

This monkey-patch seems to work perfectly fine, for fullscreen and non-fullscreen applications:

        old_get_size = app.output.get_size

        def new_get_size():
            size = old_get_size()
            return Size(size.rows, size.columns + 1)

        app.output.get_size = new_get_size

Perhaps prompt-toolkit used to rely on some cursor positioning detail that required a workaround, but that doesn't seem to be the case anymore. I propose simply removing the - 1 altogether. Is there even any reason to keep it?

asmeurer commented 1 year ago

For me prompt-toolkit uses every available column in the terminal.

LoganDark commented 1 year ago

For me prompt-toolkit uses every available column in the terminal.

well, for me, in both Windows Terminal and conhost.exe, there is an unoccupied column on the right.

image

applying the monkey-patch fixes the issue.

image

if it uses every available column for you, then something is going on for sure. this might be a workaround for some issue that still affects some terminals? but it's clearly not needed for mine