Skip to content

Commit

Permalink
Get filenos of original stdout and stderr in console
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Mar 16, 2022
1 parent 1d61867 commit 98969ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import io
import os
import platform
import pty
import sys
import threading
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -83,6 +82,15 @@ class NoChange:

NO_CHANGE = NoChange()

try:
_STDOUT_FILENO = sys.__stdout__.fileno()
except Exception:
_STDOUT_FILENO = 1

try:
_STDERR_FILENO = sys.__stderr__.fileno()
except Exception:
_STDERR_FILENO = 2

CONSOLE_HTML_FORMAT = """\
<!DOCTYPE html>
Expand Down Expand Up @@ -1937,8 +1945,8 @@ def _check_buffer(self) -> None:
except (ValueError, io.UnsupportedOperation):
file_no = -1

stdout_num = pty.STDOUT_FILENO
stderr_num = pty.STDERR_FILENO
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:
Expand Down

0 comments on commit 98969ab

Please sign in to comment.