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

[BUG] Colorization of STDERR is unexpectedly disabled when STDOUT is redirected #3234

Closed
2 tasks done
huettenhain opened this issue Dec 17, 2023 · 5 comments
Closed
2 tasks done

Comments

@huettenhain
Copy link

huettenhain commented Dec 17, 2023

Describe the bug

Consider the following code:

from rich.console import Console
_print = Console(highlight=False, stderr=True, no_color=False).print
_print("[bright_red]hello[/]")

When running this on Windows 10, 22H2, colorization is disabled when the standard output is redirected.

Example:
image

Click to expand Rich is running in the standard Windows CMD terminal.
$ python -m rich.diagnose
┌────────── <class 'rich.console.Console'> ───────────┐
│ A high level console interface.                     │
│                                                     │
│ ┌─────────────────────────────────────────────────┐ │
│ │ <console width=55 ColorSystem.WINDOWS>          │ │
│ └─────────────────────────────────────────────────┘ │
│                                                     │
│     color_system = 'windows'                        │
│         encoding = 'utf-8'                          │
│             file = <_io.TextIOWrapper               │
│                    name='<stdout>' mode='w'         │
│                    encoding='utf-8'>                │
│           height = 9                                │
│    is_alt_screen = False                            │
│ is_dumb_terminal = False                            │
│   is_interactive = True                             │
│       is_jupyter = False                            │
│      is_terminal = True                             │
│   legacy_windows = True                             │
│         no_color = False                            │
│          options = ConsoleOptions(                  │
│                        size=ConsoleDimensions(      │
│                            width=55,                │
│                            height=9                 │
│                        ),                           │
│                        legacy_windows=True,         │
│                        min_width=1,                 │
│                        max_width=55,                │
│                        is_terminal=True,            │
│                        encoding='utf-8',            │
│                        max_height=9,                │
│                        justify=None,                │
│                        overflow=None,               │
│                        no_wrap=False,               │
│                        highlight=None,              │
│                        markup=None,                 │
│                        height=None                  │
│                    )                                │
│            quiet = False                            │
│           record = False                            │
│         safe_box = True                             │
│             size = ConsoleDimensions(               │
│                        width=55,                    │
│                        height=9                     │
│                    )                                │
│        soft_wrap = False                            │
│           stderr = False                            │
│            style = None                             │
│         tab_size = 8                                │
│            width = 55                               │
└─────────────────────────────────────────────────────┘
┌── <class 'rich._windows.WindowsConsoleFeatures'> ───┐
│ Windows features available.                         │
│                                                     │
│ ┌─────────────────────────────────────────────────┐ │
│ │ WindowsConsoleFeatures(                         │ │
│ │ │   vt=False,                                   │ │
│ │ │   truecolor=False                             │ │
│ │ )                                               │ │
│ └─────────────────────────────────────────────────┘ │
│                                                     │
│ truecolor = False                                   │
│        vt = False                                   │
└─────────────────────────────────────────────────────┘
┌────── Environment Variables ───────┐
│ {                                  │
│     'TERM': None,                  │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
└────────────────────────────────────┘
platform="Windows"
$ pip freeze | grep rich
rich==13.7.0
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

https://rich.readthedocs.io/en/latest/console.html#terminal-detection

Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@huettenhain
Copy link
Author

Apologies dear @willmcgugan, I forgot to mention that I did try setting force_terminal=True, but it does not alter the output.

@huettenhain
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants