Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] Parse escape codes in pretty printer #2287

Closed
dlukes opened this issue May 20, 2022 · 6 comments
Closed

[REQUEST] Parse escape codes in pretty printer #2287

dlukes opened this issue May 20, 2022 · 6 comments
Assignees

Comments

@dlukes
Copy link

dlukes commented May 20, 2022

I ran into this while using https://github.com/InvestmentSystems/static-frame:

image

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 in Out[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?

@willmcgugan
Copy link
Collaborator

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.

@dlukes
Copy link
Author

dlukes commented May 20, 2022

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.

@willmcgugan
Copy link
Collaborator

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!

@willmcgugan
Copy link
Collaborator

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.

@willmcgugan willmcgugan changed the title [REQUEST] Play nicer with libraries that do their own fancy output [REQUEST] Parse escape codes in pretty printer Jun 10, 2022
@darrenburns darrenburns self-assigned this Aug 16, 2022
@darrenburns
Copy link
Member

Added in #2470, so should be fixed in the next release. Let us know if not.

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants