Closed dlukes closed 2 years ago
I'm guess this library is writing escape codes with it's repr, which is frankly a bad idea.
Yes, it would be possible to workaround. The simplest solution would be to not do any further processing if there is an escape code in the output.
I'm guess this library is writing escape codes with it's repr, which is frankly a bad idea.
Ah, that's a good point. Yes, that's what it's doing, based on the cursory look I had before submitting this issue.
So maybe just leave such reprs as is, not to make matters worse, even though rich's expectation that there be no escape codes in the repr is reasonable? Bandwidth allowing of course.
So maybe just leave such reprs as is, not to make matters worse, even though rich's expectation that there be no escape codes in the repr is reasonable? Bandwidth allowing of course.
It is reasonable. repr strings are used in many contexts where escape codes won't work. However, we've worked around unreasonable things that developers do before!
I think what we'll do is in pretty.py, if a repr contains an escape we will attempt to parse that as ANSI escape codes.
Added in https://github.com/Textualize/rich/pull/2470, so should be fixed in the next release. Let us know if not.
Did I solve your problem?
Why not buy the devs a coffee to say thanks?
I ran into this while using https://github.com/InvestmentSystems/static-frame:
StaticFrame does its own coloring, seen in
Out[3]
. But when I enable rich's REPL support (which I typically do by default), rich attempts to color the ANSI escape codes that are already there and corrupts them, resulting in the garbled output seen inOut[5]
.Would it be possible to detect whether the output already contains ANSI escape codes, and if so, either strip them before applying rich's own coloring, or skip it entirely? Ideally, the behavior could be configured via
rich.pretty.install
or some similar mechanism.Alternatively, maybe there is an existing way to deal with this when using rich that I'm not aware of?