Skip to content

Commit

Permalink
Merge pull request #2081 from Textualize/win32-refinements
Browse files Browse the repository at this point in the history
streamline legacy windows logic
  • Loading branch information
willmcgugan committed Mar 21, 2022
2 parents 1f758c4 + 3415272 commit a278b6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 1 addition & 3 deletions rich/_windows_renderer.py
Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions rich/console.py
Expand Up @@ -92,6 +92,8 @@ class NoChange:
except Exception:
_STDERR_FILENO = 2

_STD_STREAMS = (_STDOUT_FILENO, _STDERR_FILENO)

CONSOLE_HTML_FORMAT = """\
<!DOCTYPE html>
<head>
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a278b6e

Please sign in to comment.