Textualize / rich

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

[REQUEST] Allow setting default parameters for `Console` via environment variables #2119

Closed joouha closed 2 years ago

joouha commented 2 years ago

Hello,

When using rich in euporie (a terminal Jupyter notebook client), rich detects that it is running in a Jupyter notebook and not running in a TTY, and so returns HTML output.

However, you get a far superior experience when using rich in euporie by by setting the following Console parameters:

Console(force_jupyter=False, force_terminal=True)

I'd like to be able to pre-configure rich to use these parameters by default when running in euporie.

The Jupyter kernel in which rich runs is a separate process to euporie, but will almost always be a sub-process of it. This means that if the default Console parameters could be set using environment variables, this would allow me to pre-configure rich to give the best user experience when used in euporie.

I'm happy to take stab at implementing this.

Let me know your thoughts, Thanks

willmcgugan commented 2 years ago

What are you proposing?

joouha commented 2 years ago

I'm proposing that the some of the default parameters values for Console.__init__ should be configurable using environment variables

willmcgugan commented 2 years ago

I got that, but what environment variables and what parameters?

joouha commented 2 years ago

I think it makes sense to be able to override the default behaviour of force_jupyter, force_terminal & force_interactive.

The environment variables could be called "RICH_FORCE_JUPYTER", "RICH_FORCE_TERMINAL", etc.

I've made a PR: #2122

joouha commented 2 years ago

Hello,

I've "fixed" my original issue by implementing ipywidgets support, and writing a HTML/CSS renderer for euporie, so rich's output is now handled in the same way as it is in JupyterLab.

It feels like a bit of an overly-complex solution, but it now means that rich.live.Live objects work without clearing the entire cell output, and that the HTML output of JupyterRenderables / JupyterMixins look good in the terminal.

So you can now do this:

_rich.webm

github-actions[bot] commented 2 years ago

Did I solve your problem?

Why not buy the devs a coffee to say thanks?