From 3415272059952cc86114bf5a2148c3e932ae4ff5 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 18 Mar 2022 17:09:03 +0000 Subject: [PATCH] streamline legacy windows logic --- rich/_windows_renderer.py | 4 +--- rich/console.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/rich/_windows_renderer.py b/rich/_windows_renderer.py index e9debe30f..514c45115 100644 --- a/rich/_windows_renderer.py +++ b/rich/_windows_renderer.py @@ -11,9 +11,7 @@ def legacy_windows_render(buffer: Iterable[Segment], term: LegacyWindowsTerm) -> buffer (Iterable[Segment]): Iterable of Segments to convert to Win32 API calls. term (LegacyWindowsTerm): Used to call the Windows Console API. """ - for segment in buffer: - text, style, control = segment - + for text, style, control in buffer: if not control: if style: term.write_styled(text, style) diff --git a/rich/console.py b/rich/console.py index b91c84871..6a0b3e902 100644 --- a/rich/console.py +++ b/rich/console.py @@ -92,6 +92,8 @@ class NoChange: except Exception: _STDERR_FILENO = 2 +_STD_STREAMS = (_STDOUT_FILENO, _STDERR_FILENO) + CONSOLE_HTML_FORMAT = """\ @@ -1940,16 +1942,16 @@ def _check_buffer(self) -> None: del self._buffer[:] else: if WINDOWS: - try: - file_no = self.file.fileno() - except (ValueError, io.UnsupportedOperation): - file_no = -1 - - stdout_num = _STDOUT_FILENO - stderr_num = _STDERR_FILENO - is_std_stream = file_no in (stdout_num, stderr_num) - legacy_windows_std = self.legacy_windows and is_std_stream - if legacy_windows_std: + use_legacy_windows_render = False + if self.legacy_windows: + try: + use_legacy_windows_render = ( + self.file.fileno() in _STD_STREAMS + ) + except (ValueError, io.UnsupportedOperation): + pass + + if use_legacy_windows_render: from rich._win32_console import LegacyWindowsTerm from rich._windows_renderer import legacy_windows_render