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

Console width off by one on some terminals / ssh #7

Closed
dzerrenner opened this issue Feb 4, 2020 · 3 comments
Closed

Console width off by one on some terminals / ssh #7

dzerrenner opened this issue Feb 4, 2020 · 3 comments
Labels
accepted Task was accepted

Comments

@dzerrenner
Copy link

dzerrenner commented Feb 4, 2020

On some consoles the output width seems to be calculated one character too wide. See the following example:

>>> from rich.console import Console
>>> from rich.table import Table
>>> c = Console()
>>> t = Table("Yo!", "Tables!")
>>> t.add_row("a", "row")
>>> t.add_row("another", "row")
>>> c.print(t)
┏━━━━━━━━━┳━━━━━━━━━┓

┃ Yo!     ┃ Tables! ┃

┡━━━━━━━━━╇━━━━━━━━━┩

│ a       │ row     │

│ another │ row     │

└─────────┴─────────┘

>>> c = Console(width=c.width-1)
>>> c.print(t)
┏━━━━━━━━━┳━━━━━━━━━┓
┃ Yo!     ┃ Tables! ┃
┡━━━━━━━━━╇━━━━━━━━━┩
│ a       │ row     │
│ another │ row     │
└─────────┴─────────┘

I played around a bit and tested some combinations, some seem fine, others not:

  • ssh terminal in vscode: OK
  • ssh terminal in ConEmu: one too wide
  • ssh terminal in Windows command interpreter (Win+R, cmd): one too wide

Source System is Win10, the system the console runs on was either Ubuntu 18 or Oracle Linux

A possible workaround is as shown above: get a Console, and then get another one which is one narrower than the first one.

Looking ath the code, i understand that you are retrieving the terminal size via shutil.get_terminal_size(), so maybe that issue is beyond the reach of the lib.

@willmcgugan
Copy link
Collaborator

I've noticed this on Windows terminal. I think the issue is that the Windows terminal treats a new line character has having width of 1. On Linux terminal emulators the new line has no width.

The master branch does width-1 for windows, but it doesn't feel like a good solution, so I'm investigating alternatives.

@willmcgugan willmcgugan added the accepted Task was accepted label Feb 4, 2020
@dzerrenner
Copy link
Author

I just tried it with the code at the master branch with no luck. I think it is because the code does not run on Windows, i just connect to the terminal from a windows machine.

I'll stick with the workaround for the moment, i think i can spare that one character even if it is not necessary to cut it. Besides of this little issue, rich is a great lib!

@willmcgugan
Copy link
Collaborator

Glad you like it.

With a bit of experimentation, it appears as though Windows inserts new lines for you when the text reaches the right of the terminal, MacOS and Linux doesn't. I think the only option is to always subtract 1, as you did. v0.3.3 has that fix.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted
Projects
None yet
Development

No branches or pull requests

2 participants