diff --git a/CHANGELOG.md b/CHANGELOG.md index 8191a7767..c86bf324c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed issue with Segment._split_cells https://github.com/Textualize/rich/pull/3506 +- Fix auto detection of terminal size on Windows https://github.com/Textualize/rich/pull/2916 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9294136fa..4dd14dde1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -87,5 +87,6 @@ The following people have contributed to the development of Rich: - [Pierro](https://github.com/xpierroz) - [Bernhard Wagner](https://github.com/bwagner) - [Aaron Beaudoin](https://github.com/AaronBeaudoin) +- [L. Yeung](https://github.com/lewis-yeung) - [chthollyphile](https://github.com/chthollyphile) - [Jonathan Helmus](https://github.com/jjhelmus) diff --git a/rich/console.py b/rich/console.py index 9e697327b..9ef0d60bb 100644 --- a/rich/console.py +++ b/rich/console.py @@ -1005,19 +1005,13 @@ def size(self) -> ConsoleDimensions: width: Optional[int] = None height: Optional[int] = None - if WINDOWS: # pragma: no cover + for file_descriptor in _STD_STREAMS_OUTPUT if WINDOWS else _STD_STREAMS: try: - width, height = os.get_terminal_size() + width, height = os.get_terminal_size(file_descriptor) except (AttributeError, ValueError, OSError): # Probably not a terminal pass - else: - for file_descriptor in _STD_STREAMS: - try: - width, height = os.get_terminal_size(file_descriptor) - except (AttributeError, ValueError, OSError): - pass - else: - break + else: + break columns = self._environ.get("COLUMNS") if columns is not None and columns.isdigit():