Fix auto detection of terminal size on Windows #2916
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of changes
Checklist
Description
Currently, the automatic detection of terminal size on Windows is only performed for
_STDOUT_FILENO
which is the default value passed toos.get_terminal_size
. So if we redirect the standard output (stdout
) to a file and create aConsole
on the standard error (stderr
) withwidth
andheight
leftNone
, the auto-detected terminal size will always be a fallback value(80, 25)
(supposing thatlegacy_windows
isFalse
).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):and I got following output:
which is not what I expected:
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
.