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] [Windows only] Table defaults to safe_box when the output is piped. #3625

Open
2 tasks done
zapta opened this issue Jan 30, 2025 · 1 comment
Open
2 tasks done

Comments

@zapta
Copy link

zapta commented Jan 30, 2025

Describe the bug

When running on window and with piped output, the table are displayed in "safe box" mode by default. This is not the case on Max OSX and Linux.

Run this on windows and pipe the output.

from rich.console import Console
from rich.table import Table
from rich import box

console = Console(color_system="auto", force_terminal=True)

table = Table(
  show_header=True,
  show_lines=True,
  box=box.SQUARE,
  border_style="dim",
  title="My Table")

table.add_column("COL1")
table.add_column("COL2")

table.add_row("aaa", "bbb", style="red")
table.add_row("ccc", "ddd")

console.print(table)

Workaround: Add this at the beginning of the program:

sys.stdout.reconfigure(encoding='utf-8')

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

Windows 10. (it's ok on Mac and Linux). Reproduced on both windows cmd and on git bash.

~/work$ python -m rich.diagnose
pip freeze | grep rich
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=152 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 42                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=152, height=42),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=152,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=42,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=152, height=42)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 152                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm',               │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'mintty',      │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"
rich==13.9.4

And this is the same output with piped output (notice that the encoding is different):

~/work$ python -m rich.diagnose | cat
+------------------------- <class 'rich.console.Console'> --------------------------+
| A high level console interface.                                                   |
|                                                                                   |
| +-------------------------------------------------------------------------------+ |
| | <console width=151 None>                                                      | |
| +-------------------------------------------------------------------------------+ |
|                                                                                   |
|     color_system = None                                                           |
|         encoding = 'cp1252'                                                       |
|             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'> |
|           height = 42                                                             |
|    is_alt_screen = False                                                          |
| is_dumb_terminal = False                                                          |
|   is_interactive = False                                                          |
|       is_jupyter = False                                                          |
|      is_terminal = False                                                          |
|   legacy_windows = True                                                           |
|         no_color = False                                                          |
|          options = ConsoleOptions(                                                |
|                        size=ConsoleDimensions(width=151, height=42),              |
|                        legacy_windows=True,                                       |
|                        min_width=1,                                               |
|                        max_width=151,                                             |
|                        is_terminal=False,                                         |
|                        encoding='cp1252',                                         |
|                        max_height=42,                                             |
|                        justify=None,                                              |
|                        overflow=None,                                             |
|                        no_wrap=False,                                             |
|                        highlight=None,                                            |
|                        markup=None,                                               |
|                        height=None                                                |
|                    )                                                              |
|            quiet = False                                                          |
|           record = False                                                          |
|         safe_box = True                                                           |
|             size = ConsoleDimensions(width=151, height=42)                        |
|        soft_wrap = False                                                          |
|           stderr = False                                                          |
|            style = None                                                           |
|         tab_size = 8                                                              |
|            width = 151                                                            |
+-----------------------------------------------------------------------------------+
+--- <class 'rich._windows.WindowsConsoleFeatures'> ----+
| Windows features available.                           |
|                                                       |
| +---------------------------------------------------+ |
| | WindowsConsoleFeatures(vt=False, truecolor=False) | |
| +---------------------------------------------------+ |
|                                                       |
| truecolor = False                                     |
|        vt = False                                     |
+-------------------------------------------------------+
+------ Environment Variables -------+
| {                                  |
|     'TERM': 'xterm',               |
|     'COLORTERM': None,             |
|     'CLICOLOR': None,              |
|     'NO_COLOR': None,              |
|     'TERM_PROGRAM': 'mintty',      |
|     'COLUMNS': None,               |
|     'LINES': None,                 |
|     'JUPYTER_COLUMNS': None,       |
|     'JUPYTER_LINES': None,         |
|     'JPY_PARENT_PID': None,        |
|     'VSCODE_VERBOSE_LOGGING': None |
| }                                  |
+------------------------------------+
platform="Windows"

If you're using Rich in a Jupyter Notebook, run the following snippet in a cell
and paste the output in your bug report.

from rich.diagnose import report
report()
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

zapta added a commit to zapta/apio_dev that referenced this issue Jan 30, 2025
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

1 participant