Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.73k stars 1.73k forks source link

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

Closed ericfrederich closed 2 months ago

ericfrederich commented 2 months ago

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 ╭─────────────────────── ────────────────────────╮ │ A high level console interface. │ │ │ │ ╭───────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = '256' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' 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 │ ╰───────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ 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 commented 2 months ago

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.

github-actions[bot] commented 2 months ago

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual