Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamline legacy windows logic #2081

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions rich/_windows_renderer.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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