[go: nahoru, domu]

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] rich + crlf = notepad python #1824

Open
philiparvidsson opened this issue Jan 11, 2022 · 3 comments
Open

[bug] rich + crlf = notepad python #1824

philiparvidsson opened this issue Jan 11, 2022 · 3 comments
Labels

Comments

@philiparvidsson
Copy link
philiparvidsson commented Jan 11, 2022

How to h4x?

After approx. 12 hours of debugging why my app is silently crashing, I have finally figured out the cause. Here's a minimal (non-)working example file for you to work on, lol. It only crashes on Windoze, and it does so in a really nasty way which seems to entirely screw up the Python runtime. Line 1088 in one of the rich source files may be related.

import os
import time

from rich.layout import Layout
from rich.live import Live
from rich.text import Text

text = Text()
text.append(Text("foo" + os.linesep, style="yellow"))
layout = Layout(renderable=text)

with Live(layout):
    while True:
        time.sleep(0.1)

Screenshot

image

Platform

Windows 10 Command Prompt in a VM, but also tested on live Windows 10 system. Does not crash on Linux.

┌─────────────────────── <class 'rich.console.Console'> ───────────────────────┐
│ A high level console interface.                                              │
│                                                                              │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ <console width=189 ColorSystem.WINDOWS>                                  │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│                                                                              │
│     color_system = 'windows'                                                 │
│         encoding = 'utf-8'                                                   │
│             file = <colorama.ansitowin32.StreamWrapper object at 0x01809C10> │
│           height = 42                                                        │
│    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=189, height=42),         │
│                        legacy_windows=True,                                  │
│                        min_width=1,                                          │
│                        max_width=189,                                        │
│                        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=189, height=42)                   │
│        soft_wrap = False                                                     │
│           stderr = False                                                     │
│            style = None                                                      │
│         tab_size = 8                                                         │
│            width = 189                                                       │
└──────────────────────────────────────────────────────────────────────────────┘
platform="Windows"
WindowsConsoleFeatures(vt=False, truecolor=False)
rich==11.0.0
@darrenburns
Copy link
Member

Hi @philiparvidsson, thanks for the report. I'd just like to confirm a few things:

  • After you import the module, does anything happen at all? Did the "live display" not appear?
  • Did you press any additional keys after the import to get the terminal into that state?
  • Does the same behaviour happen if you run the module directly rather than importing it into the Python REPL?
  • If you have access to Windows Terminal and could check if you can reproduce it on that instead of command prompt, that would be appreciated.

Thanks!

@philiparvidsson
Copy link
Author
philiparvidsson commented Jan 19, 2022

After you import the module, does anything happen at all?

No.

Did the "live display" not appear?

It did not appear, correct.

Did you press any additional keys after the import to get the terminal into that state?

No.

Does the same behaviour happen if you run the module directly rather than importing it into the Python REPL?

Yes.

If you have access to Windows Terminal and could check if you can reproduce it on that instead of command prompt, that would be appreciated.

I don't have access to it. It seems the cause is crlf (\r) causing incorrect behavior in splitlines (or whatever it's called, line 1088 in text.py or something). So I don't think terminal matters. This doesn't crash on n*x because os.linesep has no \r in it.

@aroberge
Copy link

I have tried it with Windows Terminal (both cmd and Powershell) and, for all practical purpose, it disable the Python interpreter when importing the file. Anything typed in is ignored except that exit() is recognized.

Running python script.py simply returns to the console prompt.

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

No branches or pull requests

4 participants