diff --git a/rich/console.py b/rich/console.py index 8a0fdcd9be..ca3bb1a0ea 100644 --- a/rich/console.py +++ b/rich/console.py @@ -1004,19 +1004,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():