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] Jupyter font, line spacing, and status/spinners not consistent with terminal output #3507

Closed mwinokan closed 2 months ago

mwinokan commented 2 months ago

Describe the bug

Opening a new issue as #236 did not help me to fully resolve my Jupyter issues.

Namely I have not found a way to set up a rich.console.Console object for use in Jupyter that is consistent with the terminal output.

A default Console object used in Jupyter adds an unwanted line spacing, increased font size, and the reversed text is white on green rather than black on green:

Screenshot 2024-09-30 at 13 02 41

Compare the above to the output when setting force_jupyter=False, force_terminal=True to restore the expected font size, line spacing, and reverse colours (although now the bright colours are not supported): Screenshot 2024-09-30 at 13 05 13

However, it goes without saying that being limited to using force_terminal=True causes issues with interactive objects such as console.status:

Screenshot 2024-09-30 at 13 07 59

Using the console as the context manager is also not desirable as the interactive status/spinner displays are thereby useless.

I am a big fan of rich and would love to include it across my packages which should behave consistently in both terminal and Jupyter notebooks, any suggestions are much appreciated. Thank you

Platform

Jupyter platform report ```python ╭──────────────────── ─────────────────────╮ │ A high level console interface. │ │ │ │ ╭─────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰─────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = │ │ height = 100 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = False │ │ is_jupyter = True │ │ is_terminal = False │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=115, height=100), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=115, │ │ is_terminal=False, │ │ encoding='utf-8', │ │ max_height=100, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=115, height=100) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 115 │ ╰─────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭──────── Environment Variables ────────╮ │ { │ │ 'TERM': 'xterm-color', │ │ 'COLORTERM': None, │ │ 'CLICOLOR': '1', │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': 'Apple_Terminal', │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': '95091', │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰───────────────────────────────────────╯ platform="Darwin" ```
github-actions[bot] commented 2 months ago

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

willmcgugan commented 2 months ago

You are expecting too much. Rich is a terminal out library. Jupyter support is there so you can run code in terminal and Jupyter context. But Rich can't detect what your Jupyter background color is. It can't know the width of your browser. And it can't be certain how the browser's style will impact the output. There are so many implementations of Jupyter, that pleasing everyone is quite literally impossible.

I'm glad you like Rich. But it is a terminal library first and foremost.

github-actions[bot] commented 2 months ago

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual