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] Console.size returns the wrong width if legacy_windows is True #3430

Open
2 tasks done
PalmtopTiger opened this issue Jul 18, 2024 · 1 comment
Open
2 tasks done

Comments

@PalmtopTiger
Copy link

PalmtopTiger commented Jul 18, 2024

Describe the bug

There is no need to subtract self.legacy_windows from self._width in the size getter (link) because the self._width field already contains a value that takes legacy_windows into account (link).

For example, you can't directly get the size value from one console and assign it to another. The width of the second console will be 1 character smaller.

from rich import get_console
from rich.console import Console

console  = get_console()
econsole = Console(stderr=True)

print("Before:\nconsole.size  =", console.size, "\neconsole.size =", econsole.size)

econsole.size = console.size

print("After:\nconsole.size  =", console.size, "\neconsole.size =", econsole.size)

Output:

Before:
console.size  = ConsoleDimensions(width=182, height=26)
econsole.size = ConsoleDimensions(width=182, height=26)
After:
console.size  = ConsoleDimensions(width=182, height=26)
econsole.size = ConsoleDimensions(width=181, height=26)

Platform

Click to expand

OS: Windows 10 22H2
Terminal: ConEmu

$ python -m rich.diagnose
┌───────────────────────── <class 'rich.console.Console'> ─────────────────────────┐
│ A high level console interface.                                                  │
│                                                                                  │
│ ┌──────────────────────────────────────────────────────────────────────────────┐ │
│ │ <console width=182 ColorSystem.WINDOWS>                                      │ │
│ └──────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                  │
│     color_system = 'windows'                                                     │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 26                                                            │
│    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=182, height=26),             │
│                        legacy_windows=True,                                      │
│                        min_width=1,                                              │
│                        max_width=182,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=26,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=182, height=26)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 182                                                           │
└──────────────────────────────────────────────────────────────────────────────────┘
┌─── <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': '184',              │
│     'LINES': '26',                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
└────────────────────────────────────┘
platform="Windows"
$ pip freeze | rg rich
rich==13.7.1
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

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