rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Console(no_color=True) does not work on Windows 10

Open pirxthepilot opened this issue 3 years ago • 1 comments

You may find a solution to your problem in the docs or issues.

Describe the bug

The "no_color=True" Console parameter does not seem to do anything on Windows 10. I tested on both Cmder and native cmd.exe terminals and got the same results. See screenshots below.

Cmder: richbug01

cmd.exe richbug02

for reference, this is what it looks like from my Ubuntu laptop:

richbug-linux-ok

Also happy to help fix this if you can point me in the right direction. Thank you!

Platform

Click to expand

OS: Windows 10

Cmder:

┌───────────────────────── <class 'rich.console.Console'> ─────────────────────────┐ │ A high level console interface. │ │ │ │ ┌──────────────────────────────────────────────────────────────────────────────┐ │ │ │ <console width=155 ColorSystem.WINDOWS> │ │ │ └──────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ color_system = 'windows' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 83 │ │ 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=155, height=83), │ │ legacy_windows=True, │ │ min_width=1, │ │ max_width=155, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=83, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=155, height=83) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 155 │ └──────────────────────────────────────────────────────────────────────────────────┘ ┌─── <class 'rich._windows.WindowsConsoleFeatures'> ────┐ │ Windows features available. │ │ │ │ ┌───────────────────────────────────────────────────┐ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ └───────────────────────────────────────────────────┘ │ │ │ │ truecolor = False │ │ vt = False │ └───────────────────────────────────────────────────────┘ ┌────── Environment Variables ───────┐ │ { │ │ 'TERM': 'cygwin', │ │ 'COLORTERM': None, │ │ 'CLICOLOR': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': None, │ │ 'COLUMNS': '157', │ │ 'LINES': '83', │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ └────────────────────────────────────┘ platform="Windows"

cmd.exe

┌───────────────────────── <class 'rich.console.Console'> ─────────────────────────┐ │ A high level console interface. │ │ │ │ ┌──────────────────────────────────────────────────────────────────────────────┐ │ │ │ <console width=119 ColorSystem.WINDOWS> │ │ │ └──────────────────────────────────────────────────────────────────────────────┘ │ │ │ │ color_system = 'windows' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 30 │ │ 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=119, height=30), │ │ legacy_windows=True, │ │ min_width=1, │ │ max_width=119, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=30, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=119, height=30) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 119 │ └──────────────────────────────────────────────────────────────────────────────────┘ ┌─── <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"

rich==12.5.1

pirxthepilot avatar Aug 09 '22 04:08 pirxthepilot

Update: Seems to work if I explicitly set legacy_windows=False:

richbug-windows-legacy-false-ok

pirxthepilot avatar Aug 09 '22 08:08 pirxthepilot

The bug also does not occur when running cmd.exe within windows terminal.

MarkZH avatar Aug 14 '22 17:08 MarkZH

It was an issue with rendering on "legacy" terminals on Windows, so would only affect people using older versions of cmd.

In legacy rendering, Rich calls Win32 APIs directly, rather than using the same codepath as on Linux/MacOS. Turns out that code didn't consider no_color at all!

Fixed as part of https://github.com/Textualize/rich/pull/2458, so this should be resolved in the next release of Rich. Keep an eye out for the next release and let us know if you hit any further issues with it 🙂

darrenburns avatar Aug 16 '22 09:08 darrenburns

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

github-actions[bot] avatar Aug 16 '22 09:08 github-actions[bot]

Thanks so much for fixing in a timely manner!

pirxthepilot avatar Aug 16 '22 19:08 pirxthepilot