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

Fix auto detection of terminal size on Windows #2916

Closed
wants to merge 1 commit into from

Conversation

lewis-yeung
Copy link
Contributor

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Currently, the automatic detection of terminal size on Windows is only performed for _STDOUT_FILENO which is the default value passed to os.get_terminal_size. So if we redirect the standard output (stdout) to a file and create a Console on the standard error (stderr) with width and height left None, the auto-detected terminal size will always be a fallback value (80, 25) (supposing that legacy_windows is False).

A simple example to illustrate this problem: I ran the following test script with only stdout redirected to a file (stderr was still connected to a terminal with width = 110 and height = 45):

import sys
from rich.console import Console

console = Console(stderr=True, legacy_windows=False)
print(console.size, file=sys.stderr)

and I got following output:

ConsoleDimensions(width=80, height=25)

which is not what I expected:

ConsoleDimensions(width=110, height=45)

On Linux, it works as expected.

To resolve the problem on Windows, we should perform the automatic detection for both _STDOUT_FILENO and _STDERR_FILENO.

@lewis-yeung lewis-yeung changed the title fix auto detection of terminal size on Windows Fix auto detection of terminal size on Windows May 9, 2023
@lewis-yeung
Copy link
Contributor Author

lewis-yeung commented Sep 18, 2023

@willmcgugan Anything stopping us from going on?

@willmcgugan
Copy link
Collaborator

Closing, assumed stale. If it is still relevant, please open an issue with code to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants