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] extraneous newline added with rich.syntax module #3489

Closed
2 tasks done
ericfrederich opened this issue Sep 11, 2024 · 2 comments
Closed
2 tasks done

[BUG] extraneous newline added with rich.syntax module #3489

ericfrederich opened this issue Sep 11, 2024 · 2 comments

Comments

@ericfrederich
Copy link

Describe the bug

While running rich.syntax as a module a new line is added on each invocation.

Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.

I use an alias of alias hili='python -m rich.syntax -b default'. It always adds a newline. Subsequent invocations of this do as well.

image

When running through xxd you can see it adding newlines (0x0A) characters.
Ideally when running through a pipe nothing should be modified.

image

Platform

Click to expand

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

Linux VM (via WSL2)

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich
# python -m rich.diagnose
╭─────────────────────── <class 'rich.console.Console'> ────────────────────────╮
│ A high level console interface.                                               │
│                                                                               │
│ ╭───────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=81 ColorSystem.EIGHT_BIT>                                  │ │
│ ╰───────────────────────────────────────────────────────────────────────────╯ │
│                                                                               │
│     color_system = '256'                                                      │
│         encoding = 'utf-8'                                                    │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w'                │
│                    encoding='utf-8'>                                          │
│           height = 32                                                         │
│    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=81, height=32),           │
│                        legacy_windows=False,                                  │
│                        min_width=1,                                           │
│                        max_width=81,                                          │
│                        is_terminal=True,                                      │
│                        encoding='utf-8',                                      │
│                        max_height=32,                                         │
│                        justify=None,                                          │
│                        overflow=None,                                         │
│                        no_wrap=False,                                         │
│                        highlight=None,                                        │
│                        markup=None,                                           │
│                        height=None                                            │
│                    )                                                          │
│            quiet = False                                                      │
│           record = False                                                      │
│         safe_box = True                                                       │
│             size = ConsoleDimensions(width=81, height=32)                     │
│        soft_wrap = False                                                      │
│           stderr = False                                                      │
│            style = None                                                       │
│         tab_size = 8                                                          │
│            width = 81                                                         │
╰───────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-256color',      │
│     '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="Linux"

# pip freeze | grep rich
rich==13.8.1
@willmcgugan
Copy link
Collaborator

Rich syntax doesn't just apply highlighting to a stream of text. It changes tabs to spaces, wraps or truncates lines. It can add line numbers, indentation guides etc. i.e. it makes no guarantee that all it will do is add color.

Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

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