Rich for library authors #1924
Replies: 3 comments 3 replies
-
You could define a However, I can't recommend that. If the result is not printed in a terminal, it will look like garbage. The most reliable way would be to use the rich display hook and define a
|
Beta Was this translation helpful? Give feedback.
-
Rich will strip ansi codes when not writing to a terminal. You will need to
construct your Console with `force_terminal=True`.
…On Sun, Feb 6, 2022 at 5:49 PM Filippo Vicentini ***@***.***> wrote:
However, I can't recommend that. If the result is not printed in a
terminal, it will look like garbage.
I just tried to redirect the output from to a text file and it seems to me
that the output does not look like garbage, but that ansi codes are simply
stripped...
why do you think they would not be stripped?
—
Reply to this email directly, view it on GitHub
<#1924 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEHLAJ23YFSDDA7GK33Z4TUZ2YA5ANCNFSM5NVSKOZQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
--
Will McGugan
https://www.willmcgugan.com <http://www.willmcgugan.com>
|
Beta Was this translation helpful? Give feedback.
-
I am having the exact same issue. I have added |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I develop a large library for machine-learning/quantum physics based on Jax, and I like rich and would like to integrate it in our framework.
There's 1 thing I'd like to do in particular: use colours in the
repr
of a structure to better signal our users when a diagnostic is bad or good. see the screenshot for exampleThe structure is a custom data class defined in our codebase. I would like to have the structure be printed by rich when the REPL displays it, but I don't want to force our users to
install()
rich.pretty
.To make it display nicely I can:
from rich.pretty import install; install()
when users import our libraries, and then define a__rich__
method on our structure. I think I cannot do this as it is beyond of our scope to activate rich for users.JupyterMixin
and define__rich__
but that is not a great solution because it confuses our class hierarchy. AlsoJupyterMixin
is not part of the documented API. Also, this will only work in ipython._ipython_display_(self): rich.print(self)
and__rich__
, but defining that is not recommended so... also not an ideal option and also would only work in ipython.Are there any other options, that ideally will also work in a 'bare' python repl?
EDIT:
upon some investigating, I realised that if I define the
__rich__
method together withthen the
rich
representation will be used even in python REPL! that is exactly what I need.However is this considered API stable?
Beta Was this translation helpful? Give feedback.
All reactions